1 line
5.6 KiB
JavaScript
1 line
5.6 KiB
JavaScript
jQuery(document).ready(function(){new GFOwnerSetting});var legacyUI=gform_hubspot_owner_settings_strings.legacy_ui,prefix={input:legacyUI?"_gaddon_setting_":"_gform_setting_",field:legacyUI?"gaddon-setting-row-":"gform_setting_"};function GFOwnerSetting(){var r=jQuery;this.init=function(){this.initOwner(),new GFConditionsSetting},this.initOwner=function(){var t=this;r("#contact_owner0, #contact_owner1, #contact_owner2").on("change",function(){t.toggleOwner(!0)}),this.toggleOwner(!1)},this.toggleOwner=function(t){var e=["#"+prefix.field+"contact_owner_select","#"+prefix.field+"contact_owner_conditional"],o=r(".contact_owner_section"),i=r('input[name="'+prefix.input+'contact_owner"]:checked').val();r(e.join(", ")).hide(),"none"===i?t&&legacyUI?o.slideUp():o.hide():(o.is(":hidden")&&(t&&legacyUI?o.slideDown():o.show()),r("#"+prefix.field+"contact_owner_"+i).show())},this.init()}function GFConditionsSetting(){var n=jQuery;this.$element=jQuery("#gform_conditions_setting"),this.fieldId="conditions",this.fieldName=prefix.input+"conditions",this.options=null,this.init=function(){var r=this,t=(this.options={fieldName:this.fieldName,fieldId:this.fieldId,fields:gform_hubspot_owner_settings_strings.fields,owners:gform_hubspot_owner_settings_strings.owners,imagesURL:gf_vars.baseUrl+"/images",items:this.getItems(),operatorStrings:{is:"is",isnot:"isNot",">":"greaterThan","<":"lessThan",contains:"contains",starts_with:"startsWith",ends_with:"endsWith"}},t=(t=(t='<thead><tr><th class="gform-routings__heading gform-routings__heading--assign">{0}</th>')+'<th class="gform-routings__heading gform-routings__heading--condition" colspan="3">{1}</th>'+"</tr></thead>").gformFormat(gform_hubspot_owner_settings_strings.assign_to,gform_hubspot_owner_settings_strings.condition),t='<table class="gform-routings">{0}<tbody class="repeater">{1}</tbody></table>'.gformFormat(t,this.getNewRow()),n(t));t.find(".repeater").repeater({limit:0,items:this.options.items,addButtonMarkup:'<i class="gficon-add"></i>',removeButtonMarkup:'<i class="gficon-subtract"></i>',callbacks:{save:function(t,e){n("#"+r.options.fieldId).val(n.toJSON(e))},beforeAdd:function(t,e,o){o.owner&&e.find(".gform-routing-owners").val(o.owner);var i=e.find(".gform-routing-field").first(),i=(i.value=o.fieldId,r.changeField(i),e.find(".gform-routing-operator").first());i.value=o.operator,r.changeOperator(i),e.find(".gform-routing-value").val(o.value)}}}).on("change",".gform-routing-field",function(t){r.changeField(this)}).on("change",".gform-routing-operator",function(){r.changeOperator(this)}),this.$element.append(t)},this.getNewRow=function(){var t=[];return t.push("<td>{0}</td>".gformFormat(this.getOwners())),t.push("<td>{0}</td>".gformFormat(this.getFields())),t.push("<td>{0}</td>".gformFormat(this.getOperators(this.options.fields[0]))),t.push("<td>{0}</td>".gformFormat(this.getValues())),t.push('<td class="gform-routings-field gform-routings-field__buttons">{buttons}</td>'),'<tr class="gform-routing-row">{0}</tr>'.gformFormat(t.join(""))},this.getOwners=function(){for(var t=this.options.owners,e='<select class="gform-routing-owners owner_{i}">',o=0;o<t.length;o++)e+='<option value="{0}">{1}</option>'.gformFormat(t[o].value,t[o].label);return e+="</select>"},this.getFields=function(){var t,e,o,i,r,n,s,a,g=[],l=this.options.fields;for(g.push('<select class="gform-routing-field fieldId_{i}" >'),t=0;t<l.length;t++)if(o=l[t].key,l[t].group){for(n=l[t].text,a=l[t].filters.length,s=[],e=0;e<a;e++)r=l[t].filters[e].text,i=l[t].filters[e].key,s.push('<option value="{0}">{1}</option>'.gformFormat(i,r));g.push('<optgroup label="{0}">{1}</optgroup>'.gformFormat(n,s.join("")))}else r=l[t].text,g.push('<option value="{0}">{1}</option>'.gformFormat(o,r));return g.push("</select>"),g.join("")},this.changeOperator=function(t){var e=n(t),o=e.closest("tr").find(".repeater-buttons").find(".add-item ").data("index"),i=e.closest("tr").find(".gform-routing-field"),i=this.getFilter(i.value);i&&e.closest("tr").find(".gform-routing-value").replaceWith(this.getValues(i,t.value,o))},this.changeField=function(t){var e,o=this.getFilter(t.value);o&&(e=(t=n(t)).closest("tr").find(".repeater-buttons").find(".add-item ").data("index"),t.closest("tr").find(".gform-routing-value").replaceWith(this.getValues(o,null,e)),t.closest("tr").find(".gform-filter-type").val(o.type).change(),o=n(this.getOperators(o,e)),t.closest("tr").find(".gform-routing-operator").replaceWith(o),t.closest("tr").find(".gform-routing-operator").change())},this.getOperators=function(t,e){var o,i,r=this.options.operatorStrings,n='<select class="gform-routing-operator operator_{0}">'.gformFormat(e=null==e?"{i}":e);if(t)for(o=0;o<t.operators.length;o++)i=t.operators[o],n+='<option value="{0}">{1}</option>'.gformFormat(i,gf_vars[r[i]]);return n+="</select>"},this.getValues=function(t,e,o){var i,r,n,s,a="";if(null==o&&(o="{i}"),t&&t.values&&"contains"!=e){for(i=0;i<t.values.length;i++)r=t.values[i].value,n=t.values[i].text,a+='<option value="{0}">{1}</option>'.gformFormat(r,n);s='<select class="gform-routing-value value_{0}">{1}</select>'.gformFormat(o,a)}else s='<input type="text" value="" class="gform-routing-value value_{0}" />'.gformFormat(o);return s},this.getFilter=function(t){var e=this.options.fields;if(t)for(var o=0;o<e.length;o++){if(t==e[o].key)return e[o];if(e[o].group)for(var i=0;i<e[o].filters.length;i++)if(t==e[o].filters[i].key)return e[o].filters[i]}},this.selected=function(t,e){return t==e?'selected="selected"':""},this.getItems=function(){var t=n("#"+this.fieldId).val();return t?n.parseJSON(t):[{owner:"",fieldId:"0",operator:"is",value:""}]},this.init(),String.prototype.format=function(){var o=arguments;return this.replace(/{(\d+)}/g,function(t,e){return void 0!==o[e]?o[e]:t})}} |