cvs diff: Diffing modules/signup_status_mailer
Index: modules/signup_status_mailer/signup_status_mailer.settings.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup_status/modules/signup_status_mailer/signup_status_mailer.settings.inc,v
retrieving revision 1.6
diff -u -p -r1.6 signup_status_mailer.settings.inc
--- modules/signup_status_mailer/signup_status_mailer.settings.inc	20 Aug 2009 15:50:56 -0000	1.6
+++ modules/signup_status_mailer/signup_status_mailer.settings.inc	22 Aug 2009 02:00:32 -0000
@@ -11,6 +11,7 @@
  * Form builder for signup_status_mailer settings.
  */
 function signup_status_mailer_settings($form_state, $node = 0) {
+  drupal_add_js(drupal_get_path('module', 'signup_status_mailer') . '/signup_status_mailer.settings.js');
   $codes = signup_status_codes(array(), TRUE);
   $form = array('#tree' => TRUE);
   $site_settings = signup_status_mailer_get_settings(0);
@@ -153,24 +154,31 @@ function _signup_status_mailer_settings_
   );
 
   foreach (array('add', 'update') as $action) {
-    $form[$action] = array();
+    $form[$action] = array(
+      '#prefix' => '<div class="signup-status-mailer-action">',
+      '#suffix' => '</div>',
+    );
 
     if (!empty($node)) {
       // Figure out the appropriate options for the notifications setting.
-      $site_default = (!empty($site_setting[$action]['notification']) && $site_setting[$action]['notification'] != 'none') ? t('Enabled') : t('Disabled');
-
-      // Since these are select options, they'll be check_plain()'ed by FAPI,
-      // so we want to use !default to prevent double-escaping.
       $notification_options = array(
         'none' => t('Disabled'),
-        'default' => t("Use default (currently '!default')", array('!default' => $site_default)),
         'custom' => t('Enabled (custom)'),
       );
+      if (!empty($site_setting[$action]['notification']) && $site_setting[$action]['notification'] != 'none') {
+        $current_default = 'default-enabled';
+        $notification_options['default-enabled'] = t("Use default (currently 'Enabled')");
+      }
+      else {
+        $current_default = 'default-disabled';
+        $notification_options['default-disabled'] = t("Use default (currently 'Disabled')");
+      }
     }
 
     $form[$action]['notification'] = array(
       '#type' => 'select',
       '#options' => $notification_options,
+      '#attributes' => array('class' => 'signup_status_mailer_notification_select'),
     );
     if ($action == 'add') {
       $form[$action]['notification']['#title'] = t("E-mail notifications when the status '@status' is first set", array('@status' => $status['name']));
@@ -180,7 +188,7 @@ function _signup_status_mailer_settings_
     }
 
     $form[$action]['email'] = array(
-      // TODO will want some divs for jQuery
+      '#weight' => 1,
     );
     $form[$action]['email']['subject'] = array(
       '#type' => 'textfield',
@@ -196,33 +204,52 @@ function _signup_status_mailer_settings_
     // Now, figure out the default values to use for all of this.
     if (!empty($node)) {
       // Per-node settings
-      if (isset($node_setting[$action]['notification'])) {
+      if (isset($node_setting[$action]['notification']) && $node_setting[$action]['notification'] != 'default') {
         $default_notification = $node_setting[$action]['notification'];
       }
       else {
-        $default_notification = 'default';
+        $default_notification = $current_default;
       }
 
       // If we're on a node settings page, and we're configured to use the
       // site defaults, include them as disabled form elements for info, with
       // help text explaining how to change it.
-      if ($default_notification == 'default') {
+      if ($default_notification == $current_default) {
         $default_subject = isset($site_setting[$action]['subject']) ? $site_setting[$action]['subject'] : '';
         $default_body = isset($site_setting[$action]['body']) ? $site_setting[$action]['body'] : '';
         $form[$action]['email']['subject']['#disabled'] = TRUE;
         $form[$action]['email']['body']['#disabled'] = TRUE;
-        if (user_access(SIGNUP_STATUS_MAILER_ADMIN_PERM)) {
-          $form[$action]['notification']['#description'] = t('This message is configured to use the site-wide default text for this status. To modify the subject or body just for this %node_type, select "Enabled (custom)" to override the defaults. To change the subject or body for all status notifications, visit the <a href="@settings_url">site-wide Signup status mailer settings page</a>.', array('%node_type' => node_get_types('name', $node->type), '@settings_url' => url('admin/settings/signup_status/mailer', array('query' => drupal_get_destination()))));
-        }
-        else {
-          $form[$action]['notification']['#description'] = t('This message is configured to use the site-wide default text for this status. To modify the subject or body below, select "Enabled (custom)" to override the defaults for this %node_type.', array('%node_type' => node_get_types('name', $node->type)));
-        }
       }
       else {
         // Using per-node values, if any.
         $default_subject = isset($node_setting[$action]['subject']) ? $node_setting[$action]['subject'] : '';
         $default_body = isset($node_setting[$action]['body']) ? $node_setting[$action]['body'] : '';
       }
+
+      if (user_access(SIGNUP_STATUS_MAILER_ADMIN_PERM)) {
+        if ($current_default == 'default-disabled') {
+          $description = t('This message is configured to use the site-wide default, which is currently set to not send an e-mail. To send a message and specify the subject and body just for this %node_type, select "Enabled (custom)" to override the defaults. To send a message and define the subject and body for all status notifications, visit the <a href="@settings_url">site-wide Signup status mailer settings page</a>.', array('%node_type' => node_get_types('name', $node->type), '@settings_url' => url('admin/settings/signup_status/mailer', array('query' => drupal_get_destination()))));
+        }
+        else {
+          $description = t('This message is configured to use the site-wide default text for this status. To modify the subject or body just for this %node_type, select "Enabled (custom)" to override the defaults. To change the subject or body for all status notifications, visit the <a href="@settings_url">site-wide Signup status mailer settings page</a>.', array('%node_type' => node_get_types('name', $node->type), '@settings_url' => url('admin/settings/signup_status/mailer', array('query' => drupal_get_destination()))));
+        }
+      }
+      else {
+        if ($current_default == 'default-disabled') {
+          $description = t('This message is configured to use the site-wide default, which is currently set to not send an e-mail. To send a message and specify the subject and body, select "Enabled (custom)" to override the defaults for this %node_type.', array('%node_type' => node_get_types('name', $node->type)));
+        }
+        else {
+          $description = t('This message is configured to use the site-wide default text for this status. To modify the subject or body below, select "Enabled (custom)" to override the defaults for this %node_type.', array('%node_type' => node_get_types('name', $node->type)));
+        }
+      }
+      $description_classes = 'notification-description description';
+      if ($default_notification == 'none' || $default_notification == 'custom') {
+        $description_classes .= ' js-hide';
+      }
+      $form[$action]['notification-description'] = array(
+        '#type' => 'markup',
+        '#value' => '<div class="'. $description_classes . '">' . $description . '</div>',
+      );
     }
     else {
       // Site-wide settings
@@ -236,6 +263,15 @@ function _signup_status_mailer_settings_
       $default_body = isset($site_setting[$action]['body']) ? $site_setting[$action]['body'] : '';
     }
 
+    $email_classes = 'email-settings';
+    // If the notification for this status/action is currently configured not
+    // to send any notification, hide the email fields on page load.
+    if ($default_notification == 'none' || $default_notification == 'default-disabled') {
+      $email_classes .= ' js-hide';
+    }
+    $form[$action]['email']['#prefix'] = '<div class="'. $email_classes .'">';
+    $form[$action]['email']['#suffix'] = '</div>';
+
     // Finally load our defaults into the form.
     $form[$action]['notification']['#default_value'] = $default_notification;
     $form[$action]['email']['subject']['#default_value'] = $default_subject;
@@ -308,6 +344,9 @@ function signup_status_mailer_settings_s
         if (!empty($status_values[$action])) {
           $values = $status_values[$action];
           $values['action'] = $action;
+          if (strpos($values['notification'], 'default-')) {
+            $values['notification'] = 'default';
+          }
           $values['cid'] = $status_values['cid'];
           $values['nid'] = $form_state['values']['nid'];
           if ($values['nid'] == 0) {
Index: modules/signup_status_mailer/signup_status_mailer.settings.js
===================================================================
RCS file: modules/signup_status_mailer/signup_status_mailer.settings.js
diff -N modules/signup_status_mailer/signup_status_mailer.settings.js
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/signup_status_mailer/signup_status_mailer.settings.js	22 Aug 2009 02:00:32 -0000
@@ -0,0 +1,54 @@
+/* $Id$ */
+
+/**
+ * @file
+ * JavaScript to help the Signup Status Mailer settings UI not suck so much.
+ */
+
+/**
+ * Attach to the "E-mail notifications" select boxes and change other elements.
+ *
+ * - "Disabled" ('none'): Hide the e-mail fields and help text.
+ * - "Enabled" on the side-wide settings page ('default'): Show the
+ *   e-mail fields.
+ * - "Enabled (custom)" ('custom'): Show the e-mail fields and enable
+ *   them, hide the help text.
+ * - "Use default (currently 'Enabled')" ('default-enabled'): Show but
+ *   disable the e-mail fields, and show the help text.
+ * - "Use default (currently 'Disabled')" ('default-disabled'): Hide
+ *   the e-mail fields but show the help text.
+ */
+Drupal.behaviors.signupStatusMailerNotificationSetting = function() {
+  $('.signup_status_mailer_notification_select').click(function() {
+    /* Remember which select box form element was clicked. */
+    var self = this;
+    /* Find the DOM element that holds all the related elements for the same
+       action and status that belong to the select box that was clicked. */
+    var self_action = $(self).parent().parent();
+    /* Depending on the value of the select box, hide/show the right things. */
+    if (self.value == 'none') {
+      $(self_action).find('div.notification-description').hide();
+      $(self_action).find('div.email-settings').hide();
+    }
+    else if (self.value == 'default') {
+      $(self_action).find('div.email-settings').show();
+    }
+    else if (self.value == 'custom') {
+      $(self_action).find('div.notification-description').hide();
+      $(self_action).find('div.email-settings').show();
+      $(self_action).find('div.email-settings input[type=text]').removeAttr("disabled");
+      $(self_action).find('div.email-settings .form-textarea').removeAttr("disabled");
+    }
+    else if (self.value == 'default-enabled') {
+      $(self_action).find('div.notification-description').show();
+      $(self_action).find('div.email-settings').show();
+      $(self_action).find('div.email-settings input[type=text]').attr("disabled", "disabled");
+      $(self_action).find('div.email-settings .form-textarea').attr("disabled", "disabled");
+    }
+    else if (self.value == 'default-disabled') {
+      $(self_action).find('div.notification-description').show();
+      $(self_action).find('div.email-settings').hide();
+    }
+  });
+};
+
