##// END OF EJS Templates
streamline tree-selector menu using checkboxes...
Mathieu -
Show More
@@ -122,12 +122,9 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 $('#tree-selector .select-all').click($.proxy(this.select_all, this));
125 $('.tree-selector').change(function(){that.select($(this).attr('id'),$(this).is(':checked'))});
126 $('#tree-selector .select-notebooks').click($.proxy(this.select_notebooks, this));
126 // Do not propagate click for the menu to prevent the menu from closing
127 $('#tree-selector .select-running-notebooks').click($.proxy(this.select_running_notebooks, this));
127 $('#tree-selector-menu').click(function(event){event.stopPropagation();})
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));
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() {
386 NotebookList.prototype.select = function(checkbox_id,state) {
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();
412 var that = this;
387 var that = this;
413 $('.list_item').each(function(index, item) {
388 $('.list_item').each(function(index, item) {
414 if ($(item).data('type') === 'notebook' && that.sessions[$(item).data('path')] !== undefined) {
389 // For each item, determine if the state should be set, depending on the checkbox_id that triggered select
415 $(item).find('input[type=checkbox]').prop('checked', true);
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 this._selection_changed();
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 * Handles when any row selector checkbox is toggled.
404 * Handles when any row selector checkbox is toggled.
460 */
405 */
461 NotebookList.prototype._selection_changed = function() {
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 // we decide to add more checkboxes in the future, this code will need
408 // we decide to add more checkboxes in the future, this code will need
464 // to be changed to distinguish which checkbox is the row selector.
409 // to be changed to distinguish which checkbox is the row selector.
465 var selected = [];
410 var selected = [];
466 var has_running_notebook = false;
411 var num_sel_notebook = 0;
467 var has_directory = false;
412 var num_sel_running_notebook = 0;
468 var has_file = false;
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 var that = this;
419 var that = this;
470 var checked = 0;
420 $('.list_item input[type=checkbox]').each(function(index, item) {
471 $('.list_item :checked').each(function(index, item) {
472 var parent = $(item).parent().parent();
421 var parent = $(item).parent().parent();
473
474 // If the item doesn't have an upload button and it's not the
422 // If the item doesn't have an upload button and it's not the
475 // breadcrumbs, it can be selected. Breadcrumbs path == ''.
423 // breadcrumbs, it can be selected. Breadcrumbs path == ''.
476 if (parent.find('.upload_button').length === 0 && parent.data('path') !== '') {
424 if (parent.find('.upload_button').length === 0 && parent.data('path') !== '') {
477 checked++;
425 if (parent.data('type') == 'notebook') {
478 selected.push({
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 name: parent.data('name'),
437 name: parent.data('name'),
480 path: parent.data('path'),
438 path: parent.data('path'),
481 type: parent.data('type')
439 type: parent.data('type')
482 });
440 });
483
441 if (parent.data('type') == 'notebook') {
484 // Set flags according to what is selected. Flags are later
442 num_sel_notebook++;
485 // used to decide which action buttons are visible.
443 if (that.sessions[parent.data('path')] !== undefined) {
486 has_running_notebook = has_running_notebook ||
444 num_sel_running_notebook++;
487 (parent.data('type') == 'notebook' && that.sessions[parent.data('path')] !== undefined);
445 }
488 has_file = has_file || parent.data('type') == 'file';
446 } else if (parent.data('type') == 'file') {
489 has_directory = has_directory || parent.data('type') == 'directory';
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 this.selected = selected;
460 this.selected = selected;
493
461
494 // Rename is only visible when one item is selected.
462 // Rename is only visible when one item is selected.
@@ -521,26 +489,23 b' define(['
521 }
489 }
522
490
523 // If all of the items are selected, show the selector as checked. If
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 // uncheck it.
493 // uncheck it.
526 var total = 0;
494 var checkbox_ids = ['select-all','select-folders','select-notebooks','select-running-notebooks','select-files'];
527 $('.list_item input[type=checkbox]').each(function(index, item) {
495 var total_nums = [num_file+num_directory+num_notebook, num_directory, num_notebook, num_running_notebook, num_file];
528 var parent = $(item).parent().parent();
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];
529 // If the item doesn't have an upload button and it's not the
497
530 // breadcrumbs, it can be selected. Breadcrumbs path == ''.
498 for (var i=0; i < 5; i++) {
531 if (parent.find('.upload_button').length === 0 && parent.data('path') !== '') {
499 if (selected_nums[i] === 0) {
532 total++;
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 </div>
76 </div>
77 <div id="notebook_list">
77 <div id="notebook_list">
78 <div id="notebook_list_header" class="row list_header">
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 <button class="btn btn-default btn-xs dropdown-toggle" type="button" id="tree-selector-btn" data-toggle="dropdown" aria-expanded="true">
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 <span class="caret"></span>
82 <span class="caret"></span>
83 <span class="sr-only">Toggle Dropdown</span>
83 </button>
84 </button>
84 <ul class="dropdown-menu" role="menu" aria-labelledby="tree-selector-btn">
85 <ul id="tree-selector-menu" 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">
86 <li role="presentation" class="select-notebooks"><a role="menuitem" tabindex="-1" href="#">Select notebooks</a></li>
87 <input type="checkbox" class="tree-selector" id="select-folders"></input>
87 <li role="presentation" class="select-running-notebooks"><a role="menuitem" tabindex="-1" href="#">Select running notebooks</a></li>
88 <label for="select-folders">
88 <li role="presentation" class="select-files"><a role="menuitem" tabindex="-1" href="#">Select files</a></li>
89 <i class="item_icon folder_icon icon-fixed-width"></i>
89 <li role="presentation" class="select-directories"><a role="menuitem" tabindex="-1" href="#">Select directories</a></li>
90 Folders
90 <li role="presentation" class="divider"></li>
91 </label>
91 <li role="presentation" class="deselect-all"><a role="menuitem" tabindex="-1" href="#">Deselect all</a></li>
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 </ul>
114 </ul>
93 </div>
115 </div>
94 <div id="project_name">
116 <div id="project_name">
General Comments 0
You need to be logged in to leave comments. Login now