summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/enigma/enigma.js99
-rw-r--r--plugins/enigma/lib/enigma_ui.php134
2 files changed, 167 insertions, 66 deletions
diff --git a/plugins/enigma/enigma.js b/plugins/enigma/enigma.js
index 609e78114..2cd2d62e3 100644
--- a/plugins/enigma/enigma.js
+++ b/plugins/enigma/enigma.js
@@ -17,12 +17,18 @@ if (window.rcmail)
rcmail.keys_list.addEventListener('select', function(o){ p.enigma_key_select(o); });
rcmail.keys_list.init();
rcmail.keys_list.focus();
+
+ rcmail.enigma_list();
+
+ rcmail.register_command('firstpage', function(props) {return rcmail.enigma_list_page('first'); });
+ rcmail.register_command('previouspage', function(props) {return rcmail.enigma_list_page('previous'); });
+ rcmail.register_command('nextpage', function(props) {return rcmail.enigma_list_page('next'); });
+ rcmail.register_command('lastpage', function(props) {return rcmail.enigma_list_page('last'); });
}
if (rcmail.env.action == 'edit-prefs') {
- rcmail.enable_command('search', 'reset-search', true);
- rcmail.addEventListener('beforesearch', 'enigma_search', rcmail);
- rcmail.addEventListener('beforereset-search', 'enigma_search_reset', rcmail);
+ rcmail.register_command('search', function(props) {return rcmail.enigma_search(props); }, true);
+ rcmail.register_command('reset-search', function(props) {return rcmail.enigma_search_reset(props); }, true);
}
else if (rcmail.env.action == 'plugin.enigma') {
rcmail.register_command('plugin.enigma-import', function() { rcmail.enigma_import() }, true);
@@ -33,7 +39,7 @@ if (window.rcmail)
}
/*********************************************************/
-/********* Enigma Settings methods *********/
+/********* Enigma Settings/Keys/Certs UI *********/
/*********************************************************/
// Display key(s) import form
@@ -83,28 +89,28 @@ rcube_webmail.prototype.enigma_loadframe = function(id, url)
}
};
+// Search keys/certs
rcube_webmail.prototype.enigma_search = function(props)
{
if (!props && this.gui_objects.qsearchbox)
props = this.gui_objects.qsearchbox.value;
- if (props) {
+ if (props || this.env.search_request) {
+ var params = {'_a': 'keysearch', '_q': urlencode(props)};
// if (this.gui_objects.search_filter)
// addurl += '&_filter=' + this.gui_objects.search_filter.value;
this.env.current_page = 1;
this.set_busy(true, 'searching');
- this.enigma_loadframe();
- // reload page (for keys list refresh)
- this.http_post('plugin.enigma',
- {'_a': 'keysearch', '_q': urlencode(props)},
- true);
+ this.enigma_loadframe();
+ this.enigma_clear_list();
+ this.http_post('plugin.enigma', params, true);
}
- // skip default 'search' command action
return false;
}
+// Reset search filter and the list
rcube_webmail.prototype.enigma_search_reset = function(props)
{
var s = this.env.search_request;
@@ -112,13 +118,79 @@ rcube_webmail.prototype.enigma_search_reset = function(props)
if (s) {
this.enigma_loadframe();
- // reload page (for keys list refresh)
+ this.enigma_clear_list();
+
+ // refresh the list
+ this.enigma_list();
}
- // skip default 'reset-search' command action
return false;
}
+// Keys/certs listing
+rcube_webmail.prototype.enigma_list = function(page)
+{
+ var params = {'_a': 'keylist'};
+
+ this.env.current_page = page ? page : 1;
+ this.set_busy(true, 'loading');
+
+ if (this.env.search_request)
+ params._q = this.env.search_request;
+ if (page)
+ params._p = page;
+
+ this.enigma_clear_list();
+ this.http_post('plugin.enigma', params, true);
+}
+
+// Change list page
+rcube_webmail.prototype.enigma_list_page = function(page)
+{
+ if (page == 'next')
+ page = this.env.current_page + 1;
+ else if (page == 'last')
+ page = this.env.pagecount;
+ else if (page == 'prev' && this.env.current_page > 1)
+ page = this.env.current_page - 1;
+ else if (page == 'first' && this.env.current_page > 1)
+ page = 1;
+
+ this.enigma_list(page);
+}
+
+// Remove list rows
+rcube_webmail.prototype.enigma_clear_list = function()
+{
+ this.enigma_loadframe();
+ if (this.keys_list)
+ this.keys_list.clear(true);
+}
+
+// Adds a row to the list
+rcube_webmail.prototype.enigma_add_list_row = function(r)
+{
+ if (!this.gui_objects.keyslist || !this.keys_list)
+ return false;
+
+ var list = this.keys_list,
+ tbody = this.gui_objects.keyslist.tBodies[0],
+ rowcount = tbody.rows.length,
+ even = rowcount%2,
+ css_class = 'message'
+ + (even ? ' even' : ' odd'),
+ // for performance use DOM instead of jQuery here
+ row = document.createElement('tr'),
+ col = document.createElement('td');
+
+ row.id = 'rcmrow' + r.id;
+ row.className = css_class;
+
+ col.innerHTML = r.name;
+ row.appendChild(col);
+ list.insert_row(row);
+}
+
/*********************************************************/
/********* Enigma Message methods *********/
/*********************************************************/
@@ -132,3 +204,4 @@ rcube_webmail.prototype.enigma_import_attachment = function(mime_id)
return false;
};
+
diff --git a/plugins/enigma/lib/enigma_ui.php b/plugins/enigma/lib/enigma_ui.php
index 0e9c7be9d..a8af09362 100644
--- a/plugins/enigma/lib/enigma_ui.php
+++ b/plugins/enigma/lib/enigma_ui.php
@@ -27,7 +27,6 @@ class enigma_ui
private $enigma;
private $home;
private $css_added;
- private $listsize;
private $data;
@@ -50,7 +49,7 @@ class enigma_ui
// Enigma actions
if ($this->rc->action == 'plugin.enigma') {
- $action = get_input_value('_a', RCUBE_INPUT_GET);
+ $action = get_input_value('_a', RCUBE_INPUT_GPC);
switch ($action) {
case 'keyedit':
@@ -60,8 +59,10 @@ class enigma_ui
$this->key_import();
break;
case 'keysearch':
- $this->key_search();
+ case 'keylist':
+ $this->key_list();
break;
+ case 'keyinfo':
default:
$this->key_info();
}
@@ -70,9 +71,9 @@ class enigma_ui
else { // if ($this->rc->action == 'edit-prefs') {
if ($section == 'enigmacerts') {
$this->rc->output->add_handlers(array(
- 'keyslist' => array($this, 'certs_list'),
- 'keyframe' => array($this, 'cert_frame'),
- 'countdisplay' => array($this, 'certs_rowcount'),
+ 'keyslist' => array($this, 'tpl_certs_list'),
+ 'keyframe' => array($this, 'tpl_cert_frame'),
+ 'countdisplay' => array($this, 'tpl_certs_rowcount'),
'searchform' => array($this->rc->output, 'search_form'),
));
$this->rc->output->set_pagetitle($this->enigma->gettext('enigmacerts'));
@@ -80,9 +81,9 @@ class enigma_ui
}
else {
$this->rc->output->add_handlers(array(
- 'keyslist' => array($this, 'keys_list'),
- 'keyframe' => array($this, 'key_frame'),
- 'countdisplay' => array($this, 'keys_rowcount'),
+ 'keyslist' => array($this, 'tpl_keys_list'),
+ 'keyframe' => array($this, 'tpl_key_frame'),
+ 'countdisplay' => array($this, 'tpl_keys_rowcount'),
'searchform' => array($this->rc->output, 'search_form'),
));
$this->rc->output->set_pagetitle($this->enigma->gettext('enigmakeys'));
@@ -114,12 +115,12 @@ class enigma_ui
*
* @return string HTML output
*/
- function key_frame($attrib)
+ function tpl_key_frame($attrib)
{
if (!$attrib['id']) {
$attrib['id'] = 'rcmkeysframe';
}
-
+
$attrib['name'] = $attrib['id'];
$this->rc->output->set_env('contentframe', $attrib['name']);
@@ -136,10 +137,8 @@ class enigma_ui
*
* @return string HTML content
*/
- function keys_list($attrib)
+ function tpl_keys_list($attrib)
{
- $this->enigma->load_engine();
-
// add id to message list table if not specified
if (!strlen($attrib['id'])) {
$attrib['id'] = 'rcmenigmakeyslist';
@@ -147,41 +146,71 @@ class enigma_ui
// define list of cols to be displayed
$a_show_cols = array('name');
- $result = array();
-
- // Get the list
- $list = $this->enigma->engine->list_keys();
-
- if (is_array($list)) {
- // Sort the list by key (user) name
- usort($list, array('enigma_key', 'cmp'));
-
- foreach($list as $idx => $key) {
- $result[] = array('name' => $key->name, 'id' => $key->id);
- unset($list[$idx]);
- }
- }
// create XHTML table
- $out = rcube_table_output($attrib, $result, $a_show_cols, 'id');
-
- if ($list && ($list instanceof enigma_error))
- $this->rc->output->show_message('enigma.keylisterror', 'error');
- else if (empty($result))
- $this->rc->output->show_message('enigma.nokeysfound', 'notice');
- else
- $this->listsize = count($result);
+ $out = rcube_table_output($attrib, array(), $a_show_cols, 'id');
// set client env
$this->rc->output->add_gui_object('keyslist', $attrib['id']);
$this->rc->output->include_script('list.js');
-
+
// add some labels to client
$this->rc->output->add_label('enigma.keyconfirmdelete');
-
+
return $out;
}
+ /**
+ * Key listing (and searching) request handler
+ */
+ private function key_list()
+ {
+ $this->enigma->load_engine();
+
+ $pagesize = $this->rc->config->get('pagesize', 100);
+ $page = max(intval(get_input_value('_p', RCUBE_INPUT_GPC)), 1);
+ $search = get_input_value('_q', RCUBE_INPUT_GPC);
+
+ // define list of cols to be displayed
+ $a_show_cols = array('name');
+ $result = array();
+
+ // Get the list
+ $list = $this->enigma->engine->list_keys($search);
+
+ if ($list && ($list instanceof enigma_error))
+ $this->rc->output->show_message('enigma.keylisterror', 'error');
+ else if (empty($list))
+ $this->rc->output->show_message('enigma.nokeysfound', 'notice');
+ else {
+ if (is_array($list)) {
+ // Save the size
+ $listsize = count($list);
+
+ // Sort the list by key (user) name
+ usort($list, array('enigma_key', 'cmp'));
+
+ // Slice current page
+ $list = array_slice($list, ($page - 1) * $pagesize, $pagesize);
+
+ $size = count($list);
+
+ // Add rows
+ foreach($list as $idx => $key) {
+ $this->rc->output->command('enigma_add_list_row',
+ array('name' => Q($key->name), 'id' => $key->id));
+ }
+ }
+ }
+
+ $this->rc->output->set_env('search_request', $search);
+ $this->rc->output->set_env('pagecount', ceil($listsize/$pagesize));
+ $this->rc->output->set_env('current_page', $page);
+ $this->rc->output->command('set_rowcount',
+ $this->get_rowcount_text($listsize, $size, $page));
+
+ $this->rc->output->send();
+ }
/**
* Template object for list records counter.
@@ -190,7 +219,7 @@ class enigma_ui
*
* @return string HTML output
*/
- function keys_rowcount($attrib)
+ function tpl_keys_rowcount($attrib)
{
if (!$attrib['id'])
$attrib['id'] = 'rcmcountdisplay';
@@ -203,22 +232,21 @@ class enigma_ui
/**
* Returns text representation of list records counter
*/
- private function get_rowcount_text()
+ private function get_rowcount_text($all, $curr_count, $page)
{
- $page_size = $this->rc->config->get('pagesize', 100);
- $count = $this->listsize;
- $first = 0;
+ $pagesize = $this->rc->config->get('pagesize', 100);
+ $first = ($page - 1) * $pagesize;
- if (!$count)
+ if (!$curr_count)
$out = $this->enigma->gettext('nokeysfound');
else
$out = $this->enigma->gettext(array(
'name' => 'keysfromto',
'vars' => array(
'from' => $first + 1,
- 'to' => min($count, $page_size),
- 'count' => $count)
- ));
+ 'to' => $first + $curr_count,
+ 'count' => $all)
+ ));
return $out;
}
@@ -242,8 +270,8 @@ class enigma_ui
}
$this->rc->output->add_handlers(array(
- 'keyname' => array($this, 'key_name'),
- 'keydata' => array($this, 'key_data'),
+ 'keyname' => array($this, 'tpl_key_name'),
+ 'keydata' => array($this, 'tpl_key_data'),
));
$this->rc->output->set_pagetitle($this->enigma->gettext('keyinfo'));
@@ -253,7 +281,7 @@ class enigma_ui
/**
* Template object for key name
*/
- function key_name($attrib)
+ function tpl_key_name($attrib)
{
return Q($this->data->name);
}
@@ -261,7 +289,7 @@ class enigma_ui
/**
* Template object for key information page content
*/
- function key_data($attrib)
+ function tpl_key_data($attrib)
{
$out = '';
$table = new html_table(array('cols' => 2));
@@ -340,7 +368,7 @@ class enigma_ui
}
$this->rc->output->add_handlers(array(
- 'importform' => array($this, 'key_import_form'),
+ 'importform' => array($this, 'tpl_key_import_form'),
));
$this->rc->output->set_pagetitle($this->enigma->gettext('keyimport'));
@@ -350,7 +378,7 @@ class enigma_ui
/**
* Template object for key import (upload) form
*/
- function key_import_form($attrib)
+ function tpl_key_import_form($attrib)
{
$attrib += array('id' => 'rcmKeyImportForm');