Ext.namespace("Zarafa.plugins.contactfax");
Zarafa.plugins.contactfax.ContactFax=Ext.extend(Zarafa.core.Plugin,{model:undefined,initPlugin:function(){Zarafa.plugins.contactfax.ContactFax.superclass.initPlugin.apply(this,arguments);this.registerInsertionPoint("context.contact.contextmenu.actions",this.createSendFaxContextItem,this)},getMailContextModel:function(){if(!this.model){var a=container.getHierarchyStore().getDefaultFolder("drafts");this.model=container.getContextByFolder(a).getModel()}return this.model},convertToFaxRecipient:function(a,
b){for(var e=["business_fax_number","home_fax_number","primary_fax_number"],c=[],f=0;f<4;f++)if(!Ext.isEmpty(b.get(e[f]))){var d=b.get(e[f])+"@"+container.getSettingsModel().get(this.getSettingsBase()+"/faxdomain");d={entryid:Zarafa.core.EntryId.wrapContactProviderEntryId(b.get("entryid"),Zarafa.core.mapi.ObjectType.MAPI_MAILUSER),object_type:Zarafa.core.mapi.ObjectType.MAPI_MAILUSER,display_type:Zarafa.core.mapi.DisplayType.DT_MAILUSER,display_type_ex:Zarafa.core.mapi.DisplayType.DT_MAILUSER,display_name:b.get("display_name")+
" ("+d+")",smtp_address:d,email_address:d,address_type:"SMTP",recipient_type:a||Zarafa.core.mapi.RecipientType.MAPI_TO};c.push(Zarafa.core.data.RecordFactory.createRecordObjectByCustomType(Zarafa.core.data.RecordCustomObjectType.ZARAFA_RECIPIENT,d))}return c},openFaxMailCreateDialogForContacts:function(a){var b=this.getMailContextModel().createRecord(),e=b.getRecipientStore();a=Ext.isArray(a)?a:[a];for(var c=0,f=a.length;c<f;c++){var d=this.convertToFaxRecipient(Zarafa.core.mapi.RecipientType.MAPI_TO,
a[c]);e.add(d)}e.getCount()>0&&Zarafa.core.data.UIFactory.openCreateRecord(b)},hasFaxAddress:function(a){return!Ext.isEmpty(a.get("business_fax_number"))||!Ext.isEmpty(a.get("home_fax_number"))||!Ext.isEmpty(a.get("primary_fax_number"))},createSendFaxContextItem:function(){return{text:_("Send Fax"),iconCls:"icon_fax",scope:this,handler:function(a){this.openFaxMailCreateDialogForContacts(a.parentMenu.records)},beforeShow:function(a,b){for(var e=false,c=0,f=b.length;c<f;c++){var d=b[c];if(!d.isMessageClass("IPM.Contact")||
this.hasFaxAddress(d)){e=true;break}}a.setVisible(e)}}}});Zarafa.onReady(function(){container.registerPlugin(new Zarafa.core.PluginMetaData({name:"contactfax",displayName:_("Contact Fax"),pluginConstructor:Zarafa.plugins.contactfax.ContactFax}))});
