mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-01 15:09:14 +00:00
[system repo admin] fix, improvement, supplement, clean
This commit is contained in:
@@ -8,12 +8,18 @@ define([
|
||||
|
||||
var DirentCollection = Backbone.Collection.extend({
|
||||
model: DirentModel,
|
||||
parse: function (data) {
|
||||
|
||||
url: function() {
|
||||
return Common.getUrl({name: 'admin-library-dirents', repo_id: this.repo_id});
|
||||
},
|
||||
|
||||
parse: function(data) {
|
||||
this.repo_name = data.repo_name;
|
||||
this.repo_id = data.repo_id;
|
||||
this.is_system_library = data.is_system_library;
|
||||
return data.dirent_list; // return the array
|
||||
},
|
||||
|
||||
setPath: function(repo_id, path) {
|
||||
this.repo_id = repo_id;
|
||||
this.path = path;
|
||||
|
@@ -10,10 +10,10 @@ define([
|
||||
model: RepoModel,
|
||||
state: {pageSize: 100},
|
||||
parseState: function(data) {
|
||||
return {hasNextPage: data[0].has_next_page, current_page: data[0].current_page};
|
||||
return data.page_info; // {'has_next_page': has_next_page, 'current_page': current_page}
|
||||
},
|
||||
parseRecords: function(data) {
|
||||
return data[1];
|
||||
return data.repos;
|
||||
},
|
||||
url: function () {
|
||||
return Common.getUrl({name: 'admin-libraries'});
|
||||
|
25
static/scripts/sysadmin-app/collection/search-repos.js
Normal file
25
static/scripts/sysadmin-app/collection/search-repos.js
Normal file
@@ -0,0 +1,25 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'sysadmin-app/models/repo'
|
||||
], function(_, Backbone, Common, RepoModel) {
|
||||
'use strict';
|
||||
|
||||
var RepoCollection = Backbone.Collection.extend({
|
||||
|
||||
model: RepoModel,
|
||||
|
||||
url: function () {
|
||||
return Common.getUrl({name: 'admin-libraries'});
|
||||
},
|
||||
|
||||
parse: function(data) {
|
||||
this.search_name = data.name;
|
||||
this.search_owner = data.owner;
|
||||
return data.repos;
|
||||
}
|
||||
});
|
||||
|
||||
return RepoCollection;
|
||||
});
|
@@ -8,9 +8,16 @@ define([
|
||||
|
||||
var TrashRepoCollection = Backbone.Collection.extend({
|
||||
model: TrashRepoModel,
|
||||
|
||||
url: function () {
|
||||
return Common.getUrl({name: 'admin-trash-libraries'});
|
||||
},
|
||||
|
||||
parse: function(data) {
|
||||
this.search_owner = data.search_owner;
|
||||
return data.repos;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return TrashRepoCollection;
|
||||
|
@@ -18,18 +18,19 @@ define([
|
||||
var dirent_path = this.getPath();
|
||||
|
||||
if (this.get('is_file')) {
|
||||
return '#';
|
||||
return '';
|
||||
} else {
|
||||
return '#libraries/' + dir.repo_id + '/dirents' + Common.encodePath(dirent_path);
|
||||
return '#libs/' + dir.repo_id + Common.encodePath(dirent_path);
|
||||
}
|
||||
},
|
||||
|
||||
// only for file
|
||||
getDownloadUrl: function() {
|
||||
var dir = this.collection;
|
||||
var dirent_path = this.getPath();
|
||||
|
||||
return app.config.siteRoot + "api/v2.1/admin/libraries/" + dir.repo_id
|
||||
+ "/dirent/?path=" + Common.encodePath(dirent_path) + "&dl=1";
|
||||
+ "/dirent/?path=" + encodeURIComponent(dirent_path) + "&dl=1";
|
||||
},
|
||||
|
||||
getDeleteUrl: function() {
|
||||
@@ -37,7 +38,7 @@ define([
|
||||
var dirent_path = this.getPath();
|
||||
|
||||
return app.config.siteRoot + "api/v2.1/admin/libraries/" + dir.repo_id
|
||||
+ "/dirent/?path=" + Common.encodePath(dirent_path);
|
||||
+ "/dirent/?path=" + encodeURIComponent(dirent_path);
|
||||
},
|
||||
|
||||
getIconUrl: function(size) {
|
||||
|
@@ -9,14 +9,15 @@ define([
|
||||
'sysadmin-app/views/mobile-devices',
|
||||
'sysadmin-app/views/device-errors',
|
||||
'sysadmin-app/views/repos',
|
||||
'sysadmin-app/views/dir',
|
||||
'sysadmin-app/views/search-repos',
|
||||
'sysadmin-app/views/system-repo',
|
||||
'sysadmin-app/views/trash-repos',
|
||||
'sysadmin-app/views/dir',
|
||||
'app/views/account'
|
||||
], function($, Backbone, Common, SideNavView, DashboardView,
|
||||
DesktopDevicesView, MobileDevicesView, DeviceErrorsView,
|
||||
ReposView, DirView, SystemReposView,
|
||||
TrashReposView, AccountView) {
|
||||
ReposView, SearchReposView, SystemReposView, TrashReposView, DirView,
|
||||
AccountView) {
|
||||
|
||||
"use strict";
|
||||
|
||||
@@ -27,10 +28,11 @@ define([
|
||||
'desktop-devices/': 'showDesktopDevices',
|
||||
'mobile-devices/': 'showMobileDevices',
|
||||
'device-errors/': 'showDeviceErrors',
|
||||
'libraries/': 'showLibraries',
|
||||
'libraries/:repo_id/dirents(/*path)': 'showLibraryDir',
|
||||
'libraries/system/': 'showSystemLibrary',
|
||||
'libraries/trash/': 'showTrashLibraries',
|
||||
'all-libs/': 'showLibraries',
|
||||
'search-libs/': 'showSearchLibraries',
|
||||
'system-lib/': 'showSystemLibrary',
|
||||
'trash-libs/': 'showTrashLibraries',
|
||||
'libs/:repo_id(/*path)': 'showLibraryDir',
|
||||
// Default
|
||||
'*actions': 'showDashboard'
|
||||
},
|
||||
@@ -50,7 +52,9 @@ define([
|
||||
this.desktopDevicesView = new DesktopDevicesView();
|
||||
this.mobileDevicesView = new MobileDevicesView();
|
||||
this.deviceErrorsView = new DeviceErrorsView();
|
||||
|
||||
this.reposView = new ReposView();
|
||||
this.searchReposView = new SearchReposView();
|
||||
this.systemReposView = new SystemReposView();
|
||||
this.trashReposView = new TrashReposView();
|
||||
this.dirView = new DirView();
|
||||
@@ -108,16 +112,27 @@ define([
|
||||
},
|
||||
|
||||
showLibraries: function() {
|
||||
var url = window.location.href;
|
||||
var page = url.match(/.*?page=(\d+)/);
|
||||
if (page) {
|
||||
var current_page = page[1];
|
||||
} else {
|
||||
var current_page = null;
|
||||
}
|
||||
// url_match: null or an array like ["http://127.0.0.1:8000/sysadmin/#libraries/?page=2", "2"]
|
||||
var url_match = location.href.match(/.*?page=(\d+)/);
|
||||
var page = url_match ? url_match[1] : 1; // 1: default
|
||||
|
||||
this.switchCurrentView(this.reposView);
|
||||
this.sideNavView.setCurTab('libraries');
|
||||
this.reposView.show({'current_page': current_page});
|
||||
this.sideNavView.setCurTab('libraries', {'option': 'all'});
|
||||
this.reposView.show({'page': page});
|
||||
},
|
||||
|
||||
showSearchLibraries: function() {
|
||||
// url_match: null or an array
|
||||
var url_match = location.href.match(/.*?name=(.*)&owner=(.*)/); // search by repo_name/owner
|
||||
var repo_name = url_match ? url_match[1] : '';
|
||||
var owner = url_match ? url_match[2] : '';
|
||||
|
||||
this.switchCurrentView(this.searchReposView);
|
||||
this.sideNavView.setCurTab('libraries', {'option': 'all'});
|
||||
this.searchReposView.show({
|
||||
'name': decodeURIComponent(repo_name),
|
||||
'owner': decodeURIComponent(owner)
|
||||
});
|
||||
},
|
||||
|
||||
showLibraryDir: function(repo_id, path) {
|
||||
@@ -128,19 +143,23 @@ define([
|
||||
}
|
||||
this.switchCurrentView(this.dirView);
|
||||
this.dirView.show(repo_id, path);
|
||||
this.sideNavView.setCurTab('libraries');
|
||||
this.sideNavView.setCurTab('libraries', {'option': ''});
|
||||
},
|
||||
|
||||
showSystemLibrary: function() {
|
||||
this.switchCurrentView(this.systemReposView);
|
||||
this.sideNavView.setCurTab('libraries');
|
||||
this.sideNavView.setCurTab('libraries', {'option': 'system'});
|
||||
this.systemReposView.show();
|
||||
},
|
||||
|
||||
showTrashLibraries: function() {
|
||||
// url_match: null or an array
|
||||
var url_match = location.href.match(/.*?name=(.*)/); // search by owner
|
||||
var owner = url_match ? url_match[1] : '';
|
||||
|
||||
this.switchCurrentView(this.trashReposView);
|
||||
this.sideNavView.setCurTab('libraries');
|
||||
this.trashReposView.show();
|
||||
this.sideNavView.setCurTab('libraries', {'option': 'trash'});
|
||||
this.trashReposView.show({'owner': decodeURIComponent(owner)});
|
||||
}
|
||||
|
||||
});
|
||||
|
@@ -3,11 +3,10 @@ define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'moment',
|
||||
'app/views/fileupload',
|
||||
'sysadmin-app/views/dirent',
|
||||
'sysadmin-app/collection/dirents'
|
||||
], function($, _, Backbone, Common, Moment, FileUploadView,
|
||||
], function($, _, Backbone, Common, FileUploadView,
|
||||
DirentView, DirentCollection) {
|
||||
'use strict';
|
||||
|
||||
@@ -17,30 +16,34 @@ define([
|
||||
|
||||
template: _.template($('#dir-view-tmpl').html()),
|
||||
pathBarTemplate: _.template($('#dir-path-bar-tmpl').html()),
|
||||
newDirTemplate: _.template($("#add-new-dir-form-template").html()),
|
||||
dir_op_bar_template: _.template($('#dir-op-bar-tmpl').html()),
|
||||
|
||||
newDirTemplate: _.template($("#add-new-dir-form-template").html()),
|
||||
|
||||
initialize: function() {
|
||||
this.dir = new DirentCollection();
|
||||
this.listenTo(this.dir, 'add', this.addOne);
|
||||
this.listenTo(this.dir, 'reset', this.reset);
|
||||
|
||||
this.fileUploadView = new FileUploadView({dirView: this});
|
||||
|
||||
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');
|
||||
//this.$emptyTip = this.$('.empty-tips');
|
||||
this.$path_bar = this.$('.path-bar');
|
||||
this.$dir_op_bar = this.$('.repo-op');
|
||||
},
|
||||
|
||||
events: {
|
||||
'click .basic-upload-btn': 'uploadFile',
|
||||
'click #add-new-dir': 'newDir',
|
||||
'click #add-new-dir': 'newDir'
|
||||
},
|
||||
|
||||
uploadFile: function() {
|
||||
@@ -49,9 +52,19 @@ define([
|
||||
|
||||
addNewFile: function(new_dirent) {
|
||||
new_dirent.set('last_update', new Date().getTime());
|
||||
var dirView = this;
|
||||
var view = new DirentView({model: new_dirent, dirView: dirView});
|
||||
dirView.$tableBody.prepend(view.render().el);
|
||||
var view = new DirentView({model: new_dirent, dirView: this});
|
||||
var new_file = view.render().el;
|
||||
if ($('tr', this.$tableBody).length == 0) {
|
||||
this.$tableBody.append(new_file);
|
||||
} else {
|
||||
var dirs = this.dir.where({'is_file':false});
|
||||
if (dirs.length == 0) {
|
||||
this.$tableBody.prepend(new_file);
|
||||
} else {
|
||||
// put the new file after the last dir
|
||||
$($('tr', this.$tableBody)[dirs.length - 1]).after(new_file);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
newDir: function() {
|
||||
@@ -120,7 +133,7 @@ define([
|
||||
|
||||
this.$tableBody.empty();
|
||||
this.$loadingTip.show();
|
||||
this.$emptyTip.hide();
|
||||
//this.$emptyTip.hide();
|
||||
},
|
||||
|
||||
renderPath: function() {
|
||||
@@ -129,6 +142,7 @@ define([
|
||||
var obj = {
|
||||
path: path,
|
||||
repo_name: dir.repo_name,
|
||||
is_system_library: dir.is_system_library
|
||||
};
|
||||
|
||||
var path_list = path.substr(1).split('/');
|
||||
@@ -145,11 +159,12 @@ define([
|
||||
},
|
||||
|
||||
renderDirOpBar: function() {
|
||||
var data = {
|
||||
'is_system_library': this.dir.is_system_library,
|
||||
'encrypted': this.dir.encrypted,
|
||||
};
|
||||
this.$dir_op_bar.html(this.dir_op_bar_template(data));
|
||||
// only system lib has 'dir op'(upload file, add dir)
|
||||
if (this.dir.is_system_library) {
|
||||
this.$dir_op_bar.html(this.dir_op_bar_template()).show();
|
||||
} else {
|
||||
this.$dir_op_bar.empty().hide();
|
||||
}
|
||||
},
|
||||
|
||||
setFileInput: function () {
|
||||
@@ -163,9 +178,8 @@ define([
|
||||
fetchLibraryDirents: function() {
|
||||
var dir = this.dir;
|
||||
dir.fetch({
|
||||
url: Common.getUrl({name: 'admin-library-dirents', repo_id: dir.repo_id}) + '?parent_dir=' + Common.encodePath(dir.path),
|
||||
data: {},
|
||||
cache: false, // for IE
|
||||
data: {'parent_dir': dir.path},
|
||||
cache: false,
|
||||
reset: true,
|
||||
error: function (collection, response, opts) {
|
||||
var err_msg;
|
||||
@@ -193,7 +207,7 @@ define([
|
||||
this.dir.each(this.addOne, this);
|
||||
this.$table.show();
|
||||
} else {
|
||||
this.$emptyTip.show();
|
||||
//this.$emptyTip.show();
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -15,7 +15,7 @@ define([
|
||||
|
||||
events: {
|
||||
'click .dirent-download-btn': 'downloadDirent',
|
||||
'click .dirent-delete-btn': 'deleteDirent',
|
||||
'click .dirent-delete-btn': 'deleteDirent'
|
||||
},
|
||||
|
||||
initialize: function(options) {
|
||||
@@ -24,12 +24,11 @@ define([
|
||||
},
|
||||
|
||||
downloadDirent: function() {
|
||||
var _this = this;
|
||||
$.ajax({
|
||||
url: _this.model.getDownloadUrl(),
|
||||
url: this.model.getDownloadUrl(),
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
location.href = data['download_url']
|
||||
location.href = data['download_url'];
|
||||
},
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
|
||||
@@ -41,7 +40,7 @@ define([
|
||||
deleteDirent: function() {
|
||||
var _this = this;
|
||||
$.ajax({
|
||||
url: _this.model.getDeleteUrl(),
|
||||
url: this.model.getDeleteUrl(),
|
||||
type: 'DELETE',
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
dataType: 'json',
|
||||
@@ -64,10 +63,13 @@ define([
|
||||
data['time'] = last_update.format('LLLL');
|
||||
data['time_from_now'] = Common.getRelativeTimeStr(last_update);
|
||||
data['icon_url'] = this.model.getIconUrl(file_icon_size);
|
||||
data['download_url'] = this.model.getDownloadUrl(),
|
||||
if (this.model.get('is_file')) {
|
||||
data['download_url'] = this.model.getDownloadUrl();
|
||||
} else {
|
||||
data['url'] = this.model.getWebUrl();
|
||||
}
|
||||
data['repo_id'] = this.dir.repo_id;
|
||||
data['is_system_library'] = this.dir.is_system_library;
|
||||
data['url'] = this.model.getWebUrl(),
|
||||
|
||||
this.$el.html(this.template(data));
|
||||
|
||||
|
@@ -7,8 +7,7 @@ define([
|
||||
'simplemodal',
|
||||
'select2',
|
||||
'app/views/widgets/hl-item-view'
|
||||
], function($, _, Backbone, Common, Moment, Simplemodal,
|
||||
Select2, HLItemView) {
|
||||
], function($, _, Backbone, Common, Moment, Simplemodal, Select2, HLItemView) {
|
||||
'use strict';
|
||||
|
||||
var RepoView = HLItemView.extend({
|
||||
@@ -19,7 +18,7 @@ define([
|
||||
|
||||
events: {
|
||||
'click .repo-delete-btn': 'deleteLibrary',
|
||||
'click .repo-transfer-btn': 'transferLibrary',
|
||||
'click .repo-transfer-btn': 'transferLibrary'
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
@@ -29,19 +28,32 @@ define([
|
||||
|
||||
deleteLibrary: function() {
|
||||
var _this = this;
|
||||
$.ajax({
|
||||
url: Common.getUrl({'name':'admin-library', 'repo_id': _this.model.get('id')}),
|
||||
type: 'DELETE',
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
dataType: 'json',
|
||||
success: function() {
|
||||
_this.$el.remove();
|
||||
Common.feedback(gettext("Success"), 'success');
|
||||
},
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
|
||||
}
|
||||
})
|
||||
var repo_name = this.model.get('name');
|
||||
var popupTitle = gettext("Delete Library");
|
||||
var popupContent = gettext("Are you sure you want to delete %s ?").replace('%s', '<span class="op-target ellipsis ellipsis-op-target" title="' + Common.HTMLescape(repo_name) + '">' + Common.HTMLescape(repo_name) + '</span>');
|
||||
var yesCallback = function() {
|
||||
$.ajax({
|
||||
url: Common.getUrl({
|
||||
'name':'admin-library',
|
||||
'repo_id': _this.model.get('id')
|
||||
}),
|
||||
type: 'DELETE',
|
||||
cache: false,
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
dataType: 'json',
|
||||
success: function() {
|
||||
_this.$el.remove();
|
||||
Common.feedback(gettext("Successfully deleted."), 'success');
|
||||
},
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
|
||||
},
|
||||
complete: function() {
|
||||
$.modal.close();
|
||||
}
|
||||
});
|
||||
};
|
||||
Common.showConfirm(popupTitle, popupContent, yesCallback);
|
||||
return false;
|
||||
},
|
||||
|
||||
@@ -86,8 +98,8 @@ define([
|
||||
},
|
||||
success: function() {
|
||||
$.modal.close();
|
||||
Common.feedback(gettext("Successfully transferred the library."), 'success');
|
||||
_this.model.set({'owner': email}); // it will trigger 'change' event
|
||||
Common.feedback(gettext("Successfully transferred the library."), 'success');
|
||||
},
|
||||
error: function(xhr) {
|
||||
var error_msg;
|
||||
|
@@ -3,16 +3,16 @@ define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'moment',
|
||||
'sysadmin-app/views/repo',
|
||||
'sysadmin-app/collection/repos'
|
||||
], function($, _, Backbone, Common, Moment, RepoView, RepoCollection) {
|
||||
], function($, _, Backbone, Common, RepoView, RepoCollection) {
|
||||
'use strict';
|
||||
|
||||
var ReposView = Backbone.View.extend({
|
||||
|
||||
id: 'libraries',
|
||||
|
||||
tabNavTemplate: _.template($("#libraries-tabnav-tmpl").html()),
|
||||
template: _.template($("#libraries-tmpl").html()),
|
||||
|
||||
initialize: function() {
|
||||
@@ -23,8 +23,10 @@ define([
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var data = {'cur_tab': 'all'};
|
||||
this.$el.html(this.template(data));
|
||||
var $tabnav = $(this.tabNavTemplate({'cur_tab': 'all'}));
|
||||
this.$el.append($tabnav);
|
||||
this.$el.append(this.template());
|
||||
|
||||
this.$table = this.$('table');
|
||||
this.$tableBody = $('tbody', this.$table);
|
||||
this.$loadingTip = this.$('.loading-tip');
|
||||
@@ -50,7 +52,7 @@ define([
|
||||
getNextPage: function() {
|
||||
this.initPage();
|
||||
var current_page = this.repoCollection.state.current_page;
|
||||
if (this.repoCollection.state.hasNextPage) {
|
||||
if (this.repoCollection.state.has_next_page) {
|
||||
this.repoCollection.getPage(current_page + 1, {
|
||||
reset: true
|
||||
});
|
||||
@@ -62,7 +64,7 @@ define([
|
||||
getPreviousPage: function() {
|
||||
this.initPage();
|
||||
var current_page = this.repoCollection.state.current_page;
|
||||
if ( current_page > 1) {
|
||||
if (current_page > 1) {
|
||||
this.repoCollection.getPage(current_page - 1, {
|
||||
reset: true
|
||||
});
|
||||
@@ -81,19 +83,17 @@ define([
|
||||
this.attached = true;
|
||||
$("#right-panel").html(this.$el);
|
||||
}
|
||||
this.showLibraries();
|
||||
this.getContent();
|
||||
},
|
||||
|
||||
showLibraries: function() {
|
||||
getContent: function() {
|
||||
this.initPage();
|
||||
var _this = this,
|
||||
current_page = this.option.current_page || 1;
|
||||
|
||||
var _this = this;
|
||||
this.repoCollection.fetch({
|
||||
data: {'page': current_page},
|
||||
cache: false, // for IE
|
||||
data: {'page': this.option.page},
|
||||
cache: false,
|
||||
reset: true,
|
||||
error: function (collection, response, opts) {
|
||||
error: function(collection, response, opts) {
|
||||
var err_msg;
|
||||
if (response.responseText) {
|
||||
if (response['status'] == 401 || response['status'] == 403) {
|
||||
@@ -105,29 +105,30 @@ define([
|
||||
err_msg = gettext("Failed. Please check the network.");
|
||||
}
|
||||
Common.feedback(err_msg, 'error');
|
||||
},
|
||||
complete:function() {
|
||||
_this.$loadingTip.hide();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
var length = this.repoCollection.length,
|
||||
current_page = this.repoCollection.state.current_page;
|
||||
// update the url
|
||||
var current_page = this.repoCollection.state.current_page;
|
||||
app.router.navigate('all-libs/?page=' + current_page);
|
||||
|
||||
this.$loadingTip.hide();
|
||||
|
||||
if (length > 0) {
|
||||
if (this.repoCollection.length > 0) {
|
||||
this.repoCollection.each(this.addOne, this);
|
||||
this.$table.show();
|
||||
this.renderPaginator();
|
||||
} else {
|
||||
this.$emptyTip.show();
|
||||
}
|
||||
|
||||
app.router.navigate('libraries/?page=' + current_page);
|
||||
},
|
||||
|
||||
renderPaginator: function() {
|
||||
if (this.repoCollection.state.hasNextPage) {
|
||||
if (this.repoCollection.state.has_next_page) {
|
||||
this.$jsNext.show();
|
||||
} else {
|
||||
this.$jsNext.hide();
|
||||
|
126
static/scripts/sysadmin-app/views/search-repos.js
Normal file
126
static/scripts/sysadmin-app/views/search-repos.js
Normal file
@@ -0,0 +1,126 @@
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'sysadmin-app/views/repo',
|
||||
'sysadmin-app/collection/search-repos'
|
||||
], function($, _, Backbone, Common, RepoView, RepoCollection) {
|
||||
'use strict';
|
||||
|
||||
var ReposView = Backbone.View.extend({
|
||||
|
||||
id: 'search-libraries',
|
||||
|
||||
tabNavTemplate: _.template($("#libraries-tabnav-tmpl").html()),
|
||||
template: _.template($("#search-libraries-tmpl").html()),
|
||||
|
||||
initialize: function() {
|
||||
this.repoCollection = new RepoCollection();
|
||||
this.listenTo(this.repoCollection, 'add', this.addOne);
|
||||
this.listenTo(this.repoCollection, 'reset', this.reset);
|
||||
this.render();
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var $tabnav = $(this.tabNavTemplate({'cur_tab': 'all'}));
|
||||
this.$el.append($tabnav);
|
||||
this.$el.append(this.template());
|
||||
|
||||
this.$form = this.$('#search-repo-form');
|
||||
this.$name = $('[name="name"]', this.$form);
|
||||
this.$owner = $('[name="owner"]', this.$form);
|
||||
|
||||
this.$table = this.$('table');
|
||||
this.$tableBody = $('tbody', this.$table);
|
||||
this.$loadingTip = this.$('.loading-tip');
|
||||
this.$emptyTip = this.$('.empty-tips');
|
||||
},
|
||||
|
||||
events: {
|
||||
'submit #search-repo-form': 'formSubmit'
|
||||
},
|
||||
|
||||
initPage: function() {
|
||||
this.$table.hide();
|
||||
this.$tableBody.empty();
|
||||
this.$loadingTip.show();
|
||||
this.$emptyTip.hide();
|
||||
},
|
||||
|
||||
hide: function() {
|
||||
this.$el.detach();
|
||||
this.attached = false;
|
||||
},
|
||||
|
||||
show: function(option) {
|
||||
if (!this.attached) {
|
||||
this.attached = true;
|
||||
$("#right-panel").html(this.$el);
|
||||
}
|
||||
this.getContent(option);
|
||||
},
|
||||
|
||||
getContent: function(obj) {
|
||||
this.initPage();
|
||||
var _this = this;
|
||||
this.repoCollection.fetch({
|
||||
data: obj,
|
||||
cache: false,
|
||||
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');
|
||||
},
|
||||
complete:function() {
|
||||
_this.$loadingTip.hide();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
var name = this.repoCollection.search_name;
|
||||
var owner = this.repoCollection.search_owner;
|
||||
app.router.navigate('#search-libs/?name=' + encodeURIComponent(name) + '&owner=' + encodeURIComponent(owner));
|
||||
this.$name.val(name);
|
||||
this.$owner.val(owner);
|
||||
|
||||
this.$loadingTip.hide();
|
||||
if (this.repoCollection.length > 0) {
|
||||
this.repoCollection.each(this.addOne, this);
|
||||
this.$table.show();
|
||||
} else {
|
||||
this.$emptyTip.show();
|
||||
}
|
||||
},
|
||||
|
||||
addOne: function(library) {
|
||||
var view = new RepoView({model: library});
|
||||
this.$tableBody.append(view.render().el);
|
||||
},
|
||||
|
||||
formSubmit: function() {
|
||||
var name = $.trim(this.$name.val());
|
||||
var owner = $.trim(this.$owner.val());
|
||||
|
||||
if (!name && !owner) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.getContent({'name': name, 'owner': owner});
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return ReposView;
|
||||
|
||||
});
|
@@ -31,6 +31,37 @@ define([
|
||||
$.extend(this.data, options);
|
||||
}
|
||||
this.render();
|
||||
},
|
||||
|
||||
events: {
|
||||
'submit #libs-search-form': 'searchLibs', // for 'all' libs
|
||||
'submit #trash-libs-search-form': 'searchTrashLibs'
|
||||
},
|
||||
|
||||
// search libs by repo_name
|
||||
searchLibs: function() {
|
||||
var $form = this.$('#libs-search-form');
|
||||
var name = $.trim($('[name="name"]', $form).val());
|
||||
if (!name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var url = $form.attr('action') + '?name=' + encodeURIComponent(name) + '&owner=';
|
||||
location.href = url;
|
||||
return false; // necessary
|
||||
},
|
||||
|
||||
// search trash libs by owner
|
||||
searchTrashLibs: function() {
|
||||
var $form = this.$('#trash-libs-search-form');
|
||||
var owner = $.trim($('[name="name"]', $form).val());
|
||||
if (!owner) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var url = $form.attr('action') + '?name=' + encodeURIComponent(owner);
|
||||
location.href = url;
|
||||
return false; // necessary
|
||||
}
|
||||
|
||||
});
|
||||
|
@@ -11,6 +11,7 @@ define([
|
||||
|
||||
id: "system-library",
|
||||
|
||||
tabNavTemplate: _.template($("#libraries-tabnav-tmpl").html()),
|
||||
template: _.template($("#system-library-tmpl").html()),
|
||||
itemTemplate: _.template($("#system-library-item-tmpl").html()),
|
||||
|
||||
@@ -20,8 +21,10 @@ define([
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var data = {'cur_tab': 'system',};
|
||||
this.$el.html(this.template(data));
|
||||
var $tabnav = $(this.tabNavTemplate({'cur_tab': 'system'}));
|
||||
this.$el.append($tabnav);
|
||||
this.$el.append(this.template());
|
||||
|
||||
this.$table = this.$('table');
|
||||
this.$tableBody = $('tbody', this.$table);
|
||||
this.$loadingTip = this.$('.loading-tip');
|
||||
|
@@ -15,7 +15,7 @@ define([
|
||||
|
||||
events: {
|
||||
'click .repo-delete-btn': 'deleteTrashLibrary',
|
||||
'click .repo-restore-btn': 'restoreTrashLibrary',
|
||||
'click .repo-restore-btn': 'restoreTrashLibrary'
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
@@ -24,37 +24,61 @@ define([
|
||||
|
||||
deleteTrashLibrary: function() {
|
||||
var _this = this;
|
||||
$.ajax({
|
||||
url: Common.getUrl({'name':'admin-trash-library', 'repo_id': _this.model.get('id')}),
|
||||
type: 'DELETE',
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
dataType: 'json',
|
||||
success: function() {
|
||||
_this.$el.remove();
|
||||
Common.feedback(gettext("Success"), 'success');
|
||||
},
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
|
||||
}
|
||||
})
|
||||
var repo_name = this.model.get('name');
|
||||
var popupTitle = gettext("Delete Library");
|
||||
var popupContent = gettext("Are you sure you want to delete %s completely?").replace('%s', '<span class="op-target ellipsis ellipsis-op-target" title="' + Common.HTMLescape(repo_name) + '">' + Common.HTMLescape(repo_name) + '</span>');
|
||||
var yesCallback = function() {
|
||||
$.ajax({
|
||||
url: Common.getUrl({
|
||||
'name':'admin-trash-library',
|
||||
'repo_id': _this.model.get('id')
|
||||
}),
|
||||
type: 'DELETE',
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
dataType: 'json',
|
||||
success: function() {
|
||||
_this.$el.remove();
|
||||
Common.feedback(gettext("Success"), 'success');
|
||||
},
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
|
||||
},
|
||||
complete: function() {
|
||||
$.modal.close();
|
||||
}
|
||||
});
|
||||
};
|
||||
Common.showConfirm(popupTitle, popupContent, yesCallback);
|
||||
return false;
|
||||
},
|
||||
|
||||
restoreTrashLibrary: function() {
|
||||
var _this = this;
|
||||
$.ajax({
|
||||
url: Common.getUrl({'name':'admin-trash-library', 'repo_id': _this.model.get('id')}),
|
||||
type: 'PUT',
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
dataType: 'json',
|
||||
success: function() {
|
||||
_this.$el.remove();
|
||||
Common.feedback(gettext("Success"), 'success');
|
||||
},
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
|
||||
}
|
||||
})
|
||||
var repo_name = this.model.get('name');
|
||||
var popupTitle = gettext("Restore Library");
|
||||
var popupContent = gettext("Are you sure you want to restore %s?").replace('%s', '<span class="op-target ellipsis ellipsis-op-target" title="' + Common.HTMLescape(repo_name) + '">' + Common.HTMLescape(repo_name) + '</span>');
|
||||
var yesCallback = function() {
|
||||
$.ajax({
|
||||
url: Common.getUrl({
|
||||
'name':'admin-trash-library',
|
||||
'repo_id': _this.model.get('id')
|
||||
}),
|
||||
type: 'PUT',
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
dataType: 'json',
|
||||
success: function() {
|
||||
_this.$el.remove();
|
||||
Common.feedback(gettext("Success"), 'success');
|
||||
},
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
|
||||
},
|
||||
complete: function() {
|
||||
$.modal.close();
|
||||
}
|
||||
});
|
||||
};
|
||||
Common.showConfirm(popupTitle, popupContent, yesCallback);
|
||||
return false;
|
||||
},
|
||||
|
||||
|
@@ -14,60 +14,87 @@ define([
|
||||
|
||||
id: 'trash-libraries',
|
||||
|
||||
tabNavTemplate: _.template($("#libraries-tabnav-tmpl").html()),
|
||||
template: _.template($("#trash-libraries-tmpl").html()),
|
||||
|
||||
initialize: function() {
|
||||
this.trashRepoCollection = new TrashRepoCollection();
|
||||
this.listenTo(this.trashRepoCollection, 'add', this.addOne);
|
||||
this.listenTo(this.trashRepoCollection, 'reset', this.reset);
|
||||
|
||||
this.render();
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var data = {'cur_tab': 'trash',};
|
||||
this.$el.html(this.template(data));
|
||||
this.$el.html(this.tabNavTemplate({'cur_tab': 'trash'}) + this.template());
|
||||
|
||||
this.$tip = this.$('.tip');
|
||||
this.$table = this.$('table');
|
||||
this.$tableBody = $('tbody', this.$table);
|
||||
this.$loadingTip = this.$('.loading-tip');
|
||||
this.$emptyTip = this.$('.empty-tips');
|
||||
this.$cleanBtn = this.$('.js-clean');
|
||||
},
|
||||
|
||||
events: {
|
||||
'click #clean-trash-libraries': 'cleanTrashLibraries',
|
||||
'click .js-clean': 'cleanTrashLibraries'
|
||||
},
|
||||
|
||||
cleanTrashLibraries: function() {
|
||||
var _this = this;
|
||||
$.ajax({
|
||||
url: Common.getUrl({'name':'admin-trash-libraries'}),
|
||||
type: 'DELETE',
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
dataType: 'json',
|
||||
success: function() {
|
||||
_this.$table.hide();
|
||||
_this.$emptyTip.show();
|
||||
Common.feedback(gettext("Success"), 'success');
|
||||
},
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
|
||||
}
|
||||
})
|
||||
var popupTitle, popupContent;
|
||||
var owner = this.trashRepoCollection.search_owner;
|
||||
if (owner) {
|
||||
popupTitle = gettext("Delete Library By Owner");
|
||||
popupContent = gettext("Are you sure you want to delete all %s's libraries?").replace('%s', '<span class="op-target ellipsis ellipsis-op-target">' + Common.HTMLescape(owner) + '</span>');
|
||||
} else {
|
||||
popupTitle = gettext("Clear Trash");
|
||||
popupContent = gettext("Are you sure you want to clear trash?");
|
||||
}
|
||||
var yesCallback = function() {
|
||||
$.ajax({
|
||||
url: Common.getUrl({'name':'admin-trash-libraries'}),
|
||||
type: 'DELETE',
|
||||
data: {'owner': _this.option.owner},
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
dataType: 'json',
|
||||
success: function() {
|
||||
_this.$tip.hide();
|
||||
_this.$table.hide();
|
||||
_this.$emptyTip.show();
|
||||
Common.feedback(gettext("Success"), 'success');
|
||||
},
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
|
||||
},
|
||||
complete: function() {
|
||||
$.modal.close();
|
||||
}
|
||||
});
|
||||
};
|
||||
Common.showConfirm(popupTitle, popupContent, yesCallback);
|
||||
},
|
||||
|
||||
initPage: function() {
|
||||
this.$tip.hide();
|
||||
this.$table.hide();
|
||||
this.$tableBody.empty();
|
||||
this.$loadingTip.show();
|
||||
this.$emptyTip.hide();
|
||||
this.$cleanBtn.hide();
|
||||
},
|
||||
|
||||
hide: function() {
|
||||
this.$el.detach();
|
||||
this.attached = false;
|
||||
},
|
||||
|
||||
show: function(option) {
|
||||
this.option = option;
|
||||
this.render();
|
||||
$("#right-panel").html(this.$el);
|
||||
if (!this.attached) {
|
||||
this.attached = true;
|
||||
$("#right-panel").html(this.$el);
|
||||
}
|
||||
this.showTrashLibraries();
|
||||
},
|
||||
|
||||
@@ -76,8 +103,8 @@ define([
|
||||
var _this = this;
|
||||
|
||||
this.trashRepoCollection.fetch({
|
||||
data: {},
|
||||
cache: false, // for IE
|
||||
data: {'owner': this.option.owner},
|
||||
cache: false,
|
||||
reset: true,
|
||||
error: function (collection, response, opts) {
|
||||
var err_msg;
|
||||
@@ -102,9 +129,12 @@ define([
|
||||
|
||||
if (length > 0) {
|
||||
this.trashRepoCollection.each(this.addOne, this);
|
||||
this.$cleanBtn.show();
|
||||
this.$tip.show();
|
||||
this.$table.show();
|
||||
} else {
|
||||
this.$emptyTip.show();
|
||||
this.$cleanBtn.hide();
|
||||
}
|
||||
},
|
||||
|
||||
|
Reference in New Issue
Block a user