mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-16 07:08:55 +00:00
new devices page
This commit is contained in:
17
static/scripts/app/collections/devices.js
Normal file
17
static/scripts/app/collections/devices.js
Normal file
@@ -0,0 +1,17 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'app/models/device'
|
||||
], function(_, Backbone, Common, Device) {
|
||||
'use strict';
|
||||
|
||||
var DevicesCollection = Backbone.Collection.extend({
|
||||
model: Device,
|
||||
url: function () {
|
||||
return Common.getUrl({name: 'devices'});
|
||||
}
|
||||
});
|
||||
|
||||
return DevicesCollection;
|
||||
});
|
10
static/scripts/app/models/device.js
Normal file
10
static/scripts/app/models/device.js
Normal file
@@ -0,0 +1,10 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone'
|
||||
], function(_, Backbone) {
|
||||
'use strict';
|
||||
|
||||
var Device = Backbone.Model.extend({});
|
||||
|
||||
return Device;
|
||||
});
|
@@ -29,6 +29,7 @@ define([
|
||||
'common/lib/:repo_id(/*path)': 'showCommonDir',
|
||||
'starred/': 'showStarredFile',
|
||||
'activities/': 'showActivities',
|
||||
'devices/': 'showDevices',
|
||||
// Default
|
||||
'*actions': 'showRepos'
|
||||
},
|
||||
@@ -96,6 +97,12 @@ define([
|
||||
this.sideNavView.setCurTab('starred');
|
||||
},
|
||||
|
||||
showDevices: function() {
|
||||
this.switchCurrentView(this.myHomeView);
|
||||
this.myHomeView.showDevices();
|
||||
this.sideNavView.setCurTab('devices');
|
||||
},
|
||||
|
||||
showActivities: function() {
|
||||
this.switchCurrentView(this.myHomeView);
|
||||
this.myHomeView.showActivities();
|
||||
|
104
static/scripts/app/views/device.js
Normal file
104
static/scripts/app/views/device.js
Normal file
@@ -0,0 +1,104 @@
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
], function($, _, Backbone, Common) {
|
||||
'use strict';
|
||||
|
||||
var DeviceView = Backbone.View.extend({
|
||||
tagName: 'tr',
|
||||
|
||||
template: _.template($('#device-item-tmpl').html()),
|
||||
|
||||
events: {
|
||||
'mouseenter': 'showAction',
|
||||
'mouseleave': 'hideAction',
|
||||
'click .unlink-device': 'unlinkDevice',
|
||||
'click .lib-num': 'showSyncedRepos'
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
},
|
||||
|
||||
render: function () {
|
||||
var data = this.model.toJSON();
|
||||
|
||||
if (typeof(data['synced_repos']) == 'undefined') {
|
||||
data['synced_repos'] = new Array();
|
||||
}
|
||||
|
||||
if (data['synced_repos']) {
|
||||
data['synced_repos_length'] = data['synced_repos'].length;
|
||||
} else {
|
||||
data['synced_repos_length'] = 0;
|
||||
}
|
||||
|
||||
// convert to human readable time
|
||||
var now = new Date(),
|
||||
last_accessed = Common.getMomentWithLocale(data['last_accessed']);
|
||||
|
||||
data['time'] = last_accessed.format('LLLL');
|
||||
if (last_accessed - now > 0) {
|
||||
data['time_from_now'] = gettext("Just now");
|
||||
} else {
|
||||
data['time_from_now'] = last_accessed.fromNow();
|
||||
}
|
||||
|
||||
this.$el.html(this.template(data));
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
showAction: function() {
|
||||
this.$el.addClass('hl');
|
||||
this.$el.find('.op-icon').removeClass('vh');
|
||||
},
|
||||
|
||||
hideAction: function() {
|
||||
this.$el.removeClass('hl');
|
||||
this.$el.find('.op-icon').addClass('vh');
|
||||
},
|
||||
|
||||
showSyncedRepos: function(e) {
|
||||
var $lib_num = $(e.currentTarget);
|
||||
var lib_list = $lib_num.next('.lib-list');
|
||||
var dir_icon = $lib_num.children('.dir-icon');
|
||||
|
||||
if (lib_list.length > 0) {
|
||||
lib_list.toggleClass('hide');
|
||||
if (lib_list.hasClass('hide')) {
|
||||
dir_icon.removeClass('icon-caret-up').addClass('icon-caret-down');
|
||||
} else {
|
||||
dir_icon.removeClass('icon-caret-down').addClass('icon-caret-up');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
unlinkDevice: function() {
|
||||
var _this = this,
|
||||
data = {
|
||||
'platform': this.model.get('platform'),
|
||||
'device_id': this.model.get('device_id')
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: Common.getUrl({name: 'devices'}),
|
||||
type: 'DELETE',
|
||||
dataType: 'json',
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
data: data,
|
||||
success: function() {
|
||||
_this.remove();
|
||||
Common.feedback(gettext("Success"), 'success');
|
||||
},
|
||||
error: function (xhr) {
|
||||
Common.ajaxErrorHandler(xhr);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return DeviceView;
|
||||
});
|
58
static/scripts/app/views/devices.js
Normal file
58
static/scripts/app/views/devices.js
Normal file
@@ -0,0 +1,58 @@
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'app/views/device',
|
||||
'app/collections/devices',
|
||||
], function($, _, Backbone, Common, Device, DevicesCollection) {
|
||||
'use strict';
|
||||
|
||||
var DevicesView = Backbone.View.extend({
|
||||
|
||||
el: $('#devices'),
|
||||
|
||||
initialize: function() {
|
||||
this.$table = this.$('table');
|
||||
this.$tableBody = this.$('tbody');
|
||||
this.$loadingTip = this.$('.loading-tip');
|
||||
this.$emptyTip = this.$('.empty-tips');
|
||||
|
||||
this.devices = new DevicesCollection();
|
||||
this.listenTo(this.devices, 'reset', this.reset);
|
||||
|
||||
},
|
||||
|
||||
addOne: function(device) {
|
||||
var view = new Device({model: device});
|
||||
this.$tableBody.append(view.render().el);
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
this.$tableBody.empty();
|
||||
this.$loadingTip.hide();
|
||||
this.devices.each(this.addOne, this);
|
||||
if (this.devices.length) {
|
||||
this.$emptyTip.hide();
|
||||
this.$table.show();
|
||||
} else {
|
||||
this.$emptyTip.show();
|
||||
this.$table.hide();
|
||||
}
|
||||
},
|
||||
|
||||
hide: function() {
|
||||
this.$el.hide();
|
||||
},
|
||||
|
||||
show: function() {
|
||||
this.$el.show();
|
||||
this.$table.hide();
|
||||
this.$loadingTip.show();
|
||||
this.devices.fetch({reset: true});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return DevicesView;
|
||||
});
|
@@ -6,9 +6,10 @@ define([
|
||||
'app/views/myhome-repos',
|
||||
'app/views/myhome-shared-repos',
|
||||
'app/views/starred-file',
|
||||
'app/views/devices',
|
||||
'app/views/activities'
|
||||
], function($, _, Backbone, Common, ReposView,
|
||||
SharedReposView, StarredFileView, ActivitiesView) {
|
||||
SharedReposView, StarredFileView, DevicesView, ActivitiesView) {
|
||||
'use strict';
|
||||
|
||||
var MyHomeView = Backbone.View.extend({
|
||||
@@ -18,6 +19,7 @@ define([
|
||||
this.reposView = new ReposView();
|
||||
this.sharedReposView = new SharedReposView();
|
||||
this.starredFileView = new StarredFileView();
|
||||
this.devicesView = new DevicesView();
|
||||
this.activitiesView = new ActivitiesView();
|
||||
|
||||
this.dirView = options.dirView;
|
||||
@@ -45,6 +47,12 @@ define([
|
||||
this.currentView = this.starredFileView;
|
||||
},
|
||||
|
||||
showDevices: function() {
|
||||
this.currentView.hide();
|
||||
this.devicesView.show();
|
||||
this.currentView = this.devicesView;
|
||||
},
|
||||
|
||||
showActivities: function() {
|
||||
this.currentView.hide();
|
||||
this.activitiesView.show();
|
||||
|
Reference in New Issue
Block a user