New settings section to manage canned responses

pull/134/head
Thomas Bruederli 11 years ago
parent 2d6242ffb2
commit 0ce2126ac9

@ -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.

@ -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 *********/

@ -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';

@ -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.';

@ -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);
}

@ -0,0 +1,108 @@
<?php
/*
+-----------------------------------------------------------------------+
| program/steps/settings/edit_response.inc |
| |
| This file is part of the Roundcube Webmail client |
| Copyright (C) 2013, The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Show edit form for a canned response record or to add a new one |
| |
+-----------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> |
+-----------------------------------------------------------------------+
*/
$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');

@ -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',
));

@ -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');

@ -4,6 +4,7 @@
<span id="settingstabpreferences" class="listitem preferences"><roundcube:button command="preferences" type="link" label="preferences" title="editpreferences" /></span>
<span id="settingstabfolders" class="listitem folders"><roundcube:button command="folders" type="link" label="folders" title="managefolders" /></span>
<span id="settingstabidentities" class="listitem identities"><roundcube:button command="identities" type="link" label="identities" title="manageidentities" /></span>
<span id="settingstabresponses" class="listitem responses"><roundcube:button command="responses" type="link" label="responses" title="editresponses" /></span>
<roundcube:container name="tabs" id="settings-tabs" />
</div>
</div>

@ -0,0 +1,22 @@
<roundcube:object name="doctype" value="html5" />
<html>
<head>
<title><roundcube:object name="pagetitle" /></title>
<roundcube:include file="/includes/links.html" />
</head>
<body class="iframe">
<h1 class="boxtitle"><roundcube:object name="steptitle" /></h1>
<div id="preferences-details" class="boxcontent">
<roundcube:object name="responseform" class="propform" size="60" textareacols="60" textarearows="18" />
</div>
<div class="footerleft formbuttons">
<roundcube:button command="save" type="input" class="button mainaction" label="save" />
</div>
<roundcube:include file="/includes/footer.html" />
</body>
</html>

@ -0,0 +1,41 @@
<roundcube:object name="doctype" value="html5" />
<html>
<head>
<title><roundcube:object name="pagetitle" /></title>
<roundcube:include file="/includes/links.html" />
</head>
<body class="noscroll">
<roundcube:include file="/includes/header.html" />
<div id="mainscreen" class="offset">
<roundcube:include file="/includes/settingstabs.html" />
<div id="settings-right">
<div id="identitieslist" class="uibox listbox">
<h2 class="boxtitle"><roundcube:label name="responses" /></h2>
<div class="scroller withfooter">
<roundcube:object name="responsesList" id="identities-table" class="listing" cellspacing="0" summary="Responses list" noheader="true" />
</div>
<div class="boxfooter">
<roundcube:button command="add" type="link" title="savenewresponse" class="listbutton add disabled" classAct="listbutton add" innerClass="inner" content="+" /><roundcube:button command="delete" type="link" title="delete" class="listbutton delete disabled" classAct="listbutton delete" innerClass="inner" content="-" />
</div>
</div>
<div id="identity-details" class="uibox contentbox">
<div class="iframebox">
<roundcube:object name="responseframe" id="preferences-frame" style="width:100%; height:100%" frameborder="0" src="/watermark.html" />
</div>
<roundcube:object name="message" id="message" class="statusbar" />
</div>
</div>
</div>
<roundcube:include file="/includes/footer.html" />
</body>
</html>
Loading…
Cancel
Save