199 lines
5.4 KiB
JavaScript
199 lines
5.4 KiB
JavaScript
|
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'),
|
||
|
items : [{
|
||
|
xtype : 'container',
|
||
|
layout : 'column',
|
||
|
items : [{
|
||
|
xtype : 'grid',
|
||
|
name : _('Devices'),
|
||
|
ref : '../deviceGrid',
|
||
|
height : 400,
|
||
|
store : store,
|
||
|
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, 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'),
|
||
|
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
|
||
|
});
|
||
|
|
||
|
// 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();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Ext.reg('Zarafa.plugins.mdm.mdmsettingswidget', Zarafa.plugins.mdm.settings.MDMSettingsWidget);
|