##// END OF EJS Templates
streamline tree-selector menu using checkboxes...
Mathieu -
Show More
@@ -122,12 +122,9 b' define(['
122 122 $('.delete-button').click($.proxy(this.delete_selected, this));
123 123
124 124 // Bind events for selection menu buttons.
125 $('#tree-selector .select-all').click($.proxy(this.select_all, this));
126 $('#tree-selector .select-notebooks').click($.proxy(this.select_notebooks, this));
127 $('#tree-selector .select-running-notebooks').click($.proxy(this.select_running_notebooks, this));
128 $('#tree-selector .select-files').click($.proxy(this.select_files, this));
129 $('#tree-selector .select-directories').click($.proxy(this.select_directories, this));
130 $('#tree-selector .deselect-all').click($.proxy(this.deselect_all, this));
125 $('.tree-selector').change(function(){that.select($(this).attr('id'),$(this).is(':checked'))});
126 // Do not propagate click for the menu to prevent the menu from closing
127 $('#tree-selector-menu').click(function(event){event.stopPropagation();})
131 128 }
132 129 };
133 130
@@ -382,113 +379,84 b' define(['
382 379 };
383 380
384 381 /**
385 * Select all of the items in the tree.
382 * Select items in the tree of specified kind.
383 * checkbox_id : string among "select-all, "select-folders", "select-notebooks", "select-running-notebooks", "select-files"
384 * state : boolean, true to select and false to deselect
386 385 */
387 NotebookList.prototype.select_all = function() {
388 $('.list_item input[type=checkbox]').each(function(index, item) {
389 $(item).prop('checked', true);
390 });
391 this._selection_changed();
392 };
393
394 /**
395 * Select all of the notebooks in the tree.
396 */
397 NotebookList.prototype.select_notebooks = function() {
398 this.deselect_all();
399 $('.list_item').each(function(index, item) {
400 if ($(item).data('type') === 'notebook') {
401 $(item).find('input[type=checkbox]').prop('checked', true);
402 }
403 });
404 this._selection_changed();
405 };
406
407 /**
408 * Select all of the running notebooks in the tree.
409 */
410 NotebookList.prototype.select_running_notebooks = function() {
411 this.deselect_all();
386 NotebookList.prototype.select = function(checkbox_id,state) {
412 387 var that = this;
413 388 $('.list_item').each(function(index, item) {
414 if ($(item).data('type') === 'notebook' && that.sessions[$(item).data('path')] !== undefined) {
415 $(item).find('input[type=checkbox]').prop('checked', true);
389 // For each item, determine if the state should be set, depending on the checkbox_id that triggered select
390 var set_state = (checkbox_id === "select-all");
391 set_state = set_state || (checkbox_id === "select-folders" && $(item).data('type') === 'directory');
392 set_state = set_state || (checkbox_id === "select-notebooks" && $(item).data('type') === 'notebook');
393 set_state = set_state || (checkbox_id === "select-running-notebooks" && $(item).data('type') === 'notebook' && that.sessions[$(item).data('path')] !== undefined);
394 set_state = set_state || (checkbox_id === "select-files" && $(item).data('type') === 'file');
395 if (set_state) {
396 $(item).find('input[type=checkbox]').prop('checked', state);
416 397 }
417 398 });
418 399 this._selection_changed();
419 400 };
420 401
421 /**
422 * Select all of the files in the tree.
423 */
424 NotebookList.prototype.select_files = function() {
425 this.deselect_all();
426 $('.list_item').each(function(index, item) {
427 if ($(item).data('type') === 'file') {
428 $(item).find('input[type=checkbox]').prop('checked', true);
429 }
430 });
431 this._selection_changed();
432 };
433
434 /**
435 * Select all of the directories in the tree.
436 */
437 NotebookList.prototype.select_directories = function() {
438 this.deselect_all();
439 $('.list_item').each(function(index, item) {
440 if ($(item).data('type') === 'directory') {
441 $(item).find('input[type=checkbox]').prop('checked', true);
442 }
443 });
444 this._selection_changed();
445 };
446
447 /**
448 * Unselect everything selected in the tree.
449 */
450 NotebookList.prototype.deselect_all = function() {
451 $('.list_item input[type=checkbox]').each(function(index, item) {
452 $(item).prop('checked', false);
453 });
454 this._selection_changed();
455 };
456
457 402
458 403 /**
459 404 * Handles when any row selector checkbox is toggled.
460 405 */
461 406 NotebookList.prototype._selection_changed = function() {
462 // Use a JQuery selector to find each row with a checked checkbox. If
407 // Use a JQuery selector to find each row with a checkbox. If
463 408 // we decide to add more checkboxes in the future, this code will need
464 409 // to be changed to distinguish which checkbox is the row selector.
465 410 var selected = [];
466 var has_running_notebook = false;
467 var has_directory = false;
468 var has_file = false;
411 var num_sel_notebook = 0;
412 var num_sel_running_notebook = 0;
413 var num_sel_directory = 0;
414 var num_sel_file = 0;
415 var num_notebook = 0;
416 var num_running_notebook = 0;
417 var num_directory = 0;
418 var num_file = 0;
469 419 var that = this;
470 var checked = 0;
471 $('.list_item :checked').each(function(index, item) {
420 $('.list_item input[type=checkbox]').each(function(index, item) {
472 421 var parent = $(item).parent().parent();
473
474 422 // If the item doesn't have an upload button and it's not the
475 423 // breadcrumbs, it can be selected. Breadcrumbs path == ''.
476 424 if (parent.find('.upload_button').length === 0 && parent.data('path') !== '') {
477 checked++;
478 selected.push({
425 if (parent.data('type') == 'notebook') {
426 num_notebook++;
427 if (that.sessions[parent.data('path')] !== undefined) {
428 num_running_notebook++;
429 }
430 } else if (parent.data('type') == 'file') {
431 num_file++;
432 } else if (parent.data('type') == 'directory') {
433 num_directory++;
434 }
435 if ($(item).is(':checked')) {
436 selected.push({
479 437 name: parent.data('name'),
480 438 path: parent.data('path'),
481 439 type: parent.data('type')
482 });
483
484 // Set flags according to what is selected. Flags are later
485 // used to decide which action buttons are visible.
486 has_running_notebook = has_running_notebook ||
487 (parent.data('type') == 'notebook' && that.sessions[parent.data('path')] !== undefined);
488 has_file = has_file || parent.data('type') == 'file';
489 has_directory = has_directory || parent.data('type') == 'directory';
440 });
441 if (parent.data('type') == 'notebook') {
442 num_sel_notebook++;
443 if (that.sessions[parent.data('path')] !== undefined) {
444 num_sel_running_notebook++;
445 }
446 } else if (parent.data('type') == 'file') {
447 num_sel_file++;
448 } else if (parent.data('type') == 'directory') {
449 num_sel_directory++;
450 }
451 }
490 452 }
491 453 });
454
455 // Set flags according to what is selected. Flags are later
456 // used to decide which action buttons are visible.
457 var has_running_notebook = num_sel_running_notebook > 0;
458 var has_directory = num_sel_directory > 0;
459 var has_file = num_sel_file > 0;
492 460 this.selected = selected;
493 461
494 462 // Rename is only visible when one item is selected.
@@ -521,26 +489,23 b' define(['
521 489 }
522 490
523 491 // If all of the items are selected, show the selector as checked. If
524 // some of the items are selected, show it as checked. Otherwise,
492 // some of the items are selected, show it as indeterminate. Otherwise,
525 493 // uncheck it.
526 var total = 0;
527 $('.list_item input[type=checkbox]').each(function(index, item) {
528 var parent = $(item).parent().parent();
529 // If the item doesn't have an upload button and it's not the
530 // breadcrumbs, it can be selected. Breadcrumbs path == ''.
531 if (parent.find('.upload_button').length === 0 && parent.data('path') !== '') {
532 total++;
494 var checkbox_ids = ['select-all','select-folders','select-notebooks','select-running-notebooks','select-files'];
495 var total_nums = [num_file+num_directory+num_notebook, num_directory, num_notebook, num_running_notebook, num_file];
496 var selected_nums = [num_sel_file+num_sel_directory+num_sel_notebook, num_sel_directory, num_sel_notebook, num_sel_running_notebook, num_sel_file];
497
498 for (var i=0; i < 5; i++) {
499 if (selected_nums[i] === 0) {
500 $('#'+checkbox_ids[i])[0].indeterminate = false;
501 $('#'+checkbox_ids[i]).prop('checked', false);
502 } else if (selected_nums[i] === total_nums[i]) {
503 $('#'+checkbox_ids[i])[0].indeterminate = false;
504 $('#'+checkbox_ids[i]).prop('checked', true);
505 } else {
506 $('#'+checkbox_ids[i]).prop('checked', false);
507 $('#'+checkbox_ids[i])[0].indeterminate = true;
533 508 }
534 });
535 if (checked === 0) {
536 $('#tree-selector input[type=checkbox]')[0].indeterminate = false;
537 $('#tree-selector input[type=checkbox]').prop('checked', false);
538 } else if (checked === total) {
539 $('#tree-selector input[type=checkbox]')[0].indeterminate = false;
540 $('#tree-selector input[type=checkbox]').prop('checked', true);
541 } else {
542 $('#tree-selector input[type=checkbox]').prop('checked', false);
543 $('#tree-selector input[type=checkbox]')[0].indeterminate = true;
544 509 }
545 510 };
546 511
@@ -76,19 +76,41 b' data-terminals-available="{{terminals_available}}"'
76 76 </div>
77 77 <div id="notebook_list">
78 78 <div id="notebook_list_header" class="row list_header">
79 <div class="dropdown" id='tree-selector'>
79 <div class="btn-group dropdown" id='tree-selector'>
80 <button type="button" class="btn btn-default btn-xs"><input type="checkbox" class="tree-selector" id="select-all"></input></button>
80 81 <button class="btn btn-default btn-xs dropdown-toggle" type="button" id="tree-selector-btn" data-toggle="dropdown" aria-expanded="true">
81 <input type='checkbox'></input>
82 82 <span class="caret"></span>
83 <span class="sr-only">Toggle Dropdown</span>
83 84 </button>
84 <ul class="dropdown-menu" role="menu" aria-labelledby="tree-selector-btn">
85 <li role="presentation" class="select-all"><a role="menuitem" tabindex="-1" href="#">Select all</a></li>
86 <li role="presentation" class="select-notebooks"><a role="menuitem" tabindex="-1" href="#">Select notebooks</a></li>
87 <li role="presentation" class="select-running-notebooks"><a role="menuitem" tabindex="-1" href="#">Select running notebooks</a></li>
88 <li role="presentation" class="select-files"><a role="menuitem" tabindex="-1" href="#">Select files</a></li>
89 <li role="presentation" class="select-directories"><a role="menuitem" tabindex="-1" href="#">Select directories</a></li>
90 <li role="presentation" class="divider"></li>
91 <li role="presentation" class="deselect-all"><a role="menuitem" tabindex="-1" href="#">Deselect all</a></li>
85 <ul id="tree-selector-menu" class="dropdown-menu" role="menu" aria-labelledby="tree-selector-btn">
86 <li role="presentation">
87 <input type="checkbox" class="tree-selector" id="select-folders"></input>
88 <label for="select-folders">
89 <i class="item_icon folder_icon icon-fixed-width"></i>
90 Folders
91 </label>
92 </li>
93 <li role="presentation">
94 <input type="checkbox" class="tree-selector" id="select-notebooks"></input>
95 <label for="select-notebooks">
96 <i class="item_icon notebook_icon icon-fixed-width"></i>
97 All Notebooks
98 </label>
99 </li>
100 <li role="presentation">
101 <input type="checkbox" class="tree-selector" id="select-running-notebooks"></input>
102 <label for="select-running-notebooks">
103 <i class="item_icon running_notebook_icon icon-fixed-width"></i>
104 Running
105 </label>
106 </li>
107 <li role="presentation">
108 <input type="checkbox" class="tree-selector" id="select-files"></input>
109 <label for="select-files">
110 <i class="item_icon file_icon icon-fixed-width"></i>
111 Files
112 </label>
113 </li>
92 114 </ul>
93 115 </div>
94 116 <div id="project_name">
General Comments 0
You need to be logged in to leave comments. Login now