2017-05-08 05:30:24 +02:00
( function ( $ ) {
2012-08-06 08:14:45 +02:00
"use strict" ;
2012-07-31 08:16:54 +02:00
2017-05-08 05:30:24 +02:00
$ . entwine ( 'ss' , function ( $ ) {
2012-07-31 08:16:54 +02:00
2012-08-03 02:18:55 +02:00
$ ( '#DocumentTypeID ul li' ) . entwine ( {
2017-05-01 05:54:48 +02:00
onadd : function ( ) {
2012-08-06 07:33:52 +02:00
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' ) ;
2017-05-01 05:54:48 +02:00
if ( this . find ( 'input' ) . is ( ':checked' ) ) {
this . addClass ( 'selected' ) ;
}
2012-08-22 05:34:11 +02:00
} ,
2017-05-08 05:30:24 +02:00
onclick : function ( e ) {
2012-08-22 05:34:11 +02:00
$ ( '#DocumentTypeID' ) . find ( 'li.selected' ) . removeClass ( 'selected' ) ;
this . find ( 'input' ) . prop ( "checked" , true ) ;
this . addClass ( 'selected' ) ;
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-22 05:34:11 +02:00
/ * $ ( ' # D o c u m e n t T y p e I D i n p u t [ t y p e = r a d i o ] ' ) . e n t w i n e ( {
2012-08-06 07:33:52 +02:00
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-22 05:34:11 +02:00
} ) ; * /
2017-05-18 02:47:22 +02:00
$ ( '.permissions input[name="CanViewType"], .permissions input[name="CanEditType"]' ) . entwine ( {
2017-05-08 05:30:24 +02:00
onchange : function ( ) {
2017-05-18 02:47:22 +02:00
if ( ! this . is ( ':checked' ) ) {
return ;
}
var dropDown = this . closest ( '.fieldholder-small' ) . next ( ) ;
if ( this . val ( ) === 'OnlyTheseUsers' ) {
2017-05-08 05:30:24 +02:00
dropDown . removeClass ( 'hide' ) ;
} else {
dropDown . addClass ( 'hide' ) ;
}
} ,
onadd : function ( ) {
2017-05-18 02:47:22 +02:00
this . trigger ( 'change' ) ;
2017-05-08 05:30:24 +02:00
}
} ) ;
2017-05-22 04:06:06 +02:00
$ ( '.dmsdocment-actions ul li' ) . entwine ( {
2017-05-01 05:54:48 +02:00
onclick : function ( e ) {
2013-11-12 08:09:32 +01:00
2012-08-13 06:41:43 +02:00
//add active state to the current button
2017-05-22 04:06:06 +02:00
$ ( '.dmsdocment-actions ul li' ) . removeClass ( 'dms-active' ) ;
2012-08-13 06:41:43 +02:00
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
2017-05-22 04:06:06 +02:00
var panel = $ ( '.dmsdocument-actionspanel:first' ) ;
2016-06-09 07:12:12 +02:00
panel . find ( '> .fieldgroup > .fieldgroup-field' ) . hide ( ) ;
2012-08-13 06:41:43 +02:00
//show the correct group of controls
2013-11-12 08:09:32 +01:00
//panel.find('.'+this.data('panel')).closest('div.fieldgroup').show();
2014-07-10 01:44:13 +02:00
panel . find ( '.' + this . data ( 'panel' ) ) . show ( ) . parents ( '.fieldgroup-field' ) . show ( ) ;
2013-11-12 08:09:32 +01:00
2012-08-13 06:41:43 +02:00
}
} ) ;
2012-08-16 07:01:57 +02:00
$ ( '#Form_ItemEditForm_Embargo input, #Form_EditForm_Embargo input' ) . entwine ( {
2017-05-01 05:54:48 +02:00
onchange : function ( ) {
2012-08-13 08:28:15 +02:00
//selected the date options
2012-08-14 05:05:23 +02:00
if ( this . attr ( 'value' ) === 'Date' ) {
2013-05-09 00:19:30 +02:00
$ ( '.embargoDatetime' ) . children ( ) . show ( ) ;
2012-08-13 08:28:15 +02:00
$ ( '.embargoDatetime' ) . show ( ) ;
} else {
$ ( '.embargoDatetime' ) . hide ( ) ;
}
}
} ) ;
2012-08-16 07:01:57 +02:00
$ ( '#Form_ItemEditForm_Expiry input, #Form_EditForm_Expiry input' ) . entwine ( {
2017-05-01 05:54:48 +02:00
onchange : function ( ) {
2012-08-13 08:28:15 +02:00
//selected the date options
2012-08-14 05:05:23 +02:00
if ( this . attr ( 'value' ) === 'Date' ) {
2013-05-09 00:19:30 +02:00
$ ( '.expiryDatetime' ) . children ( ) . show ( ) ;
2012-08-13 08:28:15 +02:00
$ ( '.expiryDatetime' ) . show ( ) ;
} else {
$ ( '.expiryDatetime' ) . hide ( ) ;
}
}
} ) ;
2017-05-22 04:06:06 +02:00
$ ( '.dmsdocument-actionspanel' ) . entwine ( {
2017-05-01 05:54:48 +02:00
onadd : function ( ) {
2012-08-13 06:41:43 +02:00
//do an initial show of the entire panel
this . show ( ) ;
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' ) ;
2017-05-18 02:47:22 +02:00
2016-06-09 07:12:12 +02:00
// add class and hide
2017-05-22 04:06:06 +02:00
$ ( '.dmsdocument-actionspanel .embargo input.date' ) . closest ( '.fieldholder-small' ) . addClass ( 'embargoDatetime' ) . hide ( ) ;
$ ( '.dmsdocument-actionspanel .expiry input.date' ) . closest ( '.fieldholder-small' ) . addClass ( 'expiryDatetime' ) . hide ( ) ;
2016-06-09 07:12:12 +02:00
// We need to duplicate the above functions to work when Adding documents
// $('#Form_EditForm_EmbargoedUntilDate_date').closest('.fieldholder-small').addClass('embargoDatetime').hide();
// $('#Form_EditForm_ExpireAtDate_date').closest('.fieldholder-small').addClass('expiryDatetime').hide();
2012-08-21 04:48:18 +02:00
//Add placeholder attribute to date and time fields
2017-05-22 04:06:06 +02:00
$ ( '.dmsdocument-actionspanel .embargo input.date' ) . attr ( 'placeholder' , 'dd-mm-yyyy' ) ;
$ ( '.dmsdocument-actionspanel .embargo input.time' ) . attr ( 'placeholder' , 'hh:mm:ss' ) ;
$ ( '.dmsdocument-actionspanel .expiry input.date' ) . attr ( 'placeholder' , 'dd-mm-yyyy' ) ;
$ ( '.dmsdocument-actionspanel .expiry input.time' ) . attr ( 'placeholder' , 'hh:mm:ss' ) ;
2012-08-21 04:48:18 +02:00
// We need to duplicate to work when adding documents
2016-06-09 07:12:12 +02:00
// $('#Form_EditForm_EmbargoedUntilDate_date').attr('placeholder', 'dd-mm-yyyy');
// $('#Form_EditForm_EmbargoedUntilDate_time').attr('placeholder', 'hh:mm:ss');
// $('#Form_EditForm_ExpireAtDate_date').attr('placeholder', 'dd-mm-yyyy');
// $('#Form_EditForm_ExpireAtDate_time').attr('placeholder', 'hh:mm:ss');
2012-08-13 08:28:15 +02:00
2016-06-09 07:12:12 +02:00
//show the embargo 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
2017-05-22 04:06:06 +02:00
$ ( '.dmsdocument-actionspanel .embargo input[type="radio"][checked]' ) . change ( ) ;
$ ( '.dmsdocument-actionspanel .expiry input[type="radio"][checked]' ) . change ( ) ;
2012-08-16 07:01:57 +02:00
//Again we need to duplicate the above function to work when adding documents
2016-06-09 07:12:12 +02:00
// $('#Form_EditForm_Embargo input[checked]').change();
// $('#Form_EditForm_Expiry input[checked]').change();
2012-08-03 02:18:55 +02:00
}
} ) ;
2012-08-06 08:14:45 +02:00
$ ( '#Form_ItemEditForm_action_doDelete' ) . entwine ( {
2017-05-01 05:54:48 +02:00
onclick : function ( e ) {
2012-08-06 08:14:45 +02:00
//work out how many pages are left attached to this document
var form = this . closest ( 'form' ) ;
var pagesCount = form . data ( 'pages-count' ) ;
2012-08-21 07:57:06 +02:00
var relationCount = form . data ( 'relation-count' ) ;
2012-08-06 08:14:45 +02:00
//display an appropriate message
var message = '' ;
2012-08-21 07:57:06 +02:00
if ( pagesCount > 1 || relationCount > 0 ) {
var pages = '' ;
if ( pagesCount > 1 ) {
pages = "\nWarning: doc is attached to a total of " + pagesCount + " pages. " ;
}
var references = '' ;
var referencesWarning = '' ;
if ( relationCount > 0 ) {
var pname = 'pages' ;
referencesWarning = "\n\nBefore deleting: please update the content on the pages where this document is referenced, otherwise the links on those pages will break." ;
if ( relationCount === 1 ) {
pname = 'page' ;
referencesWarning = "\n\nBefore deleting: please update the content on the page where this document is referenced, otherwise the links on that page will break." ;
}
references = "\nWarning: doc is referenced in the text of " + relationCount + " " + pname + "." ;
}
message = "Permanently delete this document and remove it from all pages where it is referenced?\n" + pages + references + "\n\nDeleting it here will permanently delete it from this page and all other pages where it is referenced." + referencesWarning ;
2012-08-06 08:14:45 +02:00
} 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." ;
}
2017-05-01 05:54:48 +02:00
if ( ! confirm ( message ) ) {
2012-08-06 08:14:45 +02:00
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
2017-05-18 02:47:22 +02:00
} ( jQuery ) ) ;