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 --- program/js/app.js | 170 +++++++++++++++++++++++++++++++- program/lib/Roundcube/html.php | 2 +- program/localization/en_US/labels.inc | 8 ++ program/localization/en_US/messages.inc | 1 + program/steps/mail/compose.inc | 42 +++++++- program/steps/settings/responses.inc | 53 ++++++++++ skins/larry/styles.css | 33 ++++++- skins/larry/templates/compose.html | 11 +++ 8 files changed, 315 insertions(+), 5 deletions(-) create mode 100644 program/steps/settings/responses.inc diff --git a/program/js/app.js b/program/js/app.js index dedad37d2..7e58121f2 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -256,7 +256,9 @@ function rcube_webmail() } else if (this.env.action == 'compose') { this.env.address_group_stack = []; - this.env.compose_commands = ['send-attachment', 'remove-attachment', 'send', 'cancel', 'toggle-editor', 'list-adresses', 'pushgroup', 'search', 'reset-search', 'extwin']; + 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']; if (this.env.drafts_mailbox) this.env.compose_commands.push('savedraft') @@ -272,6 +274,22 @@ function rcube_webmail() this.enable_command('spellcheck', true); } + // init canned response functions + if (this.gui_objects.responseslist) { + $('a.insertresponse', this.gui_objects.responseslist) + .mousedown(function(e){ return rcube_event.cancel(e); }) + .mouseup(function(e){ + ref.command('insert-response', $(this).attr('rel')); + $(document.body).trigger('mouseup'); // hides the menu + return rcube_event.cancel(e); + }); + + // avoid textarea loosing focus when hitting the save-response button/link + for (var i=0; this.buttons['save-response'] && i < this.buttons['save-response'].length; i++) { + $('#'+this.buttons['save-response'][i].id).mousedown(function(e){ return rcube_event.cancel(e); }) + } + } + document.onmouseup = function(e){ return p.doc_mouse_up(e); }; // init message compose form @@ -3283,6 +3301,108 @@ function rcube_webmail() return true; }; + this.insert_response = function(key) + { + var insert = this.env.textresponses[key] ? this.env.textresponses[key].text : null; + if (!insert) + return false; + + // get cursor pos + var textarea = rcube_find_object(this.env.composebody), + selection = $(textarea).is(':focus') ? this.get_input_selection(textarea) : { start:0, end:0 }, + inp_value = textarea.value; + pre = inp_value.substring(0, selection.start), + end = inp_value.substring(selection.end, inp_value.length); + + // insert response text + textarea.value = pre + insert + end; + + // set caret after inserted text + this.set_caret_pos(textarea, selection.start + insert.length); + textarea.focus(); + }; + + /** + * Open the dialog to save a new canned response + */ + this.save_response = function() + { + var textarea = rcube_find_object(this.env.composebody), + text = '', sigstart; + + if (textarea && $(textarea).is(':focus')) { + text = this.get_input_selection(textarea).text; + } + + if (!text && textarea) { + text = textarea.value; + + // strip off signature + sigstart = text.indexOf('-- \n'); + if (sigstart > 0) { + text = textarea.value.substring(0, sigstart); + } + } + + // show dialog to enter a name and to modify the text to be saved + var buttons = {}, + html = '
' + + '
' + + '
' + + '
' + + '
' + + '
'; + + buttons[this.gettext('save')] = function(e) { + var name = $('#ffresponsename').val(), + text = $('#ffresponsetext').val(); + + if (!text) { + $('#ffresponsetext').select(); + return false; + } + if (!name) + name = text.substring(0,40); + + var lock = ref.display_message(ref.get_label('savingresponse'), 'loading'); + ref.http_post('settings/responses', { _insert:1, _name:name, _text:text }, lock); + $(this).dialog('close'); + }; + + buttons[this.gettext('cancel')] = function() { + $(this).dialog('close'); + }; + + this.show_popup_dialog(html, this.gettext('savenewresponse'), buttons); + + $('#ffresponsetext').val(text); + $('#ffresponsename').select(); + }; + + this.add_response_item = function(response) + { + var key = response.key; + this.env.textresponses[key] = response; + + // append to responses list + if (this.gui_objects.responseslist) { + var li = $('
  • ').appendTo(this.gui_objects.responseslist); + $('').addClass('insertresponse active') + .attr('href', '#') + .attr('rel', key) + .html(response.name) + .appendTo(li) + .mousedown(function(e){ + return rcube_event.cancel(e); + }) + .mouseup(function(e){ + ref.command('insert-response', key); + $(document.body).trigger('mouseup'); // hides the menu + return rcube_event.cancel(e); + }); + } + }; + this.stop_spellchecking = function() { var ed; @@ -6822,6 +6942,54 @@ function rcube_webmail() } }; + // get selected text from an input field + // http://stackoverflow.com/questions/7186586/how-to-get-the-selected-text-in-textarea-using-jquery-in-internet-explorer-7 + this.get_input_selection = function(obj) + { + var start = 0, end = 0, + normalizedValue, range, + textInputRange, len, endRange; + + if (typeof obj.selectionStart == "number" && typeof obj.selectionEnd == "number") { + normalizedValue = obj.value; + start = obj.selectionStart; + end = obj.selectionEnd; + } else { + range = document.selection.createRange(); + + if (range && range.parentElement() == obj) { + len = obj.value.length; + normalizedValue = obj.value.replace(/\r\n/g, "\n"); + + // create a working TextRange that lives only in the input + textInputRange = obj.createTextRange(); + textInputRange.moveToBookmark(range.getBookmark()); + + // Check if the start and end of the selection are at the very end + // of the input, since moveStart/moveEnd doesn't return what we want + // in those cases + endRange = obj.createTextRange(); + endRange.collapse(false); + + if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) { + start = end = len; + } else { + start = -textInputRange.moveStart("character", -len); + start += normalizedValue.slice(0, start).split("\n").length - 1; + + if (textInputRange.compareEndPoints("EndToEnd", endRange) > -1) { + end = len; + } else { + end = -textInputRange.moveEnd("character", -len); + end += normalizedValue.slice(0, end).split("\n").length - 1; + } + } + } + } + + return { start:start, end:end, text:normalizedValue.substr(start, end-start) }; + }; + // disable/enable all fields of a form this.lock_form = function(form, lock) { diff --git a/program/lib/Roundcube/html.php b/program/lib/Roundcube/html.php index a36711281..2086aaa85 100644 --- a/program/lib/Roundcube/html.php +++ b/program/lib/Roundcube/html.php @@ -33,7 +33,7 @@ class html public static $doctype = 'xhtml'; public static $lc_tags = true; public static $common_attrib = array('id','class','style','title','align'); - public static $containers = array('iframe','div','span','p','h1','h2','h3','form','textarea','table','thead','tbody','tr','th','td','style','script'); + 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/localization/en_US/labels.inc b/program/localization/en_US/labels.inc index 1865bcb3d..8cda30990 100644 --- a/program/localization/en_US/labels.inc +++ b/program/localization/en_US/labels.inc @@ -232,6 +232,14 @@ $labels['checkspelling'] = 'Check spelling'; $labels['resumeediting'] = 'Resume editing'; $labels['revertto'] = 'Revert to'; +$labels['responses'] = 'Responses'; +$labels['insertresponse'] = 'Insert a response'; +$labels['manageresponses'] = 'Manage responses'; +$labels['savenewresponse'] = 'Save new response'; +$labels['editresponses'] = 'Edit responses'; +$labels['responsename'] = 'Name'; +$labels['responsetext'] = 'Response Text'; + $labels['attach'] = 'Attach'; $labels['attachments'] = 'Attachments'; $labels['upload'] = 'Upload'; diff --git a/program/localization/en_US/messages.inc b/program/localization/en_US/messages.inc index 47b0f797d..e9feb243d 100644 --- a/program/localization/en_US/messages.inc +++ b/program/localization/en_US/messages.inc @@ -46,6 +46,7 @@ $messages['messagesent'] = 'Message sent successfully.'; $messages['savingmessage'] = 'Saving message...'; $messages['messagesaved'] = 'Message saved to Drafts.'; $messages['successfullysaved'] = 'Successfully saved.'; +$messages['savingresponse'] = 'Saving 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 f3ff19d72..efc0cc8e0 100644 --- a/program/steps/mail/compose.inc +++ b/program/steps/mail/compose.inc @@ -127,7 +127,8 @@ if (!is_array($COMPOSE)) $OUTPUT->add_label('nosubject', 'nosenderwarning', 'norecipientwarning', 'nosubjectwarning', 'cancel', 'nobodywarning', 'notsentwarning', 'notuploadedwarning', 'savingmessage', 'sendingmessage', 'messagesaved', 'converting', 'editorwarning', 'searching', 'uploading', 'uploadingmany', - 'fileuploaderror', 'sendmessage'); + 'fileuploaderror', 'sendmessage', 'savenewresponse', 'responsename', 'responsetext', 'save', + 'savingresponse'); $OUTPUT->set_env('compose_id', $COMPOSE['id']); $OUTPUT->set_pagetitle(rcube_label('compose')); @@ -1696,6 +1697,44 @@ function compose_file_drop_area($attrib) } +/** + * + */ +function rcmail_compose_responses_list($attrib) +{ + global $RCMAIL, $OUTPUT; + + $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( + '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); + } + + // set client env + $OUTPUT->set_env('textresponses', $jsenv); + $OUTPUT->add_gui_object('responseslist', $attrib['id']); + + return $list->show(); +} + + // register UI objects $OUTPUT->add_handlers(array( 'composeheaders' => 'rcmail_compose_headers', @@ -1712,6 +1751,7 @@ $OUTPUT->add_handlers(array( 'storetarget' => 'rcmail_store_target_selection', 'addressbooks' => 'rcmail_addressbook_list', 'addresslist' => 'rcmail_contacts_list', + 'responseslist' => 'rcmail_compose_responses_list', )); $OUTPUT->send('compose'); diff --git a/program/steps/settings/responses.inc b/program/steps/settings/responses.inc new file mode 100644 index 000000000..5a7db5687 --- /dev/null +++ b/program/steps/settings/responses.inc @@ -0,0 +1,53 @@ + | + +-----------------------------------------------------------------------+ +*/ + + +if (!empty($_POST['_insert'])) { + $name = 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()); + foreach ($responses as $resp) { + 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)); + $responses[] = $response; + + if ($RCMAIL->user->save_prefs(array('compose_responses' => $responses))) { + $RCMAIL->output->command('add_response_item', $response); + $RCMAIL->output->command('display_message', rcube_label('successfullysaved'), 'confirmation'); + } + else { + $RCMAIL->output->command('display_message', rcube_label('errorsaving'), 'error'); + } + } +} + +// send response +$RCMAIL->output->send(); + diff --git a/skins/larry/styles.css b/skins/larry/styles.css index d542768b7..131e85030 100644 --- a/skins/larry/styles.css +++ b/skins/larry/styles.css @@ -1440,6 +1440,20 @@ body.iframe .footerleft.floating:before, font-size: 12px; } +.propform div.prop { + margin-bottom: 0.5em; +} + +.propform div.prop.block label { + display: block; + margin-bottom: 0.3em; +} + +.propform div.prop.block input, +.propform div.prop.block textarea { + width: 95%; +} + fieldset.floating { float: left; margin-right: 10px; @@ -1922,6 +1936,7 @@ select.decorated option { } ul.toolbarmenu, +ul.toolbarmenu ul, #rcmKSearchpane ul { margin: 0; padding: 0; @@ -1940,13 +1955,13 @@ ul.toolbarmenu li, } .googie_list tr:first-child td, -ul.toolbarmenu li:first-child, +ul.toolbarmenu > li:first-child, select.decorated option:first-child { border-top: 0; } .googie_list tr:last-child td, -ul.toolbarmenu li:last-child, +ul.toolbarmenu > li:last-child, select.decorated option:last-child { border-bottom: 0; } @@ -2000,6 +2015,11 @@ ul.toolbarmenu li label { text-shadow: 0px 1px 1px #333; } +ul.toolbarmenu li.separator label { + color: #bbb; + font-style: italic; +} + ul.toolbarmenu li a.icon { color: #eee; padding: 2px 6px; @@ -2078,6 +2098,15 @@ ul.toolbarmenu li span.conversation { background-position: 0 -1532px; } +#snippetslist { + max-width: 200px; +} + +#snippetslist li a { + overflow: hidden; + text-overflow: ellipsis; +} + #rcmKSearchpane { border-radius: 0 0 4px 4px; border-top: 0; 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 2d6242ffb25b199b569d956b65dec36170026d1e Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Thu, 25 Jul 2013 18:55:24 +0200 Subject: Make canned response insertion and extraction work with both plaintext and HTML editors --- program/js/app.js | 142 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 89 insertions(+), 53 deletions(-) diff --git a/program/js/app.js b/program/js/app.js index 7e58121f2..a7a92175d 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -3307,19 +3307,27 @@ function rcube_webmail() if (!insert) return false; - // get cursor pos - var textarea = rcube_find_object(this.env.composebody), - selection = $(textarea).is(':focus') ? this.get_input_selection(textarea) : { start:0, end:0 }, - inp_value = textarea.value; - pre = inp_value.substring(0, selection.start), - end = inp_value.substring(selection.end, inp_value.length); + // insert into tinyMCE editor + if ($("input[name='_is_html']").val() == '1') { + var editor = tinyMCE.get(this.env.composebody); + editor.getWin().focus(); // correct focus in IE & Chrome + editor.selection.setContent(insert, { format:'text' }); + } + // replace selection in compose textarea + else { + var textarea = rcube_find_object(this.env.composebody), + selection = $(textarea).is(':focus') ? this.get_input_selection(textarea) : { start:0, end:0 }, + inp_value = textarea.value; + pre = inp_value.substring(0, selection.start), + end = inp_value.substring(selection.end, inp_value.length); - // insert response text - textarea.value = pre + insert + end; + // insert response text + textarea.value = pre + insert + end; - // set caret after inserted text - this.set_caret_pos(textarea, selection.start + insert.length); - textarea.focus(); + // set caret after inserted text + this.set_caret_pos(textarea, selection.start + insert.length); + textarea.focus(); + } }; /** @@ -3327,20 +3335,37 @@ function rcube_webmail() */ this.save_response = function() { - var textarea = rcube_find_object(this.env.composebody), - text = '', sigstart; + var sigstart, text = '', strip = false; - if (textarea && $(textarea).is(':focus')) { - text = this.get_input_selection(textarea).text; + // get selected text from tinyMCE editor + if ($("input[name='_is_html']").val() == '1') { + var editor = tinyMCE.get(this.env.composebody); + editor.getWin().focus(); // correct focus in IE & Chrome + text = editor.selection.getContent({ format:'text' }); + + if (!text) { + text = editor.getContent({ format:'text' }); + strip = true; + } } + // get selected text from compose textarea + else { + var textarea = rcube_find_object(this.env.composebody), sigstart; + if (textarea && $(textarea).is(':focus')) { + text = this.get_input_selection(textarea).text; + } - if (!text && textarea) { - text = textarea.value; + if (!text && textarea) { + text = textarea.value; + strip = true; + } + } - // strip off signature + // strip off signature + if (strip) { sigstart = text.indexOf('-- \n'); if (sigstart > 0) { - text = textarea.value.substring(0, sigstart); + text = text.substring(0, sigstart); } } @@ -3390,7 +3415,7 @@ function rcube_webmail() $('').addClass('insertresponse active') .attr('href', '#') .attr('rel', key) - .html(response.name) + .html(this.quote_html(response.name)) .appendTo(li) .mousedown(function(e){ return rcube_event.cancel(e); @@ -6878,6 +6903,14 @@ function rcube_webmail() /********* helper methods *********/ /********************************************************/ + /** + * Quote html entities + */ + this.quote_html = function(str) + { + return String(str).replace(//g, '>').replace(/"/g, '"'); + }; + // get window.opener.rcmail if available this.opener = function() { @@ -6951,40 +6984,43 @@ function rcube_webmail() textInputRange, len, endRange; if (typeof obj.selectionStart == "number" && typeof obj.selectionEnd == "number") { - normalizedValue = obj.value; - start = obj.selectionStart; - end = obj.selectionEnd; - } else { - range = document.selection.createRange(); - - if (range && range.parentElement() == obj) { - len = obj.value.length; - normalizedValue = obj.value.replace(/\r\n/g, "\n"); - - // create a working TextRange that lives only in the input - textInputRange = obj.createTextRange(); - textInputRange.moveToBookmark(range.getBookmark()); - - // Check if the start and end of the selection are at the very end - // of the input, since moveStart/moveEnd doesn't return what we want - // in those cases - endRange = obj.createTextRange(); - endRange.collapse(false); - - if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) { - start = end = len; - } else { - start = -textInputRange.moveStart("character", -len); - start += normalizedValue.slice(0, start).split("\n").length - 1; - - if (textInputRange.compareEndPoints("EndToEnd", endRange) > -1) { - end = len; - } else { - end = -textInputRange.moveEnd("character", -len); - end += normalizedValue.slice(0, end).split("\n").length - 1; - } - } + normalizedValue = obj.value; + start = obj.selectionStart; + end = obj.selectionEnd; + } + else { + range = document.selection.createRange(); + + if (range && range.parentElement() == obj) { + len = obj.value.length; + normalizedValue = obj.value.replace(/\r\n/g, "\n"); + + // create a working TextRange that lives only in the input + textInputRange = obj.createTextRange(); + textInputRange.moveToBookmark(range.getBookmark()); + + // Check if the start and end of the selection are at the very end + // of the input, since moveStart/moveEnd doesn't return what we want + // in those cases + endRange = obj.createTextRange(); + endRange.collapse(false); + + if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) { + start = end = len; } + else { + start = -textInputRange.moveStart("character", -len); + start += normalizedValue.slice(0, start).split("\n").length - 1; + + if (textInputRange.compareEndPoints("EndToEnd", endRange) > -1) { + end = len; + } + else { + end = -textInputRange.moveEnd("character", -len); + end += normalizedValue.slice(0, end).split("\n").length - 1; + } + } + } } return { start:start, end:end, text:normalizedValue.substr(start, end-start) }; -- 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 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 80b3c6200ee7788bef1bca0562aa53113ffea9bd Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Sun, 1 Sep 2013 16:35:58 +0200 Subject: Toolbar and list icons for responses + list header icon for prority column (#1489234) --- skins/larry/images/buttons.png | Bin 50162 -> 38670 bytes skins/larry/images/listicons.png | Bin 26384 -> 26242 bytes skins/larry/mail.css | 4 ++++ skins/larry/settings.css | 8 ++++++++ skins/larry/styles.css | 6 +++++- 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/skins/larry/images/buttons.png b/skins/larry/images/buttons.png index 9f8f44536..3e28d128d 100644 Binary files a/skins/larry/images/buttons.png and b/skins/larry/images/buttons.png differ diff --git a/skins/larry/images/listicons.png b/skins/larry/images/listicons.png index e4ffef660..e2906d957 100644 Binary files a/skins/larry/images/listicons.png and b/skins/larry/images/listicons.png differ diff --git a/skins/larry/mail.css b/skins/larry/mail.css index b65b08112..c5c00554c 100644 --- a/skins/larry/mail.css +++ b/skins/larry/mail.css @@ -621,6 +621,10 @@ table.messagelist.fixedcopy { background-position: -24px -1116px; } +.messagelist thead tr td.priority span.priority { + background-position: -24px -1845px; +} + .messagelist tr td.priority span.prio5 { background-position: 0 -1905px; } diff --git a/skins/larry/settings.css b/skins/larry/settings.css index 59037ac76..8deb24716 100644 --- a/skins/larry/settings.css +++ b/skins/larry/settings.css @@ -110,6 +110,14 @@ background-position: 6px -1819px; } +#settings-sections span.responses a { + background-position: 6px -1972px; +} + +#settings-sections span.responses.selected a { + background-position: 6px -1996px; +} + #sections-table #rcmrowgeneral td.section { background-position: 6px -573px; } diff --git a/skins/larry/styles.css b/skins/larry/styles.css index 131e85030..3313e1839 100644 --- a/skins/larry/styles.css +++ b/skins/larry/styles.css @@ -1831,7 +1831,11 @@ ul.proplist li { } .toolbar a.button.download { - background-position: center -1906px; + background-position: center -1892px; +} + +.toolbar a.button.responses { + background-position: center -1932px; } a.menuselector { -- 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(-) 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 4f35bec6b29d6b6b84ae4a4d64f72a139a6e8f32 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Wed, 4 Sep 2013 10:16:46 +0200 Subject: Don't normalize line breaks (doesn't work properly on IE) --- program/js/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/program/js/app.js b/program/js/app.js index 5233d9c9a..abe267a6d 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -7072,7 +7072,7 @@ function rcube_webmail() if (range && range.parentElement() == obj) { len = obj.value.length; - normalizedValue = obj.value.replace(/\r\n/g, "\n"); + normalizedValue = obj.value; //.replace(/\r\n/g, "\n"); // create a working TextRange that lives only in the input textInputRange = obj.createTextRange(); -- cgit v1.2.3 From 0d9b63e9c022c48b98ec1542dccb50f1b28f80b8 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Wed, 4 Sep 2013 11:13:26 +0200 Subject: Add canned response UI elements to classic skin --- skins/classic/common.css | 29 ++++++++++++++++++- skins/classic/images/mail_toolbar.png | Bin 40806 -> 39276 bytes skins/classic/includes/settingstabs.html | 1 + skins/classic/mail.css | 4 +++ skins/classic/settings.css | 15 ++++++++++ skins/classic/templates/compose.html | 11 +++++++ skins/classic/templates/responseedit.html | 24 ++++++++++++++++ skins/classic/templates/responses.html | 46 ++++++++++++++++++++++++++++++ skins/larry/images/buttons.png | Bin 53350 -> 38715 bytes 9 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 skins/classic/templates/responseedit.html create mode 100644 skins/classic/templates/responses.html diff --git a/skins/classic/common.css b/skins/classic/common.css index 3c322f0ed..accdf7166 100644 --- a/skins/classic/common.css +++ b/skins/classic/common.css @@ -511,7 +511,8 @@ body.iframe .boxtitle margin: 3px -4px; } -.popupmenu li a +.popupmenu li a, +.popupmenu li label { display: block; color: #a0a0a0; @@ -521,6 +522,14 @@ body.iframe .boxtitle background: transparent; } +.popupmenu li label.comment +{ + color: #999; + font-style: italic; + padding-top: 4px; + padding-bottom: 3px; +} + .popupmenu li a.active, .popupmenu li a.active:active, .popupmenu li a.active:visited @@ -704,6 +713,24 @@ ul.treelist li div.expanded outline: none; } +.propform div.prop +{ + margin-bottom: 0.5em; +} + +.propform div.prop.block label +{ + display: block; + margin-bottom: 2px; +} + +.propform div.prop.block input, +.propform div.prop.block textarea +{ + width: 97%; +} + + /***** roundcube webmail pre-defined classes *****/ #rcmversion diff --git a/skins/classic/images/mail_toolbar.png b/skins/classic/images/mail_toolbar.png index 4a8431715..3ef003f23 100644 Binary files a/skins/classic/images/mail_toolbar.png and b/skins/classic/images/mail_toolbar.png differ diff --git a/skins/classic/includes/settingstabs.html b/skins/classic/includes/settingstabs.html index 0aea80b67..e44eb5b8b 100644 --- a/skins/classic/includes/settingstabs.html +++ b/skins/classic/includes/settingstabs.html @@ -2,6 +2,7 @@ + diff --git a/skins/classic/mail.css b/skins/classic/mail.css index b8cc9f351..d472d6d07 100644 --- a/skins/classic/mail.css +++ b/skins/classic/mail.css @@ -171,6 +171,10 @@ background-position: -480px -32px; } +#messagetoolbar a.responses { + background-position: -512px 0; +} + #messagetoolbar select.mboxlist { position: relative; diff --git a/skins/classic/settings.css b/skins/classic/settings.css index 2433f5040..0e4f796a4 100644 --- a/skins/classic/settings.css +++ b/skins/classic/settings.css @@ -81,6 +81,7 @@ } #identity-details table td.title, +#response-details table td.title, #folder-details table td.title { font-weight: bold; @@ -89,6 +90,14 @@ white-space: nowrap; } +#response-details table td.title +{ + text-align: left; + vertical-align: top; + width: 140px; + padding-top: 5px; +} + #bottomboxes { position: absolute; @@ -149,6 +158,12 @@ body.iframe, float: right; } +#formfooter .footerindent +{ + padding: 10px 0; + margin-left: 155px; +} + #quota { position: absolute; diff --git a/skins/classic/templates/compose.html b/skins/classic/templates/compose.html index 5e259e11c..7ed9fac36 100644 --- a/skins/classic/templates/compose.html +++ b/skins/classic/templates/compose.html @@ -40,6 +40,7 @@ +   @@ -191,6 +192,16 @@ +
    +
      +
    • + +
    • +
    • +
    • +
    +
    +
    diff --git a/skins/classic/templates/responseedit.html b/skins/classic/templates/responseedit.html new file mode 100644 index 000000000..fbc5f663d --- /dev/null +++ b/skins/classic/templates/responseedit.html @@ -0,0 +1,24 @@ + + + +<roundcube:object name="pagetitle" /> + + + + + + +
    + +
    + + +
    +
    + +
    +
    +
    + + + diff --git a/skins/classic/templates/responses.html b/skins/classic/templates/responses.html new file mode 100644 index 000000000..14087d82e --- /dev/null +++ b/skins/classic/templates/responses.html @@ -0,0 +1,46 @@ + + + +<roundcube:object name="pagetitle" /> + + + + + + + + + + + + +
    + +
    +
    +
    + +
    +
    + +
    +
    + + + +
    + +
    + +
    + + + diff --git a/skins/larry/images/buttons.png b/skins/larry/images/buttons.png index 03c61ed93..8e2560198 100644 Binary files a/skins/larry/images/buttons.png and b/skins/larry/images/buttons.png differ -- cgit v1.2.3 From 460a3eaaac0ec17d04df310b0a696e39559c9446 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Wed, 4 Sep 2013 11:19:34 +0200 Subject: Fix indentation --- program/include/rcmail.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/program/include/rcmail.php b/program/include/rcmail.php index 9713cdb4e..62f6254b5 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -358,17 +358,17 @@ class rcmail extends rcube 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; - } + $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); - } + if ($sorted) { + // sort list by name + ksort($responses, SORT_LOCALE_STRING); + return array_values($responses); + } - return $responses; + return $responses; } -- cgit v1.2.3 From 4f432f880afeb078c2b60ce594872ec3eb1713e7 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Wed, 4 Sep 2013 12:07:58 +0200 Subject: Make result of rcmail::get_compose_responses() always an (indexed) array; add plugin hook for updating user prefs: 'preferences_update' --- program/include/rcmail.php | 6 +++--- program/lib/Roundcube/rcube_user.php | 12 ++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/program/include/rcmail.php b/program/include/rcmail.php index 62f6254b5..f58235cbf 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -355,6 +355,7 @@ class rcmail extends rcube */ public function get_compose_responses($sorted = false) { + $responses = array(); foreach ($this->config->get('compose_responses', array()) as $response) { if (empty($response['key'])) $response['key'] = substr(md5($response['name']), 0, 16); @@ -362,13 +363,12 @@ class rcmail extends rcube $responses[$k] = $response; } + // sort list by name if ($sorted) { - // sort list by name ksort($responses, SORT_LOCALE_STRING); - return array_values($responses); } - return $responses; + return array_values($responses); } diff --git a/program/lib/Roundcube/rcube_user.php b/program/lib/Roundcube/rcube_user.php index 5e9c9af80..57f63361d 100644 --- a/program/lib/Roundcube/rcube_user.php +++ b/program/lib/Roundcube/rcube_user.php @@ -163,8 +163,16 @@ class rcube_user if (!$this->ID) return false; - $config = $this->rc->config; - $old_prefs = (array)$this->get_prefs(); + $plugin = $this->rc->plugins->exec_hook('preferences_update', array( + 'userid' => $this->ID, 'prefs' => $a_user_prefs, 'old' => (array)$this->get_prefs())); + + if (!empty($plugin['abort'])) { + return; + } + + $a_user_prefs = $plugin['prefs']; + $old_prefs = $plugin['old']; + $config = $this->rc->config; // merge (partial) prefs array with existing settings $save_prefs = $a_user_prefs + $old_prefs; -- cgit v1.2.3 From cc041fe11c1997902f68f4ca8e95577e963a0053 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Wed, 4 Sep 2013 14:18:12 +0200 Subject: Use the correct label for responses list header --- skins/classic/templates/responses.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skins/classic/templates/responses.html b/skins/classic/templates/responses.html index 14087d82e..2459827b0 100644 --- a/skins/classic/templates/responses.html +++ b/skins/classic/templates/responses.html @@ -22,7 +22,7 @@
    -
    +
    -- 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(-) 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