@ -121,7 +121,8 @@ define([
$ ( '.duplicate-button' ) . click ( $ . proxy ( this . duplicate _selected , this ) ) ;
$ ( '.delete-button' ) . click ( $ . proxy ( this . delete _selected , this ) ) ;
// Bind events for selection checkboxes.
// Bind events for selection menu buttons.
$ ( '#selector-menu' ) . click ( function ( event ) { that . select ( $ ( event . target ) . attr ( 'id' ) , true ) } ) ;
$ ( '.tree-selector' ) . change ( function ( ) { that . select ( $ ( this ) . attr ( 'id' ) , $ ( this ) . is ( ':checked' ) ) } ) ;
$ ( '#button-select-all' ) . click ( function ( e ) {
// toggle checkbox if the click doesn't come from the checkbox already
@ -131,24 +132,10 @@ define([
that . select ( 'select-all' , checkbox . prop ( 'checked' ) ) ;
}
} ) ;
// Make the dropdown sticky
// Dirty solution by stopping click propagation
// $('#tree-selector-menu').click(function(event){event.stopPropagation();})
// Cleaner solution by reimplementing the open-close dynamics (and removing data-toggle="dropdown" in html)
$ ( '#tree-selector-btn' ) . on ( 'click' , function ( event ) {
$ ( this ) . parent ( ) . toggleClass ( 'open' ) ;
} ) ;
$ ( 'body' ) . on ( 'click' , function ( e ) {
// Close the menu if a click happens outside of the menu list (and of the tree-selector-btn)
if ( ! $ ( '#tree-selector-btn' ) . is ( e . target ) && $ ( '#tree-selector-btn' ) . has ( e . target ) . length === 0 && $ ( '#tree-selector-menu' ) . has ( e . target ) . length === 0 ) {
$ ( '#tree-selector-btn' ) . parent ( ) . removeClass ( 'open' ) ;
}
} ) ;
}
} ;
NotebookList . prototype . handleFilesUpload = function ( event , dropOrForm ) {
NotebookList . prototype . handleFilesUpload = function ( event , dropOrForm ) {
var that = this ;
var files ;
if ( dropOrForm == 'drop' ) {
@ -308,7 +295,7 @@ define([
}
}
} ) ;
this . _selection _changed ( ) ;
this . _selection _changed ( ) ;
} ;
@ -400,18 +387,18 @@ define([
/ * *
* Select all items in the tree of specified type .
* checkbox_id : string among "select-all, " select - folders ", " select - notebooks ", " select - running - notebooks ", " select - files "
* selection_type : string among "select-all, " select - folders ", " select - notebooks ", " select - running - notebooks ", " select - files "
* state : boolean , true to select and false to deselect
* /
NotebookList . prototype . select = function ( checkbox_id , state ) {
NotebookList . prototype . select = function ( selection_type , state ) {
var that = this ;
$ ( '.list_item' ) . each ( function ( index , item ) {
// For each item, determine if the state should be set, depending on the checkbox_id that triggered select
var set _state = ( checkbox_id === "select-all" ) ;
set _state = set _state || ( checkbox_id === "select-folders" && $ ( item ) . data ( 'type' ) === 'directory' ) ;
set _state = set _state || ( checkbox_id === "select-notebooks" && $ ( item ) . data ( 'type' ) === 'notebook' ) ;
set _state = set _state || ( checkbox_id === "select-running-notebooks" && $ ( item ) . data ( 'type' ) === 'notebook' && that . sessions [ $ ( item ) . data ( 'path' ) ] !== undefined ) ;
set _state = set _state || ( checkbox_id === "select-files" && $ ( item ) . data ( 'type' ) === 'file' ) ;
// For each item, determine if the state should be set, depending on the selection_type that triggered select
var set _state = ( selection_type === "select-all" ) ;
set _state = set _state || ( selection_type === "select-folders" && $ ( item ) . data ( 'type' ) === 'directory' ) ;
set _state = set _state || ( selection_type === "select-notebooks" && $ ( item ) . data ( 'type' ) === 'notebook' ) ;
set _state = set _state || ( selection_type === "select-running-notebooks" && $ ( item ) . data ( 'type' ) === 'notebook' && that . sessions [ $ ( item ) . data ( 'path' ) ] !== undefined ) ;
set _state = set _state || ( selection_type === "select-files" && $ ( item ) . data ( 'type' ) === 'file' ) ;
if ( set _state ) {
$ ( item ) . find ( 'input[type=checkbox]' ) . prop ( 'checked' , state ) ;
}
@ -424,61 +411,37 @@ define([
* Handles when any row selector checkbox is toggled .
* /
NotebookList . prototype . _selection _changed = function ( ) {
// Use a JQuery selector to find each row with a check box. If
// Use a JQuery selector to find each row with a check ed check box. If
// we decide to add more checkboxes in the future, this code will need
// to be changed to distinguish which checkbox is the row selector.
var selected = [ ] ;
var num _sel _notebook = 0 ;
var num _sel _running _notebook = 0 ;
var num _sel _directory = 0 ;
var num _sel _file = 0 ;
var num _notebook = 0 ;
var num _running _notebook = 0 ;
var num _directory = 0 ;
var num _file = 0 ;
var has _running _notebook = false ;
var has _directory = false ;
var has _file = false ;
var that = this ;
$ ( '.list_item input[type=checkbox] ') . each ( function ( index , item ) {
var checked = 0 ;
$ ( '.list_item :checked' ) . each ( function ( index , item ) {
var parent = $ ( item ) . parent ( ) . parent ( ) ;
// If the item doesn't have an upload button, isn't the
// breadcrumbs and isn't the parent folder '..', then it can be selected.
// Breadcrumbs path == ''.
if ( parent . find ( '.upload_button' ) . length === 0 && parent . data ( 'path' ) !== '' && parent . data ( 'path' ) !== utils . url _path _split ( that . notebook _path ) [ 0 ] ) {
if ( parent . data ( 'type' ) == 'notebook' ) {
num _notebook ++ ;
if ( that . sessions [ parent . data ( 'path' ) ] !== undefined ) {
num _running _notebook ++ ;
}
} else if ( parent . data ( 'type' ) == 'file' ) {
num _file ++ ;
} else if ( parent . data ( 'type' ) == 'directory' ) {
num _directory ++ ;
}
if ( $ ( item ) . is ( ':checked' ) ) {
selected . push ( {
if ( parent . find ( '.upload_button' ) . length === 0 && parent . data ( 'path' ) !== '' && parent . data ( 'path' ) !== utils . url _path _split ( that . notebook _path ) [ 0 ] ) {
checked ++ ;
selected . push ( {
name : parent . data ( 'name' ) ,
path : parent . data ( 'path' ) ,
type : parent . data ( 'type' )
} ) ;
if ( parent . data ( 'type' ) == 'notebook' ) {
num _sel _notebook ++ ;
if ( that . sessions [ parent . data ( 'path' ) ] !== undefined ) {
num _sel _running _notebook ++ ;
}
} else if ( parent . data ( 'type' ) == 'file' ) {
num _sel _file ++ ;
} else if ( parent . data ( 'type' ) == 'directory' ) {
num _sel _directory ++ ;
}
}
} ) ;
// Set flags according to what is selected. Flags are later
// used to decide which action buttons are visible.
has _running _notebook = has _running _notebook ||
( parent . data ( 'type' ) == 'notebook' && that . sessions [ parent . data ( 'path' ) ] !== undefined ) ;
has _file = has _file || parent . data ( 'type' ) == 'file' ;
has _directory = has _directory || parent . data ( 'type' ) == 'directory' ;
}
} ) ;
// Set flags according to what is selected. Flags are later
// used to decide which action buttons are visible.
var has _running _notebook = num _sel _running _notebook > 0 ;
var has _directory = num _sel _directory > 0 ;
var has _file = num _sel _file > 0 ;
this . selected = selected ;
// Rename is only visible when one item is selected.
@ -511,45 +474,29 @@ define([
}
// If all of the items are selected, show the selector as checked. If
// some of the items are selected, show it as indeterminate . Otherwise,
// some of the items are selected, show it as checked . Otherwise,
// uncheck it.
var checkbox _ids = [ 'select-all' , 'select-folders' , 'select-notebooks' , 'select-running-notebooks' , 'select-files' ] ;
var total _nums = [ num _file + num _directory + num _notebook , num _directory , num _notebook , num _running _notebook , num _file ] ;
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 ] ;
// Disable the main checkbox if the list is empty
$ ( '#' + checkbox _ids [ 0 ] ) . parent ( ) . prop ( 'disabled' , total _nums [ 0 ] === 0 ) ;
for ( var i = 0 ; i < 5 ; i ++ ) {
if ( i > 0 ) {
// Disable each menu item if there is nothing to select
$ ( '#' + checkbox _ids [ i ] ) . prop ( 'disabled' , total _nums [ i ] === 0 ) ;
if ( total _nums [ i ] === 0 ) {
$ ( '#' + checkbox _ids [ i ] ) . parent ( ) . parent ( ) . addClass ( 'disabled' ) ;
} else {
$ ( '#' + checkbox _ids [ i ] ) . parent ( ) . parent ( ) . removeClass ( 'disabled' ) ;
}
}
// Update counters
// Turn empty counter into a ' ' on the main checkbox for correct button height.
var empty _counter = i === 0 ? ' ' : '' ;
$ ( '#counter-' + checkbox _ids [ i ] ) . html ( selected _nums [ i ] === 0 ? empty _counter : selected _nums [ i ] ) ;
// Alternative : display selected/total
// $('#counter-'+checkbox_ids[i]).html(selected_nums[i]===0 ? empty_counter : selected_nums[i] + '/' + total_nums[i]);
// Update each checkbox status
if ( selected _nums [ i ] === 0 ) {
$ ( '#' + checkbox _ids [ i ] ) [ 0 ] . indeterminate = false ;
$ ( '#' + checkbox _ids [ i ] ) . prop ( 'checked' , false ) ;
} else {
if ( selected _nums [ i ] === total _nums [ i ] ) {
$ ( '#' + checkbox _ids [ i ] ) [ 0 ] . indeterminate = false ;
$ ( '#' + checkbox _ids [ i ] ) . prop ( 'checked' , true ) ;
} else {
$ ( '#' + checkbox _ids [ i ] ) . prop ( 'checked' , false ) ;
$ ( '#' + checkbox _ids [ i ] ) [ 0 ] . indeterminate = true ;
}
var total = 0 ;
$ ( '.list_item input[type=checkbox]' ) . each ( function ( index , item ) {
var parent = $ ( item ) . parent ( ) . parent ( ) ;
// If the item doesn't have an upload button and it's not the
// breadcrumbs, it can be selected. Breadcrumbs path == ''.
if ( parent . find ( '.upload_button' ) . length === 0 && parent . data ( 'path' ) !== '' && parent . data ( 'path' ) !== utils . url _path _split ( that . notebook _path ) [ 0 ] ) {
total ++ ;
}
} ) ;
if ( checked === 0 ) {
$ ( '#tree-selector input[type=checkbox]' ) [ 0 ] . indeterminate = false ;
$ ( '#tree-selector input[type=checkbox]' ) . prop ( 'checked' , false ) ;
} else if ( checked === total ) {
$ ( '#tree-selector input[type=checkbox]' ) [ 0 ] . indeterminate = false ;
$ ( '#tree-selector input[type=checkbox]' ) . prop ( 'checked' , true ) ;
} else {
$ ( '#tree-selector input[type=checkbox]' ) . prop ( 'checked' , false ) ;
$ ( '#tree-selector input[type=checkbox]' ) [ 0 ] . indeterminate = true ;
}
// Update total counter
$ ( '#counter-select-all' ) . html ( checked === 0 ? ' ' : checked ) ;
} ;
NotebookList . prototype . add _link = function ( model , item ) {