diff --git a/plugins/kolab_notes/kolab_notes.php b/plugins/kolab_notes/kolab_notes.php
index ef6cf03f..e715cecb 100644
--- a/plugins/kolab_notes/kolab_notes.php
+++ b/plugins/kolab_notes/kolab_notes.php
@@ -46,11 +46,6 @@ class kolab_notes extends rcube_plugin
$this->rc = rcube::get_instance();
- $this->register_task('notes');
-
- // load plugin configuration
- $this->load_config();
-
// proceed initialization in startup hook
$this->add_hook('startup', array($this, 'startup'));
}
@@ -65,6 +60,11 @@ class kolab_notes extends rcube_plugin
return;
}
+ $this->register_task('notes');
+
+ // load plugin configuration
+ $this->load_config();
+
// load localizations
$this->add_texts('localization/', $args['task'] == 'notes' && (!$args['action'] || $args['action'] == 'dialog-ui'));
$this->rc->load_language($_SESSION['language'], array('notes.notes' => $this->gettext('navtitle'))); // add label for task title
@@ -79,6 +79,7 @@ class kolab_notes extends rcube_plugin
$this->register_action('action', array($this, 'note_action'));
$this->register_action('list', array($this, 'list_action'));
$this->register_action('dialog-ui', array($this, 'dialog_view'));
+ $this->register_action('print', array($this, 'print_note'));
if (!$this->rc->output->ajax_call && in_array($args['action'], array('dialog-ui', 'list'))) {
$this->load_ui();
@@ -518,7 +519,7 @@ class kolab_notes extends rcube_plugin
// encode for client use
if (is_array($data)) {
- $this->_client_encode($data, true);
+ $this->_client_encode($data);
}
$this->rc->output->command('plugin.render_note', $data);
@@ -830,6 +831,52 @@ class kolab_notes extends rcube_plugin
return $status;
}
+ /**
+ * Render the template for printing with placeholders
+ */
+ public function print_note()
+ {
+ $uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_GET);
+ $list = rcube_utils::get_input_value('_list', rcube_utils::INPUT_GET);
+
+ $this->note = $this->get_note(array('uid' => $uid, 'list' => $list));
+
+ // encode for client use
+ if (is_array($this->note)) {
+ $this->_client_encode($this->note);
+ }
+
+ $this->rc->output->set_pagetitle($this->note['title']);
+ $this->rc->output->add_handlers(array(
+ 'noteheader' => array($this, 'print_note_header'),
+ 'notebody' => array($this, 'print_note_body'),
+ ));
+
+ $this->include_script('notes.js');
+
+ $this->rc->output->send('kolab_notes.print');
+ }
+
+ public function print_note_header()
+ {
+ $tags = array_map(array('rcube', 'Q'), (array) $this->note['tags']);
+ $tags = implode(' ', $tags);
+
+ return html::tag('h1', array('id' => 'notetitle'), rcube::Q($this->note['title']))
+ . html::div(array('id' => 'notetags', 'class' => 'tagline'), $tags)
+ . html::div('dates',
+ html::label(null, rcube::Q($this->gettext('created')))
+ . html::span(array('id' => 'notecreated'), rcube::Q($this->note['created']))
+ . html::label(null, rcube::Q($this->gettext('changed')))
+ . html::span(array('id' => 'notechanged'), rcube::Q($this->note['changed']))
+ );
+ }
+
+ public function print_note_body()
+ {
+ return isset($this->note['html']) ? $this->note['html'] : rcube::Q($this->note['description']);
+ }
+
/**
* Provide a list of revisions for the given object
*
@@ -1431,4 +1478,3 @@ class kolab_notes extends rcube_plugin
}
}
-
diff --git a/plugins/kolab_notes/kolab_notes_ui.php b/plugins/kolab_notes/kolab_notes_ui.php
index 41ce8118..940ebcd7 100644
--- a/plugins/kolab_notes/kolab_notes_ui.php
+++ b/plugins/kolab_notes/kolab_notes_ui.php
@@ -32,8 +32,6 @@ class kolab_notes_ui
$this->plugin->include_stylesheet($this->plugin->local_skin_path() . '/notes.css');
- $this->plugin->register_action('print', array($this, 'print_template'));
-
$this->ready = true;
}
@@ -68,7 +66,6 @@ class kolab_notes_ui
// load config options and user prefs relevant for the UI
$settings = array(
'sort_col' => $this->rc->config->get('kolab_notes_sort_col', 'changed'),
- 'print_template' => $this->rc->url('print'),
);
if ($list = rcube_utils::get_input_value('_list', rcube_utils::INPUT_GPC)) {
@@ -419,15 +416,4 @@ class kolab_notes_ui
return $acl['form']['sharing']['content'] ?: html::div('hint', $this->plugin->gettext('aclnorights'));
}
-
- /**
- * Render the template for printing with placeholders
- */
- public function print_template()
- {
- header('Content-Type: text/html; charset=' . RCUBE_CHARSET);
- $this->rc->output->reset(true);
- echo $this->rc->output->parse('kolab_notes.print', false, false);
- exit;
- }
}
diff --git a/plugins/kolab_notes/notes.js b/plugins/kolab_notes/notes.js
index 31821845..fc700f6f 100644
--- a/plugins/kolab_notes/notes.js
+++ b/plugins/kolab_notes/notes.js
@@ -455,7 +455,6 @@ function rcube_kolab_notes_ui(settings)
changed: rcmail.gettext('now', 'kolab_notes')
}
render_note(me.selected_note);
- rcmail.enable_command('print', true);
}
else {
ui_loading = rcmail.set_busy(true, 'loading');
@@ -1135,28 +1134,11 @@ function rcube_kolab_notes_ui(settings)
*/
function print_note()
{
- var printwin, data, list;
- if (me.selected_note && (printwin = rcmail.open_window(settings.print_template))) {
- list = me.notebooks[me.selected_note.list] || me.notebooks[me.selected_list] || {};
- data = get_save_data();
+ var list = me.notebooks[me.selected_list],
+ uid = me.selected_note ? me.selected_note.uid : 0;
- // for read-only notes, get_save_data() won't return the content
- if (me.selected_note.readonly || !list.editable) {
- data.description = me.selected_note.html || me.selected_note.description;
- if (!me.selected_note.html || !data.description.match(/<(html|body)/)) {
- data.description = text2html(data.description);
- }
- }
-
- $(printwin).on('load', function() {
- printwin.document.title = data.title;
- $('#notetitle', printwin.document).text(data.title);
- $('#notebody', printwin.document).html(data.description);
- $('#notetags', printwin.document).html('' + data.tags.join('') + '');
- $('#notecreated', printwin.document).text(me.selected_note.created);
- $('#notechanged', printwin.document).text(me.selected_note.changed);
- printwin.print();
- });
+ if (list && uid) {
+ rcmail.open_window(rcmail.url('print', {_uid: uid, _list: list.id}), true, true);
}
}
@@ -1691,6 +1673,11 @@ function kolab_notes_options_menu()
/* Notes plugin UI initialization */
var kolabnotes;
window.rcmail && rcmail.addEventListener('init', function(evt) {
+ if (rcmail.task == 'notes' && rcmail.env.action == 'print') {
+ rcmail.print_dialog();
+ return;
+ }
+
kolabnotes = new rcube_kolab_notes_ui(rcmail.env.kolab_notes_settings);
if (rcmail.env.action == 'dialog-ui')
diff --git a/plugins/kolab_notes/skins/elastic/templates/print.html b/plugins/kolab_notes/skins/elastic/templates/print.html
index 86ed5cdf..fddf9c35 100644
--- a/plugins/kolab_notes/skins/elastic/templates/print.html
+++ b/plugins/kolab_notes/skins/elastic/templates/print.html
@@ -1,17 +1,8 @@