2012-07-31 08:16:54 +02:00
( function ( $ ) {
2012-08-06 08:14:45 +02:00
"use strict" ;
2012-07-31 08:16:54 +02:00
$ . entwine ( 'ss' , function ( $ ) {
2012-08-03 02:18:55 +02:00
$ ( '#DocumentTypeID ul li' ) . entwine ( {
2012-08-06 07:33:52 +02:00
onadd : function ( ) {
this . addClass ( 'ui-button ss-ui-button ui-corner-all ui-state-default ui-widget ui-button-text-only' ) ;
this . parents ( 'ul' ) . removeClass ( 'ui-tabs-nav' ) ;
2012-08-06 08:14:45 +02:00
}
2012-08-06 07:33:52 +02:00
} ) ;
2012-08-03 02:18:55 +02:00
2012-08-06 07:33:52 +02:00
$ ( '#DocumentTypeID input[type=radio]' ) . entwine ( {
onadd : function ( ) {
2012-08-08 02:17:20 +02:00
// Checks to see what radio button is selected
2012-08-06 07:33:52 +02:00
if ( this . is ( ':checked' ) ) {
this . change ( ) ;
2012-08-03 02:18:55 +02:00
}
} ,
2012-08-06 07:33:52 +02:00
onchange : function ( e ) {
2012-08-08 02:17:20 +02:00
// Remove selected class from radio buttons
2012-08-06 07:33:52 +02:00
$ ( '#DocumentTypeID' ) . find ( 'li' ) . removeClass ( 'selected' ) ;
2012-08-08 02:17:20 +02:00
//If radio button is checked then add the selected class
2012-08-06 07:33:52 +02:00
if ( this . is ( ':checked' ) ) {
this . parent ( 'li' ) . addClass ( 'selected' ) ;
}
}
2012-08-03 02:18:55 +02:00
} ) ;
$ ( '#Actions ul li' ) . entwine ( {
onclick : function ( e ) {
2012-08-13 06:41:43 +02:00
//add active state to the current button
$ ( '#Actions ul li' ) . removeClass ( 'dms-active' ) ;
this . addClass ( 'dms-active' ) ;
2012-08-13 07:51:59 +02:00
//$('li.dms-active').append('<span class="arrow"></span>');
2012-08-13 06:41:43 +02:00
//hide all inner field sections
var panel = $ ( '#ActionsPanel' ) ;
panel . find ( 'div.fieldgroup-field' ) . hide ( ) ;
//show the correct group of controls
panel . find ( '.' + this . data ( 'panel' ) ) . closest ( 'div.fieldgroup-field' ) . show ( ) ;
}
} ) ;
2012-08-13 08:28:15 +02:00
$ ( '#Form_ItemEditForm_Embargo input' ) . entwine ( {
onchange : function ( ) {
//selected the date options
2012-08-14 01:35:41 +02:00
if ( this . attr ( 'value' ) === '3' ) {
2012-08-13 08:28:15 +02:00
$ ( '.embargoDatetime' ) . show ( ) ;
} else {
$ ( '.embargoDatetime' ) . hide ( ) ;
}
}
} ) ;
$ ( '#Form_ItemEditForm_Expiry input' ) . entwine ( {
onchange : function ( ) {
//selected the date options
2012-08-14 01:35:41 +02:00
if ( this . attr ( 'value' ) === '1' ) {
2012-08-13 08:28:15 +02:00
$ ( '.expiryDatetime' ) . show ( ) ;
} else {
$ ( '.expiryDatetime' ) . hide ( ) ;
}
}
} ) ;
2012-08-13 06:41:43 +02:00
$ ( '#ActionsPanel' ) . entwine ( {
onadd : function ( ) {
//do an initial show of the entire panel
this . show ( ) ;
//move the delete button into the panel
$ ( '#Actions ul' ) . append ( '<li class="delete-button-appended"></li>' ) ;
$ ( '.delete-button-appended' ) . append ( $ ( '#Form_ItemEditForm_action_doDelete' ) ) ;
2012-08-13 08:28:15 +02:00
//add some extra classes to the replace field containers to make it work with drag and drop uploading
this . find ( '.replace' ) . closest ( 'div.fieldgroup-field' ) . addClass ( 'ss-upload' ) . addClass ( 'ss-uploadfield' ) ;
$ ( '#Form_ItemEditForm_EmbargoedUntilDate-date' ) . closest ( '.fieldholder-small' ) . addClass ( 'embargoDatetime' ) . hide ( ) ;
$ ( '#Form_ItemEditForm_ExpireAtDate-date' ) . closest ( '.fieldholder-small' ) . addClass ( 'expiryDatetime' ) . hide ( ) ;
2012-08-13 06:41:43 +02:00
//show the replace panel when the page loads
2012-08-13 08:28:15 +02:00
$ ( 'li[data-panel="embargo"]' ) . click ( ) ;
2012-08-14 01:44:12 +02:00
//set the initial state of the radio button and the associated dropdown hiding
$ ( '#Form_ItemEditForm_Embargo input' ) . change ( ) ;
$ ( '#Form_ItemEditForm_Expiry input' ) . change ( ) ;
2012-08-03 02:18:55 +02:00
}
} ) ;
2012-08-06 08:14:45 +02:00
$ ( '#Form_ItemEditForm_action_doDelete' ) . entwine ( {
onclick : function ( e ) {
//work out how many pages are left attached to this document
var form = this . closest ( 'form' ) ;
var pagesCount = form . data ( 'pages-count' ) ;
//display an appropriate message
var message = '' ;
if ( pagesCount > 1 ) {
message = "Permanently delete this document and remove it from all pages where it is referenced?\n\nWarning: this document is attached to a total of " + pagesCount + " pages. Deleting it here will permanently delete it from this page and all other pages where it is referenced." ;
} else {
message = "Permanently delete this document and remove it from this page?\n\nNotice: this document is only attached to this page, so deleting it won't affect any other pages." ;
}
if ( ! confirm ( message ) ) {
e . preventDefault ( ) ;
return false ;
} else {
//user says "okay", so go ahead and do the action
this . _super ( e ) ;
}
}
} ) ;
2012-07-31 08:16:54 +02:00
} ) ;
2012-08-03 02:18:55 +02:00
} ( jQuery ) ) ;