(function ($) { "use strict"; $.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'; } }); $('.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 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); } $(this).closest('.document-list').hide(); $(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); } }); $('.document-add-existing .treedropdownfield-toggle-panel-link').entwine({ onclick: function (event) { $('.document-list:visible').hide(); } }); }); }(jQuery));