Added ActiveSync section in folder editing form (#476)

This commit is contained in:
Aleksander Machniak 2014-08-12 13:43:25 +02:00
parent 1016f4381c
commit f75cc4757d
5 changed files with 155 additions and 11 deletions

View file

@ -41,7 +41,7 @@ function kolab_activesync_config()
if (!rcmail.env.devicecount)
device_select();
}
else {
else if (rcmail.env.action != 'edit-folder') {
if (rcmail.env.active_device)
rcmail.enable_command('plugin.save-config', true);
@ -155,9 +155,36 @@ function kolab_activesync_config()
this.update_list = function(id, name)
{
$('#devices-table tr.selected span.devicealias').html(name);
}
};
};
this.update_sync_data = function(elem)
{
elem.name.match(/^_(subscriptions|alarms)\[(.+)\]$/);
var flag, type = RegExp.$1, device = RegExp.$2,
http_lock = rcmail.set_busy(true, 'kolab_activesync.savingdata');
// set subscription flag
if (elem.checked) {
flag = type == 'alarms' ? 2 : 1;
}
else {
flag = type == 'alarms' ? 1 : 0;
}
// make sure subscription checkbox is checked if alarms is checked
if (flag == 2) {
$('input[name="_subscriptions[' + device + ']"]').prop('checked', true);
}
// make sure alarms checkbox is unchecked if subscription is unchecked
else if (flag == 0) {
$('input[name="_alarms[' + device + ']"]').prop('checked', false);
}
// send the request
rcmail.http_post('plugin.activesync-json', {cmd: 'update', id: device, flag: flag, folder: rcmail.env.folder}, http_lock);
};
};
window.rcmail && rcmail.addEventListener('init', function(evt) {
activesync_object = new kolab_activesync_config();

View file

@ -53,10 +53,12 @@ class kolab_activesync extends rcube_plugin
$this->register_action('plugin.activesync-json', array($this, 'json_command'));
$this->add_hook('settings_actions', array($this, 'settings_actions'));
$this->add_hook('folder_form', array($this, 'folder_form'));
$this->add_texts('localization/', array('devicedeleteconfirm', 'savingdata'));
$this->add_texts('localization/');
if (strpos($this->rc->action, 'plugin.activesync') === 0) {
if (preg_match('/^(plugin.activesync|edit-folder|save-folder)/', $this->rc->action)) {
$this->add_label('devicedeleteconfirm', 'savingdata');
$this->include_script('kolab_activesync.js');
}
}
@ -77,13 +79,52 @@ class kolab_activesync extends rcube_plugin
return $args;
}
/**
* Handler for folder info/edit form (folder_form hook).
* Adds ActiveSync section.
*/
function folder_form($args)
{
$mbox_imap = $args['options']['name'];
$myrights = $args['options']['rights'];
// Edited folder name (empty in create-folder mode)
if (!strlen($mbox_imap)) {
return $args;
}
$devices = $this->list_devices();
// no registered devices
if (empty($devices)) {
return $args;
}
list($type, ) = explode('.', (string) kolab_storage::folder_type($mbox_imap));
if ($type && !in_array($type, array('mail', 'event', 'contact', 'task', 'note'))) {
return $args;
}
require_once $this->home . '/kolab_activesync_ui.php';
$this->ui = new kolab_activesync_ui($this);
if ($content = $this->ui->folder_options_table($mbox_imap, $devices, $type)) {
$args['form']['activesync'] = array(
'name' => rcube::Q($this->gettext('tabtitle')),
'content' => $content,
);
}
return $args;
}
/**
* Handle JSON requests
*/
public function json_command()
{
$cmd = get_input_value('cmd', RCUBE_INPUT_GPC);
$imei = get_input_value('id', RCUBE_INPUT_GPC);
$cmd = get_input_value('cmd', RCUBE_INPUT_POST);
$imei = get_input_value('id', RCUBE_INPUT_POST);
switch ($cmd) {
case 'save':
@ -130,6 +171,19 @@ class kolab_activesync extends rcube_plugin
$this->rc->output->show_message($this->gettext('savingerror'), 'error');
break;
case 'update':
$subscription = (int) get_input_value('flag', RCUBE_INPUT_POST);
$folder = get_input_value('folder', RCUBE_INPUT_POST);
$err = !$this->folder_set($folder, $imei, $subscription);
if ($err)
$this->rc->output->show_message($this->gettext('savingerror'), 'error');
else
$this->rc->output->show_message($this->gettext('successfullysaved'), 'confirmation');
break;
}
$this->rc->output->send();

View file

@ -37,7 +37,6 @@ class kolab_activesync_ui
$this->skin_path = 'plugins/kolab_activesync/' . $skin_path;
$this->plugin->include_stylesheet($skin_path . 'config.css');
$this->rc->output->include_script('list.js');
}
public function device_list($attrib = array())
@ -56,6 +55,8 @@ class kolab_activesync_ui
$this->rc->output->add_gui_object('devicelist', $attrib['id']);
$this->rc->output->set_env('devicecount', count($devices));
$this->rc->output->include_script('list.js');
return $table->show($attrib);
}
@ -195,4 +196,51 @@ class kolab_activesync_ui
return $table->show();
}
public function folder_options_table($folder_name, $devices, $type)
{
$alarms = $type == 'event' || $type == 'task';
$meta = $this->plugin->folder_meta();
$folder_data = (array) ($meta[$folder_name] ? $meta[$folder_name]['FOLDER'] : null);
$table = new html_table(array('cellspacing' => 0, 'id' => 'folder-sync-options', 'class' => 'records-table'));
// table header
$table->add_header(array('class' => 'device'), $this->plugin->gettext('devicealias'));
$table->add_header(array('class' => 'subscription'), $this->plugin->gettext('synchronize'));
if ($alarms) {
$table->add_header(array('class' => 'alarm'), $this->plugin->gettext('withalarms'));
}
// table records
foreach ($devices as $id => $device) {
$info = $this->plugin->device_info($device['ID']);
$name = $id;
$title = '';
$checkbox = new html_checkbox(array('name' => "_subscriptions[$id]", 'value' => 1,
'onchange' => 'return activesync_object.update_sync_data(this)'));
if (!empty($info)) {
$_name = trim($info['friendlyname'] . ' ' . $info['os']);
$title = $info['useragent'];
if ($_name) {
$name .= " ($_name)";
}
}
$table->add_row();
$table->add(array('class' => 'device', 'title' => $title), $name);
$table->add('subscription', $checkbox->show(!empty($folder_data[$id]['S']) ? 1 : 0));
if ($alarms) {
$checkbox_alarm = new html_checkbox(array('name' => "_alarms[$id]", 'value' => 1,
'onchange' => 'return activesync_object.update_sync_data(this)'));
$table->add('alarm', $checkbox_alarm->show($folder_data[$id]['S'] > 1 ? 1 : 0));
}
}
return $table->show();
}
}

View file

@ -19,9 +19,9 @@
<email>bruederli@kolabsys.com</email>
<active>yes</active>
</lead>
<date>2013-04-09</date>
<date>2014-08-12</date>
<version>
<release>1.0</release>
<release>1.1</release>
<api>1.0</api>
</version>
<stability>

View file

@ -46,7 +46,7 @@ div.subscriptionblock h3.event {
}
div.subscriptionblock h3.task {
background-position: 4px -58x;
background-position: 4px -58px;
}
div.subscriptionblock h3.note {
@ -98,6 +98,21 @@ div.subscriptionblock h3.note {
margin-top: 0.5em;
}
#folder-sync-options {
border-radius: 4px;
}
#folder-sync-options td.subscription,
#folder-sync-options td.alarm,
#folder-sync-options th {
text-align: center;
}
#folder-sync-options th.subscription,
#folder-sync-options th.alarm {
width: 90px;
}
#introtext {
position: absolute;
top: 16px;