##// 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 33 this.$checkbox = $('<input />')
34 34 .attr('type', 'checkbox')
35 35 .click(function(el) {
36 that.user_invoked_update = true;
37 36
38 37 // Calling model.set will trigger all of the other views of the
39 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 40 that.touch();
42 that.user_invoked_update = false;
43 41 })
44 42 .appendTo(this.$el);
45 43
@@ -47,12 +45,12 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
47 45 this.update(); // Set defaults.
48 46 },
49 47
50 update : function(){
48 update : function(options){
51 49 // Update the contents of this view
52 50 //
53 51 // Called when the model is changed. The model may have been
54 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 54 this.$checkbox.prop('checked', this.model.get('value'));
57 55
58 56 var disabled = this.model.get('disabled');
@@ -89,12 +87,12 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
89 87 this.update(); // Set defaults.
90 88 },
91 89
92 update : function(){
90 update : function(options){
93 91 // Update the contents of this view
94 92 //
95 93 // Called when the model is changed. The model may have been
96 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 96 if (this.model.get('value')) {
99 97 this.$button.addClass('active');
100 98 } else {
@@ -118,13 +116,11 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
118 116
119 117 // Handles and validates user input.
120 118 handleClick: function(e) {
121 this.user_invoked_update = true;
122
119
123 120 // Calling model.set will trigger all of the other views of the
124 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 123 this.touch();
127 this.user_invoked_update = false;
128 124 },
129 125 });
130 126
@@ -44,66 +44,68 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
44 44 this.update();
45 45 },
46 46
47 update : function(){
47 update : function(options){
48 48 // Update the contents of this view
49 49 //
50 50 // Called when the model is changed. The model may have been
51 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 54 // Slider related keys.
54 var _keys = ['step', 'max', 'min', 'disabled'];
55 for (var index in _keys) {
56 var key = _keys[index];
57 if (this.model.get(key) !== undefined) {
58 this.$slider.slider("option", key, this.model.get(key));
55 var _keys = ['step', 'max', 'min', 'disabled'];
56 for (var index in _keys) {
57 var key = _keys[index];
58 if (this.model.get(key) !== undefined) {
59 this.$slider.slider("option", key, this.model.get(key));
60 }
59 61 }
60 }
61 62
62 // WORKAROUND FOR JQUERY SLIDER BUG.
63 // The horizontal position of the slider handle
64 // depends on the value of the slider at the time
65 // of orientation change. Before applying the new
66 // workaround, we set the value to the minimum to
67 // make sure that the horizontal placement of the
68 // handle in the vertical slider is always
69 // consistent.
70 var orientation = this.model.get('orientation');
71 var value = this.model.get('min');
72 this.$slider.slider('option', 'value', value);
73 this.$slider.slider('option', 'orientation', orientation);
74 value = this.model.get('value');
75 this.$slider.slider('option', 'value', value);
63 // WORKAROUND FOR JQUERY SLIDER BUG.
64 // The horizontal position of the slider handle
65 // depends on the value of the slider at the time
66 // of orientation change. Before applying the new
67 // workaround, we set the value to the minimum to
68 // make sure that the horizontal placement of the
69 // handle in the vertical slider is always
70 // consistent.
71 var orientation = this.model.get('orientation');
72 var value = this.model.get('min');
73 this.$slider.slider('option', 'value', value);
74 this.$slider.slider('option', 'orientation', orientation);
75 value = this.model.get('value');
76 this.$slider.slider('option', 'value', value);
76 77
77 // Use the right CSS classes for vertical & horizontal sliders
78 if (orientation=='vertical') {
79 this.$slider_container
80 .removeClass('widget-hslider')
81 .addClass('widget-vslider');
82 this.$el
83 .removeClass('widget-hbox-single')
84 .addClass('widget-vbox-single');
85 this.$label
86 .removeClass('widget-hlabel')
87 .addClass('widget-vlabel');
78 // Use the right CSS classes for vertical & horizontal sliders
79 if (orientation=='vertical') {
80 this.$slider_container
81 .removeClass('widget-hslider')
82 .addClass('widget-vslider');
83 this.$el
84 .removeClass('widget-hbox-single')
85 .addClass('widget-vbox-single');
86 this.$label
87 .removeClass('widget-hlabel')
88 .addClass('widget-vlabel');
88 89
89 } else {
90 this.$slider_container
91 .removeClass('widget-vslider')
92 .addClass('widget-hslider');
93 this.$el
94 .removeClass('widget-vbox-single')
95 .addClass('widget-hbox-single');
96 this.$label
97 .removeClass('widget-vlabel')
98 .addClass('widget-hlabel');
99 }
90 } else {
91 this.$slider_container
92 .removeClass('widget-vslider')
93 .addClass('widget-hslider');
94 this.$el
95 .removeClass('widget-vbox-single')
96 .addClass('widget-hbox-single');
97 this.$label
98 .removeClass('widget-vlabel')
99 .addClass('widget-hlabel');
100 }
100 101
101 var description = this.model.get('description');
102 if (description.length === 0) {
103 this.$label.hide();
104 } else {
105 this.$label.html(description);
106 this.$label.show();
102 var description = this.model.get('description');
103 if (description.length === 0) {
104 this.$label.hide();
105 } else {
106 this.$label.html(description);
107 this.$label.show();
108 }
107 109 }
108 110 return IPython.DOMWidgetView.prototype.update.call(this);
109 111 },
@@ -114,7 +116,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
114 116
115 117 // Calling model.set will trigger all of the other views of the
116 118 // model to update.
117 this.model.set('value', ui.value);
119 this.model.set('value', ui.value, {updated_view: this});
118 120 this.touch();
119 121 },
120 122 });
@@ -141,29 +143,31 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
141 143 this.update(); // Set defaults.
142 144 },
143 145
144 update : function(){
146 update : function(options){
145 147 // Update the contents of this view
146 148 //
147 149 // Called when the model is changed. The model may have been
148 150 // changed by another view or by a state update from the back-end.
149 151
150 var value = this.model.get('value');
151 if (!this.changing && parseFloat(this.$textbox.val()) != value) {
152 this.$textbox.val(value);
153 }
154
155 if (this.model.get('disabled')) {
156 this.$textbox.attr('disabled','disabled');
157 } else {
158 this.$textbox.removeAttr('disabled');
159 }
152 if (options === undefined || options.updated_view != this) {
153 var value = this.model.get('value');
154 if (parseFloat(this.$textbox.val()) != value) {
155 this.$textbox.val(value);
156 }
157
158 if (this.model.get('disabled')) {
159 this.$textbox.attr('disabled','disabled');
160 } else {
161 this.$textbox.removeAttr('disabled');
162 }
160 163
161 var description = this.model.get('description');
162 if (description.length === 0) {
163 this.$label.hide();
164 } else {
165 this.$label.html(description);
166 this.$label.show();
164 var description = this.model.get('description');
165 if (description.length === 0) {
166 this.$label.hide();
167 } else {
168 this.$label.html(description);
169 this.$label.show();
170 }
167 171 }
168 172 return IPython.DOMWidgetView.prototype.update.call(this);
169 173 },
@@ -196,13 +200,11 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
196 200
197 201 // Apply the value if it has changed.
198 202 if (numericalValue != this.model.get('value')) {
199 this.changing = true;
200 203
201 204 // Calling model.set will trigger all of the other views of the
202 205 // model to update.
203 this.model.set('value', numericalValue);
206 this.model.set('value', numericalValue, {updated_view: this});
204 207 this.touch();
205 this.changing = false;
206 208 }
207 209 }
208 210 },
@@ -44,66 +44,67 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
44 44 this.update();
45 45 },
46 46
47 update : function(){
47 update : function(options){
48 48 // Update the contents of this view
49 49 //
50 50 // Called when the model is changed. The model may have been
51 51 // changed by another view or by a state update from the back-end.
52
53 // Slider related keys.
54 var _keys = ['step', 'max', 'min', 'disabled'];
55 for (var index in _keys) {
56 var key = _keys[index];
57 if (this.model.get(key) !== undefined) {
58 this.$slider.slider("option", key, this.model.get(key));
52 if (options === undefined || options.updated_view != this) {
53 // Slider related keys.
54 var _keys = ['step', 'max', 'min', 'disabled'];
55 for (var index in _keys) {
56 var key = _keys[index];
57 if (this.model.get(key) !== undefined) {
58 this.$slider.slider("option", key, this.model.get(key));
59 }
59 60 }
60 }
61 61
62 // WORKAROUND FOR JQUERY SLIDER BUG.
63 // The horizontal position of the slider handle
64 // depends on the value of the slider at the time
65 // of orientation change. Before applying the new
66 // workaround, we set the value to the minimum to
67 // make sure that the horizontal placement of the
68 // handle in the vertical slider is always
69 // consistent.
70 var orientation = this.model.get('orientation');
71 var value = this.model.get('min');
72 this.$slider.slider('option', 'value', value);
73 this.$slider.slider('option', 'orientation', orientation);
74 value = this.model.get('value');
75 this.$slider.slider('option', 'value', value);
62 // WORKAROUND FOR JQUERY SLIDER BUG.
63 // The horizontal position of the slider handle
64 // depends on the value of the slider at the time
65 // of orientation change. Before applying the new
66 // workaround, we set the value to the minimum to
67 // make sure that the horizontal placement of the
68 // handle in the vertical slider is always
69 // consistent.
70 var orientation = this.model.get('orientation');
71 var value = this.model.get('min');
72 this.$slider.slider('option', 'value', value);
73 this.$slider.slider('option', 'orientation', orientation);
74 value = this.model.get('value');
75 this.$slider.slider('option', 'value', value);
76 76
77 // Use the right CSS classes for vertical & horizontal sliders
78 if (orientation=='vertical') {
79 this.$slider_container
80 .removeClass('widget-hslider')
81 .addClass('widget-vslider');
82 this.$el
83 .removeClass('widget-hbox-single')
84 .addClass('widget-vbox-single');
85 this.$label
86 .removeClass('widget-hlabel')
87 .addClass('widget-vlabel');
77 // Use the right CSS classes for vertical & horizontal sliders
78 if (orientation=='vertical') {
79 this.$slider_container
80 .removeClass('widget-hslider')
81 .addClass('widget-vslider');
82 this.$el
83 .removeClass('widget-hbox-single')
84 .addClass('widget-vbox-single');
85 this.$label
86 .removeClass('widget-hlabel')
87 .addClass('widget-vlabel');
88 88
89 } else {
90 this.$slider_container
91 .removeClass('widget-vslider')
92 .addClass('widget-hslider');
93 this.$el
94 .removeClass('widget-vbox-single')
95 .addClass('widget-hbox-single');
96 this.$label
97 .removeClass('widget-vlabel')
98 .addClass('widget-hlabel');
99 }
89 } else {
90 this.$slider_container
91 .removeClass('widget-vslider')
92 .addClass('widget-hslider');
93 this.$el
94 .removeClass('widget-vbox-single')
95 .addClass('widget-hbox-single');
96 this.$label
97 .removeClass('widget-vlabel')
98 .addClass('widget-hlabel');
99 }
100 100
101 var description = this.model.get('description');
102 if (description.length === 0) {
103 this.$label.hide();
104 } else {
105 this.$label.html(description);
106 this.$label.show();
101 var description = this.model.get('description');
102 if (description.length === 0) {
103 this.$label.hide();
104 } else {
105 this.$label.html(description);
106 this.$label.show();
107 }
107 108 }
108 109 return IPython.DOMWidgetView.prototype.update.call(this);
109 110 },
@@ -114,7 +115,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
114 115
115 116 // Calling model.set will trigger all of the other views of the
116 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 119 this.touch();
119 120 },
120 121 });
@@ -140,29 +141,30 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
140 141 this.update(); // Set defaults.
141 142 },
142 143
143 update : function(){
144 update : function(options){
144 145 // Update the contents of this view
145 146 //
146 147 // Called when the model is changed. The model may have been
147 148 // changed by another view or by a state update from the back-end.
149 if (options === undefined || options.updated_view != this) {
150 var value = this.model.get('value');
151 if (parseInt(this.$textbox.val()) != value) {
152 this.$textbox.val(value);
153 }
154
155 if (this.model.get('disabled')) {
156 this.$textbox.attr('disabled','disabled');
157 } else {
158 this.$textbox.removeAttr('disabled');
159 }
148 160
149 var value = this.model.get('value');
150 if (!this.changing && parseInt(this.$textbox.val()) != value) {
151 this.$textbox.val(value);
152 }
153
154 if (this.model.get('disabled')) {
155 this.$textbox.attr('disabled','disabled');
156 } else {
157 this.$textbox.removeAttr('disabled');
158 }
159
160 var description = this.model.get('description');
161 if (description.length === 0) {
162 this.$label.hide();
163 } else {
164 this.$label.html(description);
165 this.$label.show();
161 var description = this.model.get('description');
162 if (description.length === 0) {
163 this.$label.hide();
164 } else {
165 this.$label.html(description);
166 this.$label.show();
167 }
166 168 }
167 169 return IPython.DOMWidgetView.prototype.update.call(this);
168 170 },
@@ -195,13 +197,11 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
195 197
196 198 // Apply the value if it has changed.
197 199 if (numericalValue != this.model.get('value')) {
198 this.changing = true;
199 200
200 201 // Calling model.set will trigger all of the other views of the
201 202 // model to update.
202 this.model.set('value', numericalValue);
203 this.model.set('value', numericalValue, {updated_view: this});
203 204 this.touch();
204 this.changing = false;
205 205 }
206 206 }
207 207 },
@@ -44,38 +44,39 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
44 44 },
45 45
46 46
47 update: function() {
47 update: function(options) {
48 48 // Update the contents of this view
49 49 //
50 50 // Called when the model is changed. The model may have been
51 51 // changed by another view or by a state update from the back-end.
52
53 // Set tab titles
54 var titles = this.model.get('_titles');
55 for (var page_index in titles) {
56
57 var accordian = this.containers[page_index];
58 if (accordian !== undefined) {
59 accordian
60 .find('.accordion-heading')
61 .find('.accordion-toggle')
62 .html(titles[page_index]);
52
53 if (options === undefined || options.updated_view != this) {
54 // Set tab titles
55 var titles = this.model.get('_titles');
56 for (var page_index in titles) {
57
58 var accordian = this.containers[page_index];
59 if (accordian !== undefined) {
60 accordian
61 .find('.accordion-heading')
62 .find('.accordion-toggle')
63 .html(titles[page_index]);
64 }
63 65 }
64 }
65 66
66 // Set selected page
67 var selected_index = this.model.get("selected_index");
68 if (0 <= selected_index && selected_index < this.containers.length) {
69 for (var index in this.containers) {
70 if (index==selected_index) {
71 this.containers[index].find('.accordion-body').collapse('show');
72 } else {
73 this.containers[index].find('.accordion-body').collapse('hide');
67 // Set selected page
68 var selected_index = this.model.get("selected_index");
69 if (0 <= selected_index && selected_index < this.containers.length) {
70 for (var index in this.containers) {
71 if (index==selected_index) {
72 this.containers[index].find('.accordion-body').collapse('show');
73 } else {
74 this.containers[index].find('.accordion-body').collapse('hide');
75 }
76
74 77 }
75
76 78 }
77 79 }
78
79 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 101 // Calling model.set will trigger all of the other views of the
101 102 // model to update.
102 that.model.set("selected_index", index);
103 that.model.set("selected_index", index, {updated_view: this});
103 104 that.touch();
104 105 })
105 106 .html('Page ' + index)
@@ -160,26 +161,26 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
160 161 }, this)
161 162 },
162 163
163 update: function() {
164 update: function(options) {
164 165 // Update the contents of this view
165 166 //
166 167 // Called when the model is changed. The model may have been
167 168 // changed by another view or by a state update from the back-end.
168
169 // Set tab titles
170 var titles = this.model.get('_titles');
171 for (var page_index in titles) {
172 var tab_text = this.containers[page_index];
173 if (tab_text !== undefined) {
174 tab_text.html(titles[page_index]);
169 if (options === undefined || options.updated_view != this) {
170 // Set tab titles
171 var titles = this.model.get('_titles');
172 for (var page_index in titles) {
173 var tab_text = this.containers[page_index];
174 if (tab_text !== undefined) {
175 tab_text.html(titles[page_index]);
176 }
175 177 }
176 }
177 178
178 var selected_index = this.model.get('selected_index');
179 if (0 <= selected_index && selected_index < this.containers.length) {
180 this.select_page(selected_index);
179 var selected_index = this.model.get('selected_index');
180 if (0 <= selected_index && selected_index < this.containers.length) {
181 this.select_page(selected_index);
182 }
181 183 }
182
183 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 202 // Calling model.set will trigger all of the other views of the
202 203 // model to update.
203 that.model.set("selected_index", index);
204 that.model.set("selected_index", index, {updated_view: this});
204 205 that.touch();
205 206 that.select_page(index);
206 207 });
@@ -55,49 +55,51 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
55 55 this.update();
56 56 },
57 57
58 update : function(){
58 update : function(options){
59 59 // Update the contents of this view
60 60 //
61 61 // Called when the model is changed. The model may have been
62 62 // changed by another view or by a state update from the back-end.
63 63
64 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(/\n/g, '<br>\n');
67 if (selected_item_text.length === 0) {
68 this.$droplabel.html('&nbsp;');
69 } else {
70 this.$droplabel.html(selected_item_text);
71 }
72
73 var items = this.model.get('values');
74 this.$droplist.html('');
75 for (var index in items) {
76 var that = this;
77 var item_button = $('<a href="#"/>')
78 .html(items[index])
79 .on('click', $.proxy(this.handle_click, this));
80 this.$droplist.append($('<li />').append(item_button));
81 }
82
83 if (this.model.get('disabled')) {
84 this.$buttongroup.attr('disabled','disabled');
85 this.$droplabel.attr('disabled','disabled');
86 this.$dropbutton.attr('disabled','disabled');
87 this.$droplist.attr('disabled','disabled');
88 } else {
89 this.$buttongroup.removeAttr('disabled');
90 this.$droplabel.removeAttr('disabled');
91 this.$dropbutton.removeAttr('disabled');
92 this.$droplist.removeAttr('disabled');
93 }
64 if (options === undefined || options.updated_view != this) {
65 var selected_item_text = this.model.get('value');
66 selected_item_text = selected_item_text.replace(/ /g, '&nbsp;');
67 selected_item_text = selected_item_text.replace(/\n/g, '<br>\n');
68 if (selected_item_text.length === 0) {
69 this.$droplabel.html('&nbsp;');
70 } else {
71 this.$droplabel.html(selected_item_text);
72 }
73
74 var items = this.model.get('values');
75 this.$droplist.html('');
76 for (var index in items) {
77 var that = this;
78 var item_button = $('<a href="#"/>')
79 .html(items[index])
80 .on('click', $.proxy(this.handle_click, this));
81 this.$droplist.append($('<li />').append(item_button));
82 }
83
84 if (this.model.get('disabled')) {
85 this.$buttongroup.attr('disabled','disabled');
86 this.$droplabel.attr('disabled','disabled');
87 this.$dropbutton.attr('disabled','disabled');
88 this.$droplist.attr('disabled','disabled');
89 } else {
90 this.$buttongroup.removeAttr('disabled');
91 this.$droplabel.removeAttr('disabled');
92 this.$dropbutton.removeAttr('disabled');
93 this.$droplist.removeAttr('disabled');
94 }
94 95
95 var description = this.model.get('description');
96 if (description.length === 0) {
97 this.$label.hide();
98 } else {
99 this.$label.html(description);
100 this.$label.show();
96 var description = this.model.get('description');
97 if (description.length === 0) {
98 this.$label.hide();
99 } else {
100 this.$label.html(description);
101 this.$label.show();
102 }
101 103 }
102 104 return IPython.DOMWidgetView.prototype.update.call(this);
103 105 },
@@ -107,7 +109,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
107 109
108 110 // Calling model.set will trigger all of the other views of the
109 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 113 this.touch();
112 114 },
113 115
@@ -134,62 +136,63 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
134 136 this.update();
135 137 },
136 138
137 update : function(){
139 update : function(options){
138 140 // Update the contents of this view
139 141 //
140 142 // Called when the model is changed. The model may have been
141 143 // changed by another view or by a state update from the back-end.
142
143 // Add missing items to the DOM.
144 var items = this.model.get('values');
145 var disabled = this.model.get('disabled');
146 for (var index in items) {
147 var item_query = ' :input[value="' + items[index] + '"]';
148 if (this.$el.find(item_query).length === 0) {
149 var $label = $('<label />')
150 .addClass('radio')
151 .html(items[index])
152 .appendTo(this.$container);
153
154 $('<input />')
155 .attr('type', 'radio')
156 .addClass(this.model)
157 .val(items[index])
158 .prependTo($label)
159 .on('click', $.proxy(this.handle_click, this));
160 }
161
162 var $item_element = this.$container.find(item_query);
163 if (this.model.get('value') == items[index]) {
164 $item_element.prop('checked', true);
165 } else {
166 $item_element.prop('checked', false);
167 }
168 $item_element.prop('disabled', disabled);
169 }
170
171 // Remove items that no longer exist.
172 this.$container.find('input').each(function(i, obj) {
173 var value = $(obj).val();
174 var found = false;
144 if (options === undefined || options.updated_view != this) {
145 // Add missing items to the DOM.
146 var items = this.model.get('values');
147 var disabled = this.model.get('disabled');
175 148 for (var index in items) {
176 if (items[index] == value) {
177 found = true;
178 break;
149 var item_query = ' :input[value="' + items[index] + '"]';
150 if (this.$el.find(item_query).length === 0) {
151 var $label = $('<label />')
152 .addClass('radio')
153 .html(items[index])
154 .appendTo(this.$container);
155
156 $('<input />')
157 .attr('type', 'radio')
158 .addClass(this.model)
159 .val(items[index])
160 .prependTo($label)
161 .on('click', $.proxy(this.handle_click, this));
162 }
163
164 var $item_element = this.$container.find(item_query);
165 if (this.model.get('value') == items[index]) {
166 $item_element.prop('checked', true);
167 } else {
168 $item_element.prop('checked', false);
179 169 }
170 $item_element.prop('disabled', disabled);
180 171 }
181 172
182 if (!found) {
183 $(obj).parent().remove();
184 }
185 });
173 // Remove items that no longer exist.
174 this.$container.find('input').each(function(i, obj) {
175 var value = $(obj).val();
176 var found = false;
177 for (var index in items) {
178 if (items[index] == value) {
179 found = true;
180 break;
181 }
182 }
183
184 if (!found) {
185 $(obj).parent().remove();
186 }
187 });
186 188
187 var description = this.model.get('description');
188 if (description.length === 0) {
189 this.$label.hide();
190 } else {
191 this.$label.html(description);
192 this.$label.show();
189 var description = this.model.get('description');
190 if (description.length === 0) {
191 this.$label.hide();
192 } else {
193 this.$label.html(description);
194 this.$label.show();
195 }
193 196 }
194 197 return IPython.DOMWidgetView.prototype.update.call(this);
195 198 },
@@ -199,7 +202,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
199 202
200 203 // Calling model.set will trigger all of the other views of the
201 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 206 this.touch();
204 207 },
205 208 });
@@ -226,57 +229,58 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
226 229 this.update();
227 230 },
228 231
229 update : function(){
232 update : function(options){
230 233 // Update the contents of this view
231 234 //
232 235 // Called when the model is changed. The model may have been
233 236 // changed by another view or by a state update from the back-end.
234
235 // Add missing items to the DOM.
236 var items = this.model.get('values');
237 var disabled = this.model.get('disabled');
238 for (var index in items) {
239 var item_query = ' :contains("' + items[index] + '")';
240 if (this.$buttongroup.find(item_query).length === 0) {
241 $('<button />')
242 .attr('type', 'button')
243 .addClass('btn')
244 .html(items[index])
245 .appendTo(this.$buttongroup)
246 .on('click', $.proxy(this.handle_click, this));
247 }
248
249 var $item_element = this.$buttongroup.find(item_query);
250 if (this.model.get('value') == items[index]) {
251 $item_element.addClass('active');
252 } else {
253 $item_element.removeClass('active');
254 }
255 $item_element.prop('disabled', disabled);
256 }
257
258 // Remove items that no longer exist.
259 this.$buttongroup.find('button').each(function(i, obj) {
260 var value = $(obj).html();
261 var found = false;
237 if (options === undefined || options.updated_view != this) {
238 // Add missing items to the DOM.
239 var items = this.model.get('values');
240 var disabled = this.model.get('disabled');
262 241 for (var index in items) {
263 if (items[index] == value) {
264 found = true;
265 break;
242 var item_query = ' :contains("' + items[index] + '")';
243 if (this.$buttongroup.find(item_query).length === 0) {
244 $('<button />')
245 .attr('type', 'button')
246 .addClass('btn')
247 .html(items[index])
248 .appendTo(this.$buttongroup)
249 .on('click', $.proxy(this.handle_click, this));
250 }
251
252 var $item_element = this.$buttongroup.find(item_query);
253 if (this.model.get('value') == items[index]) {
254 $item_element.addClass('active');
255 } else {
256 $item_element.removeClass('active');
266 257 }
258 $item_element.prop('disabled', disabled);
267 259 }
268 260
269 if (!found) {
270 $(obj).remove();
271 }
272 });
261 // Remove items that no longer exist.
262 this.$buttongroup.find('button').each(function(i, obj) {
263 var value = $(obj).html();
264 var found = false;
265 for (var index in items) {
266 if (items[index] == value) {
267 found = true;
268 break;
269 }
270 }
271
272 if (!found) {
273 $(obj).remove();
274 }
275 });
273 276
274 var description = this.model.get('description');
275 if (description.length === 0) {
276 this.$label.hide();
277 } else {
278 this.$label.html(description);
279 this.$label.show();
277 var description = this.model.get('description');
278 if (description.length === 0) {
279 this.$label.hide();
280 } else {
281 this.$label.html(description);
282 this.$label.show();
283 }
280 284 }
281 285 return IPython.DOMWidgetView.prototype.update.call(this);
282 286 },
@@ -286,7 +290,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
286 290
287 291 // Calling model.set will trigger all of the other views of the
288 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 294 this.touch();
291 295 },
292 296
@@ -313,54 +317,55 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
313 317 this.update();
314 318 },
315 319
316 update : function(){
320 update : function(options){
317 321 // Update the contents of this view
318 322 //
319 323 // Called when the model is changed. The model may have been
320 324 // changed by another view or by a state update from the back-end.
321
322 // Add missing items to the DOM.
323 var items = this.model.get('values');
324 for (var index in items) {
325 var item_query = ' :contains("' + items[index] + '")';
326 if (this.$listbox.find(item_query).length === 0) {
327 $('<option />')
328 .html(items[index])
329 .attr('value', items[index])
330 .appendTo(this.$listbox)
331 .on('click', $.proxy(this.handle_click, this));
332 }
333 }
334
335 // Select the correct element
336 this.$listbox.val(this.model.get('value'));
337
338 // Disable listbox if needed
339 var disabled = this.model.get('disabled');
340 this.$listbox.prop('disabled', disabled);
341
342 // Remove items that no longer exist.
343 this.$listbox.find('option').each(function(i, obj) {
344 var value = $(obj).html();
345 var found = false;
325 if (options === undefined || options.updated_view != this) {
326 // Add missing items to the DOM.
327 var items = this.model.get('values');
346 328 for (var index in items) {
347 if (items[index] == value) {
348 found = true;
349 break;
329 var item_query = ' :contains("' + items[index] + '")';
330 if (this.$listbox.find(item_query).length === 0) {
331 $('<option />')
332 .html(items[index])
333 .attr('value', items[index])
334 .appendTo(this.$listbox)
335 .on('click', $.proxy(this.handle_click, this));
350 336 }
351 337 }
338
339 // Select the correct element
340 this.$listbox.val(this.model.get('value'));
352 341
353 if (!found) {
354 $(obj).remove();
355 }
356 });
342 // Disable listbox if needed
343 var disabled = this.model.get('disabled');
344 this.$listbox.prop('disabled', disabled);
345
346 // Remove items that no longer exist.
347 this.$listbox.find('option').each(function(i, obj) {
348 var value = $(obj).html();
349 var found = false;
350 for (var index in items) {
351 if (items[index] == value) {
352 found = true;
353 break;
354 }
355 }
356
357 if (!found) {
358 $(obj).remove();
359 }
360 });
357 361
358 var description = this.model.get('description');
359 if (description.length === 0) {
360 this.$label.hide();
361 } else {
362 this.$label.html(description);
363 this.$label.show();
362 var description = this.model.get('description');
363 if (description.length === 0) {
364 this.$label.hide();
365 } else {
366 this.$label.html(description);
367 this.$label.show();
368 }
364 369 }
365 370 return IPython.DOMWidgetView.prototype.update.call(this);
366 371 },
@@ -370,7 +375,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
370 375
371 376 // Calling model.set will trigger all of the other views of the
372 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 379 this.touch();
375 380 },
376 381
@@ -95,24 +95,24 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
95 95 },
96 96
97 97
98 update: function(){
98 update: function(options){
99 99 // Update the contents of this view
100 100 //
101 101 // Called when the model is changed. The model may have been
102 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 104 this.$textbox.val(this.model.get('value'));
105 }
106 105
107 var disabled = this.model.get('disabled');
108 this.$textbox.prop('disabled', disabled);
106 var disabled = this.model.get('disabled');
107 this.$textbox.prop('disabled', disabled);
109 108
110 var description = this.model.get('description');
111 if (description.length === 0) {
112 this.$label.hide();
113 } else {
114 this.$label.html(description);
115 this.$label.show();
109 var description = this.model.get('description');
110 if (description.length === 0) {
111 this.$label.hide();
112 } else {
113 this.$label.html(description);
114 this.$label.show();
115 }
116 116 }
117 117 return IPython.DOMWidgetView.prototype.update.call(this);
118 118 },
@@ -123,13 +123,11 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
123 123
124 124 // Handles and validates user input.
125 125 handleChanging: function(e) {
126 this.user_invoked_update = true;
127 126
128 127 // Calling model.set will trigger all of the other views of the
129 128 // model to update.
130 this.model.set('value', e.target.value);
129 this.model.set('value', e.target.value, {updated_view: this});
131 130 this.touch();
132 this.user_invoked_update = false;
133 131 },
134 132 });
135 133
@@ -154,24 +152,26 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
154 152 this.update(); // Set defaults.
155 153 },
156 154
157 update: function(){
155 update: function(options){
158 156 // Update the contents of this view
159 157 //
160 158 // Called when the model is changed. The model may have been
161 159 // changed by another view or by a state update from the back-end.
162 if (this.$textbox.val() != this.model.get('value')) {
163 this.$textbox.val(this.model.get('value'));
164 }
165
166 var disabled = this.model.get('disabled');
167 this.$textbox.prop('disabled', disabled);
168
169 var description = this.model.get('description');
170 if (description.length === 0) {
171 this.$label.hide();
172 } else {
173 this.$label.html(description);
174 this.$label.show();
160 if (options === undefined || options.updated_view != this) {
161 if (this.$textbox.val() != this.model.get('value')) {
162 this.$textbox.val(this.model.get('value'));
163 }
164
165 var disabled = this.model.get('disabled');
166 this.$textbox.prop('disabled', disabled);
167
168 var description = this.model.get('description');
169 if (description.length === 0) {
170 this.$label.hide();
171 } else {
172 this.$label.html(description);
173 this.$label.show();
174 }
175 175 }
176 176 return IPython.DOMWidgetView.prototype.update.call(this);
177 177 },
@@ -186,7 +186,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
186 186
187 187 // Calling model.set will trigger all of the other views of the
188 188 // model to update.
189 this.model.set('value', e.target.value);
189 this.model.set('value', e.target.value, {updated_view: this});
190 190 this.touch();
191 191 },
192 192
General Comments 0
You need to be logged in to leave comments. Login now