1 line
4.9 KiB
JavaScript
1 line
4.9 KiB
JavaScript
!function(t,a,e){"use strict";var i="gfRoutingSetting",r={prefix:"",allowMultiple:!0,imagesURL:"",operatorStrings:{is:"is",isnot:"isNot",">":"greaterThan","<":"lessThan",contains:"contains",starts_with:"startsWith",ends_with:"endsWith"},items:[{target:"",fieldId:"0",operator:"is",value:"",type:""}],callbacks:{addNewTarget:function(){},header:function(){return'<thead><tr><th>Assign To</th><th colspan="3">Condition</th></tr></thead>'}}};function o(t,e){this.element=t,this.$element=a(t),this.options=a.extend(!0,{},r,e),this.prefix=e.prefix,this.settings=e.settings,this.accounts=e.accounts,this._defaults=r,this._name=i,this.init()}o.prototype={init:function(){var t,e,n=this;e=this.getHeaderMarkup(),t='<table class="gform-routings">{0}<tbody class="repeater">{1}</tbody></table>'.format(e,this.getNewRoutingRow());var i=a(t);i.find(".repeater").repeater({limit:0,items:this.options.items,addButtonMarkup:'<img class="gform-add" src="{0}/images/add.png" />'.format(gf_vars.baseUrl),removeButtonMarkup:'<img class="gform-remove" src="{0}/images/remove.png" />'.format(gf_vars.baseUrl),callbacks:{save:function(t,e){a("#"+n.options.fieldId).val(a.toJSON(e))},beforeAdd:function(t,e,i){e.find(".gform-routing-target").val(i.target);var r=e.find(".gform-routing-field").first();r.value=i.fieldId,n.changeField(r);var o=e.find(".gform-routing-operator").first();o.value=i.operator,n.changeOperator(o),e.find(".gform-routing-value").val(i.value)}}}).on("change",".gform-routing-field",function(t){n.changeField(this)}).on("click",".gform-no-filters",function(t){var e=a(this);0==e.find(".gform-routing").length&&n.addNewRouting(this),e.remove(),t.preventDefault()}).on("change",".gform-routing-operator",function(){n.changeOperator(this)}),this.$element.append(i)},getHeaderMarkup:function(){return this.options.callbacks.header(this,"")},getNewRoutingRow:function(){var t=[];return t.push("<td>{0}</td>".format(this.getRoutingTarget())),t.push("<td>{0}</td>".format(this.getRoutingFields())),t.push("<td>{0}</td>".format(this.getRoutingOperators(this.options.settings[0]))),t.push("<td>{0}</td>".format(this.getRoutingValues())),t.push("<td>{buttons}</td>"),'<tr class="gform-routing-row">{0}</tr>'.format(t.join(""))},getRoutingTarget:function(){var t='<input type="text" class="gform-routing-target target_{i}">';return t=this.options.callbacks.addNewTarget(this,t)},getRoutingFields:function(){var t,e,i,r,o,n,a,s,u=[],g=this.settings;for(u.push('<select class="gform-routing-field fieldId_{i}" >'),t=0;t<g.length;t++)if(i=g[t].key,g[t].group){for(n=g[t].text,s=g[t].filters.length,a=[],e=0;e<s;e++)o=g[t].filters[e].text,r=g[t].filters[e].key,a.push('<option value="{0}">{1}</option>'.format(r,o));u.push('<optgroup label="{0}">{1}</optgroup>'.format(n,a.join("")))}else o=g[t].text,u.push('<option value="{0}">{1}</option>'.format(i,o));return u.push("</select>"),u.push('<input type="hidden" class="gform-filter-type" name="type_{i}" value="" >'),u.join("")},changeOperator:function(t){var e=a(t),i=e.closest("tr").find(".repeater-buttons").find(".add-item ").data("index"),r=e.closest("tr").find(".gform-routing-field"),o=this.getFilter(r.value);o&&e.closest("tr").find(".gform-routing-value").replaceWith(this.getRoutingValues(o,t.value,i))},changeField:function(t){var e=this.getFilter(t.value);if(e){var i=a(t),r=i.closest("tr").find(".repeater-buttons").find(".add-item ").data("index");i.closest("tr").find(".gform-routing-value").replaceWith(this.getRoutingValues(e,null,r)),i.closest("tr").find(".gform-filter-type").val(e.type).change();var o=a(this.getRoutingOperators(e,r));i.closest("tr").find(".gform-routing-operator").replaceWith(o),i.closest("tr").find(".gform-routing-operator").change()}},getRoutingOperators:function(t,e){null==e&&(e="{i}");var i,r,o=this.options.operatorStrings,n='<select class="gform-routing-operator operator_{0}">'.format(e);if(t)for(i=0;i<t.operators.length;i++)r=t.operators[i],n+='<option value="{0}">{1}</option>'.format(r,gf_vars[o[r]]);return n+="</select>"},getRoutingValues:function(t,e,i){var r,o,n,a,s="";if(null==i&&(i="{i}"),t&&t.values&&"contains"!=e){for(r=0;r<t.values.length;r++)o=t.values[r].value,n=t.values[r].text,s+='<option value="{0}">{1}</option>'.format(o,n);a='<select class="gform-routing-value value_{0}">{1}</select>'.format(i,s)}else a='<input type="text" value="" class="gform-routing-value value_{0}" />'.format(i);return a},getFilter:function(t){var e=this.settings;if(t)for(var i=0;i<e.length;i++){if(t==e[i].key)return e[i];if(e[i].group)for(var r=0;r<e[i].filters.length;r++)if(t==e[i].filters[r].key)return e[i].filters[r]}},selected:function(t,e){return t==e?'selected="selected"':""}},a.fn[i]=function(t){return this.each(function(){a.data(this,"plugin_"+i)||a.data(this,"plugin_"+i,new o(this,t))})},String.prototype.format=function(){var i=arguments;return this.replace(/{(\d+)}/g,function(t,e){return void 0!==i[e]?i[e]:t})}}(window.GFRoutingSetting=window.GFRoutingSetting||{},jQuery); |