Page MenuHomePhorge

No OneTemporary

Size
16 KB
Referenced Files
None
Subscribers
None
diff --git a/plugins/kolab_zpush/kolab_zpush.js b/plugins/kolab_zpush/kolab_zpush.js
index 76c89f4d..1605fcdb 100644
--- a/plugins/kolab_zpush/kolab_zpush.js
+++ b/plugins/kolab_zpush/kolab_zpush.js
@@ -1,172 +1,181 @@
/**
* Client scripts for the Kolab Z-Push configuration utitlity
*
* @version 0.2
* @author Thomas Bruederli <roundcube@gmail.com>
*
* Copyright (C) 2011, Kolab Systems AG <contact@kolabsys.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function kolab_zpush_config()
{
/* private members */
var me = this;
var http_lock = null;
var active_device = null;
/* constructor */
var devicelist = new rcube_list_widget(rcmail.gui_objects.devicelist,
{ multiselect:true, draggable:false, keyboard:true });
devicelist.addEventListener('select', select_device);
devicelist.init();
rcmail.register_command('plugin.save-config', save_config);
rcmail.register_command('plugin.delete-device', delete_device_config);
rcmail.addEventListener('plugin.zpush_data_ready', device_data_ready);
rcmail.addEventListener('plugin.zpush_save_complete', save_complete);
- $('input.subscription').change(function(e){ $('#'+this.id+'_alarm').prop('disabled', !this.checked); });
+ $('input.alarm').change(function(e){ if (this.checked) $('#'+this.id.replace(/_alarm/, '')).prop('checked', this.checked); });
+ $('input.subscription').change(function(e){ if (!this.checked) $('#'+this.id+'_alarm').prop('checked', false); });
$(window).bind('resize', resize_ui);
-
+
+ $('.subscriptionblock thead td.subscription img, .subscriptionblock thead td.alarm img').click(function(e){
+ var $this = $(this);
+ var classname = $this.parent().get(0).className;
+ var check = !($this.data('checked') || false);
+ $this.css('cursor', 'pointer').data('checked', check)
+ .closest('table').find('input.'+classname).prop('checked', check).change();
+ });
+
// select the one and only device from list
if (rcmail.env.devicecount == 1) {
for (var imei in rcmail.env.devices)
break;
devicelist.select(imei);
}
/* private methods */
function select_device(list)
{
active_device = list.get_single_selection();
rcmail.enable_command('plugin.save-config', 'plugin.delete-device', true);
if (active_device) {
http_lock = rcmail.set_busy(true, 'loading');
rcmail.http_request('plugin.zpushjson', { cmd:'load', id:active_device }, http_lock);
}
$('#introtext').hide();
}
// callback from server after loading device data
function device_data_ready(data)
{
// reset form first
$('input.alarm:checked').prop('checked', false);
$('input.subscription:checked').prop('checked', false).change();
if (data.id && data.id == active_device) {
$('#config-device-alias').val(data.devicealias);
$('#config-device-mode').val(data.syncmode);
$('#config-device-laxpic').prop('checked', data.laxpic ? true : false);
$('input.subscription').each(function(i, elem){
var key = elem.value;
elem.checked = data.subscribed[key] ? true : false;
}).change();
$('input.alarm').each(function(i, elem){
var key = elem.value;
elem.checked = data.subscribed[key] == 2;
});
$('#configform, #prefs-box .boxtitle').show();
resize_ui();
}
else {
$('#configform, #prefs-box .boxtitle').hide();
}
}
// submit current configuration form to server
function save_config()
{
// TODO: validate device info
var data = {
cmd: 'save',
id: active_device,
devicealias: $('#config-device-alias').val(),
syncmode: $('#config-device-mode option:selected').val(),
laxpic: $('#config-device-laxpic').get(0).checked ? 1 : 0
};
data.subscribed = {};
$('input.subscription:checked').each(function(i, elem){
data.subscribed[elem.value] = 1;
});
$('input.alarm:checked').each(function(i, elem){
if (data.subscribed[elem.value])
data.subscribed[elem.value] = 2;
});
http_lock = rcmail.set_busy(true, 'kolab_zpush.savingdata');
rcmail.http_post('plugin.zpushjson', data, http_lock);
}
// callback function when saving has completed
function save_complete(p)
{
if (p.success && p.devicealias) {
$('#devices-table tr.selected span.devicealias').html(p.devicealias);
rcmail.env.devices[p.id].ALIAS = p.devicealias;
}
}
// handler for delete commands
function delete_device_config()
{
if (active_device && confirm(rcmail.gettext('devicedeleteconfirm', 'kolab_zpush'))) {
http_lock = rcmail.set_busy(true, 'kolab_zpush.savingdata');
rcmail.http_post('plugin.zpushjson', { cmd:'delete', id:active_device }, http_lock);
}
}
// handler for window resize events: sets max-height of folders list scroll container
function resize_ui()
{
if (active_device) {
var h = $(window).height();
var pos = $('#foldersubscriptions').offset();
$('#foldersubscriptions').css('max-height', (h - pos.top - 90) + 'px');
}
}
}
window.rcmail && rcmail.addEventListener('init', function(evt) {
var ACTION_CONFIG = 'plugin.zpushconfig';
// add button to tabs list
var tab = $('<span>').attr('id', 'settingstabpluginzpushconfig').addClass('tablink');
var button = $('<a>').attr('href', rcmail.env.comm_path+'&_action=plugin.zpushconfig').html(rcmail.gettext('tabtitle', 'kolab_zpush')).appendTo(tab);
rcmail.add_element(tab, 'tabs');
if (rcmail.env.action == ACTION_CONFIG)
new kolab_zpush_config();
});
// extend jQuery
(function($){
$.fn.serializeJSON = function(){
var json = {};
jQuery.map($(this).serializeArray(), function(n, i) {
json[n['name']] = n['value'];
});
return json;
};
})(jQuery);
diff --git a/plugins/kolab_zpush/kolab_zpush_ui.php b/plugins/kolab_zpush/kolab_zpush_ui.php
index 1536f0a0..4abf3096 100644
--- a/plugins/kolab_zpush/kolab_zpush_ui.php
+++ b/plugins/kolab_zpush/kolab_zpush_ui.php
@@ -1,216 +1,171 @@
<?php
/**
* Z-Push configuration user interface builder
*
* @version 0.1
* @author Thomas Bruederli <bruederli@kolabsys.com>
*
* Copyright (C) 2011, Kolab Systems AG <contact@kolabsys.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class kolab_zpush_ui
{
private $rc;
private $config;
public function __construct($config)
{
$this->config = $config;
$this->rc = rcmail::get_instance();
$skin = $this->rc->config->get('skin');
$this->config->include_stylesheet('skins/' . $skin . '/config.css');
$this->rc->output->include_script('list.js');
$this->skin_path = $this->config->urlbase . 'skins/' . $skin . '/';
}
public function device_list($attrib = array())
{
$attrib += array('id' => 'devices-list');
$devices = $this->config->list_devices();
$table = new html_table();
foreach ($devices as $id => $device) {
$name = $device['ALIAS'] ? $device['ALIAS'] : $id;
$table->add_row(array('id' => 'rcmrow' . $id));
$table->add(null, html::span('devicealias', Q($name)) . html::span('devicetype', Q($device['TYPE'])));
}
$this->rc->output->add_gui_object('devicelist', $attrib['id']);
$this->rc->output->set_env('devices', $devices);
return $table->show($attrib);
}
public function device_config_form($attrib = array())
{
$table = new html_table(array('cols' => 2));
$field_id = 'config-device-alias';
$input = new html_inputfield(array('name' => 'devicealias', 'id' => $field_id, 'size' => 40));
$table->add('title', html::label($field_id, $this->config->gettext('devicealias')));
$table->add(null, $input->show());
$field_id = 'config-device-mode';
$select = new html_select(array('name' => 'syncmode', 'id' => $field_id));
$select->add(array($this->config->gettext('modeauto'), $this->config->gettext('modeflat'), $this->config->gettext('modefolder')), array('-1', '0', '1'));
$table->add('title', html::label($field_id, $this->config->gettext('syncmode')));
$table->add(null, $select->show('-1'));
$field_id = 'config-device-laxpic';
$checkbox = new html_checkbox(array('name' => 'laxpic', 'value' => '1', 'id' => $field_id));
$table->add('title', $this->config->gettext('imageformat'));
$table->add(null, html::label($field_id, $checkbox->show() . ' ' . $this->config->gettext('laxpiclabel')));
if ($attrib['form'])
$this->rc->output->add_gui_object('editform', $attrib['form']);
return $table->show($attrib);
}
public function folder_subscriptions($attrib = array())
{
if (!$attrib['id'])
$attrib['id'] = 'foldersubscriptions';
// group folders by type (show only known types)
$folder_groups = array('mail' => array(), 'contact' => array(), 'event' => array(), 'task' => array());
$folder_meta = $this->config->folders_meta();
foreach ($this->config->list_folders() as $folder) {
$type = $folder_meta[$folder]['TYPE'] ? $folder_meta[$folder]['TYPE'] : 'mail';
if (is_array($folder_groups[$type]))
$folder_groups[$type][] = $folder;
}
// build block for every folder type
foreach ($folder_groups as $type => $group) {
if (empty($group))
continue;
$attrib['type'] = $type;
$html .= html::div('subscriptionblock',
html::tag('h3', $type, $this->config->gettext($type)) .
$this->folder_subscriptions_block($group, $attrib));
}
$this->rc->output->add_gui_object('subscriptionslist', $attrib['id']);
return html::div($attrib, $html);
}
public function folder_subscriptions_block($a_folders, $attrib)
{
$alarms = ($attrib['type'] == 'event' || $attrib['type'] == 'task');
$table = new html_table(array('cellspacing' => 0));
$table->add_header('subscription', $attrib['syncicon'] ? html::img(array('src' => $this->skin_path . $attrib['syncicon'], 'title' => $this->config->gettext('synchronize'))) : '');
$table->add_header('alarm', $alarms && $attrib['alarmicon'] ? html::img(array('src' => $this->skin_path . $attrib['alarmicon'], 'title' => $this->config->gettext('withalarms'))) : '');
$table->add_header('foldername', $this->config->gettext('folder'));
$checkbox_sync = new html_checkbox(array('name' => 'subscribed[]', 'class' => 'subscription'));
- $checkbox_alarm = new html_checkbox(array('name' => 'alarm[]', 'class' => 'alarm', 'disabled' => true));
+ $checkbox_alarm = new html_checkbox(array('name' => 'alarm[]', 'class' => 'alarm'));
$names = array();
foreach ($a_folders as $folder) {
$foldername = $origname = preg_replace('/^INBOX &raquo;\s+/', '', rcube_kolab::object_name($folder));
// find folder prefix to truncate (the same code as in kolab_addressbook plugin)
for ($i = count($names)-1; $i >= 0; $i--) {
if (strpos($foldername, $names[$i].' &raquo; ') === 0) {
$length = strlen($names[$i].' &raquo; ');
$prefix = substr($foldername, 0, $length);
$count = count(explode(' &raquo; ', $prefix));
$foldername = str_repeat('&nbsp;&nbsp;', $count-1) . '&raquo; ' . substr($foldername, $length);
break;
}
}
$names[] = $origname;
$classes = array('mailbox');
if ($folder_class = rcmail_folder_classname($folder)) {
$foldername = rcube_label($folder_class);
$classes[] = $folder_class;
}
$folder_id = 'rcmf' . html_identifier($folder);
$padding = str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $level);
$table->add_row(array('class' => (($level+1) * $idx++) % 2 == 0 ? 'even' : 'odd'));
$table->add('subscription', $checkbox_sync->show('', array('value' => $folder, 'id' => $folder_id)));
if ($alarms)
$table->add('alarm', $checkbox_alarm->show('', array('value' => $folder, 'id' => $folder_id.'_alarm')));
else
$table->add('alarm', '');
$table->add(join(' ', $classes), html::label($folder_id, $padding . Q($foldername)));
}
return $table->show();
}
- /**
- * Recursively compose folders table
- */
- private function render_folders($a_folders, $table, $level = 0)
- {
- $idx = 0;
- $checkbox_sync = new html_checkbox(array('name' => 'subscribed[]', 'class' => 'subscription'));
- $checkbox_alarm = new html_checkbox(array('name' => 'alarm[]', 'class' => 'alarm', 'disabled' => true));
- $folders_meta = $this->config->folders_meta();
-
- foreach ($a_folders as $key => $folder) {
- $classes = array('mailbox');
-
- if ($folder_class = rcmail_folder_classname($folder['id'])) {
- $foldername = rcube_label($folder_class);
- $classes[] = $folder_class;
- }
- else
- $foldername = $folder['name'];
-
- // visualize folder type
- if ($type = $folders_meta[$folder['id']]['TYPE'])
- $classes[] = $type;
-
- if ($folder['virtual'])
- $classes[] = 'virtual';
-
- $folder_id = 'rcmf' . html_identifier($folder['id']);
- $padding = str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $level);
-
- $table->add_row(array('class' => (($level+1) * $idx++) % 2 == 0 ? 'even' : 'odd'));
- $table->add(join(' ', $classes), html::label($folder_id, $padding . Q($foldername)));
- $table->add('subscription', $folder['virtual'] ? '' : $checkbox_sync->show('', array('value' => $folder['id'], 'id' => $folder_id)));
-
- if (($type == 'event' || $type == 'task') && !$folder['virtual'])
- $table->add('alarm', $checkbox_alarm->show('', array('value' => $folder['id'], 'id' => $folder_id.'_alarm')));
- else
- $table->add('alarm', '');
-
- if (!empty($folder['folders']))
- $this->render_folders($folder['folders'], $table, $level+1);
- }
-
- }
-
}

File Metadata

Mime Type
text/x-diff
Expires
Tue, Aug 18, 1:05 AM (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1258678
Default Alt Text
(16 KB)

Event Timeline