From 3e64165a47b83e5902abf51242f9992f7f210862 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sat, 3 Jan 2015 14:58:25 -0800 Subject: [PATCH] INFRA-132 - Fix jshint warnings in Backbone-based code --- js/crm.backbone.js | 25 +++++++++++++------------ js/model/crm.uf.js | 20 ++++++++++---------- js/view/crm.designer.js | 22 +++++++++++----------- 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/js/crm.backbone.js b/js/crm.backbone.js index eb45249c17..ad27bec160 100644 --- a/js/crm.backbone.js +++ b/js/crm.backbone.js @@ -15,8 +15,9 @@ CRM.Backbone.sync = function(method, model, options) { var isCollection = _.isArray(model.models); + var apiOptions, params; if (isCollection) { - var apiOptions = { + apiOptions = { success: function(data) { // unwrap data options.success(_.toArray(data.values)); @@ -35,7 +36,7 @@ break; // replace all entities matching "x.crmCriteria" with new entities in "x.models" case 'crm-replace': - var params = this.toCrmCriteria(); + params = this.toCrmCriteria(); params.version = 3; params.values = this.toJSON(); CRM.api(model.crmEntityName, model.toCrmAction('replace'), params, apiOptions); @@ -46,10 +47,10 @@ } } else { // callback options to pass to CRM.api - var apiOptions = { + apiOptions = { success: function(data) { // unwrap data - var values = _.toArray(data['values']); + var values = _.toArray(data.values); if (data.count == 1) { options.success(values[0]); } else { @@ -69,8 +70,8 @@ switch (method) { case 'create': // pass-through case 'update': - var params = model.toJSON(); - params.options || (params.options = {}); + params = model.toJSON(); + if (!params.options) params.options = {}; params.options.reload = 1; if (!model._isDuplicate) { CRM.api(model.crmEntityName, model.toCrmAction('create'), params, apiOptions); @@ -81,7 +82,7 @@ case 'read': case 'delete': var apiAction = (method == 'delete') ? 'delete' : 'get'; - var params = model.toCrmCriteria(); + params = model.toCrmCriteria(); if (!params.id) { apiOptions.error({is_error: 1, error_message: 'Missing ID for ' + model.crmEntityName}); return; @@ -359,7 +360,7 @@ * @param Object options - accepts "success" and "error" callbacks */ save: function(options) { - options || (options = {}); + if (!options) options = {}; var collection = this; var success = options.success; options.success = function(resp) { @@ -370,14 +371,14 @@ }; wrapError(collection, options); - return this.sync('crm-replace', this, options) + return this.sync('crm-replace', this, options); } }); // Overrides - if specified in CollectionClass, replace _.extend(CollectionClass.prototype, { sync: CRM.Backbone.sync, initialize: function(models, options) { - options || (options = {}); + if (!options) options = {}; if (options.crmCriteriaModel) { this.setCriteriaModel(options.crmCriteriaModel); } else if (options.crmCriteria) { @@ -416,7 +417,7 @@ * - error: function(collection, error) */ CRM.Backbone.findCreate = function(options) { - options || (options = {}); + if (!options) options = {}; var collection = new options.CollectionClass([], { crmCriteria: options.crmCriteria }); @@ -564,7 +565,7 @@ var wrapError = function (model, options) { var error = options.error; options.error = function(resp) { - if (error) error(model, resp, optio) + if (error) error(model, resp, optio); model.trigger('error', model, resp, options); }; }; diff --git a/js/model/crm.uf.js b/js/model/crm.uf.js index be089b1a32..08b725a0a1 100644 --- a/js/model/crm.uf.js +++ b/js/model/crm.uf.js @@ -111,7 +111,7 @@ throw "Cannot guess entity name for field_type=" + field_type; } } - } + }; /** * Represents a field in a customizable form. @@ -245,10 +245,10 @@ * @return {String} */ getSignature: function() { - return this.get("entity_name") - + '::' + this.get("field_name") - + '::' + (this.get("location_type_id") ? this.get("location_type_id") : '') - + '::' + (this.get("phone_type_id") ? this.get("phone_type_id") : ''); + return this.get("entity_name") + + '::' + this.get("field_name") + + '::' + (this.get("location_type_id") ? this.get("location_type_id") : '') + + '::' + (this.get("phone_type_id") ? this.get("phone_type_id") : ''); }, /** @@ -496,14 +496,14 @@ }, 'help_post': { title: ts('Post-form Help'), - help: ts('Explanatory text displayed at the end of the form.') - + ts('Note that this help text is displayed on profile create/edit screens only.'), + help: ts('Explanatory text displayed at the end of the form.') + + ts('Note that this help text is displayed on profile create/edit screens only.'), type: 'TextArea' }, 'help_pre': { title: ts('Pre-form Help'), - help: ts('Explanatory text displayed at the beginning of the form.') - + ts('Note that this help text is displayed on profile create/edit screens only.'), + help: ts('Explanatory text displayed at the beginning of the form.') + + ts('Note that this help text is displayed on profile create/edit screens only.'), type: 'TextArea' }, 'is_active': { @@ -598,7 +598,7 @@ ufGroupModel: this }); paletteFieldCollection.sync = function(method, model, options) { - options || (options = {}); + if (!options) options = {}; // console.log(method, model, options); switch (method) { case 'read': diff --git a/js/view/crm.designer.js b/js/view/crm.designer.js index b4b49cd249..b6d0ad11f2 100644 --- a/js/view/crm.designer.js +++ b/js/view/crm.designer.js @@ -52,7 +52,7 @@ CRM.designerApp.vent.on('ufSaved', this.onUfSaved, this); }, onClose: function() { - this.undoAlert && this.undoAlert.close && this.undoAlert.close(); + if (this.undoAlert && this.undoAlert.close) this.undoAlert.close(); CRM.designerApp.vent.off('ufUnsaved', this.onUfChanged, this); }, onUfChanged: function(isUfUnsaved) { @@ -69,7 +69,7 @@ title: ts('Edit Profile'), modal: true, width: '75%', - height: parseInt($(window).height() *.8, 10), + height: parseInt($(window).height() * 0.8, 10), minWidth: 500, minHeight: 600, // to allow dropping in big whitespace, coordinate with min-height of .crm-designer-fields open: function() { @@ -84,11 +84,11 @@ return designerDialog.oldOnBeforeUnload.apply(arguments); } }; - designerDialog.undoAlert && designerDialog.undoAlert.close && designerDialog.undoAlert.close(); + if (designerDialog.undoAlert && designerDialog.undoAlert.close) designerDialog.undoAlert.close(); designerDialog.isDialogOpen = true; // Initialize new dialog if we are not re-opening unsaved changes if (designerDialog.undoState === false) { - designerDialog.designerRegion && designerDialog.designerRegion.close && designerDialog.designerRegion.close(); + if (designerDialog.designerRegion && designerDialog.designerRegion.close) designerDialog.designerRegion.close(); designerDialog.$el.block(); designerDialog.options.findCreateUfGroupModel({ onLoad: function(ufGroupModel) { @@ -112,7 +112,7 @@ window.onbeforeunload = designerDialog.oldOnBeforeUnload; designerDialog.isDialogOpen = false; - designerDialog.undoAlert && designerDialog.undoAlert.close && designerDialog.undoAlert.close(); + if (designerDialog.undoAlert && designerDialog.undoAlert.close) designerDialog.undoAlert.close(); if (designerDialog.isUfUnsaved) { designerDialog.undoAlert = CRM.alert('

' + ts('%1 has not been saved.', {1: designerDialog.model.get('title')}) + '

' + ts('Restore') + '', ts('Unsaved Changes'), 'alert', {expires: 60000}); $('.ui-notify-message a.crm-undo').button({icons: {primary: 'ui-icon-arrowreturnthick-1-w'}}).click(function(e) { @@ -254,7 +254,7 @@ if (!this.previewMode) { $('.crm-designer-preview-canvas').html(''); $('.crm-designer-canvas > *, .crm-designer-palette-region').show(); - $('.crm-designer-preview').button('option', {icons: {primary: 'ui-icon-search'}}).find('span').text(ts('Preview'));; + $('.crm-designer-preview').button('option', {icons: {primary: 'ui-icon-search'}}).find('span').text(ts('Preview')); return; } if (this.model.getRel('ufFieldCollection').hasDuplicates()) { @@ -357,7 +357,7 @@ } }); } - }) + }); }); this.$('.crm-designer-palette-tree').jstree({ @@ -381,7 +381,7 @@ connectToSortable: '.crm-designer-fields' // FIXME: tight canvas/palette coupling }); paletteView.model.getRel('ufFieldCollection').each(function(ufFieldModel) { - paletteView.toggleActive(ufFieldModel, paletteView.model.getRel('ufFieldCollection')) + paletteView.toggleActive(ufFieldModel, paletteView.model.getRel('ufFieldCollection')); }); paletteView.$('.crm-designer-palette-add a').replaceWith(''); @@ -452,7 +452,7 @@ CRM.loadForm(url, {refreshAction: ['next']}) .on('crmFormSuccess', function(e, data) { // When form switches to create custom field context, modify button behavior to only continue for "save and new" - data.customField && ($(this).data('civiCrmSnippet').options.crmForm.refreshAction = ['next_new']); + if (data.customField) ($(this).data('civiCrmSnippet').options.crmForm.refreshAction = ['next_new']); paletteView.doRefresh(data.customField ? 'custom_' + data.id : null); }); }, @@ -494,7 +494,7 @@ this.openTreeNodes = []; this.$('.crm-designer-palette-section.jstree-open').each(function() { paletteView.openTreeNodes.push($(this).data('section')); - }) + }); } }); @@ -623,7 +623,7 @@ model: this.model, fieldSchema: this.model.getFieldSchema() })); - this.onChangeIsDuplicate(this.model, this.model.get('is_duplicate')) + this.onChangeIsDuplicate(this.model, this.model.get('is_duplicate')); if (!this.expanded) { this.detail.$el.hide(); } -- 2.25.1