##// END OF EJS Templates
Fixed error stemming from mixed args and 'commented out' args
Fixed error stemming from mixed args and 'commented out' args

File last commit:

r19799:9603e514 merge
r20900:15144034
Show More
widget_selectioncontainer.js
324 lines | 11.7 KiB | application/javascript | JavascriptLexer
/ IPython / html / static / widgets / js / widget_selectioncontainer.js
Jonathan Frederic
Almost done!...
r17198 // Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
Jonathan Frederic
Added standard IPY JS header to widget JS files.
r14366
Jonathan Frederic
Almost done!...
r17198 define([
"widgets/js/widget",
Jonathan Frederic
Done with major changes,...
r17199 "base/js/utils",
Jonathan Frederic
Fix all the tests
r17216 "jquery",
MinRK
add bootstrap shim for require...
r17312 "bootstrap",
Jonathan Frederic
Fix all the tests
r17216 ], function(widget, utils, $){
Jonathan Frederic
Added standard IPY JS header to widget JS files.
r14366
Jonathan Frederic
Almost done!...
r17198 var AccordionView = widget.DOMWidgetView.extend({
Jonathan Frederic
Implement view logic in selection containers.
r19023 initialize: function(){
AccordionView.__super__.initialize.apply(this, arguments);
this.containers = [];
this.model_containers = {};
Jason Grout
Update widget selection containers to reflect how viewlist works...
r19067 this.children_views = new widget.ViewList(this.add_child_view, this.remove_child_view, this);
Jonathan Frederic
Implement view logic in selection containers.
r19023 this.listenTo(this.model, 'change:children', function(model, value) {
this.children_views.update(value);
}, this);
},
Jonathan Frederic
Added multicontainer widget
r14284 render: function(){
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Called when view is rendered.
*/
Jonathan Frederic
Done with major changes,...
r17199 var guid = 'panel-group' + utils.uuid();
Jonathan Frederic
Fixed backbone event handling for accordion view
r14455 this.$el
.attr('id', guid)
Jonathan Frederic
Ran jdfreder/bootstrap2to3
r16913 .addClass('panel-group');
Jonathan Frederic
Fix broken accordion widget,...
r15950 this.model.on('change:selected_index', function(model, value, options) {
Jonathan Frederic
Fix a bunch of bugs with the accordion and tab widgets
r19773 this.update_selected_index(options);
Jonathan Frederic
Fix broken accordion widget,...
r15950 }, this);
this.model.on('change:_titles', function(model, value, options) {
Jonathan Frederic
Fix a bunch of bugs with the accordion and tab widgets
r19773 this.update_titles(options);
Jonathan Frederic
Fix broken accordion widget,...
r15950 }, this);
Jonathan Frederic
Move displayed event to view.
r17179 this.on('displayed', function() {
Jonathan Frederic
Add displayed property....
r15955 this.update_titles();
sylvain.corlay
correction
r17354 }, this);
Jonathan Frederic
Implement view logic in selection containers.
r19023 this.children_views.update(this.model.get('children'));
Jason Grout
Live updates for children automatically change container views....
r14503 },
Jonathan Frederic
Added multicontainer widget
r14284
Jonathan Frederic
Fix a bunch of bugs with the accordion and tab widgets
r19773 /**
* Update the contents of this view
*
* Called when the model is changed. The model may have been
* changed by another view or by a state update from the back-end.
*/
update: function(options) {
this.update_titles();
this.update_selected_index(options);
return TabView.__super__.update.apply(this);
},
update_titles: function() {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Set tab titles
*/
Jonathan Frederic
Fix a bunch of bugs with the accordion and tab widgets
r19773 var titles = this.model.get('_titles');
Jonathan Frederic
Fix broken accordion widget,...
r15950 var that = this;
_.each(titles, function(title, page_index) {
var accordian = that.containers[page_index];
if (accordian !== undefined) {
accordian
Jonathan Frederic
Ran jdfreder/bootstrap2to3
r16913 .find('.panel-heading')
Jonathan Frederic
Fix broken accordion widget,...
r15950 .find('.accordion-toggle')
.text(title);
}
});
},
Jonathan Frederic
Fix a bunch of bugs with the accordion and tab widgets
r19773 update_selected_index: function(options) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Only update the selection if the selection wasn't triggered
* by the front-end. It must be triggered by the back-end.
*/
Jonathan Frederic
Fix broken accordion widget,...
r15950 if (options === undefined || options.updated_view != this) {
Jonathan Frederic
Fix a bunch of bugs with the accordion and tab widgets
r19773 var old_index = this.model.previous('selected_index');
var new_index = this.model.get('selected_index');
Jonathan Frederic
Ran jdfreder/bootstrap2to3
r16913 this.containers[old_index].find('.panel-collapse').collapse('hide');
Jonathan Frederic
Fix broken accordion widget,...
r15950 if (0 <= new_index && new_index < this.containers.length) {
Jonathan Frederic
Ran jdfreder/bootstrap2to3
r16913 this.containers[new_index].find('.panel-collapse').collapse('show');
Jonathan Frederic
Added selected_index support to accordion view.
r14370 }
}
Jonathan Frederic
Added multicontainer widget
r14284 },
Jason Grout
Update widget selection containers to reflect how viewlist works...
r19067 remove_child_view: function(view) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Called when a child is removed from children list.
* TODO: does this handle two different views of the same model as children?
*/
Jason Grout
Update widget selection containers to reflect how viewlist works...
r19067 var model = view.model;
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 var accordion_group = this.model_containers[model.id];
this.containers.splice(accordion_group.container_index, 1);
delete this.model_containers[model.id];
accordion_group.remove();
},
Jonathan Frederic
Added multicontainer widget
r14284
Jason Grout
Update widget selection containers to reflect how viewlist works...
r19067 add_child_view: function(model) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Called when a child is added to children list.
*/
Jonathan Frederic
Added multicontainer widget
r14284 var index = this.containers.length;
Jonathan Frederic
Done with major changes,...
r17199 var uuid = utils.uuid();
Jonathan Frederic
Added multicontainer widget
r14284 var accordion_group = $('<div />')
Jonathan Frederic
Ran jdfreder/bootstrap2to3
r16913 .addClass('panel panel-default')
Jonathan Frederic
Added multicontainer widget
r14284 .appendTo(this.$el);
var accordion_heading = $('<div />')
Jonathan Frederic
Ran jdfreder/bootstrap2to3
r16913 .addClass('panel-heading')
Jonathan Frederic
Added multicontainer widget
r14284 .appendTo(accordion_group);
Jonathan Frederic
Added selected_index support to accordion view.
r14370 var that = this;
Jonathan Frederic
Added multicontainer widget
r14284 var accordion_toggle = $('<a />')
.addClass('accordion-toggle')
.attr('data-toggle', 'collapse')
.attr('data-parent', '#' + this.$el.attr('id'))
.attr('href', '#' + uuid)
Jonathan Frederic
Added selected_index support to accordion view.
r14370 .click(function(evt){
Jonathan Frederic
comment model.set, so we know that it triggers update on other views
r14569
// Calling model.set will trigger all of the other views of the
// model to update.
Jonathan Frederic
Fix broken accordion widget,...
r15950 that.model.set("selected_index", index, {updated_view: that});
Jonathan Frederic
Moved touch logic out of model into view....
r14482 that.touch();
Jonathan Frederic
Added selected_index support to accordion view.
r14370 })
Jonathan Frederic
Replace .html with .text everywhere possible
r14663 .text('Page ' + index)
Jonathan Frederic
Added multicontainer widget
r14284 .appendTo(accordion_heading);
var accordion_body = $('<div />', {id: uuid})
Jonathan Frederic
Ran jdfreder/bootstrap2to3
r16913 .addClass('panel-collapse collapse')
Jonathan Frederic
Added multicontainer widget
r14284 .appendTo(accordion_group);
var accordion_inner = $('<div />')
Jonathan Frederic
Ran jdfreder/bootstrap2to3
r16913 .addClass('panel-body')
Jonathan Frederic
Added multicontainer widget
r14284 .appendTo(accordion_body);
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 var container_index = this.containers.push(accordion_group) - 1;
accordion_group.container_index = container_index;
this.model_containers[model.id] = accordion_group;
Thomas Kluyver
Allow widget views to be loaded from require modules...
r18142
Jonathan Frederic
Fix view rendering order.
r18883 var dummy = $('<div/>');
accordion_inner.append(dummy);
Jonathan Frederic
Finished adding error handling.
r18896 return this.create_child_view(model).then(function(view) {
Jonathan Frederic
Fix view rendering order.
r18883 dummy.replaceWith(view.$el);
Thomas Kluyver
Allow widget views to be loaded from require modules...
r18142 that.update();
that.update_titles();
Jonathan Frederic
Fixed bugs in displayed event triggering for containers
r16660
Thomas Kluyver
Allow widget views to be loaded from require modules...
r18142 // Trigger the displayed event of the child view.
that.after_displayed(function() {
view.trigger('displayed');
});
Jonathan Frederic
Finished adding error handling.
r18896 return view;
Jason Grout
Catch errors after our then()s, instead of in parallel with them (this missing exceptions)...
r19080 }).catch(utils.reject("Couldn't add child view to box", true));
Jonathan Frederic
Added multicontainer widget
r14284 },
Jonathan Frederic
Implement view logic in selection containers.
r19023
remove: function() {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* We remove this widget before removing the children as an optimization
* we want to remove the entire container from the DOM first before
* removing each individual child separately.
*/
Jonathan Frederic
Implement view logic in selection containers.
r19023 AccordionView.__super__.remove.apply(this, arguments);
this.children_views.remove();
},
Jonathan Frederic
Added multicontainer widget
r14284 });
Jonathan Frederic
Added TabView to multicontainer
r14290
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609
Jonathan Frederic
Almost done!...
r17198 var TabView = widget.DOMWidgetView.extend({
Jonathan Frederic
Added `update_children` pattern to remaining parent widgets
r14507 initialize: function() {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Public constructor.
*/
Jonathan Frederic
Many checks off the todo list, test fixes
r14583 TabView.__super__.initialize.apply(this, arguments);
Jonathan Frederic
Implement view logic in selection containers.
r19023
this.containers = [];
Jason Grout
Update widget selection containers to reflect how viewlist works...
r19067 this.children_views = new widget.ViewList(this.add_child_view, this.remove_child_view, this);
Jonathan Frederic
Implement view logic in selection containers.
r19023 this.listenTo(this.model, 'change:children', function(model, value) {
this.children_views.update(value);
}, this);
Jonathan Frederic
Added `update_children` pattern to remaining parent widgets
r14507 },
Jason Grout
Intermediate changes to javascript side of backbone widgets
r14486
Jonathan Frederic
Added TabView to multicontainer
r14290 render: function(){
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Called when view is rendered.
*/
Jonathan Frederic
Done with major changes,...
r17199 var uuid = 'tabs'+utils.uuid();
Jonathan Frederic
Added TabView to multicontainer
r14290 this.$tabs = $('<div />', {id: uuid})
.addClass('nav')
.addClass('nav-tabs')
.appendTo(this.$el);
this.$tab_contents = $('<div />', {id: uuid + 'Content'})
.addClass('tab-content')
.appendTo(this.$el);
Jonathan Frederic
Implement view logic in selection containers.
r19023 this.children_views.update(this.model.get('children'));
Jonathan Frederic
Added `update_children` pattern to remaining parent widgets
r14507 },
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609
Jonathan Frederic
Finished style attributes.
r17724 update_attr: function(name, value) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Set a css attr of the widget view.
*/
Jonathan Frederic
Fix padding of widgets.
r19366 if (name == 'padding' || name == 'margin') {
this.$el.css(name, value);
} else {
this.$tabs.css(name, value);
}
Jonathan Frederic
Finished style attributes.
r17724 },
Jason Grout
Update widget selection containers to reflect how viewlist works...
r19067 remove_child_view: function(view) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Called when a child is removed from children list.
*/
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 this.containers.splice(view.parent_tab.tab_text_index, 1);
view.parent_tab.remove();
view.parent_container.remove();
view.remove();
Jonathan Frederic
Added TabView to multicontainer
r14290 },
Jason Grout
Update widget selection containers to reflect how viewlist works...
r19067 add_child_view: function(model) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Called when a child is added to children list.
*/
Jonathan Frederic
Added TabView to multicontainer
r14290 var index = this.containers.length;
Jonathan Frederic
Done with major changes,...
r17199 var uuid = utils.uuid();
Jonathan Frederic
Added TabView to multicontainer
r14290
var that = this;
var tab = $('<li />')
.css('list-style-type', 'none')
.appendTo(this.$tabs);
Thomas Kluyver
Allow widget views to be loaded from require modules...
r18142
Jonathan Frederic
Fix view rendering order.
r18883 var tab_text = $('<a />')
.attr('href', '#' + uuid)
.attr('data-toggle', 'tab')
.text('Page ' + index)
.appendTo(tab)
.click(function (e) {
// Calling model.set will trigger all of the other views of the
// model to update.
that.model.set("selected_index", index, {updated_view: that});
that.touch();
that.select_page(index);
});
tab.tab_text_index = that.containers.push(tab_text) - 1;
var dummy = $('<div />');
var contents_div = $('<div />', {id: uuid})
.addClass('tab-pane')
.addClass('fade')
.append(dummy)
.appendTo(that.$tab_contents);
Jonathan Frederic
Fix a bunch of bugs with the accordion and tab widgets
r19773 this.update();
Jonathan Frederic
Finished adding error handling.
r18896 return this.create_child_view(model).then(function(view) {
Jonathan Frederic
Fix view rendering order.
r18883 dummy.replaceWith(view.$el);
view.parent_tab = tab;
Thomas Kluyver
Allow widget views to be loaded from require modules...
r18142 view.parent_container = contents_div;
// Trigger the displayed event of the child view.
that.after_displayed(function() {
view.trigger('displayed');
Jonathan Frederic
Fix a bunch of bugs with the accordion and tab widgets
r19773 that.update();
Jonathan Frederic
Added TabView to multicontainer
r14290 });
Jonathan Frederic
Finished adding error handling.
r18896 return view;
Jason Grout
Catch errors after our then()s, instead of in parallel with them (this missing exceptions)...
r19080 }).catch(utils.reject("Couldn't add child view to box", true));
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 },
update: function(options) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Update the contents of this view
*
* Called when the model is changed. The model may have been
* changed by another view or by a state update from the back-end.
*/
Jonathan Frederic
Fix a bunch of bugs with the accordion and tab widgets
r19773 this.update_titles();
this.update_selected_index(options);
return TabView.__super__.update.apply(this);
},
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598
Jonathan Frederic
Fix a bunch of bugs with the accordion and tab widgets
r19773 /**
* Updates the tab page titles.
*/
update_titles: function() {
var titles = this.model.get('_titles');
var that = this;
_.each(titles, function(title, page_index) {
var tab_text = that.containers[page_index];
if (tab_text !== undefined) {
tab_text.text(title);
}
});
},
/**
* Updates the tab page titles.
*/
update_selected_index: function(options) {
if (options === undefined || options.updated_view != this) {
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 var selected_index = this.model.get('selected_index');
if (0 <= selected_index && selected_index < this.containers.length) {
this.select_page(selected_index);
}
}
Jonathan Frederic
Added TabView to multicontainer
r14290 },
Jonathan Frederic
Added selected_index property to TabView
r14307
select_page: function(index) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Select a page.
*/
Jonathan Frederic
Added selected_index property to TabView
r14307 this.$tabs.find('li')
.removeClass('active');
this.containers[index].tab('show');
},
Jonathan Frederic
Implement view logic in selection containers.
r19023
remove: function() {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* We remove this widget before removing the children as an optimization
* we want to remove the entire container from the DOM first before
* removing each individual child separately.
*/
Jonathan Frederic
Implement view logic in selection containers.
r19023 TabView.__super__.remove.apply(this, arguments);
this.children_views.remove();
},
Jonathan Frederic
Added TabView to multicontainer
r14290 });
Jonathan Frederic
Almost done!...
r17198
return {
'AccordionView': AccordionView,
'TabView': TabView,
};
Jonathan Frederic
Added TabView to multicontainer
r14290 });