##// END OF EJS Templates
add locks to update everywhere by using options to pass this...
Jonathan Frederic -
Show More
@@ -33,13 +33,11 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
33 this.$checkbox = $('<input />')
33 this.$checkbox = $('<input />')
34 .attr('type', 'checkbox')
34 .attr('type', 'checkbox')
35 .click(function(el) {
35 .click(function(el) {
36 that.user_invoked_update = true;
37
36
38 // Calling model.set will trigger all of the other views of the
37 // Calling model.set will trigger all of the other views of the
39 // model to update.
38 // model to update.
40 that.model.set('value', that.$checkbox.prop('checked'));
39 that.model.set('value', that.$checkbox.prop('checked'), {updated_view: this});
41 that.touch();
40 that.touch();
42 that.user_invoked_update = false;
43 })
41 })
44 .appendTo(this.$el);
42 .appendTo(this.$el);
45
43
@@ -47,12 +45,12 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
47 this.update(); // Set defaults.
45 this.update(); // Set defaults.
48 },
46 },
49
47
50 update : function(){
48 update : function(options){
51 // Update the contents of this view
49 // Update the contents of this view
52 //
50 //
53 // Called when the model is changed. The model may have been
51 // Called when the model is changed. The model may have been
54 // changed by another view or by a state update from the back-end.
52 // changed by another view or by a state update from the back-end.
55 if (!this.user_invoked_update) {
53 if (options === undefined || options.updated_view != this) {
56 this.$checkbox.prop('checked', this.model.get('value'));
54 this.$checkbox.prop('checked', this.model.get('value'));
57
55
58 var disabled = this.model.get('disabled');
56 var disabled = this.model.get('disabled');
@@ -89,12 +87,12 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
89 this.update(); // Set defaults.
87 this.update(); // Set defaults.
90 },
88 },
91
89
92 update : function(){
90 update : function(options){
93 // Update the contents of this view
91 // Update the contents of this view
94 //
92 //
95 // Called when the model is changed. The model may have been
93 // Called when the model is changed. The model may have been
96 // changed by another view or by a state update from the back-end.
94 // changed by another view or by a state update from the back-end.
97 if (!this.user_invoked_update) {
95 if (options === undefined || options.updated_view != this) {
98 if (this.model.get('value')) {
96 if (this.model.get('value')) {
99 this.$button.addClass('active');
97 this.$button.addClass('active');
100 } else {
98 } else {
@@ -118,13 +116,11 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
118
116
119 // Handles and validates user input.
117 // Handles and validates user input.
120 handleClick: function(e) {
118 handleClick: function(e) {
121 this.user_invoked_update = true;
122
119
123 // Calling model.set will trigger all of the other views of the
120 // Calling model.set will trigger all of the other views of the
124 // model to update.
121 // model to update.
125 this.model.set('value', ! $(e.target).hasClass('active'));
122 this.model.set('value', ! $(e.target).hasClass('active'), {updated_view: this});
126 this.touch();
123 this.touch();
127 this.user_invoked_update = false;
128 },
124 },
129 });
125 });
130
126
@@ -44,12 +44,13 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
44 this.update();
44 this.update();
45 },
45 },
46
46
47 update : function(){
47 update : function(options){
48 // Update the contents of this view
48 // Update the contents of this view
49 //
49 //
50 // Called when the model is changed. The model may have been
50 // Called when the model is changed. The model may have been
51 // changed by another view or by a state update from the back-end.
51 // changed by another view or by a state update from the back-end.
52
52
53 if (options === undefined || options.updated_view != this) {
53 // Slider related keys.
54 // Slider related keys.
54 var _keys = ['step', 'max', 'min', 'disabled'];
55 var _keys = ['step', 'max', 'min', 'disabled'];
55 for (var index in _keys) {
56 for (var index in _keys) {
@@ -105,6 +106,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
105 this.$label.html(description);
106 this.$label.html(description);
106 this.$label.show();
107 this.$label.show();
107 }
108 }
109 }
108 return IPython.DOMWidgetView.prototype.update.call(this);
110 return IPython.DOMWidgetView.prototype.update.call(this);
109 },
111 },
110
112
@@ -114,7 +116,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
114
116
115 // Calling model.set will trigger all of the other views of the
117 // Calling model.set will trigger all of the other views of the
116 // model to update.
118 // model to update.
117 this.model.set('value', ui.value);
119 this.model.set('value', ui.value, {updated_view: this});
118 this.touch();
120 this.touch();
119 },
121 },
120 });
122 });
@@ -141,14 +143,15 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
141 this.update(); // Set defaults.
143 this.update(); // Set defaults.
142 },
144 },
143
145
144 update : function(){
146 update : function(options){
145 // Update the contents of this view
147 // Update the contents of this view
146 //
148 //
147 // Called when the model is changed. The model may have been
149 // Called when the model is changed. The model may have been
148 // changed by another view or by a state update from the back-end.
150 // changed by another view or by a state update from the back-end.
149
151
152 if (options === undefined || options.updated_view != this) {
150 var value = this.model.get('value');
153 var value = this.model.get('value');
151 if (!this.changing && parseFloat(this.$textbox.val()) != value) {
154 if (parseFloat(this.$textbox.val()) != value) {
152 this.$textbox.val(value);
155 this.$textbox.val(value);
153 }
156 }
154
157
@@ -165,6 +168,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
165 this.$label.html(description);
168 this.$label.html(description);
166 this.$label.show();
169 this.$label.show();
167 }
170 }
171 }
168 return IPython.DOMWidgetView.prototype.update.call(this);
172 return IPython.DOMWidgetView.prototype.update.call(this);
169 },
173 },
170
174
@@ -196,13 +200,11 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
196
200
197 // Apply the value if it has changed.
201 // Apply the value if it has changed.
198 if (numericalValue != this.model.get('value')) {
202 if (numericalValue != this.model.get('value')) {
199 this.changing = true;
200
203
201 // Calling model.set will trigger all of the other views of the
204 // Calling model.set will trigger all of the other views of the
202 // model to update.
205 // model to update.
203 this.model.set('value', numericalValue);
206 this.model.set('value', numericalValue, {updated_view: this});
204 this.touch();
207 this.touch();
205 this.changing = false;
206 }
208 }
207 }
209 }
208 },
210 },
@@ -44,12 +44,12 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
44 this.update();
44 this.update();
45 },
45 },
46
46
47 update : function(){
47 update : function(options){
48 // Update the contents of this view
48 // Update the contents of this view
49 //
49 //
50 // Called when the model is changed. The model may have been
50 // Called when the model is changed. The model may have been
51 // changed by another view or by a state update from the back-end.
51 // changed by another view or by a state update from the back-end.
52
52 if (options === undefined || options.updated_view != this) {
53 // Slider related keys.
53 // Slider related keys.
54 var _keys = ['step', 'max', 'min', 'disabled'];
54 var _keys = ['step', 'max', 'min', 'disabled'];
55 for (var index in _keys) {
55 for (var index in _keys) {
@@ -105,6 +105,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
105 this.$label.html(description);
105 this.$label.html(description);
106 this.$label.show();
106 this.$label.show();
107 }
107 }
108 }
108 return IPython.DOMWidgetView.prototype.update.call(this);
109 return IPython.DOMWidgetView.prototype.update.call(this);
109 },
110 },
110
111
@@ -114,7 +115,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
114
115
115 // Calling model.set will trigger all of the other views of the
116 // Calling model.set will trigger all of the other views of the
116 // model to update.
117 // model to update.
117 this.model.set('value', ~~ui.value); // Double bit-wise not to truncate decimel
118 this.model.set('value', ~~ui.value, {updated_view: this}); // Double bit-wise not to truncate decimel
118 this.touch();
119 this.touch();
119 },
120 },
120 });
121 });
@@ -140,14 +141,14 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
140 this.update(); // Set defaults.
141 this.update(); // Set defaults.
141 },
142 },
142
143
143 update : function(){
144 update : function(options){
144 // Update the contents of this view
145 // Update the contents of this view
145 //
146 //
146 // Called when the model is changed. The model may have been
147 // Called when the model is changed. The model may have been
147 // changed by another view or by a state update from the back-end.
148 // changed by another view or by a state update from the back-end.
148
149 if (options === undefined || options.updated_view != this) {
149 var value = this.model.get('value');
150 var value = this.model.get('value');
150 if (!this.changing && parseInt(this.$textbox.val()) != value) {
151 if (parseInt(this.$textbox.val()) != value) {
151 this.$textbox.val(value);
152 this.$textbox.val(value);
152 }
153 }
153
154
@@ -164,6 +165,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
164 this.$label.html(description);
165 this.$label.html(description);
165 this.$label.show();
166 this.$label.show();
166 }
167 }
168 }
167 return IPython.DOMWidgetView.prototype.update.call(this);
169 return IPython.DOMWidgetView.prototype.update.call(this);
168 },
170 },
169
171
@@ -195,13 +197,11 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
195
197
196 // Apply the value if it has changed.
198 // Apply the value if it has changed.
197 if (numericalValue != this.model.get('value')) {
199 if (numericalValue != this.model.get('value')) {
198 this.changing = true;
199
200
200 // Calling model.set will trigger all of the other views of the
201 // Calling model.set will trigger all of the other views of the
201 // model to update.
202 // model to update.
202 this.model.set('value', numericalValue);
203 this.model.set('value', numericalValue, {updated_view: this});
203 this.touch();
204 this.touch();
204 this.changing = false;
205 }
205 }
206 }
206 }
207 },
207 },
@@ -44,12 +44,13 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
44 },
44 },
45
45
46
46
47 update: function() {
47 update: function(options) {
48 // Update the contents of this view
48 // Update the contents of this view
49 //
49 //
50 // Called when the model is changed. The model may have been
50 // Called when the model is changed. The model may have been
51 // changed by another view or by a state update from the back-end.
51 // changed by another view or by a state update from the back-end.
52
52
53 if (options === undefined || options.updated_view != this) {
53 // Set tab titles
54 // Set tab titles
54 var titles = this.model.get('_titles');
55 var titles = this.model.get('_titles');
55 for (var page_index in titles) {
56 for (var page_index in titles) {
@@ -75,7 +76,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
75
76
76 }
77 }
77 }
78 }
78
79 }
79 return IPython.DOMWidgetView.prototype.update.call(this);
80 return IPython.DOMWidgetView.prototype.update.call(this);
80 },
81 },
81
82
@@ -99,7 +100,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
99
100
100 // Calling model.set will trigger all of the other views of the
101 // Calling model.set will trigger all of the other views of the
101 // model to update.
102 // model to update.
102 that.model.set("selected_index", index);
103 that.model.set("selected_index", index, {updated_view: this});
103 that.touch();
104 that.touch();
104 })
105 })
105 .html('Page ' + index)
106 .html('Page ' + index)
@@ -160,12 +161,12 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
160 }, this)
161 }, this)
161 },
162 },
162
163
163 update: function() {
164 update: function(options) {
164 // Update the contents of this view
165 // Update the contents of this view
165 //
166 //
166 // Called when the model is changed. The model may have been
167 // Called when the model is changed. The model may have been
167 // changed by another view or by a state update from the back-end.
168 // changed by another view or by a state update from the back-end.
168
169 if (options === undefined || options.updated_view != this) {
169 // Set tab titles
170 // Set tab titles
170 var titles = this.model.get('_titles');
171 var titles = this.model.get('_titles');
171 for (var page_index in titles) {
172 for (var page_index in titles) {
@@ -179,7 +180,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
179 if (0 <= selected_index && selected_index < this.containers.length) {
180 if (0 <= selected_index && selected_index < this.containers.length) {
180 this.select_page(selected_index);
181 this.select_page(selected_index);
181 }
182 }
182
183 }
183 return IPython.DOMWidgetView.prototype.update.call(this);
184 return IPython.DOMWidgetView.prototype.update.call(this);
184 },
185 },
185
186
@@ -200,7 +201,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
200
201
201 // Calling model.set will trigger all of the other views of the
202 // Calling model.set will trigger all of the other views of the
202 // model to update.
203 // model to update.
203 that.model.set("selected_index", index);
204 that.model.set("selected_index", index, {updated_view: this});
204 that.touch();
205 that.touch();
205 that.select_page(index);
206 that.select_page(index);
206 });
207 });
@@ -55,12 +55,13 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
55 this.update();
55 this.update();
56 },
56 },
57
57
58 update : function(){
58 update : function(options){
59 // Update the contents of this view
59 // Update the contents of this view
60 //
60 //
61 // Called when the model is changed. The model may have been
61 // Called when the model is changed. The model may have been
62 // changed by another view or by a state update from the back-end.
62 // changed by another view or by a state update from the back-end.
63
63
64 if (options === undefined || options.updated_view != this) {
64 var selected_item_text = this.model.get('value');
65 var selected_item_text = this.model.get('value');
65 selected_item_text = selected_item_text.replace(/ /g, '&nbsp;');
66 selected_item_text = selected_item_text.replace(/ /g, '&nbsp;');
66 selected_item_text = selected_item_text.replace(/\n/g, '<br>\n');
67 selected_item_text = selected_item_text.replace(/\n/g, '<br>\n');
@@ -99,6 +100,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
99 this.$label.html(description);
100 this.$label.html(description);
100 this.$label.show();
101 this.$label.show();
101 }
102 }
103 }
102 return IPython.DOMWidgetView.prototype.update.call(this);
104 return IPython.DOMWidgetView.prototype.update.call(this);
103 },
105 },
104
106
@@ -107,7 +109,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
107
109
108 // Calling model.set will trigger all of the other views of the
110 // Calling model.set will trigger all of the other views of the
109 // model to update.
111 // model to update.
110 this.model.set('value', $(e.target).html(), this);
112 this.model.set('value', $(e.target).html(), {updated_view: this});
111 this.touch();
113 this.touch();
112 },
114 },
113
115
@@ -134,12 +136,12 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
134 this.update();
136 this.update();
135 },
137 },
136
138
137 update : function(){
139 update : function(options){
138 // Update the contents of this view
140 // Update the contents of this view
139 //
141 //
140 // Called when the model is changed. The model may have been
142 // Called when the model is changed. The model may have been
141 // changed by another view or by a state update from the back-end.
143 // changed by another view or by a state update from the back-end.
142
144 if (options === undefined || options.updated_view != this) {
143 // Add missing items to the DOM.
145 // Add missing items to the DOM.
144 var items = this.model.get('values');
146 var items = this.model.get('values');
145 var disabled = this.model.get('disabled');
147 var disabled = this.model.get('disabled');
@@ -191,6 +193,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
191 this.$label.html(description);
193 this.$label.html(description);
192 this.$label.show();
194 this.$label.show();
193 }
195 }
196 }
194 return IPython.DOMWidgetView.prototype.update.call(this);
197 return IPython.DOMWidgetView.prototype.update.call(this);
195 },
198 },
196
199
@@ -199,7 +202,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
199
202
200 // Calling model.set will trigger all of the other views of the
203 // Calling model.set will trigger all of the other views of the
201 // model to update.
204 // model to update.
202 this.model.set('value', $(e.target).val(), this);
205 this.model.set('value', $(e.target).val(), {updated_view: this});
203 this.touch();
206 this.touch();
204 },
207 },
205 });
208 });
@@ -226,12 +229,12 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
226 this.update();
229 this.update();
227 },
230 },
228
231
229 update : function(){
232 update : function(options){
230 // Update the contents of this view
233 // Update the contents of this view
231 //
234 //
232 // Called when the model is changed. The model may have been
235 // Called when the model is changed. The model may have been
233 // changed by another view or by a state update from the back-end.
236 // changed by another view or by a state update from the back-end.
234
237 if (options === undefined || options.updated_view != this) {
235 // Add missing items to the DOM.
238 // Add missing items to the DOM.
236 var items = this.model.get('values');
239 var items = this.model.get('values');
237 var disabled = this.model.get('disabled');
240 var disabled = this.model.get('disabled');
@@ -278,6 +281,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
278 this.$label.html(description);
281 this.$label.html(description);
279 this.$label.show();
282 this.$label.show();
280 }
283 }
284 }
281 return IPython.DOMWidgetView.prototype.update.call(this);
285 return IPython.DOMWidgetView.prototype.update.call(this);
282 },
286 },
283
287
@@ -286,7 +290,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
286
290
287 // Calling model.set will trigger all of the other views of the
291 // Calling model.set will trigger all of the other views of the
288 // model to update.
292 // model to update.
289 this.model.set('value', $(e.target).html(), this);
293 this.model.set('value', $(e.target).html(), {updated_view: this});
290 this.touch();
294 this.touch();
291 },
295 },
292
296
@@ -313,12 +317,12 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
313 this.update();
317 this.update();
314 },
318 },
315
319
316 update : function(){
320 update : function(options){
317 // Update the contents of this view
321 // Update the contents of this view
318 //
322 //
319 // Called when the model is changed. The model may have been
323 // Called when the model is changed. The model may have been
320 // changed by another view or by a state update from the back-end.
324 // changed by another view or by a state update from the back-end.
321
325 if (options === undefined || options.updated_view != this) {
322 // Add missing items to the DOM.
326 // Add missing items to the DOM.
323 var items = this.model.get('values');
327 var items = this.model.get('values');
324 for (var index in items) {
328 for (var index in items) {
@@ -362,6 +366,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
362 this.$label.html(description);
366 this.$label.html(description);
363 this.$label.show();
367 this.$label.show();
364 }
368 }
369 }
365 return IPython.DOMWidgetView.prototype.update.call(this);
370 return IPython.DOMWidgetView.prototype.update.call(this);
366 },
371 },
367
372
@@ -370,7 +375,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
370
375
371 // Calling model.set will trigger all of the other views of the
376 // Calling model.set will trigger all of the other views of the
372 // model to update.
377 // model to update.
373 this.model.set('value', $(e.target).html(), this);
378 this.model.set('value', $(e.target).html(), {updated_view: this});
374 this.touch();
379 this.touch();
375 },
380 },
376
381
@@ -95,14 +95,13 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
95 },
95 },
96
96
97
97
98 update: function(){
98 update: function(options){
99 // Update the contents of this view
99 // Update the contents of this view
100 //
100 //
101 // Called when the model is changed. The model may have been
101 // Called when the model is changed. The model may have been
102 // changed by another view or by a state update from the back-end.
102 // changed by another view or by a state update from the back-end.
103 if (!this.user_invoked_update) {
103 if (options === undefined || options.updated_view != this) {
104 this.$textbox.val(this.model.get('value'));
104 this.$textbox.val(this.model.get('value'));
105 }
106
105
107 var disabled = this.model.get('disabled');
106 var disabled = this.model.get('disabled');
108 this.$textbox.prop('disabled', disabled);
107 this.$textbox.prop('disabled', disabled);
@@ -114,6 +113,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
114 this.$label.html(description);
113 this.$label.html(description);
115 this.$label.show();
114 this.$label.show();
116 }
115 }
116 }
117 return IPython.DOMWidgetView.prototype.update.call(this);
117 return IPython.DOMWidgetView.prototype.update.call(this);
118 },
118 },
119
119
@@ -123,13 +123,11 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
123
123
124 // Handles and validates user input.
124 // Handles and validates user input.
125 handleChanging: function(e) {
125 handleChanging: function(e) {
126 this.user_invoked_update = true;
127
126
128 // Calling model.set will trigger all of the other views of the
127 // Calling model.set will trigger all of the other views of the
129 // model to update.
128 // model to update.
130 this.model.set('value', e.target.value);
129 this.model.set('value', e.target.value, {updated_view: this});
131 this.touch();
130 this.touch();
132 this.user_invoked_update = false;
133 },
131 },
134 });
132 });
135
133
@@ -154,11 +152,12 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
154 this.update(); // Set defaults.
152 this.update(); // Set defaults.
155 },
153 },
156
154
157 update: function(){
155 update: function(options){
158 // Update the contents of this view
156 // Update the contents of this view
159 //
157 //
160 // Called when the model is changed. The model may have been
158 // Called when the model is changed. The model may have been
161 // changed by another view or by a state update from the back-end.
159 // changed by another view or by a state update from the back-end.
160 if (options === undefined || options.updated_view != this) {
162 if (this.$textbox.val() != this.model.get('value')) {
161 if (this.$textbox.val() != this.model.get('value')) {
163 this.$textbox.val(this.model.get('value'));
162 this.$textbox.val(this.model.get('value'));
164 }
163 }
@@ -173,6 +172,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
173 this.$label.html(description);
172 this.$label.html(description);
174 this.$label.show();
173 this.$label.show();
175 }
174 }
175 }
176 return IPython.DOMWidgetView.prototype.update.call(this);
176 return IPython.DOMWidgetView.prototype.update.call(this);
177 },
177 },
178
178
@@ -186,7 +186,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
186
186
187 // Calling model.set will trigger all of the other views of the
187 // Calling model.set will trigger all of the other views of the
188 // model to update.
188 // model to update.
189 this.model.set('value', e.target.value);
189 this.model.set('value', e.target.value, {updated_view: this});
190 this.touch();
190 this.touch();
191 },
191 },
192
192
General Comments 0
You need to be logged in to leave comments. Login now