diff --git a/media/scripts/app/collections/group-repos.js b/media/scripts/app/collections/group-repos.js index 1a83428d4f..b8417aaa75 100644 --- a/media/scripts/app/collections/group-repos.js +++ b/media/scripts/app/collections/group-repos.js @@ -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(); diff --git a/media/scripts/app/models/group-repo.js b/media/scripts/app/models/group-repo.js index f97e15e830..f7fede00c7 100644 --- a/media/scripts/app/models/group-repo.js +++ b/media/scripts/app/models/group-repo.js @@ -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: "-" } }); diff --git a/media/scripts/app/routers/group.js b/media/scripts/app/routers/group.js index 9cd0a5324d..9f33046bee 100644 --- a/media/scripts/app/routers/group.js +++ b/media/scripts/app/routers/group.js @@ -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){ diff --git a/media/scripts/app/views/add-group-repo.js b/media/scripts/app/views/add-group-repo.js index 7b5fbc769e..6c6bcbbcab 100644 --- a/media/scripts/app/views/add-group-repo.js +++ b/media/scripts/app/views/add-group-repo.js @@ -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); diff --git a/media/scripts/app/views/group.js b/media/scripts/app/views/group.js index 8151dc9195..ff9de2d357 100644 --- a/media/scripts/app/views/group.js +++ b/media/scripts/app/views/group.js @@ -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(); } }); diff --git a/media/scripts/common.js b/media/scripts/common.js index 33d3e482d0..5fb7530e3e 100644 --- a/media/scripts/common.js +++ b/media/scripts/common.js @@ -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; diff --git a/seahub/api2/views.py b/seahub/api2/views.py index 1f41177475..deccb554de 100644 --- a/seahub/api2/views.py +++ b/seahub/api2/views.py @@ -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 diff --git a/seahub/group/templates/group/group_info.html b/seahub/group/templates/group/group_info.html index 8972386208..6df68c9f95 100644 --- a/seahub/group/templates/group/group_info.html +++ b/seahub/group/templates/group/group_info.html @@ -73,17 +73,20 @@ {% endif %}
- - - - - - - - - +

{% trans "Loading ..." %}

-

{% trans "Loading ..." %}

+
{% trans "Name" %} {% trans "Description" %}{% trans "Last Update" %} {% trans "Shared By" %}{% trans "Operations" %}
+ + + + + + + + + + +
{% trans "Name" %} {% trans "Description" %}{% trans "Last Update" %} {% trans "Shared By" %}{% trans "Operations" %}