(function(){$.extend(page,{"Form.onCreate":function(e,t){var i=this.url.getUid();if(u8.isValidRecordUid(i)){new a({uid:i,form:e,parent:e})}}});var e=["<ul>{{each items}}","<li>",'{{if label}}<span class="u8-label">${label}</span>&nbsp;{{/if}}','<a href="javascript:void(0);" data-index="${$index}">${text}</a>',"</li>","{{/each}}</ul>"].join("");var t={FI:"companyNumbers",KP:"personNumbers",CP:"personNumbers",PE:"humanNumbers"};function a(e){$.extend(this,e);u8.using({schema:["FI","KP","CP","PE"],texts:"wizard_callnumber_text"},this._create.bind(this))}$.extend(a.prototype,{_create:function(){Function.chain(this._createModel,this._assertTelephoneNumberAvailable,this._createView).call(this)},_createModel:function(e){var t={};this.model=t;u8.request("PhoneChannel.GetTelephoneNumbers",{uid:this.uid,options:{tableCaptionName:"%%"}},function(a,i){var n=i.response&&i.response.telephoneNumbers||{};var r={};for(var o in n){var l=n[o],s=l&&l.items;if(!s||s.length<=0){continue}if(l.tableCaption){l.tableCaption=new u8.Crm.TableCaption(l.tableCaption)}t.telephoneNumberAvailable=true;for(var u=0;u<s.length;u++){var c=s[u];var d=u8.services.schema.getField(c.fieldInfoAreaId,c.fieldId);c.label=d&&d.label;c.text=u8.Crm.Phone.formatNumber(c)}var m=u8.services.schema.toBaseInfoAreaId(o);r[m]=l}t.infoAreas=r;e()})},_assertTelephoneNumberAvailable:function(e){if(this.model.telephoneNumberAvailable){return e()}u8.services.notification.info("TXT_wizard_callnumber_text_2");page.proceed({command:"NoNumber"});return false},_createView:function(){for(var e in this.model.infoAreas){var a=t[e];if(a){this._createInfoAreaView(a,this.model.infoAreas[e])}}},_createInfoAreaView:function(t,a){var i=this.form.getWidget(t+"Panel"),n=this.form.getWidget(t+"Label"),r=this.form.getWidget(t);i.element.style.display="";if(a.tableCaption){n.setHtml("<h2>"+u8.services.tableCaptions.createView(a.tableCaption)+"</h2>")}$(r.element).bind("click.telephonenumbers",this._onTelephoneNumberClick.bind(this,a)).utml({template:e,data:a,inserter:function(e,t){$(e).append(t)}})},_onTelephoneNumberClick:function(e,t){var a=$(t.target).closest("[data-index]").attr("data-index"),i=e.items[a];if(!i){return}u8.services.phone.makeCall(i);page.proceed({command:"Select",selectedUid:e.uid})}})})();