diff -u includes/admin.batch_confirm.inc includes/admin.batch_confirm.inc --- includes/admin.batch_confirm.inc +++ includes/admin.batch_confirm.inc 24 Apr 2010 01:56:21 -0000 @@ -11,7 +11,7 @@ * * This function will find the range of all rows in the {project_issues} table * and run a query against that table incerementally, 100 rows at a time. This - * function is intended to be used iwth batch_set(). + * function is intended to be used with batch_set(). * * @param $sql * A SQL query intended to be run for each row in the {project_issues} table. @@ -23,13 +23,13 @@ * range with BETWEEN. * @param $context * An array containing information about batch progress. $context['sandbox'] - * contains the following keys which will be populated after this function has - * been called: + * contains the following keys which will be populated after this function + * has been called: * 'min' The minimum value, or starting point. * 'max' The maximum value, or end point. * 'current' The nid of the last row that has been updated. - * 'finished' Will contain a percentage of total rows processed, and will be - * set to 1 when all rows have been processed. + * 'finished' Will contain a percentage of total rows processed, and will + * be set to 1 when all rows have been processed. */ function _project_issue_batch_update($sql, $base_arguments, &$context = array()) { $last_nid = 0; diff -u includes/admin.issue_priority.inc includes/admin.issue_priority.inc --- includes/admin.issue_priority.inc +++ includes/admin.issue_priority.inc 24 Apr 2010 01:56:21 -0000 @@ -6,46 +6,9 @@ * Code for the issue priorities admin configuration form. */ -function project_issue_delete_priority_confirm(&$form_state, $priority_id) { - // Helper functions are in issue.inc - require_once drupal_get_path('module', 'project_issue') .'/issue.inc'; - $schema = drupal_get_schema('project_issues'); - if (!function_exists('project_issue_priority') || !isset($schema['fields']['priority']) || !db_table_exists('project_issue_priority')) { - drupal_access_denied(); - return; - } - $priorities = project_issue_priorities(); - $name = $priorities[$priority_id]; - unset($priorities[$priority_id]); - - // $column is verified to exist - $total = db_result(db_query("SELECT COUNT(nid) AS total FROM {project_issues} WHERE priority = %d", $priority_id)); - if ($total > 0) { - $form['new_pid'] = array( - '#type' => 'select', - '#title' => t('Reassign priority'), - '#default_value' => $priority_id, - '#options' => $priorities, - '#description' => format_plural($total, 'There is 1 existing issue assigned @name priority. Please select a new priority for this issue.', 'There are @count existing issues assigned @name priority. Please select a new priority for these issues.', array('@name' => $name)), - ); - } - $form['pid'] = array( - '#type' => 'value', - '#value' => $priority_id, - ); - $form['name'] = array( - '#type' => 'hidden', - '#value' => $name, - ); - return confirm_form( - $form, - t('Are you sure you want to delete the priority %name?', array('%name' => $name)), - 'admin/project/project-issue-priority', - t('This action cannot be undone.'), - t('Delete'), t('Cancel') - ); -} - +/** + * Build the form for project_issue_admin_priority_form. + */ function project_issue_admin_priority_form(&$form_state) { $result = db_query('SELECT priority, name, weight FROM {project_issue_priority} ORDER BY weight'); $max = 15; @@ -77,7 +40,9 @@ ); $form['priority'][0]['weight'] = array( '#type' => 'weight', - '#default_value' => $max + 1, // Make sure that the new item has a weight higher than highest priority since new item appears at bottom of form by default.. + // Make sure that the new item has a weight higher than highest priority + // since new item appears at bottom of the form by default. + '#default_value' => $max + 1, '#delta' => $max + 1, '#attributes' => array('class' => 'project-issue-priority-weight'), ); @@ -92,6 +57,34 @@ } /** + * Render the HTML for the admin issue priority form. + * + * @see project_issue_admin_priority_form() + * @see drupal_add_tabledrag() + */ +function theme_project_issue_admin_priority_form($form) { + drupal_add_tabledrag('project-issue-admin-priority-table', 'order', 'self', 'project-issue-priority-weight'); + $header = array( + t('Priority'), + t('Weight'), + t('Operations'), + ); + foreach (element_children($form['priority']) as $key) { + $rows[] = array( + 'class' => 'draggable', + 'data' => array( + drupal_render($form['priority'][$key]['name']), + drupal_render($form['priority'][$key]['weight']), + drupal_render($form['delete'][$key]), + ), + ); + } + $output = '
' . theme('table', $header, $rows, array('id' => 'project-issue-admin-priority-table')) . '
'; + $output .= drupal_render($form); + return $output; +} + +/** * Submit handler for project_issue_admin_states_form. */ function project_issue_admin_priority_form_submit($form, &$form_state) { @@ -155,6 +148,59 @@ } } +/** + * Build a confirmation form when deleting an issue priority. + * + * This allows the admin to re-prioritize any issues with the priority being + * deleted using admin.batch_confirm.inc. + * + * @param $form_state + * The state of the form we're trying to build. + * @param $priority_id + * The {project_issue_priority}.priority ID being deleted. + */ +function project_issue_delete_priority_confirm(&$form_state, $priority_id) { + // Helper functions are in issue.inc. + require_once drupal_get_path('module', 'project_issue') .'/issue.inc'; + $schema = drupal_get_schema('project_issues'); + if (!function_exists('project_issue_priority') || !isset($schema['fields']['priority']) || !db_table_exists('project_issue_priority')) { + return drupal_access_denied(); + } + $priorities = project_issue_priorities(); + $name = $priorities[$priority_id]; + unset($priorities[$priority_id]); + + // $column is verified to exist. + $total = db_result(db_query("SELECT COUNT(nid) AS total FROM {project_issues} WHERE priority = %d", $priority_id)); + if ($total > 0) { + $form['new_pid'] = array( + '#type' => 'select', + '#title' => t('Reassign priority'), + '#default_value' => $priority_id, + '#options' => $priorities, + '#description' => format_plural($total, 'There is 1 existing issue assigned @name priority. Please select a new priority for this issue.', 'There are @count existing issues assigned @name priority. Please select a new priority for these issues.', array('@name' => $name)), + ); + } + $form['pid'] = array( + '#type' => 'value', + '#value' => $priority_id, + ); + $form['name'] = array( + '#type' => 'hidden', + '#value' => $name, + ); + return confirm_form( + $form, + t('Are you sure you want to delete the priority %name?', array('%name' => $name)), + 'admin/project/project-issue-priority', + t('This action cannot be undone.'), + t('Delete'), t('Cancel') + ); +} + +/** + * Submit handler for confirm form when deleting an issue priority. + */ function project_issue_delete_priority_confirm_submit($form, &$form_state) { db_query('DELETE FROM {project_issue_priority} WHERE priority = %d', $form_state['values']['pid']); $form_state['redirect'] = 'admin/project/project-issue-priority'; @@ -182,22 +227,0 @@ - -function theme_project_issue_admin_priority_form($form) { - drupal_add_tabledrag('project-issue-admin-priority-table', 'order', 'self', 'project-issue-priority-weight'); - $header = array( - t('Priority'), - t('Weight'), - t('Operations'), - ); - foreach (element_children($form['priority']) as $key) { - $rows[] = array( - 'class' => 'draggable', - 'data' => array( - drupal_render($form['priority'][$key]['name']), - drupal_render($form['priority'][$key]['weight']), - drupal_render($form['delete'][$key]), - ), - ); - } - $output = '
' . theme('table', $header, $rows, array('id' => 'project-issue-admin-priority-table')) . '
'; - $output .= drupal_render($form); - return $output; -} diff -u includes/admin.issue_status.inc includes/admin.issue_status.inc --- includes/admin.issue_status.inc +++ includes/admin.issue_status.inc 24 Apr 2010 01:56:21 -0000 @@ -156,7 +156,7 @@ '#title' => t('Reassign status'), '#default_value' => $sid, '#options' => $states, - '#description' => format_plural($total, 'There is 1 existing issue assigned to @name status. Please select a new status for this issue.', 'There are @count existing issues assigned to @name status. Please select a new status for these issues.', array('@name' => $name)), + '#description' => t('There are !total existing issues with the status of @name. Please select a new status for these issues.', array('!total' => $total, '@name' => $name)), ); } $form['sid'] = array( diff -u project_issue.install project_issue.install --- project_issue.install +++ project_issue.install 24 Apr 2010 01:56:20 -0000 @@ -522,7 +522,7 @@ } /** - * Update project_issues, with denormalized priority weight. + * Update {project_issues} with denormalized priority weight. */ function project_issue_update_6004(&$sandbox) { $ret = array(); @@ -531,7 +531,7 @@ // Load the include. require_once drupal_get_path('module', 'project_issue') .'/includes/admin.batch_confirm.inc'; // Call the batch upgrade which will set its variables in the sandbox. - _project_issue_batch_update('UPDATE project_issues SET priority_weight = priority WHERE nid BETWEEN %d AND %d', array(), $context); + _project_issue_batch_update('UPDATE {project_issues} SET priority_weight = priority WHERE nid BETWEEN %d AND %d', array(), $context); // Pass back progress. $ret['#finished'] = $context['finished']; return $ret; diff -u project_issue.module project_issue.module --- project_issue.module +++ project_issue.module 24 Apr 2010 01:56:21 -0000 @@ -101,7 +101,7 @@ // Administrative pages $items['admin/project/project-issue-priority'] = array( - 'title' => 'Project issue priorities', + 'title' => 'Project issue priority options', 'description' => 'Configure what issue priorities should be used on your site.', 'page callback' => 'drupal_get_form', 'page arguments' => array('project_issue_admin_priority_form'),