##// END OF EJS Templates
Merge branch 'viewlists' of https://github.com/jasongrout/ipython into viewlists
Jason Grout -
r19057:a8bea3d8 merge
parent child Browse files
Show More
@@ -603,7 +603,7 b' define(["widgets/js/manager",'
603 // will be called in that context.
603 // will be called in that context.
604
604
605 this.initialize.apply(this, arguments);
605 this.initialize.apply(this, arguments);
606 }
606 };
607
607
608 _.extend(ViewList.prototype, {
608 _.extend(ViewList.prototype, {
609 initialize: function(create_view, remove_view, context) {
609 initialize: function(create_view, remove_view, context) {
@@ -663,7 +663,7 b' define(["widgets/js/manager",'
663 this.state_change = this.state_change.then(function() {
663 this.state_change = this.state_change.then(function() {
664 for (var i = 0, len=that.views.length; i <len; i++) {
664 for (var i = 0, len=that.views.length; i <len; i++) {
665 that._remove_view.call(that._handler_context, that.views[i]);
665 that._remove_view.call(that._handler_context, that.views[i]);
666 };
666 }
667 that._models = [];
667 that._models = [];
668 that.views = [];
668 that.views = [];
669 });
669 });
@@ -9,18 +9,23 b' define(['
9 ], function(widget, utils, $){
9 ], function(widget, utils, $){
10
10
11 var AccordionView = widget.DOMWidgetView.extend({
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 render: function(){
23 render: function(){
13 // Called when view is rendered.
24 // Called when view is rendered.
14 var guid = 'panel-group' + utils.uuid();
25 var guid = 'panel-group' + utils.uuid();
15 this.$el
26 this.$el
16 .attr('id', guid)
27 .attr('id', guid)
17 .addClass('panel-group');
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 this.model.on('change:selected_index', function(model, value, options) {
29 this.model.on('change:selected_index', function(model, value, options) {
25 this.update_selected_index(model.previous('selected_index'), value, options);
30 this.update_selected_index(model.previous('selected_index'), value, options);
26 }, this);
31 }, this);
@@ -31,6 +36,7 b' define(['
31 this.on('displayed', function() {
36 this.on('displayed', function() {
32 this.update_titles();
37 this.update_titles();
33 }, this);
38 }, this);
39 this.children_views.update(this.model.get('children'));
34 },
40 },
35
41
36 update_titles: function(titles) {
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 remove_child_model: function(model) {
71 remove_child_model: function(model) {
74 // Called when a child is removed from children list.
72 // Called when a child is removed from children list.
@@ -128,14 +126,24 b' define(['
128 return view;
126 return view;
129 }, utils.reject("Couldn't add child view to box", true));
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 var TabView = widget.DOMWidgetView.extend({
137 var TabView = widget.DOMWidgetView.extend({
135 initialize: function() {
138 initialize: function() {
136 // Public constructor.
139 // Public constructor.
137 this.containers = [];
138 TabView.__super__.initialize.apply(this, arguments);
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 render: function(){
149 render: function(){
@@ -149,11 +157,7 b' define(['
149 this.$tab_contents = $('<div />', {id: uuid + 'Content'})
157 this.$tab_contents = $('<div />', {id: uuid + 'Content'})
150 .addClass('tab-content')
158 .addClass('tab-content')
151 .appendTo(this.$el);
159 .appendTo(this.$el);
152 this.containers = [];
160 this.children_views.update(this.model.get('children'));
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);
157 },
161 },
158
162
159 update_attr: function(name, value) {
163 update_attr: function(name, value) {
@@ -161,14 +165,6 b' define(['
161 this.$tabs.css(name, value);
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 remove_child_model: function(model) {
168 remove_child_model: function(model) {
173 // Called when a child is removed from children list.
169 // Called when a child is removed from children list.
174 var view = this.pop_child_view(model);
170 var view = this.pop_child_view(model);
@@ -254,6 +250,11 b' define(['
254 .removeClass('active');
250 .removeClass('active');
255 this.containers[index].tab('show');
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 return {
260 return {
General Comments 0
You need to be logged in to leave comments. Login now