diff --git a/media/scripts/app/main/organization.js b/media/scripts/app/main/organization.js new file mode 100644 index 0000000000..0d2d6ab58e --- /dev/null +++ b/media/scripts/app/main/organization.js @@ -0,0 +1,6 @@ +define([ + 'app/routers/organization' +], function(Router){ + new Router(); + Backbone.history.start(); +}); diff --git a/media/scripts/app/routers/organization.js b/media/scripts/app/routers/organization.js new file mode 100644 index 0000000000..c8c6b3ea23 --- /dev/null +++ b/media/scripts/app/routers/organization.js @@ -0,0 +1,30 @@ +/*global define*/ +define([ + 'jquery', + 'backbone', + 'app/views/organization' +], function($, Backbone, OrganizationView) { + "use strict"; + + var OrganizationRouter = Backbone.Router.extend({ + routes: { + 'libs/:id(/*path)': 'showDir', + // Default + '*actions': 'defaultAction' + }, + + initialize: function() { + this.organizationView = new OrganizationView(); + }, + + showDir: function() { + alert('todo'); + }, + + defaultAction: function(){ + this.organizationView.showPublicRepos(); + } + }); + + return OrganizationRouter; +}); diff --git a/media/scripts/app/views/myhome.js b/media/scripts/app/views/myhome.js index 9a37c00649..7e6e1bb337 100644 --- a/media/scripts/app/views/myhome.js +++ b/media/scripts/app/views/myhome.js @@ -54,12 +54,14 @@ define([ this.sharedReposView.hide(); this.reposView.show(); this.dirView.hide(); + $('#repo-create').show(); }, showSharedRepos: function() { this.dirView.hide(); this.reposView.hide(); this.sharedReposView.show(); + $('#repo-create').hide(); }, showDir: function(category, repo_id, path) { diff --git a/media/scripts/app/views/organization-repo.js b/media/scripts/app/views/organization-repo.js new file mode 100644 index 0000000000..0b11513bb3 --- /dev/null +++ b/media/scripts/app/views/organization-repo.js @@ -0,0 +1,70 @@ +define([ + 'jquery', + 'underscore', + 'backbone', + 'common', + 'text!' + app.config._tmplRoot + 'organization-repos.html' +], function($, _, Backbone, Common, reposTemplate) { + 'use strict'; + + var OrganizationRepoView = Backbone.View.extend({ + tagName: 'tr', + + template: _.template(reposTemplate), + + events: { + 'mouseenter': 'showAction', + 'mouseleave': 'hideAction', + 'click .cancel-share': 'removeShare' + }, + + initialize: function() { + }, + + removeShare: function(e) { + var _this = this, + success_callback = function(data) { + Common.feedback(gettext('Success'), 'success', Common.SUCCESS_TIMOUT); + _this.$el.remove(); + _this.collection.remove(_this.model, {silent: true}); + if (_this.collection.length == 0) { + $('#organization-repos table').hide(); + $('#organization-repos .empty-tips').show(); + }; + }; + + Common.ajaxGet({ + 'get_url': Common.getUrl({name: 'ajax_repo_remove_share'}), + 'data': { + 'repo_id': this.model.get('id'), + 'share_type': this.model.get('share_type') + }, + 'after_op_success': success_callback + }); + }, + + render: function() { + var data, show_unshare_btn; + if (this.model.get('share_from') == app.pageOptions.current_user || app.pageOptions.is_staff == true) { + show_unshare_btn = true; + } else { + show_unshare_btn = false; + }; + data = $.extend(this.model.toJSON(), {'show_unshare_btn': show_unshare_btn}); + this.$el.html(this.template(data)); + return this; + }, + + showAction: function() { + this.$el.addClass('hl'); + this.$el.find('.op-icon').removeClass('vh'); + }, + + hideAction: function() { + this.$el.removeClass('hl'); + this.$el.find('.op-icon').addClass('vh'); + } + }); + + return OrganizationRepoView; +}); diff --git a/media/scripts/app/views/organization.js b/media/scripts/app/views/organization.js new file mode 100644 index 0000000000..b99e0b2049 --- /dev/null +++ b/media/scripts/app/views/organization.js @@ -0,0 +1,63 @@ +define([ + 'jquery', + 'underscore', + 'backbone', + 'common', + 'app/collections/repos', + 'app/views/organization-repo' +], function($, _, Backbone, Common, RepoCollection, OrganizationRepoView) { + 'use strict'; + + var OrganizationView = Backbone.View.extend({ + el: '#main', + + initialize: function() { + + this.$table = $('#organization-repos table'); + this.$tableBody = $('tbody', this.$table); + this.$loadingTip = $('#organization-repos .loading-tip'); + this.$emptyTip = $('#organization-repos .empty-tips'); + + this.repos = new RepoCollection({type: 'org'}); + this.listenTo(this.repos, 'add', this.addOne); + this.listenTo(this.repos, 'reset', this.reset); + }, + + events: { + 'click #repo-create': 'createRepo' + }, + + createRepo: function() { + alert('todo'); + }, + + addOne: function(repo, collection, options) { + var view = new OrganizationRepoView({model: repo, collection: this.repos}); + if (options.prepend) { + this.$tableBody.prepend(view.render().el); + } else { + this.$tableBody.append(view.render().el); + } + }, + + reset: function() { + this.$tableBody.empty(); + this.repos.each(this.addOne, this); + if (this.repos.length) { + this.$emptyTip.hide(); + this.$table.show(); + } else { + this.$emptyTip.show(); + this.$table.hide(); + } + this.$loadingTip.hide(); + }, + + showPublicRepos: function() { + this.repos.fetch({reset: true}); + } + + }); + + return OrganizationView; +}); diff --git a/media/scripts/app/views/shared-repo.js b/media/scripts/app/views/shared-repo.js index e17054517d..49d804abe0 100644 --- a/media/scripts/app/views/shared-repo.js +++ b/media/scripts/app/views/shared-repo.js @@ -23,7 +23,7 @@ define([ removeShare: function(e) { var _this = this, - after_leave_success = function(data) { + success_callback = function(data) { Common.feedback(gettext('Success'), 'success', Common.SUCCESS_TIMOUT); _this.$el.remove(); _this.collection.remove(_this.model, {silent: true}); @@ -40,7 +40,7 @@ define([ 'from': this.model.get('owner'), 'share_type': this.model.get('share_type') }, - 'after_op_success': after_leave_success + 'after_op_success': success_callback }); }, diff --git a/media/scripts/organization.js b/media/scripts/organization.js new file mode 100644 index 0000000000..5546bc0906 --- /dev/null +++ b/media/scripts/organization.js @@ -0,0 +1,4 @@ +//Load common code that includes config, then load the app logic for this page. +require(['./common'], function (common) { + require(['app/main/organization']); +}); diff --git a/seahub/api2/views.py b/seahub/api2/views.py index 882d15bee6..7918ce4d25 100644 --- a/seahub/api2/views.py +++ b/seahub/api2/views.py @@ -622,10 +622,13 @@ class Repos(APIView): "desc": r.repo_desc, "owner": "Organization", "mtime": r.last_modified, + "mtime_relative": translate_seahub_time(r.last_modified), "root": r.root, "size": r.size, "encrypted": r.encrypted, "permission": r.permission, + "share_from": r.user, + "share_type": r.share_type, } if r.encrypted: repo["enc_version"] = commit.enc_version diff --git a/seahub/templates/js/organization-repos.html b/seahub/templates/js/organization-repos.html new file mode 100644 index 0000000000..caef9ab3b3 --- /dev/null +++ b/seahub/templates/js/organization-repos.html @@ -0,0 +1,23 @@ +{% load i18n %} +
- | {% trans "Name"%} | -{% trans "Description"%} | -{% trans "Last Update"%} | -{% trans "Share From"%} | -{% trans "Operations"%} | -
---|---|---|---|---|---|
- {% if repo.encrypted %}
- ![]() ![]() ![]() |
- {{ repo.props.repo_name }} | -{{ repo.props.repo_desc }} | -{% if repo.props.last_modified %}{{ repo.props.last_modified|translate_seahub_time }}{% else %}--{% endif %} | -{{ repo.props.user|email2nickname }} | -
- {% if request.user.is_staff or repo.share_from_me %}
- ![]() |
-
{% blocktrans %}You can create a public library by clicking "New Library" button, others can view and download this library.{% endblocktrans %}
+ +