;(function($){"use strict";ips.controller.register('core.admin.core.notificationMenu',{initialize:function(){$('body').on('updateNotificationCount',this.updateNotificationCount);this.setup();},setup:function(){var notificationCount=parseInt(this.scope.find('[data-role="notificationCount"]').text());if(isNaN(notificationCount)){notificationCount=0;}
var storedNotificationCount=parseInt(ips.utils.cookie.get('acpNotificationCount'));if(isNaN(storedNotificationCount)){storedNotificationCount=0;}
if(notificationCount>storedNotificationCount){setTimeout(function(){$(this.scope).find('[data-role="notificationIcon"]').addClass('cAcpNotifications_animate');}.bind(this),800);}
ips.utils.cookie.set('acpNotificationCount',notificationCount);},updateNotificationCount:function(){ips.getAjax()('?app=core&module=overview&controller=notifications').done(function(response){var count=parseInt(response.count);if(count){$(this).find('[data-role="notificationCount"]').removeClass('ipsHide').text(count).closest('.cAcpNotifications').addClass('cAcpNotifications_active');}else{$(this).find('[data-role="notificationCount"]').addClass('ipsHide').closest('.cAcpNotifications').removeClass('cAcpNotifications_active');}}.bind(this));}});}(jQuery));;
;(function($){"use strict";ips.controller.register('core.admin.core.tags',{initialize:function(){this.on('submit',this.submitForm);},submitForm:function(e){if($(e.currentTarget).attr('data-bypassValidation')){return true;}
e.preventDefault();e.stopPropagation();ips.ui.alert.show({type:'confirm',subText:ips.getString('tag_delete_confirm_detail'),icon:'fa-solid fa-triangle-exclamation',callbacks:{ok:function(){$(e.currentTarget).attr('data-bypassValidation',true);$(e.currentTarget).trigger('submit');},cancel:function(){return false;}}});}});}(jQuery));;
;(function($){"use strict";ips.controller.register('core.admin.core.acpSearchKeywords',{initialize:function(){this.on('click','[data-action="save"]',this.saveKeywords);},saveKeywords:function(e){e.preventDefault();var scope=this.scope;var data={url:scope.attr('data-url'),lang_key:scope.find("[data-role='lang_key']").val(),restriction:scope.find("[data-role='restriction']").val(),keywords:[]};scope.find("[data-role='keywords']").each(function(){if($(this).val()){data.keywords.push($(this).val());}});ips.getAjax()(scope.attr('data-action'),{data:data,type:'post',showLoading:true}).done(function(response){scope[0].closest("[popover]")?.hidePopover();ips.ui.flashMsg.show('Keywords saved');});},});}(jQuery));;
;(function($){"use strict";ips.controller.register('core.admin.core.changeTheme',{initialize:function(){this.on('menuItemSelected',this.themePreferenceSelected.bind(this));this.on('click','[data-role="mobileThemeMenu"] button',this.mobileThemePreferenceSelected);this.setTheme();},setTheme:function(){if(ips.utils.cookie.get('acptheme')===undefined||ips.utils.cookie.get('acptheme')=='undefined'){if(window.matchMedia&&window.matchMedia('(prefers-color-scheme: dark)').matches){$('html').attr('data-ips-scheme','dark');ips.utils.cookie.set('acpthemedefault','dark');}
else
{$('html').attr('data-ips-scheme','light');ips.utils.cookie.set('acpthemedefault','light');}}
else
{if(ips.utils.cookie.get('acptheme')==='dark'){$('html').attr('data-ips-scheme','dark');}else{$('html').attr('data-ips-scheme','light');}}},updatePreference:function(choice){if(choice=='os'){ips.utils.cookie.unset('acptheme');}
else
{var expires=new Date();expires.setFullYear(expires.getFullYear()+1);ips.utils.cookie.set('acptheme',choice,expires.toUTCString());}},themePreferenceSelected:function(e,data=e.detail){if(data.selectedItemID===undefined){return;}
this.updatePreference(data.selectedItemID);this.setTheme();},mobileThemePreferenceSelected:function(e){let choice=e.currentTarget.getAttribute("data-value");this.updatePreference(choice);this.setTheme();}});}(jQuery));;
;(function($){"use strict";ips.controller.register('core.admin.core.editable',{_editTimeout:null,_editing:false,initialize:function(){this.on('mousedown',this.editMousedown);this.on('mouseup mouseleave',this.editMouseup);this.on('click',this.editMouseclick);this.on('click','[data-role="edit"]',this.clickEdit);this.setup();},setup:function(){var defaultFill=this.scope.attr('data-default');if(ips.utils.events.isTouchDevice()||(defaultFill!==undefined&&defaultFill=='empty')){this.scope.removeClass('ipsType_editable').find('[data-role="edit"]').show();}},clickEdit:function(e){e.preventDefault();this._triggerEdit();},editMousedown:function(e){var self=this;if(e.which!==1){return;}
this._editTimeout=setTimeout(this._triggerEdit.bind(this),1000);},editMouseup:function(e){clearTimeout(this._editTimeout);},editMouseclick:function(e){if(this._editing){e.preventDefault();}},_triggerEdit:function(){var self=this;this._editing=true;clearTimeout(this._editTimeout);var span=this.scope;var url=span.attr('data-url');var textField=span.find('[data-role="text"]');var fieldName=span.find('[data-name]').attr('data-name');var defaultFill=span.attr('data-default');span.hide();var defaultText=(defaultFill===undefined||defaultFill!='empty')?textField.text().trim():'';var inputNode=$('<input/>').attr({type:'text'}).attr('data-role','editField').val(defaultText);span.after(inputNode);inputNode.trigger('focus');inputNode.on('blur',function(){inputNode.addClass('ipsField_loading');if(inputNode.val()==''){inputNode.remove();span.show();self._editing=false;}else{var dataToSend={};dataToSend[fieldName]=inputNode.val();ips.getAjax()(url,{method:'post',data:dataToSend}).done(function(response){textField.text(inputNode.val());}).fail(function(response){ips.ui.alert.show({type:'alert',icon:'warn',message:response.responseJSON,});}).always(function(){inputNode.remove();span.show();self._editing=false;});}});inputNode.on('keypress',function(e){if(e.keyCode==ips.ui.key.ENTER){e.stopPropagation();e.preventDefault();inputNode.trigger('blur');return false;}});inputNode.on('keydown',function(e){if(e.keyCode==ips.ui.key.ESCAPE){inputNode.remove();span.show();self._editing=false;return false;}});}});}(jQuery));;
;(function($){"use strict";ips.controller.register('core.admin.core.langString',{_url:null,_hideTimeout:null,_currentValue:'',initialize:function(){this.on('input','textarea',this.changeTextarea);this.on('focus','textarea',this.focusTextarea);this.on('blur','textarea',this.blurTextarea);this.on('click','[data-action="saveWords"]',this.saveWords);this.on('click','[data-action="revertWords"]',this.revertWords);this.setup();},setup:function(){this._url=this.scope.attr('data-saveURL');const contentRoot=this.elem.querySelector('[data-langcontent]');let contents;if(contentRoot){const getText=node=>(node instanceof Text?[node.wholeText]:(node.childNodes?.length?[...node.childNodes].map(getText):[])).flat();contents=getText(contentRoot).join('');}else{contents=this.elem.innerText;}
var html=ips.templates.render('languages.translateString',{value:contents});this._currentValue=contents;this.scope.html(html);this.changeTextarea();},changeTextarea:function(){this.elem.querySelector('[data-action="saveWords"]').disabled=this._currentValue===this.elem.querySelector('textarea').value},focusTextarea:function(){this.scope.addClass('cTranslateTable_field_focus').find('textarea').removeClass('ipsField_success').end().find('[data-action]').show();},blurTextarea:function(){this._saveWords(true);},_hideButtons:function(e){this.scope.removeClass('cTranslateTable_field_focus');},saveWords:function(e){e.preventDefault();this._saveWords(false);},_saveWords:function(hideButtonsImmediately){var self=this;var url=this._url+'&form_submitted=1&csrfKey='+ips.getSetting('csrfKey');var textarea=this.scope.find('textarea');var value=textarea.val();if(this._currentValue==value){this._hideButtons();return;}
if(this._hideTimeout){clearTimeout(this._hideTimeout);}
this.elem.querySelector('[data-action="saveWords"]').disabled=true;ips.getAjax()(url,{type:'post',data:{lang_word_custom:encodeURIComponent(value)}}).done(function(){textarea.removeClass('ipsField_loading').addClass('ipsField_success');ips.ui.flashMsg.show(ips.getString('saved'));if(!hideButtonsImmediately){self._hideTimeout=setTimeout(self._hideButtons.bind(self),300);}else{self._hideButtons();}
self._currentValue=value;}).fail(function(){window.location=url;});},revertWords:function(e){}});}(jQuery));;
;(function($){"use strict";ips.controller.register('core.admin.core.mobileNav',{initialize:function(){this.on(document,'click','[data-role="clearCaches"]',this.clearCaches);},clearCaches:function(e){e.preventDefault();var self=this;ips.getAjax()('?app=core&module=support&controller=support&do=clearCaches').done(function(response){ips.ui.flashMsg.show(ips.getString('health_caches_cleared'));});}});}(jQuery));;