##// END OF EJS Templates
Fix view rendering order.
Jonathan Frederic -
Show More
@@ -66,7 +66,7 b' define(['
66 dummy.replaceWith(view.$el);
66 dummy.replaceWith(view.$el);
67 }
67 }
68 view.trigger('displayed');
68 view.trigger('displayed');
69 }, function(error) { console.error(error); });
69 }, console.error);
70 }
70 }
71 };
71 };
72
72
@@ -200,7 +200,7 b' define(['
200 // model_name: 'WidgetModel',
200 // model_name: 'WidgetModel',
201 // widget_class: 'IPython.html.widgets.widget_int.IntSlider'})
201 // widget_class: 'IPython.html.widgets.widget_int.IntSlider'})
202 // .then(function(model) { console.log('Create success!', model); },
202 // .then(function(model) { console.log('Create success!', model); },
203 // function(error) { console.error(error); });
203 // console.error);
204 //
204 //
205 // Parameters
205 // Parameters
206 // ----------
206 // ----------
@@ -322,25 +322,25 b' define(["widgets/js/manager",'
322 //
322 //
323 // -given a model and (optionally) a view name if the view name is
323 // -given a model and (optionally) a view name if the view name is
324 // not given, it defaults to the model's default view attribute.
324 // not given, it defaults to the model's default view attribute.
325
325 return new Promise(function(resolve, reject) {
326 // TODO: this is hacky, and makes the view depend on this cell attribute and widget manager behavior
326 // TODO: this is hacky, and makes the view depend on this cell attribute and widget manager behavior
327 // it would be great to have the widget manager add the cell metadata
327 // it would be great to have the widget manager add the cell metadata
328 // to the subview without having to add it here.
328 // to the subview without having to add it here.
329 var that = this;
329 var that = this;
330 var old_callback = options.callback || function(view) {};
330 options = $.extend({ parent: this }, options || {});
331 options = $.extend({ parent: this }, options || {});
331
332
332 this.model.widget_manager.create_view(child_model, options).then(function(child_view) {
333 this.model.widget_manager.create_view(child_model, options).then(function(child_view) {
333 // Associate the view id with the model id.
334 // Associate the view id with the model id.
334 if (that.child_model_views[child_model.id] === undefined) {
335 if (that.child_model_views[child_model.id] === undefined) {
335 that.child_model_views[child_model.id] = [];
336 that.child_model_views[child_model.id] = [];
336 }
337 }
337 that.child_model_views[child_model.id].push(child_view.id);
338 that.child_model_views[child_model.id].push(child_view.id);
339
338
340 // Remember the view by id.
339 // Remember the view by id.
341 that.child_views[child_view.id] = child_view;
340 that.child_views[child_view.id] = child_view;
342 old_callback(child_view);
341 resolve(child_view);
343 }, function(error) { console.error(error); });
342 }, reject);
343 });
344 },
344 },
345
345
346 pop_child_view: function(child_model) {
346 pop_child_view: function(child_model) {
@@ -75,14 +75,16 b' define(['
75 add_child_model: function(model) {
75 add_child_model: function(model) {
76 // Called when a model is added to the children list.
76 // Called when a model is added to the children list.
77 var that = this;
77 var that = this;
78 this.create_child_view(model, {callback: function(view) {
78 var dummy = $('<div/>');
79 that.$box.append(view.$el);
79 that.$box.append(dummy);
80 this.create_child_view(model).then(function(view) {
81 dummy.replaceWith(view.$el);
80
82
81 // Trigger the displayed event of the child view.
83 // Trigger the displayed event of the child view.
82 that.after_displayed(function() {
84 that.after_displayed(function() {
83 view.trigger('displayed');
85 view.trigger('displayed');
84 });
86 });
85 }});
87 }, console.error);
86 },
88 },
87 });
89 });
88
90
@@ -114,9 +114,10 b' define(['
114 accordion_group.container_index = container_index;
114 accordion_group.container_index = container_index;
115 this.model_containers[model.id] = accordion_group;
115 this.model_containers[model.id] = accordion_group;
116
116
117 this.create_child_view(model, {callback: function(view) {
117 var dummy = $('<div/>');
118 accordion_inner.append(view.$el);
118 accordion_inner.append(dummy);
119
119 this.create_child_view(model).then(function(view) {
120 dummy.replaceWith(view.$el);
120 that.update();
121 that.update();
121 that.update_titles();
122 that.update_titles();
122
123
@@ -124,7 +125,7 b' define(['
124 that.after_displayed(function() {
125 that.after_displayed(function() {
125 view.trigger('displayed');
126 view.trigger('displayed');
126 });
127 });
127 }});
128 }, console.error);
128 },
129 },
129 });
130 });
130
131
@@ -186,36 +187,39 b' define(['
186 .css('list-style-type', 'none')
187 .css('list-style-type', 'none')
187 .appendTo(this.$tabs);
188 .appendTo(this.$tabs);
188
189
189 this.create_child_view(model, {callback: function(view) {
190 view.parent_tab = tab;
191
190
192 var tab_text = $('<a />')
191 var tab_text = $('<a />')
193 .attr('href', '#' + uuid)
192 .attr('href', '#' + uuid)
194 .attr('data-toggle', 'tab')
193 .attr('data-toggle', 'tab')
195 .text('Page ' + index)
194 .text('Page ' + index)
196 .appendTo(tab)
195 .appendTo(tab)
197 .click(function (e) {
196 .click(function (e) {
198
197
199 // Calling model.set will trigger all of the other views of the
198 // Calling model.set will trigger all of the other views of the
200 // model to update.
199 // model to update.
201 that.model.set("selected_index", index, {updated_view: that});
200 that.model.set("selected_index", index, {updated_view: that});
202 that.touch();
201 that.touch();
203 that.select_page(index);
202 that.select_page(index);
204 });
203 });
205 tab.tab_text_index = that.containers.push(tab_text) - 1;
204 tab.tab_text_index = that.containers.push(tab_text) - 1;
205
206 var dummy = $('<div />');
207 var contents_div = $('<div />', {id: uuid})
208 .addClass('tab-pane')
209 .addClass('fade')
210 .append(dummy)
211 .appendTo(that.$tab_contents);
206
212
207 var contents_div = $('<div />', {id: uuid})
213 this.create_child_view(model).then(function(view) {
208 .addClass('tab-pane')
214 dummy.replaceWith(view.$el);
209 .addClass('fade')
215 view.parent_tab = tab;
210 .append(view.$el)
211 .appendTo(that.$tab_contents);
212 view.parent_container = contents_div;
216 view.parent_container = contents_div;
213
217
214 // Trigger the displayed event of the child view.
218 // Trigger the displayed event of the child view.
215 that.after_displayed(function() {
219 that.after_displayed(function() {
216 view.trigger('displayed');
220 view.trigger('displayed');
217 });
221 });
218 }});
222 }, console.error);
219 },
223 },
220
224
221 update: function(options) {
225 update: function(options) {
General Comments 0
You need to be logged in to leave comments. Login now