diff --git a/media/scripts/app/models/group-repo.js b/media/scripts/app/models/group-repo.js
index f7fede00c7..cc29858670 100644
--- a/media/scripts/app/models/group-repo.js
+++ b/media/scripts/app/models/group-repo.js
@@ -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;
});
diff --git a/media/scripts/app/models/repo.js b/media/scripts/app/models/repo.js
index 1f1ee08156..e8e3bdeb0a 100644
--- a/media/scripts/app/models/repo.js
+++ b/media/scripts/app/models/repo.js
@@ -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");
}
}
diff --git a/media/scripts/app/views/add-group-repo.js b/media/scripts/app/views/add-group-repo.js
index ee87ac64fb..4fa8fd8f6b 100644
--- a/media/scripts/app/views/add-group-repo.js
+++ b/media/scripts/app/views/add-group-repo.js
@@ -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);
- },
- error: function() {
- Common.feedback('Error', 'error', Common.ERROR_TIMEOUT);
- },
- complete: function() {
- Common.closeModal();
- }
- });
- }
+ return _.extend(baseAttrs, $('select[name=permission]', this.$el).val());
+ },
});
diff --git a/media/scripts/app/views/add-repo.js b/media/scripts/app/views/add-repo.js
index eae08a5874..96489ca3bf 100644
--- a/media/scripts/app/views/add-repo.js
+++ b/media/scripts/app/views/add-repo.js
@@ -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');
diff --git a/seahub/api2/views.py b/seahub/api2/views.py
index b88e7d4108..a43f9cd1a2 100644
--- a/seahub/api2/views.py
+++ b/seahub/api2/views.py
@@ -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])
diff --git a/seahub/group/templates/group/group_info.html b/seahub/group/templates/group/group_info.html
index 4b977a64e3..5f6984053b 100644
--- a/seahub/group/templates/group/group_info.html
+++ b/seahub/group/templates/group/group_info.html
@@ -184,7 +184,8 @@
return true;
return false;
})(),
- csrfToken: "{{csrf_token}}"
+ csrfToken: "{{csrf_token}}",
+ repo_password_min_length: {{ repo_password_min_length }}
};
{% if debug %}
diff --git a/seahub/group/views.py b/seahub/group/views.py
index 7c3f1dd379..310b38eeee 100644
--- a/seahub/group/views.py
+++ b/seahub/group/views.py
@@ -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
diff --git a/seahub/templates/js/create-repo.html b/seahub/templates/js/create-repo.html
index 91bb15fade..9df79ce7d6 100644
--- a/seahub/templates/js/create-repo.html
+++ b/seahub/templates/js/create-repo.html
@@ -5,13 +5,13 @@
- {% if create_shared_repo %}
+ <% if (showSharePerm) { %>
- {% endif %}
+ <% } %>