|
@@
-121,7
+121,8
b' define(['
|
|
121
|
$('.duplicate-button').click($.proxy(this.duplicate_selected, this));
|
|
121
|
$('.duplicate-button').click($.proxy(this.duplicate_selected, this));
|
|
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 checkboxes.
|
|
124
|
// Bind events for selection menu buttons.
|
|
|
|
|
125
|
$('#selector-menu').click(function(event){that.select($(event.target).attr('id'),true)});
|
|
125
|
$('.tree-selector').change(function(){that.select($(this).attr('id'),$(this).is(':checked'))});
|
|
126
|
$('.tree-selector').change(function(){that.select($(this).attr('id'),$(this).is(':checked'))});
|
|
126
|
$('#button-select-all').click(function(e) {
|
|
127
|
$('#button-select-all').click(function(e) {
|
|
127
|
// 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
|
|
@@
-131,24
+132,10
b' define(['
|
|
131
|
that.select('select-all',checkbox.prop('checked'));
|
|
132
|
that.select('select-all',checkbox.prop('checked'));
|
|
132
|
}
|
|
133
|
}
|
|
133
|
});
|
|
134
|
});
|
|
134
|
|
|
|
|
|
135
|
// Make the dropdown sticky
|
|
|
|
|
136
|
// Dirty solution by stopping click propagation
|
|
|
|
|
137
|
// $('#tree-selector-menu').click(function(event){event.stopPropagation();})
|
|
|
|
|
138
|
// Cleaner solution by reimplementing the open-close dynamics (and removing data-toggle="dropdown" in html)
|
|
|
|
|
139
|
$('#tree-selector-btn').on('click', function(event) {
|
|
|
|
|
140
|
$(this).parent().toggleClass('open');
|
|
|
|
|
141
|
});
|
|
|
|
|
142
|
$('body').on('click', function (e) {
|
|
|
|
|
143
|
// Close the menu if a click happens outside of the menu list (and of the tree-selector-btn)
|
|
|
|
|
144
|
if (!$('#tree-selector-btn').is(e.target) && $('#tree-selector-btn').has(e.target).length === 0 && $('#tree-selector-menu').has(e.target).length === 0) {
|
|
|
|
|
145
|
$('#tree-selector-btn').parent().removeClass('open');
|
|
|
|
|
146
|
}
|
|
|
|
|
147
|
});
|
|
|
|
|
148
|
}
|
|
135
|
}
|
|
149
|
};
|
|
136
|
};
|
|
150
|
|
|
137
|
|
|
151
|
NotebookList.prototype.handleFilesUpload = function(event, dropOrForm) {
|
|
138
|
NotebookList.prototype.handleFilesUpload = function(event, dropOrForm) {
|
|
152
|
var that = this;
|
|
139
|
var that = this;
|
|
153
|
var files;
|
|
140
|
var files;
|
|
154
|
if(dropOrForm =='drop'){
|
|
141
|
if(dropOrForm =='drop'){
|
|
@@
-308,7
+295,7
b' define(['
|
|
308
|
}
|
|
295
|
}
|
|
309
|
}
|
|
296
|
}
|
|
310
|
});
|
|
297
|
});
|
|
311
|
this._selection_changed();
|
|
298
|
this._selection_changed();
|
|
312
|
};
|
|
299
|
};
|
|
313
|
|
|
300
|
|
|
314
|
|
|
301
|
|
|
@@
-400,18
+387,18
b' define(['
|
|
400
|
|
|
387
|
|
|
401
|
/**
|
|
388
|
/**
|
|
402
|
* Select all items in the tree of specified type.
|
|
389
|
* Select all items in the tree of specified type.
|
|
403
|
* checkbox_id : 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"
|
|
404
|
* state : boolean, true to select and false to deselect
|
|
391
|
* state : boolean, true to select and false to deselect
|
|
405
|
*/
|
|
392
|
*/
|
|
406
|
NotebookList.prototype.select = function(checkbox_id,state) {
|
|
393
|
NotebookList.prototype.select = function(selection_type,state) {
|
|
407
|
var that = this;
|
|
394
|
var that = this;
|
|
408
|
$('.list_item').each(function(index, item) {
|
|
395
|
$('.list_item').each(function(index, item) {
|
|
409
|
// For each item, determine if the state should be set, depending on the checkbox_id that triggered select
|
|
396
|
// For each item, determine if the state should be set, depending on the selection_type that triggered select
|
|
410
|
var set_state = (checkbox_id === "select-all");
|
|
397
|
var set_state = (selection_type === "select-all");
|
|
411
|
set_state = set_state || (checkbox_id === "select-folders" && $(item).data('type') === 'directory');
|
|
398
|
set_state = set_state || (selection_type === "select-folders" && $(item).data('type') === 'directory');
|
|
412
|
set_state = set_state || (checkbox_id === "select-notebooks" && $(item).data('type') === 'notebook');
|
|
399
|
set_state = set_state || (selection_type === "select-notebooks" && $(item).data('type') === 'notebook');
|
|
413
|
set_state = set_state || (checkbox_id === "select-running-notebooks" && $(item).data('type') === 'notebook' && that.sessions[$(item).data('path')] !== undefined);
|
|
400
|
set_state = set_state || (selection_type === "select-running-notebooks" && $(item).data('type') === 'notebook' && that.sessions[$(item).data('path')] !== undefined);
|
|
414
|
set_state = set_state || (checkbox_id === "select-files" && $(item).data('type') === 'file');
|
|
401
|
set_state = set_state || (selection_type === "select-files" && $(item).data('type') === 'file');
|
|
415
|
if (set_state) {
|
|
402
|
if (set_state) {
|
|
416
|
$(item).find('input[type=checkbox]').prop('checked', state);
|
|
403
|
$(item).find('input[type=checkbox]').prop('checked', state);
|
|
417
|
}
|
|
404
|
}
|
|
@@
-424,61
+411,37
b' define(['
|
|
424
|
* Handles when any row selector checkbox is toggled.
|
|
411
|
* Handles when any row selector checkbox is toggled.
|
|
425
|
*/
|
|
412
|
*/
|
|
426
|
NotebookList.prototype._selection_changed = function() {
|
|
413
|
NotebookList.prototype._selection_changed = function() {
|
|
427
|
// Use a JQuery selector to find each row with a checkbox. If
|
|
414
|
// Use a JQuery selector to find each row with a checked checkbox. If
|
|
428
|
// we decide to add more checkboxes in the future, this code will need
|
|
415
|
// we decide to add more checkboxes in the future, this code will need
|
|
429
|
// to be changed to distinguish which checkbox is the row selector.
|
|
416
|
// to be changed to distinguish which checkbox is the row selector.
|
|
430
|
var selected = [];
|
|
417
|
var selected = [];
|
|
431
|
var num_sel_notebook = 0;
|
|
418
|
var has_running_notebook = false;
|
|
432
|
var num_sel_running_notebook = 0;
|
|
419
|
var has_directory = false;
|
|
433
|
var num_sel_directory = 0;
|
|
420
|
var has_file = false;
|
|
434
|
var num_sel_file = 0;
|
|
|
|
|
435
|
var num_notebook = 0;
|
|
|
|
|
436
|
var num_running_notebook = 0;
|
|
|
|
|
437
|
var num_directory = 0;
|
|
|
|
|
438
|
var num_file = 0;
|
|
|
|
|
439
|
var that = this;
|
|
421
|
var that = this;
|
|
440
|
|
|
422
|
var checked = 0;
|
|
441
|
$('.list_item input[type=checkbox]').each(function(index, item) {
|
|
423
|
$('.list_item :checked').each(function(index, item) {
|
|
442
|
var parent = $(item).parent().parent();
|
|
424
|
var parent = $(item).parent().parent();
|
|
|
|
|
425
|
|
|
443
|
// If the item doesn't have an upload button, isn't the
|
|
426
|
// If the item doesn't have an upload button, isn't the
|
|
444
|
// breadcrumbs and isn't the parent folder '..', then it can be selected.
|
|
427
|
// breadcrumbs and isn't the parent folder '..', then it can be selected.
|
|
445
|
// Breadcrumbs path == ''.
|
|
428
|
// Breadcrumbs path == ''.
|
|
446
|
if (parent.find('.upload_button').length === 0 && parent.data('path') !=='' && parent.data('path') !== utils.url_path_split(that.notebook_path)[0]) {
|
|
429
|
if (parent.find('.upload_button').length === 0 && parent.data('path') !== '' && parent.data('path') !== utils.url_path_split(that.notebook_path)[0]) {
|
|
447
|
if (parent.data('type') == 'notebook') {
|
|
430
|
checked++;
|
|
448
|
num_notebook++;
|
|
431
|
selected.push({
|
|
449
|
if (that.sessions[parent.data('path')] !== undefined) {
|
|
|
|
|
450
|
num_running_notebook++;
|
|
|
|
|
451
|
}
|
|
|
|
|
452
|
} else if (parent.data('type') == 'file') {
|
|
|
|
|
453
|
num_file++;
|
|
|
|
|
454
|
} else if (parent.data('type') == 'directory') {
|
|
|
|
|
455
|
num_directory++;
|
|
|
|
|
456
|
}
|
|
|
|
|
457
|
if ($(item).is(':checked')) {
|
|
|
|
|
458
|
selected.push({
|
|
|
|
|
459
|
name: parent.data('name'),
|
|
432
|
name: parent.data('name'),
|
|
460
|
path: parent.data('path'),
|
|
433
|
path: parent.data('path'),
|
|
461
|
type: parent.data('type')
|
|
434
|
type: parent.data('type')
|
|
462
|
});
|
|
435
|
});
|
|
463
|
if (parent.data('type') == 'notebook') {
|
|
436
|
|
|
464
|
num_sel_notebook++;
|
|
437
|
// Set flags according to what is selected. Flags are later
|
|
465
|
if (that.sessions[parent.data('path')] !== undefined) {
|
|
438
|
// used to decide which action buttons are visible.
|
|
466
|
num_sel_running_notebook++;
|
|
439
|
has_running_notebook = has_running_notebook ||
|
|
467
|
}
|
|
440
|
(parent.data('type') == 'notebook' && that.sessions[parent.data('path')] !== undefined);
|
|
468
|
} else if (parent.data('type') == 'file') {
|
|
441
|
has_file = has_file || parent.data('type') == 'file';
|
|
469
|
num_sel_file++;
|
|
442
|
has_directory = has_directory || parent.data('type') == 'directory';
|
|
470
|
} else if (parent.data('type') == 'directory') {
|
|
|
|
|
471
|
num_sel_directory++;
|
|
|
|
|
472
|
}
|
|
|
|
|
473
|
}
|
|
|
|
|
474
|
}
|
|
443
|
}
|
|
475
|
});
|
|
444
|
});
|
|
476
|
|
|
|
|
|
477
|
// Set flags according to what is selected. Flags are later
|
|
|
|
|
478
|
// used to decide which action buttons are visible.
|
|
|
|
|
479
|
var has_running_notebook = num_sel_running_notebook > 0;
|
|
|
|
|
480
|
var has_directory = num_sel_directory > 0;
|
|
|
|
|
481
|
var has_file = num_sel_file > 0;
|
|
|
|
|
482
|
this.selected = selected;
|
|
445
|
this.selected = selected;
|
|
483
|
|
|
446
|
|
|
484
|
// Rename is only visible when one item is selected.
|
|
447
|
// Rename is only visible when one item is selected.
|
|
@@
-511,45
+474,29
b' define(['
|
|
511
|
}
|
|
474
|
}
|
|
512
|
|
|
475
|
|
|
513
|
// If all of the items are selected, show the selector as checked. If
|
|
476
|
// If all of the items are selected, show the selector as checked. If
|
|
514
|
// some of the items are selected, show it as indeterminate. Otherwise,
|
|
477
|
// some of the items are selected, show it as checked. Otherwise,
|
|
515
|
// uncheck it.
|
|
478
|
// uncheck it.
|
|
516
|
var checkbox_ids = ['select-all','select-folders','select-notebooks','select-running-notebooks','select-files'];
|
|
479
|
var total = 0;
|
|
517
|
var total_nums = [num_file+num_directory+num_notebook, num_directory, num_notebook, num_running_notebook, num_file];
|
|
480
|
$('.list_item input[type=checkbox]').each(function(index, item) {
|
|
518
|
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];
|
|
481
|
var parent = $(item).parent().parent();
|
|
519
|
|
|
482
|
// If the item doesn't have an upload button and it's not the
|
|
520
|
// Disable the main checkbox if the list is empty
|
|
483
|
// breadcrumbs, it can be selected. Breadcrumbs path == ''.
|
|
521
|
$('#'+checkbox_ids[0]).parent().prop('disabled',total_nums[0] === 0);
|
|
484
|
if (parent.find('.upload_button').length === 0 && parent.data('path') !== '' && parent.data('path') !== utils.url_path_split(that.notebook_path)[0]) {
|
|
522
|
for (var i=0; i < 5; i++) {
|
|
485
|
total++;
|
|
523
|
if (i>0) {
|
|
|
|
|
524
|
// Disable each menu item if there is nothing to select
|
|
|
|
|
525
|
$('#'+checkbox_ids[i]).prop('disabled',total_nums[i] === 0);
|
|
|
|
|
526
|
if (total_nums[i] === 0) {
|
|
|
|
|
527
|
$('#'+checkbox_ids[i]).parent().parent().addClass('disabled');
|
|
|
|
|
528
|
} else {
|
|
|
|
|
529
|
$('#'+checkbox_ids[i]).parent().parent().removeClass('disabled');
|
|
|
|
|
530
|
}
|
|
|
|
|
531
|
}
|
|
|
|
|
532
|
// Update counters
|
|
|
|
|
533
|
// Turn empty counter into a ' ' on the main checkbox for correct button height.
|
|
|
|
|
534
|
var empty_counter = i===0 ? ' ' : '';
|
|
|
|
|
535
|
$('#counter-'+checkbox_ids[i]).html(selected_nums[i]===0 ? empty_counter : selected_nums[i]);
|
|
|
|
|
536
|
// Alternative : display selected/total
|
|
|
|
|
537
|
// $('#counter-'+checkbox_ids[i]).html(selected_nums[i]===0 ? empty_counter : selected_nums[i] + '/' + total_nums[i]);
|
|
|
|
|
538
|
|
|
|
|
|
539
|
// Update each checkbox status
|
|
|
|
|
540
|
if (selected_nums[i] === 0) {
|
|
|
|
|
541
|
$('#'+checkbox_ids[i])[0].indeterminate = false;
|
|
|
|
|
542
|
$('#'+checkbox_ids[i]).prop('checked', false);
|
|
|
|
|
543
|
} else {
|
|
|
|
|
544
|
if (selected_nums[i] === total_nums[i]) {
|
|
|
|
|
545
|
$('#'+checkbox_ids[i])[0].indeterminate = false;
|
|
|
|
|
546
|
$('#'+checkbox_ids[i]).prop('checked', true);
|
|
|
|
|
547
|
} else {
|
|
|
|
|
548
|
$('#'+checkbox_ids[i]).prop('checked', false);
|
|
|
|
|
549
|
$('#'+checkbox_ids[i])[0].indeterminate = true;
|
|
|
|
|
550
|
}
|
|
|
|
|
551
|
}
|
|
486
|
}
|
|
|
|
|
487
|
});
|
|
|
|
|
488
|
if (checked === 0) {
|
|
|
|
|
489
|
$('#tree-selector input[type=checkbox]')[0].indeterminate = false;
|
|
|
|
|
490
|
$('#tree-selector input[type=checkbox]').prop('checked', false);
|
|
|
|
|
491
|
} else if (checked === total) {
|
|
|
|
|
492
|
$('#tree-selector input[type=checkbox]')[0].indeterminate = false;
|
|
|
|
|
493
|
$('#tree-selector input[type=checkbox]').prop('checked', true);
|
|
|
|
|
494
|
} else {
|
|
|
|
|
495
|
$('#tree-selector input[type=checkbox]').prop('checked', false);
|
|
|
|
|
496
|
$('#tree-selector input[type=checkbox]')[0].indeterminate = true;
|
|
552
|
}
|
|
497
|
}
|
|
|
|
|
498
|
// Update total counter
|
|
|
|
|
499
|
$('#counter-select-all').html(checked===0 ? ' ' : checked);
|
|
553
|
};
|
|
500
|
};
|
|
554
|
|
|
501
|
|
|
555
|
NotebookList.prototype.add_link = function (model, item) {
|
|
502
|
NotebookList.prototype.add_link = function (model, item) {
|