diff --git a/src/rockstor/storageadmin/static/storageadmin/js/views/add_user.js b/src/rockstor/storageadmin/static/storageadmin/js/views/add_user.js
index 36eb62a41..277dc43e6 100644
--- a/src/rockstor/storageadmin/static/storageadmin/js/views/add_user.js
+++ b/src/rockstor/storageadmin/static/storageadmin/js/views/add_user.js
@@ -25,147 +25,152 @@
*/
AddUserView = RockstorLayoutView.extend({
- events: {
- "click #cancel": "cancel"
- },
+ events: {
+ "click #cancel": "cancel"
+ },
- initialize: function() {
- // call initialize of base
- this.constructor.__super__.initialize.apply(this, arguments);
- // set template
- this.template = window.JST.users_add_user;
- this.username = this.options.username;
- if (!_.isUndefined(this.username)) {
- this.user = new User({username: this.username});
- this.dependencies.push(this.user);
- } else {
- this.user = new User();
- }
- this.groups = new GroupCollection();
- this.groups.pageSize = RockStorGlobals.maxPageSize;
- this.dependencies.push(this.groups);
- },
+ initialize: function() {
+ // call initialize of base
+ this.constructor.__super__.initialize.apply(this, arguments);
+ // set template
+ this.template = window.JST.users_add_user;
+ this.username = this.options.username;
+ if (!_.isUndefined(this.username)) {
+ this.user = new User({username: this.username});
+ this.dependencies.push(this.user);
+ } else {
+ this.user = new User();
+ }
+ this.groups = new GroupCollection();
+ this.groups.pageSize = RockStorGlobals.maxPageSize;
+ this.dependencies.push(this.groups);
+ },
+
+ render: function() {
+ this.fetch(this.renderUserForm, this);
+ return this;
+ },
- render: function() {
- this.fetch(this.renderUserForm, this);
- return this;
- },
+ renderUserForm: function() {
+ var _this = this;
+ $(this.el).html(this.template({
+ username: this.username,
+ user: this.user,
+ groups: this.groups
- renderUserForm: function() {
- var _this = this;
- //$(this.el).html(this.template());
- $(this.el).html(this.template({
- username: this.username,
- user: this.user,
- groups: this.groups
+ }));
- }));
+ this.$('#user-create-form :input').tooltip({placement: 'right'});
+ this.$('#group').chosen();
- this.$('#user-create-form :input').tooltip({placement: 'right'});
- this.$('#group').chosen();
+ this.validator = this.$("#user-create-form").validate({
+ onfocusout: false,
+ onkeyup: false,
+ rules: {
+ username: "required",
+ password: {
+ required: {
+ depends: function(element) {
+ return _this.username == null || _this.username == undefined;
+ }
+ }
+ },
+ password_confirmation: {
+ required: {
+ depends: function(element) {
+ return _this.username == null || _this.username == undefined;
+ }
+ },
+ equalTo: "#password"
+ }
+ },
+ messages: {
+ password_confirmation: {
+ equalTo: "The passwords do not match"
+ }
+ },
- this.validator = this.$("#user-create-form").validate({
- onfocusout: false,
- onkeyup: false,
- rules: {
- username: "required",
- password: {
- required: {
- depends: function(element) {
- return _this.username == null || _this.username == undefined;
- }
- }
- },
- password_confirmation: {
- required: {
- depends: function(element) {
- return _this.username == null || _this.username == undefined;
- }
- },
- equalTo: "#password"
- }
- },
- messages: {
- password_confirmation: {
- equalTo: "The passwords do not match"
- }
- },
+ submitHandler: function() {
+ var username = _this.$("#username").val();
+ var password = _this.$("#password").val();
+ var admin = _this.$("#admin").prop("checked");
+ var shell = _this.$("#shell").val();
- submitHandler: function() {
- var username = _this.$("#username").val();
- var password = _this.$("#password").val();
- var admin = _this.$("#admin").prop("checked");
- var shell = _this.$("#shell").val();
-
- var public_key = _this.$("#public_key").val();
- if (_.isEmpty(public_key)) {
- public_key = null;
- }
- var uid = _this.$("#uid").val();
- if (_.isEmpty(uid)) {
- uid = null;
- }
- var group = _this.$("#group").val();
- if (group == 'Create a new one') {
- group = null
- }
- if(_this.username != null && _this.username != undefined){
- if (!_.isEmpty(password)) {
- _this.user.set({password: password});
- } else {
- _this.user.unset('password');
- }
- if (!_.isEmpty(public_key)) {
- _this.user.set({public_key: public_key});
- } else {
- _this.user.unset('public_key');
- }
-
- _this.user.set({admin: admin});
- _this.user.set({group: group});
- _this.user.set({shell: shell});
- _this.user.save(null, {
- success: function(model, response, options) {
- app_router.navigate("users", {trigger: true});
- },
- error: function(model, xhr, options) {
- }
- });
- } else {
- // create a dummy user model class that does not have idAttribute
- // = username, so backbone will treat is as a new object,
- // ie isNew will return true
- var tmpUserModel = Backbone.Model.extend({
- urlRoot: "/api/users"
- });
- var user = new tmpUserModel()
- user.save({
- username: username,
- password: password,
- admin: admin,
- group: group,
- shell: shell,
- uid: uid,
- public_key: public_key
- }, {
- success: function(model, response, options) {
- _this.$('#user-create-form :input').tooltip('hide');
- app_router.navigate("users", {trigger: true});
- },
- error: function(model, xhr, options) {
- _this.$('#user-create-form :input').tooltip('hide');
- }
- });
- }
- return false;
- }
- });
- return this;
- },
+ var public_key = _this.$("#public_key").val();
+ if (_.isEmpty(public_key)) {
+ public_key = null;
+ }
+ var uid = _this.$("#uid").val();
+ if (_.isEmpty(uid)) {
+ uid = null;
+ }
+ var group = _this.$("#group").val();
+ if (group == 'Autogenerate') {
+ group = null;
+ }
+ var email = _this.$("#email").val();
+ if (_.isEmpty(email)) {
+ email = null;
+ }
+ if(_this.username != null && _this.username != undefined){
+ if (!_.isEmpty(password)) {
+ _this.user.set({password: password});
+ } else {
+ _this.user.unset('password');
+ }
+ if (!_.isEmpty(public_key)) {
+ _this.user.set({public_key: public_key});
+ } else {
+ _this.user.unset('public_key');
+ }
- cancel: function(event) {
- event.preventDefault();
- app_router.navigate("users", {trigger: true});
- }
+ _this.user.set({admin: admin});
+ _this.user.set({group: group});
+ _this.user.set({shell: shell});
+ _this.user.set({email: email});
+ _this.user.save(null, {
+ success: function(model, response, options) {
+ app_router.navigate("users", {trigger: true});
+ },
+ error: function(model, xhr, options) {
+ }
+ });
+ } else {
+ // create a dummy user model class that does not have idAttribute
+ // = username, so backbone will treat is as a new object,
+ // ie isNew will return true
+ var tmpUserModel = Backbone.Model.extend({
+ urlRoot: "/api/users"
+ });
+ var user = new tmpUserModel();
+ user.save({
+ username: username,
+ password: password,
+ admin: admin,
+ group: group,
+ shell: shell,
+ uid: uid,
+ public_key: public_key,
+ email: email
+ }, {
+ success: function(model, response, options) {
+ _this.$('#user-create-form :input').tooltip('hide');
+ app_router.navigate("users", {trigger: true});
+ },
+ error: function(model, xhr, options) {
+ _this.$('#user-create-form :input').tooltip('hide');
+ }
+ });
+ }
+ return false;
+ }
+ });
+ return this;
+ },
+
+ cancel: function(event) {
+ event.preventDefault();
+ app_router.navigate("users", {trigger: true});
+ }
});