mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-08 02:10:24 +00:00
new admin devices page;
This commit is contained in:
17
static/scripts/sysadmin-app/collection/device-errors.js
Normal file
17
static/scripts/sysadmin-app/collection/device-errors.js
Normal file
@@ -0,0 +1,17 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'sysadmin-app/models/device-error'
|
||||
], function(_, Backbone, Common, DeviceError) {
|
||||
'use strict';
|
||||
|
||||
var DeviceErrorCollection = Backbone.Collection.extend({
|
||||
model: DeviceError,
|
||||
url: function () {
|
||||
return Common.getUrl({name: 'admin-device-errors'});
|
||||
}
|
||||
});
|
||||
|
||||
return DeviceErrorCollection;
|
||||
});
|
25
static/scripts/sysadmin-app/collection/devices.js
Normal file
25
static/scripts/sysadmin-app/collection/devices.js
Normal file
@@ -0,0 +1,25 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'backbone.paginator',
|
||||
'common',
|
||||
'sysadmin-app/models/device'
|
||||
], function(_, Backbone, BackbonePaginator, Common, Device) {
|
||||
'use strict';
|
||||
|
||||
var DeviceCollection = Backbone.PageableCollection.extend({
|
||||
model: Device,
|
||||
state: {pageSize: 50,},
|
||||
parseState: function(data) {
|
||||
return {hasNextPage: data[0].has_next_page};
|
||||
},
|
||||
url: function () {
|
||||
return Common.getUrl({name: 'admin-devices'});
|
||||
},
|
||||
parseRecords: function(data) {
|
||||
return data[1];
|
||||
}
|
||||
});
|
||||
|
||||
return DeviceCollection;
|
||||
});
|
11
static/scripts/sysadmin-app/models/device-error.js
Normal file
11
static/scripts/sysadmin-app/models/device-error.js
Normal file
@@ -0,0 +1,11 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
], function(_, Backbone, Common) {
|
||||
'use strict';
|
||||
|
||||
var DeviceError = Backbone.Model.extend({});
|
||||
|
||||
return DeviceError;
|
||||
});
|
37
static/scripts/sysadmin-app/models/device.js
Normal file
37
static/scripts/sysadmin-app/models/device.js
Normal file
@@ -0,0 +1,37 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
], function(_, Backbone, Common) {
|
||||
'use strict';
|
||||
|
||||
var Device = Backbone.Model.extend({
|
||||
unlink: function(options) {
|
||||
var data = {
|
||||
'platform': this.get('platform'),
|
||||
'device_id': this.get('device_id'),
|
||||
'user': this.get('user')
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: Common.getUrl({name: 'admin-devices'}),
|
||||
type: 'DELETE',
|
||||
dataType: 'json',
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
data: data,
|
||||
success: function() {
|
||||
if (options.success) {
|
||||
options.success();
|
||||
}
|
||||
},
|
||||
error: function(xhr) {
|
||||
if (options.error) {
|
||||
options.error(xhr);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return Device;
|
||||
});
|
@@ -4,21 +4,30 @@ define([
|
||||
'backbone',
|
||||
'common',
|
||||
'sysadmin-app/views/side-nav',
|
||||
'sysadmin-app/views/dashboard'
|
||||
], function($, Backbone, Common, SideNavView, DashboardView) {
|
||||
'sysadmin-app/views/dashboard',
|
||||
'sysadmin-app/views/desktop-devices',
|
||||
'sysadmin-app/views/mobile-devices',
|
||||
'sysadmin-app/views/device-errors'
|
||||
], function($, Backbone, Common, SideNavView, DashboardView,
|
||||
DesktopDevicesView, MobileDevicesView, DeviceErrorsView) {
|
||||
"use strict";
|
||||
|
||||
var Router = Backbone.Router.extend({
|
||||
routes: {
|
||||
'': 'showDashboard',
|
||||
'dashboard/': 'showDashboard',
|
||||
'desktop-devices/': 'showDesktopDevices',
|
||||
'mobile-devices/': 'showMobileDevices',
|
||||
'device-errors/': 'showDeviceErrors',
|
||||
// Default
|
||||
'*actions': 'showDashboard'
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
$('#initial-loading-view').hide();
|
||||
|
||||
Common.prepareApiCsrf();
|
||||
Common.initAccountPopup();
|
||||
Common.initLocale();
|
||||
|
||||
this.sideNavView = new SideNavView();
|
||||
app.ui = {
|
||||
@@ -26,6 +35,10 @@ define([
|
||||
};
|
||||
|
||||
this.dashboardView = new DashboardView();
|
||||
this.desktopDevicesView = new DesktopDevicesView();
|
||||
this.mobileDevicesView = new MobileDevicesView();
|
||||
this.deviceErrorsView = new DeviceErrorsView();
|
||||
|
||||
this.currentView = this.dashboardView;
|
||||
|
||||
$('#info-bar .close').click(Common.closeTopNoticeBar);
|
||||
@@ -42,6 +55,38 @@ define([
|
||||
this.switchCurrentView(this.dashboardView);
|
||||
this.sideNavView.setCurTab('dashboard');
|
||||
this.dashboardView.show();
|
||||
},
|
||||
|
||||
showDesktopDevices: function(current_page) {
|
||||
var url = window.location.href;
|
||||
var page = url.match(/.*?page=(\d+)/);
|
||||
if (page) {
|
||||
current_page = page[1];
|
||||
} else {
|
||||
current_page = null;
|
||||
}
|
||||
this.switchCurrentView(this.desktopDevicesView);
|
||||
this.sideNavView.setCurTab('devices');
|
||||
this.desktopDevicesView.show({'current_page': current_page});
|
||||
},
|
||||
|
||||
showMobileDevices: function(current_page) {
|
||||
var url = window.location.href;
|
||||
var page = url.match(/.*?page=(\d+)/);
|
||||
if (page) {
|
||||
current_page = page[1];
|
||||
} else {
|
||||
current_page = null;
|
||||
}
|
||||
this.switchCurrentView(this.mobileDevicesView);
|
||||
this.sideNavView.setCurTab('devices');
|
||||
this.mobileDevicesView.show({'current_page': current_page});
|
||||
},
|
||||
|
||||
showDeviceErrors: function() {
|
||||
this.switchCurrentView(this.deviceErrorsView);
|
||||
this.sideNavView.setCurTab('devices');
|
||||
this.deviceErrorsView.show();
|
||||
}
|
||||
|
||||
});
|
||||
|
@@ -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()));
|
||||
}
|
||||
|
||||
});
|
||||
|
150
static/scripts/sysadmin-app/views/desktop-devices.js
Normal file
150
static/scripts/sysadmin-app/views/desktop-devices.js
Normal 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;
|
||||
|
||||
});
|
32
static/scripts/sysadmin-app/views/device-error.js
Normal file
32
static/scripts/sysadmin-app/views/device-error.js
Normal 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;
|
||||
});
|
90
static/scripts/sysadmin-app/views/device-errors.js
Normal file
90
static/scripts/sysadmin-app/views/device-errors.js
Normal 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;
|
||||
});
|
58
static/scripts/sysadmin-app/views/device.js
Normal file
58
static/scripts/sysadmin-app/views/device.js
Normal 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;
|
||||
});
|
150
static/scripts/sysadmin-app/views/mobile-devices.js
Normal file
150
static/scripts/sysadmin-app/views/mobile-devices.js
Normal 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;
|
||||
|
||||
});
|
Reference in New Issue
Block a user