mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-21 11:27:18 +00:00
[sub-lib] added 'createRepo'
This commit is contained in:
@@ -3,17 +3,18 @@ define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'file-tree',
|
||||
'app/collections/repos',
|
||||
'app/views/sub-lib',
|
||||
'app/views/add-repo',
|
||||
], function($, _, Backbone, Common, RepoCollection, RepoView, AddRepoView) {
|
||||
], function($, _, Backbone, Common, FileTree, RepoCollection, RepoView, AddRepoView) {
|
||||
'use strict';
|
||||
|
||||
var ReposView = Backbone.View.extend({
|
||||
el: $('#repo-tabs'),
|
||||
|
||||
events: {
|
||||
'click #sub-lib-create': 'createRepo', // TODO
|
||||
'click #sub-lib-create': 'createRepo',
|
||||
},
|
||||
|
||||
initialize: function(options) {
|
||||
@@ -73,9 +74,75 @@ define([
|
||||
},
|
||||
|
||||
createRepo: function() {
|
||||
var addRepoView = new AddRepoView(this.repos);
|
||||
addRepoView.render();
|
||||
var _this = this;
|
||||
|
||||
var sublib_create_form = $('#sublib-create-form');
|
||||
|
||||
var dir_tree_cont = $('.dir-tree-cont', sublib_create_form);
|
||||
sublib_create_form.modal();
|
||||
|
||||
$.ajax({
|
||||
url: Common.getUrl({'name': 'get_my_unenc_repos'}),
|
||||
cache: false,
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
var repos = FileTree.formatRepoData(data);
|
||||
if (repos.length > 0) {
|
||||
FileTree.renderDirTree(dir_tree_cont, sublib_create_form, repos);
|
||||
} else {
|
||||
dir_tree_cont.html('<p class="error">' + gettext("You don't have any library at present.") + '</p>');
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
var error;
|
||||
if (jqXHR.responseText) {
|
||||
error = $.parseJSON(jqXHR.responseText).error;
|
||||
} else {
|
||||
error = gettext("Failed. Please check the network.");
|
||||
}
|
||||
dir_tree_cont.html('<p class="error">' + error + '</p>');
|
||||
}
|
||||
});
|
||||
|
||||
$('.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(gettext("Please choose a directory")).removeClass('hide');
|
||||
return false;
|
||||
}
|
||||
|
||||
// path ends with '/', rm it here
|
||||
path = path.substr(0, path.length - 1);
|
||||
$.ajax({
|
||||
url: Common.getUrl({'name':'sub_repo', 'repo_id':ori_repo_id}) + '?p=' + encodeURIComponent(path),
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
$.modal.close();
|
||||
_this.repos.add({
|
||||
'id': data["sub_repo_id"],
|
||||
'name': data["name"],
|
||||
'origin_repo_id': ori_repo_id,
|
||||
'origin_path': path,
|
||||
'abbrev_origin_path': '', // TODO
|
||||
'mtime': new Date().getTime() / 1000,
|
||||
'mtime_relative': gettext("Just now")
|
||||
}, {prepend: true});
|
||||
},
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
var err;
|
||||
if (xhr.responseText) {
|
||||
err = jQuery.parseJSON(xhr.responseText).error;
|
||||
} else {
|
||||
err = gettext("Failed. Please check the network.");
|
||||
}
|
||||
$('.error', sublib_create_form).html(err).removeClass('hide');
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
@@ -76,9 +76,11 @@ define([
|
||||
case 'get_file_op_url': return siteRoot + 'ajax/repo/' + options.repo_id + '/file_op_url/';
|
||||
case 'get_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/';
|
||||
case 'repo_del': return siteRoot + 'ajax/repo/' + options.repo_id + '/remove/';
|
||||
case 'sub_repo': return siteRoot + 'ajax/repo/' + options.repo_id + '/dir/sub_repo/';
|
||||
|
||||
case 'thumbnail_create': return siteRoot + 'thumbnail/' + options.repo_id + '/create/';
|
||||
|
||||
case 'get_my_unenc_repos': return siteRoot + 'ajax/my-unenc-repos/';
|
||||
case 'unenc_rw_repos': return siteRoot + 'ajax/unenc-rw-repos/';
|
||||
case 'get_cp_progress': return siteRoot + 'ajax/cp_progress/';
|
||||
case 'cancel_cp': return siteRoot + 'ajax/cancel_cp/';
|
||||
|
@@ -84,7 +84,7 @@
|
||||
</div>
|
||||
|
||||
<div id="my-own-repos">
|
||||
<table class="repo-list hide">
|
||||
<table class="hide">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="4%"><!--icon--></th>
|
||||
@@ -96,11 +96,6 @@
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
<div class="op-confirm repo-del-cfm hide" id="repo-del-cfm-popup">
|
||||
<p class="con"></p>
|
||||
<button class="yes">{% trans "Yes" %}</button>
|
||||
<button class="no">{% trans "No" %}</button>
|
||||
</div>
|
||||
<div class="empty-tips hide">
|
||||
<h2 class="alc">{% trans "You have not created any libraries" %}</h2>
|
||||
<p>{% trans "You can create a library to organize your files. For example, you can create one for each of your projects. Each library can be synchronized and shared separately." %}</p>
|
||||
@@ -108,7 +103,7 @@
|
||||
</div>
|
||||
|
||||
<div id="my-sub-repos">
|
||||
<table class="repo-list hide">
|
||||
<table class="hide">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="4%"><!--icon--></th>
|
||||
@@ -168,11 +163,6 @@
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
{% url 'share_repo' as repo_share_url %}
|
||||
{% with post_url=repo_share_url %}
|
||||
{% include "snippets/repo_share_form.html" %}
|
||||
{% endwith %}
|
||||
|
||||
{% include "snippets/repo_create_form.html" %}
|
||||
|
||||
{% if need_guide %}
|
||||
|
@@ -1293,6 +1293,7 @@ def sub_repo(request, repo_id):
|
||||
name, name,
|
||||
username)
|
||||
result['sub_repo_id'] = sub_repo_id
|
||||
result['name'] = name
|
||||
except SearpcError, e:
|
||||
result['error'] = e.msg
|
||||
return HttpResponse(json.dumps(result), status=500, content_type=content_type)
|
||||
|
Reference in New Issue
Block a user