(function(){u8.Crm.SerialEntry.ProductDiscussionProvider=function(e){this.DefaultProvider($.extend({},u8.Crm.SerialEntry.ProductDiscussionProvider.defaults,e));this._leadProductsMeetings={}};u8.Crm.SerialEntry.ProductDiscussionProvider.makeClass({name:"SerialEntry.ProductDiscussionProvider",deriveFrom:u8.Crm.SerialEntry.DefaultProvider});u8.Crm.SerialEntry.ProductDiscussionProvider.defaults={linkInfoAreaIds:[]};$.extend(u8.Crm.SerialEntry.ProductDiscussionProvider.prototype,{setEditor:function(e){this.editor=e;if(e){e.bind("EnterRow",this._onEditEnterRow.bind(this))}},_onEditEnterRow:function(e,t){var i=this.model.getResultSet();var r=this.editor.gridToResultSetRowIndex(t.rowIndex);var o=i.getUidsAt(r,i.customData.targetAlias);if(!u8.isValidRecordUid(o)){this._initTargetPosition(r)}},_initTargetPosition:function(e){var t=this.model.getResultSet();var i=t.getRowAt(e);if(!i){return}var r=this.model.copyFields||{};for(var o in r){var s=r[o];var n=t.indexOfColumn(t.customData.sourceAlias,s);var d=t.indexOfColumn(t.customData.targetAlias,o);if(n<0||d<0){continue}var a=t.getColumnAt(d);if(a.visible!==false){continue}var u=t.getValue(e,n);i.values[d]=u}},_buildFilterTypes:function(){var e=[].concat(this._filtersByWebConfig).concat(this._filtersByCat.filter(u8._.falseish("disabled")));this.model.filterModel.set("filterTypes",e)},_onCreate:function(e){this.model.bind("PropertyChange",this._onModelPropertyChange.bind(this));this.model.filterModel=new u8.Base.Model({onPropertyChange:this._onFilterModelPropertyChange.bind(this)});if(!isNaN(this.model.filterType)){this.model.properties.set("LeadProductType",this.model.filterType);this.model.filterType="LeadProductType"}e()},_onPreSave:function(e,t){var i=e.isNew;if(!i){return t()}var r=this,o=e.crudOptions,s=e.source.uid,n,d;function a(e){u8.services.crud.read({uid:s,fields:["StatNo","SeqNo","Name"],options:{linkName:"$Link[SR]"}},function(t,i){n=i.businessObject;if(n){var o=u8.recordUidToString(n.uid);d=r._leadProductsMeetings[o]}e()})}function u(e){if(u8.isValidRecordUid(d)){return e()}var t='select from (BE) where (LeadProductStatNo="{LeadProductStatNo}" and LeadProductSeqNo="{LeadProductSeqNo}" and Name="{Name}")'.format({LeadProductStatNo:n.get("StatNo"),LeadProductSeqNo:n.get("SeqNo"),Name:n.get("Name")});u8.services.queries.execute({statement:t,options:{link:r.model.link}},function(t,i){var r=i.resultSet;var o=r&&r.getRowAt(0);d=o&&o.uids[0];e()})}function l(e){if(u8.isValidRecordUid(d)){return e()}u8.services.crud.create({infoAreaId:"BE",fields:[{field:"Name",value:n.get("Name")}],options:{links:[r.model.link,n.uid]}},function(t,i){d=i.businessObject;e()})}Function.chain(a,u,l)(function(){r.leadProductMeeting=d;if(u8.isValidRecordUid(d)){var e=u8.recordUidToString(n.uid);r._leadProductsMeetings[e]=d;o.options.links.push(d)}t()})},_onModelPropertyChange:function(e,t){if(t.propertyName=="filterType"){if(isNaN(t.value)){if(t.value!="LeadProductType"){this.model.properties.set("LeadProductType",undefined)}return}this.model.properties.set("LeadProductType",t.value);this.model.filterType="LeadProductType"}},_onFilterModelPropertyChange:function(e,t){if(t.propertyName=="filtersByCat"){this._filtersByCat=t.value;if(this._filtersByWebConfig){this._buildFilterTypes()}}else if(t.propertyName=="filtersByWebConfig"){this._filtersByWebConfig=t.value;if(this._filtersByCat){this._buildFilterTypes()}}}})})();