2015-01-31 05:17:47 +00:00
|
|
|
define([
|
|
|
|
'jquery',
|
2015-03-01 12:28:25 +00:00
|
|
|
'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
|
|
|
|
2015-04-22 10:45:28 +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() {
|
2015-03-19 08:06:20 +00:00
|
|
|
this.$el.html(this.template(this.templateData()));
|
2015-04-22 10:45:28 +00:00
|
|
|
return this;
|
2015-01-31 05:17:47 +00:00
|
|
|
},
|
|
|
|
|
2015-03-19 08:06:20 +00:00
|
|
|
templateData: function() {
|
|
|
|
return {
|
2015-09-24 09:20:45 +00:00
|
|
|
showSharePerm: false,
|
2015-10-09 07:40:54 +00:00
|
|
|
enable_encrypted_library: app.pageOptions.enable_encrypted_library
|
2015-03-19 08:06:20 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-04-22 10:45:28 +00:00
|
|
|
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 {
|
2015-10-08 09:54:59 +00:00
|
|
|
name: $.trim($('input[name=repo_name]', this.$el).val()),
|
2015-10-08 12:42:08 +00:00
|
|
|
encrypted: $('#encrypt-switch').prop('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-11-02 09:11:11 +00:00
|
|
|
Common.enableButton(this.$('[type="submit"]'));
|
2015-01-31 05:17:47 +00:00
|
|
|
},
|
2015-02-01 06:15:00 +00:00
|
|
|
|
2015-01-31 05:17:47 +00:00
|
|
|
addRepo: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
2015-10-08 12:42:08 +00:00
|
|
|
Common.disableButton(this.$('[type="submit"]'));
|
2015-04-22 10:45:28 +00:00
|
|
|
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() {
|
2015-04-22 10:45:28 +00:00
|
|
|
if (repos.length == 1) {
|
2015-05-20 08:19:35 +00:00
|
|
|
repos.reset(repos.models);
|
2015-04-22 10:45:28 +00:00
|
|
|
}
|
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) {
|
2015-10-08 12:42:08 +00:00
|
|
|
var $checkbox = $('#encrypt-switch');
|
2016-04-07 03:06:48 +00:00
|
|
|
var $pwd_input = this.$('input[type="password"]');
|
2015-01-31 05:17:47 +00:00
|
|
|
|
2015-10-08 12:42:08 +00:00
|
|
|
if ($checkbox.prop('checked')) {
|
2016-04-07 03:06:48 +00:00
|
|
|
$pwd_input.attr('disabled', false).removeClass('input-disabled');
|
2015-01-31 05:17:47 +00:00
|
|
|
} else {
|
2016-04-07 03:06:48 +00:00
|
|
|
$pwd_input.attr('disabled', true).addClass('input-disabled');
|
2015-01-31 05:17:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return AddRepoView;
|
|
|
|
});
|