1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-29 08:27:55 +00:00
seahub/static/scripts/app/views/devices.js

66 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-03-15 10:18:45 +00:00
define([
'jquery',
'underscore',
'backbone',
'common',
'app/views/device',
2017-10-10 08:16:37 +00:00
'app/collections/devices'
2016-03-15 10:18:45 +00:00
], function($, _, Backbone, Common, Device, DevicesCollection) {
'use strict';
var DevicesView = Backbone.View.extend({
id: 'devices',
2016-03-15 10:18:45 +00:00
template: _.template($('#devices-tmpl').html()),
2016-03-15 10:18:45 +00:00
initialize: function() {
2016-03-15 10:18:45 +00:00
this.devices = new DevicesCollection();
this.listenTo(this.devices, 'reset', this.reset);
2017-10-10 08:16:37 +00:00
this.render();
2016-03-15 10:18:45 +00:00
},
addOne: function(device) {
var view = new Device({model: device});
this.$tableBody.append(view.render().el);
},
reset: function() {
this.$tableBody.empty();
this.$loadingTip.hide();
this.devices.each(this.addOne, this);
if (this.devices.length) {
this.$emptyTip.hide();
this.$table.show();
} else {
this.$emptyTip.show();
this.$table.hide();
}
},
render: function() {
this.$el.html(this.template());
this.$table = this.$('table');
this.$tableBody = this.$('tbody');
this.$loadingTip = this.$('.loading-tip');
this.$emptyTip = this.$('.empty-tips');
2017-10-10 08:16:37 +00:00
return this;
2016-03-15 10:18:45 +00:00
},
show: function() {
$("#right-panel").html(this.$el);
2016-03-15 10:18:45 +00:00
this.devices.fetch({reset: true});
},
hide: function() {
this.$el.detach();
2016-03-15 10:18:45 +00:00
}
});
return DevicesView;
});