##// END OF EJS Templates
rewording according to feedback in #4802
rewording according to feedback in #4802

File last commit:

r15427:3bb7cf6a
r15677:4e9f0f53
Show More
widget_selectioncontainer.js
244 lines | 9.8 KiB | application/javascript | JavascriptLexer
/ IPython / html / static / widgets / js / widget_selectioncontainer.js
Jonathan Frederic
Added standard IPY JS header to widget JS files.
r14366 //----------------------------------------------------------------------------
// Copyright (C) 2013 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
//============================================================================
Jonathan Frederic
Finished renaming Multicontainer to SelectionContainer
r14578 // SelectionContainerWidget
Jonathan Frederic
Added standard IPY JS header to widget JS files.
r14366 //============================================================================
/**
* @module IPython
* @namespace IPython
**/
Jonathan Frederic
Updated require references to point to new files
r15427 define(["widgets/js/widget"], function(WidgetManager){
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609
Jonathan Frederic
s/BaseWidgetView/WidgetView and s/WidgetView/DOMWidgetView
r14564 var AccordionView = IPython.DOMWidgetView.extend({
Jonathan Frederic
Added multicontainer widget
r14284 render: function(){
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Called when view is rendered.
Jonathan Frederic
Make sure DOM element ids start with alphabetic characters, not numeric.
r14398 var guid = 'accordion' + IPython.utils.uuid();
Jonathan Frederic
Fixed backbone event handling for accordion view
r14455 this.$el
.attr('id', guid)
Jonathan Frederic
Added multicontainer widget
r14284 .addClass('accordion');
this.containers = [];
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 this.model_containers = {};
Jonathan Frederic
Fix bug in all children containing views
r14611 this.update_children([], this.model.get('_children'));
this.model.on('change:_children', function(model, value, options) {
this.update_children(model.previous('_children'), value);
Jonathan Frederic
Added `update_children` pattern to remaining parent widgets
r14507 }, this);
Jason Grout
Live updates for children automatically change container views....
r14503 },
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 update: function(options) {
Jonathan Frederic
make JS update comment more descriptive (english)
r14568 // 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
add locks to update everywhere by using options to pass this...
r14570 if (options === undefined || options.updated_view != this) {
// Set tab titles
var titles = this.model.get('_titles');
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 var that = this;
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 _.each(titles, function(title, page_index) {
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 var accordian = that.containers[page_index];
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 if (accordian !== undefined) {
accordian
.find('.accordion-heading')
.find('.accordion-toggle')
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 .text(title);
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 }
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 });
Jonathan Frederic
Added multicontainer widget
r14284
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 // Set selected page
var selected_index = this.model.get("selected_index");
if (0 <= selected_index && selected_index < this.containers.length) {
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 _.each(this.containers, function(container, index) {
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 if (index==selected_index) {
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 container.find('.accordion-body').collapse('show');
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 } else {
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 container.find('.accordion-body').collapse('hide');
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 }
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 });
Jonathan Frederic
Added selected_index support to accordion view.
r14370 }
}
Jonathan Frederic
Many checks off the todo list, test fixes
r14583 return AccordionView.__super__.update.apply(this);
Jonathan Frederic
Added multicontainer widget
r14284 },
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598
update_children: function(old_list, new_list) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Called when the children list is modified.
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 this.do_diff(old_list,
new_list,
$.proxy(this.remove_child_model, this),
$.proxy(this.add_child_model, this));
},
Jonathan Frederic
Added multicontainer widget
r14284
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 remove_child_model: function(model) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Called when a child is removed from children list.
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();
this.delete_child_view(model);
},
Jonathan Frederic
Added multicontainer widget
r14284
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 add_child_model: function(model) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Called when a child is added to children list.
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 var view = this.create_child_view(model);
Jonathan Frederic
Added multicontainer widget
r14284 var index = this.containers.length;
var uuid = IPython.utils.uuid();
var accordion_group = $('<div />')
.addClass('accordion-group')
.appendTo(this.$el);
var accordion_heading = $('<div />')
.addClass('accordion-heading')
.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
add locks to update everywhere by using options to pass this...
r14570 that.model.set("selected_index", index, {updated_view: this});
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
Added ability to set container page titles for widget multicontainer
r14288 .addClass('accordion-body collapse')
Jonathan Frederic
Added multicontainer widget
r14284 .appendTo(accordion_group);
var accordion_inner = $('<div />')
.addClass('accordion-inner')
.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;
Jonathan Frederic
Added multicontainer widget
r14284 accordion_inner.append(view.$el);
Jonathan Frederic
Added selected_index support to accordion view.
r14370
Jonathan Frederic
Added ability to title multicontainer pages before multicontainer display()
r14289 this.update();
Jonathan Frederic
Added selected_index support to accordion view.
r14370
// Stupid workaround to close the bootstrap accordion tabs which
// open by default even though they don't have the `in` class
// attached to them. For some reason a delay is required.
// TODO: Better fix.
Jonathan Frederic
jslint /widgets
r14466 setTimeout(function(){ that.update(); }, 500);
Jonathan Frederic
Added multicontainer widget
r14284 },
});
Jonathan Frederic
Widget require.js fix...
r14627 WidgetManager.register_widget_view('AccordionView', AccordionView);
Jonathan Frederic
Added TabView to multicontainer
r14290
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609
var TabView = IPython.DOMWidgetView.extend({
Jonathan Frederic
Added `update_children` pattern to remaining parent widgets
r14507 initialize: function() {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Public constructor.
Jonathan Frederic
Added `update_children` pattern to remaining parent widgets
r14507 this.containers = [];
Jonathan Frederic
Many checks off the todo list, test fixes
r14583 TabView.__super__.initialize.apply(this, arguments);
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
Added PEP8 style comments to all of the JS code.
r14609 // Called when view is rendered.
Jonathan Frederic
Make sure DOM element ids start with alphabetic characters, not numeric.
r14398 var uuid = 'tabs'+IPython.utils.uuid();
Jonathan Frederic
Added selected_index property to TabView
r14307 var that = this;
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
Added `update_children` pattern to remaining parent widgets
r14507 this.containers = [];
Jonathan Frederic
Fix bug in all children containing views
r14611 this.update_children([], this.model.get('_children'));
this.model.on('change:_children', function(model, value, options) {
this.update_children(model.previous('_children'), value);
Jonathan Frederic
Added `update_children` pattern to remaining parent widgets
r14507 }, this);
},
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 update_children: function(old_list, new_list) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Called when the children list is modified.
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 this.do_diff(old_list,
new_list,
$.proxy(this.remove_child_model, this),
$.proxy(this.add_child_model, this));
},
Jonathan Frederic
Added selected_index support to accordion view.
r14370
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 remove_child_model: function(model) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Called when a child is removed from children list.
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 var view = this.child_views[model.id];
this.containers.splice(view.parent_tab.tab_text_index, 1);
view.parent_tab.remove();
view.parent_container.remove();
view.remove();
this.delete_child_view(model);
Jonathan Frederic
Added TabView to multicontainer
r14290 },
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 add_child_model: function(model) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Called when a child is added to children list.
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 var view = this.create_child_view(model);
Jonathan Frederic
Added TabView to multicontainer
r14290 var index = this.containers.length;
var uuid = IPython.utils.uuid();
var that = this;
var tab = $('<li />')
.css('list-style-type', 'none')
.appendTo(this.$tabs);
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 view.parent_tab = tab;
Jonathan Frederic
Added TabView to multicontainer
r14290 var tab_text = $('<a />')
.attr('href', '#' + uuid)
.attr('data-toggle', 'tab')
Jonathan Frederic
Replace .html with .text everywhere possible
r14663 .text('Page ' + index)
Jonathan Frederic
Added TabView to multicontainer
r14290 .appendTo(tab)
.click(function (e) {
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
add locks to update everywhere by using options to pass this...
r14570 that.model.set("selected_index", index, {updated_view: this});
Jonathan Frederic
Moved touch logic out of model into view....
r14482 that.touch();
Jonathan Frederic
Added selected_index property to TabView
r14307 that.select_page(index);
Jonathan Frederic
Added TabView to multicontainer
r14290 });
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 tab.tab_text_index = this.containers.push(tab_text) - 1;
Jonathan Frederic
Added TabView to multicontainer
r14290
var contents_div = $('<div />', {id: uuid})
.addClass('tab-pane')
.addClass('fade')
.append(view.$el)
.appendTo(this.$tab_contents);
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 view.parent_container = contents_div;
},
update: function(options) {
// 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.
if (options === undefined || options.updated_view != this) {
// Set tab titles
var titles = this.model.get('_titles');
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 var that = this;
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 _.each(titles, function(title, page_index) {
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 var tab_text = that.containers[page_index];
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 if (tab_text !== undefined) {
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 tab_text.text(title);
}
});
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);
}
}
return TabView.__super__.update.apply(this);
Jonathan Frederic
Added TabView to multicontainer
r14290 },
Jonathan Frederic
Added selected_index property to TabView
r14307
select_page: function(index) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // 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
Added TabView to multicontainer
r14290 });
Jonathan Frederic
Widget require.js fix...
r14627 WidgetManager.register_widget_view('TabView', TabView);
Jonathan Frederic
Added TabView to multicontainer
r14290 });