Index: signup_status.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup_status/signup_status.admin.inc,v
retrieving revision 1.1
diff -u -p -r1.1 signup_status.admin.inc
--- signup_status.admin.inc 19 Jan 2009 11:02:54 -0000 1.1
+++ signup_status.admin.inc 19 Sep 2009 03:15:41 -0000
@@ -3,87 +3,124 @@
/**
* @file
- * Module admin page callbacks.
+ * Code related to the administrative (settings) pages for Signup Status.
*/
-//////////////////////////////////////////////////////////////////////////////
-// signup_status settings
-
/**
- * Implements the signup status code list.
- *
- * @return
- * A HTML table with the codes list.
+ * Render the site-wide signup status settings form.
*/
-function signup_status_admin_list() {
+function theme_signup_status_admin_settings_form($form) {
+ drupal_add_tabledrag('signup-status-admin-settings-table', 'order', 'self', 'signup-status-weight');
$header = array(
- t('Name'),
- t('Description'),
- t('Modifies signup count'),
- t('Show on form'),
- array('data' => t('Operations'), 'colspan' => 2),
+ array('data' => t('Name')),
+ array('data' => t('Weight')),
+ array('data' => t('Description')),
+ array('data' => t('Modifies signup count')),
+ array('data' => t('Show on form')),
+ array('data' => t('Operations'))
);
-
- $rows = array();
- foreach (signup_status_codes() as $cid => $code) {
+ foreach (element_children($form['status']) as $key) {
$rows[] = array(
- $code['name'],
- $code['description'],
- empty($code['mod_signup_count']) ? t('No') : t('Yes'),
- empty($code['show_on_form']) ? t('No') : t('Yes'),
- l(t('edit'), 'admin/settings/signup_status/edit/'. $cid),
- l(t('delete'), 'admin/settings/signup_status/delete/'. $cid),
+ 'class' => 'draggable',
+ 'data' => array(
+ drupal_render($form['status'][$key]['name']),
+ drupal_render($form['status'][$key]['weight']),
+ drupal_render($form['status'][$key]['description']),
+ drupal_render($form['status'][$key]['mod_signup_count']),
+ drupal_render($form['status'][$key]['show_on_form']),
+ drupal_render($form['status'][$key]['delete']),
+ ),
);
}
-
- return theme('table', $header, $rows);
+ $rows[] = array(
+ 'class' => 'draggable',
+ 'data' => array(
+ drupal_render($form['status_add']['name']),
+ drupal_render($form['status_add']['weight']),
+ drupal_render($form['status_add']['description']),
+ drupal_render($form['status_add']['mod_signup_count']),
+ drupal_render($form['status_add']['show_on_form']),
+ NULL,
+ ),
+ );
+ $output = '
' . theme('table', $header, $rows, array('id' => 'signup-status-admin-settings-table')) . '
';
+ $output .= drupal_render($form);
+ return $output;
}
/**
- * Implements the signups status code edit page.
+ * Build the form for the site-wide signup_status settings table.
*
* @param $form_state
* A form state array.
- * @param $op
- * An operatin - add or edit.
- * @param $cid
- * A signup status code ID.
*
* @return
- * The form structure.
+ * The form structured array.
*/
-function signup_status_admin_form(&$form_state, $op = NULL, $cid = NULL) {
- if (isset($cid)) {
- $form['cid'] = array(
- '#type' => 'hidden',
- '#value' => $cid,
- );
- }
+function signup_status_admin_settings_form(&$form_state) {
+ $signup_status_codes = signup_status_codes();
- $codes = signup_status_codes();
- $form['name'] = array(
+ // Form elements for existing status codes.
+ $form['status']['#tree'] = TRUE;
+ if (!empty($signup_status_codes)) {
+ foreach ($signup_status_codes as $cid => $status) {
+ $form['status'][$cid]['name'] = array(
+ '#type' => 'textfield',
+ '#default_value' => $status['name'],
+ '#maxlength' => 128,
+ '#size' => 20,
+ '#required' => TRUE,
+ );
+ $form['status'][$cid]['weight'] = array(
+ '#type' => 'weight',
+ '#default_value' => $status['weight'],
+ '#delta' => 15,
+ '#attributes' => array('class' => 'signup-status-weight'),
+ );
+ $form['status'][$cid]['description'] = array(
+ '#type' => 'textfield',
+ '#default_value' => $status['description'],
+ '#maxlength' => 128,
+ '#size' => 30,
+ );
+ $form['status'][$cid]['mod_signup_count'] = array(
+ '#type' => 'checkbox',
+ '#default_value' => $status['mod_signup_count'],
+ );
+ $form['status'][$cid]['show_on_form'] = array(
+ '#type' => 'checkbox',
+ '#default_value' => $status['show_on_form'],
+ );
+ $form['status'][$cid]['delete'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('delete'), 'admin/settings/signup_status/delete/'. $cid),
+ );
+ }
+ }
+
+ // Form elements for adding a new status.
+ $form['status_add']['#tree'] = TRUE;
+ $form['status_add']['name'] = array(
'#type' => 'textfield',
- '#title' => t('Name'),
- '#default_value' => isset($cid) ? $codes[$cid]['name'] : NULL,
+ '#size' => 20,
'#maxlength' => 128,
- '#required' => TRUE,
);
- $form['description'] = array(
- '#type' => 'textarea',
- '#title' => t('Description'),
- '#default_value' => isset($cid) ? $codes[$cid]['description'] : NULL,
+ $form['status_add']['weight'] = array(
+ '#type' => 'weight',
+ '#default_value' => 0,
+ '#delta' => 15,
+ '#attributes' => array('class' => 'signup-status-weight'),
);
- $form['mod_signup_count'] = array(
+ $form['status_add']['description'] = array(
+ '#type' => 'textfield',
+ '#maxlength' => 128,
+ '#size' => 30,
+ );
+ $form['status_add']['mod_signup_count'] = array(
'#type' => 'checkbox',
- '#title' => t('Modify the total signup count'),
- '#description' => t('If selected, users signed up with this status code will be considered in addition to the standards signup count, and node creators will be able to set limits for each status code accordingly.'),
- '#default_value' => isset($cid) ? $codes[$cid]['mod_signup_count'] : NULL,
);
- $form['show_on_form'] = array(
+ $form['status_add']['show_on_form'] = array(
'#type' => 'checkbox',
- '#title' => t('Show on the signup form'),
- '#description' => t('If selected, users can select this status when signing up for a node.'),
- '#default_value' => isset($cid) ? $codes[$cid]['show_on_form'] : NULL,
);
$form['submit'] = array(
@@ -91,42 +128,65 @@ function signup_status_admin_form(&$form
'#value' => t('Save configuration'),
);
- // Don't allow mod_signup_count to be changed on cid 0, 1
- if (in_array($cid, array(1, 2))) {
- $form['mod_signup_count']['#disabled'] = TRUE;
- }
-
return $form;
}
/**
- * Validate hook for the signup status code form.
+ * Validation callback for the signup status code settings form.
*/
-function signup_status_admin_form_validate($form, &$form_state) {
+function signup_status_admin_settings_form_validate($form, &$form_state) {
$values = $form_state['values'];
-
- $cid = isset($values['cid']) ? $values['cid'] : 0;
- if (db_fetch_object(db_query("SELECT name FROM {signup_status_codes} WHERE name = '%s' AND cid <> %d", $values['name'], $cid))) {
- form_set_error('name', t('A status code with the name %name already exists.', array('%name' => $values['name'])));
+ $names = array();
+ foreach ($values['status'] as $cid => $status) {
+ $name = $status['name'];
+ if (!empty($names[$name])) {
+ form_set_error('status][' . $cid . '][name', t('A status code with the name %name is already in use.', array('%name' => $name)));
+ }
+ else {
+ $names[$name] = $cid;
+ }
+ }
+ if (!empty($values['status_add']['name'])) {
+ $new_name = $values['status_add']['name'];
+ if (!empty($names[$new_name])) {
+ form_set_error('status_add][name', t('A status code with the name %name is already in use.', array('%name' => $new_name)));
+ }
+ }
+ else {
+ // Ensure that the name is defined if the user set anything else for the
+ // new status code row.
+ if (!empty($values['status_add']['description']) ||
+ !empty($values['status_add']['mod_signup_count']) ||
+ !empty($values['status_add']['show_on_form'])) {
+ form_set_error('status_add][name', t('A name is required for a new status.'));
+ }
}
}
/**
- * Submit hook for the signup status code form.
+ * Submit callback for the signup status code settings form.
*/
-function signup_status_admin_form_submit($form, &$form_state) {
+function signup_status_admin_settings_form_submit($form, &$form_state) {
$values = $form_state['values'];
- if (!isset($values['cid'])) {
- db_query("INSERT INTO {signup_status_codes} (name, description, mod_signup_count, show_on_form) VALUES ('%s', '%s', %d, %d)", $values['name'], $values['description'], $values['mod_signup_count'], $values['show_on_form']);
- drupal_set_message(t('Status code %name has been added.', array('%name' => $values['name'])));
- watchdog('signup_status', 'Status code %name has been added.', array('%name' => $values['name']));
- }
- else {
- db_query("UPDATE {signup_status_codes} SET name = '%s', description = '%s', mod_signup_count = %d, show_on_form = %d WHERE cid = %d", $values['name'], $values['description'], $values['mod_signup_count'], $values['show_on_form'], $values['cid']);
- drupal_set_message(t('Status code %name has been updated.', array('%name' => $values['name'])));
- watchdog('signup_status', 'Status code %name has been updated.', array('%name' => $values['name']));
+
+ if (!empty($values['status_add']['name'])) {
+ // Adding a new status.
+ drupal_write_record('signup_status_codes', $values['status_add']);
+ drupal_set_message(t('Status code %name has been added.', array('%name' => $values['status_add']['name'])));
+ watchdog('signup_status', 'Status code %name has been added.', array('%name' => $values['status_add']['name']));
+ }
+
+ // See if we modified any existing status codes.
+ $signup_status_codes = signup_status_codes();
+ foreach ($values['status'] as $cid => $status) {
+ $status['cid'] = $cid;
+ $diff = array_diff($status, $signup_status_codes[$cid]);
+ if (!empty($diff)) {
+ drupal_write_record('signup_status_codes', $status, 'cid');
+ drupal_set_message(t('Status code %name has been updated.', array('%name' => $status['name'])));
+ watchdog('signup_status', 'Status code %name has been updated.', array('%name' => $status['name']));
+ }
}
- $form_state['redirect'] = 'admin/settings/signup_status/list';
}
/**
@@ -144,11 +204,11 @@ function signup_status_admin_delete(&$fo
$codes = signup_status_codes();
if (array_key_exists($cid, $codes)) {
$form['cid'] = array(
- '#type' => 'hidden',
+ '#type' => 'value',
'#value' => $cid,
);
$form['name'] = array(
- '#type' => 'hidden',
+ '#type' => 'value',
'#value' => $codes[$cid]['name'],
);
return confirm_form(
Index: signup_status.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup_status/signup_status.install,v
retrieving revision 1.6
diff -u -p -r1.6 signup_status.install
--- signup_status.install 18 Sep 2009 23:38:23 -0000 1.6
+++ signup_status.install 19 Sep 2009 03:15:41 -0000
@@ -88,6 +88,12 @@ function signup_status_schema() {
'size' => 'tiny',
'description' => t('A flag showing if this signup status should be shown on the signup form.'),
),
+ 'weight' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => t('The weight of this signup status in the UI'),
+ ),
),
'primary key' => array('cid'),
'unique key' => array('name'),
@@ -107,3 +113,23 @@ function signup_status_schema_alter(&$sc
);
}
+//////////////////////////////////////////////////////////////////////////////
+// Schema update functions
+
+/**
+ * Add the {signup_status_codes}.weight column.
+ */
+function signup_status_update_6000() {
+ $ret = array();
+ $field = array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ );
+ db_add_field($ret, 'signup_status_codes', 'weight', $field);
+ // As an initial default, weight the status codes by the cid. This
+ // replicates the previous cronological order of status codes.
+ $ret[] = update_sql("UPDATE {signup_status_codes} SET weight = cid");
+ return $ret;
+}
+
Index: signup_status.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup_status/signup_status.module,v
retrieving revision 1.24
diff -u -p -r1.24 signup_status.module
--- signup_status.module 19 Sep 2009 01:47:56 -0000 1.24
+++ signup_status.module 19 Sep 2009 03:15:41 -0000
@@ -27,28 +27,8 @@ function signup_status_menu() {
$items['admin/settings/signup_status'] = array(
'title' => 'Signup status',
'description' => 'Configure signup status settings.',
- 'page callback' => 'signup_status_admin_list',
- 'access arguments' => array(SIGNUP_STATUS_MANAGE_PERMISSION),
- 'file' => 'signup_status.admin.inc',
- );
- $items['admin/settings/signup_status/list'] = array(
- 'title' => 'Status codes',
- 'type' => MENU_DEFAULT_LOCAL_TASK,
- );
- $items['admin/settings/signup_status/add'] = array(
- 'title' => 'Add status code',
'page callback' => 'drupal_get_form',
- 'page arguments' => array('signup_status_admin_form', 3),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 1,
- 'access arguments' => array(SIGNUP_STATUS_MANAGE_PERMISSION),
- 'file' => 'signup_status.admin.inc',
- );
- $items['admin/settings/signup_status/edit'] = array(
- 'title' => 'Configure status code',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('signup_status_admin_form', 3, 4),
- 'type' => MENU_CALLBACK,
+ 'page arguments' => array('signup_status_admin_settings_form', 4),
'access arguments' => array(SIGNUP_STATUS_MANAGE_PERMISSION),
'file' => 'signup_status.admin.inc',
);
@@ -76,6 +56,20 @@ function signup_status_action_info() {
);
}
+/**
+ * Implement hook_theme().
+ */
+function signup_status_theme() {
+ return array(
+ 'signup_status_admin_settings_form' => array(
+ 'file' => 'signup_status.admin.inc',
+ 'arguments' => array(
+ 'form' => NULL,
+ ),
+ ),
+ );
+}
+
//////////////////////////////////////////////////////////////////////////////
// Views integration
@@ -377,7 +371,7 @@ function signup_status_signup_broadcast_
function signup_status_codes() {
static $codes = array();
if (empty($codes)) {
- $result = db_query("SELECT * FROM {signup_status_codes}");
+ $result = db_query("SELECT * FROM {signup_status_codes} ORDER BY weight");
while ($row = db_fetch_array($result)) {
$codes[$row['cid']] = $row;
}