diff --git a/seahub/message/templates/message/user_msg_list.html b/seahub/message/templates/message/user_msg_list.html index 202e463475..61e7716cd5 100644 --- a/seahub/message/templates/message/user_msg_list.html +++ b/seahub/message/templates/message/user_msg_list.html @@ -152,7 +152,7 @@ $('#personal-message-form').submit(function() { var new_msg = $(data['html']); if ($('.msg-list').length == 0) { // the new discussion is the first discussion in this page form.after(''); - } + } $('.msg-list').prepend(new_msg); bind_del(new_msg); new_msg.slideDown(400); diff --git a/seahub/templates/myhome.html b/seahub/templates/myhome.html index e8ac3880a3..21ee24746e 100644 --- a/seahub/templates/myhome.html +++ b/seahub/templates/myhome.html @@ -43,6 +43,21 @@ {% endif %} + +{% if ENABLE_SUB_LIBRARY and sub_lib_enabled %} +
+

{% trans "Choose a directory:" %}

+
+ +
+ + +

+ + +
+{% endif %} + {% endblock %} {% block extra_script %}{{block.super}} @@ -51,6 +66,83 @@ $(function() {$('#guide-for-new').modal({appendTo: '#main', focus:false});}); {% endif %} {% include "snippets/myhome_extra_script.html" %} +{% if ENABLE_SUB_LIBRARY and sub_lib_enabled %} +var cur_tab = $('.ui-tabs-selected .a'); +var lib_create_btn = $('#repo-create'), + sublib_create_btn = $('#sub-lib-create'); +// for initial state +if (cur_tab.attr('id') == 'mylib-tab') { + lib_create_btn.removeClass('hide'); +} +if (cur_tab.attr('id') == 'sublib-tab') { + sublib_create_btn.removeClass('hide'); +} +$('#mylib-tab').click(function() { + lib_create_btn.removeClass('hide'); + sublib_create_btn.addClass('hide'); +}); +$('#sublib-tab').click(function() { + lib_create_btn.addClass('hide'); + sublib_create_btn.removeClass('hide'); +}); +$('#shared-lib-tab, #grp-lib-tab').click(function() { + lib_create_btn.addClass('hide'); + sublib_create_btn.addClass('hide'); +}); +var sublib_create_form = $('#sublib-create-form'); +sublib_create_btn.click(function() { + var dir_tree_cont = $('.dir-tree-cont', sublib_create_form); + sublib_create_form.modal(); + $.ajax({ + url: '{% url 'get_my_unenc_repos' %}', + cache: false, + dataType: 'json', + success: function(data) { + var file_tree = new FileTree(); + var repos = file_tree.format_repo_data(data); + if (repos.length > 0) { + file_tree.renderDirTree(dir_tree_cont.data('site_root', '{{SITE_ROOT}}'), sublib_create_form, repos); + } else { + dir_tree_cont.html('

' + "{% trans "You don't have any library at present" %}" + '

'); + } + }, + error: function(jqXHR, textStatus, errorThrown) { + if (!jqXHR.responseText) { + dir_tree_cont.html('

' + "{% trans "Failed. Please check the network." %}" + '

'); + } + } + }); +}); +$('.submit', sublib_create_form).click(function() { + var ori_repo_id = $('[name="dst_repo"]', sublib_create_form).val(); + var path = $('[name="dst_path"]', sublib_create_form).val(); + + if (!path || path == '/') { + $('.error', sublib_create_form).html("{% trans "Please choose a directory" %}").removeClass('hide'); + return false; + } + + // path ends with '/', rm it here + path = path.substr(0, path.length - 1); + $.ajax({ + url: '{{SITE_ROOT}}ajax/repo/' + ori_repo_id + '/dir/sub_repo/?p=' + e(path), + dataType: 'json', + success: function(data) { + location.reload(); + }, + error: function(xhr, textStatus, errorThrown) { + var err; + if (xhr.responseText) { + err = jQuery.parseJSON(xhr.responseText).error; + } else { + err = "{% trans "Failed. Please check the network." %}"; + } + $('.error', sublib_create_form).html(err).removeClass('hide'); + } + }); + return false; +}); +{% endif %} {% include "snippets/repo_create_js.html" with post_url=repo_create_url %} {% endblock %} diff --git a/seahub/templates/repo.html b/seahub/templates/repo.html index 27f397b217..3a9fa96909 100644 --- a/seahub/templates/repo.html +++ b/seahub/templates/repo.html @@ -205,16 +205,6 @@ - {% if ENABLE_SUB_LIBRARY and sub_lib_enabled and not repo.is_virtual %} -
-

{% trans "Sync %(dir_name)s" %}

-

{% trans "A sub-library will be created from this directory. It will be listed in your desktop client, and you can download it just like downloading a normal library." %}

- - -

-
- {% endif %} - {% include "snippets/file_share_popup.html" %} {% with attach_type='dir' %} @@ -1533,39 +1523,6 @@ $('.file-share, .dir-share', context).click(function() { return false; }); -{% if ENABLE_SUB_LIBRARY and sub_lib_enabled and not repo.is_virtual %} -$('.dir-sync', context).click(function() { - var name = $(this).parents('.dir-item').attr('data-name'); - var popup = $('#dir-sync-popup'), - hd = $('.hd', popup), - create_btn = $('.create-sub-repo', popup); - popup.modal({appendTo:'#main', focus:false, minWidth:250, maxWidth:400}); - $('#simplemodal-container').css({'height':'auto'}); - hd.html(hd.html().replace('%(dir_name)s', '' + name + '')); - - create_btn.click(function () { - $.ajax({ - url: '{% url 'sub_repo' repo.id %}?p=' + e(cur_path + name) + '&name=' + e(name), - dataType: 'json', - success: function(data) { - create_btn.replaceWith("

{% trans "Sub-library is created." %}

"); - $('.simplemodal-close', popup).removeClass('hide'); - }, - error: function(xhr, textStatus, errorThrown) { - var err; - if (xhr.responseText) { - err = jQuery.parseJSON(xhr.responseText).error; - } else { - err = "{% trans "Failed. Please check the network." %}"; - } - $('.error', popup).html(err).removeClass('hide'); - } - }); - }); - return false; -}); -{% endif %} - } //function 'opOnDirent' ends here $('#add-new-file-form, #add-new-dir-form, #rename-form, #mv-form').submit(function() { @@ -1992,7 +1949,7 @@ function updateCmt() { // check if a sub-lib exists, if not, create one $.ajax({ - url: '{% url 'sub_repo' repo.id %}?p=' + e(form.data('dir-path')) + '&name=' + e(form.attr('data-name')), + url: '{% url 'sub_repo' repo.id %}?p=' + e(form.data('dir-path')), dataType: 'json', success: function(data) { $('[name="repo_id"]', form).val(data['sub_repo_id']); diff --git a/seahub/templates/snippets/msg_form_js.html b/seahub/templates/snippets/msg_form_js.html index 6708a2815b..875936970f 100644 --- a/seahub/templates/snippets/msg_form_js.html +++ b/seahub/templates/snippets/msg_form_js.html @@ -12,22 +12,23 @@ $('.cancel', msg_form).click(function() { $('.add-file').click(function(){ $('#add-file-popup').modal(); + var file_tree_cont = $('#file-tree'); $.ajax({ - 'url': repos_get_url, - 'cache': false, - 'dataType': 'json', - 'success': function(data) { + url: repos_get_url, + cache: false, + dataType: 'json', + success: function(data) { var file_tree = new FileTree(); var repos = file_tree.format_repo_data(data); if (repos.length > 0) { - file_tree.renderFileTree($('#file-tree').data('site_root', '{{SITE_ROOT}}'), repos, {'two_state': true}); + file_tree.renderFileTree(file_tree_cont.data('site_root', '{{SITE_ROOT}}'), repos, {'two_state': true}); } else { - $('#file-tree').html('

' + "{% trans "You don't have any library at present" %}" + '

'); + file_tree_cont.html('

' + "{% trans "You don't have any library at present" %}" + '

'); } }, - 'error': function(jqXHR, textStatus, errorThrown) { + error: function(jqXHR, textStatus, errorThrown) { if (!jqXHR.responseText) { - $('#file-tree').html('

' + "{% trans "Failed. Please check the network." %}" + '

'); + file_tree_cont.html('

' + "{% trans "Failed. Please check the network." %}" + '

'); } } }); diff --git a/seahub/templates/snippets/my_owned_repos.html b/seahub/templates/snippets/my_owned_repos.html index c4c62edbcf..fa7fa97bf6 100644 --- a/seahub/templates/snippets/my_owned_repos.html +++ b/seahub/templates/snippets/my_owned_repos.html @@ -3,14 +3,21 @@
- +
+ {% if ENABLE_SUB_LIBRARY and sub_lib_enabled %} + + + {% else %} + + {% endif %} +
{% if owned_repos %} diff --git a/seahub/templates/snippets/repo_dirents.html b/seahub/templates/snippets/repo_dirents.html index 78c960b5bc..be8beb4c70 100644 --- a/seahub/templates/snippets/repo_dirents.html +++ b/seahub/templates/snippets/repo_dirents.html @@ -24,9 +24,6 @@ {% trans 'Download' %} {% if not repo.encrypted %} {% trans "Share" %} - {% if ENABLE_SUB_LIBRARY and sub_lib_enabled and not repo.is_virtual %} - {% trans "Sync" %} - {% endif %} {% endif %}
{% if user_perm == 'rw' %} diff --git a/seahub/views/ajax.py b/seahub/views/ajax.py index 72d5581fdb..f9067cd6a2 100644 --- a/seahub/views/ajax.py +++ b/seahub/views/ajax.py @@ -188,7 +188,7 @@ def get_my_unenc_repos(request): repos = seafile_api.get_owned_repo_list(request.user.username) repo_list = [] for repo in repos: - if repo.encrypted: + if repo.encrypted or repo.is_virtual: continue repo_list.append({"name": repo.name, "id": repo.id}) @@ -1140,10 +1140,10 @@ def sub_repo(request, repo_id): result = {} path = request.GET.get('p') - name = request.GET.get('name') - if not (path and name): + if not path: result['error'] = _('Argument missing') return HttpResponse(json.dumps(result), status=400, content_type=content_type) + name = os.path.basename(path) username = request.user.username