From 7a1fd857ca9e84dd15bb000fbc6c8a0455609141 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Thu, 15 Jul 2021 12:23:47 +0200 Subject: [PATCH] Fix page composer validation --- assets/src/js/composer.js | 3 +++ src/Resources/public/sonata-page.back.js | 3 +++ src/Resources/public/sonata-page.back.min.js | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/assets/src/js/composer.js b/assets/src/js/composer.js index ad6506a93..3595c755a 100644 --- a/assets/src/js/composer.js +++ b/assets/src/js/composer.js @@ -385,6 +385,9 @@ url: formAction + '&' + $.param({'composer': 1}), data: $form.serialize(), type: formMethod, + headers: { + Accept: 'text/html, application/xhtml+xml;' + }, success: function (resp) { if (resp.result && resp.result === 'ok' && resp.objectId) { var createdEvent = $.Event('blockcreated'); diff --git a/src/Resources/public/sonata-page.back.js b/src/Resources/public/sonata-page.back.js index 65a94e611..6c89c0a6e 100644 --- a/src/Resources/public/sonata-page.back.js +++ b/src/Resources/public/sonata-page.back.js @@ -393,6 +393,9 @@ url: formAction + '&' + $.param({'composer': 1}), data: $form.serialize(), type: formMethod, + headers: { + Accept: 'text/html, application/xhtml+xml;' + }, success: function (resp) { if (resp.result && resp.result === 'ok' && resp.objectId) { var createdEvent = $.Event('blockcreated'); diff --git a/src/Resources/public/sonata-page.back.min.js b/src/Resources/public/sonata-page.back.min.js index 848cc4554..4193eb8b3 100644 --- a/src/Resources/public/sonata-page.back.min.js +++ b/src/Resources/public/sonata-page.back.min.js @@ -6,4 +6,4 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -!function(e,t){function n(e){"undefined"==typeof t.admin&&Admin.shared_setup(e)}var o=function(t,n){var o=n||{};this.pageId=t,this.$container=e(".page-composer"),this.$dynamicArea=e(".page-composer__dyn-content"),this.$pagePreview=e(".page-composer__page-preview"),this.$containerPreviews=this.$pagePreview.find(".page-composer__page-preview__container"),this.routes=e.extend({},o.routes||{}),this.translations=e.extend({},o.translations||{}),this.csrfTokens=e.extend({},o.csrfTokens||{}),this.bindPagePreviewHandlers(),this.bindOrphansHandlers();var i=this,a=e(this);a.on("containerclick",function(e){i.loadContainer(e.$container)}),a.on("containerloaded",this.handleContainerLoaded),a.on("blockcreated",this.handleBlockCreated),a.on("blockremoved",this.handleBlockRemoved),a.on("blockcreateformloaded",this.handleBlockCreateFormLoaded),a.on("blockpositionsupdate",this.handleBlockPositionsUpdate),a.on("blockeditformloaded",this.handleBlockEditFormLoaded),a.on("blockparentswitched",this.handleBlockParentSwitched)};o.prototype={translate:function(e){return this.translations[e]?this.translations[e]:e},getRouteUrl:function(e,t){if(!this.routes[e])throw new Error('Route "'+e+'" does not exist');var n=this.routes[e];for(var o in t)n=n.replace(new RegExp(o),t[o]);return n},isFormControlTypeByName:function(e,t){if("undefined"!=typeof e){var n=e.length,o="["+t+"]",i=e.lastIndexOf(o),n=n-o.length;return i!==-1&&i===n}return!1},handleBlockCreated:function(t){var n=this;e.ajax({url:this.getRouteUrl("block_preview",{BLOCK_ID:t.blockId}),type:"GET",success:function(o){var i=e(o);t.$childBlock.replaceWith(i),n.controlChildBlock(i);var a=n.getContainerChildCountFromList(t.parentId);null!==a&&n.updateChildCount(t.parentId,a)},error:function(){n.containerNotification("composer_preview_error","error",!0)}})},handleBlockRemoved:function(e){var t=this.getContainerChildCountFromList(e.parentId);null!==t&&this.updateChildCount(e.parentId,t)},containerNotification:function(t,n,o){var i=this.$dynamicArea.find(".page-composer__container__view__notice");if(1===i.length)if(this.containerNotificationTimer&&clearTimeout(this.containerNotificationTimer),i.removeClass("persist success error"),n&&i.addClass(n),i.text(this.translate(t)),i.show(),o!==!0)this.containerNotificationTimer=setTimeout(function(){i.hide().empty()},2e3);else{var a=e('x');a.on("click",function(){i.hide().empty()}),i.addClass("persist"),i.append(a)}},handleBlockPositionsUpdate:function(t){var n=this;this.containerNotification("composer_update_saving"),e.ajax({url:this.getRouteUrl("save_blocks_positions"),type:"POST",data:{disposition:t.disposition},success:function(e){e.result&&"ok"===e.result&&n.containerNotification("composer_update_saved","success")},error:function(){n.containerNotification("composer_update_error","error",!0)}})},handleBlockParentSwitched:function(t){var n=e(".block-preview-"+t.previousParentId),o=n.find(".child-count"),i=parseInt(o.text().trim(),10),a=e(".block-preview-"+t.newParentId),r=a.find(".child-count"),c=parseInt(r.text().trim(),10);this.updateChildCount(t.previousParentId,i-1),this.updateChildCount(t.newParentId,c+1)},getContainerChildCountFromList:function(t){var n=this.$dynamicArea.find(".block-view-"+t);if(0===n.length)return null;var o=n.find(".page-composer__container__child"),i=0;return o.each(function(){var t=e(this),n=t.attr("data-block-id");"undefined"!=typeof n&&i++}),i},updateChildCount:function(t,n){var o=e(".block-preview-"+t),i=e(".block-view-"+t);o.length>0&&o.find(".child-count").text(n),i.length>0&&i.find(".page-composer__container__child-count span").text(n)},handleBlockCreateFormLoaded:function(t){var o=this,i=this.$dynamicArea.find(".page-composer__container__children"),a=this.$dynamicArea.find(".page-composer__container__main-edition-area");if(t.container){var r=t.container,c=r.find(".page-composer__container__child__content");c.html(t.response)}else{var r=e(['
  • ','','

    ','',"

    ","
    ",'
    ',''+t.blockTypeLabel+"","
    ",'
    ',"
    ","
  • "].join("")),c=r.find(".page-composer__container__child__content");c.append(t.response),i.append(r),c.show()}var s,l,d,p=r.find("form"),_=p.attr("action"),h=p.attr("method"),u=p.find("input, select, textarea"),f=p.find(".form-actions"),m=this.$dynamicArea.find(".page-composer__container__child__name");n(p),e(document).scrollTo(r,200),a.show(),u.each(function(){var n=e(this),a=n.attr("name");o.isFormControlTypeByName(a,"name")?(s=n,m.find(".page-composer__container__child__name__input").bind("propertychange keyup input paste",function(t){s.val(e(this).val())})):o.isFormControlTypeByName(a,"parent")?(l=n,l.val(t.containerId),l.parent().parent().hide()):o.isFormControlTypeByName(a,"position")&&(d=n,d.val(i.find("> *").length),d.closest(".form-group").hide())}),f.each(function(){var t=e(this),n=e(''+o.translate("cancel")+"");n.on("click",function(t){t.preventDefault(),r.remove(),e(document).scrollTo(o.$dynamicArea,200)}),t.append(n)}),p.on("submit",function(i){i.preventDefault();var a=s.val();return""===a&&(a=t.blockType),e.ajax({url:_+"&"+e.param({composer:1}),data:p.serialize(),type:h,success:function(i){if(i.result&&"ok"===i.result&&i.objectId){var s=e.Event("blockcreated");s.$childBlock=r,s.parentId=t.containerId,s.blockId=i.objectId,s.blockName=a,s.blockType=t.blockType,e(o).trigger(s)}else{var l=e.Event("blockcreateformloaded");l.response=i,l.containerId=t.containerId,l.blockType=t.blockType,l.container=r,e(o).trigger(l),n(c)}}}),!1})},toggleChildBlock:function(e){var t="page-composer__container__child--expanded",n=this.$dynamicArea.find(".page-composer__container__child"),o=e.find(".page-composer__container__child__name"),i=o.find(".page-composer__container__child__name__input");e.hasClass(t)?(e.removeClass(t),o.has(".page-composer__container__child__name__input")&&o.html(i.val())):(n.not(e).removeClass(t),e.addClass(t))},handleBlockEditFormLoaded:function(t){var o,i,a=this,r=t.$block.find(".page-composer__container__child__edit h4"),c=t.$block.find(".page-composer__container__child__content"),s=t.$block.find(".page-composer__container__child__loader"),l=c.find("form"),d=l.attr("action"),p=l.attr("method"),_=t.$block.find(".page-composer__container__child__edit small").text().trim();l.find("input").each(function(){var t=e(this),n=t.attr("name");a.isFormControlTypeByName(n,"name")?(o=t,r.html(''),$input=r.find("input"),$input.bind("propertychange keyup input paste",function(e){o.val($input.val())}),$input.on("click",function(e){e.stopPropagation(),e.preventDefault()})):a.isFormControlTypeByName(n,"position")&&(i=t,i.closest(".form-group").hide())}),l.on("submit",function(i){return i.preventDefault(),s.show(),e.ajax({url:d,data:l.serialize(),type:p,success:function(i){if(s.hide(),i.result&&"ok"===i.result)"undefined"!=typeof o&&r.text(""!==o.val()?o.val():_),t.$block.removeClass("page-composer__container__child--expanded"),c.empty();else{c.html(i);var l=e.Event("blockeditformloaded");l.$block=t.$block,e(a).trigger(l),n(c)}}}),!1})},controlChildBlock:function(t){var o=this,i=t.find(".page-composer__container__child__content"),a=t.find(".page-composer__container__child__loader"),r=t.find(".page-composer__container__child__edit"),c=r.attr("href"),s=t.find(".page-composer__container__child__remove"),l=s.find("a"),d=t.find(".page-composer__container__child__switch-enabled"),p=d.attr("data-label-enable"),_=d.attr("data-label-disable"),h=d.find("a"),u=h.find("i"),f=t.find(".page-composer__container__child__enabled"),m=f.find("small"),g=f.find("i"),v=h.attr("href"),b=parseInt(t.attr("data-block-enabled"),2);r.click(function(r){return r.preventDefault(),i.find("form").length>0?void o.toggleChildBlock(t):(a.show(),void e.ajax({url:c,success:function(r){i.html(r);var c=e.Event("blockeditformloaded");c.$block=t,e(o).trigger(c),n(i),a.hide(),o.toggleChildBlock(t)}}))}),h.on("click",function(n){n.preventDefault(),e.ajax({url:v,type:"POST",data:{_sonata_csrf_token:o.csrfTokens.switchEnabled,value:!b},success:function(n){if(t.attr("data-block-enabled",b?"0":"1"),b=!b,h.toggleClass("bg-yellow bg-green"),u.toggleClass("fa-toggle-off fa-toggle-on"),b?h.html(_):h.html(p),m.toggleClass("bg-yellow bg-green"),g.toggleClass("fa-times fa-check"),t.has("form")){var i=t.find("form"),a=i.find("input");a.each(function(){var t=e(this),n=t.attr("name");o.isFormControlTypeByName(n,"enabled")&&t.val(parseInt(!b))})}},error:function(){o.containerNotification("composer_status_error","error",!0)}})}),l.on("click",function(e){e.preventDefault(),o.confirmRemoveContainer(t)})},confirmRemoveContainer:function(t){var n=this,o=t.find(".page-composer__container__child__remove"),i=o.find("a"),a=t.find(".page-composer__container__child__remove__dialog"),r=i.attr("href"),c=parseInt(t.attr("data-parent-block-id"),10);0==a.length&&(a=e(['"].join("")),t.append(a));var s=a.find(".btn-primary");s.on("click",function(o){e.ajax({url:r,type:"POST",data:{_method:"DELETE",_sonata_csrf_token:n.csrfTokens.remove},success:function(o){if(o.result&&"ok"===o.result){t.remove();var i=e.Event("blockremoved");i.parentId=c,e(n).trigger(i)}}}),a.modal("hide"),0!=e(".modal-backdrop").length&&e(".modal-backdrop").hide()}),a.modal("show")},handleContainerLoaded:function(t){var o=this,i=this.$dynamicArea.find(".page-composer__container__children"),a=this.$dynamicArea.find(".page-composer__container__child"),r=this.$dynamicArea.find(".page-composer__block-type-selector"),c=r.find(".page-composer__block-type-selector__loader"),s=r.find("select"),l=r.find(".page-composer__block-type-selector__confirm"),d=l.attr("href");n(this.$dynamicArea),l.on("click",function(n){n.preventDefault(),c.css("display","inline-block");var i=s.val(),a=s.find("option:selected").text().trim();e.ajax({url:d,data:{type:i},success:function(n){c.hide(),e(o).trigger(e.Event("blockcreateformloaded",{response:n,containerId:t.containerId,blockType:i,blockTypeLabel:a}))}})}),i.sortable({revert:!0,cursor:"move",revertDuration:200,delay:200,helper:function(t,n){var o=e(n),i=o.find(".page-composer__container__child__edit h4").text().trim();o.find(".page-composer__container__child__edit small").text().trim();return o.removeClass("page-composer__container__child--expanded"),e('

    '+i+"

    ")},update:function(t,n){var a=[];if(i.find(".page-composer__container__child").each(function(t){var n=e(this),i=n.attr("data-parent-block-id"),r=n.attr("data-block-id");"undefined"!=typeof r&&a.push({id:parseInt(r,10),position:t,parent_id:parseInt(i,10),page_id:o.pageId})}),a.length>0){var r=e.Event("blockpositionsupdate");r.disposition=a,e(o).trigger(r)}}}),a.each(function(){o.controlChildBlock(e(this))})},bindPagePreviewHandlers:function(){var t=this;this.$containerPreviews.each(function(){var n=e(this);n.on("click",function(o){o.preventDefault();var i=e.Event("containerclick");i.$container=n,e(t).trigger(i)})}).droppable({hoverClass:"hover",tolerance:"pointer",revert:!0,connectToSortable:".page-composer__container__children",accept:function(t){var n=e(this).attr("data-block-allowlist")||e(this).attr("data-block-whitelist");if(""===n)return!0;n=n.split(",");var o=e(t).attr("data-block-type");return n.indexOf(o)!==-1},drop:function(n,o){var i=o.draggable.attr("data-block-id");if("undefined"!=typeof i){o.helper.remove();var a=e(this),r=parseInt(o.draggable.attr("data-parent-block-id"),10),c=parseInt(a.attr("data-block-id"),10);i=parseInt(i,10),r!==c&&(a.addClass("dropped"),a.on("webkitAnimationEnd oanimationend msAnimationEnd animationend",function(e){a.removeClass("dropped")}),e.ajax({url:t.getRouteUrl("block_switch_parent"),data:{block_id:i,parent_id:c},success:function(n){if(n.result&&"ok"===n.result){o.draggable.remove();var a=e.Event("blockparentswitched");a.previousParentId=r,a.newParentId=c,a.blockId=i,e(t).trigger(a)}}}))}}}),this.$containerPreviews.length>0&&this.loadContainer(this.$containerPreviews.eq(0))},bindOrphansHandlers:function(){var t=this;this.$container.find(".page-composer__orphan-container").each(function(){var n=e(this);n.on("click",function(o){o.preventDefault();var i=e.Event("containerclick");i.$container=n,e(t).trigger(i)})})},loadContainer:function(t){var n=t.attr("href"),o=t.attr("data-block-id"),i=this;this.$dynamicArea.empty(),this.$containerPreviews.removeClass("active"),this.$container.find(".page-composer__orphan-container").removeClass("active"),t.addClass("active"),e.ajax({url:n,success:function(t){i.$dynamicArea.html(t),e(document).scrollTo(i.$dynamicArea,200,{offset:{top:-100}});var n=e.Event("containerloaded");n.containerId=o,e(i).trigger(n)}})}},t.PageComposer=o,e(function(){e("[data-page-composer]").each(function(){var t=e(this).data("page-composer");new o(t.pageId,t)})})}(jQuery,window),function(e,t,n,o){function i(t,n){this.element=t,this.options=e.extend({},c,n),this._defaults=c,this._name=a,this.init()}var a="treeView",r=".js-treeview",c={togglersAttribute:"[data-treeview-toggler]",toggledState:"is-toggled"};i.prototype={init:function(){this.setElements(),this.setEvents()},setElements:function(){this.$element=e(this.element),this.$togglers=this.$element.find(this.options.togglersAttribute)},setEvents:function(){this.$togglers.on("click",e.proxy(this.toggle,this))},toggle:function(t){var n=e(t.currentTarget),o=n.parent();o.toggleClass(this.options.toggledState),o.next("ul").slideToggle()}},e.fn[a]=function(t){return this.each(function(){e.data(this,"plugin_"+a)||e.data(this,"plugin_"+a,new i(this,t))})},e(function(){e(r)[a]()})}(jQuery,window,document); +!function(e,t){function n(e){"undefined"==typeof t.admin&&Admin.shared_setup(e)}var o=function(t,n){var o=n||{};this.pageId=t,this.$container=e(".page-composer"),this.$dynamicArea=e(".page-composer__dyn-content"),this.$pagePreview=e(".page-composer__page-preview"),this.$containerPreviews=this.$pagePreview.find(".page-composer__page-preview__container"),this.routes=e.extend({},o.routes||{}),this.translations=e.extend({},o.translations||{}),this.csrfTokens=e.extend({},o.csrfTokens||{}),this.bindPagePreviewHandlers(),this.bindOrphansHandlers();var i=this,a=e(this);a.on("containerclick",function(e){i.loadContainer(e.$container)}),a.on("containerloaded",this.handleContainerLoaded),a.on("blockcreated",this.handleBlockCreated),a.on("blockremoved",this.handleBlockRemoved),a.on("blockcreateformloaded",this.handleBlockCreateFormLoaded),a.on("blockpositionsupdate",this.handleBlockPositionsUpdate),a.on("blockeditformloaded",this.handleBlockEditFormLoaded),a.on("blockparentswitched",this.handleBlockParentSwitched)};o.prototype={translate:function(e){return this.translations[e]?this.translations[e]:e},getRouteUrl:function(e,t){if(!this.routes[e])throw new Error('Route "'+e+'" does not exist');var n=this.routes[e];for(var o in t)n=n.replace(new RegExp(o),t[o]);return n},isFormControlTypeByName:function(e,t){if("undefined"!=typeof e){var n=e.length,o="["+t+"]",i=e.lastIndexOf(o),n=n-o.length;return i!==-1&&i===n}return!1},handleBlockCreated:function(t){var n=this;e.ajax({url:this.getRouteUrl("block_preview",{BLOCK_ID:t.blockId}),type:"GET",success:function(o){var i=e(o);t.$childBlock.replaceWith(i),n.controlChildBlock(i);var a=n.getContainerChildCountFromList(t.parentId);null!==a&&n.updateChildCount(t.parentId,a)},error:function(){n.containerNotification("composer_preview_error","error",!0)}})},handleBlockRemoved:function(e){var t=this.getContainerChildCountFromList(e.parentId);null!==t&&this.updateChildCount(e.parentId,t)},containerNotification:function(t,n,o){var i=this.$dynamicArea.find(".page-composer__container__view__notice");if(1===i.length)if(this.containerNotificationTimer&&clearTimeout(this.containerNotificationTimer),i.removeClass("persist success error"),n&&i.addClass(n),i.text(this.translate(t)),i.show(),o!==!0)this.containerNotificationTimer=setTimeout(function(){i.hide().empty()},2e3);else{var a=e('x');a.on("click",function(){i.hide().empty()}),i.addClass("persist"),i.append(a)}},handleBlockPositionsUpdate:function(t){var n=this;this.containerNotification("composer_update_saving"),e.ajax({url:this.getRouteUrl("save_blocks_positions"),type:"POST",data:{disposition:t.disposition},success:function(e){e.result&&"ok"===e.result&&n.containerNotification("composer_update_saved","success")},error:function(){n.containerNotification("composer_update_error","error",!0)}})},handleBlockParentSwitched:function(t){var n=e(".block-preview-"+t.previousParentId),o=n.find(".child-count"),i=parseInt(o.text().trim(),10),a=e(".block-preview-"+t.newParentId),r=a.find(".child-count"),c=parseInt(r.text().trim(),10);this.updateChildCount(t.previousParentId,i-1),this.updateChildCount(t.newParentId,c+1)},getContainerChildCountFromList:function(t){var n=this.$dynamicArea.find(".block-view-"+t);if(0===n.length)return null;var o=n.find(".page-composer__container__child"),i=0;return o.each(function(){var t=e(this),n=t.attr("data-block-id");"undefined"!=typeof n&&i++}),i},updateChildCount:function(t,n){var o=e(".block-preview-"+t),i=e(".block-view-"+t);o.length>0&&o.find(".child-count").text(n),i.length>0&&i.find(".page-composer__container__child-count span").text(n)},handleBlockCreateFormLoaded:function(t){var o=this,i=this.$dynamicArea.find(".page-composer__container__children"),a=this.$dynamicArea.find(".page-composer__container__main-edition-area");if(t.container){var r=t.container,c=r.find(".page-composer__container__child__content");c.html(t.response)}else{var r=e(['
  • ','','

    ','',"

    ","
    ",'
    ',''+t.blockTypeLabel+"","
    ",'
    ',"
    ","
  • "].join("")),c=r.find(".page-composer__container__child__content");c.append(t.response),i.append(r),c.show()}var s,l,d,p=r.find("form"),_=p.attr("action"),h=p.attr("method"),u=p.find("input, select, textarea"),f=p.find(".form-actions"),m=this.$dynamicArea.find(".page-composer__container__child__name");n(p),e(document).scrollTo(r,200),a.show(),u.each(function(){var n=e(this),a=n.attr("name");o.isFormControlTypeByName(a,"name")?(s=n,m.find(".page-composer__container__child__name__input").bind("propertychange keyup input paste",function(t){s.val(e(this).val())})):o.isFormControlTypeByName(a,"parent")?(l=n,l.val(t.containerId),l.parent().parent().hide()):o.isFormControlTypeByName(a,"position")&&(d=n,d.val(i.find("> *").length),d.closest(".form-group").hide())}),f.each(function(){var t=e(this),n=e(''+o.translate("cancel")+"");n.on("click",function(t){t.preventDefault(),r.remove(),e(document).scrollTo(o.$dynamicArea,200)}),t.append(n)}),p.on("submit",function(i){i.preventDefault();var a=s.val();return""===a&&(a=t.blockType),e.ajax({url:_+"&"+e.param({composer:1}),data:p.serialize(),type:h,headers:{Accept:'text/html, application/xhtml+xml;'},success:function(i){if(i.result&&"ok"===i.result&&i.objectId){var s=e.Event("blockcreated");s.$childBlock=r,s.parentId=t.containerId,s.blockId=i.objectId,s.blockName=a,s.blockType=t.blockType,e(o).trigger(s)}else{var l=e.Event("blockcreateformloaded");l.response=i,l.containerId=t.containerId,l.blockType=t.blockType,l.container=r,e(o).trigger(l),n(c)}}}),!1})},toggleChildBlock:function(e){var t="page-composer__container__child--expanded",n=this.$dynamicArea.find(".page-composer__container__child"),o=e.find(".page-composer__container__child__name"),i=o.find(".page-composer__container__child__name__input");e.hasClass(t)?(e.removeClass(t),o.has(".page-composer__container__child__name__input")&&o.html(i.val())):(n.not(e).removeClass(t),e.addClass(t))},handleBlockEditFormLoaded:function(t){var o,i,a=this,r=t.$block.find(".page-composer__container__child__edit h4"),c=t.$block.find(".page-composer__container__child__content"),s=t.$block.find(".page-composer__container__child__loader"),l=c.find("form"),d=l.attr("action"),p=l.attr("method"),_=t.$block.find(".page-composer__container__child__edit small").text().trim();l.find("input").each(function(){var t=e(this),n=t.attr("name");a.isFormControlTypeByName(n,"name")?(o=t,r.html(''),$input=r.find("input"),$input.bind("propertychange keyup input paste",function(e){o.val($input.val())}),$input.on("click",function(e){e.stopPropagation(),e.preventDefault()})):a.isFormControlTypeByName(n,"position")&&(i=t,i.closest(".form-group").hide())}),l.on("submit",function(i){return i.preventDefault(),s.show(),e.ajax({url:d,data:l.serialize(),type:p,success:function(i){if(s.hide(),i.result&&"ok"===i.result)"undefined"!=typeof o&&r.text(""!==o.val()?o.val():_),t.$block.removeClass("page-composer__container__child--expanded"),c.empty();else{c.html(i);var l=e.Event("blockeditformloaded");l.$block=t.$block,e(a).trigger(l),n(c)}}}),!1})},controlChildBlock:function(t){var o=this,i=t.find(".page-composer__container__child__content"),a=t.find(".page-composer__container__child__loader"),r=t.find(".page-composer__container__child__edit"),c=r.attr("href"),s=t.find(".page-composer__container__child__remove"),l=s.find("a"),d=t.find(".page-composer__container__child__switch-enabled"),p=d.attr("data-label-enable"),_=d.attr("data-label-disable"),h=d.find("a"),u=h.find("i"),f=t.find(".page-composer__container__child__enabled"),m=f.find("small"),g=f.find("i"),v=h.attr("href"),b=parseInt(t.attr("data-block-enabled"),2);r.click(function(r){return r.preventDefault(),i.find("form").length>0?void o.toggleChildBlock(t):(a.show(),void e.ajax({url:c,success:function(r){i.html(r);var c=e.Event("blockeditformloaded");c.$block=t,e(o).trigger(c),n(i),a.hide(),o.toggleChildBlock(t)}}))}),h.on("click",function(n){n.preventDefault(),e.ajax({url:v,type:"POST",data:{_sonata_csrf_token:o.csrfTokens.switchEnabled,value:!b},success:function(n){if(t.attr("data-block-enabled",b?"0":"1"),b=!b,h.toggleClass("bg-yellow bg-green"),u.toggleClass("fa-toggle-off fa-toggle-on"),b?h.html(_):h.html(p),m.toggleClass("bg-yellow bg-green"),g.toggleClass("fa-times fa-check"),t.has("form")){var i=t.find("form"),a=i.find("input");a.each(function(){var t=e(this),n=t.attr("name");o.isFormControlTypeByName(n,"enabled")&&t.val(parseInt(!b))})}},error:function(){o.containerNotification("composer_status_error","error",!0)}})}),l.on("click",function(e){e.preventDefault(),o.confirmRemoveContainer(t)})},confirmRemoveContainer:function(t){var n=this,o=t.find(".page-composer__container__child__remove"),i=o.find("a"),a=t.find(".page-composer__container__child__remove__dialog"),r=i.attr("href"),c=parseInt(t.attr("data-parent-block-id"),10);0==a.length&&(a=e(['"].join("")),t.append(a));var s=a.find(".btn-primary");s.on("click",function(o){e.ajax({url:r,type:"POST",data:{_method:"DELETE",_sonata_csrf_token:n.csrfTokens.remove},success:function(o){if(o.result&&"ok"===o.result){t.remove();var i=e.Event("blockremoved");i.parentId=c,e(n).trigger(i)}}}),a.modal("hide"),0!=e(".modal-backdrop").length&&e(".modal-backdrop").hide()}),a.modal("show")},handleContainerLoaded:function(t){var o=this,i=this.$dynamicArea.find(".page-composer__container__children"),a=this.$dynamicArea.find(".page-composer__container__child"),r=this.$dynamicArea.find(".page-composer__block-type-selector"),c=r.find(".page-composer__block-type-selector__loader"),s=r.find("select"),l=r.find(".page-composer__block-type-selector__confirm"),d=l.attr("href");n(this.$dynamicArea),l.on("click",function(n){n.preventDefault(),c.css("display","inline-block");var i=s.val(),a=s.find("option:selected").text().trim();e.ajax({url:d,data:{type:i},success:function(n){c.hide(),e(o).trigger(e.Event("blockcreateformloaded",{response:n,containerId:t.containerId,blockType:i,blockTypeLabel:a}))}})}),i.sortable({revert:!0,cursor:"move",revertDuration:200,delay:200,helper:function(t,n){var o=e(n),i=o.find(".page-composer__container__child__edit h4").text().trim();o.find(".page-composer__container__child__edit small").text().trim();return o.removeClass("page-composer__container__child--expanded"),e('

    '+i+"

    ")},update:function(t,n){var a=[];if(i.find(".page-composer__container__child").each(function(t){var n=e(this),i=n.attr("data-parent-block-id"),r=n.attr("data-block-id");"undefined"!=typeof r&&a.push({id:parseInt(r,10),position:t,parent_id:parseInt(i,10),page_id:o.pageId})}),a.length>0){var r=e.Event("blockpositionsupdate");r.disposition=a,e(o).trigger(r)}}}),a.each(function(){o.controlChildBlock(e(this))})},bindPagePreviewHandlers:function(){var t=this;this.$containerPreviews.each(function(){var n=e(this);n.on("click",function(o){o.preventDefault();var i=e.Event("containerclick");i.$container=n,e(t).trigger(i)})}).droppable({hoverClass:"hover",tolerance:"pointer",revert:!0,connectToSortable:".page-composer__container__children",accept:function(t){var n=e(this).attr("data-block-allowlist")||e(this).attr("data-block-whitelist");if(""===n)return!0;n=n.split(",");var o=e(t).attr("data-block-type");return n.indexOf(o)!==-1},drop:function(n,o){var i=o.draggable.attr("data-block-id");if("undefined"!=typeof i){o.helper.remove();var a=e(this),r=parseInt(o.draggable.attr("data-parent-block-id"),10),c=parseInt(a.attr("data-block-id"),10);i=parseInt(i,10),r!==c&&(a.addClass("dropped"),a.on("webkitAnimationEnd oanimationend msAnimationEnd animationend",function(e){a.removeClass("dropped")}),e.ajax({url:t.getRouteUrl("block_switch_parent"),data:{block_id:i,parent_id:c},success:function(n){if(n.result&&"ok"===n.result){o.draggable.remove();var a=e.Event("blockparentswitched");a.previousParentId=r,a.newParentId=c,a.blockId=i,e(t).trigger(a)}}}))}}}),this.$containerPreviews.length>0&&this.loadContainer(this.$containerPreviews.eq(0))},bindOrphansHandlers:function(){var t=this;this.$container.find(".page-composer__orphan-container").each(function(){var n=e(this);n.on("click",function(o){o.preventDefault();var i=e.Event("containerclick");i.$container=n,e(t).trigger(i)})})},loadContainer:function(t){var n=t.attr("href"),o=t.attr("data-block-id"),i=this;this.$dynamicArea.empty(),this.$containerPreviews.removeClass("active"),this.$container.find(".page-composer__orphan-container").removeClass("active"),t.addClass("active"),e.ajax({url:n,success:function(t){i.$dynamicArea.html(t),e(document).scrollTo(i.$dynamicArea,200,{offset:{top:-100}});var n=e.Event("containerloaded");n.containerId=o,e(i).trigger(n)}})}},t.PageComposer=o,e(function(){e("[data-page-composer]").each(function(){var t=e(this).data("page-composer");new o(t.pageId,t)})})}(jQuery,window),function(e,t,n,o){function i(t,n){this.element=t,this.options=e.extend({},c,n),this._defaults=c,this._name=a,this.init()}var a="treeView",r=".js-treeview",c={togglersAttribute:"[data-treeview-toggler]",toggledState:"is-toggled"};i.prototype={init:function(){this.setElements(),this.setEvents()},setElements:function(){this.$element=e(this.element),this.$togglers=this.$element.find(this.options.togglersAttribute)},setEvents:function(){this.$togglers.on("click",e.proxy(this.toggle,this))},toggle:function(t){var n=e(t.currentTarget),o=n.parent();o.toggleClass(this.options.toggledState),o.next("ul").slideToggle()}},e.fn[a]=function(t){return this.each(function(){e.data(this,"plugin_"+a)||e.data(this,"plugin_"+a,new i(this,t))})},e(function(){e(r)[a]()})}(jQuery,window,document);