1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-30 08:53:49 +00:00
seahub/static/scripts/app/views/device.js

104 lines
3.4 KiB
JavaScript
Raw Normal View History

2016-03-15 10:18:45 +00:00
define([
'jquery',
'underscore',
'backbone',
'common',
2016-03-21 13:29:14 +00:00
'moment',
'app/views/widgets/hl-item-view',
'app/views/widgets/dropdown'
], function($, _, Backbone, Common, Moment, HLItemView, DropdownView) {
2016-03-15 10:18:45 +00:00
'use strict';
2016-03-21 13:29:14 +00:00
var DeviceView = HLItemView.extend({
2016-03-15 10:18:45 +00:00
tagName: 'tr',
template: _.template($('#device-item-tmpl').html()),
events: {
'click .unlink-device': 'unlinkDeviceWithConfirm'
2016-03-15 10:18:45 +00:00
},
initialize: function() {
2016-03-21 13:29:14 +00:00
HLItemView.prototype.initialize.call(this);
2016-03-15 10:18:45 +00:00
},
2016-03-21 13:29:14 +00:00
render: function() {
2016-03-15 10:18:45 +00:00
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;
}
2016-03-17 07:43:05 +00:00
var last_accessed = Moment(data['last_accessed']);
2016-03-15 10:18:45 +00:00
data['time'] = last_accessed.format('LLLL');
2016-03-17 07:43:05 +00:00
data['time_from_now'] = Common.getRelativeTimeStr(last_accessed);
2016-03-15 10:18:45 +00:00
this.$el.html(this.template(data));
2016-03-21 13:29:14 +00:00
new DropdownView({
2016-04-01 09:53:41 +00:00
el: this.$('.sf-dropdown'),
2016-03-31 13:05:46 +00:00
left: '-60px'
2016-03-21 13:29:14 +00:00
});
2016-03-16 07:47:33 +00:00
2016-03-21 13:29:14 +00:00
return this;
2016-03-15 10:18:45 +00:00
},
unlinkDeviceWithConfirm: function() {
var _this = this,
2016-05-27 08:01:07 +00:00
is_desktop_client = this.model.get('is_desktop_client'),
device_name = this.model.get('device_name');
2016-05-27 08:01:07 +00:00
if (is_desktop_client) {
var title = gettext('Unlink device');
var content = gettext('Are you sure you want to unlink this device?');
var extraOption = gettext('Delete files from this device the next time it comes online.');
var yesCallback = function (wipe_device) {
_this.model.unlink({
wipe_device: wipe_device,
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);
},
complete: function() {
$.modal.close();
}
});
return false;
};
Common.showConfirmWithExtraOption(title, content, extraOption, yesCallback);
} else {
_this.model.unlink({
2016-05-27 08:01:07 +00:00
wipe_device: true,
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;
2016-05-27 08:01:07 +00:00
}
}
2016-03-15 10:18:45 +00:00
});
return DeviceView;
});