Ext.namespace("Zarafa.widgets.quickitems");
Zarafa.widgets.quickitems.AbstractQuickItemWidget=Ext.extend(Zarafa.core.ui.widget.Widget,{record:undefined,wrapCfg:undefined,wrap:undefined,resetOnSave:true,resetOnSend:true,hasDialog:true,constructor:function(a){a=a||{};a.wrapCfg=Ext.applyIf(a.wrapCfg||{},{stateful:false,height:200,closeOnSave:false,closeOnSend:false});a.wrapCfg.recordComponentPluginConfig=Ext.applyIf(a.wrapCfg.recordComponentPluginConfig||{},{useShadowStore:false});this.wrap=new Zarafa.core.ui.MessageContentPanel(a.wrapCfg);this.wrap.update=
this.update.createDelegate(this);this.wrap.updateRecord=this.updateRecord.createDelegate(this);Ext.applyIf(a,{name:"quickitem",layout:"fit",items:[this.wrap]});Zarafa.widgets.quickitems.AbstractQuickItemWidget.superclass.constructor.call(this,a)},initWidget:function(){Zarafa.widgets.quickitems.AbstractQuickItemWidget.superclass.initWidget.apply(this,arguments);this.hasDialog&&this.tools.unshift({id:"plus",handler:this.dialog,scope:this})},initEvents:function(){Zarafa.widgets.quickitems.AbstractQuickItemWidget.superclass.initEvents.apply(this,
arguments);this.mon(this,"afterlayout",this.onAfterFirstLayout,this,{single:true});this.resetOnSave&&this.mon(this.wrap,"aftersaverecord",this.reset,this,{buffer:1});this.resetOnSend&&this.mon(this.wrap,"aftersendrecord",this.reset,this,{buffer:1})},dialog:function(){this.wrap.inputAutoFocusPlugin.beginFocusEl.focus();this.wrap.saveRecord(false);Zarafa.core.data.UIFactory.openCreateRecord(this.record);this.record=null;this.reset()},reset:function(){var a=container.getShadowStore();this.record&&a.remove(this.record,
true);this.record=this.createRecord();a.add(this.record);this.wrap.setRecord(this.record)},createRecord:Ext.emptyFn,update:Ext.emptyFn,updateRecord:Ext.emptyFn,onAfterFirstLayout:function(){var a=container.getHierarchyStore();a.getDefaultStore()?this.reset():this.mon(a,"load",this.reset,this,{single:true})},onDestroy:function(){Zarafa.widgets.quickitems.AbstractQuickItemWidget.superclass.onDestroy.apply(this,arguments);this.record&&container.getShadowStore().remove(this.record,true)}});Ext.namespace("Zarafa.widgets.quickitems");
Zarafa.widgets.quickitems.QuickAppointmentWidget=Ext.extend(Zarafa.widgets.quickitems.AbstractQuickItemWidget,{constructor:function(a){a=a||{};Ext.applyIf(a,{wrapCfg:{recordComponentPluginConfig:Ext.applyIf(a.recordComponentPluginConfig||{},{allowWrite:true}),layout:"fit",items:[{xtype:"form",ref:"formPanel",layout:{type:"vbox",align:"stretch"},border:false,bodyStyle:"background-color: inherit; padding: 5px;",defaults:{border:false,labelLength:100,style:"padding-bottom: 2px"},items:[{xtype:"zarafa.compositefield",
hideLabel:true,anchor:"100%",items:[{xtype:"label",width:100,text:_("Subject")+":"},{xtype:"textfield",flex:1,name:"subject",value:undefined,listeners:{change:this.onChange,scope:this}}]},{xtype:"zarafa.datetimeperiodfield",ref:"../datetimePeriod",defaultPeriod:container.getSettingsModel().get("zarafa/v1/contexts/calendar/default_appointment_period"),timeIncrement:container.getSettingsModel().get("zarafa/v1/contexts/calendar/default_zoom_level"),width:300,listeners:{change:this.onDateRangeFieldChange,
scope:this},startFieldConfig:{fieldLabel:_("Start time"),labelWidth:100,minValue:(new Date).clearTime()},endFieldConfig:{fieldLabel:_("End time"),labelWidth:100,minValue:(new Date).clearTime()}},{xtype:"zarafa.compositefield",hideLabel:true,anchor:"100%",items:[{xtype:"spacer",width:100},{xtype:"checkbox",name:"alldayevent",ref:"../../alldayCheck",hideLabel:false,boxLabel:_("All Day Event"),handler:this.onToggleAllDay,scope:this}]},{xtype:"zarafa.editorfield",ref:"../editorField",htmlName:"html_body",
plaintextName:"body",hideLabel:true,flex:1,useHtml:false,defaultValue:"",listeners:{change:this.onBodyChange,scope:this}}]}]},buttons:[{text:_("Save"),handler:this.onSave,scope:this},{text:_("Discard"),handler:this.onDiscard,scope:this}]});Zarafa.widgets.quickitems.QuickAppointmentWidget.superclass.constructor.call(this,a)},onChange:function(a,b){this.wrap.record.set(a.name,b)},onBodyChange:function(a,b){this.wrap.record.beginEdit();a instanceof Ext.form.HtmlEditor?this.wrap.record.set("isHTML",true):
this.wrap.record.set("isHTML",false);this.wrap.record.set(a.name,b);this.wrap.record.endEdit()},onDateRangeFieldChange:function(a,b){this.updateStartDueDate(this.wrap.record,b)},onToggleAllDay:function(a,b){if(this.wrap.record.get("alldayevent")!==b){var c=container.getSettingsModel();this.wrap.record.beginEdit();this.wrap.record.set("alldayevent",b);if(b){this.updateStartDueDate(this.wrap.record,this.wrap.datetimePeriod.getValue());this.wrap.record.set("reminder_minutes",c.get("zarafa/v1/contexts/calendar/default_allday_reminder_time"));
this.wrap.record.set("busystatus",Zarafa.core.mapi.BusyStatus.FREE)}else{var d=c.get("zarafa/v1/contexts/calendar/default_zoom_level"),f=c.get("zarafa/v1/contexts/calendar/default_appointment_period"),e=new Date;if(this.wrap.record.get("startdate"))e=this.wrap.record.get("startdate").clearTime(true);e=e.ceil(Date.MINUTE,d);d=e.add(Date.MINUTE,f);this.wrap.record.set("reminder_minutes",c.get("zarafa/v1/contexts/calendar/default_reminder_time"));this.wrap.record.set("busystatus",Zarafa.core.mapi.BusyStatus.BUSY);
this.wrap.record.set("startdate",e);this.wrap.record.set("duedate",d);this.wrap.record.set("commonstart",e);this.wrap.record.set("commonend",d);this.wrap.record.set("duration",(d-e)/6E4)}this.wrap.record.endEdit()}},updateStartDueDate:function(a,b){var c=b.getStartDate().clone(),d=b.getDueDate().clone();if(a.get("alldayevent")===true){c=c.clearTime();d=d.add(Date.DAY,1).clearTime()}a.beginEdit();a.set("startdate",c);a.set("duedate",d);a.set("commonstart",c);a.set("commonend",d);a.set("duration",(d-
c)/6E4);a.endEdit()},createRecord:function(){var a=container.getHierarchyStore().getDefaultFolder("calendar");return container.getContextByName("calendar").getModel().createRecord(a)},update:function(a,b){if(b===true||a.isModifiedSinceLastUpdate("alldayevent"))a.get("alldayevent")?this.wrap.datetimePeriod.setEnabledTimeSelection(false):this.wrap.datetimePeriod.setEnabledTimeSelection(true);this.wrap.formPanel.getForm().loadRecord(a);var c=a.get("startdate"),d=false;if(Ext.isDate(c)){c=c.clone();d=
b||a.isModifiedSinceLastUpdate("startdate")}var f=a.get("duedate"),e=false;if(Ext.isDate(f)){f=f.clone();e=b||a.isModifiedSinceLastUpdate("duedate")}if(a.get("alldayevent"))f=f.add(Date.DAY,-1);if(d||e)this.wrap.datetimePeriod.getValue().set(c,f)},updateRecord:function(a){a.beginEdit();this.wrap.formPanel.getForm().updateRecord(a);this.updateStartDueDate(a,this.wrap.datetimePeriod.getValue());this.onToggleAllDay(this.wrap.alldayCheck,this.wrap.alldayCheck.getValue());this.onBodyChange(this.wrap.editorField,
this.wrap.editorField.getValue());a.endEdit()},onSave:function(){this.wrap.saveRecord()},onDiscard:function(){this.reset()}});Zarafa.onReady(function(){container.registerWidget(new Zarafa.core.ui.widget.WidgetMetaData({name:"quickappt",displayName:_("Quick Appointment"),iconPath:"plugins/quickitems/resources/images/quickappt.png",widgetConstructor:Zarafa.widgets.quickitems.QuickAppointmentWidget}))});Ext.namespace("Zarafa.widgets.quickitems");
Zarafa.widgets.quickitems.QuickContactWidget=Ext.extend(Zarafa.widgets.quickitems.AbstractQuickItemWidget,{contactParser:undefined,constructor:function(a){a=a||{};if(!a.contactParser){var b=container.getSharedComponent(Zarafa.core.data.SharedComponentType["contact.detailsparser"]);if(b)a.contactParser=new b}Ext.applyIf(a,{wrapCfg:{recordComponentPluginConfig:Ext.applyIf(a.recordComponentPluginConfig||{},{allowWrite:true}),layout:"fit",items:[{xtype:"form",ref:"formPanel",layout:{type:"vbox",align:"stretch"},
border:false,bodyStyle:"background-color: inherit; padding: 5px;",defaults:{border:false,labelLength:100,style:"padding-bottom: 2px"},items:[{xtype:"zarafa.compositefield",hideLabel:true,anchor:"100%",autoHeight:true,items:[{xtype:"label",width:100,text:_("Full Name")+":"},{xtype:"textfield",flex:1,name:"display_name",ref:"../../fullnameField",listeners:{scope:this,change:this.onFullNameChange}}]},{xtype:"zarafa.compositefield",hideLabel:true,anchor:"100%",autoHeight:true,items:[{xtype:"splitbutton",
width:100,text:_("Mobile")+":",handler:this.onPhoneButtonClick,scope:this,menu:this.initPhoneButtonMenu("cellular_telephone_number")},{xtype:"textfield",ref:"../../telephoneField",flex:1,name:"telephone_number",property:"cellular_telephone_number",listeners:{scope:this,change:this.onTelephoneNumberChange}}]},{xtype:"zarafa.compositefield",hideLabel:true,anchor:"100%",autoHeight:true,items:[{xtype:"label",width:100,text:_("Email")+":"},{xtype:"textfield",flex:1,ref:"../../mailAddressField",name:"email_address_1",
listeners:{scope:this,change:this.onChange}}]},{xtype:"zarafa.editorfield",ref:"../editorField",htmlName:"html_body",plaintextName:"body",hideLabel:true,flex:1,useHtml:false,defaultValue:"",listeners:{change:this.onBodyChange,scope:this}}]}]},buttons:[{text:_("Save"),handler:this.onSave,scope:this},{text:_("Discard"),handler:this.onDiscard,scope:this}]});Zarafa.widgets.quickitems.QuickContactWidget.superclass.constructor.call(this,a)},initPhoneButtonMenu:function(a){return{xtype:"menu",listeners:{click:this.onMenuItemSelection,
scope:this},defaults:{xtype:"menucheckitem",group:"phone_number"},items:[{text:_("Business"),property:"business_telephone_number",checked:a=="business_telephone_number"},{text:_("Company"),property:"company_telephone_number",checked:a=="company_telephone_number"},{text:_("Home"),property:"home_telephone_number",checked:a=="home_telephone_number"},{text:_("Mobile"),property:"cellular_telephone_number",checked:a=="cellular_telephone_number"},{text:_("Other"),property:"other_telephone_number",checked:a==
"other_telephone_number"}]}},onMenuItemSelection:function(a,b){if(!Ext.isEmpty(b)){var c=a.findParentByType("zarafa.compositefield"),d=c.findByType("splitbutton")[0];c=c.findByType("textfield")[0];if(!Ext.isEmpty(d)&&!Ext.isEmpty(c)){d.setText(b.initialConfig.text);c.setValue(this.record.get(b.property));c.property=b.property}}},onPhoneButtonClick:function(a){this.showDetailedPhoneContent(a.ownerCt.findByType("textfield")[0].property)},onChange:function(a,b){this.wrap.record.set(a.name,b)},onTelephoneNumberChange:function(a,
b){this.wrap.record.set(a.property,b)},onFullNameChange:function(a,b){var c=this.contactParser.parseInfo("name",b);this.wrap.record.set("display_name",b);this.wrap.record.set("display_name_prefix",c.display_name_prefix);this.wrap.record.set("given_name",c.given_name);this.wrap.record.set("middle_name",c.middle_name);this.wrap.record.set("surname",c.surname);this.wrap.record.set("generation",c.generation);c.incomplete_info===true&&container.getSettingsModel().get("zarafa/v1/contexts/contact/show_name_dialog")==
true&&!Ext.isEmpty(b)&&this.showDetailedNameContent(c)},onBodyChange:function(a,b){this.wrap.record.beginEdit();a instanceof Ext.form.HtmlEditor?this.wrap.record.set("isHTML",true):this.wrap.record.set("isHTML",false);this.wrap.record.set(a.name,b);this.wrap.record.endEdit()},showDetailedNameContent:function(a){Zarafa.contact.Actions.openDetailedNameContent(this.wrap.record,{parser:this.contactParser,parsedData:a})},showDetailedPhoneContent:function(a){Zarafa.contact.Actions.openDetailedPhoneContent(this.wrap.record,
{parser:this.contactParser,property:a})},createRecord:function(){var a=container.getHierarchyStore().getDefaultFolder("contact");return container.getContextByName("contact").getModel().createRecord(a)},update:function(a){this.wrap.formPanel.getForm().loadRecord(a);this.wrap.telephoneField.setValue(a.get(this.wrap.telephoneField.property))},updateRecord:function(a){a.beginEdit();this.wrap.formPanel.getForm().updateRecord(a);this.onFullNameChange(this.wrap.fullnameField,this.wrap.fullnameField.getValue());
a.updateSubject();a.updateAddressbookProps();a.endEdit()},onSave:function(){this.wrap.saveRecord()},onDiscard:function(){this.reset()}});Zarafa.onReady(function(){container.registerWidget(new Zarafa.core.ui.widget.WidgetMetaData({name:"quickcontact",displayName:_("Quick Contact"),iconPath:"plugins/quickitems/resources/images/quickcontact.png",widgetConstructor:Zarafa.widgets.quickitems.QuickContactWidget}))});Ext.namespace("Zarafa.widgets.quickitems");
Zarafa.widgets.quickitems.QuickMailWidget=Ext.extend(Zarafa.widgets.quickitems.AbstractQuickItemWidget,{useHtml:false,constructor:function(a){a=a||{};Ext.applyIf(a,{wrapCfg:{recordComponentPluginConfig:Ext.applyIf(a.recordComponentPluginConfig||{},{allowWrite:true}),layout:"fit",items:[{xtype:"form",ref:"formPanel",layout:{type:"vbox",align:"stretch"},border:false,bodyStyle:"background-color: inherit; padding: 5px;",defaults:{border:false,labelLength:100,style:"padding-bottom: 2px"},items:[{xtype:"zarafa.compositefield",
hideLabel:true,anchor:"100%",autoHeight:true,items:[{xtype:"label",width:100,text:_("To")+":"},{xtype:"zarafa.recipientfield",ref:"../toRecipientField",flex:1,height:30,defaultRecipientType:Zarafa.core.mapi.RecipientType.MAPI_TO}]},{xtype:"zarafa.compositefield",hideLabel:true,anchor:"100%",items:[{xtype:"label",width:100,text:_("Subject")+":"},{xtype:"textfield",flex:1,name:"subject",value:undefined,listeners:{change:this.onChange,scope:this}}]},{xtype:"zarafa.editorfield",ref:"../editorField",htmlName:"html_body",
plaintextName:"body",hideLabel:true,flex:1,useHtml:a.useHtml,defaultValue:"",listeners:{change:this.onBodyChange,scope:this}}]}]},buttons:[{text:_("Send"),handler:this.onSend,scope:this},{text:_("Discard"),handler:this.onDiscard,scope:this}]});Zarafa.widgets.quickitems.QuickMailWidget.superclass.constructor.call(this,a)},onChange:function(a,b){this.wrap.record.set(a.name,b)},onBodyChange:function(a,b){this.wrap.record.beginEdit();a instanceof Ext.form.HtmlEditor?this.wrap.record.set("isHTML",true):
this.wrap.record.set("isHTML",false);this.wrap.record.set(a.name,b);this.wrap.record.endEdit()},createRecord:function(){var a=container.getHierarchyStore().getDefaultFolder("drafts");return container.getContextByName("mail").getModel().createRecord(a)},update:function(a,b){this.wrap.formPanel.getForm().loadRecord(a);b&&this.wrap.formPanel.toRecipientField.setRecipientStore(a.getSubStore("recipients"))},updateRecord:function(a){a.beginEdit();this.wrap.formPanel.getForm().updateRecord(a);this.onBodyChange(this.wrap.editorField,
this.wrap.editorField.getValue());a.endEdit()},onSend:function(){this.wrap.sendRecord()},onDiscard:function(){this.reset()}});Zarafa.onReady(function(){container.registerWidget(new Zarafa.core.ui.widget.WidgetMetaData({name:"quickmail",displayName:_("Quick Mail"),iconPath:"plugins/quickitems/resources/images/quickmail.png",widgetConstructor:Zarafa.widgets.quickitems.QuickMailWidget}))});Ext.namespace("Zarafa.widgets.quickitems");
Zarafa.widgets.quickitems.QuickNoteWidget=Ext.extend(Zarafa.widgets.quickitems.AbstractQuickItemWidget,{currentColorCls:undefined,constructor:function(a){a=a||{};Ext.applyIf(a,{wrapCfg:{recordComponentPluginConfig:Ext.applyIf(a.recordComponentPluginConfig||{},{allowWrite:true}),layout:"fit",items:[{xtype:"form",ref:"formPanel",layout:"fit",items:[{xtype:"textarea",ref:"../editorField",name:"body",listeners:{change:this.onChange,scope:this}}]}]},buttons:[{text:_("Save"),handler:this.onSave,scope:this},
{text:_("Discard"),handler:this.onDiscard,scope:this}]});Zarafa.widgets.quickitems.QuickNoteWidget.superclass.constructor.call(this,a)},onChange:function(a,b){this.wrap.record.set(a.name,b)},createRecord:function(){var a=container.getHierarchyStore().getDefaultFolder("note");return container.getContextByName("note").getModel().createRecord(a)},update:function(a,b){this.wrap.formPanel.getForm().loadRecord(a);if(b||a.isModifiedSinceLastUpdate("icon_index")){var c;switch(a.get("icon_index")){case Zarafa.core.mapi.IconIndex.note_blue:c=
"stickynote_dialog_blue";break;case Zarafa.core.mapi.IconIndex.note_green:c="stickynote_dialog_green";break;case Zarafa.core.mapi.IconIndex.note_pink:c="stickynote_dialog_pink";break;case Zarafa.core.mapi.IconIndex.note_yellow:default:c="stickynote_dialog_yellow";break;case Zarafa.core.mapi.IconIndex.note_white:c="stickynote_dialog_white";break}this.wrap.editorField.removeClass(this.currentColorCls);this.currentColorCls=c;this.wrap.editorField.addClass(this.currentColorCls)}},updateRecord:function(a){a.beginEdit();
this.wrap.formPanel.getForm().updateRecord(a);this.record.generateSubject();a.endEdit()},onSave:function(){this.wrap.saveRecord()},onDiscard:function(){this.reset()}});Zarafa.onReady(function(){container.registerWidget(new Zarafa.core.ui.widget.WidgetMetaData({name:"quicknote",displayName:_("Quick Note"),iconPath:"plugins/quickitems/resources/images/quicknote.png",widgetConstructor:Zarafa.widgets.quickitems.QuickNoteWidget}))});Ext.namespace("Zarafa.widgets.quickitems");
Zarafa.widgets.quickitems.QuickTaskWidget=Ext.extend(Zarafa.widgets.quickitems.AbstractQuickItemWidget,{constructor:function(a){a=a||{};Ext.applyIf(a,{wrapCfg:{recordComponentPluginConfig:Ext.applyIf(a.recordComponentPluginConfig||{},{allowWrite:true}),layout:"fit",items:[{xtype:"form",ref:"formPanel",layout:{type:"vbox",align:"stretch"},border:false,bodyStyle:"background-color: inherit; padding: 5px;",defaults:{border:false,labelLength:100,style:"padding-bottom: 2px"},items:[{xtype:"zarafa.compositefield",
hideLabel:true,anchor:"100%",items:[{xtype:"label",width:100,text:_("Subject")+":"},{xtype:"textfield",flex:1,name:"subject",value:undefined,listeners:{change:this.onChange,scope:this}}]},{xtype:"zarafa.compositefield",hideLabel:true,anchor:"100%",items:[{xtype:"label",width:100,text:_("End date")+":"},{xtype:"datefield",ref:"../../dueDateField",emptyText:_("None"),flex:1,name:"commonend",utcname:"duedate",format:_("d/m/Y"),minValue:new Date,listeners:{change:this.onDueDateChange,scope:this}}]},{xtype:"zarafa.editorfield",
ref:"../editorField",htmlName:"html_body",plaintextName:"body",hideLabel:true,flex:1,useHtml:false,defaultValue:"",listeners:{change:this.onBodyChange,scope:this}}]}]},buttons:[{text:_("Save"),handler:this.onSave,scope:this},{text:_("Discard"),handler:this.onDiscard,scope:this}]});Zarafa.widgets.quickitems.QuickTaskWidget.superclass.constructor.call(this,a)},onChange:function(a,b){this.wrap.record.set(a.name,b)},onDueDateChange:function(a,b){if(Ext.isDate(b)){this.wrap.record.set(a.name,b.clone());
this.wrap.record.set(a.utcname,b.toUTC())}else{this.wrap.record.set(a.name,null);this.wrap.record.set(a.utcname,null)}},onBodyChange:function(a,b){this.wrap.record.beginEdit();a instanceof Ext.form.HtmlEditor?this.wrap.record.set("isHTML",true):this.wrap.record.set("isHTML",false);this.wrap.record.set(a.name,b);this.wrap.record.endEdit()},createRecord:function(){var a=container.getHierarchyStore().getDefaultFolder("task");return container.getContextByName("task").getModel().createRecord(a)},update:function(a){this.wrap.formPanel.getForm().loadRecord(a)},
updateRecord:function(a){a.beginEdit();this.wrap.formPanel.getForm().updateRecord(a);this.onDueDateChange(this.wrap.dueDateField,this.wrap.dueDateField.getValue());this.onBodyChange(this.wrap.editorField,this.wrap.editorField.getValue());a.endEdit()},onSave:function(){this.wrap.saveRecord()},onDiscard:function(){this.reset()}});
Zarafa.onReady(function(){container.registerWidget(new Zarafa.core.ui.widget.WidgetMetaData({name:"quicktask",displayName:_("Quick Task"),iconPath:"plugins/quickitems/resources/images/quicktask.png",widgetConstructor:Zarafa.widgets.quickitems.QuickTaskWidget}))});
