More consistent JavaScript style as per @ahgittin
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/commit/bd8e9aaa Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/tree/bd8e9aaa Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/diff/bd8e9aaa Branch: refs/heads/0.5.0 Commit: bd8e9aaa3c88fa02f8b444f57791fe2095bb2052 Parents: b0864c1 Author: Andrew Kennedy <[email protected]> Authored: Wed Feb 20 00:52:48 2013 +0000 Committer: Andrew Kennedy <[email protected]> Committed: Wed Feb 27 17:26:57 2013 +0000 ---------------------------------------------------------------------- .../webapp/assets/js/view/entity-activities.js | 94 ++++++++++---------- .../main/webapp/assets/js/view/entity-config.js | 31 +++---- .../webapp/assets/js/view/entity-sensors.js | 53 +++++------ 3 files changed, 90 insertions(+), 88 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/bd8e9aaa/usage/jsgui/src/main/webapp/assets/js/view/entity-activities.js ---------------------------------------------------------------------- diff --git a/usage/jsgui/src/main/webapp/assets/js/view/entity-activities.js b/usage/jsgui/src/main/webapp/assets/js/view/entity-activities.js index 94e1a23..f7389e7 100644 --- a/usage/jsgui/src/main/webapp/assets/js/view/entity-activities.js +++ b/usage/jsgui/src/main/webapp/assets/js/view/entity-activities.js @@ -13,26 +13,26 @@ define([ "click #activities-table tr":"rowClick" }, initialize:function () { - var that = this - this.$el.html(this.template({})) - this.collection.url = this.model.getLinkByName("activities") - this.collection.fetch() - this.collection.on("reset", this.render, this) - this.callPeriodically("entity-activities", function () { - that.collection.fetch() - }, 5000) + var that = this; + that.$el.html(that.template({})); + that.collection.url = that.model.getLinkByName("activities"); + that.collection.fetch(); + that.collection.on("reset", that.render, that); + that.callPeriodically("entity-activities", function () { + that.collection.fetch(); + }, 5000); }, beforeClose:function () { - this.collection.off("reset", this.render) + this.collection.off("reset", this.render); }, render:function () { var that = this, - $tbody = this.$("#activities-table tbody").empty() + $tbody = $("#activities-table tbody").empty(); if (this.collection.length==0) { - this.$(".has-no-activities").show(); - this.$("#activity-details-none-selected").hide() - } else { - this.$(".has-no-activities").hide(); + $(".has-no-activities").show(); + $("#activity-details-none-selected").hide(); + } else { + $(".has-no-activities").hide(); this.collection.each(function (task) { $tbody.append(that.taskRow({ cid:task.get("id"), @@ -42,53 +42,52 @@ define([ endTimeUtc:task.get("endTimeUtc"), currentStatus:task.get("currentStatus"), entityDisplayName:task.get("entityDisplayName") - })) + })); if (that.activeTask) { - $("#activities-table tr[id='"+that.activeTask+"']").addClass("selected") - that.showFullActivity(that.activeTask) + $("#activities-table tr[id='"+that.activeTask+"']").addClass("selected"); + that.showFullActivity(that.activeTask); } else { - this.$("#activity-details-none-selected").show() + $("#activity-details-none-selected").show(); } - }) + }); } - return this + return this; }, - rowClick: function(evt) { - var row = $(evt.currentTarget).closest("tr") - var id = row.attr("id") - $("#activities-table tr").removeClass("selected") + rowClick:function(evt) { + var row = $(evt.currentTarget).closest("tr"); + var id = row.attr("id"); + $("#activities-table tr").removeClass("selected"); if (this.activeTask == id) { // deselected - this.showFullActivity(null) + this.showFullActivity(null); } else { - row.addClass("selected") - this.activeTask = id - this.showFullActivity(id) + row.addClass("selected"); + this.activeTask = id; + this.showFullActivity(id); } }, showFullActivity:function (id) { - this.$("#activity-details-none-selected").hide(100) - var task = this.collection.get(id) + $("#activity-details-none-selected").hide(100); + var task = this.collection.get(id); if (task==null) { - this.activeTask = null - this.$("#activity-details").hide(100) - this.$("#activity-details-none-selected").show(100) - return + this.activeTask = null; + $("#activity-details").hide(100); + $("#activity-details-none-selected").show(100); + return; } - - var $ta = this.$("#activity-details textarea") + var $ta = this.$("#activity-details textarea"); if ($ta.length) { - $ta.val(FormatJSON(task.toJSON())) + $ta.val(FormatJSON(task.toJSON())); } else { var html = _.template(ActivityDetailsHtml, { displayName:this.model.get("displayName"), - description:FormatJSON(task.toJSON()) - }) - this.$("#activity-details").html(html) + description:FormatJSON(task.toJSON()) + }); + $("#activity-details").html(html); } - this.$("#activity-details").show(100) + $("#activity-details").show(100); } - }) + }); ActivitiesView.Details = Backbone.View.extend({ tagName:"div", @@ -98,10 +97,9 @@ define([ this.$el.html(this.template({ displayName:this.model.get("displayName"), description:FormatJSON(this.model.toJSON()) - })) - return this + })); + return this; } - }) - - return ActivitiesView -}) \ No newline at end of file + }); + return ActivitiesView; +}); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/bd8e9aaa/usage/jsgui/src/main/webapp/assets/js/view/entity-config.js ---------------------------------------------------------------------- diff --git a/usage/jsgui/src/main/webapp/assets/js/view/entity-config.js b/usage/jsgui/src/main/webapp/assets/js/view/entity-config.js index 5cf7482..0a79bc8 100644 --- a/usage/jsgui/src/main/webapp/assets/js/view/entity-config.js +++ b/usage/jsgui/src/main/webapp/assets/js/view/entity-config.js @@ -1,5 +1,6 @@ /** * Render entity config tab. + * * @type {*} */ define([ @@ -15,12 +16,13 @@ define([ 'click .filterEmpty':'toggleFilterEmpty' }, initialize:function () { - this.$el.html(this.template({})) - var configCollection = new ConfigSummary.Collection, - $table = this.$('#config-table'), - $tableBody = this.$('tbody').empty(), - that = this - configCollection.url = this.model.getLinkByName('config') + this.$el.html(this.template({})); + var that = this, + configCollection = new ConfigSummary.Collection, + $table = $('#config-table'), + $tableBody = $('tbody').empty(); + ViewUtils.myDataTable($table); + configCollection.url = this.model.getLinkByName('config'); var success = function () { configCollection.each(function (config) { $tableBody.append(that.configTemplate({ @@ -28,21 +30,20 @@ define([ description:config.get("description"), value:'', type:config.get("type") - })) - }) - that.updateConfigPeriodically(that) - ViewUtils.myDataTable($table) + })); + }); + that.updateConfigPeriodically(); // TODO tooltip doesn't work on 'i' elements in table (bottom left toolbar) - $table.find('*[rel="tooltip"]').tooltip() - } - configCollection.fetch({async:false, success:success}) - this.toggleFilterEmpty() + $table.find('*[rel="tooltip"]').tooltip(); + }; + configCollection.fetch({ async:false, success:success }); + this.toggleFilterEmpty(); }, render:function () { return this }, toggleFilterEmpty: function() { - ViewUtils.toggleFilterEmpty(this.$('#config-table'), 1) + ViewUtils.toggleFilterEmpty(this.$('#config-table'), 1); }, refreshConfig:function () { this.updateConfigNow(this); http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/bd8e9aaa/usage/jsgui/src/main/webapp/assets/js/view/entity-sensors.js ---------------------------------------------------------------------- diff --git a/usage/jsgui/src/main/webapp/assets/js/view/entity-sensors.js b/usage/jsgui/src/main/webapp/assets/js/view/entity-sensors.js index 63c9b04..044c10c 100644 --- a/usage/jsgui/src/main/webapp/assets/js/view/entity-sensors.js +++ b/usage/jsgui/src/main/webapp/assets/js/view/entity-sensors.js @@ -1,5 +1,6 @@ /** * Render entity sensors tab. + * * @type {*} */ define([ @@ -15,50 +16,52 @@ define([ 'click .filterEmpty':'toggleFilterEmpty' }, initialize:function () { - this.$el.html(this.template({})) - var sensorsCollection = new SensorSummary.Collection, - $table = this.$('#sensors-table'), - $tableBody = this.$('tbody').empty(), - that = this - sensorsCollection.url = this.model.getLinkByName('sensors') + this.$el.html(this.template({ })); + var that = this, + sensorsCollection = new SensorSummary.Collection, + $table = $('#sensors-table'), + $tableBody = $('tbody').empty(); + ViewUtils.myDataTable($table); + sensorsCollection.url = that.model.getLinkByName('sensors'); var success = function () { sensorsCollection.each(function (sensor) { var actions = {}; _.each(sensor.get("links"), function(v,k) { if (k.slice(0, 7) == "action:") { - actions[k.slice(7)] = v + actions[k.slice(7)] = v; } - }) + }); $tableBody.append(that.sensorTemplate({ name:sensor.get("name"), description:sensor.get("description"), actions:actions, type:sensor.get("type"), value:'' /* will be set later */ - })) - }) - that.updateSensorsPeriodically(that) - ViewUtils.myDataTable($table) + })); + }); + that.updateSensorsPeriodically(that); // TODO tooltip doesn't work on 'i' elements in table (bottom left toolbar) - $table.find('*[rel="tooltip"]').tooltip() - } - sensorsCollection.fetch({async:false, success:success}) - this.toggleFilterEmpty() + $table.find('*[rel="tooltip"]').tooltip(); + }; + sensorsCollection.fetch({ async:false, success:success }); + this.toggleFilterEmpty(); }, render:function () { - return this + return this; }, - toggleFilterEmpty: function() { - ViewUtils.toggleFilterEmpty(this.$('#sensors-table'), 2) + toggleFilterEmpty:function() { + ViewUtils.toggleFilterEmpty($('#sensors-table'), 2); }, refreshSensors:function () { this.updateSensorsNow(this); }, // register a callback to update the sensors updateSensorsPeriodically:function (that) { - var self = this; - that.updateSensorsNow(that) - that.callPeriodically("entity-sensors", function() { self.updateSensorsNow(that) }, 3000) + var that = this; + that.updateSensorsNow(that); + that.callPeriodically("entity-sensors", function() { + that.updateSensorsNow(that); + }, 3000); }, updateSensorsNow:function (that) { // NB: this won't add new dynamic sensors @@ -75,6 +78,6 @@ define([ }) }) } - }) - return EntitySensorsView -}) \ No newline at end of file + }); + return EntitySensorsView; +});
