2011-07-29 18:37:11 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
2011-11-05 17:04:10 +00:00
'use strict' ;
2011-05-25 19:42:45 +00:00
pandora . ui . folders = function ( ) {
2011-10-29 16:57:51 +00:00
var ui = pandora . user . ui ,
2011-11-06 18:36:22 +00:00
counter = 0 ,
2011-10-29 16:57:51 +00:00
that = Ox . Element ( )
. css ( { overflowX : 'hidden' , overflowY : 'auto' } )
. bindEvent ( {
2012-05-26 15:46:24 +00:00
resize : pandora . resizeFolders
2013-02-16 01:20:40 +00:00
} ) ,
folderItems = ui . section == 'items' ? 'Lists' : Ox . toTitleCase ( ui . section ) ,
folderItem = folderItems . slice ( 0 , - 1 ) ;
2011-05-25 19:42:45 +00:00
//var $sections = [];
2011-11-06 18:36:22 +00:00
pandora . $ui . allItems = pandora . ui . allItems ( ) . appendTo ( that ) ;
2011-06-06 15:48:11 +00:00
pandora . $ui . folder = [ ] ;
pandora . $ui . folderBrowser = { } ;
pandora . $ui . folderList = { } ;
2011-09-01 07:00:35 +00:00
pandora . $ui . findListElement = { } ;
pandora . $ui . findListSelect = { } ;
pandora . $ui . findListInput = { } ;
2011-09-04 16:08:28 +00:00
pandora . $ui . manageListsButton = { } ;
2013-02-16 01:20:40 +00:00
pandora . site . sectionFolders [ ui . section ] . forEach ( function ( folder , i ) {
var extras , $select ;
if ( folder . id == 'personal' ) {
if ( pandora . user . level == 'guest' ) {
extras = [
infoButton ( 'Personal ' + folderItems , 'To create and share your own ' + ( ui . section == 'items'
? 'lists of ' + pandora . site . itemName . plural . toLowerCase ( )
: ui . section ) + ', please sign up or sign in.' )
] ;
} else {
if ( ui . section == 'items' ) {
2011-10-29 16:57:51 +00:00
extras = [
2012-04-19 09:04:25 +00:00
pandora . $ui . personalListsMenu = Ox . MenuButton ( {
2011-10-29 16:57:51 +00:00
items : [
{ id : 'newlist' , title : 'New List' } ,
2012-04-19 09:04:25 +00:00
{ id : 'newlistfromselection' , title : 'New List from Selection' , disabled : ui . listSelection . length == 0 } ,
2011-10-29 16:57:51 +00:00
{ id : 'newsmartlist' , title : 'New Smart List' } ,
{ id : 'newsmartlistfromresults' , title : 'New Smart List from Results' } ,
{ } ,
{ id : 'duplicatelist' , title : 'Duplicate Selected List' , disabled : ! pandora . user . ui . _list } ,
{ id : 'editlist' , title : 'Edit Selected List...' , disabled : ! pandora . user . ui . _list } ,
{ id : 'deletelist' , title : 'Delete Selected List...' , disabled : ! pandora . user . ui . _list }
] ,
2011-12-22 07:27:48 +00:00
title : 'edit' ,
2011-10-29 16:57:51 +00:00
tooltip : 'Manage Personal Lists' ,
type : 'image'
} )
. bindEvent ( {
click : function ( data ) {
var $list = pandora . $ui . folderList [ folder . id ] ;
// fixme: duplicated
if ( [
'newlist' , 'newlistfromselection' , 'newsmartlist' , 'newsmartlistfromresults'
] . indexOf ( data . id ) > - 1 ) {
pandora . addList ( data . id . indexOf ( 'smart' ) > - 1 , data . id . indexOf ( 'from' ) > - 1 ) ;
} else if ( data . id == 'duplicatelist' ) {
pandora . addList ( pandora . user . ui . _list ) ;
} else if ( data . id == 'editlist' ) {
pandora . ui . listDialog ( ) . open ( ) ;
} else if ( data . id == 'deletelist' ) {
pandora . ui . deleteListDialog ( ) . open ( ) ;
}
} ,
pandora _find : function ( ) {
var action = ui . _list
&& pandora . getListData ( ui . _list ) . user == pandora . user . username
? 'enableItem' : 'disableItem' ;
2012-04-19 09:04:25 +00:00
// fixme: duplicated
pandora . $ui . personalListsMenu [ action ] ( 'editlist' ) ;
pandora . $ui . personalListsMenu [ action ] ( 'duplicatelist' ) ;
pandora . $ui . personalListsMenu [ action ] ( 'deletelist' ) ;
pandora . $ui . personalListsMenu [
ui . listSelection . length ? 'enableItem' : 'disableItem'
] ( 'newlistfromselection' ) ;
2011-10-29 16:57:51 +00:00
} ,
pandora _listselection : function ( data ) {
2012-04-19 09:04:25 +00:00
pandora . $ui . personalListsMenu [
data . value . length ? 'enableItem' : 'disableItem'
] ( 'newlistfromselection' ) ;
2011-09-01 04:46:44 +00:00
}
2011-10-29 16:57:51 +00:00
} )
] ;
2013-02-20 11:29:29 +00:00
} else if ( ui . section == 'texts' ) {
2013-02-16 01:20:40 +00:00
extras = [
pandora . $ui . personalListsMenu = Ox . MenuButton ( {
items : [
2013-02-20 11:29:29 +00:00
{ id : 'newtext' , title : 'New Text' } ,
{ id : 'newpdf' , title : 'New PDF' } ,
2013-02-16 01:20:40 +00:00
{ } ,
2013-02-20 11:29:29 +00:00
{ id : 'deletetext' , title : 'Delete Selected Text...' , disabled : ! ui . text }
2013-02-16 01:20:40 +00:00
] ,
title : 'edit' ,
2013-02-20 11:29:29 +00:00
tooltip : 'Manage Personal Texts' ,
2013-02-16 01:20:40 +00:00
type : 'image'
} )
. bindEvent ( {
click : function ( data ) {
var $list = pandora . $ui . folderList [ folder . id ] ;
2013-02-20 11:29:29 +00:00
if ( data . id == 'newtext' ) {
pandora . addText ( { type : 'text' } ) ;
} else if ( data . id == 'newpdf' ) {
pandora . addText ( { type : 'pdf' } ) ;
} else if ( data . id == 'deletetext' ) {
2013-02-16 01:20:40 +00:00
pandora . ui . deleteListDialog ( ) . open ( ) ;
2011-09-04 16:08:28 +00:00
}
2011-09-01 04:46:44 +00:00
}
2013-02-16 01:20:40 +00:00
} )
2013-02-20 11:29:29 +00:00
. bindEvent ( 'pandora_text' , function ( data ) {
2013-02-16 01:20:40 +00:00
pandora . $ui . personalListsMenu [
data . value && data . value . length ? 'enableItem' : 'disableItem'
2013-02-20 11:29:29 +00:00
] ( 'deletetext' ) ;
2013-02-16 01:20:40 +00:00
} )
] ;
2013-02-20 11:29:29 +00:00
} else {
extras = [ ] ;
2011-09-01 04:46:44 +00:00
}
2013-02-16 01:20:40 +00:00
}
} else if ( folder . id == 'favorite' ) {
if ( pandora . user . level == 'guest' ) {
extras = [ infoButton ( 'Favorite ' + folderItems ,
'To browse and subscribe to shared ' + folderItems . toLowerCase ( ) + ' from other users, please sign up or sign in.' ) ] ;
} else {
extras = [ pandora . $ui . manageListsButton [ 'favorite' ] = Ox . Button ( {
selectable : true ,
style : 'symbol' ,
title : 'Edit' ,
tooltip : 'Manage Favorite ' + folderItems ,
type : 'image'
} )
. bindEvent ( {
change : function ( data ) {
var listData ;
Ox . Request . clearCache ( ) ; // fixme: remove
pandora . site . sectionFolders [ ui . section ] [ i ] . showBrowser = ! pandora . site . sectionFolders [ ui . section ] [ i ] . showBrowser ;
2013-03-03 07:38:10 +00:00
this . options ( { tooltip : data . value ? 'Done' : 'Manage Favorite ' + folderItems } ) ;
2013-02-16 01:20:40 +00:00
if ( pandora . site . sectionFolders [ ui . section ] [ i ] . showBrowser ) {
pandora . $ui . folderList . favorite . replaceWith (
pandora . $ui . folderBrowser . favorite = pandora . ui . folderBrowser ( 'favorite' )
) ;
} else {
listData = pandora . getListData ( ) ;
if (
pandora . $ui . folderList . favorite . options ( 'selected' ) . length
&& ! listData . subscribed
) {
// the selected list in the favorites browser is not in the favorites folder
pandora . $ui . folderList . favorite . options ( { selected : [ ] } ) ;
if ( Ox . getObjectById ( pandora . site . sectionFolders [ ui . section ] , 'featured' ) . showBrowser ) {
// but in the featured browser
pandora . $ui . folderList . featured . options ( { selected : [ listData . id ] } ) ;
} else {
// and nowhere else
pandora . UI . set ( {
find : pandora . site . user . ui . find
} ) ;
2011-09-04 16:08:28 +00:00
}
2011-09-01 04:46:44 +00:00
}
2013-02-16 01:20:40 +00:00
pandora . $ui . folderBrowser . favorite . replaceWith (
pandora . $ui . folderList . favorite = pandora . ui . folderList ( 'favorite' )
) ;
2011-05-25 19:42:45 +00:00
}
2013-02-16 01:20:40 +00:00
pandora . resizeFolders ( ) ;
}
} ) ] ;
2011-05-25 19:42:45 +00:00
}
2013-02-16 01:20:40 +00:00
} else if ( folder . id == 'featured' ) {
if ( pandora . user . level != 'admin' ) {
extras = [ infoButton ( 'Featured ' + folderItems , 'Featured ' + folderItems . toLowerCase ( ) + ' are selected public ' + folderItems . toLowerCase ( ) + ', picked by the ' + pandora . site . site . name + ' staff.' ) ] ;
} else {
extras = [ pandora . $ui . manageListsButton [ 'featured' ] = Ox . Button ( {
selectable : true ,
style : 'symbol' ,
title : 'Edit' ,
tooltip : 'Manage Featured ' + folderItems ,
type : 'image'
2011-05-25 19:42:45 +00:00
} )
. bindEvent ( {
2013-02-16 01:20:40 +00:00
change : function ( data ) {
var listData ;
Ox . Request . clearCache ( ) ; // fixme: remove
pandora . site . sectionFolders [ ui . section ] [ i ] . showBrowser = ! pandora . site . sectionFolders [ ui . section ] [ i ] . showBrowser ;
2013-03-03 07:38:10 +00:00
this . options ( { tooltip : data . value ? 'Done' : 'Manage Favorite ' + folderItems } ) ;
2013-02-16 01:20:40 +00:00
if ( pandora . site . sectionFolders [ ui . section ] [ i ] . showBrowser ) {
pandora . $ui . folderList . featured . replaceWith (
pandora . $ui . folderBrowser . featured = pandora . ui . folderBrowser ( 'featured' )
) ;
} else {
listData = pandora . getListData ( ) ;
Ox . Log ( '' , 'FEATURED' , listData )
if (
pandora . $ui . folderList . featured . options ( 'selected' ) . length
&& listData . status != 'featured'
) {
// the selected list in the featured browser is not in the featured folder
pandora . $ui . folderList . featured . options ( { selected : [ ] } ) ;
if ( listData . user == pandora . user . username ) {
// but in the personal folder
pandora . $ui . folderList . personal . options ( { selected : [ listData . id ] } ) ;
} else if (
listData . subscribed
|| Ox . getObjectById ( pandora . site . sectionFolders [ ui . section ] , 'favorite' ) . showBrowser
) {
// but in the favorites folder or browser
pandora . $ui . folderList . favorite . options ( { selected : [ listData . id ] } ) ;
} else {
// and nowhere else
pandora . UI . set ( {
find : pandora . site . user . ui . find
} ) ;
}
}
pandora . $ui . folderBrowser . featured . replaceWith (
pandora . $ui . folderList . featured = pandora . ui . folderList ( 'featured' )
) ;
2011-05-25 19:42:45 +00:00
}
pandora . resizeFolders ( ) ;
}
2013-02-16 01:20:40 +00:00
} ) ] ;
}
} else if ( folder . id == 'volumes' ) {
if ( pandora . user . level == 'guest' ) {
extras = [ infoButton ( 'Local Volumes' , 'To import movies from a local disk, please sign up or sign in.' ) ] ;
} else {
extras = [ Ox . MenuButton ( {
items : [
{ id : 'add' , title : 'Add Volume...' , disabled : true } ,
{ id : 'scan' , title : 'Scan Selected Volume...' , disabled : true } ,
{ id : 'remove' , title : 'Remove Selected Volume...' , disabled : true } ,
{ } ,
{ id : 'import' , title : 'Import Movies...' , disabled : true }
] ,
title : 'edit' ,
tooltip : 'Manage Volumes' ,
type : 'image'
} )
2012-02-15 16:28:58 +00:00
. bindEvent ( {
2013-02-16 01:20:40 +00:00
click : function ( data ) {
2012-02-15 16:28:58 +00:00
}
2013-02-16 01:20:40 +00:00
} ) ] ;
}
}
pandora . $ui . folder [ i ] = Ox . CollapsePanel ( {
id : folder . id ,
collapsed : ! ui . showFolder . items [ folder . id ] ,
extras : extras ,
size : 16 ,
title : folder . title
} )
. bindEvent ( {
// fixme: duplicated
click : function ( data ) {
var $list = pandora . $ui . folderList [ i ] ,
hasFocus , id ;
if ( data . id == 'new' || data . id == 'newsmart' ) {
pandora . api . addList ( {
name : 'Untitled' ,
status : 'private' ,
type : data . id == 'new' ? 'static' : 'smart'
} , function ( result ) {
id = result . data . id ;
pandora . URL . set ( '?find=list:' + id )
Ox . Request . clearCache ( ) ; // fixme: remove
$list . reloadList ( ) . bindEventOnce ( {
load : function ( data ) {
$list . gainFocus ( )
. options ( { selected : [ id ] } )
. editCell ( id , 'name' ) ;
}
2011-05-25 19:42:45 +00:00
} ) ;
2013-02-16 01:20:40 +00:00
} ) ;
} else if ( data . id == 'browse' ) {
// alert('??')
/ *
pandora . $ui . sectionList [ 1 ] . replaceWith ( pandora . $ui . publicLists = pandora . ui . publicLists ( ) ) ;
pandora . site . showAllPublicLists = true ;
* /
2011-05-25 19:42:45 +00:00
}
2013-02-16 01:20:40 +00:00
} ,
toggle : function ( data ) {
data . collapsed && pandora . $ui . folderList [ folder . id ] . loseFocus ( ) ;
pandora . UI . set ( 'showFolder.items.' + folder . id , ! data . collapsed ) ;
pandora . resizeFolders ( ) ;
}
} ) ;
//$sections.push(pandora.$ui.section[i]);
pandora . $ui . folderList [ folder . id ] = pandora . ui . folderList ( folder . id )
. bindEvent ( {
selectafter : function ( ) {
// ...
} ,
selectbefore : function ( ) {
// ...
}
} )
. bindEventOnce ( {
init : function ( data ) {
if ( ++ counter == pandora . site . sectionFolders [ ui . section ] . length ) {
pandora . $ui . folder . forEach ( function ( $folder ) {
that . append ( $folder ) ;
} ) ;
pandora . resizeFolders ( ) ;
pandora . selectList ( ) ;
}
}
} )
. appendTo ( pandora . $ui . folder [ i ] . $content ) ;
} ) ;
2011-09-01 04:46:44 +00:00
function infoButton ( title , text ) {
return Ox . Button ( {
style : 'symbol' ,
title : 'info' ,
type : 'image'
} ) . bindEvent ( {
click : function ( ) {
2013-03-03 05:34:44 +00:00
var $dialog = pandora . ui . iconDialog ( {
2011-11-06 22:03:24 +00:00
buttons : title != 'Featured Lists' ? [
Ox . Button ( { title : 'Sign Up...' } ) . bindEvent ( {
click : function ( ) {
$dialog . close ( ) ;
pandora . $ui . accountDialog = pandora . ui . accountDialog ( 'signup' ) . open ( ) ;
}
} ) ,
Ox . Button ( { title : 'Sign In...' } ) . bindEvent ( {
click : function ( ) {
$dialog . close ( ) ;
pandora . $ui . accountDialog = pandora . ui . accountDialog ( 'signin' ) . open ( ) ;
}
} ) ,
{ } ,
Ox . Button ( { title : 'Not Now' } ) . bindEvent ( {
click : function ( ) {
$dialog . close ( ) ;
}
} )
] : [
Ox . Button ( { title : 'Close' } ) . bindEvent ( {
click : function ( ) {
$dialog . close ( ) ;
}
} )
] ,
2013-03-03 05:34:44 +00:00
text : text ,
2011-09-01 04:46:44 +00:00
title : title
} ) . open ( ) ;
}
} ) ;
}
2011-10-30 16:49:29 +00:00
that . bindEvent ( {
pandora _find : function ( ) {
2011-11-07 12:12:13 +00:00
var folder = pandora . getListData ( ) . folder ,
list = pandora . user . ui . _list ,
previousList = pandora . UI . getPrevious ( ) . _list ;
if ( list != previousList ) {
Ox . forEach ( pandora . $ui . folderList , function ( $list , id ) {
id != folder && $list . options ( 'selected' , [ ] ) ;
} ) ;
folder && pandora . $ui . folderList [ folder ] . options ( { selected : [ list ] } ) ;
}
/ *
2011-10-30 16:49:29 +00:00
if ( ! pandora . user . ui . _list && previousUI . _list ) {
2011-11-07 12:12:13 +00:00
pandora . $ui . folderList [ pandora . getListData ( previous ) ]
2011-10-30 16:49:29 +00:00
Ox . forEach ( pandora . $ui . folderList , function ( $list ) {
$list . options ( { selected : [ ] } ) ;
} ) ;
}
2011-11-07 12:12:13 +00:00
* /
2013-02-16 01:20:40 +00:00
} ,
pandora _text : function ( ) {
if ( ! pandora . user . ui . text ) {
Ox . forEach ( pandora . $ui . folderList , function ( $list , id ) {
$list . options ( 'selected' , [ ] ) ;
} ) ;
}
2011-10-30 16:49:29 +00:00
}
} )
2011-05-25 19:42:45 +00:00
return that ;
} ;