Index: css/modr8.css =================================================================== --- css/modr8.css (revision 0) +++ css/modr8.css (revision 0) @@ -0,0 +1,9 @@ +/* Adds some space below the "send email" checkbox */ +#modr8-form .send-email-item { + margin-bottom: 15px; +} + +/* Used when the "Note to author" section is greyed out */ +#modr8-form .greyed-out { + color: #777; +} \ No newline at end of file Index: modr8_admin.inc =================================================================== --- modr8_admin.inc (revision 1836) +++ modr8_admin.inc (working copy) @@ -34,6 +34,13 @@ '#title' => t('E-mail'), ); + $form['text']['modr8_send_default'] = array( + '#type' => 'checkbox', + '#title' => t('Send email notifications to author by default'), + '#default_value' => variable_get('modr8_send_default', FALSE), + '#weight' => -1, + ); + $form['text']['modr8_email_from'] = array( '#type' => 'textfield', '#title' => t('Moderator email adress'), @@ -41,12 +48,6 @@ '#default_value' => variable_get('modr8_email_from', ''), ); - $form['text']['modr8_send_approve'] = array( - '#type' => 'checkbox', - '#title' => t('Send approval messages'), - '#default_value' => variable_get('modr8_send_approve', FALSE), - ); - $form['text']['modr8_accepted_subject'] = array( '#type' => 'textfield', '#title' => t('Acceptance e-mail subject'), @@ -64,12 +65,6 @@ '#description' => t('Replacement strings are: %macros', array('%macros' => $macros)), ); - $form['text']['modr8_send_deny'] = array( - '#type' => 'checkbox', - '#title' => t('Send denial messages'), - '#default_value' => variable_get('modr8_send_deny', FALSE), - ); - $form['text']['modr8_denial_subject'] = array( '#type' => 'textfield', '#title' => t('Denial e-mail subject'), @@ -85,12 +80,6 @@ '#description' => t('Replacement strings are: %macros', array('%macros' => $macros)), ); - $form['text']['modr8_send_noact'] = array( - '#type' => 'checkbox', - '#title' => t('Send a message when taking no action, but only if the moderator enters a "Note to author".'), - '#default_value' => variable_get('modr8_send_noact', FALSE), - ); - $form['text']['modr8_noact_subject'] = array( '#type' => 'textfield', '#title' => t('No action e-mail subject'), @@ -242,13 +231,26 @@ '#options' => $op_options, '#default_value' => variable_get('modr8_default_option', 'nada'), ); - if (variable_get('modr8_send_approve', FALSE) || variable_get('modr8_send_deny', FALSE)) { - $form[$node->nid]['note'] = array( - '#type' => 'textarea', - '#title' => t('Note to author'), - '#cols' => 15, // keep it narrow - ); - } + + $form[$node->nid]['send_email'] = array( + '#type' => 'checkbox', + '#title' => t('Send email notification to author'), + '#default_value' => variable_get('modr8_send_default', FALSE), + '#weight' => 3, + '#prefix' => '
', + '#suffix' => '
', + '#description' => t('When taking no action, an email is sent only if the moderator enters a "Note to author".'), + ); + + $form[$node->nid]['note'] = array( + '#type' => 'textarea', + '#title' => t('Note to author'), + '#cols' => 15, // keep it narrow + '#prefix' => '
', + '#suffix' => '', + '#description' => t('A note to add to the default email message (optional).'), + ); + $form[$node->nid]['preview'] = array( '#type' => 'value', '#value' => $teaser, @@ -296,6 +298,17 @@ * Themes the content moderation form. */ function theme_modr8_form(&$form) { + // Setting preprocess to FALSE since it is used only for this page. + // See documetation on drupal_add_css for more details. + drupal_add_css( + drupal_get_path('module', 'modr8'). '/css/modr8.css', + 'module' + ); + drupal_add_js( + drupal_get_path('module', 'modr8'). '/js/modr8.js', + 'module' + ); + $headers = array( t('Operations'), t('Content') @@ -305,11 +318,11 @@ if (is_numeric($key)) { $row = array(); $note_field = ''; - if (variable_get('modr8_send_approve', FALSE) || variable_get('modr8_send_deny', FALSE)) { - $note_field .= drupal_render($form[$key]['note']); - } + $note_field .= drupal_render($form[$key]['note']); $row[] = array( - 'data' => drupal_render($form[$key]['ops']) . $note_field, + 'data' => drupal_render($form[$key]['ops']) + . drupal_render($form[$key]['send_email']) + . $note_field, 'style' => 'vertical-align:top;' ); // Apply extra filtering to insure we don't have nested form elements, @@ -340,7 +353,7 @@ $message = ''; switch ($values['ops']) { case 'approve': - if (variable_get('modr8_send_approve', FALSE)) { + if ($values['send_email'] == 1) { $message = modr8_usermail('approve', $nid, $values); } $publish = ''; @@ -353,7 +366,7 @@ modr8_log_action('approve', $nid, $values, $message); break; case 'delete': - if (variable_get('modr8_send_deny', FALSE)) { + if ($values['send_email'] == 1) { $message = modr8_usermail('deny', $nid, $values); } node_delete($nid); @@ -361,7 +374,7 @@ modr8_log_action('delete', $nid, $values, $message); break; case 'nada': - if (variable_get('modr8_send_noact', FALSE) && !empty($values['note'])) { + if ($values['send_email'] == 1 && !empty($values['note'])) { $message = modr8_usermail('nada', $nid, $values); modr8_log_action('nada', $nid, $values, $message); } Index: js/modr8.js =================================================================== --- js/modr8.js (revision 0) +++ js/modr8.js (revision 0) @@ -0,0 +1,29 @@ +/** + * This script is used by the modr8 module to alter + * the display of the Moderated Content page. + */ + +$(document).ready(function() { + $('.send-email-item').each(function(i) { + updateNoteItemDisplayStatus(this); + }); + + $('.send-email-item').click(function() { + updateNoteItemDisplayStatus(this); + }); +}); + +/** + * This function is used to enable of disable (grey out) the + * "Note to author" section, depending on the status of the + * "send email notification" checkbox. + */ +function updateNoteItemDisplayStatus(currentCheckbox) { + var needsEmail = $(currentCheckbox).find('input:checked').length; + if( needsEmail == 1 ) { + $(currentCheckbox).siblings('.note-item').find('*').removeAttr("disabled").removeClass("greyed-out"); + } + else { + $(currentCheckbox).siblings('.note-item').find('*').attr("disabled", true).addClass("greyed-out"); + } +}