diff --git a/gulpfile.js b/gulpfile.js index 619aa8f30..ceee66dbc 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -59,5 +59,5 @@ function lintJob() { return gulp.src(jsfiles) .pipe(eslint('./.eslintrc.js')) .pipe(eslint.format()) - .pipe(eslint.failOnError()); + .pipe(eslint.failAfterError()); } diff --git a/src/rockstor/storageadmin/static/storageadmin/js/views/access_keys.js b/src/rockstor/storageadmin/static/storageadmin/js/views/access_keys.js index b8c229527..7e7bf22ac 100644 --- a/src/rockstor/storageadmin/static/storageadmin/js/views/access_keys.js +++ b/src/rockstor/storageadmin/static/storageadmin/js/views/access_keys.js @@ -25,54 +25,56 @@ */ AccessKeysView = RockstorLayoutView.extend({ - events: { - "click a[data-action=delete]": "deleteAccessKey" - }, + events: { + 'click a[data-action=delete]': 'deleteAccessKey' + }, - initialize: function() { - this.constructor.__super__.initialize.apply(this, arguments); - this.template = window.JST.access_keys_access_keys; - this.collection = new AccessKeyCollection(); - this.dependencies.push(this.collection); - this.collection.on("reset", this.renderAccessKeys, this); - }, + initialize: function() { + this.constructor.__super__.initialize.apply(this, arguments); + this.template = window.JST.access_keys_access_keys; + this.collection = new AccessKeyCollection(); + this.dependencies.push(this.collection); + this.collection.on('reset', this.renderAccessKeys, this); + }, - render: function() { - this.fetch(this.renderAccessKeys, this); - return this; - }, + render: function() { + this.fetch(this.renderAccessKeys, this); + return this; + }, - renderAccessKeys: function() { - $(this.el).html(this.template({ - accessKeys: this.collection.toJSON(), - collection: this.collection, - collectionNotEmpty: !this.collection.isEmpty(), - })); - - this.renderDataTables(); - }, + renderAccessKeys: function() { + $(this.el).html(this.template({ + accessKeys: this.collection.toJSON(), + collection: this.collection, + collectionNotEmpty: !this.collection.isEmpty(), + })); - deleteAccessKey: function(event) { - var _this = this; - var button = $(event.currentTarget); - if (buttonDisabled(button)) return false; - var name = button.attr('data-name'); - var id = button.attr('data-id'); - if(confirm("Delete access key: " + name + " ...Are you sure?")){ - disableButton(button); - $.ajax({ - url: "/api/oauth_app/" + id, - type: "DELETE", - dataType: "json", - success: function() { - _this.collection.fetch({reset: true}); - enableButton(button); - }, - error: function(xhr, status, error) { - enableButton(button); - } - }); - } + this.renderDataTables(); + }, - }, + deleteAccessKey: function(event) { + var _this = this; + var button = $(event.currentTarget); + if (buttonDisabled(button)) return false; + var name = button.attr('data-name'); + var id = button.attr('data-id'); + if (confirm('Delete access key: ' + name + ' ...Are you sure?')) { + disableButton(button); + $.ajax({ + url: '/api/oauth_app/' + id, + type: 'DELETE', + dataType: 'json', + success: function() { + _this.collection.fetch({ + reset: true + }); + enableButton(button); + }, + error: function(xhr, status, error) { + enableButton(button); + } + }); + } + + }, }); \ No newline at end of file diff --git a/src/rockstor/storageadmin/static/storageadmin/js/views/add_access_key.js b/src/rockstor/storageadmin/static/storageadmin/js/views/add_access_key.js index 38969a933..d6d0b1cb8 100644 --- a/src/rockstor/storageadmin/static/storageadmin/js/views/add_access_key.js +++ b/src/rockstor/storageadmin/static/storageadmin/js/views/add_access_key.js @@ -26,54 +26,61 @@ AddAccessKeyView = RockstorLayoutView.extend({ - events: { - 'click #js-cancel': 'cancel' - }, + events: { + 'click #js-cancel': 'cancel' + }, - initialize: function() { - this.constructor.__super__.initialize.apply(this, arguments); - this.template = window.JST.access_keys_add_access_key; - }, + initialize: function() { + this.constructor.__super__.initialize.apply(this, arguments); + this.template = window.JST.access_keys_add_access_key; + }, - render: function() { - var _this = this; - $(this.el).html(this.template()); - this.$('#add-access-key-form :input').tooltip({placement: 'right'}); - this.$('#add-access-key-form').validate({ - onfocusout: false, - onkeyup: false, - rules: { - access_key_name: 'required', - }, - submitHandler: function() { - var button = _this.$('#create-access-key'); - if (buttonDisabled(button)) return false; - var name = _this.$('#name').val(); - disableButton(button); - $.ajax({ - url: "/api/oauth_app", - type: "POST", - dataType: "json", - data: {name: name}, - success: function() { - enableButton(button); - _this.$('#add-access-key-form :input').tooltip('hide'); - app_router.navigate('access-keys', {trigger: true}) - }, - error: function(xhr, status, error) { - enableButton(button); - }, + render: function() { + var _this = this; + $(this.el).html(this.template()); + this.$('#add-access-key-form :input').tooltip({ + placement: 'right' }); - } - }); - return this; - }, - - cancel: function(event) { - event.preventDefault(); - this.$('#add-access-key-form :input').tooltip('hide'); - app_router.navigate('access-keys', {trigger: true}); - } + this.$('#add-access-key-form').validate({ + onfocusout: false, + onkeyup: false, + rules: { + access_key_name: 'required', + }, + submitHandler: function() { + var button = _this.$('#create-access-key'); + if (buttonDisabled(button)) return false; + var name = _this.$('#name').val(); + disableButton(button); + $.ajax({ + url: '/api/oauth_app', + type: 'POST', + dataType: 'json', + data: { + name: name + }, + success: function() { + enableButton(button); + _this.$('#add-access-key-form :input').tooltip('hide'); + app_router.navigate('access-keys', { + trigger: true + }); + }, + error: function(xhr, status, error) { + enableButton(button); + }, + }); + } + }); + return this; + }, -}); + cancel: function(event) { + event.preventDefault(); + this.$('#add-access-key-form :input').tooltip('hide'); + app_router.navigate('access-keys', { + trigger: true + }); + } +}); \ No newline at end of file diff --git a/src/rockstor/storageadmin/static/storageadmin/js/views/add_afp_share.js b/src/rockstor/storageadmin/static/storageadmin/js/views/add_afp_share.js index 117709d25..99fb6c2cf 100644 --- a/src/rockstor/storageadmin/static/storageadmin/js/views/add_afp_share.js +++ b/src/rockstor/storageadmin/static/storageadmin/js/views/add_afp_share.js @@ -25,151 +25,164 @@ */ AddAFPShareView = RockstorLayoutView.extend({ - events: { - "click #cancel": "cancel" - }, - - initialize: function() { - this.constructor.__super__.initialize.apply(this, arguments); - this.template = window.JST.afp_add_afp_share; - this.shares = new ShareCollection(); - // dont paginate shares for now - this.shares.pageSize = RockStorGlobals.maxPageSize; - this.dependencies.push(this.shares); - this.afpShareId = this.options.afpShareId || null; - this.afpShares = new AFPCollection({afpShareId: this.afpShareId}); - this.dependencies.push(this.afpShares); - this.yes_no_choices = [ - {name: 'yes', value: 'yes'}, - {name: 'no', value: 'no'}, - ]; - this.time_machine_choices = this.yes_no_choices; - this.initHandlebarHelpers(); - }, - - render: function() { - this.fetch(this.renderAFPForm, this); - return this; - }, - - renderAFPForm: function() { - var _this = this; - var afpShareIdNotNull = false; //afpShareId is Null by default. - this.freeShares = this.shares.reject(function(share) { - s = this.afpShares.find(function(afpShare) { - return (afpShare.get('share') == share.get('name')); - }); - return !_.isUndefined(s); - }, this); - - if(this.afpShareId != null){ - this.aShares = this.afpShares.get(this.afpShareId); - afpShareIdNotNull = true; - }else{ - this.aShares = null; - } - - $(this.el).html(this.template({ - freeShares: this.freeShares, - afpShare: this.aShares, - afpShareId: this.afpShareId, - afpShareIdNotNull : afpShareIdNotNull, - time_machine_choices: this.time_machine_choices, - })); - - $('#add-afp-share-form :input').tooltip({ - html: true, - placement: 'right' - }); - - this.$('#shares').chosen(); - - - $.validator.setDefaults({ ignore: ":hidden:not(select)" }); - - $('#add-afp-share-form').validate({ - onfocusout: false, - onkeyup: false, - rules: { - - shares: "required" , + events: { + 'click #cancel': 'cancel' + }, + initialize: function() { + this.constructor.__super__.initialize.apply(this, arguments); + this.template = window.JST.afp_add_afp_share; + this.shares = new ShareCollection(); + // dont paginate shares for now + this.shares.pageSize = RockStorGlobals.maxPageSize; + this.dependencies.push(this.shares); + this.afpShareId = this.options.afpShareId || null; + this.afpShares = new AFPCollection({ + afpShareId: this.afpShareId + }); + this.dependencies.push(this.afpShares); + this.yes_no_choices = [{ + name: 'yes', + value: 'yes' + }, + { + name: 'no', + value: 'no' + }, + ]; + this.time_machine_choices = this.yes_no_choices; + this.initHandlebarHelpers(); }, - submitHandler: function() { - var button = $('#create-afp-export'); - if (buttonDisabled(button)) return false; - disableButton(button); - var submitmethod = 'POST'; - var posturl = '/api/netatalk'; - if(_this.afpShareId != null){ - submitmethod = 'PUT'; - posturl += '/'+_this.afpShareId; - } - $.ajax({ - url: posturl, - type: submitmethod, - dataType: 'json', - contentType: 'application/json', - data: JSON.stringify(_this.$('#add-afp-share-form').getJSON()), - success: function() { - enableButton(button); - _this.$('#add-afp-share-form :input').tooltip('hide'); - app_router.navigate('afp', {trigger: true}); - }, - error: function(xhr, status, error) { - enableButton(button); - } + render: function() { + this.fetch(this.renderAFPForm, this); + return this; + }, + + renderAFPForm: function() { + var _this = this; + var afpShareIdNotNull = false; //afpShareId is Null by default. + this.freeShares = this.shares.reject(function(share) { + s = this.afpShares.find(function(afpShare) { + return (afpShare.get('share') == share.get('name')); + }); + return !_.isUndefined(s); + }, this); + + if (this.afpShareId != null) { + this.aShares = this.afpShares.get(this.afpShareId); + afpShareIdNotNull = true; + } else { + this.aShares = null; + } + + $(this.el).html(this.template({ + freeShares: this.freeShares, + afpShare: this.aShares, + afpShareId: this.afpShareId, + afpShareIdNotNull: afpShareIdNotNull, + time_machine_choices: this.time_machine_choices, + })); + + $('#add-afp-share-form :input').tooltip({ + html: true, + placement: 'right' }); - return false; - } - }); - }, - - cancel: function(event) { - event.preventDefault(); - this.$('#add-afp-share-form :input').tooltip('hide'); - app_router.navigate('afp', {trigger: true}); - }, - - initHandlebarHelpers: function(){ - Handlebars.registerHelper('display_shares_dropdown',function(){ - var html = ''; - if (this.afpShareIdNotNull){ - var afpShare = this.afpShare.get('share'); - html += ''; - }else{ - _.each(this.freeShares, function(share, index) { - var shareName = share.get('name'); - html += ''; + + this.$('#shares').chosen(); + + + $.validator.setDefaults({ + ignore: ':hidden:not(select)' }); - } - return new Handlebars.SafeString(html); - }); - - Handlebars.registerHelper('display_timeMachine_choices',function(){ - var html = ''; - _.each(this.time_machine_choices, function(c) { - var choiceName = c.name, - choiceValue = c.value; - html += ''; - }); - return new Handlebars.SafeString(html); - }); - } - -}); + return new Handlebars.SafeString(html); + }); + + Handlebars.registerHelper('display_timeMachine_choices', function() { + var html = ''; + _.each(this.time_machine_choices, function(c) { + var choiceName = c.name, + choiceValue = c.value; + html += ''; + }); + return new Handlebars.SafeString(html); + }); + } + +}); \ No newline at end of file diff --git a/src/rockstor/storageadmin/static/storageadmin/js/views/add_appliance.js b/src/rockstor/storageadmin/static/storageadmin/js/views/add_appliance.js index 401f96192..73d830163 100644 --- a/src/rockstor/storageadmin/static/storageadmin/js/views/add_appliance.js +++ b/src/rockstor/storageadmin/static/storageadmin/js/views/add_appliance.js @@ -26,65 +26,69 @@ AddApplianceView = RockstorLayoutView.extend({ - events: { - 'click #js-cancel': 'cancel' - }, + events: { + 'click #js-cancel': 'cancel' + }, - initialize: function() { - // call initialize of base - this.constructor.__super__.initialize.apply(this, arguments); - this.template = window.JST.appliances_add_appliance; - }, + initialize: function() { + // call initialize of base + this.constructor.__super__.initialize.apply(this, arguments); + this.template = window.JST.appliances_add_appliance; + }, - render: function() { - var _this = this; - $(this.el).html(this.template()); - this.$('#add-appliance-form :input').tooltip({ - html: true, - placement: 'right' - }); - this.$('#add-appliance-form').validate({ - onfocusout: false, - onkeyup: false, - rules: { - ip: 'required', - mgmt_port: { - required: true, - number: true, - }, - client_id: 'required', - client_secret: 'required' - }, - submitHandler: function() { - var button = _this.$('#add-appliance'); - if (buttonDisabled(button)) return false; - disableButton(button); - var data = _this.$('#add-appliance-form').getJSON(); - data.current_appliance = false; - $.ajax({ - url: '/api/appliances', - type: 'POST', - dataType: 'json', - contentType: 'application/json', - data: JSON.stringify(data), - success: function() { - _this.$('#add-appliance-form :input').tooltip('hide'); - enableButton(button); - app_router.navigate('appliances', {trigger: true}); - }, - error: function(xhr, status, error) { - _this.$('#add-appliance-form :input').tooltip('hide'); - enableButton(button); - } + render: function() { + var _this = this; + $(this.el).html(this.template()); + this.$('#add-appliance-form :input').tooltip({ + html: true, + placement: 'right' }); - } - }); - return this; - }, + this.$('#add-appliance-form').validate({ + onfocusout: false, + onkeyup: false, + rules: { + ip: 'required', + mgmt_port: { + required: true, + number: true, + }, + client_id: 'required', + client_secret: 'required' + }, + submitHandler: function() { + var button = _this.$('#add-appliance'); + if (buttonDisabled(button)) return false; + disableButton(button); + var data = _this.$('#add-appliance-form').getJSON(); + data.current_appliance = false; + $.ajax({ + url: '/api/appliances', + type: 'POST', + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(data), + success: function() { + _this.$('#add-appliance-form :input').tooltip('hide'); + enableButton(button); + app_router.navigate('appliances', { + trigger: true + }); + }, + error: function(xhr, status, error) { + _this.$('#add-appliance-form :input').tooltip('hide'); + enableButton(button); + } + }); + } + }); + return this; + }, - cancel: function(event) { - event.preventDefault(); - app_router.navigate('appliances', {trigger: true}); - } + cancel: function(event) { + event.preventDefault(); + app_router.navigate('appliances', { + trigger: true + }); + } -}); +}); \ No newline at end of file diff --git a/src/rockstor/storageadmin/static/storageadmin/js/views/add_group.js b/src/rockstor/storageadmin/static/storageadmin/js/views/add_group.js index dcee5c394..8c7269db2 100644 --- a/src/rockstor/storageadmin/static/storageadmin/js/views/add_group.js +++ b/src/rockstor/storageadmin/static/storageadmin/js/views/add_group.js @@ -26,86 +26,95 @@ AddGroupView = RockstorLayoutView.extend({ events: { - "click #cancel": "cancel" + 'click #cancel': 'cancel' }, initialize: function() { - // call initialize of base - this.constructor.__super__.initialize.apply(this, arguments); - // set template - this.template = window.JST.users_add_group; - this.groupname = this.options.groupname; - this.group = new Group({groupname: this.groupname}); - this.dependencies.push(this.group); + // call initialize of base + this.constructor.__super__.initialize.apply(this, arguments); + // set template + this.template = window.JST.users_add_group; + this.groupname = this.options.groupname; + this.group = new Group({ + groupname: this.groupname + }); + this.dependencies.push(this.group); }, render: function() { - this.fetch(this.renderExportForm, this); - return this; + this.fetch(this.renderExportForm, this); + return this; }, renderExportForm: function() { //#start renderExportForm - var _this = this; - $(this.el).html(this.template({ + var _this = this; + $(this.el).html(this.template({ groupname: this.groupname, group: this.group.toJSON() - })); + })); - this.$('#group-create-form :input').tooltip({placement: 'right'}); + this.$('#group-create-form :input').tooltip({ + placement: 'right' + }); - this.validator = this.$("#group-create-form").validate({ - onfocusout: false, - onkeyup: false, - rules: { - groupname: "required", - gid: { - number: true + this.validator = this.$('#group-create-form').validate({ + onfocusout: false, + onkeyup: false, + rules: { + groupname: 'required', + gid: { + number: true - } + } }, - submitHandler: function() { - var groupname = _this.$("#groupname").val(); - var gid = _this.$("#gid").val() || null; - if(_this.groupname != null && _this.group != null) { - var group = new Group({groupname: _this.groupname}); - group.save(null, { - success: function(model, response, options) { - app_router.navigate("groups", {trigger: true}); - }, - error: function(model, xhr, options) { - } - }); - } else { - var tmpGroupModel = Backbone.Model.extend({ - urlRoot: "/api/groups" - }); - var group = new tmpGroupModel(); - group.save( - { - groupname: groupname, - gid: gid - }, - { - success: function(model, response, options) { - _this.$('#group-create-form :input').tooltip('hide'); - app_router.navigate("groups", {trigger: true}); - }, - error: function(model, xhr, options) { - _this.$('#group-create-form :input').tooltip('hide'); - } - } - ); - } - return false; - }, - }); - return this; + submitHandler: function() { + var groupname = _this.$('#groupname').val(); + var gid = _this.$('#gid').val() || null; + var group; + if (_this.groupname != null && _this.group != null) { + group = new Group({ + groupname: _this.groupname + }); + group.save(null, { + success: function(model, response, options) { + app_router.navigate('groups', { + trigger: true + }); + }, + error: function(model, xhr, options) {} + }); + } else { + var tmpGroupModel = Backbone.Model.extend({ + urlRoot: '/api/groups' + }); + group = new tmpGroupModel(); + group.save({ + groupname: groupname, + gid: gid + }, { + success: function(model, response, options) { + _this.$('#group-create-form :input').tooltip('hide'); + app_router.navigate('groups', { + trigger: true + }); + }, + error: function(model, xhr, options) { + _this.$('#group-create-form :input').tooltip('hide'); + } + }); + } + return false; + }, + }); + return this; }, cancel: function() { - app_router.navigate("groups", {trigger: true}); + app_router.navigate('groups', { + trigger: true + }); } -}); +}); \ No newline at end of file diff --git a/src/rockstor/storageadmin/static/storageadmin/js/views/add_pool.js b/src/rockstor/storageadmin/static/storageadmin/js/views/add_pool.js index 22a4e7100..c653c9f51 100644 --- a/src/rockstor/storageadmin/static/storageadmin/js/views/add_pool.js +++ b/src/rockstor/storageadmin/static/storageadmin/js/views/add_pool.js @@ -341,3 +341,4 @@ AddPoolView = Backbone.View.extend({ //Add pagination Cocktail.mixin(AddPoolView, PaginationMixin); + diff --git a/src/rockstor/storageadmin/static/storageadmin/js/views/add_replication_task.js b/src/rockstor/storageadmin/static/storageadmin/js/views/add_replication_task.js index 46835e5d3..7ddf3ee8e 100644 --- a/src/rockstor/storageadmin/static/storageadmin/js/views/add_replication_task.js +++ b/src/rockstor/storageadmin/static/storageadmin/js/views/add_replication_task.js @@ -27,147 +27,154 @@ AddReplicationTaskView = RockstorLayoutView.extend({ events: { - "click #js-cancel": "cancel", - "change #appliance": "fetchRemotePools" + 'click #js-cancel': 'cancel', + 'change #appliance': 'fetchRemotePools' }, initialize: function() { - this.constructor.__super__.initialize.apply(this, arguments); - this.template = window.JST.replication_add_replication_task; - this.shares = new ShareCollection(); - this.shares.pageSize = RockStorGlobals.maxPageSize; - this.dependencies.push(this.shares); - this.appliances = new ApplianceCollection(); - this.dependencies.push(this.appliances); - this.replicas = new ReplicaCollection(); - this.replica = null; // for new replica tasks. - this.dependencies.push(this.replicas); - this.remote_pools = []; + this.constructor.__super__.initialize.apply(this, arguments); + this.template = window.JST.replication_add_replication_task; + this.shares = new ShareCollection(); + this.shares.pageSize = RockStorGlobals.maxPageSize; + this.dependencies.push(this.shares); + this.appliances = new ApplianceCollection(); + this.dependencies.push(this.appliances); + this.replicas = new ReplicaCollection(); + this.replica = null; // for new replica tasks. + this.dependencies.push(this.replicas); + this.remote_pools = []; - this.replicaId = this.options.replicaId; + this.replicaId = this.options.replicaId; - if (!_.isUndefined(this.replicaId) && !_.isNull(this.replicaId)) { - this.replica = new Replica({id: this.replicaId}); - this.dependencies.push(this.replica); - } + if (!_.isUndefined(this.replicaId) && !_.isNull(this.replicaId)) { + this.replica = new Replica({ + id: this.replicaId + }); + this.dependencies.push(this.replica); + } }, render: function() { - this.fetch(this.renderNewReplicationTask, this); - return this; + this.fetch(this.renderNewReplicationTask, this); + return this; }, renderNewReplicationTask: function() { - var _this = this; - this.freeShares = this.shares.reject(function(share) { - return !_.isUndefined(_this.replicas.find(function(replica) { - return replica.get('share') == share.get('name'); - })) ; - }); - this.freeShares2 = this.freeShares.map(function(fs) { - return fs.toJSON(); - }); - if (this.remote_pools.length == 0) { - this.fetchRemotePools(); - } - //ip and port of the remote replication service. - var listener_ip = null; - var listener_port = 10002; - var replicaJSON = null; - if (this.replica) { - listener_ip = this.replica.get('replicaion_ip'); - listener_port = this.replica.get('remote_port'); - replicaJSON = this.replica.toJSON(); - } + var _this = this; + this.freeShares = this.shares.reject(function(share) { + return !_.isUndefined(_this.replicas.find(function(replica) { + return replica.get('share') == share.get('name'); + })); + }); + this.freeShares2 = this.freeShares.map(function(fs) { + return fs.toJSON(); + }); + if (this.remote_pools.length == 0) { + this.fetchRemotePools(); + } + //ip and port of the remote replication service. + var listener_ip = null; + var listener_port = 10002; + var replicaJSON = null; + if (this.replica) { + listener_ip = this.replica.get('replicaion_ip'); + listener_port = this.replica.get('remote_port'); + replicaJSON = this.replica.toJSON(); + } - $(this.el).html(this.template({ - shares: this.freeShares2, - appliances: this.appliances.toJSON(), - replica: replicaJSON, - listener_ip: listener_ip, - listener_port: listener_port, - replicaId: this.replicaId, - remote_pools: this.remote_pools - })); - if (!_.isUndefined(this.replicaId) && !_.isNull(this.replica)) { - var crontab = this.replica.get('crontab'); - $('#cron').cron("value", crontab); - } + $(this.el).html(this.template({ + shares: this.freeShares2, + appliances: this.appliances.toJSON(), + replica: replicaJSON, + listener_ip: listener_ip, + listener_port: listener_port, + replicaId: this.replicaId, + remote_pools: this.remote_pools + })); + if (!_.isUndefined(this.replicaId) && !_.isNull(this.replica)) { + var crontab = this.replica.get('crontab'); + $('#cron').cron('value', crontab); + } - $('#replication-task-create-form :input').tooltip({ - placement: 'right' - }); + $('#replication-task-create-form :input').tooltip({ + placement: 'right' + }); - $('#replication-task-create-form').validate({ - onfocusout: false, - onkeyup: false, - rules: { - task_name: "required", - pool: "required", - frequency: { - required: true, - number: true - } - }, - submitHandler: function() { - var button = $('#create_replication_task'); - if (buttonDisabled(button)) return false; - disableButton(button); - var data = _this.$('#replication-task-create-form').getJSON(); - if (_this.replicaId == null) { - var url = '/api/sm/replicas/'; - var req_type='POST'; - } else { - var url = '/api/sm/replicas/' + _this.replicaId; - var req_type = 'PUT'; - } - data.crontab = $("#cron").cron("value"); - $.ajax({ - url: url, - type: req_type, - dataType: 'json', - contentType: 'application/json', - data: JSON.stringify(data), - success: function() { - enableButton(button); - app_router.navigate('replication', {trigger: true}); - }, - error: function(xhr, status, error) { - enableButton(button); - } - }); - return false; - } - }); + $('#replication-task-create-form').validate({ + onfocusout: false, + onkeyup: false, + rules: { + task_name: 'required', + pool: 'required', + frequency: { + required: true, + number: true + } + }, + submitHandler: function() { + var button = $('#create_replication_task'); + if (buttonDisabled(button)) return false; + disableButton(button); + var data = _this.$('#replication-task-create-form').getJSON(); + var url, req_type; + if (_this.replicaId == null) { + url = '/api/sm/replicas/'; + req_type = 'POST'; + } else { + url = '/api/sm/replicas/' + _this.replicaId; + req_type = 'PUT'; + } + data.crontab = $('#cron').cron('value'); + $.ajax({ + url: url, + type: req_type, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(data), + success: function() { + enableButton(button); + app_router.navigate('replication', { + trigger: true + }); + }, + error: function(xhr, status, error) { + enableButton(button); + } + }); + return false; + } + }); }, fetchRemotePools: function(event) { - var _this = this; - var target_appliance = null; - var ip = $('#appliance').attr('value'); - if (!ip) { - target_appliance = this.appliances.find(function(a) { - return !a.get('current_appliance'); - }); - } else { - target_appliance = this.appliances.find(function(a) { - return (a.get(ip) == ip); - }); - } - var uuid = target_appliance.get('uuid'); - $.ajax({ - url: '/api/sm/replicas/rpool/' + uuid, - dataType: 'json', - success: function(data, status, xhr) { - _this.remote_pools = data; - _this.renderNewReplicationTask(); - } - }); + var _this = this; + var target_appliance = null; + var ip = $('#appliance').attr('value'); + if (!ip) { + target_appliance = this.appliances.find(function(a) { + return !a.get('current_appliance'); + }); + } else { + target_appliance = this.appliances.find(function(a) { + return (a.get(ip) == ip); + }); + } + var uuid = target_appliance.get('uuid'); + $.ajax({ + url: '/api/sm/replicas/rpool/' + uuid, + dataType: 'json', + success: function(data, status, xhr) { + _this.remote_pools = data; + _this.renderNewReplicationTask(); + } + }); }, cancel: function(event) { - event.preventDefault(); - app_router.navigate('replication', {trigger: true}); + event.preventDefault(); + app_router.navigate('replication', { + trigger: true + }); } -}); +}); \ No newline at end of file diff --git a/src/rockstor/storageadmin/static/storageadmin/js/views/add_samba_export.js b/src/rockstor/storageadmin/static/storageadmin/js/views/add_samba_export.js index 8dfa71871..99bc3eeea 100644 --- a/src/rockstor/storageadmin/static/storageadmin/js/views/add_samba_export.js +++ b/src/rockstor/storageadmin/static/storageadmin/js/views/add_samba_export.js @@ -25,245 +25,258 @@ */ AddSambaExportView = RockstorLayoutView.extend({ - events: { - 'click #cancel': 'cancel', - 'click #shadow-copy-info': 'shadowCopyInfo', - 'click #shadow_copy': 'toggleSnapPrefix' - }, + events: { + 'click #cancel': 'cancel', + 'click #shadow-copy-info': 'shadowCopyInfo', + 'click #shadow_copy': 'toggleSnapPrefix' + }, - initialize: function() { - this.constructor.__super__.initialize.apply(this, arguments); - this.template = window.JST.samba_add_samba_export; - this.shares = new ShareCollection(); - this.users = new UserCollection(); - // dont paginate shares for now - this.shares.pageSize = RockStorGlobals.maxPageSize; - this.users.pageSize = RockStorGlobals.maxPageSize; - this.dependencies.push(this.shares); - this.dependencies.push(this.users); - this.sambaShareId = this.options.sambaShareId || null; - this.sambaShares = new SambaCollection({sambaShareId: this.sambaShareId}); - this.dependencies.push(this.sambaShares); + initialize: function() { + this.constructor.__super__.initialize.apply(this, arguments); + this.template = window.JST.samba_add_samba_export; + this.shares = new ShareCollection(); + this.users = new UserCollection(); + // dont paginate shares for now + this.shares.pageSize = RockStorGlobals.maxPageSize; + this.users.pageSize = RockStorGlobals.maxPageSize; + this.dependencies.push(this.shares); + this.dependencies.push(this.users); + this.sambaShareId = this.options.sambaShareId || null; + this.sambaShares = new SambaCollection({ + sambaShareId: this.sambaShareId + }); + this.dependencies.push(this.sambaShares); - this.yes_no_choices = [ - {name: 'yes', value: 'yes'}, - {name: 'no', value: 'no'}, - ]; - this.initHandlebarHelpers(); - }, + this.yes_no_choices = [{ + name: 'yes', + value: 'yes' + }, + { + name: 'no', + value: 'no' + }, + ]; + this.initHandlebarHelpers(); + }, - render: function() { - this.fetch(this.renderSambaForm, this); - return this; - }, + render: function() { + this.fetch(this.renderSambaForm, this); + return this; + }, - renderSambaForm: function() { - var _this = this; - this.freeShares = this.shares.reject(function(share) { - s = this.sambaShares.find(function(sambaShare) { - return (sambaShare.get('share') == share.get('name')); - }); - return !_.isUndefined(s); - }, this); - //convert array elements into JSON objects - for(var i = 0; i < this.freeShares.length; i++){ - this.freeShares[i] = this.freeShares[i].toJSON(); - } - - this.sShares = this.shares.reject(function(share) { - s = this.sambaShares.find(function(sambaShare) { - return (sambaShare.get('share') != share.get('name')); - }); - return !_.isUndefined(s); - }, this); + renderSambaForm: function() { + var _this = this; + this.freeShares = this.shares.reject(function(share) { + s = this.sambaShares.find(function(sambaShare) { + return (sambaShare.get('share') == share.get('name')); + }); + return !_.isUndefined(s); + }, this); + //convert array elements into JSON objects + for (var i = 0; i < this.freeShares.length; i++) { + this.freeShares[i] = this.freeShares[i].toJSON(); + } - //Edit view gets the sambaShareId from initalize function and Null in Add view. - var sambaShareIdNotNull = false; - var sambaShareIdNull = false; + this.sShares = this.shares.reject(function(share) { + s = this.sambaShares.find(function(sambaShare) { + return (sambaShare.get('share') != share.get('name')); + }); + return !_.isUndefined(s); + }, this); - if(this.sambaShareId == null){ - sambaShareIdNull = true; - } - if(this.sambaShareId != null){ - this.sShares = this.sambaShares.get(this.sambaShareId); - sambaShareIdNotNull = true; - }else{ - this.sShares = null; - } + //Edit view gets the sambaShareId from initalize function and Null in Add view. + var sambaShareIdNotNull = false; + var sambaShareIdNull = false; - var configList = '', - smbShareName, - smbShadowCopy, - smbComments, - smbSnapPrefix = ''; - if (this.sShares != null) { - var config = this.sShares.get('custom_config'), - smbShareName = this.sShares.get('share'), - smbShadowCopy = this.sShares.get("shadow_copy"), - smbComments = this.sShares.get("comments"), - smbSnapPrefix = this.sShares.get("snapshot_prefix"); + if (this.sambaShareId == null) { + sambaShareIdNull = true; + } + if (this.sambaShareId != null) { + this.sShares = this.sambaShares.get(this.sambaShareId); + sambaShareIdNotNull = true; + } else { + this.sShares = null; + } - for(i=0; i 0) { - for(i=0; i< _this.smbShare.get('admin_users').length; i++){ - if(_this.smbShare.get('admin_users')[i].username == userName){ - html += 'selected= "selected"'; - } - } + toggleSnapPrefix: function() { + var cbox = this.$('#shadow_copy'); + if (cbox.prop('checked')) { + this.$('#snapprefix-ph').css('visibility', 'visible'); + } else { + this.$('#snapprefix-ph').css('visibility', 'hidden'); + } + }, - } - html += '>' + userName + ''; - }); + initHandlebarHelpers: function() { + Handlebars.registerHelper('display_adminUser_options', function() { + var html = ''; + var _this = this; + this.users.each(function(user, index) { + var userName = user.get('username'); + html += ''; + }); - Handlebars.registerHelper('display_options', function(inputOption){ - var html = ''; - var _this = this; - _.each(this.yes_no_choices, function(c) { - var choiceValue = c.value, - choiceName = c.name; + return new Handlebars.SafeString(html); + }); - html += '