1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-19 03:42:52 +00:00
seahub/static/scripts/sysadmin-app/views/device-errors.js

109 lines
3.4 KiB
JavaScript
Raw Normal View History

2016-04-23 10:07:09 +00:00
define([
'jquery',
'underscore',
'backbone',
'common',
'sysadmin-app/views/device-error',
'sysadmin-app/collection/device-errors'
2016-05-25 02:45:22 +00:00
], function($, _, Backbone, Common, DeviceError, DeviceErrorCollection) {
2016-04-23 10:07:09 +00:00
'use strict';
var DeviceErrorsView = Backbone.View.extend({
id: 'admin-device-errors',
2016-05-25 02:45:22 +00:00
template: _.template($("#device-errors-tmpl").html()),
2016-04-23 10:07:09 +00:00
initialize: function() {
2016-05-25 02:45:22 +00:00
this.deviceErrorCollection = new DeviceErrorCollection();
this.listenTo(this.deviceErrorCollection, 'add', this.addOne);
this.listenTo(this.deviceErrorCollection, 'reset', this.reset);
2016-04-23 10:07:09 +00:00
this.render();
},
2016-04-29 07:32:57 +00:00
events: {
'click #clean-device-errors': 'cleanDeviceErrors'
},
cleanDeviceErrors: function() {
var _this = this;
$.ajax({
url: Common.getUrl({name: 'admin-device-errors'}),
type: 'DELETE',
beforeSend: Common.prepareCSRFToken,
success: function() {
_this.$table.hide();
_this.$cleanBtn.hide();
_this.$emptyTip.show();
2016-05-25 02:45:22 +00:00
_this.deviceErrorCollection.reset();
2016-04-29 07:32:57 +00:00
var msg = gettext("Successfully clean all errors.");
Common.feedback(msg, 'success');
},
error: function(xhr) {
Common.ajaxErrorHandler(xhr);
}
});
return false;
},
2016-04-23 10:07:09 +00:00
render: function() {
this.$el.html(this.template({'cur_tab': 'errors'}));
this.$table = this.$('table');
this.$tableBody = $('tbody', this.$table);
this.$loadingTip = this.$('.loading-tip');
this.$emptyTip = this.$('.empty-tips');
2016-04-29 07:32:57 +00:00
this.$cleanBtn = this.$('#clean-device-errors');
2016-04-23 10:07:09 +00:00
},
hide: function() {
this.$el.detach();
},
show: function() {
$("#right-panel").html(this.$el);
this.showAdminDeviceError();
},
initPage: function() {
this.$table.hide();
this.$tableBody.empty();
this.$loadingTip.show();
this.$emptyTip.hide();
},
showAdminDeviceError: function() {
this.initPage();
var _this = this;
2016-05-25 02:45:22 +00:00
this.deviceErrorCollection.fetch({
2016-04-23 10:07:09 +00:00
cache: false, // for IE
reset: true,
success: function (collection, response, opts) {
},
error: function (collection, response, opts) {
2018-07-31 10:15:44 +00:00
var err_msg = Common.prepareCollectionFetchErrorMsg(collection, response, opts);
2016-04-23 10:07:09 +00:00
Common.feedback(err_msg, 'error');
}
});
},
reset: function() {
this.$loadingTip.hide();
2016-05-25 02:45:22 +00:00
if (this.deviceErrorCollection.length) {
this.deviceErrorCollection.each(this.addOne, this);
2016-04-23 10:07:09 +00:00
this.$table.show();
2016-04-29 07:32:57 +00:00
this.$cleanBtn.show();
2016-04-23 10:07:09 +00:00
} else {
this.$emptyTip.show();
}
},
addOne: function(deviceError) {
var view = new DeviceError({model: deviceError});
this.$tableBody.append(view.render().el);
}
});
return DeviceErrorsView;
});