ips.templates.set('templates.blocks.fieldTagList',"    <li>        <h4 class='i-color_hard i-font-weight_500 i-background_3 i-padding_2 i-flex i-align-items_center i-gap_2'><span>{{#lang}}content_block_template_fields_header{{/lang}}</span></h4>    </li>    {{{contents}}}");ips.templates.set('templates.blocks.fieldTag',"    <li>        <button type='button' data-tagKey='{{key}}'>            <code class='language-ipsphtml'>{{key}}</code>            {{#title}}<div class='i-color_soft i-font-size_-2 i-margin-top_1'>{{title}}</div>{{/title}}        </button>    </li>");;
;(function($){"use strict";ips.controller.register('cms.admin.blocks.form',{initialize:function(){this.on('change','#elSelect_block_template_use_how',this.toggle);this.on('click','[data-role=viewTemplate]',this.viewTemplate);document.getElementById('elTextarea_block_content').setAttribute('loaded','false');let blockFields=document.getElementById('block_fields')||null;if(blockFields){const blockId=document.querySelector('body').getAttribute('data-pageid')||'new';this.on('click','#ipsTabs_form_'+blockId+'_content_block_form_tab__content',this.updateFieldList);}},viewTemplate:function(e){var appOrPlugin='&block_app='+this.scope.find('input[name=block_plugin_app]').val();var dialogRef=ips.ui.dialog.create({title:this.scope.find('input[name=block_plugin]').val(),url:'?app=cms&module=pages&controller=ajax&do=loadTemplate&show=modal&t_location=block'+appOrPlugin+'&block_key='+this.scope.find('input[name=block_plugin]').val()+'&t_key='+this.scope.find('#elSelect_block_template_id').val(),forceReload:true,remoteSubmit:true});dialogRef.show();},toggle:function(e){var thisToggle=$(e.currentTarget);if(thisToggle.val()==='copy'&&$('#elTextarea_block_content').attr('loaded')=='false'){var save={'t_location':'block','t_key':this.scope.find('#elSelect_block_template_id').val(),'block_key':this.scope.find('input[name=block_plugin]').val(),'block_app':this.scope.find('input[name=block_plugin_app]').val()};ips.getAjax()('?app=cms&module=pages&controller=ajax&do=loadTemplate&show=json&noencode=1',{dataType:'json',data:save,type:'post'}).done(function(response){let content=response.template_content;$('#elTextarea_block_content').get(0).dispatchEvent(new CustomEvent('insertCode',{detail:{content}}));$('input[name=template_params]').val(response.template_params);$('#elTextarea_block_content').attr('loaded','true');});}},updateFieldList:function(){let fields=[];const container=document.getElementById('block_fields');container.querySelectorAll('[data-ipsstack-fieldname="block_fields"] [data-ipsstack-wrapper]').forEach((el)=>{let keyField=el.querySelector('input[type="hidden"]');let key=keyField.value||Math.random().toString(36).substring(2,7);keyField.value=key;fields.push(ips.templates.render('templates.blocks.fieldTag',{key:function(){return'{{'+el.querySelector('.ipsInput.ipsInput--select').value+'_'+key+'}}';},title:el.querySelector('.ipsInput.ipsInput--text').value}));});if(fields.length){let tagList=document.querySelector('#block_content [data-role="tagsList"]');let fieldList=document.querySelector('#block_content [data-role="tagsFieldList"]')||null;if(fieldList===null){fieldList=document.createElement('ul');fieldList.setAttribute('data-role','tagsFieldList');tagList.before(fieldList);}
fieldList.innerHTML=ips.templates.render('templates.blocks.fieldTagList',{contents:fields.join('')});}}});}(jQuery));;