diff --git a/javascript/DMSDocumentAddExistingField.js b/javascript/DMSDocumentAddExistingField.js index 50761b5..27f0db2 100644 --- a/javascript/DMSDocumentAddExistingField.js +++ b/javascript/DMSDocumentAddExistingField.js @@ -1,131 +1,135 @@ (function ($) { - "use strict"; + "use strict"; - $.entwine('ss', function ($) { - $('.document-add-existing').entwine({ - adddocument: function (document_id) { - var documentSetId = $(this).closest('form').find('input[name="DSID"]').val(); + $.entwine('ss', function ($) { + $('.document-add-existing').entwine({ + adddocument: function (document_id) { + var documentSetId = $(this).closest('form').find('input[name="DSID"]').val(); - jQuery.ajax( - 'admin/pages/adddocument/linkdocument?dsid=' + documentSetId + '&documentID=' + document_id, - { - dataType: 'json', - success: function (data, textstatus) { - var fn = window.tmpl.cache['ss-uploadfield-addtemplate']; - var fnout = fn({ - files: [data], - formatFileSize: function (bytes) { - if (typeof bytes !== 'number') { - return ''; - } - if (bytes >= 1000000000) { - return (bytes / 1000000000).toFixed(2) + ' GB'; - } - if (bytes >= 1000000) { - return (bytes / 1000000).toFixed(2) + ' MB'; - } - return (bytes / 1000).toFixed(2) + ' KB'; - } - }); + jQuery.ajax( + 'admin/pages/adddocument/linkdocument?dsid=' + documentSetId + '&documentID=' + document_id, + { + dataType: 'json', + success: function (data, textstatus) { + var fn = window.tmpl.cache['ss-uploadfield-addtemplate']; + var fnout = fn({ + files: [data], + formatFileSize: function (bytes) { + if (typeof bytes !== 'number') { + return ''; + } + if (bytes >= 1000000000) { + return (bytes / 1000000000).toFixed(2) + ' GB' + } + if (bytes >= 1000000) { + return (bytes / 1000000).toFixed(2) + ' MB'; + } + return (bytes / 1000).toFixed(2) + ' KB'; + } + }); - $('.ss-add-files').append(fnout); - } - } - ); - }, - selectdocument: function (documentID, documentName) { - if (typeof(documentID) !== "undefined") { - //substitute the ID for the full document name, if no name is present - if (typeof(documentName) === "undefined") { - documentName = documentID; - } - $('.ss-add-files').html('
Loading...
'); - doclist.show(); - doclist.load( - 'admin/pages/adddocument/documentlist?pageID=' + $(this).val() - ); + $('.document-add-existing input[name=PageSelector]').entwine({ + onchange: function (event) { + var doclist = $(this).closest('.document-add-existing').find('.document-list'); + doclist.html('Loading...
'); + doclist.show(); + doclist.load( + 'admin/pages/adddocument/documentlist?pageID=' + $(this).val() + ); + } + }); - } - }); + $('.document-add-existing a.add-document').entwine({ + onclick: function (event) { + var document_id = this.data('document-id'); + var dae = this.closest('.document-add-existing'); - $('.document-add-existing a.add-document').entwine({ - onclick: function (event) { - var document_id = this.data('document-id'); - var dae = this.closest('.document-add-existing'); + if (dae.hasClass('link-editor-context')) { + dae.selectdocument(document_id, this.text()); + } else { + dae.adddocument(document_id); + } - if (dae.hasClass('link-editor-context')) { - dae.selectdocument(document_id, this.text()); - } else { - dae.adddocument(document_id); - } + $(this).closest('.document-list').hide(); + $(this).closest('.document-add-existing').find('input.document-autocomplete').prop('disabled', false); - $(this).closest('.document-list').hide(); - $(this).closest('.document-add-existing').find('input.document-autocomplete').prop('disabled', false); + return false; + } + }); - return false; - } - }); + $('body').entwine({ + onclick: function (event) { + $('.document-list:visible') + .hide() + .closest('.document-add-existing') + .find('input.document-autocomplete') + .prop('disabled', false); + } + }); - $('body').entwine({ - onclick: function (event) { - $('.document-list:visible').hide() - .closest('.document-add-existing').find('input.document-autocomplete').prop('disabled', false); - } - }); - - $('.document-add-existing .treedropdownfield-toggle-panel-link').entwine({ - onclick: function (event) { - $('.document-list:visible').hide(); - } - }); - - }); + $('.document-add-existing .treedropdownfield-toggle-panel-link').entwine({ + onclick: function (event) { + $('.document-list:visible').hide(); + } + }); + }); }(jQuery)); diff --git a/javascript/DMSDocumentCMSFields.js b/javascript/DMSDocumentCMSFields.js index 180f3b5..04b3a9d 100644 --- a/javascript/DMSDocumentCMSFields.js +++ b/javascript/DMSDocumentCMSFields.js @@ -1,177 +1,144 @@ (function($) { - "use strict"; + "use strict"; - $.entwine('ss', function($) { + $.entwine('ss', function($) { + $('#DocumentTypeID ul li').entwine({ + 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'); + if (this.find('input').is(':checked')) { + this.addClass('selected'); + } + }, + onclick: function(e) { + $('#DocumentTypeID').find('li.selected').removeClass('selected'); + this.find('input').prop("checked", true); + this.addClass('selected'); + } + }); - $('#DocumentTypeID ul li').entwine({ - 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'); - if (this.find('input').is(':checked')) { - this.addClass('selected'); - } - }, - onclick: function(e) { - $('#DocumentTypeID').find('li.selected').removeClass('selected'); - this.find('input').prop("checked", true); - this.addClass('selected'); - } - }); + $('.permissions input[name="CanViewType"], .permissions input[name="CanEditType"]').entwine({ + onchange: function () { + if (!this.is(':checked')) { + return; + } -/* $('#DocumentTypeID input[type=radio]').entwine({ - onadd: function() { - // Checks to see what radio button is selected - if (this.is(':checked')) { - this.change(); - } - }, - onchange: function(e) { - // Remove selected class from radio buttons - $('#DocumentTypeID').find('li').removeClass('selected'); - //If radio button is checked then add the selected class - if (this.is(':checked')) { - this.parent('li').addClass('selected'); - } - } - });*/ - $('.permissions input[name="CanViewType"], .permissions input[name="CanEditType"]').entwine({ - onchange: function () { - if (!this.is(':checked')) { - return; - } - - var dropDown = this.closest('.fieldholder-small').next(); - if (this.val() === 'OnlyTheseUsers') { - dropDown.removeClass('hide'); - } else { - dropDown.addClass('hide'); - } - }, - onadd: function () { + var dropDown = this.closest('.fieldholder-small').next(); + if (this.val() === 'OnlyTheseUsers') { + dropDown.removeClass('hide'); + } else { + dropDown.addClass('hide'); + } + }, + onadd: function () { this.trigger('change'); - } - }); - $('.dmsdocment-actions ul li').entwine({ - onclick: function (e) { + } + }); - //add active state to the current button - $('.dmsdocment-actions ul li').removeClass('dms-active'); - this.addClass('dms-active'); - //$('li.dms-active').append(''); + $('.dmsdocment-actions ul li').entwine({ + onclick: function (e) { + // Add active state to the current button + $('.dmsdocment-actions ul li').removeClass('dms-active'); + this.addClass('dms-active'); - //hide all inner field sections - var panel = $('.dmsdocument-actionspanel:first'); - panel.find('> .fieldgroup > .fieldgroup-field').hide(); + // Hide all inner field sections + var panel = $('.dmsdocument-actionspanel:first'); + panel.find('> .fieldgroup > .fieldgroup-field').hide(); - //show the correct group of controls - //panel.find('.'+this.data('panel')).closest('div.fieldgroup').show(); - panel.find('.'+this.data('panel')).show().parents('.fieldgroup-field').show(); + // Show the correct group of controls + panel.find('.'+this.data('panel')).show().parents('.fieldgroup-field').show(); + } + }); - } - }); + $('#Form_ItemEditForm_Embargo input, #Form_EditForm_Embargo input').entwine({ + onchange: function () { + // Selected the date options + if (this.attr('value') === 'Date') { + $('.embargoDatetime').children().show(); + $('.embargoDatetime').show(); + } else { + $('.embargoDatetime').hide(); + } + } + }); - $('#Form_ItemEditForm_Embargo input, #Form_EditForm_Embargo input').entwine({ - onchange: function () { - //selected the date options - if (this.attr('value') === 'Date') { - $('.embargoDatetime').children().show(); - $('.embargoDatetime').show(); - } else { - $('.embargoDatetime').hide(); - } - } - }); + $('#Form_ItemEditForm_Expiry input, #Form_EditForm_Expiry input').entwine({ + onchange: function () { + // Selected the date options + if (this.attr('value') === 'Date') { + $('.expiryDatetime').children().show(); + $('.expiryDatetime').show(); + } else { + $('.expiryDatetime').hide(); + } + } + }); - $('#Form_ItemEditForm_Expiry input, #Form_EditForm_Expiry input').entwine({ - onchange: function () { - //selected the date options - if (this.attr('value') === 'Date') { - $('.expiryDatetime').children().show(); - $('.expiryDatetime').show(); - } else { - $('.expiryDatetime').hide(); - } - } - }); + $('.dmsdocument-actionspanel').entwine({ + onadd: function () { + // Do an initial show of the entire panel + this.show(); - $('.dmsdocument-actionspanel').entwine({ - onadd: function () { - //do an initial show of the entire panel - this.show(); + // 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'); - //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'); + // Add class and hide + $('.dmsdocument-actionspanel .embargo input.date').closest('.fieldholder-small').addClass('embargoDatetime').hide(); + $('.dmsdocument-actionspanel .expiry input.date').closest('.fieldholder-small').addClass('expiryDatetime').hide(); - // add class and hide - $('.dmsdocument-actionspanel .embargo input.date').closest('.fieldholder-small').addClass('embargoDatetime').hide(); - $('.dmsdocument-actionspanel .expiry input.date').closest('.fieldholder-small').addClass('expiryDatetime').hide(); - // 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(); + // Add placeholder attribute to date and time fields + $('.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'); - //Add placeholder attribute to date and time fields - $('.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'); - // We need to duplicate to work when adding documents -// $('#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'); + // Show the embargo panel when the page loads + $('li[data-panel="embargo"]').click(); - //show the embargo panel when the page loads - $('li[data-panel="embargo"]').click(); + // Set the initial state of the radio button and the associated dropdown hiding + $('.dmsdocument-actionspanel .embargo input[type="radio"][checked]').change(); + $('.dmsdocument-actionspanel .expiry input[type="radio"][checked]').change(); + } + }); - //set the initial state of the radio button and the associated dropdown hiding - $('.dmsdocument-actionspanel .embargo input[type="radio"][checked]').change(); - $('.dmsdocument-actionspanel .expiry input[type="radio"][checked]').change(); - //Again we need to duplicate the above function to work when adding documents -// $('#Form_EditForm_Embargo input[checked]').change(); -// $('#Form_EditForm_Expiry input[checked]').change(); - } - }); + $('#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'); + var relationCount = form.data('relation-count'); - $('#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'); - var relationCount = form.data('relation-count'); - - //display an appropriate message - var message = ''; - 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; - } 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); - } - } - }); - - }); + // Display an appropriate message + var message = ''; + 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; + } 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); + } + } + }); + }); }(jQuery)); diff --git a/javascript/DMSGridField.js b/javascript/DMSGridField.js index 35543aa..79d294c 100644 --- a/javascript/DMSGridField.js +++ b/javascript/DMSGridField.js @@ -4,7 +4,7 @@ $.entwine('ss', function ($) { $('.ss-gridfield-item a.file-url').entwine({ onclick: function (e) { - //make sure the download link doesn't trigger a gridfield edit dialog + // Make sure the download link doesn't trigger a gridfield edit dialog window.open(this.attr('href'), '_blank'); e.preventDefault(); diff --git a/javascript/DMSUploadField_addtemplate.js b/javascript/DMSUploadField_addtemplate.js index 84b33c4..c6ecc76 100644 --- a/javascript/DMSUploadField_addtemplate.js +++ b/javascript/DMSUploadField_addtemplate.js @@ -1,30 +1,30 @@ window.tmpl.cache['ss-uploadfield-addtemplate'] = tmpl( - '{% for (var i=0, files=o.files, l=files.length, file=files[0]; i