2007-07-19 12:40:05 +02:00
/ * *
* Configuration for the left hand tree
* /
if ( typeof SiteTreeHandlers == 'undefined' ) SiteTreeHandlers = { } ;
SiteTreeHandlers . parentChanged _url = 'admin/assets/ajaxupdateparent' ;
SiteTreeHandlers . orderChanged _url = 'admin/assets/ajaxupdatesort' ;
SiteTreeHandlers . loadPage _url = 'admin/assets/getitem' ;
SiteTreeHandlers . loadTree _url = 'admin/assets/getsubtree' ;
SiteTreeHandlers . showRecord _url = 'admin/assets/show/' ;
2007-09-04 06:12:30 +02:00
SiteTreeHandlers . controller _url = 'admin/assets' ;
2007-07-19 12:40:05 +02:00
var _HANDLER _FORMS = {
2009-11-21 04:15:32 +01:00
addpage : 'Form_AddPageOptionsForm' ,
2009-01-06 03:18:33 +01:00
deletepage : 'Form_DeleteItemsForm' ,
2007-07-19 12:40:05 +02:00
sortitems : 'sortitems_options'
} ;
2009-11-21 04:18:25 +01:00
( function ( $ ) {
/ * *
* Overload the "Create" tab to execute action instead of
* opening the tab content .
* /
$ ( '#TreeActions-create-btn' ) . concrete ( 'ss' , function ( $ ) {
return {
onmatch : function ( ) {
this . bind ( 'click' , function ( e ) {
var form = $ ( 'form#addpage_options' ) ;
jQuery . post (
form . attr ( 'action' ) ,
form . serialize ( ) ,
function ( data ) {
}
) ;
return false ;
} )
2007-09-15 22:47:35 +02:00
}
2009-11-21 04:18:25 +01:00
} ;
} ) ;
} ( jQuery ) ) ;
2007-09-15 22:47:35 +02:00
2007-07-19 12:40:05 +02:00
/ * *
* Add File Action
* /
addfolder = Class . create ( ) ;
addfolder . applyTo ( '#addpage' ) ;
addfolder . prototype = {
initialize : function ( ) {
Observable . applyTo ( $ ( this . id + '_options' ) ) ;
2007-09-15 02:54:13 +02:00
this . getElementsByTagName ( 'button' ) [ 0 ] . onclick = returnFalse ;
2007-07-19 12:40:05 +02:00
$ ( this . id + '_options' ) . onsubmit = this . form _submit ;
} ,
onclick : function ( ) {
statusMessage ( 'Creating new folder...' ) ;
this . form _submit ( ) ;
/ *
if ( treeactions . toggleSelection ( this ) ) {
var selectedNode = $ ( 'sitetree' ) . firstSelected ( ) ;
if ( selectedNode ) {
while ( selectedNode . parentTreeNode && ! selectedNode . hints . defaultChild ) {
$ ( 'sitetree' ) . changeCurrentTo ( selectedNode . parentTreeNode ) ;
selectedNode = selectedNode . parentTreeNode ;
}
}
}
* /
return false ;
} ,
form _submit : function ( ) {
var st = $ ( 'sitetree' ) ;
2009-11-21 04:15:32 +01:00
$ ( 'Form_AddPageOptionsForm' ) . elements . ParentID . value = st . getIdxOf ( st . firstSelected ( ) ) ;
Ajax . SubmitForm ( 'Form_AddPageOptionsForm' , null , {
2007-09-15 22:47:35 +02:00
onSuccess : this . onSuccess ,
2007-07-19 12:40:05 +02:00
onFailure : this . showAddPageError
} ) ;
return false ;
} ,
2007-09-15 22:47:35 +02:00
onSuccess : function ( response ) {
Ajax . Evaluator ( response ) ;
// Make it possible to drop files into the new folder
DropFileItem . applyTo ( '#sitetree li' ) ;
} ,
2007-07-19 12:40:05 +02:00
showAddPageError : function ( response ) {
errorMessage ( 'Error adding folder' , response ) ;
}
}
2009-07-02 00:28:06 +02:00
/ * *
* Look for new files ( FilesystemSync ) action
* /
FilesystemSyncClass = Class . create ( ) ;
FilesystemSyncClass . applyTo ( '#filesystemsync' ) ;
FilesystemSyncClass . prototype = {
initialize : function ( ) {
this . getElementsByTagName ( 'button' ) [ 0 ] . onclick = returnFalse ;
} ,
onclick : function ( ) {
statusMessage ( 'Looking for new files' ) ;
2009-10-21 06:34:41 +02:00
new Ajax . Request ( 'dev/tasks/FilesystemSyncTask' , {
2009-07-02 00:28:06 +02:00
onSuccess : function ( t ) {
2009-10-21 06:34:41 +02:00
statusMessage ( t . responseText , "good" ) ;
2009-07-02 00:28:06 +02:00
} ,
onFailure : function ( t ) {
errorMessage ( "There was an error looking for new files" ) ;
}
} ) ;
return false ;
}
}
2007-07-19 12:40:05 +02:00
/ * *
* Delete folder action
* /
deletefolder = {
button _onclick : function ( ) {
if ( treeactions . toggleSelection ( this ) ) {
deletefolder . o1 = $ ( 'sitetree' ) . observeMethod ( 'SelectionChanged' , deletefolder . treeSelectionChanged ) ;
2009-01-06 03:18:33 +01:00
deletefolder . o2 = $ ( 'Form_DeleteItemsForm' ) . observeMethod ( 'Close' , deletefolder . popupClosed ) ;
2007-07-19 12:40:05 +02:00
2009-11-21 03:37:27 +01:00
jQuery ( '#sitetree' ) . addClass ( 'multiselect' ) ;
2007-07-19 12:40:05 +02:00
deletefolder . selectedNodes = { } ;
var sel = $ ( 'sitetree' ) . firstSelected ( )
if ( sel ) {
var selIdx = $ ( 'sitetree' ) . getIdxOf ( sel ) ;
deletefolder . selectedNodes [ selIdx ] = true ;
sel . removeNodeClass ( 'current' ) ;
sel . addNodeClass ( 'selected' ) ;
}
}
return false ;
} ,
treeSelectionChanged : function ( selectedNode ) {
var idx = $ ( 'sitetree' ) . getIdxOf ( selectedNode ) ;
if ( selectedNode . selected ) {
selectedNode . removeNodeClass ( 'selected' ) ;
selectedNode . selected = false ;
deletefolder . selectedNodes [ idx ] = false ;
} else {
selectedNode . addNodeClass ( 'selected' ) ;
selectedNode . selected = true ;
deletefolder . selectedNodes [ idx ] = true ;
}
return false ;
} ,
popupClosed : function ( ) {
2009-11-21 03:37:27 +01:00
jQuery ( '#sitetree' ) . removeClass ( 'multiselect' ) ;
2007-07-19 12:40:05 +02:00
$ ( 'sitetree' ) . stopObserving ( deletefolder . o1 ) ;
2009-01-06 03:18:33 +01:00
$ ( 'Form_DeleteItemsForm' ) . stopObserving ( deletefolder . o2 ) ;
2007-07-19 12:40:05 +02:00
for ( var idx in deletefolder . selectedNodes ) {
if ( deletefolder . selectedNodes [ idx ] ) {
node = $ ( 'sitetree' ) . getTreeNodeByIdx ( idx ) ;
if ( node ) {
node . removeNodeClass ( 'selected' ) ;
node . selected = false ;
}
}
}
} ,
form _submit : function ( ) {
var csvIDs = "" ;
for ( var idx in deletefolder . selectedNodes ) {
var selectedNode = $ ( 'sitetree' ) . getTreeNodeByIdx ( idx ) ;
var link = selectedNode . getElementsByTagName ( 'a' ) [ 0 ] ;
if ( deletefolder . selectedNodes [ idx ] && ( ! Element . hasClassName ( link , 'contents' ) || confirm ( "'" + link . firstChild . nodeValue + "' contains files. Would you like to delete the files and folder?" ) ) )
csvIDs += ( csvIDs ? "," : "" ) + idx ;
}
if ( csvIDs ) {
2009-01-06 03:18:33 +01:00
$ ( 'Form_DeleteItemsForm' ) . elements . csvIDs . value = csvIDs ;
2007-07-19 12:40:05 +02:00
statusMessage ( 'deleting pages' ) ;
2009-01-06 03:18:33 +01:00
Ajax . SubmitForm ( 'Form_DeleteItemsForm' , null , {
2007-07-19 12:40:05 +02:00
onSuccess : deletefolder . submit _success ,
onFailure : function ( response ) {
errorMessage ( 'Error deleting pages' , response ) ;
}
} ) ;
2007-09-15 03:01:24 +02:00
$ ( 'deletepage' ) . getElementsByTagName ( 'button' ) [ 0 ] . onclick ( ) ;
2007-07-19 12:40:05 +02:00
} else {
alert ( "Please select at least 1 page." ) ;
}
return false ;
} ,
submit _success : function ( response ) {
Ajax . Evaluator ( response ) ;
treeactions . closeSelection ( $ ( 'deletepage' ) ) ;
}
}
Behaviour . register ( {
'#Form_EditForm_Files' : {
removeFile : function ( fileID ) {
var record ;
if ( record = $ ( 'record-' + fileID ) ) {
record . parentNode . removeChild ( record ) ;
}
}
} ,
'#Form_EditForm_Files a.deletelink' : {
onclick : function ( event ) {
2009-11-21 03:35:54 +01:00
// Send request
new Ajax . Request ( this . href + ( this . href . indexOf ( "?" ) == - 1 ? "?" : "&" ) + "ajax=1" , {
method : 'get' ,
onSuccess : Ajax . Evaluator ,
2009-11-21 04:16:21 +01:00
onFailure : function ( response ) { errorMessage ( 'Server Error' , response ) ; }
2009-11-21 03:35:54 +01:00
} ) ;
2007-07-19 12:40:05 +02:00
Event . stop ( event ) ;
return false ;
}
} ,
'#Form_EditForm' : {
changeDetection _fieldsToIgnore : {
'Files[]' : true
}
}
} ) ;
/ * *
* We don ' t want hitting the enter key in the name field
* to submit the form .
* /
Behaviour . register ( {
'#Form_EditForm_Name' : {
onkeypress : function ( event ) {
event = ( event ) ? event : window . event ;
var kc = event . keyCode ? event . keyCode : event . charCode ;
if ( kc == 13 ) {
return false ;
}
}
}
} ) ;
/ * *
* Initialisation function to set everything up
* /
2009-11-21 03:37:27 +01:00
jQuery ( document ) . ready ( function ( ) {
2007-07-19 12:40:05 +02:00
// Set up delete page
2009-01-06 03:18:33 +01:00
Observable . applyTo ( $ ( 'Form_DeleteItemsForm' ) ) ;
2007-07-19 12:40:05 +02:00
if ( $ ( 'deletepage' ) ) {
$ ( 'deletepage' ) . onclick = deletefolder . button _onclick ;
2007-09-15 03:01:24 +02:00
$ ( 'deletepage' ) . getElementsByTagName ( 'button' ) [ 0 ] . onclick = function ( ) { return false ; } ;
2009-01-06 03:18:33 +01:00
$ ( 'Form_DeleteItemsForm' ) . onsubmit = deletefolder . form _submit ;
Element . hide ( 'Form_DeleteItemsForm' ) ;
2007-07-19 12:40:05 +02:00
}
2008-04-26 08:40:29 +02:00
new CheckBoxRange ( $ ( 'Form_EditForm' ) , 'Files[]' ) ;
2009-11-21 04:18:08 +01:00
} ) ;