mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-01 23:20:51 +00:00
Enable create group repo
This commit is contained in:
@@ -7,7 +7,15 @@ define([
|
||||
|
||||
var GroupRepoCollection = Backbone.Collection.extend({
|
||||
model: GroupRepo,
|
||||
url: app.pageOptions.groupReposUrl
|
||||
url: app.pageOptions.groupReposUrl,
|
||||
|
||||
comparator: -'mtime',
|
||||
|
||||
// initialize: function( ) {
|
||||
|
||||
// },
|
||||
|
||||
|
||||
});
|
||||
|
||||
return new GroupRepoCollection();
|
||||
|
@@ -7,13 +7,14 @@ define([
|
||||
var GroupRepo = Backbone.Model.extend({
|
||||
|
||||
defaults: {
|
||||
id: "",
|
||||
id: null,
|
||||
name: "",
|
||||
desc: "",
|
||||
mtime: "",
|
||||
mtime: 0,
|
||||
encrypted: false,
|
||||
permission: "",
|
||||
owner: gettext("Unknown")
|
||||
permission: "r",
|
||||
owner: "-",
|
||||
owner_nickname: "-"
|
||||
}
|
||||
|
||||
});
|
||||
|
@@ -17,7 +17,7 @@ define([
|
||||
|
||||
showDirents: function(id, path){
|
||||
console.log("Repo route has been called.." + "id:" + id + " path:" + path);
|
||||
new GroupView().showDirentList(id, path);
|
||||
// new GroupView().showDirentList(id, path);
|
||||
},
|
||||
|
||||
defaultAction: function(actions){
|
||||
|
@@ -36,8 +36,14 @@ define([
|
||||
// Generate the attributes for a new GroupRepo item.
|
||||
newAttributes: function() {
|
||||
return {
|
||||
name: 'foo',
|
||||
desc: 'bar'
|
||||
name: $('input[name=repo_name]', this.$el).val().trim(),
|
||||
desc: $('textarea[name=repo_desc]', this.$el).val().trim(),
|
||||
permission: $('select[name=permission]', this.$el).val(),
|
||||
|
||||
// TODO: encrypted repo
|
||||
// encrypted: $('#encrypt-switch', this.$el).attr('checked'),
|
||||
// passwd1: $('input[name=passwd]', this.$el).val(),
|
||||
// passwd2: $('input[name=passwd_again]', this.$el).val()
|
||||
};
|
||||
},
|
||||
|
||||
@@ -47,8 +53,9 @@ define([
|
||||
Common.feedback('Loading...', 'info', Common.INFO_TIMEOUT);
|
||||
GroupRepos.create(this.newAttributes(), {
|
||||
wait: true,
|
||||
prepend: true, // show newly created repo at first line
|
||||
success: function() {
|
||||
|
||||
Common.feedback('Success', 'success', Common.SUCCESS_TIMEOUT);
|
||||
},
|
||||
error: function() {
|
||||
Common.feedback('Error', 'error', Common.ERROR_TIMEOUT);
|
||||
|
@@ -2,72 +2,56 @@ define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'app/collections/group-repos',
|
||||
'app/collections/dirents',
|
||||
'app/views/group-repos',
|
||||
'app/views/add-group-repo',
|
||||
'app/views/dirents'
|
||||
], function($, _, Backbone, Repos, DirentCollection, GroupRepoView, AddGroupRepoView, DirentView) {
|
||||
'app/views/add-group-repo'
|
||||
// 'app/views/dirents'
|
||||
], function($, _, Backbone, Common, Repos, DirentCollection, GroupRepoView, AddGroupRepoView/*, DirentView*/) {
|
||||
'use strict';
|
||||
|
||||
var GroupView = Backbone.View.extend({
|
||||
el: '#main',
|
||||
|
||||
prepareCsrf: function() { // TODO: move to common
|
||||
/* alias away the sync method */
|
||||
Backbone._sync = Backbone.sync;
|
||||
|
||||
/* define a new sync method */
|
||||
Backbone.sync = function(method, model, options) {
|
||||
|
||||
/* only need a token for non-get requests */
|
||||
if (method == 'create' || method == 'update' || method == 'delete') {
|
||||
// CSRF token value is in an embedded meta tag
|
||||
// var csrfToken = $("meta[name='csrf_token']").attr('content');
|
||||
var csrfToken = app.pageOptions.csrfToken;
|
||||
|
||||
options.beforeSend = function(xhr){
|
||||
xhr.setRequestHeader('X-CSRFToken', csrfToken);
|
||||
};
|
||||
}
|
||||
|
||||
/* proxy the call to the old sync method */
|
||||
return Backbone._sync(method, model, options);
|
||||
};
|
||||
},
|
||||
|
||||
events: {
|
||||
'click #repo-create': 'createRepo',
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
this.prepareCsrf();
|
||||
Common.prepareApiCsrf();
|
||||
|
||||
this.$cont = this.$('#right-panel');
|
||||
|
||||
this.$tab = this.$('#tabs div:first-child');
|
||||
this.$tabCont = this.$('#grp-repos');
|
||||
this.$tableCont = this.$('#grp-repos table');
|
||||
|
||||
this.$table = this.$('#grp-repos table');
|
||||
this.$tableHead = $('thead', this.$table);
|
||||
this.$tableBody = $('tbody', this.$table);
|
||||
|
||||
this.$createForm = this.$('#repo-create-form');
|
||||
},
|
||||
|
||||
initializeRepos: function() {
|
||||
this.listenTo(Repos, 'add', this.addOne);
|
||||
this.listenTo(Repos, 'reset', this.addAll);
|
||||
this.listenTo(Repos, 'sync', this.render);
|
||||
// this.listenTo(Repos, 'all', this.render);
|
||||
// this.listenTo(Repos, 'sync', this.render);
|
||||
this.listenTo(Repos, 'all', this.render); // XXX: really render table when recieve any event ?
|
||||
},
|
||||
|
||||
initializeDirents: function() {
|
||||
this.listenTo(this.dirents, 'add', this.addOneDirent);
|
||||
this.listenTo(this.dirents, 'reset', this.addAllDirent);
|
||||
// this.listenTo(this.dirents, 'sync', this.render);
|
||||
this.listenTo(this.dirents, 'all', this.renderDirent);
|
||||
all: function(event) {
|
||||
console.log('event: ' + event);
|
||||
},
|
||||
|
||||
addOne: function(repo) {
|
||||
console.log('add repo: ' + repo);
|
||||
addOne: function(repo, collection, options) {
|
||||
console.log('add repo: ' + repo.get('name'));
|
||||
var view = new GroupRepoView({model: repo});
|
||||
this.$tableCont.append(view.render().el);
|
||||
if (options.prepend) {
|
||||
this.$tableBody.before(view.render().el);
|
||||
} else {
|
||||
this.$tableBody.append(view.render().el);
|
||||
}
|
||||
},
|
||||
|
||||
addAll: function() {
|
||||
@@ -76,38 +60,18 @@ define([
|
||||
Repos.each(this.addOne, this);
|
||||
},
|
||||
|
||||
addOneDirent: function(dirent) {
|
||||
var view = new DirentView({model: dirent});
|
||||
this.$tableCont.append(view.render().el);
|
||||
},
|
||||
|
||||
addAllDirent: function() {
|
||||
this.$tableCont.empty();
|
||||
this.dirents.each(this.addOneDirent, this);
|
||||
},
|
||||
|
||||
renderDirent: function(eventName) {
|
||||
console.log('render dirents with event: ' + eventName);
|
||||
if (this.dirents.length) {
|
||||
this.$tabCont.show();
|
||||
}
|
||||
},
|
||||
|
||||
// Reset table by empty table body.
|
||||
resetTable: function() {
|
||||
console.log('rest table');
|
||||
_.each($('#grp-repos table').find('tr'), function(el, idx) {
|
||||
if (idx != 0) {
|
||||
$(el).remove(); // remove table content except first row.
|
||||
}
|
||||
});
|
||||
this.$tableBody.empty();
|
||||
},
|
||||
|
||||
hideTable: function() {
|
||||
this.$tableCont.hide();
|
||||
this.$table.hide();
|
||||
},
|
||||
|
||||
showTable: function() {
|
||||
this.$tableCont.show();
|
||||
this.$table.show();
|
||||
},
|
||||
|
||||
hideLoading: function() {
|
||||
@@ -126,13 +90,16 @@ define([
|
||||
this.$cont.find('.empty-tips').show();
|
||||
},
|
||||
|
||||
render: function(eventName) {
|
||||
render: function(event) {
|
||||
console.log('got event: ' + event + ', render repo list...' );
|
||||
|
||||
this.hideLoading();
|
||||
if (Repos.length) {
|
||||
this.hideEmptyTips();
|
||||
this.showTable();
|
||||
} else {
|
||||
this.showEmptyTips();
|
||||
this.hideTable();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -141,22 +108,8 @@ define([
|
||||
Repos.fetch({reset: true});
|
||||
},
|
||||
|
||||
showDirentList: function(id, path) {
|
||||
console.log('show repo page and hide repo list: ' + id + ' ' + path);
|
||||
|
||||
var path = path || '/';
|
||||
this.dirents = new DirentCollection(id, path);
|
||||
this.initializeDirents();
|
||||
|
||||
this.dirents.fetch({reset: true});
|
||||
|
||||
// this.dirent_list = new app.DirentListView({id: id, path: path});
|
||||
// $('#my-own-repos table').children().remove();
|
||||
// $('#my-own-repos table').append(this.dirent_list.render().el);
|
||||
},
|
||||
|
||||
createRepo: function() {
|
||||
var view = new AddGroupRepoView();
|
||||
new AddGroupRepoView();
|
||||
}
|
||||
|
||||
});
|
||||
|
@@ -130,6 +130,29 @@ define([
|
||||
}
|
||||
},
|
||||
|
||||
prepareApiCsrf: function() {
|
||||
/* alias away the sync method */
|
||||
Backbone._sync = Backbone.sync;
|
||||
|
||||
/* define a new sync method */
|
||||
Backbone.sync = function(method, model, options) {
|
||||
|
||||
/* only need a token for non-get requests */
|
||||
if (method == 'create' || method == 'update' || method == 'delete') {
|
||||
// CSRF token value is in an embedded meta tag
|
||||
// var csrfToken = $("meta[name='csrf_token']").attr('content');
|
||||
var csrfToken = app.pageOptions.csrfToken;
|
||||
|
||||
options.beforeSend = function(xhr){
|
||||
xhr.setRequestHeader('X-CSRFToken', csrfToken);
|
||||
};
|
||||
}
|
||||
|
||||
/* proxy the call to the old sync method */
|
||||
return Backbone._sync(method, model, options);
|
||||
};
|
||||
},
|
||||
|
||||
prepareCSRFToken: function(xhr, settings) {
|
||||
function getCookie(name) {
|
||||
var cookieValue = null;
|
||||
|
@@ -64,7 +64,7 @@ from seahub.utils import gen_file_get_url, gen_token, gen_file_upload_url, \
|
||||
get_user_events, EMPTY_SHA1, get_ccnet_server_addr_port, \
|
||||
gen_block_get_url, get_file_type_and_ext, HAS_FILE_SEARCH, \
|
||||
gen_file_share_link, gen_dir_share_link, is_org_context, gen_shared_link, \
|
||||
get_org_user_events
|
||||
get_org_user_events, calculate_repos_last_modify
|
||||
from seahub.utils.star import star_file, unstar_file
|
||||
from seahub.utils.file_types import IMAGE, DOCUMENT
|
||||
from seahub.utils.timeutils import utc_to_local
|
||||
@@ -2863,7 +2863,33 @@ class GroupRepos(APIView):
|
||||
|
||||
def post(self, request, group_id, format=None):
|
||||
# add group repo
|
||||
assert False
|
||||
|
||||
# TODO: perm check
|
||||
|
||||
username = request.user.username
|
||||
repo_name = request.DATA.get("name", None)
|
||||
repo_desc = request.DATA.get("desc", 'new repo')
|
||||
permission = request.DATA.get("permission", 'r')
|
||||
|
||||
repo_id = seafile_api.create_repo(repo_name, repo_desc,
|
||||
username, None)
|
||||
repo = seafile_api.get_repo(repo_id)
|
||||
calculate_repos_last_modify([repo])
|
||||
|
||||
seafile_api.set_group_repo(repo.id, int(group_id), username, permission)
|
||||
|
||||
group_repo = {
|
||||
"id": repo.id,
|
||||
"name": repo.name,
|
||||
"desc": repo.desc,
|
||||
"mtime": repo.latest_modify,
|
||||
"encrypted": repo.encrypted,
|
||||
"permission": 'rw', # Always have read-write permission to owned repo
|
||||
"owner": username,
|
||||
"owner_nickname": email2nickname(username)
|
||||
}
|
||||
|
||||
return Response(group_repo, status=200)
|
||||
|
||||
def get(self, request, group_id, format=None):
|
||||
username = request.user.username
|
||||
|
@@ -73,7 +73,10 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
<div id="grp-repos">
|
||||
<p class="loading">{% trans "Loading ..." %}</p>
|
||||
|
||||
<table style="display:none">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="4%"><!--icon--></th>
|
||||
<th width="20%">{% trans "Name" %} <span id="grp-repo-list-name-down" class="icon-caret-up cspt"></span> <span id="grp-repo-list-name-up" class="icon-caret-down cspt hide"></span></th>
|
||||
@@ -82,8 +85,8 @@
|
||||
<th width="14%">{% trans "Shared By" %}</th>
|
||||
<th width="13%">{% trans "Operations" %}</th>
|
||||
</tr>
|
||||
|
||||
<p class="loading">{% trans "Loading ..." %}</p>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
|
||||
<div class="empty-tips" style="margin-bottom:150px; display:none;">
|
||||
|
Reference in New Issue
Block a user