From 40cbc1d0000918f451b5b172075e9a865fe26863 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Thu, 10 Sep 2015 16:02:56 -0400 Subject: [PATCH] properties synced --- js/SerialMonitor/SerialMonitor.js | 6 +++-- js/SerialMonitor/SerialMonitorView.js | 37 ++++++++++++++++++++++++++- js/SerialMonitor/main.js | 4 +-- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/js/SerialMonitor/SerialMonitor.js b/js/SerialMonitor/SerialMonitor.js index 8fa39669..cb2a7a0d 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 8defaaa7..0e14802f 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 922150d1..d9d34715 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 -- GitLab