diff --git a/media/css/seahub.css b/media/css/seahub.css index 13052cf7cb..25b18c8ce4 100644 --- a/media/css/seahub.css +++ b/media/css/seahub.css @@ -3556,3 +3556,21 @@ textarea:-moz-placeholder {/* for FF */ .select2-result-label .text { vertical-align:middle; } + +/* add repo to public */ +#add-pubrepo-popup { + width:500px; +} +#add-pubrepo-popup table { + margin-bottom:8px; +} +#add-pubrepo-popup tbody { + display: block; + max-height: 150px; + width: 500px; + overflow-y: auto; + overflow-x: hidden; +} +button.add-pub-repo { + margin-right:10px; +} diff --git a/seahub/api2/views.py b/seahub/api2/views.py index eea01b3e1e..f8df44603b 100644 --- a/seahub/api2/views.py +++ b/seahub/api2/views.py @@ -2565,7 +2565,7 @@ class SharedRepo(APIView): """ Support uniform interface for shared libraries. """ - authentication_classes = (TokenAuthentication, ) + authentication_classes = (TokenAuthentication, SessionAuthentication ) permission_classes = (IsAuthenticated, ) throttle_classes = (UserRateThrottle, ) diff --git a/seahub/templates/js/templates.html b/seahub/templates/js/templates.html index 1cdb59b1aa..1666f92967 100644 --- a/seahub/templates/js/templates.html +++ b/seahub/templates/js/templates.html @@ -725,3 +725,40 @@ {% trans "Shared By" %} + + diff --git a/seahub/templates/libraries.html b/seahub/templates/libraries.html index a4c52fdde3..7665980fd9 100644 --- a/seahub/templates/libraries.html +++ b/seahub/templates/libraries.html @@ -185,6 +185,7 @@

{% trans "Libraries" %}

+
diff --git a/static/scripts/app/views/add-pub-repo.js b/static/scripts/app/views/add-pub-repo.js index 8108af011c..4243475be3 100644 --- a/static/scripts/app/views/add-pub-repo.js +++ b/static/scripts/app/views/add-pub-repo.js @@ -4,24 +4,81 @@ define([ 'underscore', 'backbone', 'common', - 'app/views/add-repo' -], function($, simplemodal, _, Backbone, Common, AddRepoView) { + 'app/collections/repos', + 'app/views/add-pubrepo-item' +], function($, simplemodal, _, Backbone, Common, + RepoCollection, AddPubrepoItem) { 'use strict'; - var AddPubRepoView = AddRepoView.extend({ - templateData: function() { - return { - showSharePerm: true - }; + var AddPubRepoView = Backbone.View.extend({ + id: 'add-pubrepo-popup', + + template: _.template($('#add-pubrepo-popup-tmpl').html()), + + initialize: function(pubRepos) { + this.$el.html(this.template()).modal({}); + $('#simplemodal-container').css({'width':'auto', 'height':'auto'}); + + this.$table = this.$('table'); + this.$tableBody = this.$('tbody'); + this.$loadingTip = this.$('.loading-tip'); + + this.myRepos = new RepoCollection(); + this.pubRepos = pubRepos; + + this.listenTo(this.myRepos, 'reset', this.reset); + this.myRepos.fetch({reset: true}); }, - newAttributes: function() { - var baseAttrs = AddRepoView.prototype.newAttributes.apply(this); - - return _.extend(baseAttrs, {'permission': $('select[name=permission]', this.$el).val()}); + events: { + 'click .submit': 'submit' }, + submit: function () { + var myRepos = this.myRepos.where({'selected':true}), + _this = this, + requests = []; + + _.each(myRepos, function (repo){ + var repo_id = repo.id, + perm = 'rw'; + + if (repo.has('pub_perm')) { + perm = repo.get('pub_perm'); + } + + requests.push( + $.ajax({ + url: Common.getUrl({'name':'shared_repos', 'repo_id': repo_id}) + '?share_type=public&permission=' + perm, + type: 'PUT', + beforeSend: Common.prepareCSRFToken, + dataType: 'json', + error: function(xhr, textStatus, errorThrown) { + Common.ajaxErrorHandler(xhr, textStatus, errorThrown); + } + }) + ); + }) + + var defer = $.when.apply($, requests); + defer.done(function () { + // when all ajax request complete + $.modal.close(); + _this.pubRepos.fetch({reset: true}); + }); + }, + + addOne: function(model) { + var view = new AddPubrepoItem({model: model}); + this.$tableBody.append(view.render().el); + }, + + reset: function() { + this.$loadingTip.hide(); + this.$table.show() + this.myRepos.each(this.addOne, this); + } + }); - return AddPubRepoView; }); diff --git a/static/scripts/app/views/add-pubrepo-item.js b/static/scripts/app/views/add-pubrepo-item.js new file mode 100644 index 0000000000..983cf27a4c --- /dev/null +++ b/static/scripts/app/views/add-pubrepo-item.js @@ -0,0 +1,45 @@ +define([ + 'jquery', + 'underscore', + 'backbone', + 'common' +], function($, _, Backbone, Common) { + 'use strict'; + + var AddPubrepoItem = Backbone.View.extend({ + tagName: 'tr', + + template: _.template($('#add-pubrepo-item-tmpl').html()), + + events: { + 'click .select': 'select', + 'change .share-permission-select': 'selectPerm' + }, + + initialize: function () { + }, + + selectPerm: function (e) { + var perm = $(e.currentTarget).val(); + this.model.set({'pub_perm': perm}, {silent:true}); + }, + + select: function () { + var checkbox = this.$('.checkbox'); + checkbox.toggleClass('checkbox-checked'); + if (checkbox.hasClass('checkbox-checked')) { + this.model.set({'selected':true}, {silent:true}); + } else { + this.model.set({'selected':false}, {silent:true}); + } + }, + + render: function () { + this.$el.html(this.template(this.model.toJSON())); + return this; + }, + + }); + + return AddPubrepoItem; +}); diff --git a/static/scripts/app/views/create-pub-repo.js b/static/scripts/app/views/create-pub-repo.js new file mode 100644 index 0000000000..8c87f8a304 --- /dev/null +++ b/static/scripts/app/views/create-pub-repo.js @@ -0,0 +1,27 @@ +define([ + 'jquery', + 'simplemodal', + 'underscore', + 'backbone', + 'common', + 'app/views/add-repo' +], function($, simplemodal, _, Backbone, Common, AddRepoView) { + 'use strict'; + + var CreatePubRepoView = AddRepoView.extend({ + templateData: function() { + return { + showSharePerm: true + }; + }, + + newAttributes: function() { + var baseAttrs = AddRepoView.prototype.newAttributes.apply(this); + + return _.extend(baseAttrs, {'permission': $('select[name=permission]', this.$el).val()}); + }, + + }); + + return CreatePubRepoView; +}); diff --git a/static/scripts/app/views/organization.js b/static/scripts/app/views/organization.js index 4024c4f9f8..fd52366502 100644 --- a/static/scripts/app/views/organization.js +++ b/static/scripts/app/views/organization.js @@ -5,9 +5,10 @@ define([ 'common', 'app/collections/pub-repos', 'app/views/organization-repo', + 'app/views/create-pub-repo', 'app/views/add-pub-repo' ], function($, _, Backbone, Common, PubRepoCollection, OrganizationRepoView, - AddPubRepoView) { + CreatePubRepoView, AddPubRepoView) { 'use strict'; var OrganizationView = Backbone.View.extend({ @@ -34,11 +35,16 @@ define([ events: { 'click #organization-repos .repo-create': 'createRepo', + 'click #organization-repos .add-pub-repo': 'addRepo', 'click #organization-repos .by-name': 'sortByName', 'click #organization-repos .by-time': 'sortByTime' }, createRepo: function() { + new CreatePubRepoView(this.repos); + }, + + addRepo: function() { new AddPubRepoView(this.repos); }, diff --git a/static/scripts/common.js b/static/scripts/common.js index 119bbb2253..144e3e5390 100644 --- a/static/scripts/common.js +++ b/static/scripts/common.js @@ -111,6 +111,7 @@ define([ 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/'; case 'starred_files': return siteRoot + 'api2/starredfiles/'; + case 'shared_repos': return siteRoot + 'api2/shared-repos/' + options.repo_id + '/'; } },