diff --git a/seahub/templates/js/templates.html b/seahub/templates/js/templates.html
index c8aa53aafe..97c683b3ce 100644
--- a/seahub/templates/js/templates.html
+++ b/seahub/templates/js/templates.html
@@ -453,3 +453,60 @@
<%- abbrev_origin_path %> |
<%= mtime_relative %> |
+
+
diff --git a/seahub/templates/libraries.html b/seahub/templates/libraries.html
index a792a760bc..95ae6d7d9e 100644
--- a/seahub/templates/libraries.html
+++ b/seahub/templates/libraries.html
@@ -65,6 +65,9 @@
{% trans "Members" %}
+
+
+
{% endblock %}
{% block right_panel %}
diff --git a/seahub/templates/myhome.html b/seahub/templates/myhome.html
index fc86007650..115b6427d9 100644
--- a/seahub/templates/myhome.html
+++ b/seahub/templates/myhome.html
@@ -194,7 +194,7 @@ app["pageOptions"] = {
repo_password_min_length: {{ repo_password_min_length }},
enable_upload_folder: {% if enable_upload_folder %} true {% else %} false {% endif %},
max_upload_file_size: {% if max_upload_file_size %} {{ max_upload_file_size }} {% else %} '' {% endif %},
- repo_password_min_length: {{ repo_password_min_length }}
+ enable_pubfile: {% if enable_pubfile %} true {% else %} false {% endif %}
};
diff --git a/seahub/urls.py b/seahub/urls.py
index 63a9372141..3b472d390d 100644
--- a/seahub/urls.py
+++ b/seahub/urls.py
@@ -152,6 +152,7 @@ urlpatterns = patterns('',
url(r'^ajax/repo/(?P[-0-9a-f]{36})/file_op_url/$', get_file_op_url, name='get_file_op_url'),
url(r'^ajax/u/d/(?P[-0-9a-f]{10})/upload/$', get_file_upload_url_ul, name='get_file_upload_url_ul'),
url(r'^ajax/group/(?P\d+)/repos/$', get_unenc_group_repos, name='get_group_repos'),
+ url(r'^ajax/group/(?P\d+)/basic_info/$', get_group_basic_info, name='get_group_basic_info'),
url(r'^ajax/my-unenc-repos/$', get_my_unenc_repos, name='get_my_unenc_repos'),
url(r'^ajax/unenc-rw-repos/$', unenc_rw_repos, name='unenc_rw_repos'),
url(r'^ajax/contacts/$', get_contacts, name='get_contacts'),
diff --git a/seahub/views/ajax.py b/seahub/views/ajax.py
index 4a2c902ef2..56146a8dd6 100644
--- a/seahub/views/ajax.py
+++ b/seahub/views/ajax.py
@@ -32,6 +32,7 @@ from seahub.notifications.models import UserNotification
from seahub.notifications.views import add_notice_from_info
from seahub.message.models import UserMessage
from seahub.share.models import UploadLinkShare
+from seahub.group.models import PublicGroup
from seahub.signals import upload_file_successful, repo_created, repo_deleted
from seahub.views import get_repo_dirents_with_perm, validate_owner, \
check_repo_access_permission, get_unencry_rw_repos_by_user, \
@@ -39,6 +40,9 @@ from seahub.views import get_repo_dirents_with_perm, validate_owner, \
get_owned_repo_list, check_folder_permission
from seahub.views.repo import get_nav_path, get_fileshare, get_dir_share_link, \
get_uploadlink, get_dir_shared_upload_link
+from seahub.views.modules import get_enabled_mods_by_group, \
+ get_available_mods_by_group
+from seahub.group.views import is_group_staff
import seahub.settings as settings
from seahub.settings import ENABLE_THUMBNAIL, THUMBNAIL_ROOT, \
THUMBNAIL_DEFAULT_SIZE, ENABLE_SUB_LIBRARY, ENABLE_REPO_HISTORY_SETTING
@@ -56,6 +60,7 @@ from seahub.thumbnail.utils import get_thumbnail_src, allow_generate_thumbnail
from seahub.utils.file_types import IMAGE
from seahub.thumbnail.utils import get_thumbnail_src
from seahub.base.templatetags.seahub_tags import translate_seahub_time, file_icon_filter
+from seahub.avatar.templatetags.group_avatar_tags import grp_avatar
# Get an instance of a logger
logger = logging.getLogger(__name__)
@@ -2415,14 +2420,55 @@ def toggle_group_folder_permission(request, repo_id):
return HttpResponse(json.dumps({"error": e.msg}), status=500,
content_type=content_type)
+def get_group_basic_info(request, group_id):
+ '''
+ Get group basic info for group side nav
+ '''
+ if not request.is_ajax():
+ raise Http404
-def get_groups(request):
content_type = 'application/json; charset=utf-8'
+ result = {}
- groups = request.user.joined_groups
- group_list = []
- from seahub.avatar.templatetags.group_avatar_tags import grp_avatar
- for g in groups:
- group_list.append({"name": g.group_name, "id": g.id, "avatar": grp_avatar(g.id, 16)})
+ group_id_int = int(group_id) # Checked by URL Conf
+ group = get_group(group_id_int)
+ if not group:
+ result["error"] = _('Group does not exist.')
+ return HttpResponse(json.dumps(result),
+ status=400, content_type=content_type)
- return HttpResponse(json.dumps({"groups":group_list}), content_type=content_type)
+ group.is_staff = False
+ if PublicGroup.objects.filter(group_id=group.id):
+ group.is_pub = True
+ else:
+ group.is_pub = False
+
+ if not request.user.is_authenticated():
+ if group.is_pub:
+ group.view_perm = "pub"
+
+ joined = is_group_user(group_id_int, request.user.username)
+ if joined:
+ group.view_perm = "joined"
+ group.is_staff = is_group_staff(group, request.user)
+
+ if request.user.is_staff:
+ # viewed by system admin
+ group.view_perm = "sys_admin"
+
+ if group.is_pub:
+ group.view_perm = "pub"
+
+ mods_available = get_available_mods_by_group(group.id)
+ mods_enabled = get_enabled_mods_by_group(group.id)
+
+ return HttpResponse(json.dumps({
+ "id": group.id,
+ "name": group.group_name,
+ "avatar": grp_avatar(group.id, 32),
+ "is_staff": group.is_staff,
+ "is_pub": group.is_pub,
+ "view_perm": group.view_perm,
+ "mods_available": mods_available,
+ "mods_enabled": mods_enabled,
+ }), content_type=content_type)
diff --git a/static/scripts/app/collections/group-repos.js b/static/scripts/app/collections/group-repos.js
index d1c8fc304b..32703c4103 100644
--- a/static/scripts/app/collections/group-repos.js
+++ b/static/scripts/app/collections/group-repos.js
@@ -17,10 +17,6 @@ define([
setGroupID: function(group_id) {
this.group_id = group_id;
}
-
- // initialize: function( ) {
-
- // },
});
return GroupRepoCollection;
diff --git a/static/scripts/app/views/group-side-nav.js b/static/scripts/app/views/group-side-nav.js
new file mode 100644
index 0000000000..3129a6716c
--- /dev/null
+++ b/static/scripts/app/views/group-side-nav.js
@@ -0,0 +1,75 @@
+define([
+ 'jquery',
+ 'underscore',
+ 'backbone',
+ 'common'
+], function($, _, Backbone, Common) {
+ 'use strict';
+
+ var GroupSideNavView = Backbone.View.extend({
+ el: '#grp-side-nav',
+
+ template: _.template($("#grp-side-nav-tmpl").html()),
+ enableModTemplate: _.template($("#grp-mods-enable-form-tmpl").html()),
+
+ initialize: function() {
+ },
+
+ render: function (group_id) {
+ this.group_id = group_id;
+ var _this = this;
+ $.ajax({
+ url: Common.getUrl({
+ 'name': 'group_basic_info',
+ 'group_id': this.group_id
+ }),
+ cache: false,
+ dataType: 'json',
+ success: function (data) {
+ _this.$el.html(_this.template(data));
+ // for 'enable mod'
+ _this.mods_available = data.mods_available;
+ _this.mods_enabled = data.mods_enabled;
+ },
+ error: function(xhr) {
+ var err_msg;
+ if (xhr.responseText) {
+ err_msg = $.parseJSON(xhr.responseText).error;
+ } else {
+ err_msg = gettext("Please check the network.");
+ }
+ _this.$el.html('' + err_msg + '
');
+ }
+ });
+ },
+
+ events: {
+ 'click #enable-mods': 'enableMods'
+ },
+
+ enableMods: function () {
+ var form = $(this.enableModTemplate({
+ 'id': this.group_id,
+ 'mods_available': this.mods_available,
+ 'mods_enabled': this.mods_enabled
+ }));
+ form.modal();
+ $('#simplemodal-container').css('height', 'auto');
+ $('.checkbox-orig', form).click(function() {
+ $(this).parent().toggleClass('checkbox-checked');
+ });
+ // TODO: after form submit, page goes to http://127.0.0.1:8000/
+ },
+
+ show: function() {
+ this.$el.show();
+ },
+
+ hide: function() {
+ this.$el.hide();
+ }
+
+ });
+
+ return GroupSideNavView;
+});
diff --git a/static/scripts/app/views/group.js b/static/scripts/app/views/group.js
index 0c8ac576df..76c7eeebfd 100644
--- a/static/scripts/app/views/group.js
+++ b/static/scripts/app/views/group.js
@@ -9,9 +9,10 @@ define([
'app/views/add-group-repo',
'app/views/group-recent-change',
'app/views/dir',
+ 'app/views/group-side-nav'
], function($, _, Backbone, Common, GroupRepos, DirentCollection,
GroupRepoView, AddGroupRepoView, GroupRecentChangeView,
- DirView) {
+ DirView, GroupSideNavView) {
'use strict';
var GroupView = Backbone.View.extend({
@@ -32,6 +33,8 @@ define([
this.$emptyTip = $('.empty-tips', this.$tabs);
this.$createForm = this.$('#repo-create-form');
+ this.sideNavView = new GroupSideNavView();
+
this.repos = new GroupRepos();
this.listenTo(this.repos, 'add', this.addOne);
this.listenTo(this.repos, 'reset', this.reset);
@@ -39,20 +42,6 @@ define([
this.dirView = new DirView();
},
- /*
- 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); // XXX: really render table when recieve any event ?
- this.listenTo(Repos, 'all', this.all);
- },
- */
-
- all: function(event) {
- console.log('event: ' + event);
- },
-
addOne: function(repo, collection, options) {
var view = new GroupRepoView({model: repo, group_id: this.group_id});
if (options.prepend) {
@@ -75,8 +64,14 @@ define([
}
},
+ showSideNav: function () {
+ this.sideNavView.render(this.group_id);
+ this.sideNavView.show();
+ },
+
showRepoList: function(group_id) {
this.group_id = group_id;
+ this.showSideNav();
this.dirView.hide();
this.$tabs.show();
this.repos.setGroupID(group_id);
@@ -90,6 +85,7 @@ define([
showDir: function(group_id, repo_id, path) {
this.group_id = group_id;
+ this.showSideNav();
this.hideRepoList();
this.dirView.showDir('group/' + this.group_id, repo_id, path);
},
@@ -141,7 +137,7 @@ define([
},
hide: function() {
- console.log("hide group view");
+ this.sideNavView.hide();
this.hideRepoList();
this.dirView.hide();
}
diff --git a/static/scripts/common.js b/static/scripts/common.js
index b7b6de8944..dacd4266b2 100644
--- a/static/scripts/common.js
+++ b/static/scripts/common.js
@@ -110,6 +110,7 @@ define([
case 'repo_set_password': return siteRoot + 'repo/set_password/';
case 'group_repos': return siteRoot + 'api2/groups/' + options.group_id + '/repos/';
+ case 'group_basic_info': return siteRoot + 'ajax/group/' + options.group_id + '/basic_info/';
}
},