2015-01-22 09:15:17 +00:00
|
|
|
define([
|
|
|
|
'jquery',
|
2015-03-01 12:28:25 +00:00
|
|
|
'simplemodal',
|
2015-01-22 09:15:17 +00:00
|
|
|
'underscore',
|
|
|
|
'backbone',
|
|
|
|
'common',
|
|
|
|
'app/collections/group-repos',
|
2015-03-01 12:28:25 +00:00
|
|
|
'text!' + app.config._tmplRoot + 'create-repo.html',
|
|
|
|
], function($, simplemodal, _, Backbone, Common, GroupRepos, CreateRepoTemplate) {
|
2015-01-22 09:15:17 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var AddGroupRepoView = Backbone.View.extend({
|
2015-03-01 12:28:25 +00:00
|
|
|
|
|
|
|
tagName: 'div',
|
|
|
|
|
|
|
|
template: _.template(CreateRepoTemplate),
|
2015-01-22 09:15:17 +00:00
|
|
|
|
|
|
|
events: {
|
|
|
|
"submit": "addGroupRepo"
|
|
|
|
},
|
|
|
|
|
2015-03-01 12:28:25 +00:00
|
|
|
initialize: function(repos) {
|
|
|
|
this.repos = repos;
|
2015-01-22 09:15:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2015-03-01 12:28:25 +00:00
|
|
|
this.$el.html(this.template({}));
|
|
|
|
this.$el.modal();
|
2015-01-22 09:15:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Generate the attributes for a new GroupRepo item.
|
|
|
|
newAttributes: function() {
|
|
|
|
return {
|
2015-01-27 09:32:31 +00:00
|
|
|
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()
|
2015-01-22 09:15:17 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
addGroupRepo: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
Common.feedback('Loading...', 'info', Common.INFO_TIMEOUT);
|
2015-03-01 12:28:25 +00:00
|
|
|
this.repos.create(this.newAttributes(), {
|
2015-01-22 09:15:17 +00:00
|
|
|
wait: true,
|
2015-01-27 09:32:31 +00:00
|
|
|
prepend: true, // show newly created repo at first line
|
2015-01-22 09:15:17 +00:00
|
|
|
success: function() {
|
2015-01-27 09:32:31 +00:00
|
|
|
Common.feedback('Success', 'success', Common.SUCCESS_TIMEOUT);
|
2015-01-22 09:15:17 +00:00
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
Common.feedback('Error', 'error', Common.ERROR_TIMEOUT);
|
|
|
|
},
|
|
|
|
complete: function() {
|
|
|
|
Common.closeModal();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return AddGroupRepoView;
|
|
|
|
});
|