1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-11 11:51:27 +00:00

Enable create repo at myhome and group pages

This commit is contained in:
zhengxie
2015-03-19 16:06:20 +08:00
committed by Daniel Pan
parent 27aa7e79d3
commit 1721c06ff4
10 changed files with 46 additions and 73 deletions

View File

@@ -1,23 +1,17 @@
define([
'underscore',
'backbone'
], function(_, Backbone) {
'backbone',
'app/models/repo'
], function(_, Backbone, Repo) {
'use strict';
var GroupRepo = Backbone.Model.extend({
var GroupRepo = Repo.extend({
defaults: {
id: null,
name: "",
desc: "",
mtime: 0,
encrypted: false,
permission: "r",
owner: "-",
owner_nickname: "-"
}
});
_.extend(GroupRepo.prototype.defaults, Repo.prototype.defaults);
return GroupRepo;
});

View File

@@ -32,6 +32,10 @@ define([
if (attrs.encrypted) {
if (!attrs.passwd1) return gettext("Please enter password");
if (!attrs.passwd2) return gettext("Please enter the password again");
if (attrs.passwd1.length < app.pageOptions.repo_password_min_length) {
return gettext("Password is too short");
}
if (attrs.passwd1 != attrs.passwd2) return gettext("Passwords don't match");
}
}

View File

@@ -4,62 +4,23 @@ define([
'underscore',
'backbone',
'common',
'app/collections/group-repos',
'text!' + app.config._tmplRoot + 'create-repo.html',
], function($, simplemodal, _, Backbone, Common, GroupRepos, CreateRepoTemplate) {
'app/views/add-repo',
'text!' + app.config._tmplRoot + 'create-repo.html'
], function($, simplemodal, _, Backbone, Common, AddRepoView, CreateRepoTemplate) {
'use strict';
var AddGroupRepoView = Backbone.View.extend({
tagName: 'div',
template: _.template(CreateRepoTemplate),
events: {
"submit": "addGroupRepo"
},
initialize: function(repos) {
this.repos = repos;
},
render: function() {
this.$el.html(this.template({}));
this.$el.modal();
},
// Generate the attributes for a new GroupRepo item.
newAttributes: function() {
var AddGroupRepoView = AddRepoView.extend({
templateData: function() {
return {
name: $('input[name=repo_name]', this.$el).val().trim(),
desc: $('textarea[name=repo_desc]', this.$el).val().trim(),
permission: $('select[name=permission]', this.$el).val(),
// TODO: encrypted repo
// encrypted: $('#encrypt-switch', this.$el).attr('checked'),
// passwd1: $('input[name=passwd]', this.$el).val(),
// passwd2: $('input[name=passwd_again]', this.$el).val()
showSharePerm: true
};
},
addGroupRepo: function(e) {
e.preventDefault();
newAttributes: function() {
var baseAttrs = AddRepoView.prototype.newAttributes.apply(this);
Common.feedback('Loading...', 'info', Common.INFO_TIMEOUT);
this.repos.create(this.newAttributes(), {
wait: true,
prepend: true, // show newly created repo at first line
success: function() {
Common.feedback('Success', 'success', Common.SUCCESS_TIMEOUT);
return _.extend(baseAttrs, $('select[name=permission]', this.$el).val());
},
error: function() {
Common.feedback('Error', 'error', Common.ERROR_TIMEOUT);
},
complete: function() {
Common.closeModal();
}
});
}
});

View File

@@ -4,9 +4,8 @@ define([
'underscore',
'backbone',
'common',
'app/collections/repos',
'text!' + app.config._tmplRoot + 'create-repo.html',
], function($, simplemodal, _, Backbone, Common, Repos, CreateRepoTemplate) {
'text!' + app.config._tmplRoot + 'create-repo.html'
], function($, simplemodal, _, Backbone, Common, CreateRepoTemplate) {
'use strict';
var AddRepoView = Backbone.View.extend({
@@ -26,16 +25,22 @@ define([
},
render: function() {
this.$el.html(this.template({}));
this.$el.html(this.template(this.templateData()));
this.$el.modal();
},
templateData: function() {
return {
showSharePerm: false
};
},
// Generate the attributes for a new GroupRepo item.
newAttributes: function() {
return {
name: $('input[name=repo_name]', this.$el).val().trim(),
desc: $('textarea[name=repo_desc]', this.$el).val().trim(),
encrypted: $('#encrypt-switch', this.$el).attr('checked'),
encrypted: $('#encrypt-switch', this.$el).parent().hasClass('checkbox-checked'),
passwd1: $('input[name=passwd]', this.$el).val(),
passwd2: $('input[name=passwd_again]', this.$el).val(),
passwd: $('input[name=passwd]', this.$el).val()
@@ -70,9 +75,11 @@ define([
},
togglePasswdInput: function(e) {
var pwd_input = $('input[type="password"]', this.$el);
var $parent = $(e.target).parent();
$parent.toggleClass('checkbox-checked');
if ($(e.target).attr('checked')) {
var pwd_input = $('input[type="password"]', $('.repo-create-encryption'));
if ($parent.hasClass('checkbox-checked')) {
pwd_input.attr('disabled', false).removeClass('input-disabled');
} else {
pwd_input.attr('disabled', true).addClass('input-disabled');

View File

@@ -2972,10 +2972,13 @@ class GroupRepos(APIView):
username = request.user.username
repo_name = request.DATA.get("name", None)
repo_desc = request.DATA.get("desc", 'new repo')
passwd = request.DATA.get("passwd", None)
if not passwd:
passwd = None
permission = request.DATA.get("permission", 'r')
repo_id = seafile_api.create_repo(repo_name, repo_desc,
username, None)
username, passwd)
repo = seafile_api.get_repo(repo_id)
calculate_repos_last_modify([repo])

View File

@@ -184,7 +184,8 @@
return true;
return false;
})(),
csrfToken: "{{csrf_token}}"
csrfToken: "{{csrf_token}}",
repo_password_min_length: {{ repo_password_min_length }}
};
</script>
{% if debug %}

View File

@@ -628,6 +628,7 @@ def group_info(request, group):
'create_shared_repo': True,
"mods_enabled": mods_enabled,
"mods_available": mods_available,
'repo_password_min_length': settings.REPO_PASSWORD_MIN_LENGTH,
}, context_instance=RequestContext(request))
@group_check

View File

@@ -5,13 +5,13 @@
<input type="text" name="repo_name" value="" maxlength="{{max_file_name}}" class="input" /><br />
<label>{% trans "Description"%}</label><br/>
<textarea name="repo_desc" class="textarea"></textarea><br />
{% if create_shared_repo %}
<% if (showSharePerm) { %>
<label>{% trans "Share Permission"%}</label><br />
<select name="permission" class="perm">
<option value="rw" selected="selected">{% trans "Read-Write"%}</option>
<option value="r">{% trans "Read-Only"%}</option>
</select>
{% endif %}
<% } %>
<div class="repo-create-encryption">
<label class="checkbox-label">
<span class="checkbox"><input type="checkbox" name="encryption" id="encrypt-switch" class="checkbox-orig" /></span>

View File

@@ -251,7 +251,8 @@ 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 %}
max_upload_file_size: {% if max_upload_file_size %} {{ max_upload_file_size }} {% else %} '' {% endif %},
repo_password_min_length: {{ repo_password_min_length }}
};
</script>

View File

@@ -1180,6 +1180,7 @@ def myhome(request):
"repo_create_url": repo_create_url,
'enable_upload_folder': settings.ENABLE_UPLOAD_FOLDER,
'max_upload_file_size': max_upload_file_size,
'repo_password_min_length': settings.REPO_PASSWORD_MIN_LENGTH,
}, context_instance=RequestContext(request))
@login_required