mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-01 15:09:14 +00:00
Move scripts from media to static folder
This commit is contained in:
91
static/scripts/app/views/add-repo.js
Normal file
91
static/scripts/app/views/add-repo.js
Normal file
@@ -0,0 +1,91 @@
|
||||
define([
|
||||
'jquery',
|
||||
'simplemodal',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'text!' + app.config._tmplRoot + 'create-repo.html'
|
||||
], function($, simplemodal, _, Backbone, Common, CreateRepoTemplate) {
|
||||
'use strict';
|
||||
|
||||
var AddRepoView = Backbone.View.extend({
|
||||
|
||||
tagName: 'div',
|
||||
|
||||
template: _.template(CreateRepoTemplate),
|
||||
|
||||
initialize: function(repos) {
|
||||
this.repos = repos;
|
||||
this.listenTo(repos, 'invalid', this.displayValidationErrors);
|
||||
},
|
||||
|
||||
events: {
|
||||
"submit": "addRepo",
|
||||
"click #encrypt-switch": "togglePasswdInput"
|
||||
},
|
||||
|
||||
render: function() {
|
||||
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(),
|
||||
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()
|
||||
};
|
||||
},
|
||||
|
||||
// TODO: move to common
|
||||
displayValidationErrors: function(model, error, options) {
|
||||
this.$('.error').html(error).show();
|
||||
$("#simplemodal-container").css({'height':'auto'});
|
||||
},
|
||||
|
||||
addRepo: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
this.repos.create(this.newAttributes(), {
|
||||
wait: true,
|
||||
validate: true,
|
||||
prepend: true, // show newly created repo at first line
|
||||
success: function() {
|
||||
// No need to show feedback
|
||||
// Common.feedback('Success', 'success', Common.SUCCESS_TIMEOUT);
|
||||
},
|
||||
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');
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return AddRepoView;
|
||||
});
|
Reference in New Issue
Block a user