;(function($){"use strict";ips.controller.register('core.admin.templates.simple',{_cmInstances:{},initialize:function(){this.on('click','button[type="submit"]',this.save);this.on('tabChanged',this.changedTab);var debounce=ips.utils.debounce(this._recalculatePanelWrapper.bind(this),100);this.on(window,'resize',debounce);this.setup();},setup:function(){var self=this;ips.loader.getStatic(['applications/core/interface/static/codemirror/diff_match_patch.js','applications/core/interface/static/codemirror/codemirror.js']).then(function(){self._initCodeMirror('theme_simple_header','htmlmixed');self._initCodeMirror('theme_simple_footer','htmlmixed');self._initCodeMirror('theme_simple_css','css');});},_initCodeMirror:function(key,type){var self=this;this._cmInstances[key]=CodeMirror.fromTextArea(document.getElementById('elTextarea_'+key),{mode:type,lineNumbers:false});this._cmInstances[key].setSize(null,this._getContentHeight());this.scope.find('#elTextarea_'+key).parent().addClass('i-background_3 i-padding_2');},changedTab:function(e,data){this._recalculatePanelWrapper();},save:function(e){e.preventDefault();var self=this;var form=this.scope.find('form[data-formid="form"]');var save={};for(const cm of Object.values(this._cmInstances)){cm.save();}
form.find('input').each(function(){save[$(this).attr('name')]=$(this).val();});form.find('textarea').each(function(){save[$(this).attr('name')]=$(this).val();});Debug.log(save);self.scope.find('button[type="submit"]').addClass('ipsButton--disabled').removeClass('ipsButton--primary');ips.getAjax()(form.attr('action'),{dataType:'json',data:save,type:'post'}).done(function(response){ips.ui.flashMsg.show(ips.getString('saved'));}).fail(function(jqXHR){var message=ips.getString('saveThemeError');try
{message=JSON.parse(jqXHR.responseText);}
catch(e){}
ips.ui.alert.show({type:'alert',message:message,icon:'warn'});}).always(function(){self.scope.find('button[type="submit"]').removeClass('ipsButton--disabled').addClass('ipsButton--primary');});},_getContentHeight:function(){return $(window).height()-this.scope.find('#tabs_form').offset().top-250;},_recalculatePanelWrapper:function(){var self=this;for(const cm of Object.values(this._cmInstances)){cm.setSize(null,self._getContentHeight());};}});}(jQuery));;