If a email record is added to a webform with default template used, then default template content is copied to DB and it virtually prevent changing of default template; I mean even if the default template is changed, all emails will still be sent with the previoustemplate used, until EACH email for EACH webform is opened, template is changed to "default" and then it's saved.
Also, if there are emails with custom templates set up, it could be difficult to do the above mentioned task properly, since after the defaul template changes, email template would be displayed on the email edit page as "custom", not as"default".
Here is listed a small patch that makes this situation much more clear without any breaking changes to the code. If default template is used, 'default" is saved to DB, as it's done for some other fields:
webform.js
Drupal.webform.updateTemplate = function(context) {
var defaultTemplate = $('#edit-templates-default').val();
var $templateSelect = $('#webform-template-fieldset select', context);
var $templateTextarea = $('#webform-template-fieldset textarea', context);
var updateTemplateSelect = function() {
- if ($(this).val() == defaultTemplate) {
+ var val = $(this).val();
+ if (val == '' || val == 'default') { // as a variant, may be added: || val == defaultTemplate - but I don't think it's neccessary, and it affects client browser perfomance.
$templateSelect.val('default');
}
else {
$templateSelect.val('custom');
}
}
var updateTemplateText = function() {
if ($(this).val() == 'default') {
- $templateTextarea.val(defaultTemplate);
+ $templateTextarea.val('default');
+ }
+ else {
+ var val = $templateTextarea.val();
+ if (val == '' || val == 'default') {
+ $templateTextarea.val(defaultTemplate);
+ }
}
}
$templateTextarea.keyup(updateTemplateSelect);
$templateSelect.change(updateTemplateText);
}
includes\webform.emails.inc
- $default_template = theme(array('webform_mail_'. $node->nid, 'webform_mail', 'webform_mail_message'), array(), $node, 0, 'default');
- $template = $email['template'] == 'default' ? $default_template : $email['template'];
+ $template = $email['template'];
$form['template']['template'] = array(
'#type' => 'textarea',
'#rows' => max(10, min(20, count(explode("\n", $template)))),
'#description' => theme('webform_token_help', $node),
'#default_value' => $template,
);
...
...
...
// TODO: Allow easy re-use of existing templates.
$form['templates']['#tree'] = TRUE;
+ $default_template = theme(array('webform_mail_'. $node->nid, 'webform_mail', 'webform_mail_message'), array(), $node, 0, 'default');
Comments
Comment #1
quicksketchI do not believe this is correct. The submit handler for e-mail settings regenerates the default e-mail and compares it against the template entered by the user. If the two are identical, then the word "default" is stored in the webform_emails table, not the entire default template. Could you provide steps to reproduce the problem you're describing if this doesn't seem to be the case?
Perhaps this is a line-ending issue (Windows line breaks instead of Unix ones). What browser and OS are you using?
Comment #2
marrch_caat commentedI'm really sorry for that unnecessary patch. I've found the problem and developed the patch about 1.5 or 2 months ago, but had no time to clean it up and report to you. Looks like something has changed in the module after that and I've missed it. At least I can tell that now, after I replaced the patched module with the latest 6.x-3.x-dev release, the problem isn't there and there is no need for my patch anymore. So I beg my pardon to you for the disturbance. Of course, I had to retest the problem before reporting it...