Tidy up JS indentation and comments

This commit is contained in:
Sacha Judd 2017-05-30 16:46:45 +12:00
parent 2ddd20cd6c
commit 9200d83b12
6 changed files with 397 additions and 425 deletions

View File

@ -1,131 +1,135 @@
(function ($) { (function ($) {
"use strict"; "use strict";
$.entwine('ss', function ($) { $.entwine('ss', function ($) {
$('.document-add-existing').entwine({ $('.document-add-existing').entwine({
adddocument: function (document_id) { adddocument: function (document_id) {
var documentSetId = $(this).closest('form').find('input[name="DSID"]').val(); var documentSetId = $(this).closest('form').find('input[name="DSID"]').val();
jQuery.ajax( jQuery.ajax(
'admin/pages/adddocument/linkdocument?dsid=' + documentSetId + '&documentID=' + document_id, 'admin/pages/adddocument/linkdocument?dsid=' + documentSetId + '&documentID=' + document_id,
{ {
dataType: 'json', dataType: 'json',
success: function (data, textstatus) { success: function (data, textstatus) {
var fn = window.tmpl.cache['ss-uploadfield-addtemplate']; var fn = window.tmpl.cache['ss-uploadfield-addtemplate'];
var fnout = fn({ var fnout = fn({
files: [data], files: [data],
formatFileSize: function (bytes) { formatFileSize: function (bytes) {
if (typeof bytes !== 'number') { if (typeof bytes !== 'number') {
return ''; return '';
} }
if (bytes >= 1000000000) { if (bytes >= 1000000000) {
return (bytes / 1000000000).toFixed(2) + ' GB'; return (bytes / 1000000000).toFixed(2) + ' GB'
} }
if (bytes >= 1000000) { if (bytes >= 1000000) {
return (bytes / 1000000).toFixed(2) + ' MB'; return (bytes / 1000000).toFixed(2) + ' MB';
} }
return (bytes / 1000).toFixed(2) + ' KB'; return (bytes / 1000).toFixed(2) + ' KB';
} }
}); });
$('.ss-add-files').append(fnout); $('.ss-add-files').append(fnout);
} }
} }
); );
}, },
selectdocument: function (documentID, documentName) { selectdocument: function (documentID, documentName) {
if (typeof(documentID) !== "undefined") { if (typeof(documentID) !== "undefined") {
//substitute the ID for the full document name, if no name is present // Substitute the ID for the full document name, if no name is present
if (typeof(documentName) === "undefined") { if (typeof(documentName) === "undefined") {
documentName = documentID; documentName = documentID;
} }
$('.ss-add-files').html('<div class="selected-document" data-document-id="'+documentID+'">'+documentName+'</div>'); $('.ss-add-files').html('<div class="selected-document" data-document-id="'+documentID+'">'+documentName+'</div>');
} else { } else {
$('.ss-add-files').html(''); $('.ss-add-files').html('');
} }
} }
}); });
$('.document-add-existing .document-autocomplete').entwine({ $('.document-add-existing .document-autocomplete').entwine({
onmatch: function () { onmatch: function () {
var self = this; var self = this;
this.autocomplete({ this.autocomplete({
source: 'admin/pages/adddocument/documentautocomplete', source: 'admin/pages/adddocument/documentautocomplete',
select: function (event, ui) { select: function (event, ui) {
if (ui.item) { if (ui.item) {
if (self.closest('.document-add-existing').hasClass('link-editor-context')) { if (self.closest('.document-add-existing').hasClass('link-editor-context')) {
$(this).closest('.document-add-existing').selectdocument(ui.item.value, ui.item.label); $(this).closest('.document-add-existing').selectdocument(ui.item.value, ui.item.label);
} else { } else {
$(this).closest('.document-add-existing').adddocument(ui.item.value); $(this).closest('.document-add-existing').adddocument(ui.item.value);
} }
$(this).val(''); $(this).val('');
return false; return false;
} }
} }
}); });
} }
}); });
// Add label to tree drop down button // Add label to tree drop down button
$('.document-add-existing .treedropdownfield-toggle-panel-link').entwine({ $('.document-add-existing .treedropdownfield-toggle-panel-link').entwine({
onmatch: function () { onmatch: function () {
this.prepend('<span>Browse by page</span>'); this.prepend('<span>Browse by page</span>');
} }
}); });
$('.document-add-existing .TreeDropdownField').entwine({ $('.document-add-existing .TreeDropdownField').entwine({
onpanelshow: function () { onpanelshow: function () {
$(this).closest('.document-add-existing').find('input.document-autocomplete').prop('disabled', true); $(this).closest('.document-add-existing').find('input.document-autocomplete').prop('disabled', true);
}, },
onpanelhide: function () { onpanelhide: function () {
$(this).closest('.document-add-existing').find('input.document-autocomplete').prop('disabled', $(this).closest('.document-add-existing').find('.document-list:visible').length > 0); $(this)
} .closest('.document-add-existing')
}); .find('input.document-autocomplete')
.prop('disabled', $(this).closest('.document-add-existing').find('.document-list:visible').length > 0);
}
});
$('.document-add-existing input[name=PageSelector]').entwine({ $('.document-add-existing input[name=PageSelector]').entwine({
onchange: function (event) { onchange: function (event) {
var doclist = $(this).closest('.document-add-existing').find('.document-list'); var doclist = $(this).closest('.document-add-existing').find('.document-list');
doclist.html('<p>Loading...</p>'); doclist.html('<p>Loading...</p>');
doclist.show(); doclist.show();
doclist.load( doclist.load(
'admin/pages/adddocument/documentlist?pageID=' + $(this).val() '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({ if (dae.hasClass('link-editor-context')) {
onclick: function (event) { dae.selectdocument(document_id, this.text());
var document_id = this.data('document-id'); } else {
var dae = this.closest('.document-add-existing'); dae.adddocument(document_id);
}
if (dae.hasClass('link-editor-context')) { $(this).closest('.document-list').hide();
dae.selectdocument(document_id, this.text()); $(this).closest('.document-add-existing').find('input.document-autocomplete').prop('disabled', false);
} else {
dae.adddocument(document_id);
}
$(this).closest('.document-list').hide(); return false;
$(this).closest('.document-add-existing').find('input.document-autocomplete').prop('disabled', 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({ $('.document-add-existing .treedropdownfield-toggle-panel-link').entwine({
onclick: function (event) { onclick: function (event) {
$('.document-list:visible').hide() $('.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();
}
});
});
}(jQuery)); }(jQuery));

View File

@ -1,177 +1,144 @@
(function($) { (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({ $('.permissions input[name="CanViewType"], .permissions input[name="CanEditType"]').entwine({
onadd: function () { onchange: function () {
this.addClass('ui-button ss-ui-button ui-corner-all ui-state-default ui-widget ui-button-text-only'); if (!this.is(':checked')) {
this.parents('ul').removeClass('ui-tabs-nav'); return;
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 input[type=radio]').entwine({ var dropDown = this.closest('.fieldholder-small').next();
onadd: function() { if (this.val() === 'OnlyTheseUsers') {
// Checks to see what radio button is selected dropDown.removeClass('hide');
if (this.is(':checked')) { } else {
this.change(); dropDown.addClass('hide');
} }
}, },
onchange: function(e) { onadd: function () {
// 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 () {
this.trigger('change'); this.trigger('change');
} }
}); });
$('.dmsdocment-actions ul li').entwine({
onclick: function (e) {
//add active state to the current button $('.dmsdocment-actions ul li').entwine({
$('.dmsdocment-actions ul li').removeClass('dms-active'); onclick: function (e) {
this.addClass('dms-active'); // Add active state to the current button
//$('li.dms-active').append('<span class="arrow"></span>'); $('.dmsdocment-actions ul li').removeClass('dms-active');
this.addClass('dms-active');
//hide all inner field sections // Hide all inner field sections
var panel = $('.dmsdocument-actionspanel:first'); var panel = $('.dmsdocument-actionspanel:first');
panel.find('> .fieldgroup > .fieldgroup-field').hide(); panel.find('> .fieldgroup > .fieldgroup-field').hide();
//show the correct group of controls // 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();
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({ $('#Form_ItemEditForm_Expiry input, #Form_EditForm_Expiry input').entwine({
onchange: function () { onchange: function () {
//selected the date options // Selected the date options
if (this.attr('value') === 'Date') { if (this.attr('value') === 'Date') {
$('.embargoDatetime').children().show(); $('.expiryDatetime').children().show();
$('.embargoDatetime').show(); $('.expiryDatetime').show();
} else { } else {
$('.embargoDatetime').hide(); $('.expiryDatetime').hide();
} }
} }
}); });
$('#Form_ItemEditForm_Expiry input, #Form_EditForm_Expiry input').entwine({ $('.dmsdocument-actionspanel').entwine({
onchange: function () { onadd: function () {
//selected the date options // Do an initial show of the entire panel
if (this.attr('value') === 'Date') { this.show();
$('.expiryDatetime').children().show();
$('.expiryDatetime').show();
} else {
$('.expiryDatetime').hide();
}
}
});
$('.dmsdocument-actionspanel').entwine({ // Add some extra classes to the replace field containers to make it work with drag and drop uploading
onadd: function () { this.find('.replace').closest('div.fieldgroup-field').addClass('ss-upload').addClass('ss-uploadfield');
//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 // Add class and hide
this.find('.replace').closest('div.fieldgroup-field').addClass('ss-upload').addClass('ss-uploadfield'); $('.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 // Add placeholder attribute to date and time fields
$('.dmsdocument-actionspanel .embargo input.date').closest('.fieldholder-small').addClass('embargoDatetime').hide(); $('.dmsdocument-actionspanel .embargo input.date').attr('placeholder', 'dd-mm-yyyy');
$('.dmsdocument-actionspanel .expiry input.date').closest('.fieldholder-small').addClass('expiryDatetime').hide(); $('.dmsdocument-actionspanel .embargo input.time').attr('placeholder', 'hh:mm:ss');
// We need to duplicate the above functions to work when Adding documents $('.dmsdocument-actionspanel .expiry input.date').attr('placeholder', 'dd-mm-yyyy');
// $('#Form_EditForm_EmbargoedUntilDate_date').closest('.fieldholder-small').addClass('embargoDatetime').hide(); $('.dmsdocument-actionspanel .expiry input.time').attr('placeholder', 'hh:mm:ss');
// $('#Form_EditForm_ExpireAtDate_date').closest('.fieldholder-small').addClass('expiryDatetime').hide();
//Add placeholder attribute to date and time fields // Show the embargo panel when the page loads
$('.dmsdocument-actionspanel .embargo input.date').attr('placeholder', 'dd-mm-yyyy'); $('li[data-panel="embargo"]').click();
$('.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 // Set the initial state of the radio button and the associated dropdown hiding
$('li[data-panel="embargo"]').click(); $('.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 $('#Form_ItemEditForm_action_doDelete').entwine({
$('.dmsdocument-actionspanel .embargo input[type="radio"][checked]').change(); onclick: function (e) {
$('.dmsdocument-actionspanel .expiry input[type="radio"][checked]').change(); // Work out how many pages are left attached to this document
//Again we need to duplicate the above function to work when adding documents var form = this.closest('form');
// $('#Form_EditForm_Embargo input[checked]').change(); var pagesCount = form.data('pages-count');
// $('#Form_EditForm_Expiry input[checked]').change(); var relationCount = form.data('relation-count');
}
});
$('#Form_ItemEditForm_action_doDelete').entwine({ // Display an appropriate message
onclick: function (e) { var message = '';
//work out how many pages are left attached to this document if (pagesCount > 1 || relationCount > 0) {
var form = this.closest('form'); var pages = '';
var pagesCount = form.data('pages-count'); if (pagesCount > 1) {
var relationCount = form.data('relation-count'); pages = "\nWarning: doc is attached to a total of "+pagesCount+" pages. ";
}
//display an appropriate message var references = '';
var message = ''; var referencesWarning = '';
if (pagesCount > 1 || relationCount > 0) { if (relationCount > 0) {
var pages = ''; var pname = 'pages';
if (pagesCount > 1) { referencesWarning = "\n\nBefore deleting: please update the content on the pages where this document is referenced, otherwise the links on those pages will break.";
pages = "\nWarning: doc is attached to a total of "+pagesCount+" pages. "; if (relationCount === 1) {
} pname = 'page';
var references = ''; referencesWarning = "\n\nBefore deleting: please update the content on the page where this document is referenced, otherwise the links on that page will break.";
var referencesWarning = ''; }
if (relationCount > 0) { references = "\nWarning: doc is referenced in the text of "+relationCount +" "+pname+".";
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."; 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;
if (relationCount === 1) { } else {
pname = 'page'; 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.";
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);
}
}
});
});
if (!confirm(message)) {
e.preventDefault();
return false;
} else {
// User says "okay", so go ahead and do the action
this._super(e);
}
}
});
});
}(jQuery)); }(jQuery));

View File

@ -4,7 +4,7 @@
$.entwine('ss', function ($) { $.entwine('ss', function ($) {
$('.ss-gridfield-item a.file-url').entwine({ $('.ss-gridfield-item a.file-url').entwine({
onclick: function (e) { 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'); window.open(this.attr('href'), '_blank');
e.preventDefault(); e.preventDefault();

View File

@ -1,30 +1,30 @@
window.tmpl.cache['ss-uploadfield-addtemplate'] = tmpl( window.tmpl.cache['ss-uploadfield-addtemplate'] = tmpl(
'{% for (var i=0, files=o.files, l=files.length, file=files[0]; i<l; file=files[++i]) { %}' + '{% for (var i=0, files=o.files, l=files.length, file=files[0]; i<l; file=files[++i]) { %}' +
'<li class="ss-uploadfield-item template-download{% if (file.error) { %} ui-state-error{% } %}" data-fileid="{%=file.id%}">' + '<li class="ss-uploadfield-item template-download{% if (file.error) { %} ui-state-error{% } %}" data-fileid="{%=file.id%}">' +
'<div class="ss-uploadfield-item-preview preview"><span>' + '<div class="ss-uploadfield-item-preview preview"><span>' +
'<img src="{%=file.thumbnail_url%}" alt="" />' + '<img src="{%=file.thumbnail_url%}" alt="" />' +
'</span></div>' + '</span></div>' +
'<div class="ss-uploadfield-item-info">' + '<div class="ss-uploadfield-item-info">' +
'<label class="ss-uploadfield-item-name">' + '<label class="ss-uploadfield-item-name">' +
'<span class="name" title="{%=file.name%}">{%=file.name%}</span> ' + '<span class="name" title="{%=file.name%}">{%=file.name%}</span> ' +
'{% if (!file.error) { %}' + '{% if (!file.error) { %}' +
'<div class="ss-uploadfield-item-status ui-state-success-text" title="'+ss.i18n._t('UploadField.AddedToDocumentSet', 'Added to Document Set')+'">'+ss.i18n._t('UploadField.AddedToDocumentSet', 'Added to Document Set')+'</div>' + '<div class="ss-uploadfield-item-status ui-state-success-text" title="'+ss.i18n._t('UploadField.AddedToDocumentSet', 'Added to Document Set')+'">'+ss.i18n._t('UploadField.AddedToDocumentSet', 'Added to Document Set')+'</div>' +
'{% } else { %}' + '{% } else { %}' +
'<div class="ss-uploadfield-item-status ui-state-error-text" title="{%=o.options.errorMessages[file.error] || file.error%}">{%=o.options.errorMessages[file.error] || file.error%}</div>' + '<div class="ss-uploadfield-item-status ui-state-error-text" title="{%=o.options.errorMessages[file.error] || file.error%}">{%=o.options.errorMessages[file.error] || file.error%}</div>' +
'{% } %}' + '{% } %}' +
'<div class="clear"><!-- --></div>' + '<div class="clear"><!-- --></div>' +
'</label>' + '</label>' +
'{% if (file.error) { %}' + '{% if (file.error) { %}' +
'<div class="ss-uploadfield-item-actions">' + '<div class="ss-uploadfield-item-actions">' +
'<div class="ss-uploadfield-item-cancel ss-uploadfield-item-cancelfailed"><button class="icon icon-16">' + ss.i18n._t('UploadField.CANCEL', 'Cancel') + '</button></div>' + '<div class="ss-uploadfield-item-cancel ss-uploadfield-item-cancelfailed"><button class="icon icon-16">' + ss.i18n._t('UploadField.CANCEL', 'Cancel') + '</button></div>' +
'</div>' + '</div>' +
'{% } else { %}' + '{% } else { %}' +
'<div class="ss-uploadfield-item-actions">{% print(file.buttons, true); %}</div>' + '<div class="ss-uploadfield-item-actions">{% print(file.buttons, true); %}</div>' +
'{% } %}' + '{% } %}' +
'</div>' + '</div>' +
'{% if (!file.error) { %}' + '{% if (!file.error) { %}' +
'<div class="ss-uploadfield-item-editform loading"><iframe frameborder="0" src="{%=file.edit_url%}"></iframe></div>' + '<div class="ss-uploadfield-item-editform loading"><iframe frameborder="0" src="{%=file.edit_url%}"></iframe></div>' +
'{% } %}' + '{% } %}' +
'</li>' + '</li>' +
'{% } %}' '{% } %}'
); );

View File

@ -1,27 +1,27 @@
window.tmpl.cache['ss-dmsuploadfield-downloadtemplate'] = tmpl( window.tmpl.cache['ss-dmsuploadfield-downloadtemplate'] = tmpl(
'{% for (var i=0, files=o.files, l=files.length, file=files[0]; i<l; file=files[++i]) { %}' + '{% for (var i=0, files=o.files, l=files.length, file=files[0]; i<l; file=files[++i]) { %}' +
'<li class="ss-uploadfield-item template-download{% if (file.error) { %} ui-state-error{% } %}" data-fileid="{%=file.id%}">' + '<li class="ss-uploadfield-item template-download{% if (file.error) { %} ui-state-error{% } %}" data-fileid="{%=file.id%}">' +
'<div class="ss-uploadfield-item-preview preview"><span>' + '<div class="ss-uploadfield-item-preview preview"><span>' +
'<img src="{%=file.thumbnail_url%}" alt="" />' + '<img src="{%=file.thumbnail_url%}" alt="" />' +
'</span></div>' + '</span></div>' +
'<div class="ss-uploadfield-item-info">' + '<div class="ss-uploadfield-item-info">' +
'<label class="ss-uploadfield-item-name">' + '<label class="ss-uploadfield-item-name">' +
'<span class="name" title="{%=file.name%}">{%=file.name%}</span> ' + '<span class="name" title="{%=file.name%}">{%=file.name%}</span> ' +
'{% if (!file.error) { %}' + '{% if (!file.error) { %}' +
'<div class="ss-uploadfield-item-status ui-state-success-text" title="'+ss.i18n._t('UploadField.Uploaded', 'Uploaded')+'">'+ss.i18n._t('UploadField.Uploaded', 'Uploaded')+'</div>' + '<div class="ss-uploadfield-item-status ui-state-success-text" title="'+ss.i18n._t('UploadField.Uploaded', 'Uploaded')+'">'+ss.i18n._t('UploadField.Uploaded', 'Uploaded')+'</div>' +
'{% } else { %}' + '{% } else { %}' +
'<div class="ss-uploadfield-item-status ui-state-error-text" title="{%=o.options.errorMessages[file.error] || file.error%}">{%=o.options.errorMessages[file.error] || file.error%}</div>' + '<div class="ss-uploadfield-item-status ui-state-error-text" title="{%=o.options.errorMessages[file.error] || file.error%}">{%=o.options.errorMessages[file.error] || file.error%}</div>' +
'{% } %}' + '{% } %}' +
'<div class="clear"><!-- --></div>' + '<div class="clear"><!-- --></div>' +
'</label>' + '</label>' +
'{% if (file.error) { %}' + '{% if (file.error) { %}' +
'<div class="ss-uploadfield-item-actions">' + '<div class="ss-uploadfield-item-actions">' +
'<div class="ss-uploadfield-item-cancel ss-uploadfield-item-cancelfailed"><button class="icon icon-16">' + ss.i18n._t('UploadField.CANCEL', 'Cancel') + '</button></div>' + '<div class="ss-uploadfield-item-cancel ss-uploadfield-item-cancelfailed"><button class="icon icon-16">' + ss.i18n._t('UploadField.CANCEL', 'Cancel') + '</button></div>' +
'</div>' + '</div>' +
'{% } else { %}' + '{% } else { %}' +
'<div class="ss-uploadfield-item-actions">(please click save and the page will update)</div>' + '<div class="ss-uploadfield-item-actions">(please click save and the page will update)</div>' +
'{% } %}' + '{% } %}' +
'</div>' + '</div>' +
'</li>' + '</li>' +
'{% } %}' '{% } %}'
); );

View File

@ -1,117 +1,118 @@
(function ($) { (function ($) {
"use strict"; "use strict";
$.entwine('ss', function ($) { $.entwine('ss', function ($) {
$('form.htmleditorfield-linkform input[name=LinkType]').entwine({
onchange: function (e) {
this._super(e);
$('form.htmleditorfield-linkform input[name=LinkType]').entwine({ var form = $('form.htmleditorfield-linkform');
onchange: function (e) { var show = false;
this._super(e);
var form = $('form.htmleditorfield-linkform'); if (this.attr('value') === 'document') {
var show = false; if (this.is(':checked')) {
show = true;
}
}
if (this.attr('value') === 'document') { // Hide or show the additional document link addition tool
if (this.is(':checked')) { if (show) {
show = true; form.find('.ss-add').show();
} } else {
} form.find('.ss-add').hide();
}
},
onadd: function (e) {
this.change();
}
});
//hide or show the additional document link addition tool $('form.htmleditorfield-linkform').entwine({
if (show) { getShortcodeKey: function () {
form.find('.ss-add').show(); return this.find(':input[name=DMSShortcodeHandlerKey]').val();
} else { },
form.find('.ss-add').hide(); insertLink: function () {
} var href, target = null;
}, var checkedValue = this.find(':input[name=LinkType]:checked').val();
onadd: function (e) { if (checkedValue === 'document') {
this.change(); href = '[' + this.getShortcodeKey() + ',id=' + this.find('.selected-document').data('document-id') + ']';
}
});
$('form.htmleditorfield-linkform').entwine({ // Determine target
getShortcodeKey: function () { if (this.find(':input[name=TargetBlank]').is(':checked')) {
return this.find(':input[name=DMSShortcodeHandlerKey]').val(); target = '_blank';
}, }
insertLink: function () {
var href, target = null;
var checkedValue = this.find(':input[name=LinkType]:checked').val();
if (checkedValue === 'document') {
href = '[' + this.getShortcodeKey() + ',id=' + this.find('.selected-document').data('document-id') + ']';
// Determine target var attributes = {
if (this.find(':input[name=TargetBlank]').is(':checked')) { href: href,
target = '_blank'; target: target,
} class: 'documentLink',
// Title is the text of the selected document
title: this.find('.selected-document').text()
};
var attributes = { this.modifySelection(function (ed) {
href : href, ed.insertLink(attributes);
target : target, });
class : 'documentLink',
title : this.find('.selected-document').text() //title is the text of the selected document
};
this.modifySelection(function (ed) { this.updateFromEditor();
ed.insertLink(attributes); return false;
}); } else {
this._super();
}
},
getCurrentLink: function () {
var selectedEl = this.getSelection(), href = "", target = "", title = "", action = "insert", style_class = "";
var linkDataSource = null;
if (selectedEl.length) {
if (selectedEl.is('a')) {
linkDataSource = selectedEl;
} else {
linkDataSource = selectedEl = selectedEl.parents('a:first');
}
}
this.updateFromEditor(); if (linkDataSource && linkDataSource.length) {
return false; this.modifySelection(function (ed) {
} else { ed.selectNode(linkDataSource[0]);
this._super(); });
} }
},
getCurrentLink: function () {
var selectedEl = this.getSelection(), href = "", target = "", title = "", action = "insert", style_class = "";
var linkDataSource = null;
if (selectedEl.length) {
if (selectedEl.is('a')) {
linkDataSource = selectedEl;
} else {
linkDataSource = selectedEl = selectedEl.parents('a:first');
}
}
if (linkDataSource && linkDataSource.length) {
this.modifySelection(function (ed) {
ed.selectNode(linkDataSource[0]);
});
}
// Is anchor not a link // Is anchor not a link
if (!linkDataSource.attr('href')) { if (!linkDataSource.attr('href')) {
linkDataSource = null; linkDataSource = null;
} }
if (linkDataSource) { if (linkDataSource) {
href = linkDataSource.attr('href'); href = linkDataSource.attr('href');
target = linkDataSource.attr('target'); target = linkDataSource.attr('target');
title = linkDataSource.attr('title'); title = linkDataSource.attr('title');
style_class = linkDataSource.attr('class'); style_class = linkDataSource.attr('class');
href = this.getEditor().cleanLink(href, linkDataSource); href = this.getEditor().cleanLink(href, linkDataSource);
action = "update"; action = "update";
} }
//match a document or call the regular link handling // Match a document or call the regular link handling
if (href.match(new RegExp("/^\[" + this.getShortcodeKey() + "(\s*|%20|,)?id=([0-9]+)\]?$/", "i"))) { if (href.match(new RegExp("/^\[" + this.getShortcodeKey() + "(\s*|%20|,)?id=([0-9]+)\]?$/", "i"))) {
var returnArray = { var returnArray = {
LinkType: 'document', LinkType: 'document',
DocumentID: RegExp.$2, DocumentID: RegExp.$2,
Description: title Description: title
}; };
//show the selected document // Show the selected document
$('.document-add-existing').selectdocument(returnArray.DocumentID,returnArray.Description); $('.document-add-existing').selectdocument(returnArray.DocumentID,returnArray.Description);
//select the correct radio button // Select the correct radio button
$('form.htmleditorfield-linkform input[name=LinkType][value=document]').click(); $('form.htmleditorfield-linkform input[name=LinkType][value=document]').click();
return returnArray;
} else {
$('.document-add-existing').selectdocument(); //clear the selected document
$('form.htmleditorfield-linkform .ss-add.ss-upload').hide();
return this._super();
}
}
});
});
return returnArray;
} else {
// Clear the selected document
$('.document-add-existing').selectdocument();
$('form.htmleditorfield-linkform .ss-add.ss-upload').hide();
return this._super();
}
}
});
});
}(jQuery)); }(jQuery));