##// END OF EJS Templates
Merge pull request #6 from jdfreder/viewlists...
Jason Grout -
r19056:bb44caae merge
parent child Browse files
Show More
@@ -359,8 +359,6 b' define(["widgets/js/manager",'
359 359 // Callback that is called for each item added.
360 360
361 361 // Walk the lists until an unequal entry is found.
362 console.error("Deprecated _do_diff; use a ViewList or similar class instead");
363
364 362 var i;
365 363 for (i = 0; i < new_list.length; i++) {
366 364 if (i >= old_list.length || new_list[i] !== old_list[i]) {
@@ -605,7 +603,7 b' define(["widgets/js/manager",'
605 603 // will be called in that context.
606 604
607 605 this.initialize.apply(this, arguments);
608 }
606 };
609 607
610 608 _.extend(ViewList.prototype, {
611 609 initialize: function(create_view, remove_view, context) {
@@ -661,7 +659,7 b' define(["widgets/js/manager",'
661 659 this.state_change = this.state_change.then(function() {
662 660 for (var i = 0, len=that.views.length; i <len; i++) {
663 661 that._remove_view.call(that._handler_context, that.views[i]);
664 };
662 }
665 663 that._models = [];
666 664 that.views = [];
667 665 });
@@ -9,18 +9,23 b' define(['
9 9 ], function(widget, utils, $){
10 10
11 11 var AccordionView = widget.DOMWidgetView.extend({
12 initialize: function(){
13 AccordionView.__super__.initialize.apply(this, arguments);
14
15 this.containers = [];
16 this.model_containers = {};
17 this.children_views = new widget.ViewList(this.add_child_model, this.remove_child_model, this);
18 this.listenTo(this.model, 'change:children', function(model, value) {
19 this.children_views.update(value);
20 }, this);
21 },
22
12 23 render: function(){
13 24 // Called when view is rendered.
14 25 var guid = 'panel-group' + utils.uuid();
15 26 this.$el
16 27 .attr('id', guid)
17 28 .addClass('panel-group');
18 this.containers = [];
19 this.model_containers = {};
20 this.update_children([], this.model.get('children'));
21 this.model.on('change:children', function(model, value, options) {
22 this.update_children(model.previous('children'), value);
23 }, this);
24 29 this.model.on('change:selected_index', function(model, value, options) {
25 30 this.update_selected_index(model.previous('selected_index'), value, options);
26 31 }, this);
@@ -31,6 +36,7 b' define(['
31 36 this.on('displayed', function() {
32 37 this.update_titles();
33 38 }, this);
39 this.children_views.update(this.model.get('children'));
34 40 },
35 41
36 42 update_titles: function(titles) {
@@ -61,14 +67,6 b' define(['
61 67 }
62 68 }
63 69 },
64
65 update_children: function(old_list, new_list) {
66 // Called when the children list is modified.
67 this.do_diff(old_list,
68 new_list,
69 $.proxy(this.remove_child_model, this),
70 $.proxy(this.add_child_model, this));
71 },
72 70
73 71 remove_child_model: function(model) {
74 72 // Called when a child is removed from children list.
@@ -128,14 +126,24 b' define(['
128 126 return view;
129 127 }, utils.reject("Couldn't add child view to box", true));
130 128 },
129
130 remove: function() {
131 AccordionView.__super__.remove.apply(this, arguments);
132 this.children_views.remove();
133 },
131 134 });
132 135
133 136
134 137 var TabView = widget.DOMWidgetView.extend({
135 138 initialize: function() {
136 139 // Public constructor.
137 this.containers = [];
138 140 TabView.__super__.initialize.apply(this, arguments);
141
142 this.containers = [];
143 this.children_views = new widget.ViewList(this.add_child_model, this.remove_child_model, this);
144 this.listenTo(this.model, 'change:children', function(model, value) {
145 this.children_views.update(value);
146 }, this);
139 147 },
140 148
141 149 render: function(){
@@ -149,11 +157,7 b' define(['
149 157 this.$tab_contents = $('<div />', {id: uuid + 'Content'})
150 158 .addClass('tab-content')
151 159 .appendTo(this.$el);
152 this.containers = [];
153 this.update_children([], this.model.get('children'));
154 this.model.on('change:children', function(model, value, options) {
155 this.update_children(model.previous('children'), value);
156 }, this);
160 this.children_views.update(this.model.get('children'));
157 161 },
158 162
159 163 update_attr: function(name, value) {
@@ -161,14 +165,6 b' define(['
161 165 this.$tabs.css(name, value);
162 166 },
163 167
164 update_children: function(old_list, new_list) {
165 // Called when the children list is modified.
166 this.do_diff(old_list,
167 new_list,
168 $.proxy(this.remove_child_model, this),
169 $.proxy(this.add_child_model, this));
170 },
171
172 168 remove_child_model: function(model) {
173 169 // Called when a child is removed from children list.
174 170 var view = this.pop_child_view(model);
@@ -254,6 +250,11 b' define(['
254 250 .removeClass('active');
255 251 this.containers[index].tab('show');
256 252 },
253
254 remove: function() {
255 TabView.__super__.remove.apply(this, arguments);
256 this.children_views.remove();
257 },
257 258 });
258 259
259 260 return {
General Comments 0
You need to be logged in to leave comments. Login now