1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-06 01:12:03 +00:00

enable/disable personal wiki

This commit is contained in:
lian
2015-04-15 09:36:42 +08:00
committed by Daniel Pan
parent 92d8ee3c8d
commit 66e938868a
8 changed files with 188 additions and 41 deletions

View File

@@ -2148,6 +2148,7 @@ textarea:-moz-placeholder {/* for FF */
height:80px;
padding:2px;
}
#myhome-mods-enable-form,
#mods-enable-form {
width:266px;
}
@@ -3223,11 +3224,13 @@ textarea:-moz-placeholder {/* for FF */
#search-user-form .submit {
margin-left:3.5em;
}
#myhome-enable-mods,
#enable-mods,
#edit-index {
color:#d7d7d7;
margin-top:3px;
}
#myhome-enable-mods:hover,
#enable-mods:hover,
#edit-index:hover {
color:#666;

View File

@@ -453,6 +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="myhome-side-nav-tmpl">
<div class="hd w100 ovhd">
<h3 class="fleft">{% trans "Personal" %}</h3>
<img id="myhome-enable-mods" class="fright" title="{% trans "Enable Modules" %}" src="{{MEDIA_URL}}img/setting.png" alt="" />
</div>
<ul class="side-tabnav-tabs">
<li class="tab tab-cur"><a href="{{ SITE_ROOT }}#my-libs/" class="lib">{% trans "Libraries" %}</a></li>
<li class="tab"><a href="{{ SITE_ROOT }}starred/" class="star">{% trans "Starred" %}</a></li>
<% if (events_enabled) { %>
<li class="tab"><a href="{{ SITE_ROOT }}activities/" class="activity">{% trans "Activities" %}</a></li>
<% } %>
<% for (var i = 0, len = mods_enabled.length; i < len; i++) { %>
<% if (mods_enabled[i] == 'personal wiki') { %>
<li class="tab"><a href="{{ SITE_ROOT }}home/wiki/" class="wiki">{% trans "Personal Wiki" %}</a></li>
<% } %>
<% } %>
<li class="tab"><a href="{{ SITE_ROOT }}message/list/" class="msgs">{% trans "Messages" %}</a></li>
<li class="tab"><a href="{{ SITE_ROOT }}devices/" class="clients">{% trans "Devices" %}</a></li>
<li class="tab"><a href="{{ SITE_ROOT }}contacts/" class="contacts">{% trans "Contacts" %}</a></li>
</ul>
<h3 class="hd">{% trans "Share Admin" %}</h3>
<ul class="side-tabnav-tabs">
<li class="tab"><a href="{{ SITE_ROOT }}share/" class="lib">{% trans "Libraries" %}</a></li>
<li class="tab"><a href="{{ SITE_ROOT }}share/folders/" class="folders">{% trans "Folders" %}</a></li>
<li class="tab"><a href="{{ SITE_ROOT }}share/files/" class="files">{% trans "Files" %}</a></li>
<li class="tab"><a href="{{ SITE_ROOT }}share/links/" class="links">{% trans "Links" %}</a></li>
</ul>
</script>
<script type="text/template" id="myhome-mods-enable-form-tmpl">
<form id="myhome-mods-enable-form" method="post" action="" 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] == 'personal wiki') { %>
<li>
<label class="checkbox-label">
<% if (mods_enabled.indexOf(mods_available[i]) != -1) { %>
<span class="checkbox checkbox-checked"><input type="checkbox" name="personal_wiki" class="checkbox-orig" checked="checked" /></span>
<% } else { %>
<span class="checkbox"><input type="checkbox" name="personal_wiki" class="checkbox-orig" /></span>
<% } %>
<span class="checkbox-option">{% trans "Personal Wiki" %}</span>
</label>
</li>
<% } %>
<% } %>
</ul>
<input type="submit" value="{% trans "Submit"%}" class="submit" />
</form>
</script>
<script type="text/template" id="group-side-nav-tmpl">
<div class="hd w100 ovhd">
<h3 class="fleft">

View File

@@ -24,39 +24,9 @@
{% block left_panel %}
<div class="side-tabnav hide" id="myhome-side-nav">
<div class="hd w100 ovhd">
<h3 class="fleft">{% trans "Personal" %}</h3>
{% if user.permissions.can_add_repo %}
<img id="enable-mods" class="fright" title="{% trans "Enable Modules" %}" src="{{MEDIA_URL}}img/setting.png" alt="" />
{% endif %}
</div>
<ul class="side-tabnav-tabs">
<li class="tab tab-cur"><a href="{{ SITE_ROOT }}#my-libs/" class="lib">{% trans "Libraries" %}</a></li>
<li class="tab"><a href="{% url 'starred' %}" class="star">{% trans "Starred" %}</a></li>
{% if events_enabled %}
<li class="tab"><a href="{% url 'activities' %}" class="activity">{% trans "Activities" %}</a></li>
{% endif %}
{% for mod in request.user.mods_enabled %}
{% if mod == 'personal wiki' %}
<li class="tab"><a href="{% url 'personal_wiki' %}" class="wiki">{% trans "Personal Wiki" %}</a></li>
{% endif %}
{% endfor %}
<li class="tab"><a href="{% url 'message_list' %}" class="msgs">{% trans "Messages" %}</a></li>
<li class="tab"><a href="{% url 'devices' %}" class="clients">{% trans "Devices" %}</a></li>
<li class="tab"><a href="{% url 'contacts' %}" class="contacts">{% trans "Contacts" %}</a></li>
</ul>
<h3 class="hd">{% trans "Share Admin" %}</h3>
<ul class="side-tabnav-tabs">
{% if user.permissions.can_add_repo %}
<li class="tab"><a href="{% url 'share_admin' %}" class="lib">{% trans "Libraries" %}</a></li>
<li class="tab"><a href="{% url 'list_priv_shared_folders' %}" class="folders">{% trans "Folders" %}</a></li>
{% endif %}
<li class="tab"><a href="{% url 'list_priv_shared_files' %}" class="files">{% trans "Files" %}</a></li>
<li class="tab"><a href="{% url 'list_shared_links' %}" class="links">{% trans "Links" %}</a></li>
</ul>
</div>
<div class="side-tabnav hide" id="grp-side-nav">
</div>
<div class="side-tabnav hide" id="org-side-nav">
<h3 class="hd">{% trans "Organization" %}</h3>
<ul class="side-tabnav-tabs">
@@ -65,9 +35,6 @@
<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 %}
@@ -265,7 +232,22 @@ app["pageOptions"] = {
{% endfor %}
return groups;
})(),
user_mods_available: (function () {
var mods_available = [];
{% for mod in request.user.mods_available %}
mods_available.push('{{mod}}');
{% endfor %}
return mods_available;
})(),
user_mods_enabled: (function () {
var mods_enabled = [];
{% for mod in request.user.mods_enabled %}
mods_enabled.push('{{mod}}');
{% endfor %}
return mods_enabled;
})(),
username: "{{request.user.username}}",
events_enabled: {% if events_enabled %} true {% else %} false {% endif %},
is_staff: {% if request.user.is_staff %} true {% else %} false {% endif %},
repo_password_min_length: {{ repo_password_min_length }},
enable_upload_folder: {% if enable_upload_folder %} true {% else %} false {% endif %},

View File

@@ -153,6 +153,7 @@ urlpatterns = patterns('',
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/group/(?P<group_id>\d+)/toggle-modules/$', toggle_group_modules, name='toggle_group_modules'),
url(r'^ajax/toggle-personal-modules/$', toggle_personal_modules, name='toggle_personal_modules'),
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'),

View File

@@ -42,7 +42,8 @@ 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, enable_mod_for_group, \
disable_mod_for_group, MOD_GROUP_WIKI
disable_mod_for_group, MOD_GROUP_WIKI, MOD_PERSONAL_WIKI, \
enable_mod_for_user, disable_mod_for_user
from seahub.group.views import is_group_staff
import seahub.settings as settings
from seahub.settings import ENABLE_THUMBNAIL, THUMBNAIL_ROOT, \
@@ -2484,3 +2485,19 @@ def toggle_group_modules(request, group_id):
return HttpResponse(json.dumps({
"success": True
}), content_type=content_type)
@login_required_ajax
def toggle_personal_modules(request):
content_type = 'application/json; charset=utf-8'
result = {}
username = request.user.username
personal_wiki = request.POST.get('personal_wiki', '')
if personal_wiki == 'true':
enable_mod_for_user(username, MOD_PERSONAL_WIKI)
else:
disable_mod_for_user(username, MOD_PERSONAL_WIKI)
return HttpResponse(json.dumps({ "success": True
}), content_type=content_type)

View File

@@ -0,0 +1,89 @@
define([
'jquery',
'underscore',
'backbone',
'common'
], function($, _, Backbone, Common) {
'use strict';
var MyhomeSideNavView = Backbone.View.extend({
el: '#myhome-side-nav',
template: _.template($("#myhome-side-nav-tmpl").html()),
enableModTemplate: _.template($("#myhome-mods-enable-form-tmpl").html()),
initialize: function() {
this.render();
},
render: function() {
this.$el.html(this.template({
'mods_enabled': app.pageOptions.user_mods_enabled,
'events_enabled': app.pageOptions.events_enabled
}));
},
events: {
'click #myhome-enable-mods': 'enableMods'
},
enableMods: function () {
var form = $(this.enableModTemplate({
'mods_available': app.pageOptions.user_mods_available,
'mods_enabled': app.pageOptions.user_mods_enabled
}));
form.modal();
$('#simplemodal-container').css('height', 'auto');
$('.checkbox-orig', form).click(function() {
$(this).parent().toggleClass('checkbox-checked');
});
var checkbox = $('[name="personal_wiki"]'),
original_checked = checkbox.prop('checked'),
_this = this;
form.submit(function() {
var cur_checked = checkbox.prop('checked');
if (cur_checked == original_checked) {
return false;
}
Common.ajaxPost({
form: form,
form_id: form.attr('id'),
post_url: Common.getUrl({
'name': 'toggle_personal_modules',
}),
post_data: {'personal_wiki': cur_checked },
after_op_success: function () {
if (cur_checked) {
// enable personal wiki
app.pageOptions.user_mods_enabled.push('personal wiki');
} else {
// disable personal wiki
var index = app.pageOptions.user_mods_enabled.indexOf('personal wiki');
if (index > -1) {
app.pageOptions.user_mods_enabled.splice(index, 1);
}
}
$.modal.close();
_this.render();
}
});
return false;
});
},
show: function() {
this.$el.show();
},
hide: function() {
this.$el.hide();
}
});
return MyhomeSideNavView;
});

View File

@@ -8,8 +8,9 @@ define([
'app/views/myhome-sub-repos',
'app/views/myhome-shared-repos',
'app/views/dir',
'app/views/myhome-side-nav'
], function($, _, Backbone, Common, GroupCollection,
ReposView, SubReposView, SharedReposView, DirView) {
ReposView, SubReposView, SharedReposView, DirView, MyhomeSideNavView) {
'use strict';
var MyHomeView = Backbone.View.extend({
@@ -18,8 +19,7 @@ define([
initialize: function() {
this.$cont = this.$('#right-panel');
this.$sideNav = $('#myhome-side-nav');
this.sideNavView = new MyhomeSideNavView();
this.reposView = new ReposView();
this.subReposView = new SubReposView();
this.sharedReposView = new SharedReposView();
@@ -30,7 +30,7 @@ define([
},
showSideNav: function () {
this.$sideNav.show();
this.sideNavView.show();
},
ajaxLoadingShow: function() {
@@ -80,7 +80,7 @@ define([
hide: function() {
this.currentView.hide();
this.$sideNav.hide();
this.sideNavView.hide();
}
});

View File

@@ -112,6 +112,7 @@ define([
case 'group_repos': return siteRoot + 'api2/groups/' + options.group_id + '/repos/';
case 'group_basic_info': return siteRoot + 'ajax/group/' + options.group_id + '/basic-info/';
case 'toggle_group_modules': return siteRoot + 'ajax/group/' + options.group_id + '/toggle-modules/';
case 'toggle_personal_modules': return siteRoot + 'ajax/toggle-personal-modules/';
}
},