##// END OF EJS Templates
Fix broken accordion widget,...
Jonathan Frederic -
Show More
@@ -29,40 +29,41 define(["widgets/js/widget"], function(WidgetManager){
29 this.model.on('change:_children', function(model, value, options) {
29 this.model.on('change:_children', function(model, value, options) {
30 this.update_children(model.previous('_children'), value);
30 this.update_children(model.previous('_children'), value);
31 }, this);
31 }, this);
32 this.model.on('change:selected_index', function(model, value, options) {
33 this.update_selected_index(model.previous('selected_index'), value, options);
34 }, this);
35 this.model.on('change:_titles', function(model, value, options) {
36 this.update_titles(value);
37 }, this);
32 },
38 },
33
34 update: function(options) {
35 // Update the contents of this view
36 //
37 // Called when the model is changed. The model may have been
38 // changed by another view or by a state update from the back-end.
39 if (options === undefined || options.updated_view != this) {
40 // Set tab titles
41 var titles = this.model.get('_titles');
42 var that = this;
43 _.each(titles, function(title, page_index) {
44 var accordian = that.containers[page_index];
45 if (accordian !== undefined) {
46 accordian
47 .find('.accordion-heading')
48 .find('.accordion-toggle')
49 .text(title);
50 }
51 });
52
39
53 // Set selected page
40 update_titles: function(titles) {
54 var selected_index = this.model.get("selected_index");
41 // Set tab titles
55 if (0 <= selected_index && selected_index < this.containers.length) {
42 var that = this;
56 _.each(this.containers, function(container, index) {
43 console.log('update titles');
57 if (index==selected_index) {
44 _.each(titles, function(title, page_index) {
58 container.find('.accordion-body').collapse('show');
45 var accordian = that.containers[page_index];
59 } else {
46 if (accordian !== undefined) {
60 container.find('.accordion-body').collapse('hide');
47 console.log('setting child title');
61 }
48 accordian
62 });
49 .find('.accordion-heading')
50 .find('.accordion-toggle')
51 .text(title);
52 }
53 });
54 },
55
56 update_selected_index: function(old_index, new_index, options) {
57 // Only update the selection if the selection wasn't triggered
58 // by the front-end. It must be triggered by the back-end.
59 console.log('try update selected_index');
60 if (options === undefined || options.updated_view != this) {
61 console.log('update selected_index');
62 this.containers[old_index].find('.accordion-body').collapse('hide');
63 if (0 <= new_index && new_index < this.containers.length) {
64 this.containers[new_index].find('.accordion-body').collapse('show');
63 }
65 }
64 }
66 }
65 return AccordionView.__super__.update.apply(this);
66 },
67 },
67
68
68 update_children: function(old_list, new_list) {
69 update_children: function(old_list, new_list) {
@@ -74,6 +75,7 define(["widgets/js/widget"], function(WidgetManager){
74 },
75 },
75
76
76 remove_child_model: function(model) {
77 remove_child_model: function(model) {
78 console.log('rm child');
77 // Called when a child is removed from children list.
79 // Called when a child is removed from children list.
78 var accordion_group = this.model_containers[model.id];
80 var accordion_group = this.model_containers[model.id];
79 this.containers.splice(accordion_group.container_index, 1);
81 this.containers.splice(accordion_group.container_index, 1);
@@ -83,6 +85,7 define(["widgets/js/widget"], function(WidgetManager){
83 },
85 },
84
86
85 add_child_model: function(model) {
87 add_child_model: function(model) {
88 console.log('add child');
86 // Called when a child is added to children list.
89 // Called when a child is added to children list.
87 var view = this.create_child_view(model);
90 var view = this.create_child_view(model);
88 var index = this.containers.length;
91 var index = this.containers.length;
@@ -103,7 +106,7 define(["widgets/js/widget"], function(WidgetManager){
103
106
104 // Calling model.set will trigger all of the other views of the
107 // Calling model.set will trigger all of the other views of the
105 // model to update.
108 // model to update.
106 that.model.set("selected_index", index, {updated_view: this});
109 that.model.set("selected_index", index, {updated_view: that});
107 that.touch();
110 that.touch();
108 })
111 })
109 .text('Page ' + index)
112 .text('Page ' + index)
@@ -121,11 +124,11 define(["widgets/js/widget"], function(WidgetManager){
121
124
122 this.update();
125 this.update();
123
126
124 // Stupid workaround to close the bootstrap accordion tabs which
127 // // Stupid workaround to close the bootstrap accordion tabs which
125 // open by default even though they don't have the `in` class
128 // // open by default even though they don't have the `in` class
126 // attached to them. For some reason a delay is required.
129 // // attached to them. For some reason a delay is required.
127 // TODO: Better fix.
130 // // TODO: Better fix.
128 setTimeout(function(){ that.update(); }, 500);
131 // setTimeout(function(){ that.update(); }, 500);
129 },
132 },
130 });
133 });
131 WidgetManager.register_widget_view('AccordionView', AccordionView);
134 WidgetManager.register_widget_view('AccordionView', AccordionView);
General Comments 0
You need to be logged in to leave comments. Login now