summaryrefslogtreecommitdiff
path: root/plugins/kolab_folders
diff options
context:
space:
mode:
authorAleksander Machniak (Kolab Systems) <machniak@kolabsys.com>2011-06-15 13:28:13 (GMT)
committerAleksander Machniak (Kolab Systems) <machniak@kolabsys.com>2011-06-15 13:28:13 (GMT)
commitea20b03cf326f674f97334ba5416eeff65ec0faf (patch)
tree5d454bcf9417e89b711ec47a9745e54bfb7aab57 /plugins/kolab_folders
parent431c1b4e1c001b3c23d2fc3e31a9012ffecea01d (diff)
downloadroundcubemail-plugins-kolab-ea20b03cf326f674f97334ba5416eeff65ec0faf.tar.gz
Add css classes to folders table rows. E.g. "type-default type-event"
Don't subscribe to non-mail folders on folder creation
Diffstat (limited to 'plugins/kolab_folders')
-rw-r--r--plugins/kolab_folders/README1
-rw-r--r--plugins/kolab_folders/kolab_folders.php80
2 files changed, 73 insertions, 8 deletions
diff --git a/plugins/kolab_folders/README b/plugins/kolab_folders/README
index 9edf913..ac4a56d 100644
--- a/plugins/kolab_folders/README
+++ b/plugins/kolab_folders/README
@@ -10,6 +10,7 @@ The plugin extends folders handling with features of the Kolab Suite.
With this plugin enabled it is possible to:
- set/get/change folder's type
- filter folders list by folder type.
+ - style folders list rows (in folder manager)
http://www.kolab.org/doc/kolabformat-2.0-html
diff --git a/plugins/kolab_folders/kolab_folders.php b/plugins/kolab_folders/kolab_folders.php
index c64daf1..7f0a333 100644
--- a/plugins/kolab_folders/kolab_folders.php
+++ b/plugins/kolab_folders/kolab_folders.php
@@ -3,7 +3,7 @@
/**
* Type-aware folder management/listing for Kolab
*
- * @version 0.2
+ * @version 0.3
* @author Aleksander Machniak <machniak@kolabsys.com>
*
*
@@ -46,6 +46,7 @@ class kolab_folders extends rcube_plugin
$this->add_hook('folder_form', array($this, 'folder_form'));
$this->add_hook('folder_update', array($this, 'folder_save'));
$this->add_hook('folder_create', array($this, 'folder_save'));
+ $this->add_hook('folders_list', array($this, 'folders_list'));
}
/**
@@ -117,6 +118,43 @@ class kolab_folders extends rcube_plugin
}
/**
+ * Handler for folders_list hook. Add css classes to folder rows.
+ */
+ function folders_list($args)
+ {
+ if (!$this->metadata_support()) {
+ return $args;
+ }
+
+ $table = $args['table'];
+
+ // get folders types
+ $folderdata = $this->get_folder_type_list('*');
+
+ if (!is_array($folderdata)) {
+ return $args;
+ }
+
+ // Add type-based style for table rows
+ // See kolab_folders::folder_class_name()
+ for ($i=0, $cnt=$table->size(); $i<$cnt; $i++) {
+ $attrib = $table->get_row_attribs($i);
+ $folder = $attrib['foldername']; // UTF7-IMAP
+ $data = $folderdata[$folder];
+
+ if (!empty($data)
+ && ($type = $data[kolab_folders::CTYPE_KEY])
+ && ($class_name = self::folder_class_name($type))
+ ) {
+ $attrib['class'] = trim($attrib['class'] . ' ' . $class_name);
+ $table->set_row_attribs($attrib, $i);
+ }
+ }
+
+ return $args;
+ }
+
+ /**
* Handler for folder info/edit form (folder_form hook).
* Adds folder type selector.
*/
@@ -177,10 +215,11 @@ class kolab_folders extends rcube_plugin
*/
function folder_save($args)
{
- $ctype = trim(get_input_value('_ctype', RCUBE_INPUT_POST));
- $subtype = trim(get_input_value('_subtype', RCUBE_INPUT_POST));
- $mbox = $args['record']['name'];
- $old_mbox = $args['record']['oldname'];
+ $ctype = trim(get_input_value('_ctype', RCUBE_INPUT_POST));
+ $subtype = trim(get_input_value('_subtype', RCUBE_INPUT_POST));
+ $mbox = $args['record']['name'];
+ $old_mbox = $args['record']['oldname'];
+ $subscribe = $args['record']['subscribe'];
if (empty($ctype)) {
return $args;
@@ -190,7 +229,7 @@ class kolab_folders extends rcube_plugin
if ($subtype == 'default') {
}
// Subtype sanity-checks
- else if ($subtype && $ctype != 'mail' || !in_array($subtype, $this->mail_types)) {
+ else if ($subtype && ($ctype != 'mail' || !in_array($subtype, $this->mail_types))) {
$subtype = '';
}
@@ -198,7 +237,11 @@ class kolab_folders extends rcube_plugin
// Create folder
if (!strlen($old_mbox)) {
- $result = $this->rc->imap->create_mailbox($mbox, true);
+ // By default don't subscribe to non-mail folders
+ if ($subscribe)
+ $subscribe = preg_match('/^mail/', $ctype);
+
+ $result = $this->rc->imap->create_mailbox($mbox, $subscribe);
// Set folder type
if ($result) {
$this->set_folder_type($mbox, $ctype);
@@ -223,6 +266,9 @@ class kolab_folders extends rcube_plugin
}
}
+ $args['record']['class'] = self::folder_class_name($ctype);
+ $args['record']['subscribe'] = $subscribe;
+
// Skip folder creation/rename in core
// @TODO: Maybe we should provide folder_create_after and folder_update_after hooks?
// Using create_mailbox/rename_mailbox here looks bad
@@ -340,5 +386,23 @@ class kolab_folders extends rcube_plugin
return $metadata;
}
-}
+ /**
+ * Returns CSS class name for specified folder type
+ *
+ * @param string $type Folder type
+ *
+ * @return string Class name
+ */
+ static function folder_class_name($type)
+ {
+ list($ctype, $subtype) = explode('.', $type);
+
+ $class[] = 'type-' . ($ctype ? $ctype : 'mail');
+
+ if ($subtype == 'default')
+ $class[] = 'type-default';
+
+ return implode(' ', $class);
+ }
+}