1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-20 19:08:21 +00:00

[lib view] show error msg, added decryption for enc-lib, cleaned up some code

This commit is contained in:
llj
2015-03-23 18:11:24 +08:00
committed by Daniel Pan
parent 89bba63408
commit c892ee3afa
7 changed files with 77 additions and 52 deletions

View File

@@ -82,9 +82,10 @@ define([
showDir: function(category, repo_id, path) {
this.$el.show();
this.$dirent_list.empty();
var loading_tip = this.$('.loading-tip').show(),
dir = this.dir;
var loading_tip = this.$('.loading-tip').show();
var dir = this.dir;
dir.setPath(category, repo_id, path);
var _this = this;
dir.fetch({
reset: true,
data: {'p': path},
@@ -95,8 +96,46 @@ define([
loading_tip.hide();
}
},
error: function () { // todo
error: function (collection, response, opts) {
loading_tip.hide();
var $el_con = _this.$('.repo-file-list-topbar, .repo-file-list').hide();
var $error = _this.$('.error');
var err_msg;
if (response.responseText) {
err_msg = response.responseJSON.error;
} else {
err_msg = gettext('Please check the network.');
}
$error.html(err_msg).show();
if (response.responseJSON.lib_need_decrypt) {
var form = $($('#repo-decrypt-form-template').html());
_this.$el.append(form);
form.submit(function() {
var passwd = $.trim($('[name="password"]', form).val());
if (!passwd) {
$('.error', form).html(gettext("Password is required.")).removeClass('hide');
return false;
}
Common.ajaxPost({
form: form,
form_id: form.attr('id'),
post_url: Common.getUrl({'name':'repo_set_password'}),
post_data: {
repo_id: repo_id,
password: passwd,
username: app.pageOptions.username
},
after_op_success: function() {
form.remove();
$error.html('').hide();
$el_con.show();
_this.showDir(category, repo_id, path);
}
});
return false;
});
}
}
});
},

View File

@@ -16,7 +16,6 @@ define([
tagName: 'tr',
template: _.template(direntTemplate),
shareTemplate: _.template($("#share-popup-template").html()),
renameTemplate: _.template($("#rename-form-template").html()),
mvcpTemplate: _.template($("#mvcp-form-template").html()),
mvProgressTemplate: _.template($("#mv-progress-popup-template").html()),

View File

@@ -99,6 +99,8 @@ define([
case 'set_notices_seen': return siteRoot + 'ajax/set_notices_seen/';
case 'get_unseen_notices_num': return siteRoot + 'ajax/unseen-notices-count/';
case 'set_notice_seen_by_id': return siteRoot + 'ajax/set_notice_seen_by_id/';
case 'repo_set_password': return siteRoot + 'repo/set_password/';
}
},

View File

@@ -22,5 +22,5 @@
</tbody>
</table>
<img class="loading-tip" src="{{MEDIA_URL}}img/loading-icon.gif" alt="{% trans 'Loading...' %}" />
<p class="error hide"></p>
</div>

View File

@@ -103,28 +103,12 @@
</div>
<!--/script-->
<div id="update-file-dialog" class="hide">
<h3 class="hd">{% trans "Update %(file_name)s" %}</h3>
<form id="update-file-form" enctype="multipart/form-data" method="post" action="">{% csrf_token %}
<input type="hidden" name="target_file" />
<div class="fileupload-buttonbar">
<span class="fileinput-button vam">
<span>{% trans "Choose a file" %}</span>
<input type="file" name="file" />
</span>
{% if max_upload_file_size %}
<span class="vam">({% blocktrans with max_file_size=max_upload_file_size|filesizeformat %}Smaller than {{ max_file_size }}{% endblocktrans %})</span>
{% endif %}
<div class="fileupload-progress fade">
<div class="progress progress-success progres-striped active">
<div class="bar" style="width:0%"></div>
</div>
<div class="progress-extended"></div>
</div>
<p class="saving-tip alc hide"><img src="{{MEDIA_URL}}img/loading-icon.gif" alt="" style="margin-right:5px;" class="vam" />{% trans "Saving..." %}</p>
</div>
<table class="table table-striped"><tbody class="files" data-toggle="modal-gallery" data-target="#modal-gallery"></tbody></table>
<script type="text/template" id="repo-decrypt-form-template">
<form id="repo-decrypt-form" action="">
<label>{% trans 'Password' %}</label><br />
<input type="password" name="password" class="input" />
<p class="tip">{% trans 'The password will be kept in the server for only 1 hour.' %}</p>
<p class="error hide"></p>
<button type="submit" class="submit">{% trans "Submit" %}</button>
</form>
</div>
<script type="text/template" id="share-popup-template">
</script>

View File

@@ -203,6 +203,7 @@ app["pageOptions"] = {
{% endfor %}
return groups;
})(),
username: "{{request.user.username}}",
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 %},

View File

@@ -424,7 +424,7 @@ def list_lib_dir(request, repo_id):
if repo.encrypted \
and not seafile_api.is_password_set(repo.id, username):
err_msg = _(u'Library is encrypted.')
return HttpResponse(json.dumps({'error': err_msg}),
return HttpResponse(json.dumps({'error': err_msg, 'lib_need_decrypt': True}),
status=403, content_type=content_type)
head_commit = get_commit(repo.id, repo.version, repo.head_cmmt_id)