1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 15:09:14 +00:00

admin search group by name

This commit is contained in:
lian
2017-01-19 17:24:00 +08:00
parent 622fe2705e
commit d43a2e5eb3
9 changed files with 236 additions and 5 deletions

View File

@@ -0,0 +1,24 @@
define([
'underscore',
'backbone',
'common',
'sysadmin-app/models/group'
], function(_, Backbone, Common, GroupModel) {
'use strict';
var GroupCollection = Backbone.Collection.extend({
model: GroupModel,
url: function () {
return Common.getUrl({name: 'admin-groups'});
},
parse: function(data) {
this.search_name = data.name;
return data.groups;
}
});
return GroupCollection;
});

View File

@@ -15,11 +15,13 @@ define([
'sysadmin-app/views/search-trash-repos',
'sysadmin-app/views/dir',
'sysadmin-app/views/groups',
'sysadmin-app/views/search-groups',
'app/views/account'
], function($, Backbone, Common, SideNavView, DashboardView,
DesktopDevicesView, MobileDevicesView, DeviceErrorsView,
ReposView, SearchReposView, SystemReposView, TrashReposView,
SearchTrashReposView, DirView, GroupsView, AccountView) {
SearchTrashReposView, DirView, GroupsView, SearchGroupsView,
AccountView) {
"use strict";
@@ -37,6 +39,7 @@ define([
'search-trash-libs/': 'showSearchTrashLibraries',
'libs/:repo_id(/*path)': 'showLibraryDir',
'groups/': 'showGroups',
'search-groups/': 'showSearchGroups',
// Default
'*actions': 'showDashboard'
},
@@ -65,6 +68,7 @@ define([
this.dirView = new DirView();
this.groupsView = new GroupsView();
this.searchGroupsView = new SearchGroupsView();
app.ui.accountView = this.accountView = new AccountView();
@@ -189,6 +193,18 @@ define([
this.switchCurrentView(this.groupsView);
this.sideNavView.setCurTab('groups');
this.groupsView.show({'page': page});
},
showSearchGroups: function() {
// url_match: null or an array
var url_match = location.href.match(/.*?name=(.*)/); // search by group_name
var group_name = url_match ? url_match[1] : '';
this.switchCurrentView(this.searchGroupsView);
this.sideNavView.setCurTab('groups', {'option': 'search'});
this.searchGroupsView.show({
'name': decodeURIComponent(group_name)
});
}
});

View File

@@ -0,0 +1,119 @@
define([
'jquery',
'underscore',
'backbone',
'common',
'sysadmin-app/views/group',
'sysadmin-app/collection/search-groups'
], function($, _, Backbone, Common, GroupView, GroupCollection) {
'use strict';
var GroupsView = Backbone.View.extend({
id: 'search-groups',
template: _.template($("#search-groups-tmpl").html()),
initialize: function() {
this.groupCollection = new GroupCollection();
this.listenTo(this.groupCollection, 'add', this.addOne);
this.listenTo(this.groupCollection, 'reset', this.reset);
this.render();
},
render: function() {
this.$el.append(this.template());
this.$form = this.$('#search-group-form');
this.$name = $('[name="name"]', this.$form);
this.$table = this.$('table');
this.$tableBody = $('tbody', this.$table);
this.$loadingTip = this.$('.loading-tip');
this.$emptyTip = this.$('.empty-tips');
},
events: {
'submit #search-group-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.groupCollection.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.groupCollection.search_name;
app.router.navigate('#search-groups/?name=' + encodeURIComponent(name));
this.$name.val(name);
this.$loadingTip.hide();
if (this.groupCollection.length > 0) {
this.groupCollection.each(this.addOne, this);
this.$table.show();
} else {
this.$emptyTip.show();
}
},
addOne: function(group) {
var view = new GroupView({model: group});
this.$tableBody.append(view.render().el);
},
formSubmit: function() {
var name = $.trim(this.$name.val());
if (!name) {
return false;
}
this.getContent({'name': name});
return false;
}
});
return GroupsView;
});

View File

@@ -35,13 +35,14 @@ define([
events: {
'submit #libs-search-form': 'searchLibs', // for 'all' libs
'submit #trash-libs-search-form': 'searchTrashLibs'
'submit #trash-libs-search-form': 'searchTrashLibs',
'submit #groups-search-form': 'searchGroups'
},
// search libs by repo_name
searchLibs: function() {
var $form = this.$('#libs-search-form');
var name = $.trim($('[name="name"]', $form).val());
var name = $.trim($('[name="name"]', $form).val());
if (!name) {
return false;
}
@@ -54,7 +55,7 @@ define([
// search trash libs by owner
searchTrashLibs: function() {
var $form = this.$('#trash-libs-search-form');
var owner = $.trim($('[name="name"]', $form).val());
var owner = $.trim($('[name="name"]', $form).val());
if (!owner) {
return false;
}
@@ -62,6 +63,18 @@ define([
var url = $form.attr('action') + '?name=' + encodeURIComponent(owner);
location.href = url;
return false; // necessary
},
searchGroups: function() {
var $form = this.$('#groups-search-form');
var name = $.trim($('[name="name"]', $form).val());
if (!name) {
return false;
}
var url = $form.attr('action') + '?name=' + encodeURIComponent(name);
location.href = url;
return false; // necessary
}
});