##// END OF EJS Templates
simpler select function
Mathieu -
Show More
@@ -122,14 +122,14 b' define(['
122 $('.delete-button').click($.proxy(this.delete_selected, this));
122 $('.delete-button').click($.proxy(this.delete_selected, this));
123
123
124 // Bind events for selection menu buttons.
124 // Bind events for selection menu buttons.
125 $('#selector-menu').click(function(event){that.select($(event.target).attr('id'),true)});
125 $('#selector-menu').click(function(event){that.select($(event.target).attr('id'))});
126 $('.tree-selector').change(function(){that.select($(this).attr('id'),$(this).is(':checked'))});
126 $('#select-all').change(function(){that.select($(this).is(':checked') ? 'select-all' : 'select-none')});
127 $('#button-select-all').click(function(e) {
127 $('#button-select-all').click(function(e) {
128 // toggle checkbox if the click doesn't come from the checkbox already
128 // toggle checkbox if the click doesn't come from the checkbox already
129 if (!$(e.target).is('input[type=checkbox]')) {
129 if (!$(e.target).is('input[type=checkbox]')) {
130 var checkbox = $('#select-all');
130 var checkbox = $('#select-all');
131 checkbox.prop('checked', !checkbox.prop('checked'));
131 checkbox.prop('checked', !checkbox.prop('checked'));
132 that.select('select-all',checkbox.prop('checked'));
132 that.select(checkbox.prop('checked') ? 'select-all' : 'select-none');
133 }
133 }
134 });
134 });
135 }
135 }
@@ -387,21 +387,20 b' define(['
387
387
388 /**
388 /**
389 * Select all items in the tree of specified type.
389 * Select all items in the tree of specified type.
390 * selection_type : string among "select-all, "select-folders", "select-notebooks", "select-running-notebooks", "select-files"
390 * selection_type : string among "select-all", "select-folders", "select-notebooks", "select-running-notebooks", "select-files"
391 * state : boolean, true to select and false to deselect
391 * any other string (like "select-none") deselects all items
392 */
392 */
393 NotebookList.prototype.select = function(selection_type,state) {
393 NotebookList.prototype.select = function(selection_type) {
394 var that = this;
394 var that = this;
395 $('.list_item').each(function(index, item) {
395 $('.list_item').each(function(index, item) {
396 // For each item, determine if the state should be set, depending on the selection_type that triggered select
396 var item_type = $(item).data('type');
397 var set_state = (selection_type === "select-all");
397 var state = false;
398 set_state = set_state || (selection_type === "select-folders" && $(item).data('type') === 'directory');
398 state = state || (selection_type === "select-all");
399 set_state = set_state || (selection_type === "select-notebooks" && $(item).data('type') === 'notebook');
399 state = state || (selection_type === "select-folders" && item_type === 'directory');
400 set_state = set_state || (selection_type === "select-running-notebooks" && $(item).data('type') === 'notebook' && that.sessions[$(item).data('path')] !== undefined);
400 state = state || (selection_type === "select-notebooks" && item_type === 'notebook');
401 set_state = set_state || (selection_type === "select-files" && $(item).data('type') === 'file');
401 state = state || (selection_type === "select-running-notebooks" && item_type === 'notebook' && that.sessions[$(item).data('path')] !== undefined);
402 if (set_state) {
402 state = state || (selection_type === "select-files" && item_type === 'file');
403 $(item).find('input[type=checkbox]').prop('checked', state);
403 $(item).find('input[type=checkbox]').prop('checked', state);
404 }
405 });
404 });
406 this._selection_changed();
405 this._selection_changed();
407 };
406 };
General Comments 0
You need to be logged in to leave comments. Login now