2016-05-25 02:45:22 +00:00
|
|
|
define([
|
|
|
|
'jquery',
|
|
|
|
'underscore',
|
|
|
|
'backbone',
|
|
|
|
'common',
|
2016-05-27 08:42:40 +00:00
|
|
|
'sysadmin-app/models/system-repo'
|
|
|
|
], function($, _, Backbone, Common, SystemRepo) {
|
2016-05-25 02:45:22 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-05-27 08:42:40 +00:00
|
|
|
var SystemRepoView = Backbone.View.extend({
|
2016-05-25 02:45:22 +00:00
|
|
|
|
2016-05-27 08:42:40 +00:00
|
|
|
id: "system-library",
|
2016-05-25 02:45:22 +00:00
|
|
|
|
2016-06-07 09:32:01 +00:00
|
|
|
tabNavTemplate: _.template($("#libraries-tabnav-tmpl").html()),
|
2016-05-25 02:45:22 +00:00
|
|
|
template: _.template($("#system-library-tmpl").html()),
|
|
|
|
itemTemplate: _.template($("#system-library-item-tmpl").html()),
|
|
|
|
|
|
|
|
initialize: function() {
|
2016-05-27 08:42:40 +00:00
|
|
|
this.systemRepo = new SystemRepo();
|
2016-05-25 02:45:22 +00:00
|
|
|
this.render();
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2016-06-07 09:32:01 +00:00
|
|
|
var $tabnav = $(this.tabNavTemplate({'cur_tab': 'system'}));
|
|
|
|
this.$el.append($tabnav);
|
|
|
|
this.$el.append(this.template());
|
|
|
|
|
2016-05-25 02:45:22 +00:00
|
|
|
this.$table = this.$('table');
|
|
|
|
this.$tableBody = $('tbody', this.$table);
|
|
|
|
this.$loadingTip = this.$('.loading-tip');
|
|
|
|
},
|
|
|
|
|
|
|
|
initPage: function() {
|
|
|
|
this.$table.hide();
|
|
|
|
this.$tableBody.empty();
|
|
|
|
this.$loadingTip.show();
|
|
|
|
},
|
|
|
|
|
|
|
|
showSystemLibrary: function() {
|
|
|
|
this.initPage();
|
|
|
|
var _this = this;
|
|
|
|
|
2016-05-27 08:42:40 +00:00
|
|
|
this.systemRepo.fetch({
|
2016-05-25 02:45:22 +00:00
|
|
|
url: Common.getUrl({name: 'admin-system-library'}),
|
|
|
|
cache: false, // for IE
|
|
|
|
reset: true,
|
|
|
|
success: function(model, response, options) {
|
|
|
|
_this.reset();
|
|
|
|
},
|
|
|
|
error: function(model, response, options) {
|
|
|
|
var err_msg;
|
|
|
|
if (response.responseText) {
|
|
|
|
if (response['status'] == 401 || response['status'] == 403) {
|
|
|
|
err_msg = gettext("Permission error");
|
|
|
|
} else {
|
2018-02-05 08:47:56 +00:00
|
|
|
err_msg = JSON.parse(response.responseText).error_msg;
|
2016-05-25 02:45:22 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
err_msg = gettext("Failed. Please check the network.");
|
|
|
|
}
|
|
|
|
Common.feedback(err_msg, 'error');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
|
|
|
this.$el.detach();
|
|
|
|
},
|
|
|
|
|
|
|
|
show: function() {
|
|
|
|
$("#right-panel").html(this.$el);
|
|
|
|
this.showSystemLibrary();
|
|
|
|
},
|
|
|
|
|
|
|
|
reset: function() {
|
|
|
|
this.$loadingTip.hide();
|
2016-05-27 08:42:40 +00:00
|
|
|
this.$tableBody.html(this.itemTemplate(this.systemRepo.toJSON()));
|
2016-05-25 02:45:22 +00:00
|
|
|
this.$table.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2016-05-27 08:42:40 +00:00
|
|
|
return SystemRepoView;
|
2016-05-25 02:45:22 +00:00
|
|
|
});
|