1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-29 00:17:18 +00:00
seahub/static/scripts/app/views/add-repo.js

98 lines
3.0 KiB
JavaScript
Raw Normal View History

2015-01-31 05:17:47 +00:00
define([
'jquery',
'simplemodal',
2015-01-31 05:17:47 +00:00
'underscore',
'backbone',
2015-04-03 04:15:41 +00:00
'common'
], function($, simplemodal, _, Backbone, Common) {
2015-01-31 05:17:47 +00:00
'use strict';
var AddRepoView = Backbone.View.extend({
2015-03-01 02:44:00 +00:00
tagName: 'div',
2015-04-03 04:15:41 +00:00
template: _.template($('#create-repo-tmpl').html()),
2015-01-31 05:17:47 +00:00
2015-02-01 06:15:00 +00:00
initialize: function(repos) {
this.repos = repos;
2015-01-31 05:17:47 +00:00
this.render();
this.$el.modal();
$("#simplemodal-container").css({'height':'auto'});
this.listenTo(repos, 'invalid', this.displayValidationErrors);
2015-03-01 02:44:00 +00:00
},
2015-01-31 05:17:47 +00:00
render: function() {
this.$el.html(this.template(this.templateData()));
return this;
2015-01-31 05:17:47 +00:00
},
templateData: function() {
return {
2015-09-24 09:20:45 +00:00
showSharePerm: false,
enable_encrypt_library: app.pageOptions.enable_encrypt_library
};
},
events: {
"submit": "addRepo",
"click #encrypt-switch": "togglePasswdInput"
},
2015-01-31 05:17:47 +00:00
// Generate the attributes for a new GroupRepo item.
newAttributes: function() {
return {
name: $('input[name=repo_name]', this.$el).val().trim(),
encrypted: $('#encrypt-switch', this.$el).parent().hasClass('checkbox-checked'),
2015-01-31 05:17:47 +00:00
passwd1: $('input[name=passwd]', this.$el).val(),
passwd2: $('input[name=passwd_again]', this.$el).val(),
passwd: $('input[name=passwd]', this.$el).val()
};
},
// TODO: move to common
displayValidationErrors: function(model, error, options) {
this.$('.error').html(error).show();
},
2015-02-01 06:15:00 +00:00
2015-01-31 05:17:47 +00:00
addRepo: function(e) {
e.preventDefault();
var repos = this.repos;
repos.create(this.newAttributes(), {
2015-01-31 05:17:47 +00:00
wait: true,
validate: true,
prepend: true, // show newly created repo at first line
success: function() {
if (repos.length == 1) {
repos.reset(repos.models);
}
2015-01-31 05:17:47 +00:00
},
error: function(xhr, textStatus, errorThrown) {
// TODO: handle error gracefully
Common.feedback('Error', 'error', Common.ERROR_TIMEOUT);
},
complete: function() {
Common.closeModal();
}
});
},
togglePasswdInput: function(e) {
var $parent = $(e.target).parent();
$parent.toggleClass('checkbox-checked');
2015-01-31 05:17:47 +00:00
var pwd_input = $('input[type="password"]', $('.repo-create-encryption'));
if ($parent.hasClass('checkbox-checked')) {
2015-01-31 05:17:47 +00:00
pwd_input.attr('disabled', false).removeClass('input-disabled');
} else {
pwd_input.attr('disabled', true).addClass('input-disabled');
}
}
});
return AddRepoView;
});