Show More
@@ -113,7 +113,7 define(["notebook/js/widget"], function(widget_manager){ | |||||
113 | // Handles: Backend -> Frontend Sync |
|
113 | // Handles: Backend -> Frontend Sync | |
114 | // Frontent -> Frontend Sync |
|
114 | // Frontent -> Frontend Sync | |
115 | update : function(){ |
|
115 | update : function(){ | |
116 | if (!this.user_invoked_update) { |
|
116 | if (this.$textbox.val() != this.model.get('value')) { | |
117 | this.$textbox.val(this.model.get('value')); |
|
117 | this.$textbox.val(this.model.get('value')); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
@@ -137,19 +137,15 define(["notebook/js/widget"], function(widget_manager){ | |||||
137 |
|
137 | |||
138 | // Handles and validates user input. |
|
138 | // Handles and validates user input. | |
139 | handleChanging: function(e) { |
|
139 | handleChanging: function(e) { | |
140 | this.user_invoked_update = true; |
|
|||
141 | this.model.set('value', e.target.value); |
|
140 | this.model.set('value', e.target.value); | |
142 | this.model.update_other_views(this); |
|
141 | this.model.update_other_views(this); | |
143 | this.user_invoked_update = false; |
|
|||
144 | }, |
|
142 | }, | |
145 |
|
143 | |||
146 | // Handles text submition |
|
144 | // Handles text submition | |
147 | handleKeypress: function(e) { |
|
145 | handleKeypress: function(e) { | |
148 | if (e.keyCode == 13) { // Return key |
|
146 | if (e.keyCode == 13) { // Return key | |
149 | this.user_invoked_update = true; |
|
|||
150 | this.model.set('submits', this.model.get('submits') + 1); |
|
147 | this.model.set('submits', this.model.get('submits') + 1); | |
151 | this.model.update_other_views(this); |
|
148 | this.model.update_other_views(this); | |
152 | this.user_invoked_update = false; |
|
|||
153 | } |
|
149 | } | |
154 | }, |
|
150 | }, | |
155 | }); |
|
151 | }); |
@@ -58,7 +58,7 class Widget(LoggingConfigurable): | |||||
58 | old._children.remove(self) |
|
58 | old._children.remove(self) | |
59 |
|
59 | |||
60 | # Private/protected declarations |
|
60 | # Private/protected declarations | |
61 | _property_lock = False |
|
61 | _property_lock = (None, None) # Last updated (key, value) from the front-end. Prevents echo. | |
62 | _css = Dict() # Internal CSS property dict |
|
62 | _css = Dict() # Internal CSS property dict | |
63 | _add_class = List() # Used to add a js class to a DOM element (call#, selector, class_name) |
|
63 | _add_class = List() # Used to add a js class to a DOM element (call#, selector, class_name) | |
64 | _remove_class = List() # Used to remove a js class from a DOM element (call#, selector, class_name) |
|
64 | _remove_class = List() # Used to remove a js class from a DOM element (call#, selector, class_name) | |
@@ -153,20 +153,21 class Widget(LoggingConfigurable): | |||||
153 |
|
153 | |||
154 | def _handle_recieve_state(self, sync_data): |
|
154 | def _handle_recieve_state(self, sync_data): | |
155 | """Called when a state is recieved from the frontend.""" |
|
155 | """Called when a state is recieved from the frontend.""" | |
156 | self._property_lock = True |
|
156 | # Use _keys instead of keys - Don't get retrieve the css from the client side. | |
157 | try: |
|
157 | for name in self._keys: | |
158 |
|
158 | if name in sync_data: | ||
159 | # Use _keys instead of keys - Don't get retrieve the css from the client side. |
|
159 | try: | |
160 | for name in self._keys: |
|
160 | self._property_lock = (name, sync_data[name]) | |
161 | if name in sync_data: |
|
|||
162 | setattr(self, name, sync_data[name]) |
|
161 | setattr(self, name, sync_data[name]) | |
163 | finally: |
|
162 | finally: | |
164 |
self._property_lock = |
|
163 | self._property_lock = (None, None) | |
165 |
|
164 | |||
166 |
|
165 | |||
167 | def _handle_property_changed(self, name, old, new): |
|
166 | def _handle_property_changed(self, name, old, new): | |
168 | """Called when a proeprty has been changed.""" |
|
167 | """Called when a proeprty has been changed.""" | |
169 | if not self._property_lock and self._comm is not None: |
|
168 | # Make sure this isn't information that the front-end just sent us. | |
|
169 | if self._property_lock[0] != name and self._property_lock[1] != new \ | |||
|
170 | and self._comm is not None: | |||
170 | # TODO: Validate properties. |
|
171 | # TODO: Validate properties. | |
171 | # Send new state to frontend |
|
172 | # Send new state to frontend | |
172 | self.send_state(key=name) |
|
173 | self.send_state(key=name) |
General Comments 0
You need to be logged in to leave comments.
Login now