From 0b1de8a487034724e8acbdccf8a7b506d1ecaeed Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Thu, 25 Jul 2013 17:39:35 +0200 Subject: Add new feature to save and recall text snippets (aka canned responses) when composing messages --- skins/larry/templates/compose.html | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'skins/larry/templates') diff --git a/skins/larry/templates/compose.html b/skins/larry/templates/compose.html index 806939a42..0e4568bdd 100644 --- a/skins/larry/templates/compose.html +++ b/skins/larry/templates/compose.html @@ -30,6 +30,7 @@ + @@ -194,6 +195,16 @@
+
+
    +
  • + +
  • +
  • +
  • +
+
+ -- cgit v1.2.3 From 0ce2126ac91f634b0bc5bf7f3567acd2f87f9972 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Thu, 29 Aug 2013 17:29:18 +0200 Subject: New settings section to manage canned responses --- program/include/rcmail.php | 25 +++++++ program/js/app.js | 84 +++++++++++++++++++++++- program/localization/en_US/labels.inc | 1 + program/localization/en_US/messages.inc | 1 + program/steps/mail/compose.inc | 15 ++--- program/steps/settings/edit_response.inc | 108 +++++++++++++++++++++++++++++++ program/steps/settings/func.inc | 3 + program/steps/settings/responses.inc | 81 +++++++++++++++++++++-- skins/larry/includes/settingstabs.html | 1 + skins/larry/templates/responseedit.html | 22 +++++++ skins/larry/templates/responses.html | 41 ++++++++++++ 11 files changed, 364 insertions(+), 18 deletions(-) create mode 100644 program/steps/settings/edit_response.inc create mode 100644 skins/larry/templates/responseedit.html create mode 100644 skins/larry/templates/responses.html (limited to 'skins/larry/templates') diff --git a/program/include/rcmail.php b/program/include/rcmail.php index 02287d312..9713cdb4e 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -346,6 +346,31 @@ class rcmail extends rcube return $list; } + /** + * Getter for compose responses. + * These are stored in local config and user preferences. + * + * @param boolean True to sort the list alphabetically + * @return array List of the current user's stored responses + */ + public function get_compose_responses($sorted = false) + { + foreach ($this->config->get('compose_responses', array()) as $response) { + if (empty($response['key'])) + $response['key'] = substr(md5($response['name']), 0, 16); + $k = $sorted ? strtolower($response['name']) : $response['key']; + $responses[$k] = $response; + } + + if ($sorted) { + // sort list by name + ksort($responses, SORT_LOCALE_STRING); + return array_values($responses); + } + + return $responses; + } + /** * Init output object for GUI and add common scripts. diff --git a/program/js/app.js b/program/js/app.js index a7a92175d..cef688204 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -399,7 +399,7 @@ function rcube_webmail() break; case 'settings': - this.enable_command('preferences', 'identities', 'save', 'folders', true); + this.enable_command('preferences', 'identities', 'responses', 'save', 'folders', true); if (this.env.action == 'identities') { this.enable_command('add', this.env.identities_level < 2); @@ -420,6 +420,9 @@ function rcube_webmail() parent.rcmail.enable_command('purge', this.env.messagecount); $("input[type='text']").first().select(); } + else if (this.env.action == 'responses') { + this.enable_command('add', true); + } if (this.gui_objects.identitieslist) { this.identity_list = new rcube_list_widget(this.gui_objects.identitieslist, {multiselect:false, draggable:false, keyboard:false}); @@ -436,8 +439,22 @@ function rcube_webmail() this.sections_list.init(); this.sections_list.focus(); } - else if (this.gui_objects.subscriptionlist) + else if (this.gui_objects.subscriptionlist) { this.init_subscription_list(); + } + else if (this.gui_objects.responseslist) { + this.responses_list = new rcube_list_widget(this.gui_objects.responseslist, {multiselect:false, draggable:false, keyboard:false}); + this.responses_list.addEventListener('select', function(list){ + var win, id = list.get_single_selection(); + p.enable_command('delete', !!id); + if (id && (win = p.get_frame_window(p.env.contentframe))) { + p.set_busy(true); + p.location_href({ _action:'edit-response', _key:id, _framed:1 }, win); + } + }); + this.responses_list.init(); + this.responses_list.focus(); + } break; @@ -743,6 +760,13 @@ function rcube_webmail() case 'add': if (this.task == 'addressbook') this.load_contact(0, 'add'); + else if (this.task == 'settings' && this.env.action == 'responses') { + var frame; + if ((frame = this.get_frame_window(this.env.contentframe))) { + this.set_busy(true); + this.location_href({ _action:'add-response', _framed:1 }, frame); + } + } else if (this.task == 'settings') { this.identity_list.clear_selection(); this.load_identity(0, 'add-identity'); @@ -806,7 +830,10 @@ function rcube_webmail() // addressbook task else if (this.task == 'addressbook') this.delete_contacts(); - // user settings task + // settings: canned response + else if (this.task == 'settings' && this.env.action == 'responses') + this.delete_response(); + // settings: user identities else if (this.task == 'settings') this.delete_identity(); break; @@ -1191,6 +1218,7 @@ function rcube_webmail() // user settings commands case 'preferences': case 'identities': + case 'responses': case 'folders': this.goto_url('settings/' + command); break; @@ -3428,6 +3456,27 @@ function rcube_webmail() } }; + this.edit_responses = function() + { + // TODO: decide what to do here... + }; + + this.delete_response = function(key) + { + if (!key && this.responses_list) { + var selection = this.responses_list.get_selection(); + key = selection[0]; + } + + // submit delete request + if (key && confirm(this.get_label('deleteresponseconfirm'))) { + this.http_post('settings/delete-response', { _key: key }, false); + return true; + } + + return false; + }; + this.stop_spellchecking = function() { var ed; @@ -5343,6 +5392,35 @@ function rcube_webmail() } }; + this.update_response_row = function(response, oldkey) + { + var list = this.responses_list; + + if (list && oldkey) { + list.update_row(oldkey, [ response.name ], response.key, true); + } + else if (list) { + list.insert_row({ id:'rcmrow'+response.key, cols:[ { className:'name', innerHTML:response.name } ] }); + list.select(response.key); + } + }; + + this.remove_response = function(key) + { + var frame; + + if (this.env.textresponses) { + delete this.env.textresponses[key]; + } + + if (this.responses_list) { + this.responses_list.remove_row(key); + if (this.env.contentframe && (frame = this.get_frame_window(this.env.contentframe))) { + frame.location.href = this.env.blankpage; + } + } + }; + /*********************************************************/ /********* folder manager methods *********/ diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc index 8cda30990..1f0697ccb 100644 --- a/program/localization/en_US/labels.inc +++ b/program/localization/en_US/labels.inc @@ -237,6 +237,7 @@ $labels['insertresponse'] = 'Insert a response'; $labels['manageresponses'] = 'Manage responses'; $labels['savenewresponse'] = 'Save new response'; $labels['editresponses'] = 'Edit responses'; +$labels['editresponse'] = 'Edit response'; $labels['responsename'] = 'Name'; $labels['responsetext'] = 'Response Text'; diff --git a/program/localization/en_US/messages.inc b/program/localization/en_US/messages.inc index e9feb243d..c2a7b6e29 100644 --- a/program/localization/en_US/messages.inc +++ b/program/localization/en_US/messages.inc @@ -47,6 +47,7 @@ $messages['savingmessage'] = 'Saving message...'; $messages['messagesaved'] = 'Message saved to Drafts.'; $messages['successfullysaved'] = 'Successfully saved.'; $messages['savingresponse'] = 'Saving response text...'; +$messages['deleteresponseconfirm'] = 'Do you really want to delete this response text?'; $messages['addedsuccessfully'] = 'Contact added successfully to address book.'; $messages['contactexists'] = 'A contact with the same e-mail address already exists.'; $messages['contactnameexists'] = 'A contact with the same name already exists.'; diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc index efc0cc8e0..282a2fd3e 100644 --- a/program/steps/mail/compose.inc +++ b/program/steps/mail/compose.inc @@ -1707,23 +1707,16 @@ function rcmail_compose_responses_list($attrib) $attrib += array('id' => 'rcmresponseslist', 'tagname' => 'ul', 'cols' => 1); $jsenv = array(); - $items = array(); - foreach ($RCMAIL->config->get('compose_responses', array()) as $response) { - $key = $response['key'] ? $response['key'] : substr(md5($response['name']), 0, 16); - $items[strtolower($response['name'])] = html::a(array( + $list = new html_table($attrib); + foreach ($RCMAIL->get_compose_responses(true) as $response) { + $key = $response['key']; + $item = html::a(array( 'href '=> '#'.urlencode($response['name']), 'class' => rtrim('insertresponse ' . $attrib['itemclass']), 'rel' => $key, ), Q($response['name'])); $jsenv[$key] = $response; - } - - // sort list by name - ksort($items, SORT_LOCALE_STRING); - - $list = new html_table($attrib); - foreach ($items as $item) { $list->add(array(), $item); } diff --git a/program/steps/settings/edit_response.inc b/program/steps/settings/edit_response.inc new file mode 100644 index 000000000..26f7e6e48 --- /dev/null +++ b/program/steps/settings/edit_response.inc @@ -0,0 +1,108 @@ + | + +-----------------------------------------------------------------------+ +*/ + +$responses = $RCMAIL->get_compose_responses(); + +// edit-response +if (($key = get_input_value('_key', RCUBE_INPUT_GPC))) { + foreach ($responses as $i => $response) { + if (empty($response['key'])) + $response['key'] = substr(md5($response['name']), 0, 16); + if ($response['key'] == $key) { + $RESPONSE_RECORD = $response; + $RESPONSE_RECORD['index'] = $i; + break; + } + } +} + +// save response +if ($RCMAIL->action == 'save-response' && isset($_POST['_name'])) { + $name = trim(get_input_value('_name', RCUBE_INPUT_POST)); + $text = trim(get_input_value('_text', RCUBE_INPUT_POST)); + + if (!empty($_REQUEST['_framed'])) + $RCMAIL->output->framed = 1; + + if (!empty($name) && !empty($text)) { + $dupes = 0; + foreach ($responses as $i => $resp) { + if ($RESPONSE_RECORD && $RESPONSE_RECORD['index'] === $i) + continue; + if (strcasecmp($name, preg_replace('/\s\(\d+\)$/', '', $resp['name'])) == 0) + $dupes++; + } + if ($dupes) { // require a unique name + $name .= ' (' . ++$dupes . ')'; + } + + $response = array('name' => $name, 'text' => $text, 'format' => 'text', 'key' => substr(md5($name), 0, 16)); + if ($RESPONSE_RECORD && $responses[$RESPONSE_RECORD['index']]) { + $responses[$RESPONSE_RECORD['index']] = $response; + } + else { + $responses[] = $response; + } + + if ($RCMAIL->user->save_prefs(array('compose_responses' => $responses))) { + $RCMAIL->output->show_message('successfullysaved', 'confirmation'); + $RCMAIL->output->command('update_response_row', $response, $key); + $RESPONSE_RECORD = $response; + } + } + else { + $RCMAIL->output->show_message('formincomplete', 'error'); + } +} + + +function rcube_response_form($attrib) +{ + global $RCMAIL, $OUTPUT, $RESPONSE_RECORD; + + // Set form tags and hidden fields + $key = $RESPONSE_RECORD['key']; + list($form_start, $form_end) = get_form_tags($attrib, 'save-response', $key, array('name' => '_key', 'value' => $key)); + unset($attrib['form'], $attrib['id']); + + // return the complete edit form as table + $out = "$form_start\n"; + + $table = new html_table(array('cols' => 2)); + $label = rcube_label('responsename'); + + $table->add('title', html::label('ffname', Q(rcube_label('responsename')))); + $table->add(null, rcube_output::get_edit_field('name', $RESPONSE_RECORD['name'], array('id' => 'ffname', 'size' => $attrib['size']), 'text')); + + $table->add('title', html::label('fftext', Q(rcube_label('responsetext')))); + $table->add(null, rcube_output::get_edit_field('text', $RESPONSE_RECORD['text'], array('id' => 'fftext', 'size' => $attrib['textareacols'], 'rows' => $attrib['textarearows']), 'textarea')); + + $out .= $table->show($attrib); + $out .= $form_end; + + return $out; +} + +$OUTPUT->add_handler('responseform', 'rcube_response_form'); +$OUTPUT->set_pagetitle(rcube_label(($RCMAIL->action=='add-response' ? 'savenewresponse' : 'editresponse'))); + +$OUTPUT->send('responseedit'); + diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc index fdc07be9e..39a925e0e 100644 --- a/program/steps/settings/func.inc +++ b/program/steps/settings/func.inc @@ -1253,4 +1253,7 @@ $RCMAIL->register_action_map(array( 'purge' => 'folders.inc', 'folder-size' => 'folders.inc', 'add-identity' => 'edit_identity.inc', + 'add-response' => 'edit_response.inc', + 'save-response' => 'edit_response.inc', + 'delete-response' => 'responses.inc', )); diff --git a/program/steps/settings/responses.inc b/program/steps/settings/responses.inc index 5a7db5687..330b4fde4 100644 --- a/program/steps/settings/responses.inc +++ b/program/steps/settings/responses.inc @@ -21,12 +21,12 @@ if (!empty($_POST['_insert'])) { - $name = get_input_value('_name', RCUBE_INPUT_POST); + $name = trim(get_input_value('_name', RCUBE_INPUT_POST)); $text = trim(get_input_value('_text', RCUBE_INPUT_POST)); if (!empty($name) && !empty($text)) { $dupes = 0; - $responses = $RCMAIL->config->get('compose_responses', array()); + $responses = $RCMAIL->get_compose_responses(); foreach ($responses as $resp) { if (strcasecmp($name, preg_replace('/\s\(\d+\)$/', '', $resp['name'])) == 0) $dupes++; @@ -46,8 +46,81 @@ if (!empty($_POST['_insert'])) { $RCMAIL->output->command('display_message', rcube_label('errorsaving'), 'error'); } } + + // send response + $RCMAIL->output->send(); +} + + +if ($RCMAIL->action == 'delete-response') { + if ($key = get_input_value('_key', RCUBE_INPUT_GPC)) { + $responses = $RCMAIL->get_compose_responses(); + foreach ($responses as $i => $response) { + if (empty($response['key'])) + $response['key'] = substr(md5($response['name']), 0, 16); + if ($response['key'] == $key) { + unset($responses[$i]); + $deleted = $RCMAIL->user->save_prefs(array('compose_responses' => $responses)); + break; + } + } + } + + if ($deleted) { + $RCMAIL->output->command('display_message', rcube_label('successfullydeleted'), 'confirmation'); + $RCMAIL->output->command('remove_response', $key); + } + + if ($RCMAIL->output->ajax_call) { + $RCMAIL->output->send(); + } +} + + +$OUTPUT->set_pagetitle(rcube_label('responses')); +$OUTPUT->include_script('list.js'); + + +/** + * + */ +function rcmail_responses_list($attrib) +{ + global $RCMAIL, $OUTPUT; + + $attrib += array('id' => 'rcmresponseslist', 'tagname' => 'table', 'cols' => 1); + + $plugin = $RCMAIL->plugins->exec_hook('responses_list', array( + 'list' => $RCMAIL->get_compose_responses(true), + 'cols' => array('name') + )); + + $out = rcube_table_output($attrib, $plugin['list'], $plugin['cols'], 'key'); + + // set client env + $OUTPUT->add_gui_object('responseslist', $attrib['id']); + + return $out; +} + + +// similar function as /steps/addressbook/func.inc::rcmail_contact_frame() +function rcmail_response_frame($attrib) +{ + global $OUTPUT; + + if (!$attrib['id']) { + $attrib['id'] = 'rcmResponseFrame'; + } + + $OUTPUT->set_env('contentframe', $attrib['id']); + return $OUTPUT->frame($attrib, true); } -// send response -$RCMAIL->output->send(); +$OUTPUT->add_handlers(array( + 'responseframe' => 'rcmail_response_frame', + 'responseslist' => 'rcmail_responses_list', +)); +$OUTPUT->add_label('deleteresponseconfirm'); +$OUTPUT->send('responses'); diff --git a/skins/larry/includes/settingstabs.html b/skins/larry/includes/settingstabs.html index bb26fc6a6..14d875696 100644 --- a/skins/larry/includes/settingstabs.html +++ b/skins/larry/includes/settingstabs.html @@ -4,6 +4,7 @@ + diff --git a/skins/larry/templates/responseedit.html b/skins/larry/templates/responseedit.html new file mode 100644 index 000000000..d2f031b34 --- /dev/null +++ b/skins/larry/templates/responseedit.html @@ -0,0 +1,22 @@ + + + +<roundcube:object name="pagetitle" /> + + + + +

+ +
+ +
+ +
+ +
+ + + + + diff --git a/skins/larry/templates/responses.html b/skins/larry/templates/responses.html new file mode 100644 index 000000000..fb40048c8 --- /dev/null +++ b/skins/larry/templates/responses.html @@ -0,0 +1,41 @@ + + + +<roundcube:object name="pagetitle" /> + + + + + + +
+ + + +
+ +
+

+
+ +
+
+ +
+
+ +
+
+ +
+ +
+ +
+ +
+ + + + + -- cgit v1.2.3 From 0933d66b591056358b5e645cbd563814308998d2 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Wed, 4 Sep 2013 10:08:42 +0200 Subject: Keep current selection on IE browsers by adding unselectable=on to link elements --- program/include/rcmail_output_html.php | 2 +- program/js/app.js | 7 ++++--- program/lib/Roundcube/html.php | 4 ++-- program/steps/mail/compose.inc | 1 + skins/larry/images/buttons.png | Bin 38670 -> 53350 bytes skins/larry/templates/compose.html | 6 +++--- 6 files changed, 11 insertions(+), 9 deletions(-) (limited to 'skins/larry/templates') diff --git a/program/include/rcmail_output_html.php b/program/include/rcmail_output_html.php index a2ec29ca3..006b89c64 100644 --- a/program/include/rcmail_output_html.php +++ b/program/include/rcmail_output_html.php @@ -1171,7 +1171,7 @@ class rcmail_output_html extends rcmail_output // generate html code for button if ($btn_content) { - $attrib_str = html::attrib_string($attrib, $link_attrib); + $attrib_str = html::attrib_string($attrib, array_merge(html::$common_attrib, $link_attrib)); $out = sprintf('%s', $attrib_str, $btn_content); } diff --git a/program/js/app.js b/program/js/app.js index cef688204..5233d9c9a 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -258,12 +258,12 @@ function rcube_webmail() this.env.address_group_stack = []; this.env.compose_commands = ['send-attachment', 'remove-attachment', 'send', 'cancel', 'toggle-editor', 'list-adresses', 'pushgroup', 'search', 'reset-search', 'extwin', - 'insert-response', 'save-response', 'edit-responses']; + 'insert-response', 'save-response']; if (this.env.drafts_mailbox) this.env.compose_commands.push('savedraft') - this.enable_command(this.env.compose_commands, 'identities', true); + this.enable_command(this.env.compose_commands, 'identities', 'responses', true); // add more commands (not enabled) $.merge(this.env.compose_commands, ['add-recipient', 'firstpage', 'previouspage', 'nextpage', 'lastpage']); @@ -277,6 +277,7 @@ function rcube_webmail() // init canned response functions if (this.gui_objects.responseslist) { $('a.insertresponse', this.gui_objects.responseslist) + .attr('unselectable', 'on') .mousedown(function(e){ return rcube_event.cancel(e); }) .mouseup(function(e){ ref.command('insert-response', $(this).attr('rel')); @@ -3458,7 +3459,7 @@ function rcube_webmail() this.edit_responses = function() { - // TODO: decide what to do here... + // TODO: implement inline editing of responses }; this.delete_response = function(key) diff --git a/program/lib/Roundcube/html.php b/program/lib/Roundcube/html.php index 2086aaa85..4295f26d6 100644 --- a/program/lib/Roundcube/html.php +++ b/program/lib/Roundcube/html.php @@ -3,7 +3,7 @@ /* +-----------------------------------------------------------------------+ | This file is part of the Roundcube Webmail client | - | Copyright (C) 2005-2011, The Roundcube Dev Team | + | Copyright (C) 2005-2013, The Roundcube Dev Team | | | | Licensed under the GNU General Public License version 3 or | | any later version with exceptions for skins & plugins. | @@ -32,7 +32,7 @@ class html public static $doctype = 'xhtml'; public static $lc_tags = true; - public static $common_attrib = array('id','class','style','title','align'); + public static $common_attrib = array('id','class','style','title','align','unselectable'); public static $containers = array('iframe','div','span','p','h1','h2','h3','ul','form','textarea','table','thead','tbody','tr','th','td','style','script'); diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc index 282a2fd3e..bce4fd313 100644 --- a/program/steps/mail/compose.inc +++ b/program/steps/mail/compose.inc @@ -1713,6 +1713,7 @@ function rcmail_compose_responses_list($attrib) $item = html::a(array( 'href '=> '#'.urlencode($response['name']), 'class' => rtrim('insertresponse ' . $attrib['itemclass']), + 'unselectable' => 'on', 'rel' => $key, ), Q($response['name'])); diff --git a/skins/larry/images/buttons.png b/skins/larry/images/buttons.png index 3e28d128d..03c61ed93 100644 Binary files a/skins/larry/images/buttons.png and b/skins/larry/images/buttons.png differ diff --git a/skins/larry/templates/compose.html b/skins/larry/templates/compose.html index 0e4568bdd..863570cd1 100644 --- a/skins/larry/templates/compose.html +++ b/skins/larry/templates/compose.html @@ -30,7 +30,7 @@ - + @@ -200,8 +200,8 @@
  • -
  • -
  • +
  • +
  • -- cgit v1.2.3 From 9c41ba3c9ebbb14d01abe961c420f71f9463e61a Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Thu, 19 Sep 2013 17:56:14 +0200 Subject: Allow sysadmins to define static responses which are immutable for the user --- config/defaults.inc.php | 6 ++++++ program/include/rcmail.php | 15 ++++++++++++++- program/js/app.js | 2 +- program/steps/settings/edit_response.inc | 19 +++++++++---------- program/steps/settings/responses.inc | 8 +++++--- skins/classic/settings.css | 5 +++++ skins/classic/templates/responseedit.html | 2 +- skins/larry/settings.css | 4 ++++ skins/larry/templates/responseedit.html | 2 +- 9 files changed, 46 insertions(+), 17 deletions(-) (limited to 'skins/larry/templates') diff --git a/config/defaults.inc.php b/config/defaults.inc.php index 2a51b0805..a5bf34415 100644 --- a/config/defaults.inc.php +++ b/config/defaults.inc.php @@ -586,6 +586,12 @@ $config['upload_progress'] = false; // Setting it to 0, disables the feature. $config['undo_timeout'] = 0; +// A static list of canned responses which are immutable for the user +$config['compose_responses_static'] = array( +// array('name' => 'Canned Response 1', 'text' => 'Static Response One'), +// array('name' => 'Canned Response 2', 'text' => 'Static Response Two'), +); + // ---------------------------------- // ADDRESSBOOK SETTINGS // ---------------------------------- diff --git a/program/include/rcmail.php b/program/include/rcmail.php index f58235cbf..4a07e0b69 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -351,11 +351,24 @@ class rcmail extends rcube * These are stored in local config and user preferences. * * @param boolean True to sort the list alphabetically + * @param boolean True if only this user's responses shall be listed * @return array List of the current user's stored responses */ - public function get_compose_responses($sorted = false) + public function get_compose_responses($sorted = false, $user_only = false) { $responses = array(); + + if (!$user_only) { + foreach ($this->config->get('compose_responses_static', array()) as $response) { + if (empty($response['key'])) + $response['key'] = substr(md5($response['name']), 0, 16); + $response['static'] = true; + $response['class'] = 'readonly'; + $k = $sorted ? '0000-' . strtolower($response['name']) : $response['key']; + $responses[$k] = $response; + } + } + foreach ($this->config->get('compose_responses', array()) as $response) { if (empty($response['key'])) $response['key'] = substr(md5($response['name']), 0, 16); diff --git a/program/js/app.js b/program/js/app.js index abe267a6d..5943ad0fd 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -447,7 +447,7 @@ function rcube_webmail() this.responses_list = new rcube_list_widget(this.gui_objects.responseslist, {multiselect:false, draggable:false, keyboard:false}); this.responses_list.addEventListener('select', function(list){ var win, id = list.get_single_selection(); - p.enable_command('delete', !!id); + p.enable_command('delete', !!id && $.inArray(id, p.env.readonly_responses) < 0); if (id && (win = p.get_frame_window(p.env.contentframe))) { p.set_busy(true); p.location_href({ _action:'edit-response', _key:id, _framed:1 }, win); diff --git a/program/steps/settings/edit_response.inc b/program/steps/settings/edit_response.inc index 26f7e6e48..49856775a 100644 --- a/program/steps/settings/edit_response.inc +++ b/program/steps/settings/edit_response.inc @@ -24,8 +24,6 @@ $responses = $RCMAIL->get_compose_responses(); // edit-response if (($key = get_input_value('_key', RCUBE_INPUT_GPC))) { foreach ($responses as $i => $response) { - if (empty($response['key'])) - $response['key'] = substr(md5($response['name']), 0, 16); if ($response['key'] == $key) { $RESPONSE_RECORD = $response; $RESPONSE_RECORD['index'] = $i; @@ -35,13 +33,10 @@ if (($key = get_input_value('_key', RCUBE_INPUT_GPC))) { } // save response -if ($RCMAIL->action == 'save-response' && isset($_POST['_name'])) { +if ($RCMAIL->action == 'save-response' && isset($_POST['_name']) && !$RESPONSE_RECORD['static']) { $name = trim(get_input_value('_name', RCUBE_INPUT_POST)); $text = trim(get_input_value('_text', RCUBE_INPUT_POST)); - if (!empty($_REQUEST['_framed'])) - $RCMAIL->output->framed = 1; - if (!empty($name) && !empty($text)) { $dupes = 0; foreach ($responses as $i => $resp) { @@ -62,9 +57,11 @@ if ($RCMAIL->action == 'save-response' && isset($_POST['_name'])) { $responses[] = $response; } - if ($RCMAIL->user->save_prefs(array('compose_responses' => $responses))) { + $responses = array_filter($responses, function($item){ return empty($item['static']); }); + if ($RCMAIL->user->save_prefs(array('compose_responses' => array_values($responses)))) { $RCMAIL->output->show_message('successfullysaved', 'confirmation'); - $RCMAIL->output->command('update_response_row', $response, $key); + $RCMAIL->output->command('parent.update_response_row', $response, $key); + $RCMAIL->overwrite_action('edit-response'); $RESPONSE_RECORD = $response; } } @@ -79,6 +76,7 @@ function rcube_response_form($attrib) global $RCMAIL, $OUTPUT, $RESPONSE_RECORD; // Set form tags and hidden fields + $disabled = !empty($RESPONSE_RECORD['static']); $key = $RESPONSE_RECORD['key']; list($form_start, $form_end) = get_form_tags($attrib, 'save-response', $key, array('name' => '_key', 'value' => $key)); unset($attrib['form'], $attrib['id']); @@ -90,10 +88,10 @@ function rcube_response_form($attrib) $label = rcube_label('responsename'); $table->add('title', html::label('ffname', Q(rcube_label('responsename')))); - $table->add(null, rcube_output::get_edit_field('name', $RESPONSE_RECORD['name'], array('id' => 'ffname', 'size' => $attrib['size']), 'text')); + $table->add(null, rcube_output::get_edit_field('name', $RESPONSE_RECORD['name'], array('id' => 'ffname', 'size' => $attrib['size'], 'disabled' => $disabled), 'text')); $table->add('title', html::label('fftext', Q(rcube_label('responsetext')))); - $table->add(null, rcube_output::get_edit_field('text', $RESPONSE_RECORD['text'], array('id' => 'fftext', 'size' => $attrib['textareacols'], 'rows' => $attrib['textarearows']), 'textarea')); + $table->add(null, rcube_output::get_edit_field('text', $RESPONSE_RECORD['text'], array('id' => 'fftext', 'size' => $attrib['textareacols'], 'rows' => $attrib['textarearows'], 'disabled' => $disabled), 'textarea')); $out .= $table->show($attrib); $out .= $form_end; @@ -101,6 +99,7 @@ function rcube_response_form($attrib) return $out; } +$OUTPUT->set_env('readonly', !empty($RESPONSE_RECORD['static'])); $OUTPUT->add_handler('responseform', 'rcube_response_form'); $OUTPUT->set_pagetitle(rcube_label(($RCMAIL->action=='add-response' ? 'savenewresponse' : 'editresponse'))); diff --git a/program/steps/settings/responses.inc b/program/steps/settings/responses.inc index 330b4fde4..cfc4148c3 100644 --- a/program/steps/settings/responses.inc +++ b/program/steps/settings/responses.inc @@ -26,7 +26,7 @@ if (!empty($_POST['_insert'])) { if (!empty($name) && !empty($text)) { $dupes = 0; - $responses = $RCMAIL->get_compose_responses(); + $responses = $RCMAIL->get_compose_responses(false, true); foreach ($responses as $resp) { if (strcasecmp($name, preg_replace('/\s\(\d+\)$/', '', $resp['name'])) == 0) $dupes++; @@ -54,7 +54,7 @@ if (!empty($_POST['_insert'])) { if ($RCMAIL->action == 'delete-response') { if ($key = get_input_value('_key', RCUBE_INPUT_GPC)) { - $responses = $RCMAIL->get_compose_responses(); + $responses = $RCMAIL->get_compose_responses(false, true); foreach ($responses as $i => $response) { if (empty($response['key'])) $response['key'] = substr(md5($response['name']), 0, 16); @@ -67,7 +67,7 @@ if ($RCMAIL->action == 'delete-response') { } if ($deleted) { - $RCMAIL->output->command('display_message', rcube_label('successfullydeleted'), 'confirmation'); + $RCMAIL->output->command('display_message', rcube_label('deletedsuccessfully'), 'confirmation'); $RCMAIL->output->command('remove_response', $key); } @@ -99,6 +99,8 @@ function rcmail_responses_list($attrib) // set client env $OUTPUT->add_gui_object('responseslist', $attrib['id']); + $OUTPUT->set_env('readonly_responses', array_values(array_map(function($rec){ return $rec['key']; }, + array_filter($plugin['list'], function($item){ return !empty($item['static']); })))); return $out; } diff --git a/skins/classic/settings.css b/skins/classic/settings.css index 0e4f796a4..acd0b9fd0 100644 --- a/skins/classic/settings.css +++ b/skins/classic/settings.css @@ -34,6 +34,11 @@ height: 18px; } +#identities-table tbody tr.readonly td +{ + font-style: italic; +} + #subscription-table tr.virtual td { color: #666; diff --git a/skins/classic/templates/responseedit.html b/skins/classic/templates/responseedit.html index fbc5f663d..67ba35bac 100644 --- a/skins/classic/templates/responseedit.html +++ b/skins/classic/templates/responseedit.html @@ -15,7 +15,7 @@
    - +
    diff --git a/skins/larry/settings.css b/skins/larry/settings.css index 8deb24716..920376a96 100644 --- a/skins/larry/settings.css +++ b/skins/larry/settings.css @@ -194,6 +194,10 @@ text-overflow: ellipsis; } +#identities-table tbody tr.readonly td { + font-style: italic; +} + #folder-details, #identity-details { position: absolute; diff --git a/skins/larry/templates/responseedit.html b/skins/larry/templates/responseedit.html index d2f031b34..8f180fe7f 100644 --- a/skins/larry/templates/responseedit.html +++ b/skins/larry/templates/responseedit.html @@ -13,7 +13,7 @@
    - +
    -- cgit v1.2.3