import Core from 'spotlight/core' import SpotlightNestable from 'spotlight/admin/spotlight_nestable' Core.Block.Resources = (function(){ return Core.Block.extend({ type: "resources", formable: true, autocompleteable: true, show_heading: true, title: function() { return i18n.t("blocks:" + this.type + ":title"); }, description: function() { return i18n.t("blocks:" + this.type + ":description"); }, icon_name: "resources", blockGroup: function() { return i18n.t("blocks:group:items") }, primary_field_key: "primary-caption-field", show_primary_field_key: "show-primary-caption", secondary_field_key: "secondary-caption-field", show_secondary_field_key: "show-secondary-caption", display_checkbox: "display-checkbox", globalIndex: 0, _itemPanelIiifFields: function(index, data) { return []; }, _itemPanel: function(data) { var index = "item_" + this.globalIndex++; var checked; if (data.display == "true") { checked = "checked='checked'" } else { checked = ""; } var resource_id = data.slug || data.id; var markup = `
  • ${this._itemPanelIiifFields(index, data)}
    ${i18n.t("blocks:resources:panel:drag")}
    ${data.title}
    ${(data.slug || data.id)}
  • ` const panel = $(markup); var context = this; $('.remove a', panel).on('click', function(e) { e.preventDefault(); $(this).closest('.field').remove(); context.afterPanelDelete(); }); this.afterPanelRender(data, panel); return panel; }, afterPanelRender: function(data, panel) { }, afterPanelDelete: function() { }, createItemPanel: function(data) { var panel = this._itemPanel(data); $(panel).appendTo($('.panels > ol', this.inner)); $('[data-behavior="nestable"]', this.inner).trigger('change'); }, item_options: function() { return ""; }, content: function() { var templates = [this.items_selector()]; if (this.plustextable) { templates.push(this.text_area()); } return templates.join("
    \n"); }, items_selector: function() { return [ '
    ', '
    ', '
    ', '
      ', this.autocomplete_control(), '
      ', '
      ', '
      ', this.item_options(), '
      ', '
      '].join("\n") }, editorHTML: function() { return `
      ${this.description()}
      ${this.content()}
      ` }, onBlockRender: function() { SpotlightNestable.init($('[data-behavior="nestable"]', this.inner)); $('[data-input-select-target]', this.inner).selectRelatedInput(); }, afterLoadData: function(data) { var context = this; $.each(Object.keys(data.item || {}).map(function(k) { return data.item[k]}).sort(function(a,b) { return a.weight - b.weight; }), function(index, item) { context.createItemPanel(item); }); }, }); })();