import SpotlightNestable from 'spotlight/admin/spotlight_nestable' import Core from 'spotlight/core' SirTrevor.Blocks.UploadedItems = (function(){ return Core.Block.Resources.extend({ plustextable: true, uploadable: true, autocompleteable: false, id_key: 'file', type: 'uploaded_items', icon_name: 'items', blockGroup: 'undefined', // Clear out the default Uploadable upload options // since we will be using our own custom controls upload_options: { html: '' }, fileInput: function() { return $(this.inner).find('input[type="file"]'); }, onBlockRender: function(){ SpotlightNestable.init($(this.inner).find('[data-behavior="nestable"]')); this.fileInput().on('change', (function(ev) { this.onDrop(ev.currentTarget); }).bind(this)); }, onDrop: function(transferData){ var file = transferData.files[0], urlAPI = (typeof URL !== "undefined") ? URL : (typeof webkitURL !== "undefined") ? webkitURL : null; // Handle one upload at a time if (/image/.test(file.type)) { this.loading(); this.uploader( file, function(data) { this.createItemPanel(data); this.fileInput().val(''); this.ready(); }, function(error) { this.addMessage(i18n.t('blocks:image:upload_error')); this.ready(); } ); } }, title: function() { return i18n.t('blocks:uploaded_items:title'); }, description: function() { return i18n.t('blocks:uploaded_items:description'); }, globalIndex: 0, _itemPanel: function(data) { var index = "file_" + this.globalIndex++; var checked = 'checked="checked"'; if (data.display == 'false') { checked = ''; } var dataId = data.id || data.uid; var dataTitle = data.title || data.name; var dataUrl = data.url || data.file.url; var markup = `
  • ${i18n.t("blocks:resources:panel:drag")}
    ${dataTitle}
    ${this._altTextFieldsHTML(index, data)}
  • ` const panel = $(markup); panel.find('[data-field="caption"]').val(data.caption); panel.find('[data-field="link"]').val(data.link); var context = this; $('.remove a', panel).on('click', function(e) { e.preventDefault(); $(this).closest('.field').remove(); context.afterPanelDelete(); }); this.afterPanelRender(data, panel); return panel; }, editorHTML: function() { return `
    ${this.description()} ${this.alt_text_guidelines()} ${this.alt_text_guidelines_link()}
    ${this.text_area()}
    ` }, altTextHTML: function(index, data) { const { isDecorative, altText, altTextBackup, placeholderAttr, disabledAttr } = this._altTextData(data); return `
    ` }, zpr_key: 'zpr_link' }); })();