diff --git a/js/SerialMonitor/SerialMonitor.js b/js/SerialMonitor/SerialMonitor.js index 8fa39669b431e5bf99c43538691ed2cc86572903..cb2a7a0d307251677b1ba2788bf445473a81604c 100644 --- a/js/SerialMonitor/SerialMonitor.js +++ b/js/SerialMonitor/SerialMonitor.js @@ -5,11 +5,13 @@ define(['backbone'], function(Backbone){ - return Backbone.Model.extend({ + var SerialMonitor = Backbone.Model.extend({ defaults: { - autoscroll: true + autoscroll: false } }); + + return new SerialMonitor(); }); \ No newline at end of file diff --git a/js/SerialMonitor/SerialMonitorView.js b/js/SerialMonitor/SerialMonitorView.js index 8defaaa758b5a8a58668ebce759186952ec76613..0e14802f98509e183db2e08ce4ceb12d4c989de9 100644 --- a/js/SerialMonitor/SerialMonitorView.js +++ b/js/SerialMonitor/SerialMonitorView.js @@ -11,13 +11,48 @@ define(['jquery', 'underscore', 'commParentMenu', 'serialComm', 'text!SerialMoni el: "#serialMonitorView", events: { - "click #clearMonitor": "_clear" + "click #clearMonitor": "_clear", + "change input:checkbox": "_clickCheckbox" }, __initialize: function(){ this.render(); }, + _clickCheckbox: function(e){ + e.preventDefault(); + var $target = $(e.target); + $target.blur(); + var property = $target.data("property"); + if (!property) { + console.warn("no property associated with checkbox input"); + return; + } + this._toggleProperty($target, property); + }, + + _toggleProperty: function($target, property){ //val = !val + var owner = this._getPropertyOwner($target); + if (owner) this._setOwnerProperty(owner, property, !(this._getOwnerProperty(owner, property))); + }, + + _getPropertyOwner: function($target){ + if ($target.hasClass("serialMonitor")) return this.model; + return null; + }, + + _getOwnerProperty: function(owner, property){ + if (owner instanceof Backbone.Model) return owner.get(property); + return owner[property]; + }, + + _setOwnerProperty: function(owner, property, value){ + if (owner instanceof Backbone.Model) owner.set(property, value); + else { + owner[property] = value; + } + }, + _makeTemplateJSON: function(){ return this.model.toJSON(); }, diff --git a/js/SerialMonitor/main.js b/js/SerialMonitor/main.js index 922150d190748874f9801b33e2f5422cfca8fd56..d9d34715d71772d41d18f4ff48d581f539f4994d 100644 --- a/js/SerialMonitor/main.js +++ b/js/SerialMonitor/main.js @@ -35,6 +35,6 @@ require.config({ }); -require(['serialMonitorView', 'serialMonitor'], function(SerialMonitorView, SerialMonitor){ - new SerialMonitorView({model: new SerialMonitor()}); +require(['serialMonitorView', 'serialMonitor'], function(SerialMonitorView, serialMonitor){ + new SerialMonitorView({model: serialMonitor}); }); \ No newline at end of file