KWA-MDM/js/settings/MDMSettingsWidget.js

199 lines
5.6 KiB
JavaScript
Raw Normal View History

2016-05-11 10:40:44 +02:00
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'),
2016-05-11 10:40:44 +02:00
items : [{
xtype : 'container',
layout : 'column',
items : [{
xtype : 'grid',
name : _('Devices', 'plugin_mdm'),
2016-05-11 10:40:44 +02:00
ref : '../deviceGrid',
height : 400,
store : store,
viewConfig : {
forceFit : true,
deferEmptyText: false,
emptyText: '<div class="emptytext">' + _('No devices connected to your account', 'plugin_mdm') + '</div>'
2016-05-11 10:40:44 +02:00
},
columns : [{
dataIndex : 'devicetype',
header : _('Device', 'plugin_mdm'),
2016-05-11 10:40:44 +02:00
renderer : Ext.util.Format.htmlEncode
},{
dataIndex : 'useragent',
header : _('User Agent', 'plugin_mdm'),
2016-05-11 10:40:44 +02:00
renderer : Ext.util.Format.htmlEncode
},{
dataIndex : 'wipestatus',
header : _('Provisioning Status', 'plugin_mdm'),
2016-05-11 10:40:44 +02:00
renderer : Zarafa.plugins.mdm.ui.Renderers.provisioningStatus
},{
dataIndex : 'lastupdatetime',
header : _('Last Update', 'plugin_mdm'),
2016-05-11 10:40:44 +02:00
renderer : Ext.util.Format.htmlEncode
},{
dataIndex : 'entryid',
header : _('Device ID', 'plugin_mdm'),
2016-05-11 10:40:44 +02:00
renderer : Ext.util.Format.htmlEncode
},{
dataIndex : 'deviceos',
header : _('Device OS', 'plugin_mdm'),
2016-05-11 10:40:44 +02:00
hidden : true,
renderer : Ext.util.Format.htmlEncode
},{
dataIndex : 'devicefriendlyname',
header : _('Device Info', 'plugin_mdm'),
2016-05-11 10:40:44 +02:00
hidden : true,
renderer : Ext.util.Format.htmlEncode
},{
dataIndex : 'firstsynctime',
header : _('First Sync time', 'plugin_mdm'),
2016-05-11 10:40:44 +02:00
hidden : true,
renderer : Ext.util.Format.htmlEncode
}],
buttons : [{
text : _('Wipe Device', 'plugin_mdm'),
2016-05-11 10:40:44 +02:00
ref : '../../../wipeBtn',
handler : this.onWipeBtn,
scope : this
},{
text : _('Full resync', 'plugin_mdm'),
2016-05-11 10:40:44 +02:00
ref : '../../../resyncBtn',
handler : this.onFullResync,
scope : this
},{
text : _('Remove device', 'plugin_mdm'),
2016-05-11 10:40:44 +02:00
ref : '../../../removeBtn',
handler : this.onRemoveDevice,
scope : this
},{
text : _('Refresh', 'plugin_mdm'),
2016-05-11 10:40:44 +02:00
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', 'plugin_mdm'),
msg: _('Do you really want to wipe your device?\n Enter your password to confirm.', 'plugin_mdm'),
2016-05-11 10:40:44 +02:00
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);