diff --git a/src/model.js b/src/model.js index cb102004..3253ec7d 100644 --- a/src/model.js +++ b/src/model.js @@ -179,7 +179,7 @@ my.Field = Backbone.Model.extend({ if ('0' in data) { throw new Error('Looks like you did not pass a proper hash with id to Field constructor'); } - if (this.attributes.label == null) { + if (this.attributes.label === null) { this.set({label: this.id}); } if (options) { @@ -192,7 +192,7 @@ my.Field = Backbone.Model.extend({ }, defaultRenderers: { object: function(val, field, doc) { - return JSON.stringify(val) + return JSON.stringify(val); }, 'float': function(val, field, doc) { var format = field.get('format'); @@ -259,13 +259,13 @@ my.FieldList = Backbone.Collection.extend({ my.Query = Backbone.Model.extend({ defaults: function() { return { - size: 100 - , from: 0 - , facets: {} + size: 100, + from: 0, + facets: {}, // // , filter: {} - , filters: [] - } + filters: [] + }; }, // #### addTermFilter // @@ -372,7 +372,7 @@ my.Facet = Backbone.Model.extend({ other: 0, missing: 0, terms: [] - } + }; } }); diff --git a/src/util.js b/src/util.js index ab2acbef..cd0086be 100644 --- a/src/util.js +++ b/src/util.js @@ -2,8 +2,8 @@ var util = function() { var templates = { - transformActions: '
  • Global transform...
  • ' - , cellEditor: ' \ + transformActions: '
  • Global transform...
  • ', + cellEditor: ' \ \ \ - ' - , editPreview: ' \ + ', + editPreview: ' \
    \ \ \ @@ -63,7 +63,7 @@ var util = function() { function registerEmitter() { var Emitter = function(obj) { this.emit = function(obj, channel) { - if (!channel) var channel = 'data'; + if (!channel) channel = 'data'; this.trigger(channel, obj); }; }; @@ -80,7 +80,7 @@ var util = function() { 104: "8", 105: "9", 106: "*", 107: "+", 109: "-", 110: ".", 111 : "/", 112: "f1", 113: "f2", 114: "f3", 115: "f4", 116: "f5", 117: "f6", 118: "f7", 119: "f8", 120: "f9", 121: "f10", 122: "f11", 123: "f12", 144: "numlock", 145: "scroll", 191: "/", 224: "meta" - } + }; window.addEventListener("keyup", function(e) { var pressed = shortcuts[e.keyCode]; if(_.include(keys, pressed)) app.emitter.emit("keyup", pressed); @@ -126,10 +126,11 @@ var util = function() { if ( !options ) options = {data: {}}; if ( !options.data ) options = {data: options}; var html = $.mustache( templates[template], options.data ); + var targetDom = null; if (target instanceof jQuery) { - var targetDom = target; + targetDom = target; } else { - var targetDom = $( "." + target + ":first" ); + targetDom = $( "." + target + ":first" ); } if( options.append ) { targetDom.append( html ); diff --git a/src/view-flot-graph.js b/src/view-flot-graph.js index cb47f441..afb8f061 100644 --- a/src/view-flot-graph.js +++ b/src/view-flot-graph.js @@ -80,10 +80,10 @@ my.FlotGraph = Backbone.View.extend({ ', events: { - 'change form select': 'onEditorSubmit' - , 'click .editor-add': 'addSeries' - , 'click .action-remove-series': 'removeSeries' - , 'click .action-toggle-help': 'toggleHelp' + 'change form select': 'onEditorSubmit', + 'click .editor-add': 'addSeries', + 'click .action-remove-series': 'removeSeries', + 'click .action-toggle-help': 'toggleHelp' }, initialize: function(options, config) { @@ -129,12 +129,12 @@ my.FlotGraph = Backbone.View.extend({ var series = this.$series.map(function () { return $(this).val(); }); - this.chartConfig.series = $.makeArray(series) + this.chartConfig.series = $.makeArray(series); this.chartConfig.group = this.el.find('.editor-group select').val(); this.chartConfig.graphType = this.el.find('.editor-type select').val(); // update navigation var qs = my.parseHashQueryString(); - qs['graph'] = JSON.stringify(this.chartConfig); + qs.graph = JSON.stringify(this.chartConfig); my.setHashQueryString(qs); this.redraw(); }, @@ -147,8 +147,8 @@ my.FlotGraph = Backbone.View.extend({ // Uncaught Invalid dimensions for plot, width = 0, height = 0 // * There is no data for the plot -- either same error or may have issues later with errors like 'non-existent node-value' var areWeVisible = !jQuery.expr.filters.hidden(this.el[0]); - if ((!areWeVisible || this.model.currentDocuments.length == 0)) { - return + if ((!areWeVisible || this.model.currentDocuments.length === 0)) { + return; } var series = this.createSeries(); var options = this.getGraphOptions(this.chartConfig.graphType); @@ -181,7 +181,7 @@ my.FlotGraph = Backbone.View.extend({ } } return val; - } + }; // TODO: we should really use tickFormatter and 1 interval ticks if (and // only if) x-axis values are non-numeric // However, that is non-trivial to work out from a dataset (datasets may @@ -191,21 +191,21 @@ my.FlotGraph = Backbone.View.extend({ series: { lines: { show: true } } - } - , points: { + }, + points: { series: { points: { show: true } }, grid: { hoverable: true, clickable: true } - } - , 'lines-and-points': { + }, + 'lines-and-points': { series: { points: { show: true }, lines: { show: true } }, grid: { hoverable: true, clickable: true } - } - , bars: { + }, + bars: { series: { lines: {show: false}, bars: { @@ -225,7 +225,7 @@ my.FlotGraph = Backbone.View.extend({ max: self.model.currentDocuments.length - 0.5 } } - } + }; return options[typeId]; }, diff --git a/src/view-grid.js b/src/view-grid.js index 527b33c5..eb736524 100644 --- a/src/view-grid.js +++ b/src/view-grid.js @@ -25,10 +25,10 @@ my.DataGrid = Backbone.View.extend({ }, events: { - 'click .column-header-menu': 'onColumnHeaderClick' - , 'click .row-header-menu': 'onRowHeaderClick' - , 'click .root-header-menu': 'onRootHeaderClick' - , 'click .data-table-menu li a': 'onMenuClick' + 'click .column-header-menu': 'onColumnHeaderClick', + 'click .row-header-menu': 'onRowHeaderClick', + 'click .root-header-menu': 'onRootHeaderClick', + 'click .data-table-menu li a': 'onMenuClick' }, // TODO: delete or re-enable (currently this code is not used from anywhere except deprecated or disabled methods (see above)). @@ -67,7 +67,7 @@ my.DataGrid = Backbone.View.extend({ var self = this; e.preventDefault(); var actions = { - bulkEdit: function() { self.showTransformColumnDialog('bulkEdit', {name: self.state.currentColumn}) }, + bulkEdit: function() { self.showTransformColumnDialog('bulkEdit', {name: self.state.currentColumn}); }, facet: function() { self.model.queryState.addFacet(self.state.currentColumn); }, @@ -77,26 +77,25 @@ my.DataGrid = Backbone.View.extend({ filter: function() { self.model.queryState.addTermFilter(self.state.currentColumn, ''); }, - transform: function() { self.showTransformDialog('transform') }, - sortAsc: function() { self.setColumnSort('asc') }, - sortDesc: function() { self.setColumnSort('desc') }, - hideColumn: function() { self.hideColumn() }, - showColumn: function() { self.showColumn(e) }, + transform: function() { self.showTransformDialog('transform'); }, + sortAsc: function() { self.setColumnSort('asc'); }, + sortDesc: function() { self.setColumnSort('desc'); }, + hideColumn: function() { self.hideColumn(); }, + showColumn: function() { self.showColumn(e); }, deleteRow: function() { var doc = _.find(self.model.currentDocuments.models, function(doc) { // important this is == as the currentRow will be string (as comes // from DOM) while id may be int - return doc.id == self.state.currentRow + return doc.id == self.state.currentRow; }); doc.destroy().then(function() { self.model.currentDocuments.remove(doc); my.notify("Row deleted successfully"); - }) - .fail(function(err) { - my.notify("Errorz! " + err) - }) + }).fail(function(err) { + my.notify("Errorz! " + err); + }); } - } + }; actions[$(e.target).attr('data-action')](); }, @@ -112,7 +111,7 @@ my.DataGrid = Backbone.View.extend({ $el.append(view.el); util.observeExit($el, function() { util.hide('dialog'); - }) + }); $('.dialog').draggable({ handle: '.dialog-header', cursor: 'move' }); }, @@ -126,7 +125,7 @@ my.DataGrid = Backbone.View.extend({ $el.append(view.el); util.observeExit($el, function() { util.hide('dialog'); - }) + }); $('.dialog').draggable({ handle: '.dialog-header', cursor: 'move' }); }, @@ -189,10 +188,10 @@ my.DataGrid = Backbone.View.extend({ ', toTemplateJSON: function() { - var modelData = this.model.toJSON() - modelData.notEmpty = ( this.fields.length > 0 ) + var modelData = this.model.toJSON(); + modelData.notEmpty = ( this.fields.length > 0 ); // TODO: move this sort of thing into a toTemplateJSON method on Dataset? - modelData.fields = _.map(this.fields, function(field) { return field.toJSON() }); + modelData.fields = _.map(this.fields, function(field) { return field.toJSON(); }); return modelData; }, render: function() { @@ -212,7 +211,7 @@ my.DataGrid = Backbone.View.extend({ }); newView.render(); }); - this.el.toggleClass('no-hidden', (self.hiddenFields.length == 0)); + this.el.toggleClass('no-hidden', (self.hiddenFields.length === 0)); return this; } }); @@ -271,9 +270,9 @@ my.DataGridRow = Backbone.View.extend({ return { field: field.id, value: doc.getFieldValue(field) - } - }) - return { id: this.id, cells: cellData } + }; + }); + return { id: this.id, cells: cellData }; }, render: function() { diff --git a/src/view-map.js b/src/view-map.js index 1d985a6e..0cc22d06 100644 --- a/src/view-map.js +++ b/src/view-map.js @@ -59,7 +59,7 @@ my.Map = Backbone.View.extend({ if (!self.mapReady){ self._setupMap(); } - self.redraw() + self.redraw(); }); return this; @@ -79,9 +79,9 @@ my.Map = Backbone.View.extend({ if (feature){ // Build popup contents // TODO: mustache? - html = '' - for (key in doc.attributes){ - html += '
    ' + key + ': '+ doc.attributes[key] + '
    ' + var html = ''; + for (key in doc.attributes) { + html += '
    ' + key + ': '+ doc.attributes[key] + '
    '; } feature.properties = {popupContent: html}; @@ -105,9 +105,9 @@ my.Map = Backbone.View.extend({ type: 'Point', coordinates: [ doc.attributes[this._lonFieldName], - doc.attributes[this._latFieldName], + doc.attributes[this._latFieldName] ] - } + }; } return null; } diff --git a/src/view-transform-dialog.js b/src/view-transform-dialog.js index 191e6811..12f83872 100644 --- a/src/view-transform-dialog.js +++ b/src/view-transform-dialog.js @@ -132,8 +132,8 @@ my.ColumnTransform = Backbone.View.extend({ ', events: { - 'click .okButton': 'onSubmit' - , 'keydown .expression-preview-code': 'onEditorKeydown' + 'click .okButton': 'onSubmit', + 'keydown .expression-preview-code': 'onEditorKeydown' }, initialize: function() { @@ -143,7 +143,7 @@ my.ColumnTransform = Backbone.View.extend({ render: function() { var htmls = $.mustache(this.template, {name: this.state.currentColumn} - ) + ); this.el.html(htmls); // Put in the basic (identity) transform script // TODO: put this into the template? @@ -181,7 +181,7 @@ my.ColumnTransform = Backbone.View.extend({ _.each(toUpdate, function(editedDoc) { var realDoc = self.model.currentDocuments.get(editedDoc.id); realDoc.set(editedDoc); - realDoc.save().then(onCompletedUpdate).fail(onCompletedUpdate) + realDoc.save().then(onCompletedUpdate).fail(onCompletedUpdate); }); }, diff --git a/src/view.js b/src/view.js index 4eb078dd..d9369f49 100644 --- a/src/view.js +++ b/src/view.js @@ -123,7 +123,7 @@ my.DataExplorer = Backbone.View.extend({ my.notify('Data loaded', {category: 'success'}); // update navigation var qs = my.parseHashQueryString(); - qs['reclineQuery'] = JSON.stringify(self.model.queryState.toJSON()); + qs.reclineQuery = JSON.stringify(self.model.queryState.toJSON()); var out = my.getNewHashForQueryString(qs); self.router.navigate(out); }); @@ -172,7 +172,7 @@ my.DataExplorer = Backbone.View.extend({ $(this.el).html(template); var $dataViewContainer = this.el.find('.data-view-container'); _.each(this.pageViews, function(view, pageName) { - $dataViewContainer.append(view.view.el) + $dataViewContainer.append(view.view.el); }); var queryEditor = new my.QueryEditor({ model: this.model.queryState @@ -250,8 +250,8 @@ my.QueryEditor = Backbone.View.extend({ ', events: { - 'submit form': 'onFormSubmit' - , 'click .action-pagination-update': 'onPaginationUpdate' + 'submit form': 'onFormSubmit', + 'click .action-pagination-update': 'onPaginationUpdate' }, initialize: function() { @@ -270,10 +270,11 @@ my.QueryEditor = Backbone.View.extend({ onPaginationUpdate: function(e) { e.preventDefault(); var $el = $(e.target); + var newFrom = 0; if ($el.parent().hasClass('prev')) { - var newFrom = this.model.get('from') - Math.max(0, this.model.get('size')); + newFrom = this.model.get('from') - Math.max(0, this.model.get('size')); } else { - var newFrom = this.model.get('from') + this.model.get('size'); + newFrom = this.model.get('from') + this.model.get('size'); } this.model.set({from: newFrom}); }, @@ -346,7 +347,7 @@ my.FilterEditor = Backbone.View.extend({ fieldId: fieldId, label: fieldId, value: filter.term[fieldId] - } + }; }); var out = $.mustache(this.template, tmplData); this.el.html(out); @@ -462,15 +463,15 @@ var urlPathRegex = /^([^?]+)(\?.*)?/; // Parse the Hash section of a URL into path and query string my.parseHashUrl = function(hashUrl) { var parsed = urlPathRegex.exec(hashUrl); - if (parsed == null) { + if (parsed === null) { return {}; } else { return { path: parsed[1], query: parsed[2] || '' - } + }; } -} +}; // Parse a URL query string (?xyz=abc...) into a dictionary. my.parseQueryString = function(q) { @@ -491,13 +492,13 @@ my.parseQueryString = function(q) { urlParams[d(e[1])] = d(e[2]); } return urlParams; -} +}; // Parse the query string out of the URL hash my.parseHashQueryString = function() { q = my.parseHashUrl(window.location.hash).query; return my.parseQueryString(q); -} +}; // Compse a Query String my.composeQueryString = function(queryParams) { @@ -508,7 +509,7 @@ my.composeQueryString = function(queryParams) { }); queryString += items.join('&'); return queryString; -} +}; my.getNewHashForQueryString = function(queryParams) { var queryPart = my.composeQueryString(queryParams); @@ -518,11 +519,11 @@ my.getNewHashForQueryString = function(queryParams) { } else { return queryPart; } -} +}; my.setHashQueryString = function(queryParams) { window.location.hash = my.getNewHashForQueryString(queryParams); -} +}; // ## notify // @@ -532,7 +533,7 @@ my.setHashQueryString = function(queryParams) { // * persist: if true alert is persistent, o/w hidden after 3s (default = false) // * loader: if true show loading spinner my.notify = function(message, options) { - if (!options) var options = {}; + if (!options) options = {}; var tmplData = _.extend({ msg: message, category: 'warning' @@ -554,7 +555,7 @@ my.notify = function(message, options) { }); }, 1000); } -} +}; // ## clearNotifications // @@ -562,7 +563,7 @@ my.notify = function(message, options) { my.clearNotifications = function() { var $notifications = $('.recline-data-explorer .alert-messages .alert'); $notifications.remove(); -} +}; })(jQuery, recline.View);