From b588a56f76a437e42dac645fc45ade5a082d4e3c Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Mon, 30 Dec 2013 07:32:23 -0800 Subject: [PATCH] Moved touch logic out of model into view. View now updates using backbone events. --- .../html/static/notebook/js/widgets/base.js | 19 ++++++------------- .../html/static/notebook/js/widgets/bool.js | 4 ++-- .../notebook/js/widgets/multicontainer.js | 4 ++-- .../static/notebook/js/widgets/selection.js | 8 ++++---- .../html/static/notebook/js/widgets/string.js | 4 ++-- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/IPython/html/static/notebook/js/widgets/base.js b/IPython/html/static/notebook/js/widgets/base.js index 863acf64b..fb8b7efea 100644 --- a/IPython/html/static/notebook/js/widgets/base.js +++ b/IPython/html/static/notebook/js/widgets/base.js @@ -45,19 +45,6 @@ function(widget_manager, underscore, backbone){ return Backbone.Model.apply(this); }, - - - update_other_views: function (caller) { - this.last_modified_view = caller; - this.save(this.changedAttributes(), {patch: true}); - - for (var view_index in this.views) { - var view = this.views[view_index]; - if (view !== caller) { - view.update(); - } - } - }, send: function (content, cell) { @@ -507,6 +494,12 @@ function(widget_manager, underscore, backbone){ this.model.send(content, this.cell); }, + + touch: function () { + this.model.last_modified_view = this; + this.model.save(this.model.changedAttributes(), {patch: true}); + }, + update: function () { if (this.model.get('visible') !== undefined) { if (this.visible != this.model.get('visible')) { diff --git a/IPython/html/static/notebook/js/widgets/bool.js b/IPython/html/static/notebook/js/widgets/bool.js index 9d57f7db4..8f805e004 100644 --- a/IPython/html/static/notebook/js/widgets/bool.js +++ b/IPython/html/static/notebook/js/widgets/bool.js @@ -35,7 +35,7 @@ define(["notebook/js/widgets/base"], function(widget_manager){ .click(function(el) { that.user_invoked_update = true; that.model.set('value', that.$checkbox.prop('checked')); - that.model.update_other_views(that); + that.touch(); that.user_invoked_update = false; }) .appendTo(this.$el); @@ -113,7 +113,7 @@ define(["notebook/js/widgets/base"], function(widget_manager){ handleClick: function(e) { this.user_invoked_update = true; this.model.set('value', ! $(e.target).hasClass('active')); - this.model.update_other_views(this); + this.touch(); this.user_invoked_update = false; }, }); diff --git a/IPython/html/static/notebook/js/widgets/multicontainer.js b/IPython/html/static/notebook/js/widgets/multicontainer.js index f4975c066..a93f4e5f3 100644 --- a/IPython/html/static/notebook/js/widgets/multicontainer.js +++ b/IPython/html/static/notebook/js/widgets/multicontainer.js @@ -76,7 +76,7 @@ define(["notebook/js/widgets/base"], function(widget_manager){ .attr('href', '#' + uuid) .click(function(evt){ that.model.set("selected_index", index); - that.model.update_other_views(that); + that.touch(); }) .html('Page ' + index) .appendTo(accordion_heading); @@ -151,7 +151,7 @@ define(["notebook/js/widgets/base"], function(widget_manager){ .appendTo(tab) .click(function (e) { that.model.set("selected_index", index); - that.model.update_other_views(that); + that.touch(); that.select_page(index); }); this.containers.push(tab_text); diff --git a/IPython/html/static/notebook/js/widgets/selection.js b/IPython/html/static/notebook/js/widgets/selection.js index 43c7f65a3..59f814360 100644 --- a/IPython/html/static/notebook/js/widgets/selection.js +++ b/IPython/html/static/notebook/js/widgets/selection.js @@ -103,7 +103,7 @@ define(["notebook/js/widgets/base"], function(widget_manager){ // Handle when a value is clicked. handle_click: function (e) { this.model.set('value', $(e.target).html(), this); - this.model.update_other_views(this); + this.touch(); }, }); @@ -190,7 +190,7 @@ define(["notebook/js/widgets/base"], function(widget_manager){ // Handle when a value is clicked. handle_click: function (e) { this.model.set('value', $(e.target).val(), this); - this.model.update_other_views(this); + this.touch(); }, }); @@ -272,7 +272,7 @@ define(["notebook/js/widgets/base"], function(widget_manager){ // Handle when a value is clicked. handle_click: function (e) { this.model.set('value', $(e.target).html(), this); - this.model.update_other_views(this); + this.touch(); }, }); @@ -351,7 +351,7 @@ define(["notebook/js/widgets/base"], function(widget_manager){ // Handle when a value is clicked. handle_click: function (e) { this.model.set('value', $(e.target).html(), this); - this.model.update_other_views(this); + this.touch(); }, }); diff --git a/IPython/html/static/notebook/js/widgets/string.js b/IPython/html/static/notebook/js/widgets/string.js index da759ac2f..fc97992eb 100644 --- a/IPython/html/static/notebook/js/widgets/string.js +++ b/IPython/html/static/notebook/js/widgets/string.js @@ -119,7 +119,7 @@ define(["notebook/js/widgets/base"], function(widget_manager){ handleChanging: function(e) { this.user_invoked_update = true; this.model.set('value', e.target.value); - this.model.update_other_views(this); + this.touch(); this.user_invoked_update = false; }, }); @@ -173,7 +173,7 @@ define(["notebook/js/widgets/base"], function(widget_manager){ // Handles and validates user input. handleChanging: function(e) { this.model.set('value', e.target.value); - this.model.update_other_views(this); + this.touch(); }, // Handles text submition