mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-09 19:01:42 +00:00
added group side nav
This commit is contained in:
@@ -453,3 +453,60 @@
|
||||
<td><a href="#my-libs/lib/<%= origin_repo_id %><%- origin_path %>"><%- abbrev_origin_path %></a></td>
|
||||
<td><%= mtime_relative %></td>
|
||||
</script>
|
||||
<script type="text/template" id="grp-side-nav-tmpl">
|
||||
<div class="hd w100 ovhd">
|
||||
<h3 class="fleft">
|
||||
<%= avatar %> <span title="<%- name %>" class="grp-name ellipsis vam"><%- name %></span>
|
||||
</h3>
|
||||
<% if (is_staff) { %>
|
||||
<img id="enable-mods" class="fright" title="{% trans "Enable Modules" %}" src="{{MEDIA_URL}}img/setting.png" alt="" style="margin:8px 0 0 5px;" />
|
||||
<% } %>
|
||||
<% if (is_pub) { %>
|
||||
<img src="{{MEDIA_URL}}img/grp_public.png" alt="" title="{% trans "This group is public." %}" class="fright" style="margin:8px 0 0 5px;" />
|
||||
<% } %>
|
||||
</div>
|
||||
<ul class="side-tabnav-tabs">
|
||||
<li class="tab tab-cur"><a href="#group/<%= id %>/" class="lib">{% trans "Libraries" %}</a></li>
|
||||
<li class="tab"><a href="{{ SITE_ROOT }}group/<%= id %>/discuss/" class="msgs">{% trans "Discussion" %}</a></li>
|
||||
|
||||
<% for (var i = 0, len = mods_enabled.length; i < len; i++) { %>
|
||||
<% if (mods_enabled[i] == 'group wiki') { %>
|
||||
<li class="tab"><a href="{{ SITE_ROOT }}group/<%= id %>/wiki/" class="wiki">{% trans "Wiki" %}</a></li>
|
||||
<% } %>
|
||||
<% } %>
|
||||
|
||||
<% if (app.pageOptions.enable_pubfile && is_pub) { %>
|
||||
<li class="tab"><a href="{{ SITE_ROOT }}group/<%= id %>/files/" class="files">{% trans "Files" %}</a></li>
|
||||
<% } %>
|
||||
|
||||
<% if (view_perm != 'pub') { %>
|
||||
<li class="tab"><a href="{{ SITE_ROOT }}group/<%= id %>/members/" class="members">{% trans "Members" %}</a></li>
|
||||
<% } %>
|
||||
|
||||
<% if (is_staff) { %>
|
||||
<li class="tab"><a href="{{ SITE_ROOT }}group/<%= id %>/manage/" class="admin">{% trans "Admin" %}</a></li>
|
||||
<% } %>
|
||||
</ul>
|
||||
</script>
|
||||
<script type="text/template" id="grp-mods-enable-form-tmpl">
|
||||
<form id="mods-enable-form" method="post" action="{{ SITE_ROOT }}group/<%= id %>/modules/toggle/" class="hide">{% csrf_token%}
|
||||
<h3>{% trans "Enable Modules"%}</h3>
|
||||
<ul>
|
||||
<% for (var i = 0, len = mods_available.length; i < len; i++) { %>
|
||||
<% if (mods_available[i] == 'group wiki') { %>
|
||||
<li>
|
||||
<label class="checkbox-label">
|
||||
<% if (mods_enabled.indexOf(mods_available[i]) != -1) { %>
|
||||
<span class="checkbox checkbox-checked"><input type="checkbox" name="group_wiki" class="checkbox-orig" checked="checked" /></span>
|
||||
<% } else { %>
|
||||
<span class="checkbox"><input type="checkbox" name="group_wiki" class="checkbox-orig" /></span>
|
||||
<% } %>
|
||||
<span class="checkbox-option">{% trans "Wiki" %}</span>
|
||||
</label>
|
||||
</li>
|
||||
<% } %>
|
||||
<% } %>
|
||||
</ul>
|
||||
<input type="submit" value="{% trans "Submit"%}" class="submit" />
|
||||
</form>
|
||||
</script>
|
||||
|
@@ -65,6 +65,9 @@
|
||||
<li class="tab"><a href="{% url 'pubuser' %}" class="members">{% trans "Members" %}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="side-tabnav hide" id="grp-side-nav">
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block right_panel %}
|
||||
|
@@ -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 %}
|
||||
};
|
||||
|
||||
</script>
|
||||
|
@@ -152,6 +152,7 @@ urlpatterns = patterns('',
|
||||
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/file_op_url/$', get_file_op_url, name='get_file_op_url'),
|
||||
url(r'^ajax/u/d/(?P<token>[-0-9a-f]{10})/upload/$', get_file_upload_url_ul, name='get_file_upload_url_ul'),
|
||||
url(r'^ajax/group/(?P<group_id>\d+)/repos/$', get_unenc_group_repos, name='get_group_repos'),
|
||||
url(r'^ajax/group/(?P<group_id>\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'),
|
||||
|
@@ -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)
|
||||
|
@@ -17,10 +17,6 @@ define([
|
||||
setGroupID: function(group_id) {
|
||||
this.group_id = group_id;
|
||||
}
|
||||
|
||||
// initialize: function( ) {
|
||||
|
||||
// },
|
||||
});
|
||||
|
||||
return GroupRepoCollection;
|
||||
|
75
static/scripts/app/views/group-side-nav.js
Normal file
75
static/scripts/app/views/group-side-nav.js
Normal file
@@ -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('<p class="error">' + err_msg + '</p>');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
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;
|
||||
});
|
@@ -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();
|
||||
}
|
||||
|
@@ -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/';
|
||||
}
|
||||
},
|
||||
|
||||
|
Reference in New Issue
Block a user