2008-11-04 00:09:49 +01:00
AssetTableField = Class . create ( ) ;
AssetTableField . applyTo ( '#Form_EditForm_Files' ) ;
AssetTableField . prototype = {
initialize : function ( ) {
Behaviour . register ( {
'#Form_EditForm div.FileFilter input' : {
onkeypress : this . prepareSearch . bind ( this )
} ,
'#Form_EditForm' : {
changeDetection _fieldsToIgnore : {
'ctf[start]' : true ,
'ctf[ID]' : true ,
'FileFilterButton' : true ,
'FileFieldName' : true ,
'FileSearch' : true
}
}
} ) ;
2010-01-13 00:50:39 +01:00
var rules = { } ;
// Assume that the delete link uses the deleteRecord method
rules [ '#' + this . id + ' table.data a.deletelink' ] = { onclick : this . deleteRecord . bind ( this ) } ;
Behaviour . register ( 'ComplexTableField_' + this . id , rules ) ;
2008-11-04 00:09:49 +01:00
} ,
// prevent submission of wrong form-button (FileFilterButton)
prepareSearch : function ( e ) {
// IE6 doesnt send an event-object with onkeypress
var event = ( e ) ? e : window . event ;
var keyCode = ( event . keyCode ) ? event . keyCode : event . which ;
if ( keyCode == Event . KEY _RETURN ) {
var el = Event . element ( event ) ;
$ ( 'FileFilterButton' ) . onclick ( event ) ;
Event . stop ( event ) ;
return false ;
}
2010-01-13 00:50:39 +01:00
} ,
// Override deleteRecord function, so that we can give warning if there are
// links to this file. This is mostly a copy paste from TableField.js
deleteRecord : function ( e ) {
var img = Event . element ( e ) ;
var link = Event . findElement ( e , "a" ) ;
var row = Event . findElement ( e , "tr" ) ;
2010-04-29 06:27:04 +02:00
var linkCount = row . getElementsByClassName ( 'linkCount' ) [ 0 ] ;
2010-01-13 00:50:39 +01:00
if ( linkCount ) linkCount = linkCount . innerHTML ;
var confirmMessage = ss . i18n . _t ( 'TABLEFIELD.DELETECONFIRMMESSAGE' , 'Are you sure you want to delete this record?' ) ;
if ( linkCount ) confirmMessage += '\nThere are ' + linkCount + ' page(s) that use this file, please review the list of pages on the Links tab of the file before continuing.' ;
// TODO ajaxErrorHandler and loading-image are dependent on cms, but formfield is in sapphire
var confirmed = confirm ( confirmMessage ) ;
if ( confirmed )
{
img . setAttribute ( "src" , 'cms/images/network-save.gif' ) ; // TODO doesn't work
new Ajax . Request (
link . getAttribute ( "href" ) ,
{
method : 'post' ,
postBody : 'forceajax=1' + ( $ ( 'SecurityID' ) ? '&SecurityID=' + $ ( 'SecurityID' ) . value : '' ) ,
onComplete : function ( ) {
Effect . Fade (
row ,
{
afterFinish : function ( obj ) {
// remove row from DOM
obj . element . parentNode . removeChild ( obj . element ) ;
// recalculate summary if needed (assumes that TableListField.js is present)
// TODO Proper inheritance
if ( this . _summarise ) this . _summarise ( ) ;
// custom callback
if ( this . callback _deleteRecord ) this . callback _deleteRecord ( e ) ;
} . bind ( this )
}
) ;
} . bind ( this ) ,
onFailure : this . ajaxErrorHandler
}
) ;
}
Event . stop ( e ) ;
2008-11-04 00:09:49 +01:00
}
}
FileFilterButton = Class . create ( ) ;
FileFilterButton . applyTo ( '#FileFilterButton' ) ;
FileFilterButton . prototype = {
initialize : function ( ) {
this . inputFields = new Array ( ) ;
var childNodes = this . parentNode . parentNode . getElementsByTagName ( 'input' ) ;
for ( var index = 0 ; index < childNodes . length ; index ++ ) {
if ( childNodes [ index ] . tagName ) {
childNodes [ index ] . resetChanged = function ( ) { return false ; }
childNodes [ index ] . isChanged = function ( ) { return false ; }
this . inputFields . push ( childNodes [ index ] ) ;
}
}
childNodes = this . parentNode . getElementsByTagName ( 'select' ) ;
for ( var index = 0 ; index < childNodes . length ; index ++ ) {
if ( childNodes [ index ] . tagName ) {
childNodes [ index ] . resetChanged = function ( ) { return false ; }
childNodes [ index ] . field _changed = function ( ) { return false ; }
this . inputFields . push ( childNodes [ index ] ) ;
}
}
} ,
isChanged : function ( ) {
return false ;
} ,
onclick : function ( e ) {
if ( ! $ ( 'ctf-ID' ) || ! $ ( 'FileFieldName' ) ) {
return false ;
}
try {
var form = Event . findElement ( e , 'form' ) ;
var fieldName = $ ( 'FileFieldName' ) . value ;
2009-10-21 06:39:50 +02:00
// build url
var updateURL = form . action + '/field/' + fieldName + '?' ;
2008-11-04 00:09:49 +01:00
for ( var index = 0 ; index < this . inputFields . length ; index ++ ) {
if ( this . inputFields [ index ] . tagName ) {
updateURL += '&' + this . inputFields [ index ] . name + '=' + encodeURIComponent ( this . inputFields [ index ] . value ) ;
}
}
updateURL += ( $ ( 'SecurityID' ) ? '&SecurityID=' + $ ( 'SecurityID' ) . value : '' ) ;
2009-10-21 06:39:50 +02:00
// update the field
2010-01-11 02:16:37 +01:00
var field = document . getElementsByClassName ( 'AssetTableField' ) [ 0 ] ;
2009-10-21 06:39:50 +02:00
field . setAttribute ( 'href' , updateURL ) ;
field . refresh ( ) ;
2008-11-04 00:09:49 +01:00
} catch ( er ) {
errorMessage ( 'Error searching' ) ;
}
return false ;
}
2010-01-13 00:50:39 +01:00
}