1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-21 12:48:24 +00:00
seahub/static/scripts/sysadmin-app/views/dashboard.js

117 lines
3.5 KiB
JavaScript
Raw Normal View History

2016-03-16 05:30:00 +00:00
define([
'jquery',
'underscore',
'backbone',
2016-03-16 08:21:53 +00:00
'common',
'sysadmin-app/models/sysinfo'
2016-03-16 08:21:53 +00:00
], function($, _, Backbone, Common, SysInfo) {
2016-03-16 05:30:00 +00:00
'use strict';
var DashboardView = Backbone.View.extend({
2016-04-23 10:07:09 +00:00
id: "admin-dashboard",
2016-03-16 08:21:53 +00:00
template: _.template($("#sysinfo-tmpl").html()),
conTemplate: _.template($("#sysinfo-con-tmpl").html()),
2016-03-16 05:30:00 +00:00
initialize: function() {
2016-03-16 08:21:53 +00:00
this.sysinfo = new SysInfo();
2016-04-23 10:07:09 +00:00
this.render();
2016-03-16 05:30:00 +00:00
},
events: {
'change .license-file-upload-input': 'uploadLicenseFile'
},
uploadLicenseFile: function() {
var $input = this.$('.license-file-upload-input');
var file;
if ($input[0].files) {
file = $input[0].files[0];
} else {
return;
}
var input_name = $input.attr('name');
var fd = new FormData();
fd.append(input_name, file);
$.ajax({
url: Common.getUrl({'name': 'license'}),
type: 'POST',
data: fd,
processData: false,
contentType: false,
beforeSend: Common.prepareCSRFToken,
success: function(){
location.reload(true);
},
error: function(xhr) {
Common.ajaxErrorHandler(xhr);
}
});
},
2016-04-23 10:07:09 +00:00
render: function() {
this.$el.html(this.template());
2016-04-23 10:07:09 +00:00
this.$loadingTip = this.$('.loading-tip');
this.$sysinfo = this.$('.sysinfo');
2016-03-16 05:30:00 +00:00
},
2016-04-23 10:07:09 +00:00
showSysinfo: function() {
this.$sysinfo.empty();
this.$loadingTip.show();
2016-03-16 08:21:53 +00:00
var _this = this;
this.sysinfo.fetch({
2016-04-23 10:07:09 +00:00
cache: false, // for IE
2016-03-16 08:21:53 +00:00
success: function(model, response, options) {
2016-04-23 10:07:09 +00:00
_this.reset();
2016-03-16 08:21:53 +00:00
},
error: function(model, response, options) {
var err_msg;
if (response.responseText) {
if (response['status'] == 401 || response['status'] == 403) {
err_msg = gettext("Permission error");
} else {
err_msg = $.parseJSON(response.responseText).error_msg;
}
} else {
err_msg = gettext("Failed. Please check the network.");
}
Common.feedback(err_msg, 'error');
}
});
2016-03-16 05:30:00 +00:00
},
hide: function() {
2016-04-23 10:07:09 +00:00
this.$el.detach();
2016-03-16 05:30:00 +00:00
},
show: function() {
2016-04-23 10:07:09 +00:00
$("#right-panel").html(this.$el);
this.showSysinfo();
2016-03-16 08:21:53 +00:00
},
setLicenceUploadUI: function() {
var $btn = this.$('.license-file-upload-btn');
this.$('.license-file-upload').css({
'width': $btn.outerWidth()
});
this.$('.license-file-upload-input').css({
'height': $btn.outerHeight()
});
},
2016-04-23 10:07:09 +00:00
reset: function() {
this.$loadingTip.hide();
2017-01-07 02:12:17 +00:00
var json_data = this.sysinfo.toJSON();
json_data['formatted_storage'] = Common.quotaSizeFormat(json_data['total_storage'], 1)
this.$sysinfo.html(this.conTemplate(json_data));
this.setLicenceUploadUI();
2016-03-16 05:30:00 +00:00
}
});
return DashboardView;
});