1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-31 14:42:10 +00:00

new admin devices page;

This commit is contained in:
lian
2016-04-23 18:07:09 +08:00
parent b3911c5081
commit bc2828969d
29 changed files with 2391 additions and 31 deletions

View File

@@ -9,21 +9,30 @@ define([
var DashboardView = Backbone.View.extend({
tagName: 'div',
id: "admin-dashboard",
template: _.template($("#sysinfo-tmpl").html()),
headerTemplate: _.template($("#sysinfo-header-tmpl").html()),
initialize: function() {
this.sysinfo = new SysInfo();
},
events: {
this.render();
},
render: function() {
this.$el.html(this.headerTemplate());
this.$loadingTip = this.$('.loading-tip');
this.$sysinfo = this.$('.sysinfo');
},
showSysinfo: function() {
this.$sysinfo.empty();
this.$loadingTip.show();
var _this = this;
this.sysinfo.fetch({
cache: false, // for IE
success: function(model, response, options) {
_this._showContent();
_this.reset();
},
error: function(model, response, options) {
var err_msg;
@@ -42,19 +51,17 @@ define([
},
hide: function() {
this.$el.detach();
},
show: function() {
this.render();
$("#right-panel").html(this.$el);
this.showSysinfo();
},
_showContent: function() {
console.log(this.sysinfo.toJSON());
this.$el.html(this.template(this.sysinfo.toJSON()));
$("#right-panel").html(this.$el);
return this;
reset: function() {
this.$loadingTip.hide();
this.$sysinfo.html(this.template(this.sysinfo.toJSON()));
}
});

View File

@@ -0,0 +1,150 @@
define([
'jquery',
'underscore',
'backbone',
'common',
'moment',
'sysadmin-app/views/device',
'sysadmin-app/collection/devices'
], function($, _, Backbone, Common, Moment, Device, DevicesCollection) {
'use strict';
var DevicesView = Backbone.View.extend({
id: 'admin-devices',
template: _.template($("#admin-devices-tmpl").html()),
initialize: function() {
this.deviceCollection = new DevicesCollection();
this.listenTo(this.deviceCollection, 'add', this.addOne);
this.listenTo(this.deviceCollection, 'reset', this.reset);
},
render: function() {
this.$el.html(this.template({'cur_tab': 'desktop', 'is_pro': app.pageOptions.is_pro}));
this.$table = this.$('table');
this.$tableBody = $('tbody', this.$table);
this.$loadingTip = this.$('.loading-tip');
this.$emptyTip = this.$('.empty-tips');
this.$jsPrevious = this.$('.js-previous');
this.$jsNext = this.$('.js-next');
},
events: {
'click #paginator .js-next': 'getNextPage',
'click #paginator .js-previous': 'getPreviousPage'
},
initPage: function() {
this.$table.hide();
this.$tableBody.empty();
this.$loadingTip.show();
this.$emptyTip.hide();
this.$jsNext.hide();
this.$jsPrevious.hide();
},
getNextPage: function() {
this.initPage();
if (this.deviceCollection.state.hasNextPage) {
var _this = this;
this.deviceCollection.getNextPage({
reset:true,
data: {'platform': 'desktop'},
});
}
return false;
},
getPreviousPage: function() {
this.initPage();
if (this.deviceCollection.state.currentPage > 1) {
var _this = this;
this.deviceCollection.getPreviousPage({
reset:true,
data: {'platform': 'desktop'},
});
}
return false;
},
hide: function() {
this.$el.detach();
},
show: function(option) {
this.option = option;
this.render();
$("#right-panel").html(this.$el);
this.showDesktopDevices();
},
showDesktopDevices: function() {
this.initPage();
var _this = this,
current_page = this.option.current_page || this.deviceCollection.state.currentPage;
this.deviceCollection.fetch({
data: {'platform': 'desktop', 'page': current_page},
cache: false, // for IE
reset: true,
error: function (collection, response, opts) {
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');
}
});
},
reset: function() {
var length = this.deviceCollection.length,
current_page = this.option.current_page || this.deviceCollection.state.currentPage;
this.$loadingTip.hide();
if (length > 0) {
this.deviceCollection.each(this.addOne, this);
this.$table.show();
} else {
this.$emptyTip.show();
}
this.renderPaginator();
app.router.navigate('desktop-devices/?page=' + current_page);
},
addOne: function(device) {
var view = new Device({model: device});
this.$tableBody.append(view.render().el);
},
renderPaginator: function() {
if (this.deviceCollection.state.hasNextPage) {
this.$jsNext.show();
} else {
this.$jsNext.hide();
}
var current_page = this.option.current_page || this.deviceCollection.state.currentPage;
if (current_page > 1 && this.deviceCollection.length > 0) {
this.$jsPrevious.show();
} else {
this.$jsPrevious.hide();
}
}
});
return DevicesView;
});

View File

@@ -0,0 +1,32 @@
define([
'jquery',
'underscore',
'backbone',
'common',
'moment',
'app/views/widgets/hl-item-view'
], function($, _, Backbone, Common, Moment, HLItemView) {
'use strict';
var DeviceErrorView = HLItemView.extend({
tagName: 'tr',
template: _.template($('#admin-device-error-tmpl').html()),
initialize: function() {
HLItemView.prototype.initialize.call(this);
},
render: function() {
var data = this.model.toJSON();
var last_accessed = Moment(data['last_accessed']);
data['time'] = last_accessed.format('LLLL');
data['time_from_now'] = Common.getRelativeTimeStr(last_accessed);
this.$el.html(this.template(data));
return this;
}
});
return DeviceErrorView;
});

View File

@@ -0,0 +1,90 @@
define([
'jquery',
'underscore',
'backbone',
'common',
'sysadmin-app/views/device-error',
'sysadmin-app/collection/device-errors'
], function($, _, Backbone, Common, DeviceError, DeviceErrorsCollection) {
'use strict';
var DeviceErrorsView = Backbone.View.extend({
id: 'admin-device-errors',
template: _.template($("#admin-device-errors-tmpl").html()),
initialize: function() {
this.deviceErrorsCollection = new DeviceErrorsCollection();
this.listenTo(this.deviceErrorsCollection, 'add', this.addOne);
this.listenTo(this.deviceErrorsCollection, 'reset', this.reset);
this.render();
},
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');
},
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;
this.deviceErrorsCollection.fetch({
cache: false, // for IE
reset: true,
success: function (collection, response, opts) {
},
error: function (collection, response, opts) {
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');
}
});
},
reset: function() {
this.$loadingTip.hide();
if (this.deviceErrorsCollection.length) {
this.deviceErrorsCollection.each(this.addOne, this);
this.$table.show();
} else {
this.$emptyTip.show();
}
},
addOne: function(deviceError) {
var view = new DeviceError({model: deviceError});
this.$tableBody.append(view.render().el);
}
});
return DeviceErrorsView;
});

View File

@@ -0,0 +1,58 @@
define([
'jquery',
'underscore',
'backbone',
'common',
'moment',
'app/views/widgets/hl-item-view'
], function($, _, Backbone, Common, Moment, HLItemView) {
'use strict';
var DeviceView = HLItemView.extend({
tagName: 'tr',
template: _.template($('#admin-device-item-tmpl').html()),
events: {
'click .unlink-device': 'unlinkDevice'
},
initialize: function() {
HLItemView.prototype.initialize.call(this);
},
render: function() {
var data = this.model.toJSON(),
last_accessed = Moment(data['last_accessed']);
data['time'] = last_accessed.format('LLLL');
data['time_from_now'] = Common.getRelativeTimeStr(last_accessed);
this.$el.html(this.template(data));
return this;
},
unlinkDevice: function() {
var _this = this,
device_name = this.model.get('device_name');
this.model.unlink({
success: function() {
_this.remove();
var msg = gettext("Successfully unlink %(name)s.")
.replace('%(name)s', Common.HTMLescape(device_name));
Common.feedback(msg, 'success');
},
error: function(xhr) {
Common.ajaxErrorHandler(xhr);
}
});
return false;
}
});
return DeviceView;
});

View File

@@ -0,0 +1,150 @@
define([
'jquery',
'underscore',
'backbone',
'common',
'moment',
'sysadmin-app/views/device',
'sysadmin-app/collection/devices'
], function($, _, Backbone, Common, Moment, Device, DevicesCollection) {
'use strict';
var DevicesView = Backbone.View.extend({
id: 'admin-devices',
template: _.template($("#admin-devices-tmpl").html()),
initialize: function() {
this.deviceCollection = new DevicesCollection();
this.listenTo(this.deviceCollection, 'add', this.addOne);
this.listenTo(this.deviceCollection, 'reset', this.reset);
},
render: function() {
this.$el.html(this.template({'cur_tab': 'mobile', 'is_pro': app.pageOptions.is_pro}));
this.$table = this.$('table');
this.$tableBody = $('tbody', this.$table);
this.$loadingTip = this.$('.loading-tip');
this.$emptyTip = this.$('.empty-tips');
this.$jsPrevious = this.$('.js-previous');
this.$jsNext = this.$('.js-next');
},
events: {
'click #paginator .js-next': 'getNextPage',
'click #paginator .js-previous': 'getPreviousPage'
},
initPage: function() {
this.$table.hide();
this.$tableBody.empty();
this.$loadingTip.show();
this.$emptyTip.hide();
this.$jsNext.hide();
this.$jsPrevious.hide();
},
getNextPage: function() {
this.initPage();
if (this.deviceCollection.state.hasNextPage) {
var _this = this;
this.deviceCollection.getNextPage({
reset:true,
data: {'platform': 'mobile'},
});
}
return false;
},
getPreviousPage: function() {
this.initPage();
if (this.deviceCollection.state.currentPage > 1) {
var _this = this;
this.deviceCollection.getPreviousPage({
reset:true,
data: {'platform': 'mobile'},
});
}
return false;
},
hide: function() {
this.$el.detach();
},
show: function(option) {
this.option = option;
this.render();
$("#right-panel").html(this.$el);
this.showMobileDevices();
},
showMobileDevices: function() {
this.initPage();
var _this = this,
current_page = this.option.current_page || this.deviceCollection.state.currentPage;
this.deviceCollection.fetch({
data: {'platform': 'mobile', 'page': current_page},
cache: false, // for IE
reset: true,
error: function (collection, response, opts) {
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');
}
});
},
reset: function() {
var length = this.deviceCollection.length,
current_page = this.option.current_page || this.deviceCollection.state.currentPage;
this.$loadingTip.hide();
if (length > 0) {
this.deviceCollection.each(this.addOne, this);
this.$table.show();
} else {
this.$emptyTip.show();
}
this.renderPaginator();
app.router.navigate('mobile-devices/?page=' + current_page);
},
addOne: function(device) {
var view = new Device({model: device});
this.$tableBody.append(view.render().el);
},
renderPaginator: function() {
if (this.deviceCollection.state.hasNextPage) {
this.$jsNext.show();
} else {
this.$jsNext.hide();
}
var current_page = this.option.current_page || this.deviceCollection.state.currentPage;
if (current_page > 1 && this.deviceCollection.length > 0) {
this.$jsPrevious.show();
} else {
this.$jsPrevious.hide();
}
}
});
return DevicesView;
});