Ext.namespace('Zarafa.plugins.mdm.settings'); /** * @class Zarafa.plugins.mdm.settings.MDMSettingsWidget * @extends Zarafa.settings.ui.SettingsWidget */ Zarafa.plugins.mdm.settings.MDMSettingsWidget = Ext.extend(Zarafa.settings.ui.SettingsWidget, { /** * @constructor * @param {Object} config Configuration object */ constructor : function(config) { config = config || {}; var store = new Zarafa.plugins.mdm.data.MDMDeviceStore(); Ext.applyIf(config, { title : _('Mobile Devices', 'plugin_mdm'), items : [{ xtype : 'container', layout: 'fit', items : [{ xtype : 'grid', name : _('Devices', 'plugin_mdm'), ref : '../deviceGrid', height : 400, store : store, viewConfig : { forceFit : true, deferEmptyText: false, emptyText: '
' + _('No devices connected to your account', 'plugin_mdm') + '
' }, columns : [{ dataIndex : 'devicetype', header : _('Device', 'plugin_mdm'), renderer : Ext.util.Format.htmlEncode },{ dataIndex : 'useragent', header : _('User Agent', 'plugin_mdm'), renderer : Ext.util.Format.htmlEncode },{ dataIndex : 'wipestatus', header : _('Provisioning Status', 'plugin_mdm'), renderer : Zarafa.plugins.mdm.ui.Renderers.provisioningStatus },{ dataIndex : 'lastupdatetime', header : _('Last Update', 'plugin_mdm'), renderer : Ext.util.Format.htmlEncode },{ dataIndex : 'entryid', header : _('Device ID', 'plugin_mdm'), renderer : Ext.util.Format.htmlEncode },{ dataIndex : 'deviceos', header : _('Device OS', 'plugin_mdm'), hidden : true, renderer : Ext.util.Format.htmlEncode },{ dataIndex : 'devicefriendlyname', header : _('Device Info', 'plugin_mdm'), hidden : true, renderer : Ext.util.Format.htmlEncode },{ dataIndex : 'firstsynctime', header : _('First Sync time', 'plugin_mdm'), hidden : true, renderer : Ext.util.Format.htmlEncode }], buttons : [{ text : _('Wipe Device', 'plugin_mdm'), ref : '../../../wipeBtn', handler : this.onWipeBtn, scope : this },{ text : _('Full resync', 'plugin_mdm'), ref : '../../../resyncBtn', handler : this.onFullResync, scope : this },{ text : _('Remove device', 'plugin_mdm'), ref : '../../../removeBtn', handler : this.onRemoveDevice, scope : this },{ text : _('Refresh', 'plugin_mdm'), ref : '../../../refresh', handler : this.onRefresh, scope : this }], listeners : { rowdblclick: this.onRowDblClick, rowclick: this.onRowClick, scope: this } }] }] }); Zarafa.plugins.mdm.settings.MDMSettingsWidget.superclass.constructor.call(this, config); }, /** * Function which handles the click event on the "Wipe Device" button, displays * a MessageBox for the user to confirm the wipe action. The wipe action is * handled by the onWipeDevice function. */ onWipeBtn : function() { var msgbox = Ext.MessageBox.show({ title: _('Kopano WebApp', 'plugin_mdm'), msg: _('Do you really want to wipe your device?\n Enter your password to confirm.', 'plugin_mdm'), inputType :'password', icon: Ext.MessageBox.WARNING, buttons: Ext.MessageBox.YESNO, fn: this.onWipeDevice, prompt: true, scope: this.deviceGrid }); // ExtJS does not support a password field. msgbox.getDialog().body.child('input').dom.type = 'password'; }, /** * Function which handles the confirmation button in the "wipe device" messagebox. * Sends an wipe request to PHP for the selected device in the grid. * * @param {Ext.Button} button button from the messagebox * @param {String} password user password */ onWipeDevice : function(button, password) { if (button === 'yes') { var selectionModel = this.getSelectionModel(); var record = selectionModel.getSelected(); if (record) { container.getRequest().singleRequest( 'pluginmdmmodule', 'wipe', { 'deviceid' : record.get('entryid'), 'password': password }, new Zarafa.plugins.mdm.data.MDMResponseHandler() ); } } }, /** * Function which handles the click event on the "Full resync" button, sends a * full resync request to PHP. */ onFullResync : function() { var selectionModel = this.deviceGrid.getSelectionModel(); var record = selectionModel.getSelected(); if(record) { container.getRequest().singleRequest( 'pluginmdmmodule', 'resync', { 'deviceid' : record.get('entryid') }, new Zarafa.plugins.mdm.data.MDMResponseHandler() ); } }, /** * Remove all state data for a device, essentially resyncing it. */ onRemoveDevice : function() { var selectionModel = this.deviceGrid.getSelectionModel(); var record = selectionModel.getSelected(); if(record) { container.getRequest().singleRequest( 'pluginmdmmodule', 'remove', { 'deviceid' : record.get('entryid') }, new Zarafa.plugins.mdm.data.MDMResponseHandler({ successCallback : this.removeDone.createDelegate(this, [record], true) }) ); } }, /** * Callback function triggers when device was successfully removed from the z-push server. * we have to remove that device from {@link Zarafa.plugins.mdm.data.MDMDeviceStore store}. * @param {Zarafa.plugins.mdm.data.MDMDeviceRecord} record {@link Zarafa.core.data.IPMRecord record} object */ removeDone : function(record) { record.getStore().remove(record); }, /** * Function which refreshes the store records from the server. */ onRefresh : function() { this.deviceGrid.getStore().load(); }, /** * Function is called if a row in the grid gets double clicked. * Which is use to show a dialog with detail device information * @param {Ext.grid.GridPanel} grid The Grid on which the user double-clicked * @param {Number} rowIndex The Row number on which was double-clicked. */ onRowDblClick : function (grid, rowIndex) { var record = grid.getStore().getAt(rowIndex); Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType['mdm.dialog.mdmdevicecontentpanel'], undefined, { manager : Ext.WindowMgr, record : record }); }, /** * Function is called if a row in the grid gets clicked. * Which is use to disabled wipe button if wipe status is not available. * @param {Ext.grid.GridPanel} grid The Grid on which the user clicked * @param {Number} rowIndex The Row number on which was clicked. */ onRowClick : function (grid, rowIndex) { var record = grid.getStore().getAt(rowIndex); this.wipeBtn.setDisabled(!Ext.isDefined(record.get('wipestatus'))); } }); Ext.reg('Zarafa.plugins.mdm.mdmsettingswidget', Zarafa.plugins.mdm.settings.MDMSettingsWidget);