Commit 40cbc1d0 authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

properties synced

parent 068abffb
......@@ -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
......@@ -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();
},
......
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment