Ext.namespace("Zarafa.plugins.mdm");Zarafa.plugins.mdm.MDM=Ext.extend(Zarafa.core.Plugin,{constructor:function(a){a=a||{};Zarafa.plugins.mdm.MDM.superclass.constructor.call(this,a)},initPlugin:function(){this.registerInsertionPoint("context.settings.categories",this.createSettingCategory,this);Zarafa.plugins.mdm.MDM.superclass.initPlugin.apply(this,arguments)},createSettingCategory:function(){return[{xtype:"Zarafa.plugins.mdm.mdmsettingscategory"}]}});
Zarafa.onReady(function(){container.registerPlugin(new Zarafa.core.PluginMetaData({name:"mdm",displayName:_("Mobile device management"),pluginConstructor:Zarafa.plugins.mdm.MDM}))});Ext.namespace("Zarafa.plugins.mdm.data");
Zarafa.plugins.mdm.data.JsonCertificateReader=Ext.extend(Zarafa.core.data.JsonReader,{customObjectType:Zarafa.core.data.RecordCustomObjectType.ZARAFA_MDM,constructor:function(a,b){a=Ext.applyIf(a||{},{dynamicRecord:false});b=Zarafa.core.data.RecordFactory.getRecordClassByCustomType(Zarafa.core.data.RecordCustomObjectType.ZARAFA_MDM);Zarafa.plugins.mdm.data.JsonCertificateReader.superclass.constructor.call(this,a,b)}});Ext.namespace("Zarafa.plugins.mdm");
Zarafa.plugins.mdm.data.MDMDeviceRecordFields=[{name:"entryid",type:"string"},{name:"changed",type:"boolean"},{name:"deviceos",type:"string"},{name:"devicefriendlyname",type:"string"},{name:"deviceinfo",type:"string"},{name:"devicetype",type:"string"},{name:"devicemodel",type:"string"},{name:"domain",type:"string"},{name:"hierarchyuuid",type:"string"},{name:"firstsynctime",type:"date",dateFormat:"timestamp"},{name:"lastupdatetime",type:"date",dateFormat:"timestamp"},{name:"wipestatus",type:"string"},
{name:"useragent",type:"string"}];Zarafa.plugins.mdm.data.MDMDeviceRecord=Ext.extend(Zarafa.core.data.IPMRecord,{});Zarafa.core.data.RecordCustomObjectType.addProperty("ZARAFA_MDM");Zarafa.core.data.RecordFactory.addFieldToCustomType(Zarafa.core.data.RecordCustomObjectType.ZARAFA_MDM,Zarafa.plugins.mdm.data.MDMDeviceRecordFields);Zarafa.core.data.RecordFactory.addListenerToCustomType(Zarafa.core.data.RecordCustomObjectType.ZARAFA_MDM,"createphantom",function(a){a.afterOpen()});
Zarafa.core.data.RecordFactory.setBaseClassToCustomType(Zarafa.core.data.RecordCustomObjectType.ZARAFA_MDM,Zarafa.plugins.mdm.data.MDMDeviceRecord);Ext.namespace("Zarafa.plugins.mdm.data");
Zarafa.plugins.mdm.data.MDMDeviceStore=Ext.extend(Zarafa.core.data.ListModuleStore,{constructor:function(a){a=a||{};Ext.applyIf(a,{autoLoad:true,remoteSort:false,reader:new Zarafa.plugins.mdm.data.JsonCertificateReader,writer:new Zarafa.core.data.JsonWriter,proxy:new Zarafa.core.data.IPMProxy({listModuleName:"pluginmdmmodule",itemModuleName:"pluginmdmmodule"})});Zarafa.plugins.mdm.data.MDMDeviceStore.superclass.constructor.call(this,a)}});Ext.reg("mdm.devicestore",Zarafa.plugins.mdm.data.MDMDeviceStore);
Ext.namespace("Zarafa.plugins.mdm.data");
Zarafa.plugins.mdm.data.MDMResponseHandler=Ext.extend(Zarafa.core.data.AbstractResponseHandler,{successCallback:Ext.emptyFn,failureCallback:Ext.emptyFn,doInfo:function(a){this.successCallback(a)},doRemove:function(a){a.remove&&this.successCallback()},doWipe:function(a){a.wipe===true?container.getNotifier().notify("info.mdm",_("Mobile Device Manager"),_("Wiping device")):container.getNotifier().notify("info.mdm",_("Mobile Device Manager"),_("Password incorrect"))},doResync:function(a){a.resync===true&&
container.getNotifier().notify("info.mdm",_("Mobile Device Manager"),_("Full resync in progress"))}});Ext.reg("mdm.responsehandler",Zarafa.plugins.mdm.data.MDMResponseHandler);Ext.namespace("Zarafa.plugins.mdm.data");
Zarafa.plugins.mdm.data.ProvisioningStatus=Zarafa.core.Enum.create({NOT_APPLICABLE:0,OK:1,WIPE_PENDING:2,WIPE_REQUESTED:4,WIPE_EXECUTED:8,getDisplayName:function(a){switch(a){case Zarafa.plugins.mdm.data.ProvisioningStatus.NOT_APPLICABLE:return _("Not Applicable");case Zarafa.plugins.mdm.data.ProvisioningStatus.OK:return _("Ok");case Zarafa.plugins.mdm.data.ProvisioningStatus.WIPE_PENDING:return _("Wipe Pending");case Zarafa.plugins.mdm.data.ProvisioningStatus.WIPE_REQUESTED:return _("Wipe Requested");
case Zarafa.plugins.mdm.data.ProvisioningStatus.WIPE_EXECUTED:return _("Wipe Executed")}return""}});Ext.namespace("Zarafa.plugins.mdm.settings");Zarafa.plugins.mdm.settings.MDMSettingsCategory=Ext.extend(Zarafa.settings.ui.SettingsCategory,{constructor:function(a){a=a||{};Ext.applyIf(a,{title:_("MDM"),iconCls:"icon_mdm_settings",items:[{xtype:"Zarafa.plugins.mdm.mdmsettingswidget"}]});Zarafa.plugins.mdm.settings.MDMSettingsCategory.superclass.constructor.call(this,a)}});
Ext.reg("Zarafa.plugins.mdm.mdmsettingscategory",Zarafa.plugins.mdm.settings.MDMSettingsCategory);Ext.namespace("Zarafa.plugins.mdm.settings");
Zarafa.plugins.mdm.settings.MDMSettingsWidget=Ext.extend(Zarafa.settings.ui.SettingsWidget,{constructor:function(a){a=a||{};var b=new Zarafa.plugins.mdm.data.MDMDeviceStore;Ext.applyIf(a,{title:_("Mobile Devices"),items:[{xtype:"container",layout:"column",items:[{xtype:"grid",name:_("Devices"),ref:"../deviceGrid",height:400,store:b,viewConfig:{forceFit:true,deferEmptyText:false,emptyText:'<div class="emptytext">'+_("No devices connected to your account")+"</div>"},columns:[{dataIndex:"devicetype",
header:_("Device"),renderer:Ext.util.Format.htmlEncode},{dataIndex:"useragent",header:_("User Agent"),renderer:Ext.util.Format.htmlEncode},{dataIndex:"wipestatus",header:_("Provisioning Status"),renderer:Zarafa.plugins.mdm.ui.Renderers.provisioningStatus},{dataIndex:"lastupdatetime",header:_("Last Update"),renderer:Ext.util.Format.htmlEncode},{dataIndex:"entryid",header:_("Device ID"),renderer:Ext.util.Format.htmlEncode},{dataIndex:"deviceos",header:_("Device OS"),hidden:true,renderer:Ext.util.Format.htmlEncode},
{dataIndex:"devicefriendlyname",header:_("Device Info"),hidden:true,renderer:Ext.util.Format.htmlEncode},{dataIndex:"firstsynctime",header:_("First Sync time"),hidden:true,renderer:Ext.util.Format.htmlEncode}],buttons:[{text:_("Wipe Device"),ref:"../../../wipeBtn",handler:this.onWipeBtn,scope:this},{text:_("Full resync"),ref:"../../../resyncBtn",handler:this.onFullResync,scope:this},{text:_("Remove device"),ref:"../../../removeBtn",handler:this.onRemoveDevice,scope:this},{text:_("Refresh"),ref:"../../../refresh",
handler:this.onRefresh,scope:this}]}]}]});Zarafa.plugins.mdm.settings.MDMSettingsWidget.superclass.constructor.call(this,a)},onWipeBtn:function(){Ext.MessageBox.show({title:_("Zarafa WebApp"),msg:_("Do you really want to wipe your device?\n Enter your password to confirm."),inputType:"password",icon:Ext.MessageBox.WARNING,buttons:Ext.MessageBox.YESNO,fn:this.onWipeDevice,prompt:true,scope:this.deviceGrid}).getDialog().body.child("input").dom.type="password"},onWipeDevice:function(a,b){if(a==="yes"){var c=
this.getSelectionModel().getSelected();c&&container.getRequest().singleRequest("pluginmdmmodule","wipe",{deviceid:c.get("entryid"),password:b},new Zarafa.plugins.mdm.data.MDMResponseHandler)}},onFullResync:function(){var a=this.deviceGrid.getSelectionModel().getSelected();a&&container.getRequest().singleRequest("pluginmdmmodule","resync",{deviceid:a.get("entryid")},new Zarafa.plugins.mdm.data.MDMResponseHandler)},onRemoveDevice:function(){var a=this.deviceGrid.getSelectionModel().getSelected();a&&
container.getRequest().singleRequest("pluginmdmmodule","remove",{deviceid:a.get("entryid")},new Zarafa.plugins.mdm.data.MDMResponseHandler({successCallback:this.removeDone.createDelegate(this,[a],true)}))},removeDone:function(a){a.getStore().remove(a)},onRefresh:function(){this.deviceGrid.getStore().load()}});Ext.reg("Zarafa.plugins.mdm.mdmsettingswidget",Zarafa.plugins.mdm.settings.MDMSettingsWidget);Ext.namespace("Zarafa.plugins.mdm.ui");Zarafa.plugins.mdm.ui.Renderers={provisioningStatus:function(a){return Zarafa.plugins.mdm.data.ProvisioningStatus.getDisplayName(parseInt(a))}};
