From 8ea31a048252bc2fe3b73ea051be4092d629b8fe Mon Sep 17 00:00:00 2001 From: Harvel218 Date: Fri, 14 Jan 2022 09:00:37 +0100 Subject: [PATCH] add reload preview on locale/chanel change --- .../assets/admin/js/bitbag/bitbag-cms-preview.js | 14 ++++++++++++++ src/Resources/public/build/bitbag-cms-admin.css | 2 +- src/Resources/public/build/bitbag-cms-admin.js | 2 +- src/Resources/public/build/manifest.json | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Resources/assets/admin/js/bitbag/bitbag-cms-preview.js b/src/Resources/assets/admin/js/bitbag/bitbag-cms-preview.js index a372c202a..76f0de1a4 100644 --- a/src/Resources/assets/admin/js/bitbag/bitbag-cms-preview.js +++ b/src/Resources/assets/admin/js/bitbag/bitbag-cms-preview.js @@ -49,6 +49,20 @@ export class HandlePreview { this.button.addEventListener('click', (e) => { e.preventDefault(); + this._$_CKEDITOR_UPDATE_INSTANCES; + this._createPreview(); + this._$_CKEDITOR_MODAL_SHOW(); + }); + document.querySelector(`[${this.channelSelector}]`).addEventListener('change', (e) => { + e.preventDefault(); + + this._$_CKEDITOR_UPDATE_INSTANCES; + this._createPreview(); + this._$_CKEDITOR_MODAL_SHOW(); + }); + document.querySelector(`[${this.localeSelector}]`).addEventListener('change', (e) => { + e.preventDefault(); + this._$_CKEDITOR_UPDATE_INSTANCES; this._createPreview(); this._$_CKEDITOR_MODAL_SHOW(); diff --git a/src/Resources/public/build/bitbag-cms-admin.css b/src/Resources/public/build/bitbag-cms-admin.css index bf1f77963..83c50b5d9 100644 --- a/src/Resources/public/build/bitbag-cms-admin.css +++ b/src/Resources/public/build/bitbag-cms-admin.css @@ -1 +1 @@ -#bitbag-cms-resource-preview-modal{height:90%}#bitbag-cms-resource-preview-modal iframe{height:600px;width:100%}#bitbag-cms-resource-preview-modal .ui.header{padding-bottom:0}.bitbag-cms-import .ui.action.input input[type=file]{display:none}.bitbag-cms-import .ui.action.input input[type=text]{width:auto}.media-list{grid-gap:20px;display:grid;grid-template-columns:repeat(6,150px);margin:0 auto}.media-list__item{align-items:flex-start;display:flex;flex-direction:column;justify-content:space-between;max-width:150px;position:relative!important}.media-list__item__label,.media-list__item__label>strong{word-wrap:break-word!important;white-space:-moz-pre-wrap!important;white-space:-webkit-pre-wrap!important;white-space:-pre-wrap!important;white-space:-o-pre-wrap!important;white-space:pre-wrap!important;white-space:normal!important;word-break:break-all!important}.media-list__item__label>strong{display:block!important}.media-list__item__input{bottom:10px;position:absolute!important;right:10px}.media-list__item__input:hover{cursor:pointer}.media-list__item__img{height:150px!important;width:150px!important}.btn{display:inline-block!important;font-size:1.4em!important}.btn:hover{cursor:pointer}.page-number{font-size:1.4em!important}.btn-delete{color:#db2828;cursor:pointer;font-weight:700;height:20px;position:absolute;right:30px;width:20px;z-index:5}.btn-delete.is-hidden{opacity:.2;pointer-events:none}.bitbag-media-autocomplete .dropdown.icon{pointer-events:none}.bitbag-media-autocomplete .search{cursor:pointer!important} \ No newline at end of file +#bitbag-cms-resource-preview-modal{height:100%}#bitbag-cms-resource-preview-modal iframe{height:100vh;width:100%}#bitbag-cms-resource-preview-modal .ui.header{padding-bottom:0}.bitbag-cms-import .ui.action.input input[type=file]{display:none}.bitbag-cms-import .ui.action.input input[type=text]{width:auto}.media-list{grid-gap:20px;display:grid;grid-template-columns:repeat(6,150px);margin:0 auto}.media-list__item{align-items:flex-start;display:flex;flex-direction:column;justify-content:space-between;max-width:150px;position:relative!important}.media-list__item__label,.media-list__item__label>strong{word-wrap:break-word!important;white-space:-moz-pre-wrap!important;white-space:-webkit-pre-wrap!important;white-space:-pre-wrap!important;white-space:-o-pre-wrap!important;white-space:pre-wrap!important;white-space:normal!important;word-break:break-all!important}.media-list__item__label>strong{display:block!important}.media-list__item__input{bottom:10px;position:absolute!important;right:10px;z-index:99}.media-list__item__input:hover{cursor:pointer}.media-list__item__img{height:150px!important;width:150px!important}.btn{display:inline-block!important;font-size:1.4em!important}.btn:hover{cursor:pointer}.page-number{font-size:1.4em!important}.btn-delete{color:#db2828;cursor:pointer;font-weight:700;height:20px;position:absolute;right:30px;width:20px;z-index:5}.btn-delete.is-hidden{opacity:.2;pointer-events:none}.bitbag-media-autocomplete .dropdown.icon{pointer-events:none}.bitbag-media-autocomplete .search{cursor:pointer!important} \ No newline at end of file diff --git a/src/Resources/public/build/bitbag-cms-admin.js b/src/Resources/public/build/bitbag-cms-admin.js index edc886bcf..f2e29849b 100644 --- a/src/Resources/public/build/bitbag-cms-admin.js +++ b/src/Resources/public/build/bitbag-cms-admin.js @@ -1 +1 @@ -(()=>{"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{textField:"data-bb-cms-text",fileField:"data-bb-cms-file"};t(this,a),this.config=e,this.textField=document.querySelector("[".concat(e.textField,"]")),this.fileField=document.querySelector("[".concat(e.fileField,"]"))}var r,i,o;return r=a,(i=[{key:"init",value:function(){if("object"!==e(this.config))throw new Error("Bitbag CMS Plugin - HandleCsvUpload class config is not a valid object");this._handleFields()}},{key:"_handleFields",value:function(){this._handleTextField(),this._handleFileField()}},{key:"_handleTextField",value:function(){var e=this;this.textField.addEventListener("click",(function(){e.fileField.click()}))}},{key:"_handleFileField",value:function(){var e=this;this.fileField.addEventListener("change",(function(t){e.textField.value=t.target.files[0].name}))}}])&&n(r.prototype,i),o&&n(r,o),a}();const r=function(e,t,n){var a=new CustomEvent("".concat("bb",".").concat(t),{detail:n});return e.dispatchEvent(a),e};function i(e,t,n,a,r,i,o){try{var c=e[i](o),l=c.value}catch(e){return void n(e)}c.done?t(l):Promise.resolve(l).then(a,r)}function o(e){return function(){var t=this,n=arguments;return new Promise((function(a,r){var o=e.apply(t,n);function c(e){i(o,a,r,c,l,"next",e)}function l(e){i(o,a,r,c,l,"throw",e)}c(void 0)}))}}function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{wrappersIndicator:"data-bb-cms-wrapper",lockFieldIndicator:"data-bb-cms-toggle-slug",bbTarget:"bitbag_sylius_cms_plugin_page"};l(this,e),this.wrappers=document.querySelectorAll("[".concat(t.wrappersIndicator,"]")),this.lockFieldIndicator="[".concat(t.lockFieldIndicator,"]"),this.bbTarget=t.bbTarget,this.config=t}var t,n,a,i,u;return t=e,n=[{key:"init",value:function(){if("object"!==c(this.config))throw new Error("Bitbag CMS Plugin - HandleSlugUpdate class config is not a valid object");if("string"!=typeof this.lockFieldIndicator||"string"!=typeof this.bbTarget)throw new Error("Bitbag CMS Plugin - HandleSlugUpdate class config key values are not valid strings");this._handleFields()}},{key:"_handleFields",value:function(){var e=this;this.wrappers.forEach((function(t){var n,a=t.dataset.locale,r=t.querySelector("#".concat(e.bbTarget,"_translations_").concat(a,"_name")),i=t.querySelector("#".concat(e.bbTarget,"_translations_").concat(a,"_slug")),o=t.querySelector(e.lockFieldIndicator);r&&i&&a&&(r.addEventListener("input",(function(t){t.preventDefault(),i.readOnly||(clearTimeout(n),n=setTimeout((function(){e._updateSlug(i,r.value)}),1e3))})),o&&o.addEventListener("click",(function(t){t.preventDefault(),e._toggleSlugModification(i,o)})))}))}},{key:"_updateSlug",value:(u=o(regeneratorRuntime.mark((function e(t,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r(t,"cms.slug.update.start"),t.parentNode.classList.add("loading"),e.next=4,this._getValidSlug(t.dataset.url,n);case 4:t.value=e.sent,t.parentNode.classList.remove("loading"),r(t,"cms.slug.update.end");case 7:case"end":return e.stop()}}),e,this)}))),function(e,t){return u.apply(this,arguments)})},{key:"_getValidSlug",value:(i=o(regeneratorRuntime.mark((function e(t,n){var a,r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,fetch("".concat(t,"?name=").concat(n));case 3:return a=e.sent,e.next=6,a.json();case 6:return r=e.sent,e.abrupt("return",r.slug);case 10:e.prev=10,e.t0=e.catch(0),console.error("BitBag CMS Plugin - HandleSlugUpdate class error : ".concat(e.t0));case 13:case"end":return e.stop()}}),e,null,[[0,10]])}))),function(e,t){return i.apply(this,arguments)})},{key:"_toggleSlugModification",value:function(e,t){e.readOnly=!e.readOnly;var n=t.querySelector("i");n.classList.toggle("lock"),n.classList.toggle("unlock")}}],n&&s(t.prototype,n),a&&s(t,a),e}();function d(e,t,n,a,r,i,o){try{var c=e[i](o),l=c.value}catch(e){return void n(e)}c.done?t(l):Promise.resolve(l).then(a,r)}function m(e){return function(e){if(Array.isArray(e))return h(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return h(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return h(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:{previewButton:"data-bb-cms-preview-btn",previewModal:"data-bb-cms-preview-modal",channelSwitch:"data-bb-cms-channel",localeSwitch:"data-bb-cms-locale"};p(this,e),this.config=t,this.button=document.querySelector("[".concat(t.previewButton,"]")),this.modal=document.querySelector("[".concat(t.previewModal,"]")),this.modalSelector=t.previewModal,this.channelSelector=t.channelSwitch,this.localeSelector=t.localeSwitch}var t,n,a,i,o;return t=e,n=[{key:"init",value:function(){if("object"!==f(this.config))throw new Error("Bitbag CMS Plugin - HandlePreview class config is not a valid object");if("string"!=typeof this.localeSelector||"string"!=typeof this.channelSelector||"string"!=typeof this.modalSelector)throw new Error("Bitbag CMS Plugin - HandlePreview class config key values are not valid strings");this._resourcePreview()}},{key:"_$_CKEDITOR_MODAL_SHOW",value:function(){return $("[".concat(this.modalSelector,"]")).modal("show")}},{key:"_$_CKEDITOR_UPDATE_INSTANCES",value:function(){m(CKEDITOR.instances).forEach((function(e){return e.updateElement()}))}},{key:"_resourcePreview",value:function(){var e=this;this.button.addEventListener("click",(function(t){t.preventDefault(),e._$_CKEDITOR_UPDATE_INSTANCES,e._createPreview(),e._$_CKEDITOR_MODAL_SHOW()}))}},{key:"_createPreview",value:(i=regeneratorRuntime.mark((function e(){var t,n,a,i,o,c,l,s,u;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.modal.querySelector(".ui.loadable").classList.add("loading"),this.modal.disabled=!0,t=document.querySelector("[".concat(this.channelSelector,"]")).value,n=document.querySelector("[".concat(this.localeSelector,"]")).value,a=this.button.dataset.url,i=this.button.closest("form"),o={method:"POST",body:new FormData(i)},e.prev=7,r(this.modal,"cms.create.preview.start"),e.next=11,fetch("".concat(a,"?_channel_code=").concat(t,"&_locale=").concat(n),o);case 11:return c=e.sent,e.next=14,c.text();case 14:l=e.sent,s=new Blob([l],{type:"text/html",charset:"utf-8"}),u=window.URL.createObjectURL(s),this.modal.querySelector("iframe").src=u,r(this.modal,"cms.create.preview.completed",l),e.next=25;break;case 21:e.prev=21,e.t0=e.catch(7),console.error("BitBag CMS Plugin - HandlePreview class error : ".concat(e.t0)),r(this.modal,"cms.create.preview.error",e.t0);case 25:return e.prev=25,this.modal.querySelector(".ui.loadable").classList.remove("loading"),this.modal.disabled=!1,r(this.modal,"cms.create.preview.end"),e.finish(25);case 30:case"end":return e.stop()}}),e,this,[[7,21,25,30]])})),o=function(){var e=this,t=arguments;return new Promise((function(n,a){var r=i.apply(e,t);function o(e){d(r,n,a,o,c,"next",e)}function c(e){d(r,n,a,o,c,"throw",e)}o(void 0)}))},function(){return o.apply(this,arguments)})}],n&&v(t.prototype,n),a&&v(t,a),e}();function y(e,t,n,a,r,i,o){try{var c=e[i](o),l=c.value}catch(e){return void n(e)}c.done?t(l):Promise.resolve(l).then(a,r)}function g(e){return function(){var t=this,n=arguments;return new Promise((function(a,r){var i=e.apply(t,n);function o(e){y(i,a,r,o,c,"next",e)}function c(e){y(i,a,r,o,c,"throw",e)}o(void 0)}))}}function S(e){return S="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},S(e)}function w(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{bbMediaContainer:"data-bb-cms-autocomplete",choiceName:"data-bb-cms-choice-name",choiceValue:"data-bb-cms-choice-value",criteriaType:"data-bb-cms-criteria-type",criteriaName:"data-bb-cms-criteria-name",editUrl:"data-bb-cms-load-edit-url",nameMessage:"data-bb-cms-name-message",deleteButton:"data-bb-cms-delete-selected",choosenPreview:"data-bb-cms-selected-image",selectMenu:"data-bb-cms-selection-menu",selectInput:"data-bb-cms-image-select",placeholder:"data-bb-cms-placeholder",limit:30};w(this,e),this.config=t,this.mediaContainer=document.querySelector("[".concat(t.bbMediaContainer,"]")),this.deleteButton=document.querySelector("[".concat(t.deleteButton,"]")),this.selectMenu=document.querySelector("[".concat(t.selectMenu,"]")),this.selectInput=document.querySelector("[".concat(t.selectInput,"]")),this.placeholder=document.querySelector("[".concat(t.placeholder,"]")),this.hiddenInput=this.mediaContainer.querySelector("input[type=hidden]")}var t,n,a,i,o;return t=e,n=[{key:"init",value:function(){if("object"!==S(this.config))throw new Error("Bitbag CMS Plugin - HandleAutoComplete class config is not a valid object");this._handleSavedValue(),this._handleImageChoice(),this._handleResetBtn()}},{key:"_handleResetBtn",value:function(){var e=this;""!==this.hiddenInput.value?(this.deleteButton.classList.remove("is-hidden"),this.deleteButton.addEventListener("click",(function(t){e._resetValues()}))):this.deleteButton.classList.add("is-hidden")}},{key:"_handleImageChoice",value:function(){var e=this;this.selectInput.addEventListener("click",(function(t){t.preventDefault(),e._getMediaImages()})),this.hiddenInput.addEventListener("change",(function(t){t.preventDefault(),e._handleResetBtn()}))}},{key:"_handleSavedValue",value:(o=g(regeneratorRuntime.mark((function e(){var t,n,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(""!==this.hiddenInput.value){e.next=2;break}return e.abrupt("return");case 2:return t="".concat(this.mediaContainer.dataset.bbCmsLoadEditUrl,"?code=").concat(this.hiddenInput.value),e.prev=3,r(this.mediaContainer,"cms.media.saved.reload.start"),this.mediaContainer.classList.add("loading"),e.next=8,fetch(t);case 8:return n=e.sent,e.next=11,n.json();case 11:a=e.sent,this._addToSelectMenu(a),this.selectMenu.firstChild.click(),r(this.mediaContainer,"cms.media.saved.reload.completed",a),e.next=21;break;case 17:e.prev=17,e.t0=e.catch(3),console.error("BitBag CMS Plugin - HandleAutoComplete class error : ".concat(e.t0)),r(this.mediaContainer,"cms.media.saved.reload.error",e.t0);case 21:return e.prev=21,this.mediaContainer.classList.remove("loading"),r(this.mediaContainer,"cms.media.saved.reload.end"),e.finish(21);case 25:case"end":return e.stop()}}),e,this,[[3,17,21,25]])}))),function(){return o.apply(this,arguments)})},{key:"_getMediaImages",value:(i=g(regeneratorRuntime.mark((function e(){var t,n,a,i,o,c;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=this.mediaContainer.dataset.bbCmsUrl,n=this.mediaContainer.dataset.bbCmsCriteriaType,a="".concat(t,"&limit=").concat(this.config.limit,"&criteria[search][type]=").concat(n),e.prev=3,r(this.mediaContainer,"cms.media.display.start"),this.mediaContainer.classList.add("loading"),e.next=8,fetch(a);case 8:return i=e.sent,e.next=11,i.json();case 11:o=e.sent,c=o._embedded.items,this._addToSelectMenu(c),r(this.mediaContainer,"cms.media.display.completed",o),e.next=21;break;case 17:e.prev=17,e.t0=e.catch(3),console.error("BitBag CMS Plugin - HandleAutoComplete class error : ".concat(e.t0)),r(this.mediaContainer,"cms.media.display.error",e.t0);case 21:return e.prev=21,this.mediaContainer.classList.remove("loading"),r(this.mediaContainer,"cms.media.display.end"),e.finish(21);case 25:case"end":return e.stop()}}),e,this,[[3,17,21,25]])}))),function(){return i.apply(this,arguments)})},{key:"_resetValues",value:function(){r(this.mediaContainer,"cms.media.reset.start"),this.hiddenInput.value="",this.selectMenu.innerHTML="",this.placeholder.innerHTML="",r(this.mediaContainer,"cms.media.reset.end")}},{key:"_addToSelectMenu",value:function(e){var t=this;r(this.mediaContainer,"cms.media.display.update.start"),this.selectMenu.innerHTML="",e.forEach((function(e){t.selectMenu.insertAdjacentHTML("beforeend",t._itemTemplate(e.path,e.code.trim()))})),r(this.mediaContainer,"cms.media.display.update.end")}},{key:"_itemTemplate",value:function(e,t){return'
').concat(t,"
")}}],n&&_(t.prototype,n),a&&_(t,a),e}();var k;document.querySelector('[data-bb-target="cms-import"]')&&(new a).init(),(null===(k=document.querySelectorAll('[data-bb-target="cms-slug-update"]'))||void 0===k?void 0:k.length)>0&&(new u).init(),document.querySelectorAll("[data-bb-cms-preview-btn]").length>0&&(new b).init(),document.querySelector('[data-bb-target="cms-handle-autocomplete"]')&&(new C).init()})(); \ No newline at end of file +(()=>{"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{textField:"data-bb-cms-text",fileField:"data-bb-cms-file"};t(this,a),this.config=e,this.textField=document.querySelector("[".concat(e.textField,"]")),this.fileField=document.querySelector("[".concat(e.fileField,"]"))}var r,i,o;return r=a,(i=[{key:"init",value:function(){if("object"!==e(this.config))throw new Error("Bitbag CMS Plugin - HandleCsvUpload class config is not a valid object");this._handleFields()}},{key:"_handleFields",value:function(){this._handleTextField(),this._handleFileField()}},{key:"_handleTextField",value:function(){var e=this;this.textField.addEventListener("click",(function(){e.fileField.click()}))}},{key:"_handleFileField",value:function(){var e=this;this.fileField.addEventListener("change",(function(t){e.textField.value=t.target.files[0].name}))}}])&&n(r.prototype,i),o&&n(r,o),a}();const r=function(e,t,n){var a=new CustomEvent("".concat("bb",".").concat(t),{detail:n});return e.dispatchEvent(a),e};function i(e,t,n,a,r,i,o){try{var c=e[i](o),l=c.value}catch(e){return void n(e)}c.done?t(l):Promise.resolve(l).then(a,r)}function o(e){return function(){var t=this,n=arguments;return new Promise((function(a,r){var o=e.apply(t,n);function c(e){i(o,a,r,c,l,"next",e)}function l(e){i(o,a,r,c,l,"throw",e)}c(void 0)}))}}function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{wrappersIndicator:"data-bb-cms-wrapper",lockFieldIndicator:"data-bb-cms-toggle-slug",bbTarget:"bitbag_sylius_cms_plugin_page"};l(this,e),this.wrappers=document.querySelectorAll("[".concat(t.wrappersIndicator,"]")),this.lockFieldIndicator="[".concat(t.lockFieldIndicator,"]"),this.bbTarget=t.bbTarget,this.config=t}var t,n,a,i,u;return t=e,n=[{key:"init",value:function(){if("object"!==c(this.config))throw new Error("Bitbag CMS Plugin - HandleSlugUpdate class config is not a valid object");if("string"!=typeof this.lockFieldIndicator||"string"!=typeof this.bbTarget)throw new Error("Bitbag CMS Plugin - HandleSlugUpdate class config key values are not valid strings");this._handleFields()}},{key:"_handleFields",value:function(){var e=this;this.wrappers.forEach((function(t){var n,a=t.dataset.locale,r=t.querySelector("#".concat(e.bbTarget,"_translations_").concat(a,"_name")),i=t.querySelector("#".concat(e.bbTarget,"_translations_").concat(a,"_slug")),o=t.querySelector(e.lockFieldIndicator);r&&i&&a&&(r.addEventListener("input",(function(t){t.preventDefault(),i.readOnly||(clearTimeout(n),n=setTimeout((function(){e._updateSlug(i,r.value)}),1e3))})),o&&o.addEventListener("click",(function(t){t.preventDefault(),e._toggleSlugModification(i,o)})))}))}},{key:"_updateSlug",value:(u=o(regeneratorRuntime.mark((function e(t,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r(t,"cms.slug.update.start"),t.parentNode.classList.add("loading"),e.next=4,this._getValidSlug(t.dataset.url,n);case 4:t.value=e.sent,t.parentNode.classList.remove("loading"),r(t,"cms.slug.update.end");case 7:case"end":return e.stop()}}),e,this)}))),function(e,t){return u.apply(this,arguments)})},{key:"_getValidSlug",value:(i=o(regeneratorRuntime.mark((function e(t,n){var a,r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,fetch("".concat(t,"?name=").concat(n));case 3:return a=e.sent,e.next=6,a.json();case 6:return r=e.sent,e.abrupt("return",r.slug);case 10:e.prev=10,e.t0=e.catch(0),console.error("BitBag CMS Plugin - HandleSlugUpdate class error : ".concat(e.t0));case 13:case"end":return e.stop()}}),e,null,[[0,10]])}))),function(e,t){return i.apply(this,arguments)})},{key:"_toggleSlugModification",value:function(e,t){e.readOnly=!e.readOnly;var n=t.querySelector("i");n.classList.toggle("lock"),n.classList.toggle("unlock")}}],n&&s(t.prototype,n),a&&s(t,a),e}();function d(e,t,n,a,r,i,o){try{var c=e[i](o),l=c.value}catch(e){return void n(e)}c.done?t(l):Promise.resolve(l).then(a,r)}function m(e){return function(e){if(Array.isArray(e))return h(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return h(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return h(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:{previewButton:"data-bb-cms-preview-btn",previewModal:"data-bb-cms-preview-modal",channelSwitch:"data-bb-cms-channel",localeSwitch:"data-bb-cms-locale"};p(this,e),this.config=t,this.button=document.querySelector("[".concat(t.previewButton,"]")),this.modal=document.querySelector("[".concat(t.previewModal,"]")),this.modalSelector=t.previewModal,this.channelSelector=t.channelSwitch,this.localeSelector=t.localeSwitch}var t,n,a,i,o;return t=e,n=[{key:"init",value:function(){if("object"!==f(this.config))throw new Error("Bitbag CMS Plugin - HandlePreview class config is not a valid object");if("string"!=typeof this.localeSelector||"string"!=typeof this.channelSelector||"string"!=typeof this.modalSelector)throw new Error("Bitbag CMS Plugin - HandlePreview class config key values are not valid strings");this._resourcePreview()}},{key:"_$_CKEDITOR_MODAL_SHOW",value:function(){return $("[".concat(this.modalSelector,"]")).modal("show")}},{key:"_$_CKEDITOR_UPDATE_INSTANCES",value:function(){m(CKEDITOR.instances).forEach((function(e){return e.updateElement()}))}},{key:"_resourcePreview",value:function(){var e=this;this.button.addEventListener("click",(function(t){t.preventDefault(),e._$_CKEDITOR_UPDATE_INSTANCES,e._createPreview(),e._$_CKEDITOR_MODAL_SHOW()})),document.querySelector("[".concat(this.channelSelector,"]")).addEventListener("change",(function(t){t.preventDefault(),e._$_CKEDITOR_UPDATE_INSTANCES,e._createPreview(),e._$_CKEDITOR_MODAL_SHOW()})),document.querySelector("[".concat(this.localeSelector,"]")).addEventListener("change",(function(t){t.preventDefault(),e._$_CKEDITOR_UPDATE_INSTANCES,e._createPreview(),e._$_CKEDITOR_MODAL_SHOW()}))}},{key:"_createPreview",value:(i=regeneratorRuntime.mark((function e(){var t,n,a,i,o,c,l,s,u;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.modal.querySelector(".ui.loadable").classList.add("loading"),this.modal.disabled=!0,t=document.querySelector("[".concat(this.channelSelector,"]")).value,n=document.querySelector("[".concat(this.localeSelector,"]")).value,a=this.button.dataset.url,i=this.button.closest("form"),o={method:"POST",body:new FormData(i)},e.prev=7,r(this.modal,"cms.create.preview.start"),e.next=11,fetch("".concat(a,"?_channel_code=").concat(t,"&_locale=").concat(n),o);case 11:return c=e.sent,e.next=14,c.text();case 14:l=e.sent,s=new Blob([l],{type:"text/html",charset:"utf-8"}),u=window.URL.createObjectURL(s),this.modal.querySelector("iframe").src=u,r(this.modal,"cms.create.preview.completed",l),e.next=25;break;case 21:e.prev=21,e.t0=e.catch(7),console.error("BitBag CMS Plugin - HandlePreview class error : ".concat(e.t0)),r(this.modal,"cms.create.preview.error",e.t0);case 25:return e.prev=25,this.modal.querySelector(".ui.loadable").classList.remove("loading"),this.modal.disabled=!1,r(this.modal,"cms.create.preview.end"),e.finish(25);case 30:case"end":return e.stop()}}),e,this,[[7,21,25,30]])})),o=function(){var e=this,t=arguments;return new Promise((function(n,a){var r=i.apply(e,t);function o(e){d(r,n,a,o,c,"next",e)}function c(e){d(r,n,a,o,c,"throw",e)}o(void 0)}))},function(){return o.apply(this,arguments)})}],n&&v(t.prototype,n),a&&v(t,a),e}();function y(e,t,n,a,r,i,o){try{var c=e[i](o),l=c.value}catch(e){return void n(e)}c.done?t(l):Promise.resolve(l).then(a,r)}function g(e){return function(){var t=this,n=arguments;return new Promise((function(a,r){var i=e.apply(t,n);function o(e){y(i,a,r,o,c,"next",e)}function c(e){y(i,a,r,o,c,"throw",e)}o(void 0)}))}}function S(e){return S="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},S(e)}function w(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{bbMediaContainer:"data-bb-cms-autocomplete",choiceName:"data-bb-cms-choice-name",choiceValue:"data-bb-cms-choice-value",criteriaType:"data-bb-cms-criteria-type",criteriaName:"data-bb-cms-criteria-name",editUrl:"data-bb-cms-load-edit-url",nameMessage:"data-bb-cms-name-message",deleteButton:"data-bb-cms-delete-selected",choosenPreview:"data-bb-cms-selected-image",selectMenu:"data-bb-cms-selection-menu",selectInput:"data-bb-cms-image-select",placeholder:"data-bb-cms-placeholder",limit:30};w(this,e),this.config=t,this.mediaContainer=document.querySelector("[".concat(t.bbMediaContainer,"]")),this.deleteButton=document.querySelector("[".concat(t.deleteButton,"]")),this.selectMenu=document.querySelector("[".concat(t.selectMenu,"]")),this.selectInput=document.querySelector("[".concat(t.selectInput,"]")),this.placeholder=document.querySelector("[".concat(t.placeholder,"]")),this.hiddenInput=this.mediaContainer.querySelector("input[type=hidden]")}var t,n,a,i,o;return t=e,n=[{key:"init",value:function(){if("object"!==S(this.config))throw new Error("Bitbag CMS Plugin - HandleAutoComplete class config is not a valid object");this._handleSavedValue(),this._handleImageChoice(),this._handleResetBtn()}},{key:"_handleResetBtn",value:function(){var e=this;""!==this.hiddenInput.value?(this.deleteButton.classList.remove("is-hidden"),this.deleteButton.addEventListener("click",(function(t){e._resetValues()}))):this.deleteButton.classList.add("is-hidden")}},{key:"_handleImageChoice",value:function(){var e=this;this.selectInput.addEventListener("click",(function(t){t.preventDefault(),e._getMediaImages()})),this.hiddenInput.addEventListener("change",(function(t){t.preventDefault(),e._handleResetBtn()}))}},{key:"_handleSavedValue",value:(o=g(regeneratorRuntime.mark((function e(){var t,n,a,i,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(""!==this.hiddenInput.value){e.next=2;break}return e.abrupt("return");case 2:return t="".concat(this.mediaContainer.dataset.bbCmsLoadEditUrl,"?code=").concat(this.hiddenInput.value),e.prev=3,r(this.mediaContainer,"cms.media.saved.reload.start"),this.mediaContainer.classList.add("loading"),e.next=8,fetch(t);case 8:return i=e.sent,e.next=11,i.json();case 11:o=e.sent,this._addToSelectMenu(o),null===(n=this.selectMenu)||void 0===n||null===(a=n.firstChild)||void 0===a||a.click(),r(this.mediaContainer,"cms.media.saved.reload.completed",o),e.next=21;break;case 17:e.prev=17,e.t0=e.catch(3),console.error("BitBag CMS Plugin - HandleAutoComplete class error : ".concat(e.t0)),r(this.mediaContainer,"cms.media.saved.reload.error",e.t0);case 21:return e.prev=21,this.mediaContainer.classList.remove("loading"),r(this.mediaContainer,"cms.media.saved.reload.end"),e.finish(21);case 25:case"end":return e.stop()}}),e,this,[[3,17,21,25]])}))),function(){return o.apply(this,arguments)})},{key:"_getMediaImages",value:(i=g(regeneratorRuntime.mark((function e(){var t,n,a,i,o,c;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=this.mediaContainer.dataset.bbCmsUrl,n=this.mediaContainer.dataset.bbCmsCriteriaType,a="".concat(t,"&limit=").concat(this.config.limit,"&criteria[search][type]=").concat(n),e.prev=3,r(this.mediaContainer,"cms.media.display.start"),this.mediaContainer.classList.add("loading"),e.next=8,fetch(a);case 8:return i=e.sent,e.next=11,i.json();case 11:o=e.sent,c=o._embedded.items,this._addToSelectMenu(c),r(this.mediaContainer,"cms.media.display.completed",o),e.next=21;break;case 17:e.prev=17,e.t0=e.catch(3),console.error("BitBag CMS Plugin - HandleAutoComplete class error : ".concat(e.t0)),r(this.mediaContainer,"cms.media.display.error",e.t0);case 21:return e.prev=21,this.mediaContainer.classList.remove("loading"),r(this.mediaContainer,"cms.media.display.end"),e.finish(21);case 25:case"end":return e.stop()}}),e,this,[[3,17,21,25]])}))),function(){return i.apply(this,arguments)})},{key:"_resetValues",value:function(){r(this.mediaContainer,"cms.media.reset.start"),this.hiddenInput.value="",this.selectMenu.innerHTML="",this.placeholder.innerHTML="",r(this.mediaContainer,"cms.media.reset.end")}},{key:"_addToSelectMenu",value:function(e){var t=this;r(this.mediaContainer,"cms.media.display.update.start"),this.selectMenu.innerHTML="",null==e||e.forEach((function(e){t.selectMenu.insertAdjacentHTML("beforeend",t._itemTemplate(e.path,e.code.trim()))})),r(this.mediaContainer,"cms.media.display.update.end")}},{key:"_itemTemplate",value:function(e,t){return'
').concat(t,"
")}}],n&&_(t.prototype,n),a&&_(t,a),e}();var k;document.querySelector('[data-bb-target="cms-import"]')&&(new a).init(),(null===(k=document.querySelectorAll('[data-bb-target="cms-slug-update"]'))||void 0===k?void 0:k.length)>0&&(new u).init(),document.querySelectorAll("[data-bb-cms-preview-btn]").length>0&&(new b).init(),document.querySelector('[data-bb-target="cms-handle-autocomplete"]')&&(new C).init()})(); \ No newline at end of file diff --git a/src/Resources/public/build/manifest.json b/src/Resources/public/build/manifest.json index 4a3704191..fe4d82bd6 100644 --- a/src/Resources/public/build/manifest.json +++ b/src/Resources/public/build/manifest.json @@ -3,4 +3,4 @@ "public/build/bitbag-cms-shop.js": "/public/build/bitbag-cms-shop.js", "public/build/bitbag-cms-admin.css": "/public/build/bitbag-cms-admin.css", "public/build/bitbag-cms-admin.js": "/public/build/bitbag-cms-admin.js" -} +} \ No newline at end of file