(function(){var e=/^[A-Za-z_][A-Za-z0-9$_.]+$/;u8.Crm.FieldHook=function(e){$.extend(this,e);$assert(this.field,"Failed to construct a FieldHook! Property 'field' must be set.");this._create()};u8.Crm.FieldHook.makeClass({name:"FieldHook"});$.extend(u8.Crm.FieldHook.prototype,{getValue:function(e){$assert(this._executing,"$.getValue() must not be called from an asynchronous callback.");return this._getValue(e)},getNativeValue:function(e){$assert(this._executing,"$.getNativeValue() must not be called from an asynchronous callback.");var t=this._getValue(e),i=this._getField(e);return u8.services.typeConverter.toObject(i.schema,t)},setValue:function(e,t){$assert(this._executing,"$.setValue() must not be called from an asynchronous callback.");if(arguments.length==1){t=e;e=null}var i=this._getField(e),n=this._convertForSetting(i,t);this._setModelValue(i,n)},getLinks:function(e,t){return null},getUid:function(e){return null},getWidget:function(e){var t=this.widget;var i=$w(t.element).$widget(e);return i&&i.isChildOf(t)?i:undefined},_setModelValue:function(e,t){},_getModelValue:function(e){},_getValue:function(e,t){var i=this._getField(e);if(arguments.length==2){}else if(typeof e=="undefined"){t=this.value}else{t=this._getModelValue(i)}return t},_convertForGetting:function(e,t){var i=undefined;if(e.schema.isHierarchicalCatalogField()){i=self.getValue(e.schema.catalogParentFieldId).value}return e.converter?e.converter.to(t,i):{convertedValue:t}},_convertForSetting:function(e,t){return e.converter?e.converter.from(t):t},_getField:function(e){var t=this.field.fieldId,i=this.field.alias,n=this.field.operator,o,r;if(e||e===0){e+="";var u=e.split(".");if(u.length==1){t=u[0]}else if(u.length==2){i=u[0];t=u[1]}else if(u.length==3){i=u[0];t=u[1];n=u[2]}}o=i;if(!u8.services.schema.isInfoAreaId(o)){o=this.field.infoAreaId}r=u8.services.schema.getField(o,t);return{alias:i,infoAreaId:o,fieldId:t,schema:r,operator:n}},_getHookField:function(){return this._getField()},_isHookField:function(e){if(!e&&e!==0){return true}var t=this.getFields(e),i=t&&t[0];return i&&i.alias==this.field.alias&&i.fieldId==this.field.fieldId},_create:function(){this._hookFunction=this.hook&&this._createHookFunction(this.hook);if(!this._hookFunction){this._hookFunction=t}this.onCalculate=this._onHook.bind(this)},_createHookFunction:function(t){if(t.match(e)){var n=u8.debug.tryCatch(function(){return evalValue(t)},"hooks",function(){return{message:"The FieldHook for field '"+i(u)+"' is invalid and will be ignored.",artifacts:[t]}});return n&&function(e,t,i){return n(e,t,i)}}var o=t[0]=="$"&&t[1]!="."&&t.indexOf("$command")!=0;if(o){var r=t.substr(1);return function(e,t){var i=$.extend({},t);$command(e,r,i)}}else{var u=this.field;return u8.debug.tryCatch(function(){return new Function("sender","args","$",t)},"hooks",function(){return{message:"The field hook for field '"+i(u)+"' is invalid and will be ignored.",artifacts:[t]}})}},_onHook:function(e,t){if(this._executing){u8.log.warn("Blocked execution loop of field hook on field '"+i(this.field)+"'.");return}this._executing=true;t.pending=true;this.value=t.value;var n=this,o,r,u=function(e){u=null;if(e){t=$.extend(t,e)}t.value=n.value;delete n.value;n._executing=false;t.proceed()};o=this._hookFunction;r=u8.debug.tryCatch(function(){return o(e,t,n)},function(){return{message:"Execution of the hook for field '"+i(n.field)+"' failed.",artifacts:[n.hook]}});if(u8.tools.isPromise(r)){r.then(u)}else{u()}}});function t(){}function i(e){return e&&e.alias+"."+e.fieldId}})();