Files
roi-theme/wp-content/plugins/wp-marketing-automations/admin/assets/js/bwfan-admin-ui-rules.min.js
root a22573bf0b Commit inicial - WordPress Análisis de Precios Unitarios
- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 21:04:30 -06:00

1 line
12 KiB
JavaScript
Executable File

"use strict";function _typeof(e){"@babel/helpers - typeof";return(_typeof="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)}var bwfan_app={Helpers:{},Views:{},Events:{},SelectedSelects:{}};_.extend(bwfan_app.Events,Backbone.Events),bwfan_app.Helpers.uniqid=function(e,t){var a;void 0===e&&(e="");var n=function(e,t){return t<(e=parseInt(e,10).toString(16)).length?e.slice(e.length-t):t>e.length?Array(t-e.length+1).join("0")+e:e};return this.php_js||(this.php_js={}),this.php_js.uniqidSeed||(this.php_js.uniqidSeed=Math.floor(123456789*Math.random())),this.php_js.uniqidSeed++,a=e,a+=n(parseInt((new Date).getTime()/1e3,10),8),a+=n(this.php_js.uniqidSeed,5),t&&(a+=(10*Math.random()).toFixed(8).toString()),a},jQuery(function(e){jQuery(document).on("bwfan_condition_modified",function(e,a){BWFAN_Auto.emptySidebar();var n=wp.template("bwfan-condition-form-container");bwfan_make_html(2,".wr .wr_wrap_form",n({groupid:a}));var r=new t({model:new Backbone.Model({groupId:a})});bwfan_app.Views[a]=r,r.render()}),jQuery(document).on("bwfan_ui_before_load_dom",function(){var e=BWFAN_Auto.uiDataDetail.condition;for(var a in e){var n=new t({model:new Backbone.Model({groupId:a})});bwfan_app.Views[a]=n}}),e(document).on("submit","#bwfan-condition-form-container",function(t){t.preventDefault();var a=jQuery(this).bwfan_serializeAndEncode();a=bwfan_deserialize_obj(a),BWFAN_Auto.setConditionData(a.bwfan_group_id,0,a.bwfan_rule),BWFAN_Auto.buildAutomation();var n=wp.template("bwfan-sidebar-top"),r=BWFAN_Auto.getSidebarTopTextArr("select_actions");return BWFAN_Auto.rightElemTop.html(n(r)),e(document).trigger("bwfan_automation_save"),!1}),e(document).on("select2ajaxdataRecieved",function(t,a,n,r){var o=e(a).attr("data-rule-type");if(void 0!==o)for(var i in r.results)_.isUndefined(bwfan_automation_data.rule_ui_data[o])&&(bwfan_automation_data.rule_ui_data[o]={}),bwfan_automation_data.rule_ui_data[o][r.results[i].id.toString()]=r.results[i].text});var t=Backbone.View.extend({groupCount:0,groupID:0,el:".bwfan_rules_form",events:{"click .bwfan-add-rule-group":"addRuleGroup"},render:function(){this.$target=e(".bwfan-rules-builder"),bwfan_app.Events.bind("bwfan:remove-rule-group",this.removeRuleGroup,this);var t=this.model.get("groupId");this.views={};var n,r=BWFAN_Auto.getConditionData(t,0);if(_.size(r)>0)for(var o in r){this.groupCount++;var i=o;for(var l in n=new a({model:new Backbone.Model({groupId:i,groupCount:this.groupCount,headerText:this.groupCount>1?bwfanParams.rules_texts.text_or:bwfanParams.rules_texts.text_apply_when,removeText:bwfanParams.rules_texts.remove_text,ruleItems:r[o]})}),this.$target.append(n.render().el),n.ItemViews)n.ItemViews[l].populateRuleType(),n.ItemViews[l].operatorView.populateOperatorType(),n.ItemViews[l].conditionView.populateConditions();this.views[i]=n,n.bind("bwfan:remove-rule-group",this.removeRuleGroup,this)}else{var u="group"+bwfan_app.Helpers.uniqid();this.groupCount++,n=new a({model:new Backbone.Model({groupId:u,groupCount:this.groupCount,headerText:this.groupCount>1?bwfanParams.rules_texts.text_or:bwfanParams.rules_texts.text_apply_when,removeText:bwfanParams.rules_texts.remove_text})}),this.$target.append(n.render().el),this.views[u]=n,n.bind("bwfan:remove-rule-group",this.removeRuleGroup,this)}this.groupCount>0&&e(".rules-basic-actions-wrapper").show()},addRuleGroup:function(t){t.preventDefault();var n="group"+bwfan_app.Helpers.uniqid();this.groupCount++;var r=new a({model:new Backbone.Model({groupId:n,groupCount:this.groupCount,headerText:this.groupCount>1?bwfanParams.rules_texts.text_or:bwfanParams.rules_texts.text_apply_when,removeText:bwfanParams.rules_texts.remove_text})});return this.$target.append(r.render().el),this.views[n]=r,r.bind("bwfan:remove-rule-group",this.removeRuleGroup,this),this.groupCount>0&&e(".rules-basic-actions-wrapper").show(),!1},removeRuleGroup:function(e){delete this.views[e.model.get("groupId")],e.remove()},GetUiText:function(){var t=this.model.get("groupId"),a=BWFAN_Auto.getConditionData(t,0),n="";try{for(var r in a){for(var o in n+='<div data-type="or">',a[r])if("null"!==a[r][o].rule_type)if(!1!==_.has(a[r][o],"condition")){var i=e("#tmpl-bwfan-rules-ui-view-"+a[r][o].rule_type).html(),l=_.template(i),u=a[r][o];u.uiData=void 0!==bwfan_automation_data.rule_ui_data[u.rule_type]?bwfan_automation_data.rule_ui_data[u.rule_type]:{},n+='<div class="ui-prev-rule" data-type="and">'+l(u)+"</div>"}else n+='<div class="bwfan_rule_empty">Rule value is not configured</div>';else n+='<div class="bwfan_rule_empty">Rule is not configured</div>';n+="</div>"}return n}catch(e){return console.log("GetUiText func error"+e),bwfan_hard_texts.select_condition}}}),a=Backbone.View.extend({tagName:"div",className:"bwfan-rule-group-container",template:_.template('<table class="bwfan-rules" data-groupid="<%= groupId %>"><tbody></tbody></table>'),events:{},initialize:function(){this.ItemViews={},this.$rows=this.$el.find("table.bwfan-rules tbody");var e=this.model.get("ruleItems");_.each(e,function(e,t){var a=t,r=new n({model:new Backbone.Model({groupId:this.model.get("groupId"),ruleId:a,ruleData:e,ruleSet:this.getRuleFilteredForEvent(),rulesGroups:bwfan_automation_data.rule_groups})});r.delegateEvents(),r.bind("bwfan:add-rule",this.onAddRule,this),r.bind("bwfan:remove-rule",this.onRemoveRule,this),this.ItemViews[a]=r},this)},getRuleFilteredForEvent:function(){var e=BWFAN_Auto.uiDataDetail.trigger.event,t={},a=bwfanParams.events_rules[e];for(var n in _.extend(t,bwfan_automation_data.rules),t)-1===a.indexOf(n)&&delete t[n];return t},render:function(){this.$el.html(this.template(this.model.toJSON())),this.$rows=this.$el.find("table.bwfan-rules tbody"),this.$el.attr("data-groupid",this.model.get("groupId"));var e=this.model.get("ruleItems");return e?_.each(e,function(e,t){this.$rows.append(this.ItemViews[t].render().el)},this):this.onAddRule(null),this},onAddRule:function(e){var t="rule"+bwfan_app.Helpers.uniqid(),a=new n({model:new Backbone.Model({groupId:this.model.get("groupId"),ruleId:t,ruleSet:this.getRuleFilteredForEvent(),rulesGroups:bwfan_automation_data.rule_groups})});null==e?this.$rows.append(a.render().el):e.$el.after(a.render().el),a.bind("bwfan:add-rule",this.onAddRule,this),a.bind("bwfan:remove-rule",this.onRemoveRule,this),a.conditionView.bindHandlers(),this.ItemViews[t]=a,bwfan_app.Events.trigger("bwfan:added-rule",this)},onRemoveRule:function(t){var a=t.model.get("ruleId");1!=e(".bwfan-rules-builder .bwfan-rule-group-container table tr.bwfan-rule").length&&(delete this.ItemViews[a],t.remove(),0==e("table[data-groupid='"+this.model.get("groupId")+"'] tbody tr").length&&(bwfan_app.Events.trigger("bwfan:removing-rule-group",this),this.trigger("bwfan:remove-rule-group",this)))}}),n=Backbone.View.extend({tagName:"tr",className:"bwfan-rule",events:{"click .bwfan-add-rule":"onAddClick","click .bwfan-remove-rule":"onRemoveClick","change .rule_type":"onchangeRule"},initialize:function(){var e=this.model.get("groupId"),t=this.model.get("ruleId"),a=new r({model:new Backbone.Model({groupId:e,ruleId:t,ruleData:this.model.get("ruleData")})});this.operatorView=a;var n=new o({model:new Backbone.Model({groupId:e,ruleId:t,ruleData:this.model.get("ruleData")})});this.conditionView=n},render:function(){var t=e("#bwfan-rule-template").html(),a=_.template(t);return this.$el.html(a(this.model.toJSON())),this.$el.attr("data-ruleid",this.model.get("ruleId")),this.bind("bwfan:add-rule",this.test,this),this},populateRuleType:function(){var t=this.model.get("groupId"),a=this.model.get("ruleId"),n=this.model.get("ruleData"),r="bwfan_rule["+t+"]["+a+"][rule_type]";e("select[name='"+r+"']").val(n.rule_type),e("select[name='"+r+"']").trigger("change")},onAddClick:function(e){return e.preventDefault(),bwfan_app.Events.trigger("bwfan:adding-rule",this),this.trigger("bwfan:add-rule",this),!1},onRemoveClick:function(e){return e.preventDefault(),bwfan_app.Events.trigger("bwfan:removing-rule",this),this.trigger("bwfan:remove-rule",this),!1},onchangeRule:function(){var t=e(this.el);t.find("td.condition").html("").remove(),t.find("td.operator").html("").remove();var a=t.find(".rule_type").val();if("null"===a){var n=e("#bwfan-rule-template").html(),r=_.template(n);t.html(r(this.model.toJSON())),t.attr("data-ruleid",this.model.get("ruleId"))}else this.operatorView.model.set("rule_type",t.find(".rule_type").val()),this.operatorView.model.set("ruleData",this.model.get("ruleData")),this.conditionView.model.set("rule_type",t.find(".rule_type").val()),this.conditionView.model.set("ruleData",this.model.get("ruleData")),t.find("td.loading").hide().before(this.operatorView.render().el).before(this.conditionView.render().el),this.conditionView.bindHandlers(),e("body").trigger("bwfan-change-rule",{value:a,scope:t})}}),r=Backbone.View.extend({tagName:"td",className:"operator",populateOperatorType:function(){var t=this.model.get("groupId"),a=this.model.get("ruleId"),n=this.model.get("ruleData");e("select[name='"+("bwfan_rule["+t+"]["+a+"][operator]")+"']").val(n.operator)},render:function(){var t=this.model.get("rule_type"),a=e("#tmpl-bwfan-rules-operator-"+t).html(),n=_.template(a);return this.$el.html(n(this.model.toJSON())),this.$el.attr("data-ruleid",this.model.get("ruleId")),this}}),o=Backbone.View.extend({tagName:"td",className:"condition",events:{},populateConditions:function(){var t,a,n=this.model.get("groupId"),r=this.model.get("ruleId"),o=this.model.get("ruleData");if("object"===_typeof(o.condition)&&void 0===o.condition.length)for(var i in o.condition){if(t="bwfan_rule["+n+"]["+r+"][condition]["+i+"]",0===(a=document.getElementsByName(t)).length&&(t="bwfan_rule["+n+"]["+r+"][condition]["+i+"][]",0===(a=document.getElementsByName(t)).length))break;if("null"!==o.rule_type)switch(a[0].tagName){case"INPUT":a[0].value=o.condition[i];break;case"SELECT":e(a[0]).val(o.condition[i])}}else if(t="bwfan_rule["+n+"]["+r+"][condition]",0===(a=document.getElementsByName(t)).length&&(t="bwfan_rule["+n+"]["+r+"][condition][]",a=document.getElementsByName(t)),-1!==(_.has(a[0],"className")?a[0].className:"").split(" ").indexOf("bwfan_select2_ajax")&&this.UpDateSelects(),"null"!==o.rule_type)switch(a[0].tagName){case"INPUT":a[0].value=o.condition;break;case"SELECT":e(a[0]).val(o.condition)}},render:function(){var t=this.model.get("rule_type"),a=e("#tmpl-bwfan-rules-conditions-"+t).html(),n=_.template(a);return this.$el.html(n(this.model.toJSON())),this.$el.attr("data-ruleid",this.model.get("ruleId")),this},bindHandlers:function(){e(".bwfan-date-picker-field").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,beforeShow:function(t,a){e(a.dpDiv).addClass("xl-datepickers")}}),e("select.chosen_select").select2();var t=this.model.get("ruleId"),a=this.model.get("ruleData"),n='.bwfan-rule[data-ruleid="'+t+'"]',r=void 0!==a&&void 0!==a.condition?a.condition:[];if(_.size(r)>0&&_.has(r,"products")&&(r=_.isArray(r.products)?r.products:[r.products]),e("td.condition[data-ruleid='"+t+"'] select.bwfan_select2").each(function(){jQuery(this).select2().val(r).trigger("change")}),e("td.condition[data-ruleid='"+t+"'] select.bwfan_select2_ajax").each(function(){BWFAN_Actions.initiate_select2_ajax(this,"",jQuery(this).attr("data-search-type"),r)}),e(n+" .bwfan-select2ajax-single").length>0){var o=e(n+" .bwfan-select2ajax-single").attr("data-search"),i=e(n+" .bwfan-select2ajax-single").attr("data-search-text");BWFAN_Actions.initiate_select2_ajax_single(n+" .bwfan-select2ajax-single",i,o,r)}},UpDateSelects:function(){var e=this.model.get("groupId"),t=this.model.get("ruleId"),a=this.model.get("ruleData");void 0===bwfan_app.SelectedSelects[e]&&(bwfan_app.SelectedSelects[e]={}),void 0===bwfan_app.SelectedSelects[e][t]&&(bwfan_app.SelectedSelects[e][t]={}),bwfan_app.SelectedSelects[e][t]=a.condition}})});