From 6e4f62c3384c3bbec90052b3d6d3807b545b5643 Mon Sep 17 00:00:00 2001 From: Hugh Messenger Date: Sat, 10 Sep 2022 21:35:26 -0500 Subject: [PATCH] Fix missing commits for autofill --- plugins/fabrik_form/autofill/autofill-min.js | 31 ++------------------ plugins/fabrik_form/autofill/autofill.js | 1 + 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/plugins/fabrik_form/autofill/autofill-min.js b/plugins/fabrik_form/autofill/autofill-min.js index d9447e1c3e3..61f4b7b93ae 100644 --- a/plugins/fabrik_form/autofill/autofill-min.js +++ b/plugins/fabrik_form/autofill/autofill-min.js @@ -1,28 +1,3 @@ -/** - * Form Autofill - * - * @copyright: Copyright (C) 2005-2016 Media A-Team, Inc. - All rights reserved. - * @license: GNU/GPL http://www.gnu.org/copyleft/gpl.html - */ -define(['jquery','fab/fabrik'],function(jQuery,Fabrik){'use strict';var Autofill=new Class({Implements:[Events],options:{'observe':'','trigger':'',cnn:0,table:0,map:'',editOrig:!1,fillOnLoad:!1,confirm:!0,autofill_lookup_field:0,showNotFound:!1,notFoundMsg:''},initialize:function(options){var self=this;this.options=jQuery.extend(this.options,options);this.attached=[];this.newAttach=[];this.setupDone=!1;this.setUp(Fabrik.getBlock('form_'+this.options.formid));Fabrik.addEvent('fabrik.form.elements.added',function(form){self.setUp(form)})},getElement:function(repeatNum){var testE=!1,self=this,e=this.form.formElements.get(this.options.observe),k,repeatCount=0;if(!e){k=Object.keys(this.form.formElements);k.each(function(i){if(i.contains(self.options.observe)){testE=self.form.formElements.get(i);if(!self.attached.contains(testE.options.element)){self.attached.push(testE.options.element)} - if(typeOf(repeatNum)==='null'||repeatNum===repeatCount){e=testE} - repeatCount++}})}else{this.attached.push(e.options.element)} - return e},doLookup:function(e){this.lookUp(e)},setUp:function(form){var self=this;if(this.setupDone){return} - if(form===undefined){return} - try{this.form=form}catch(err){return} - this.doLookupEvent=this.doLookup.bind(this);var testE=!1;var e=this.form.formElements.get(this.options.observe);if(!e){var repeatCount=0,k=Object.keys(this.form.formElements);k.each(function(i){if(i.contains(self.options.observe)){testE=self.form.formElements.get(i);if(!self.attached.contains(testE.options.element)){self.attached.push(testE.options.element);self.newAttach.push(testE.options.element)} - var repeatNum=parseInt(testE.getRepeatNum(),10);if(isNaN(repeatNum)||repeatNum===repeatCount){e=testE} - repeatCount++}})}else{this.attached.push(e.options.element);self.newAttach.push(e.options.element)} - this.element=e;if(this.options.trigger===''){if(!this.element){fconsole('autofill - couldnt find element to observe')}else{var elEvnt=this.element.getBlurEvent();this.newAttach.each(function(el){var e=self.form.formElements.get(el);self.form.dispatchEvent('',el,elEvnt,self.doLookupEvent);if(self.options.fillOnLoad){self.form.dispatchEvent('',el,'load',self.doLookupEvent)}})}}else{this.form.dispatchEvent('',this.options.trigger,'click',this.doLookupEvent);if(this.options.fillOnLoad){this.form.dispatchEvent('',this.options.trigger,'load',this.doLookupEvent)}} - this.setupDone=!0;this.newAttach=[]},lookUp:function(el){if(!this.options.trigger){this.element=el} - if(this.options.confirm===!0){if(!window.confirm(Joomla.JText._('PLG_FORM_AUTOFILL_DO_UPDATE'))){return}} - Fabrik.loader.start('form_'+this.options.formid,Joomla.JText._('PLG_FORM_AUTOFILL_SEARCHING'));if(!this.element){this.element=this.getElement(0)} - var v=this.element.getValue(),formid=this.options.formid,observe=this.options.observe,self=this;jQuery.ajax({url:'index.php',method:'post',dataType:'json','data':{'option':'com_fabrik','format':'raw','task':'plugin.pluginAjax','plugin':'autofill','method':'ajax_getAutoFill','g':'form','v':v,'formid':formid,'observe':observe,'cnn':this.options.cnn,'table':this.options.table,'map':this.options.map,'autofill_lookup_field':this.options.autofill_lookup_field}}).always(function(){Fabrik.loader.stop('form_'+self.options.formid)}).fail(function(jqXHR,textStatus,errorThrown){window.alert(textStatus)}).done(function(json){self.updateForm(json)})},updateForm:function(json){this.json=json;Fabrik.fireEvent('fabrik.form.autofill.update.start',[this,json]);var el=this.form.formElements.get(json.__elid);var repeatNum=el.getRepeatNum(),key,val,k2,origKey;if(jQuery.isEmptyObject(this.json)){if(this.options.showNotFound){var msg=this.options.notFoundMsg===''?Joomla.JText._('PLG_FORM_AUTOFILL_NORECORDS_FOUND'):this.options.notFoundMsg;window.alert(msg)} - return} - for(key in this.json){if(this.json.hasOwnProperty(key)){val=this.json[key];k2=key.substr(key.length-4,4);if(k2==='_raw'){key=key.replace('_raw','');origKey=key;if(!this.tryUpdate(key,val)){key=this.updateRepeats(key,val,repeatNum,origKey)}}}} - if(this.options.editOrig===!0){this.form.getForm().getElement('input[name=rowid]').value=this.json.__pk_val} - Fabrik.fireEvent('fabrik.form.autofill.update.end',[this,json])},updateRepeats:function(key,val,repeatNum,origKey){var k,k2;if(typeof val==='object'){for(k in val){if(val.hasOwnProperty(k)){k2=key+'_'+k;this.tryUpdate(k2,val[k])}}}else{key+=repeatNum?'_'+repeatNum:'_0';if(!this.tryUpdate(key,val)){key='join___'+this.element.options.joinid+'___'+key;this.tryUpdate(origKey,val,!0)}} - return key},tryUpdate:function(key,val,looseMatch){var m,self=this,el;looseMatch=looseMatch?!0:!1;if(!looseMatch){el=this.form.elements[key];if(el!==undefined){if(el.options.displayType==='auto-complete'){el.activePopUp=!0} - el.update(val);if(el.baseElementId!==this.element.baseElementId){el.element.fireEvent(el.getBlurEvent(),new Event.Mock(el.element,el.getBlurEvent()));if(el.getBlurEvent()!==el.getChangeEvent()){el.element.fireEvent(el.getChangeEvent(),new Event.Mock(el.element,el.getChangeEvent()))}} - return!0}}else{m=Object.keys(this.form.formElements).filter(function(k,v){return k.contains(key)});if(m.length>0){m.each(function(key){el=self.form.elements[key];el.update(val);if(el.baseElementId!==self.element.baseElementId){el.element.fireEvent(el.getBlurEvent(),new Event.Mock(el.element,el.getBlurEvent()));if(el.getBlurEvent()!==el.getChangeEvent()){el.element.fireEvent(el.getChangeEvent(),new Event.Mock(el.element,el.getChangeEvent()))}}});return!0}} - return!1}});return Autofill}) \ No newline at end of file +/*! Fabrik */ + +define(["jquery","fab/fabrik"],function(r,a){"use strict";return new Class({Implements:[Events],options:{observe:"",trigger:"",cnn:0,table:0,map:"",editOrig:!1,fillOnLoad:!1,confirm:!0,autofill_lookup_field:0,showNotFound:!1,notFoundMsg:""},initialize:function(t){var e=this;this.options=r.extend(this.options,t),this.attached=[],this.newAttach=[],this.setupDone=!1,this.setUp(a.getBlock("form_"+this.options.formid)),a.addEvent("fabrik.form.elements.added",function(t){e.setUp(t)})},getElement:function(e){var o=!1,n=this,i=this.form.formElements.get(this.options.observe),s=0;return i?this.attached.push(i.options.element):Object.keys(this.form.formElements).each(function(t){t.contains(n.options.observe)&&(o=n.form.formElements.get(t),n.attached.contains(o.options.element)||n.attached.push(o.options.element),"null"!==typeOf(e)&&e!==s||(i=o),s++)}),i},doLookup:function(t){this.lookUp(t)},setUp:function(t){var o=this;if(!this.setupDone&&void 0!==t){try{this.form=t}catch(t){return}this.doLookupEvent=this.doLookup.bind(this);var n=!1,i=this.form.formElements.get(this.options.observe);if(i)this.attached.push(i.options.element),o.newAttach.push(i.options.element);else{var s=0;Object.keys(this.form.formElements).each(function(t){if(t.contains(o.options.observe)){n=o.form.formElements.get(t),o.attached.contains(n.options.element)||(o.attached.push(n.options.element),o.newAttach.push(n.options.element));var e=parseInt(n.getRepeatNum(),10);(isNaN(e)||e===s)&&(i=n),s++}})}if(this.element=i,""===this.options.trigger)if(this.element){var e=this.element.getBlurEvent();this.newAttach.each(function(t){o.form.formElements.get(t);o.form.dispatchEvent("",t,e,o.doLookupEvent),o.options.fillOnLoad&&o.form.dispatchEvent("",t,"load",o.doLookupEvent)})}else fconsole("autofill - couldnt find element to observe");else this.form.dispatchEvent("",this.options.trigger,"click",this.doLookupEvent),this.options.fillOnLoad&&this.form.dispatchEvent("",this.options.trigger,"load",this.doLookupEvent);this.setupDone=!0,this.newAttach=[]}},lookUp:function(t){if(this.options.trigger||(this.element=t),!0!==this.options.confirm||window.confirm(Joomla.JText._("PLG_FORM_AUTOFILL_DO_UPDATE"))){a.loader.start("form_"+this.options.formid,Joomla.JText._("PLG_FORM_AUTOFILL_SEARCHING")),this.element||(this.element=this.getElement(0));var e=this.element.getValue(),o=this.options.formid,n=this.options.observe,i=this;r.ajax({url:"index.php",method:"post",dataType:"json",data:{option:"com_fabrik",format:"raw",task:"plugin.pluginAjax",plugin:"autofill",method:"ajax_getAutoFill",g:"form",v:e,formid:o,elid:t.element.id,observe:n,cnn:this.options.cnn,table:this.options.table,map:this.options.map,autofill_lookup_field:this.options.autofill_lookup_field}}).always(function(){a.loader.stop("form_"+i.options.formid)}).fail(function(t,e,o){window.alert(e)}).done(function(t){i.updateForm(t)})}},updateForm:function(t){this.json=t,a.fireEvent("fabrik.form.autofill.update.start",[this,t]);var e,o,n,i=this.form.formElements.get(t.__elid).getRepeatNum();if(r.isEmptyObject(this.json)){if(this.options.showNotFound){var s=""===this.options.notFoundMsg?Joomla.JText._("PLG_FORM_AUTOFILL_NORECORDS_FOUND"):this.options.notFoundMsg;window.alert(s)}}else{for(e in this.json)this.json.hasOwnProperty(e)&&(o=this.json[e],"_raw"===e.substr(e.length-4,4)&&(n=e=e.replace("_raw",""),this.tryUpdate(e,o)||(e=this.updateRepeats(e,o,i,n))));!0===this.options.editOrig&&(this.form.getForm().getElement("input[name=rowid]").value=this.json.__pk_val),a.fireEvent("fabrik.form.autofill.update.end",[this,t])}},updateRepeats:function(t,e,o,n){var i,s;if("object"==typeof e)for(i in e)e.hasOwnProperty(i)&&(s=t+"_"+i,this.tryUpdate(s,e[i]));else t+=o?"_"+o:"_0",this.tryUpdate(t,e)||(t="join___"+this.element.options.joinid+"___"+t,this.tryUpdate(n,e,!0));return t},tryUpdate:function(o,e,t){var n,i,s=this;if(t=!!t){if(0<(n=Object.keys(this.form.formElements).filter(function(t,e){return t.contains(o)})).length)return n.each(function(t){(i=s.form.elements[t]).update(e),i.baseElementId!==s.element.baseElementId&&(i.element.fireEvent(i.getBlurEvent(),new Event.Mock(i.element,i.getBlurEvent())),i.getBlurEvent()!==i.getChangeEvent()&&i.element.fireEvent(i.getChangeEvent(),new Event.Mock(i.element,i.getChangeEvent())))}),!0}else if(void 0!==(i=this.form.elements[o]))return"auto-complete"===i.options.displayType&&(i.activePopUp=!0),i.update(e),i.baseElementId!==this.element.baseElementId&&(i.element.fireEvent(i.getBlurEvent(),new Event.Mock(i.element,i.getBlurEvent())),i.getBlurEvent()!==i.getChangeEvent()&&i.element.fireEvent(i.getChangeEvent(),new Event.Mock(i.element,i.getChangeEvent()))),!0;return!1}})}); \ No newline at end of file diff --git a/plugins/fabrik_form/autofill/autofill.js b/plugins/fabrik_form/autofill/autofill.js index bb7e9d9c43c..aacf8d96f73 100644 --- a/plugins/fabrik_form/autofill/autofill.js +++ b/plugins/fabrik_form/autofill/autofill.js @@ -201,6 +201,7 @@ define(['jquery', 'fab/fabrik'], function (jQuery, Fabrik) { 'g' : 'form', 'v' : v, 'formid' : formid, + 'elid' : el.element.id, 'observe' : observe, 'cnn' : this.options.cnn, 'table' : this.options.table,