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 = `