mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-09 02:42:47 +00:00
new share admin page (#1233)
This commit is contained in:
20
static/scripts/app/collections/share-admin-folders.js
Normal file
20
static/scripts/app/collections/share-admin-folders.js
Normal file
@@ -0,0 +1,20 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'app/models/share-admin-folder'
|
||||
], function(_, Backbone, Common, ShareAdminFolder) {
|
||||
'use strict';
|
||||
|
||||
var ShareAdminFolderCollection = Backbone.Collection.extend({
|
||||
|
||||
model: ShareAdminFolder,
|
||||
|
||||
url: function() {
|
||||
return Common.getUrl({name: 'share_admin_folders'});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return ShareAdminFolderCollection;
|
||||
});
|
20
static/scripts/app/collections/share-admin-repos.js
Normal file
20
static/scripts/app/collections/share-admin-repos.js
Normal file
@@ -0,0 +1,20 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'app/models/share-admin-repo'
|
||||
], function(_, Backbone, Common, ShareAdminRepo) {
|
||||
'use strict';
|
||||
|
||||
var ShareAdminRepoCollection = Backbone.Collection.extend({
|
||||
|
||||
model: ShareAdminRepo,
|
||||
|
||||
url: function() {
|
||||
return Common.getUrl({name: 'share_admin_repos'});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return ShareAdminRepoCollection;
|
||||
});
|
20
static/scripts/app/collections/share-admin-share-links.js
Normal file
20
static/scripts/app/collections/share-admin-share-links.js
Normal file
@@ -0,0 +1,20 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'app/models/share-admin-share-link'
|
||||
], function(_, Backbone, Common, ShareAdminShareLink) {
|
||||
'use strict';
|
||||
|
||||
var ShareAdminShareLinkCollection = Backbone.Collection.extend({
|
||||
|
||||
model: ShareAdminShareLink,
|
||||
|
||||
url: function() {
|
||||
return Common.getUrl({name: 'share_admin_share_links'});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return ShareAdminShareLinkCollection;
|
||||
});
|
20
static/scripts/app/collections/share-admin-upload-links.js
Normal file
20
static/scripts/app/collections/share-admin-upload-links.js
Normal file
@@ -0,0 +1,20 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'app/models/share-admin-upload-link'
|
||||
], function(_, Backbone, Common, ShareAdminUploadLink) {
|
||||
'use strict';
|
||||
|
||||
var ShareAdminUploadLinkCollection = Backbone.Collection.extend({
|
||||
|
||||
model: ShareAdminUploadLink,
|
||||
|
||||
url: function() {
|
||||
return Common.getUrl({name: 'share_admin_upload_links'});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return ShareAdminUploadLinkCollection;
|
||||
});
|
35
static/scripts/app/models/share-admin-folder.js
Normal file
35
static/scripts/app/models/share-admin-folder.js
Normal file
@@ -0,0 +1,35 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common'
|
||||
], function(_, Backbone, Common) {
|
||||
'use strict';
|
||||
|
||||
var ShareAdminFolder = Backbone.Model.extend({
|
||||
|
||||
getWebUrl: function() {
|
||||
var path = this.get('path'),
|
||||
repo_id = this.get('repo_id');
|
||||
|
||||
return "#my-libs/lib/" + repo_id + Common.encodePath(path);
|
||||
},
|
||||
|
||||
getIconUrl: function(size) {
|
||||
var is_readonly = this.get('share_permission') == "r" ? true : false;
|
||||
return Common.getDirIconUrl(is_readonly, size);
|
||||
},
|
||||
|
||||
getIconTitle: function() {
|
||||
var icon_title = '';
|
||||
if (this.get('share_permission') == "rw") {
|
||||
icon_title = gettext("Read-Write");
|
||||
} else {
|
||||
icon_title = gettext("Read-Only");
|
||||
}
|
||||
return icon_title;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return ShareAdminFolder;
|
||||
});
|
33
static/scripts/app/models/share-admin-repo.js
Normal file
33
static/scripts/app/models/share-admin-repo.js
Normal file
@@ -0,0 +1,33 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common'
|
||||
], function(_, Backbone, Common) {
|
||||
'use strict';
|
||||
|
||||
var ShareAdminRepo = Backbone.Model.extend({
|
||||
|
||||
getWebUrl: function() {
|
||||
return "#common/lib/" + this.get('repo_id') + "/";
|
||||
},
|
||||
|
||||
getIconUrl: function(size) {
|
||||
var is_readonly = this.get('share_permission') == "r" ? true : false;
|
||||
return Common.getLibIconUrl(false, is_readonly, size);
|
||||
},
|
||||
|
||||
getIconTitle: function() {
|
||||
var icon_title = '';
|
||||
if (this.get('share_permission') == "rw") {
|
||||
icon_title = gettext("Read-Write");
|
||||
} else {
|
||||
icon_title = gettext("Read-Only");
|
||||
}
|
||||
|
||||
return icon_title;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return ShareAdminRepo;
|
||||
});
|
45
static/scripts/app/models/share-admin-share-link.js
Normal file
45
static/scripts/app/models/share-admin-share-link.js
Normal file
@@ -0,0 +1,45 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'moment'
|
||||
], function(_, Backbone, Common, Moment) {
|
||||
'use strict';
|
||||
|
||||
var ShareAdminShareLink = Backbone.Model.extend({
|
||||
parse: function(response) {
|
||||
var attrs = _.clone(response),
|
||||
expire_date = response.expire_date;
|
||||
|
||||
if (expire_date) {
|
||||
attrs.expire_date_timestamp = Moment(expire_date).format('X');
|
||||
} else {
|
||||
attrs.expire_date_timestamp = 0;
|
||||
}
|
||||
|
||||
return attrs;
|
||||
},
|
||||
|
||||
getIconUrl: function(size) {
|
||||
if (this.get('is_dir')) {
|
||||
return Common.getDirIconUrl(false, size);
|
||||
} else {
|
||||
return Common.getFileIconUrl(this.get('obj_name'), size);
|
||||
}
|
||||
},
|
||||
|
||||
getWebUrl: function() {
|
||||
var repo_id = this.get('repo_id');
|
||||
var dirent_path = this.get('path');
|
||||
|
||||
if (this.get('is_dir')) {
|
||||
return "#common/lib/" + repo_id + Common.encodePath(dirent_path);
|
||||
} else {
|
||||
return app.config.siteRoot + "lib/" + repo_id + "/file" + Common.encodePath(dirent_path);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return ShareAdminShareLink;
|
||||
});
|
21
static/scripts/app/models/share-admin-upload-link.js
Normal file
21
static/scripts/app/models/share-admin-upload-link.js
Normal file
@@ -0,0 +1,21 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common'
|
||||
], function(_, Backbone, Common) {
|
||||
'use strict';
|
||||
|
||||
var ShareAdminUploadLink = Backbone.Model.extend({
|
||||
getIconUrl: function(size) {
|
||||
return Common.getDirIconUrl(false , size);
|
||||
},
|
||||
|
||||
getWebUrl: function() {
|
||||
var repo_id = this.get('repo_id');
|
||||
var dirent_path = this.get('path');
|
||||
return "#common/lib/" + repo_id + Common.encodePath(dirent_path);
|
||||
}
|
||||
});
|
||||
|
||||
return ShareAdminUploadLink;
|
||||
});
|
@@ -11,14 +11,19 @@ define([
|
||||
'app/views/organization',
|
||||
'app/views/dir',
|
||||
'app/views/starred-file',
|
||||
'app/views/devices',
|
||||
'app/views/activities',
|
||||
'app/views/devices',
|
||||
'app/views/share-admin-repos',
|
||||
'app/views/share-admin-folders',
|
||||
'app/views/share-admin-share-links',
|
||||
'app/views/share-admin-upload-links',
|
||||
'app/views/notifications',
|
||||
'app/views/account'
|
||||
], function($, Backbone, Common, SideNavView, MyReposView,
|
||||
SharedReposView, GroupsView, GroupView,
|
||||
OrgView, DirView, StarredFileView, DevicesView, ActivitiesView,
|
||||
NotificationsView, AccountView) {
|
||||
SharedReposView, GroupsView, GroupView, OrgView, DirView,
|
||||
StarredFileView, ActivitiesView, DevicesView, ShareAdminReposView,
|
||||
ShareAdminFoldersView, ShareAdminShareLinksView,
|
||||
ShareAdminUploadLinksView, NotificationsView, AccountView) {
|
||||
"use strict";
|
||||
|
||||
var Router = Backbone.Router.extend({
|
||||
@@ -38,6 +43,10 @@ define([
|
||||
'starred/': 'showStarredFile',
|
||||
'activities/': 'showActivities',
|
||||
'devices/': 'showDevices',
|
||||
'share-admin-libs/': 'showShareAdminRepos',
|
||||
'share-admin-folders/': 'showShareAdminFolders',
|
||||
'share-admin-share-links/': 'showShareAdminShareLinks',
|
||||
'share-admin-upload-links/': 'showShareAdminUploadLinks',
|
||||
// Default
|
||||
'*actions': 'showRepos'
|
||||
},
|
||||
@@ -62,6 +71,10 @@ define([
|
||||
this.starredFileView = new StarredFileView();
|
||||
this.devicesView = new DevicesView();
|
||||
this.activitiesView = new ActivitiesView();
|
||||
this.shareAdminReposView = new ShareAdminReposView();
|
||||
this.shareAdminFoldersView = new ShareAdminFoldersView();
|
||||
this.shareAdminShareLinksView = new ShareAdminShareLinksView();
|
||||
this.shareAdminUploadLinksView = new ShareAdminUploadLinksView();
|
||||
|
||||
app.ui.notificationsView = this.notificationsView = new NotificationsView();
|
||||
app.ui.accountView = this.accountView = new AccountView();
|
||||
@@ -204,16 +217,40 @@ define([
|
||||
this.sideNavView.setCurTab('starred');
|
||||
},
|
||||
|
||||
showActivities: function() {
|
||||
this.switchCurrentView(this.activitiesView);
|
||||
this.activitiesView.show();
|
||||
this.sideNavView.setCurTab('activities');
|
||||
},
|
||||
|
||||
showDevices: function() {
|
||||
this.switchCurrentView(this.devicesView);
|
||||
this.devicesView.show();
|
||||
this.sideNavView.setCurTab('devices');
|
||||
},
|
||||
|
||||
showActivities: function() {
|
||||
this.switchCurrentView(this.activitiesView);
|
||||
this.activitiesView.show();
|
||||
this.sideNavView.setCurTab('activities');
|
||||
showShareAdminRepos: function() {
|
||||
this.switchCurrentView(this.shareAdminReposView);
|
||||
this.shareAdminReposView.show();
|
||||
this.sideNavView.setCurTab('share-admin-repos');
|
||||
},
|
||||
|
||||
showShareAdminFolders: function() {
|
||||
this.switchCurrentView(this.shareAdminFoldersView);
|
||||
this.shareAdminFoldersView.show();
|
||||
this.sideNavView.setCurTab('share-admin-folders');
|
||||
},
|
||||
|
||||
showShareAdminShareLinks: function() {
|
||||
this.switchCurrentView(this.shareAdminShareLinksView);
|
||||
this.shareAdminShareLinksView.show();
|
||||
this.sideNavView.setCurTab('share-admin-links');
|
||||
},
|
||||
|
||||
showShareAdminUploadLinks: function() {
|
||||
this.switchCurrentView(this.shareAdminUploadLinksView);
|
||||
this.shareAdminUploadLinksView.show();
|
||||
this.sideNavView.setCurTab('share-admin-links');
|
||||
}
|
||||
|
||||
});
|
||||
|
@@ -170,19 +170,22 @@ define([
|
||||
sortByName: function() {
|
||||
this.$('.by-time .sort-icon').hide();
|
||||
var repos = this.repos;
|
||||
var el = this.$('.by-name .sort-icon');
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
||||
if (el.hasClass('icon-caret-up')) {
|
||||
var $el = this.$('.by-name .sort-icon');
|
||||
if ($el.hasClass('icon-caret-up')) {
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
||||
return -result;
|
||||
} else {
|
||||
};
|
||||
} else {
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
||||
return result;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
repos.sort();
|
||||
this.$tableBody.empty();
|
||||
repos.each(this.addOne, this);
|
||||
el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
repos.comparator = null;
|
||||
return false;
|
||||
},
|
||||
@@ -190,18 +193,20 @@ define([
|
||||
sortByTime: function() {
|
||||
this.$('.by-name .sort-icon').hide();
|
||||
var repos = this.repos;
|
||||
var el = this.$('.by-time .sort-icon');
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
if (el.hasClass('icon-caret-down')) {
|
||||
var $el = this.$('.by-time .sort-icon');
|
||||
if ($el.hasClass('icon-caret-down')) {
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
return a.get('mtime') < b.get('mtime') ? 1 : -1;
|
||||
} else {
|
||||
};
|
||||
} else {
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
return a.get('mtime') < b.get('mtime') ? -1 : 1;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
repos.sort();
|
||||
this.$tableBody.empty();
|
||||
repos.each(this.addOne, this);
|
||||
el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
repos.comparator = null;
|
||||
return false;
|
||||
},
|
||||
|
@@ -117,19 +117,22 @@ define([
|
||||
sortByName: function() {
|
||||
$('.by-time .sort-icon').hide();
|
||||
var repos = this.repos;
|
||||
var el = $('.by-name .sort-icon', this.$table);
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
||||
if (el.hasClass('icon-caret-up')) {
|
||||
var $el = $('.by-name .sort-icon', this.$table);
|
||||
if ($el.hasClass('icon-caret-up')) {
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
||||
return -result;
|
||||
} else {
|
||||
};
|
||||
} else {
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
||||
return result;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
repos.sort();
|
||||
this.$tableBody.empty();
|
||||
repos.each(this.addOne, this);
|
||||
el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
repos.comparator = null;
|
||||
return false;
|
||||
},
|
||||
@@ -137,18 +140,20 @@ define([
|
||||
sortByTime: function() {
|
||||
$('.by-name .sort-icon').hide();
|
||||
var repos = this.repos;
|
||||
var el = $('.by-time .sort-icon', this.$table);
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
if (el.hasClass('icon-caret-down')) {
|
||||
var $el = $('.by-time .sort-icon', this.$table);
|
||||
if ($el.hasClass('icon-caret-down')) {
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
return a.get('mtime') < b.get('mtime') ? 1 : -1;
|
||||
} else {
|
||||
};
|
||||
} else {
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
return a.get('mtime') < b.get('mtime') ? -1 : 1;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
repos.sort();
|
||||
this.$tableBody.empty();
|
||||
repos.each(this.addOne, this);
|
||||
el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
repos.comparator = null;
|
||||
return false;
|
||||
}
|
||||
|
@@ -104,19 +104,22 @@ define([
|
||||
sortByName: function() {
|
||||
$('.by-time .sort-icon', this.$table).hide();
|
||||
var repos = this.repos;
|
||||
var el = $('.by-name .sort-icon', this.$table);
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
||||
if (el.hasClass('icon-caret-up')) {
|
||||
var $el = $('.by-name .sort-icon', this.$table);
|
||||
if ($el.hasClass('icon-caret-up')) {
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
||||
return -result;
|
||||
} else {
|
||||
};
|
||||
} else {
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
||||
return result;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
repos.sort();
|
||||
this.$tableBody.empty();
|
||||
repos.each(this.addOne, this);
|
||||
el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
repos.comparator = null;
|
||||
return false;
|
||||
},
|
||||
@@ -124,18 +127,20 @@ define([
|
||||
sortByTime: function() {
|
||||
$('.by-name .sort-icon', this.$table).hide();
|
||||
var repos = this.repos;
|
||||
var el = $('.by-time .sort-icon', this.$table);
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
if (el.hasClass('icon-caret-down')) {
|
||||
var $el = $('.by-time .sort-icon', this.$table);
|
||||
if ($el.hasClass('icon-caret-down')) {
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
return a.get('mtime') < b.get('mtime') ? 1 : -1;
|
||||
} else {
|
||||
};
|
||||
} else {
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
return a.get('mtime') < b.get('mtime') ? -1 : 1;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
repos.sort();
|
||||
this.$tableBody.empty();
|
||||
repos.each(this.addOne, this);
|
||||
el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
repos.comparator = null;
|
||||
return false;
|
||||
}
|
||||
|
@@ -125,19 +125,22 @@ define([
|
||||
sortByName: function() {
|
||||
$('.by-time .sort-icon', this.$table).hide();
|
||||
var repos = this.repos;
|
||||
var el = $('.by-name .sort-icon', this.$table);
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
||||
if (el.hasClass('icon-caret-up')) {
|
||||
var $el = $('.by-name .sort-icon', this.$table);
|
||||
if ($el.hasClass('icon-caret-up')) {
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
||||
return -result;
|
||||
} else {
|
||||
};
|
||||
} else {
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
||||
return result;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
repos.sort();
|
||||
this.$tableBody.empty();
|
||||
repos.each(this.addOne, this);
|
||||
el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
repos.comparator = null;
|
||||
return false;
|
||||
},
|
||||
@@ -145,18 +148,20 @@ define([
|
||||
sortByTime: function() {
|
||||
$('.by-name .sort-icon', this.$table).hide();
|
||||
var repos = this.repos;
|
||||
var el = $('.by-time .sort-icon', this.$table);
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
if (el.hasClass('icon-caret-down')) {
|
||||
var $el = $('.by-time .sort-icon', this.$table);
|
||||
if ($el.hasClass('icon-caret-down')) {
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
return a.get('mtime') < b.get('mtime') ? 1 : -1;
|
||||
} else {
|
||||
};
|
||||
} else {
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
return a.get('mtime') < b.get('mtime') ? -1 : 1;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
repos.sort();
|
||||
this.$tableBody.empty();
|
||||
repos.each(this.addOne, this);
|
||||
el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
repos.comparator = null;
|
||||
return false;
|
||||
}
|
||||
|
121
static/scripts/app/views/share-admin-folder.js
Normal file
121
static/scripts/app/views/share-admin-folder.js
Normal file
@@ -0,0 +1,121 @@
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'app/views/widgets/hl-item-view'
|
||||
], function($, _, Backbone, Common, HLItemView) {
|
||||
'use strict';
|
||||
|
||||
var ShareAdminFolderView = HLItemView.extend({
|
||||
|
||||
tagName: 'tr',
|
||||
|
||||
template: _.template($('#share-admin-folder-tmpl').html()),
|
||||
|
||||
events: {
|
||||
'click .perm-edit-icon': 'showPermSelect',
|
||||
'change .perm-select': 'updatePermission',
|
||||
'click .unshare': 'removeShare'
|
||||
},
|
||||
|
||||
initialize: function(option) {
|
||||
HLItemView.prototype.initialize.call(this);
|
||||
this.listenTo(this.model, "change", this.render);
|
||||
},
|
||||
|
||||
showPermSelect: function() {
|
||||
this.$el.closest('table')
|
||||
.find('.perm-select').hide().end()
|
||||
.find('.cur-perm, .perm-edit-icon').show();
|
||||
|
||||
this.$('.cur-perm, .perm-edit-icon').hide();
|
||||
this.$('.perm-select').show();
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
updatePermission: function() {
|
||||
var _this = this;
|
||||
var share_type = this.model.get('share_type');
|
||||
var perm = this.$('.perm-select').val();
|
||||
var url = Common.getUrl({
|
||||
name: 'dir_shared_items',
|
||||
repo_id: this.model.get('repo_id')
|
||||
}) + '?p=' + encodeURIComponent(this.model.get('path'));
|
||||
|
||||
if (share_type == 'personal') {
|
||||
url += '&share_type=user&username=' + encodeURIComponent(this.model.get('user_email'));
|
||||
} else if (share_type == 'group') {
|
||||
url += '&share_type=group&group_id=' + this.model.get('group_id');
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
data: {
|
||||
'permission': perm
|
||||
},
|
||||
success: function() {
|
||||
_this.model.set({'share_permission': perm});
|
||||
Common.feedback(gettext("Successfully modified permission"), 'success');
|
||||
},
|
||||
error: function(xhr) {
|
||||
Common.ajaxErrorHandler(xhr);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
removeShare: function() {
|
||||
var _this = this;
|
||||
var share_type = this.model.get('share_type');
|
||||
var url = Common.getUrl({
|
||||
name: 'dir_shared_items',
|
||||
repo_id: this.model.get('repo_id')
|
||||
}) + '?p=' + Common.encodePath(this.model.get('path'));
|
||||
|
||||
if (share_type == 'personal') {
|
||||
url += '&share_type=user&username=' + Common.encodePath(this.model.get('user_email'));
|
||||
} else if (share_type == 'group') {
|
||||
url += '&share_type=group&group_id=' + this.model.get('group_id');
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'DELETE',
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
success: function() {
|
||||
_this.remove();
|
||||
Common.feedback(gettext("Successfully deleted 1 item"), 'success');
|
||||
},
|
||||
error: function (xhr) {
|
||||
Common.ajaxErrorHandler(xhr);
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var obj = this.model.toJSON(),
|
||||
icon_size = Common.isHiDPI() ? 96 : 24,
|
||||
icon_url = this.model.getIconUrl(icon_size);
|
||||
|
||||
_.extend(obj, {
|
||||
'icon_url': icon_url,
|
||||
'icon_title': this.model.getIconTitle(),
|
||||
'url': this.model.getWebUrl(),
|
||||
'name': this.model.get('folder_name')
|
||||
});
|
||||
|
||||
this.$el.html(this.template(obj));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return ShareAdminFolderView;
|
||||
});
|
136
static/scripts/app/views/share-admin-folders.js
Normal file
136
static/scripts/app/views/share-admin-folders.js
Normal file
@@ -0,0 +1,136 @@
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'app/collections/share-admin-folders',
|
||||
'app/views/share-admin-folder'
|
||||
], function($, _, Backbone, Common, ShareAdminFolderCollection, ShareAdminFolderView) {
|
||||
'use strict';
|
||||
|
||||
var ShareAdminFoldersView = Backbone.View.extend({
|
||||
|
||||
id: 'share-admin-folders',
|
||||
|
||||
template: _.template($('#share-admin-folders-tmpl').html()),
|
||||
|
||||
initialize: function() {
|
||||
this.folders = new ShareAdminFolderCollection();
|
||||
this.listenTo(this.folders, 'add', this.addOne);
|
||||
this.listenTo(this.folders, 'reset', this.reset);
|
||||
this.render();
|
||||
|
||||
var _this = this;
|
||||
$(document).click(function(e) {
|
||||
var target = e.target || event.srcElement;
|
||||
var $select = _this.$('.perm-select:visible');
|
||||
if ($select.length && !$select.is(target)) {
|
||||
$select.hide();
|
||||
$select.closest('tr').find('.cur-perm, .perm-edit-icon').show();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
events: {
|
||||
'click .by-name': 'sortByName'
|
||||
},
|
||||
|
||||
sortByName: function() {
|
||||
var folders = this.folders;
|
||||
var $el = this.$sortIcon;
|
||||
if ($el.hasClass('icon-caret-up')) {
|
||||
folders.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('folder_name'), b.get('folder_name'));
|
||||
return -result;
|
||||
};
|
||||
} else {
|
||||
folders.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('folder_name'), b.get('folder_name'));
|
||||
return result;
|
||||
};
|
||||
}
|
||||
folders.sort();
|
||||
this.$tableBody.empty();
|
||||
folders.each(this.addOne, this);
|
||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
folders.comparator = null;
|
||||
return false;
|
||||
},
|
||||
|
||||
render: function() {
|
||||
this.$el.html(this.template());
|
||||
this.$table = this.$('table');
|
||||
this.$sortIcon = $('.by-name .sort-icon', this.$table);
|
||||
this.$tableBody = $('tbody', this.$table);
|
||||
this.$loadingTip = this.$('.loading-tip');
|
||||
this.$emptyTip = this.$('.empty-tips');
|
||||
},
|
||||
|
||||
hide: function() {
|
||||
this.$el.detach();
|
||||
this.attached = false;
|
||||
},
|
||||
|
||||
show: function() {
|
||||
if (!this.attached) {
|
||||
this.attached = true;
|
||||
$("#right-panel").html(this.$el);
|
||||
}
|
||||
this.showContent();
|
||||
},
|
||||
|
||||
showContent: function() {
|
||||
this.initPage();
|
||||
this.folders.fetch({
|
||||
cache: false,
|
||||
reset: true,
|
||||
error: function(collection, response, opts) {
|
||||
_this.$loadingTip.hide();
|
||||
var $error = _this.$('.error');
|
||||
var err_msg;
|
||||
if (response.responseText) {
|
||||
if (response['status'] == 401 || response['status'] == 403) {
|
||||
err_msg = gettext("Permission error");
|
||||
} else {
|
||||
err_msg = gettext("Error");
|
||||
}
|
||||
} else {
|
||||
err_msg = gettext('Please check the network.');
|
||||
}
|
||||
$error.html(err_msg).show();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
initPage: function() {
|
||||
this.$table.hide();
|
||||
this.$sortIcon.attr('class', 'sort-icon icon-caret-down').hide();
|
||||
this.$tableBody.empty();
|
||||
this.$loadingTip.show();
|
||||
this.$emptyTip.hide();
|
||||
this.$('.error').hide();
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
this.$('.error').hide();
|
||||
this.$loadingTip.hide();
|
||||
if (this.folders.length) {
|
||||
this.$emptyTip.hide();
|
||||
this.$tableBody.empty();
|
||||
this.folders.each(this.addOne, this);
|
||||
this.$table.show();
|
||||
} else {
|
||||
this.$table.hide();
|
||||
this.$emptyTip.show();
|
||||
}
|
||||
},
|
||||
|
||||
addOne: function(folder) {
|
||||
var view = new ShareAdminFolderView({model: folder});
|
||||
this.$tableBody.append(view.render().el);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return ShareAdminFoldersView;
|
||||
});
|
124
static/scripts/app/views/share-admin-repo.js
Normal file
124
static/scripts/app/views/share-admin-repo.js
Normal file
@@ -0,0 +1,124 @@
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'app/views/widgets/hl-item-view'
|
||||
], function($, _, Backbone, Common, HLItemView) {
|
||||
'use strict';
|
||||
|
||||
var ShareAdminRepoView = HLItemView.extend({
|
||||
|
||||
tagName: 'tr',
|
||||
|
||||
template: _.template($('#share-admin-folder-tmpl').html()),
|
||||
|
||||
events: {
|
||||
'click .perm-edit-icon': 'showPermSelect',
|
||||
'change .perm-select': 'updatePermission',
|
||||
'click .unshare': 'removeShare'
|
||||
},
|
||||
|
||||
initialize: function(option) {
|
||||
HLItemView.prototype.initialize.call(this);
|
||||
this.listenTo(this.model, "change", this.render);
|
||||
},
|
||||
|
||||
showPermSelect: function() {
|
||||
this.$el.closest('table')
|
||||
.find('.perm-select').hide().end()
|
||||
.find('.cur-perm, .perm-edit-icon').show();
|
||||
|
||||
this.$('.cur-perm, .perm-edit-icon').hide();
|
||||
this.$('.perm-select').show();
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
updatePermission: function() {
|
||||
var _this = this;
|
||||
var url = Common.getUrl({
|
||||
'name': 'share_admin_repo',
|
||||
'repo_id': this.model.get('repo_id')
|
||||
});
|
||||
var share_type = this.model.get('share_type');
|
||||
var perm = this.$('.perm-select').val();
|
||||
var data = {
|
||||
'share_type': share_type,
|
||||
'permission': perm
|
||||
};
|
||||
if (share_type == 'personal') {
|
||||
data['user'] = this.model.get('user_email');
|
||||
} else if (share_type == 'group') {
|
||||
data['group_id'] = this.model.get('group_id');
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: 'PUT',
|
||||
cache: false,
|
||||
dataType: 'json',
|
||||
data: data,
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
success: function() {
|
||||
_this.model.set({'share_permission': perm});
|
||||
Common.feedback(gettext("Successfully modified permission"), 'success');
|
||||
},
|
||||
error: function(xhr) {
|
||||
Common.ajaxErrorHandler(xhr);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
removeShare: function() {
|
||||
var _this = this;
|
||||
var share_type = this.model.get('share_type');
|
||||
var url = Common.getUrl({
|
||||
'name': 'share_admin_repo',
|
||||
'repo_id': this.model.get('repo_id')
|
||||
});
|
||||
|
||||
if (share_type == 'personal') {
|
||||
url += '?share_type=personal&user=' + encodeURIComponent(this.model.get('user_email'));
|
||||
} else if (share_type == 'group') {
|
||||
url += '?share_type=group&group_id=' + this.model.get('group_id');
|
||||
} else if (share_type == 'public') {
|
||||
url += '?share_type=public';
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'DELETE',
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
success: function() {
|
||||
_this.remove();
|
||||
Common.feedback(gettext("Successfully deleted 1 item"), 'success');
|
||||
},
|
||||
error: function(xhr) {
|
||||
Common.ajaxErrorHandler(xhr);
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var obj = this.model.toJSON(),
|
||||
icon_size = Common.isHiDPI() ? 96 : 24,
|
||||
icon_url = this.model.getIconUrl(icon_size);
|
||||
|
||||
_.extend(obj, {
|
||||
'icon_url': icon_url,
|
||||
'icon_title': this.model.getIconTitle(),
|
||||
'url': this.model.getWebUrl(),
|
||||
'name': this.model.get('repo_name')
|
||||
});
|
||||
|
||||
this.$el.html(this.template(obj));
|
||||
return this;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return ShareAdminRepoView;
|
||||
});
|
138
static/scripts/app/views/share-admin-repos.js
Normal file
138
static/scripts/app/views/share-admin-repos.js
Normal file
@@ -0,0 +1,138 @@
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'app/collections/share-admin-repos',
|
||||
'app/views/share-admin-repo'
|
||||
], function($, _, Backbone, Common, ShareAdminRepoCollection, ShareAdminRepoView) {
|
||||
'use strict';
|
||||
|
||||
var ShareAdminReposView = Backbone.View.extend({
|
||||
|
||||
id: 'share-admin-repos',
|
||||
|
||||
template: _.template($('#share-admin-repos-tmpl').html()),
|
||||
|
||||
initialize: function() {
|
||||
this.repos = new ShareAdminRepoCollection();
|
||||
this.listenTo(this.repos, 'add', this.addOne);
|
||||
this.listenTo(this.repos, 'reset', this.reset);
|
||||
this.render();
|
||||
|
||||
var _this = this;
|
||||
$(document).click(function(e) {
|
||||
var target = e.target || event.srcElement;
|
||||
var $select = _this.$('.perm-select:visible');
|
||||
if ($select.length && !$select.is(target)) {
|
||||
$select.hide();
|
||||
$select.closest('tr').find('.cur-perm, .perm-edit-icon').show();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
events: {
|
||||
'click .by-name': 'sortByName'
|
||||
},
|
||||
|
||||
sortByName: function() {
|
||||
var repos = this.repos;
|
||||
var $el = this.$sortIcon;
|
||||
if ($el.hasClass('icon-caret-up')) {
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('repo_name'), b.get('repo_name'));
|
||||
return -result;
|
||||
};
|
||||
} else {
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('repo_name'), b.get('repo_name'));
|
||||
return result;
|
||||
};
|
||||
}
|
||||
repos.sort();
|
||||
this.$tableBody.empty();
|
||||
repos.each(this.addOne, this);
|
||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
repos.comparator = null;
|
||||
return false;
|
||||
},
|
||||
|
||||
render: function() {
|
||||
this.$el.html(this.template());
|
||||
this.$table = this.$('table');
|
||||
this.$sortIcon = $('.by-name .sort-icon', this.$table);
|
||||
this.$tableBody = $('tbody', this.$table);
|
||||
this.$loadingTip = this.$('.loading-tip');
|
||||
this.$emptyTip = this.$('.empty-tips');
|
||||
|
||||
},
|
||||
|
||||
hide: function() {
|
||||
this.$el.detach();
|
||||
this.attached = false;
|
||||
},
|
||||
|
||||
show: function() {
|
||||
if (!this.attached) {
|
||||
this.attached = true;
|
||||
$("#right-panel").html(this.$el);
|
||||
}
|
||||
this.showContent();
|
||||
},
|
||||
|
||||
showContent: function() {
|
||||
var _this = this;
|
||||
this.initPage();
|
||||
this.repos.fetch({
|
||||
cache: false,
|
||||
reset: true,
|
||||
error: function(collection, response, opts) {
|
||||
_this.$loadingTip.hide();
|
||||
var $error = _this.$('.error');
|
||||
var err_msg;
|
||||
if (response.responseText) {
|
||||
if (response['status'] == 401 || response['status'] == 403) {
|
||||
err_msg = gettext("Permission error");
|
||||
} else {
|
||||
err_msg = gettext("Error");
|
||||
}
|
||||
} else {
|
||||
err_msg = gettext('Please check the network.');
|
||||
}
|
||||
$error.html(err_msg).show();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
initPage: function() {
|
||||
this.$table.hide();
|
||||
this.$sortIcon.attr('class', 'sort-icon icon-caret-down').hide();
|
||||
this.$tableBody.empty();
|
||||
this.$loadingTip.show();
|
||||
this.$emptyTip.hide();
|
||||
this.$('.error').hide();
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
this.$('.error').hide();
|
||||
this.$loadingTip.hide();
|
||||
if (this.repos.length) {
|
||||
this.$emptyTip.hide();
|
||||
this.$tableBody.empty();
|
||||
this.repos.each(this.addOne, this);
|
||||
this.$table.show();
|
||||
} else {
|
||||
this.$table.hide();
|
||||
this.$emptyTip.show();
|
||||
}
|
||||
},
|
||||
|
||||
addOne: function(repo) {
|
||||
var view = new ShareAdminRepoView({model: repo});
|
||||
this.$tableBody.append(view.render().el);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return ShareAdminReposView;
|
||||
});
|
83
static/scripts/app/views/share-admin-share-link.js
Normal file
83
static/scripts/app/views/share-admin-share-link.js
Normal file
@@ -0,0 +1,83 @@
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'moment',
|
||||
'app/views/widgets/hl-item-view'
|
||||
], function($, _, Backbone, Common, Moment, HLItemView) {
|
||||
'use strict';
|
||||
|
||||
var ShareAdminShareLinkView = HLItemView.extend({
|
||||
|
||||
tagName: 'tr',
|
||||
|
||||
template: _.template($('#share-admin-download-link-tmpl').html()),
|
||||
linkPopupTemplate: _.template($('#share-admin-link-popup-tmpl').html()),
|
||||
|
||||
events: {
|
||||
'click .rm-link': 'removeLink',
|
||||
'click .view-link': 'viewLink'
|
||||
},
|
||||
|
||||
initialize: function(option) {
|
||||
HLItemView.prototype.initialize.call(this);
|
||||
},
|
||||
|
||||
viewLink: function() {
|
||||
var $popup = $(this.linkPopupTemplate({'link': this.model.get('link')}));
|
||||
$popup.modal({focus:false});
|
||||
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
||||
|
||||
var $p = $('p', $popup),
|
||||
$input = $('input', $popup);
|
||||
$input.css({'width': $p.width() + 2});
|
||||
$p.hide();
|
||||
$input.show();
|
||||
$input.click(function() {
|
||||
$(this).select();
|
||||
});
|
||||
return false;
|
||||
},
|
||||
|
||||
removeLink: function() {
|
||||
var _this = this;
|
||||
|
||||
$.ajax({
|
||||
url: Common.getUrl({
|
||||
'name': 'share_admin_share_link',
|
||||
'token': this.model.get('token')
|
||||
}),
|
||||
type: 'DELETE',
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
success: function() {
|
||||
_this.remove();
|
||||
Common.feedback(gettext("Successfully deleted 1 item"), 'success');
|
||||
},
|
||||
error: function(xhr) {
|
||||
Common.ajaxErrorHandler(xhr);
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var data = this.model.toJSON();
|
||||
var icon_size = Common.isHiDPI() ? 96 : 24;
|
||||
var icon_url = this.model.getIconUrl(icon_size);
|
||||
|
||||
_.extend(data, {
|
||||
'icon_url': icon_url,
|
||||
'dirent_url': this.model.getWebUrl(),
|
||||
'time': data['expire_date'] ? Moment(data['expire_date']).format('YYYY-MM-DD') : ''
|
||||
});
|
||||
|
||||
this.$el.html(this.template(data));
|
||||
return this;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return ShareAdminShareLinkView;
|
||||
});
|
189
static/scripts/app/views/share-admin-share-links.js
Normal file
189
static/scripts/app/views/share-admin-share-links.js
Normal file
@@ -0,0 +1,189 @@
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'app/collections/share-admin-share-links',
|
||||
'app/views/share-admin-share-link'
|
||||
], function($, _, Backbone, Common, ShareAdminShareLinkCollection,
|
||||
ShareAdminShareLinkView) {
|
||||
|
||||
'use strict';
|
||||
|
||||
var ShareAdminShareLinksView = Backbone.View.extend({
|
||||
|
||||
id: 'share-admin-download-links',
|
||||
|
||||
template: _.template($('#share-admin-download-links-tmpl').html()),
|
||||
|
||||
initialize: function() {
|
||||
this.links = new ShareAdminShareLinkCollection();
|
||||
this.listenTo(this.links, 'add', this.addOne);
|
||||
this.listenTo(this.links, 'reset', this.reset);
|
||||
this.render();
|
||||
},
|
||||
|
||||
events: {
|
||||
'click .by-name': 'sortByName',
|
||||
'click .by-time': 'sortByTime'
|
||||
},
|
||||
|
||||
// initialSort: dirs come first
|
||||
initialSort: function(a, b) { // a, b: model
|
||||
var a_is_dir = a.get('is_dir'),
|
||||
b_is_dir = b.get('is_dir');
|
||||
if (a_is_dir && !b_is_dir) {
|
||||
return -1;
|
||||
} else if (!a_is_dir && b_is_dir) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
|
||||
sortByName: function() {
|
||||
var _this = this;
|
||||
var links = this.links;
|
||||
var $el = this.$sortByNameIcon;
|
||||
this.$sortByTimeIcon.hide();
|
||||
if ($el.hasClass('icon-caret-up')) {
|
||||
links.comparator = function(a, b) { // a, b: model
|
||||
var initialResult = _this.initialSort(a, b);
|
||||
if (initialResult != 0) {
|
||||
return initialResult;
|
||||
} else {
|
||||
var result = Common.compareTwoWord(a.get('obj_name'), b.get('obj_name'));
|
||||
return -result;
|
||||
}
|
||||
};
|
||||
} else {
|
||||
links.comparator = function(a, b) { // a, b: model
|
||||
var initialResult = _this.initialSort(a, b);
|
||||
if (initialResult != 0) {
|
||||
return initialResult;
|
||||
} else {
|
||||
var result = Common.compareTwoWord(a.get('obj_name'), b.get('obj_name'));
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
links.sort();
|
||||
this.$tableBody.empty();
|
||||
links.each(this.addOne, this);
|
||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
links.comparator = null;
|
||||
return false;
|
||||
},
|
||||
|
||||
sortByTime: function() {
|
||||
var _this = this;
|
||||
var links = this.links;
|
||||
var $el = this.$sortByTimeIcon;
|
||||
this.$sortByNameIcon.hide();
|
||||
if ($el.hasClass('icon-caret-down')) {
|
||||
links.comparator = function(a, b) { // a, b: model
|
||||
var initialResult = _this.initialSort(a, b);
|
||||
if (initialResult != 0) {
|
||||
return initialResult;
|
||||
} else {
|
||||
return a.get('expire_date_timestamp') < b.get('expire_date_timestamp') ? 1 : -1;
|
||||
}
|
||||
};
|
||||
} else {
|
||||
links.comparator = function(a, b) { // a, b: model
|
||||
var initialResult = _this.initialSort(a, b);
|
||||
if (initialResult != 0) {
|
||||
return initialResult;
|
||||
} else {
|
||||
return a.get('expire_date_timestamp') < b.get('expire_date_timestamp') ? -1 : 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
links.sort();
|
||||
this.$tableBody.empty();
|
||||
links.each(this.addOne, this);
|
||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
||||
links.comparator = null;
|
||||
return false;
|
||||
},
|
||||
|
||||
render: function() {
|
||||
this.$el.html(this.template());
|
||||
this.$table = this.$('table');
|
||||
this.$sortByNameIcon = this.$('.by-name .sort-icon');
|
||||
this.$sortByTimeIcon = this.$('.by-time .sort-icon');
|
||||
this.$tableBody = $('tbody', this.$table);
|
||||
this.$loadingTip = this.$('.loading-tip');
|
||||
this.$emptyTip = this.$('.empty-tips');
|
||||
},
|
||||
|
||||
hide: function() {
|
||||
this.$el.detach();
|
||||
this.attached = false;
|
||||
},
|
||||
|
||||
show: function() {
|
||||
if (!this.attached) {
|
||||
this.attached = true;
|
||||
$("#right-panel").html(this.$el);
|
||||
}
|
||||
this.showContent();
|
||||
},
|
||||
|
||||
showContent: function() {
|
||||
var _this = this;
|
||||
this.initPage();
|
||||
this.links.fetch({
|
||||
cache: false,
|
||||
reset: true,
|
||||
error: function(collection, response, opts) {
|
||||
_this.$loadingTip.hide();
|
||||
var $error = _this.$('.error');
|
||||
var err_msg;
|
||||
if (response.responseText) {
|
||||
if (response['status'] == 401 || response['status'] == 403) {
|
||||
err_msg = gettext("Permission error");
|
||||
} else {
|
||||
err_msg = gettext("Error");
|
||||
}
|
||||
} else {
|
||||
err_msg = gettext('Please check the network.');
|
||||
}
|
||||
$error.html(err_msg).show();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
initPage: function() {
|
||||
this.$table.hide();
|
||||
this.$sortByNameIcon.attr('class', 'sort-icon icon-caret-up').show();
|
||||
this.$sortByTimeIcon.attr('class', 'sort-icon icon-caret-down').hide();
|
||||
this.$tableBody.empty();
|
||||
this.$loadingTip.show();
|
||||
this.$emptyTip.hide();
|
||||
this.$('.error').hide();
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
this.$('.error').hide();
|
||||
this.$loadingTip.hide();
|
||||
if (this.links.length) {
|
||||
this.$emptyTip.hide();
|
||||
this.$tableBody.empty();
|
||||
this.links.each(this.addOne, this);
|
||||
this.$table.show();
|
||||
} else {
|
||||
this.$emptyTip.show();
|
||||
this.$table.hide();
|
||||
}
|
||||
},
|
||||
|
||||
addOne: function(link) {
|
||||
var view = new ShareAdminShareLinkView({model: link});
|
||||
this.$tableBody.append(view.render().el);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return ShareAdminShareLinksView;
|
||||
});
|
81
static/scripts/app/views/share-admin-upload-link.js
Normal file
81
static/scripts/app/views/share-admin-upload-link.js
Normal file
@@ -0,0 +1,81 @@
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'app/views/widgets/hl-item-view'
|
||||
], function($, _, Backbone, Common, HLItemView) {
|
||||
'use strict';
|
||||
|
||||
var ShareAdminUploadLinkView = HLItemView.extend({
|
||||
|
||||
tagName: 'tr',
|
||||
|
||||
template: _.template($('#share-admin-upload-link-tmpl').html()),
|
||||
linkPopupTemplate: _.template($('#share-admin-link-popup-tmpl').html()),
|
||||
|
||||
events: {
|
||||
'click .rm-link': 'removeLink',
|
||||
'click .view-link': 'viewLink'
|
||||
},
|
||||
|
||||
initialize: function(option) {
|
||||
HLItemView.prototype.initialize.call(this);
|
||||
},
|
||||
|
||||
viewLink: function() {
|
||||
var $popup = $(this.linkPopupTemplate({'link': this.model.get('link')}));
|
||||
$popup.modal({focus:false});
|
||||
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
||||
|
||||
var $p = $('p', $popup),
|
||||
$input = $('input', $popup);
|
||||
$input.css({'width': $p.width() + 2});
|
||||
$p.hide();
|
||||
$input.show();
|
||||
$input.click(function() {
|
||||
$(this).select();
|
||||
});
|
||||
return false;
|
||||
},
|
||||
|
||||
removeLink: function() {
|
||||
var _this = this;
|
||||
|
||||
$.ajax({
|
||||
url: Common.getUrl({
|
||||
'name': 'share_admin_upload_link',
|
||||
'token': this.model.get('token')
|
||||
}),
|
||||
type: 'DELETE',
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
success: function() {
|
||||
_this.remove();
|
||||
Common.feedback(gettext("Successfully deleted 1 item"), 'success');
|
||||
},
|
||||
error: function(xhr) {
|
||||
Common.ajaxErrorHandler(xhr);
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var data = this.model.toJSON();
|
||||
var icon_size = Common.isHiDPI() ? 96 : 24;
|
||||
var icon_url = this.model.getIconUrl(icon_size);
|
||||
|
||||
_.extend(data, {
|
||||
'icon_url': icon_url,
|
||||
'dirent_url': this.model.getWebUrl()
|
||||
});
|
||||
|
||||
this.$el.html(this.template(data));
|
||||
return this;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return ShareAdminUploadLinkView;
|
||||
});
|
101
static/scripts/app/views/share-admin-upload-links.js
Normal file
101
static/scripts/app/views/share-admin-upload-links.js
Normal file
@@ -0,0 +1,101 @@
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'app/collections/share-admin-upload-links',
|
||||
'app/views/share-admin-upload-link'
|
||||
], function($, _, Backbone, Common, ShareAdminUploadLinkCollection,
|
||||
ShareAdminUploadLinkView) {
|
||||
|
||||
'use strict';
|
||||
|
||||
var ShareAdminUploadLinksView = Backbone.View.extend({
|
||||
|
||||
id: 'share-admin-upload-links',
|
||||
|
||||
template: _.template($('#share-admin-upload-links-tmpl').html()),
|
||||
|
||||
initialize: function() {
|
||||
this.links = new ShareAdminUploadLinkCollection();
|
||||
this.listenTo(this.links, 'add', this.addOne);
|
||||
this.listenTo(this.links, 'reset', this.reset);
|
||||
this.render();
|
||||
},
|
||||
|
||||
render: function() {
|
||||
this.$el.html(this.template());
|
||||
this.$table = this.$('table');
|
||||
this.$tableBody = $('tbody', this.$table);
|
||||
this.$loadingTip = this.$('.loading-tip');
|
||||
this.$emptyTip = this.$('.empty-tips');
|
||||
},
|
||||
|
||||
hide: function() {
|
||||
this.$el.detach();
|
||||
this.attached = false;
|
||||
},
|
||||
|
||||
show: function() {
|
||||
if (!this.attached) {
|
||||
this.attached = true;
|
||||
$("#right-panel").html(this.$el);
|
||||
}
|
||||
this.showContent();
|
||||
},
|
||||
|
||||
showContent: function() {
|
||||
var _this = this;
|
||||
this.initPage();
|
||||
this.links.fetch({
|
||||
cache: false,
|
||||
reset: true,
|
||||
error: function(collection, response, opts) {
|
||||
_this.$loadingTip.hide();
|
||||
var $error = _this.$('.error');
|
||||
var err_msg;
|
||||
if (response.responseText) {
|
||||
if (response['status'] == 401 || response['status'] == 403) {
|
||||
err_msg = gettext("Permission error");
|
||||
} else {
|
||||
err_msg = gettext("Error");
|
||||
}
|
||||
} else {
|
||||
err_msg = gettext('Please check the network.');
|
||||
}
|
||||
$error.html(err_msg).show();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
initPage: function() {
|
||||
this.$table.hide();
|
||||
this.$tableBody.empty();
|
||||
this.$loadingTip.show();
|
||||
this.$emptyTip.hide();
|
||||
this.$('.error').hide();
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
this.$('.error').hide();
|
||||
this.$loadingTip.hide();
|
||||
if (this.links.length) {
|
||||
this.$emptyTip.hide();
|
||||
this.$tableBody.empty();
|
||||
this.links.each(this.addOne, this);
|
||||
this.$table.show();
|
||||
} else {
|
||||
this.$emptyTip.show();
|
||||
this.$table.hide();
|
||||
}
|
||||
},
|
||||
|
||||
addOne: function(link) {
|
||||
var view = new ShareAdminUploadLinkView({model: link});
|
||||
this.$tableBody.append(view.render().el);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return ShareAdminUploadLinksView;
|
||||
});
|
@@ -105,16 +105,18 @@ define([
|
||||
|
||||
downloadLinkPanelInit: function() {
|
||||
var _this = this;
|
||||
var after_op_success = function(data) {
|
||||
var after_op_success = function(data) { // data is [] or [{...}]
|
||||
|
||||
_this.$('.loading-tip').hide();
|
||||
|
||||
if (data['download_link']) {
|
||||
_this.download_link = data["download_link"]; // for 'link send'
|
||||
_this.download_link_token = data["token"]; // for 'link delete'
|
||||
_this.$('#download-link').html(data['download_link']);
|
||||
_this.$('#direct-dl-link').html(data['download_link']+'?raw=1');
|
||||
if (data['is_expired']) {
|
||||
if (data.length == 1) {
|
||||
var link_data = data[0],
|
||||
link = link_data.link;
|
||||
_this.download_link = link; // for 'link send'
|
||||
_this.download_link_token = link_data.token; // for 'link delete'
|
||||
_this.$('#download-link').html(link);
|
||||
_this.$('#direct-dl-link').html(link + '?raw=1');
|
||||
if (link_data.is_expired) {
|
||||
_this.$('#send-download-link').addClass('hide');
|
||||
_this.$('#download-link, #direct-dl-link').append(' <span class="error">(' + gettext('Expired') + ')</span>');
|
||||
}
|
||||
@@ -125,11 +127,10 @@ define([
|
||||
};
|
||||
// check if downloadLink exists
|
||||
Common.ajaxGet({
|
||||
'get_url': Common.getUrl({name: 'get_shared_download_link'}),
|
||||
'get_url': Common.getUrl({name: 'share_admin_share_links'}),
|
||||
'data': {
|
||||
'repo_id': this.repo_id,
|
||||
'p': this.dirent_path,
|
||||
'type': this.is_dir ? 'd' : 'f'
|
||||
'path': this.dirent_path
|
||||
},
|
||||
'after_op_success': after_op_success
|
||||
});
|
||||
@@ -239,13 +240,8 @@ define([
|
||||
|
||||
$.extend(post_data, {
|
||||
'repo_id': this.repo_id,
|
||||
'p': this.dirent_path
|
||||
'path': this.dirent_path
|
||||
});
|
||||
if (link_type == 'download') {
|
||||
$.extend(post_data, {
|
||||
'type': this.is_dir? 'd' : 'f'
|
||||
});
|
||||
}
|
||||
|
||||
var _this = this;
|
||||
var after_op_success = function(data) {
|
||||
@@ -269,14 +265,14 @@ define([
|
||||
}
|
||||
|
||||
if (link_type == 'download') {
|
||||
_this.$('#download-link').html(data["download_link"]); // TODO: add 'click & select' func
|
||||
_this.$('#direct-dl-link').html(data['download_link'] + '?raw=1');
|
||||
_this.download_link = data["download_link"]; // for 'link send'
|
||||
_this.$('#download-link').html(data["link"]); // TODO: add 'click & select' func
|
||||
_this.$('#direct-dl-link').html(data['link'] + '?raw=1');
|
||||
_this.download_link = data["link"]; // for 'link send'
|
||||
_this.download_link_token = data["token"]; // for 'link delete'
|
||||
_this.$('#download-link-operations').removeClass('hide');
|
||||
} else {
|
||||
_this.$('#upload-link').html(data["upload_link"]);
|
||||
_this.upload_link = data["upload_link"];
|
||||
_this.$('#upload-link').html(data["link"]);
|
||||
_this.upload_link = data["link"];
|
||||
_this.upload_link_token = data["token"];
|
||||
_this.$('#upload-link-operations').removeClass('hide');
|
||||
}
|
||||
@@ -295,7 +291,7 @@ define([
|
||||
this.generateLink({
|
||||
link_type: 'download',
|
||||
form: this.$('#generate-download-link-form'),
|
||||
post_url: Common.getUrl({name: 'get_shared_download_link'})
|
||||
post_url: Common.getUrl({name: 'share_admin_share_links'})
|
||||
});
|
||||
return false;
|
||||
},
|
||||
@@ -384,9 +380,12 @@ define([
|
||||
deleteDownloadLink: function() {
|
||||
var _this = this;
|
||||
$.ajax({
|
||||
url: Common.getUrl({name: 'delete_shared_download_link'}),
|
||||
type: 'POST',
|
||||
data: { 't': this.download_link_token },
|
||||
url: Common.getUrl({
|
||||
'name': 'share_admin_share_link',
|
||||
'token': this.download_link_token
|
||||
}),
|
||||
type: 'DELETE',
|
||||
cache: false,
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
@@ -398,11 +397,13 @@ define([
|
||||
|
||||
uploadLinkPanelInit: function() {
|
||||
var _this = this;
|
||||
var after_op_success = function(data) {
|
||||
if (data['upload_link']) {
|
||||
_this.upload_link_token = data["token"];
|
||||
_this.upload_link = data["upload_link"];
|
||||
_this.$('#upload-link').html(data["upload_link"]); // TODO
|
||||
var after_op_success = function(data) { // data is [] or [{...}]
|
||||
if (data.length == 1) {
|
||||
var link_data = data[0],
|
||||
link = link_data.link;
|
||||
_this.upload_link_token = link_data.token;
|
||||
_this.upload_link = link;
|
||||
_this.$('#upload-link').html(link);
|
||||
_this.$('#upload-link-operations').removeClass('hide');
|
||||
} else {
|
||||
_this.$('#generate-upload-link-form').removeClass('hide');
|
||||
@@ -410,8 +411,11 @@ define([
|
||||
};
|
||||
// check if upload link exists
|
||||
Common.ajaxGet({
|
||||
'get_url': Common.getUrl({name: 'get_share_upload_link'}), // TODO
|
||||
'data': {'repo_id': this.repo_id, 'p': this.dirent_path},
|
||||
'get_url': Common.getUrl({name: 'share_admin_upload_links'}),
|
||||
'data': {
|
||||
'repo_id': this.repo_id,
|
||||
'path': this.dirent_path
|
||||
},
|
||||
'after_op_success': after_op_success
|
||||
});
|
||||
},
|
||||
@@ -428,7 +432,7 @@ define([
|
||||
this.generateLink({
|
||||
link_type: 'upload',
|
||||
form: this.$('#generate-upload-link-form'),
|
||||
post_url: Common.getUrl({name: 'get_share_upload_link'})
|
||||
post_url: Common.getUrl({name: 'share_admin_upload_links'})
|
||||
});
|
||||
return false;
|
||||
},
|
||||
@@ -458,9 +462,12 @@ define([
|
||||
deleteUploadLink: function() {
|
||||
var _this = this;
|
||||
$.ajax({
|
||||
url: Common.getUrl({name: 'delete_shared_upload_link'}),
|
||||
type: 'POST',
|
||||
data: { 't': this.upload_link_token },
|
||||
url: Common.getUrl({
|
||||
'name': 'share_admin_upload_link',
|
||||
'token': this.upload_link_token
|
||||
}),
|
||||
type: 'DELETE',
|
||||
cache: false,
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
|
@@ -119,17 +119,22 @@ define([
|
||||
case 'repo_group_folder_perm': return siteRoot + 'api2/repos/' + options.repo_id + '/group-folder-perm/';
|
||||
case 'repo_change_password': return siteRoot + 'ajax/repo/' + options.repo_id + '/setting/change-passwd/';
|
||||
|
||||
// Share admin
|
||||
case 'share_admin_repos': return siteRoot + 'api/v2.1/shared-repos/';
|
||||
case 'share_admin_repo': return siteRoot + 'api/v2.1/shared-repos/' + options.repo_id + '/';
|
||||
case 'share_admin_folders': return siteRoot + 'api/v2.1/shared-folders/';
|
||||
case 'share_admin_share_links': return siteRoot + 'api/v2.1/share-links/';
|
||||
case 'share_admin_share_link': return siteRoot + 'api/v2.1/share-links/' + options.token + '/';
|
||||
case 'share_admin_upload_links': return siteRoot + 'api/v2.1/upload-links/';
|
||||
case 'share_admin_upload_link': return siteRoot + 'api/v2.1/upload-links/' + options.token + '/';
|
||||
|
||||
// Permission
|
||||
case 'set_user_folder_perm': return siteRoot + 'ajax/repo/' + options.repo_id + '/set-user-folder-perm/';
|
||||
case 'set_group_folder_perm': return siteRoot + 'ajax/repo/' + options.repo_id + '/set-group-folder-perm/';
|
||||
|
||||
// Links
|
||||
case 'get_shared_download_link': return siteRoot + 'share/ajax/get-download-link/';
|
||||
case 'delete_shared_download_link': return siteRoot + 'share/ajax/link/remove/';
|
||||
case 'send_shared_download_link': return siteRoot + 'share/link/send/';
|
||||
case 'send_shared_upload_link': return siteRoot + 'share/upload_link/send/';
|
||||
case 'delete_shared_upload_link': return siteRoot + 'share/ajax/upload_link/remove/';
|
||||
case 'get_share_upload_link': return siteRoot + 'share/ajax/get-upload-link/';
|
||||
|
||||
// Group
|
||||
case 'groups': return siteRoot + 'api/v2.1/groups/';
|
||||
@@ -157,6 +162,7 @@ define([
|
||||
case 'search_user': return siteRoot + 'api2/search-user/';
|
||||
case 'user_profile': return siteRoot + 'profile/' + options.username + '/';
|
||||
case 'space_and_traffic': return siteRoot + 'ajax/space_and_traffic/';
|
||||
|
||||
// sysadmin
|
||||
case 'sysinfo': return siteRoot + 'api/v2.1/admin/sysinfo/';
|
||||
case 'admin-devices': return siteRoot + 'api/v2.1/admin/devices/';
|
||||
|
Reference in New Issue
Block a user