? .DS_Store ? actions_14.patch ? actions_help.patch ? block_dnd-add_drag_drop_to_blocks-181066-86.patch ? block_sane_help.patch ? book_ahahapi_4.patch ? comment_notice.patch ? draggable-menu-181126-16.patch ? drupal_drag_and_drop_12.patch ? drupal_drag_and_drop_14.patch ? files ? fix_garland_and_menu_theme.patch ? form_expand_ahah.patch ? install_profile_notice.patch ? jquery_upgrade.patch ? lower_13.patch ? lower_14.patch ? menu_drag_and_drop_0.patch ? poll-drag-drop.patch ? powered_by_drupal.patch ? powered_by_drupal_2.patch ? tracker-union-2.patch ? misc/draggable.png ? misc/tabledrag.js ? misc/tree-bottom.png ? misc/tree.png ? modules/.DS_Store ? modules/block/.DS_Store ? modules/block/block.js ? modules/menu/.DS_Store ? modules/tracker/.DS_Store ? modules/translation/.DS_Store ? profiles/.DS_Store ? profiles/single_user_blog ? sites/.DS_Store ? sites/views ? sites/all/.DS_Store ? sites/all/modules ? sites/all/themes ? sites/default/settings.php ? themes/.DS_Store ? themes/engines/.DS_Store ? themes/garland/.DS_Store Index: modules/poll/poll.module =================================================================== RCS file: /cvs/drupal/drupal/modules/poll/poll.module,v retrieving revision 1.249 diff -u -p -r1.249 poll.module --- modules/poll/poll.module 5 Nov 2007 16:28:25 -0000 1.249 +++ modules/poll/poll.module 17 Nov 2007 17:44:25 -0000 @@ -225,8 +225,9 @@ function poll_form(&$node, $form_state) for ($delta = 0; $delta < $choice_count; $delta++) { $text = isset($node->choice[$delta]['chtext']) ? $node->choice[$delta]['chtext'] : ''; $votes = isset($node->choice[$delta]['chvotes']) ? $node->choice[$delta]['chvotes'] : 0; + $order = isset($node->choice[$delta]['chorder']) ? $node->choice[$delta]['chorder'] : $delta; - $form['choice_wrapper']['choice'][$delta] = _poll_choice_form($delta, $text, $votes); + $form['choice_wrapper']['choice'][$delta] = _poll_choice_form($delta, $text, $votes, $order); } // We name our button 'poll_more' to avoid conflicts with other modules using @@ -246,30 +247,30 @@ function poll_form(&$node, $form_state) ); // Poll attributes - $_duration = array(0 => t('Unlimited')) + drupal_map_assoc(array(86400, 172800, 345600, 604800, 1209600, 2419200, 4838400, 9676800, 31536000), "format_interval"); - $_active = array(0 => t('Closed'), 1 => t('Active')); + $duration = array(0 => t('Unlimited')) + drupal_map_assoc(array(86400, 172800, 345600, 604800, 1209600, 2419200, 4838400, 9676800, 31536000), "format_interval"); + $active = array(0 => t('Closed'), 1 => t('Active')); - if ($admin) { - $form['settings'] = array( - '#type' => 'fieldset', - '#collapsible' => TRUE, - '#title' => t('Poll settings'), - '#weight' => -3, - ); + $form['settings'] = array( + '#type' => 'fieldset', + '#collapsible' => TRUE, + '#title' => t('Poll settings'), + '#weight' => -3, + '#access' => $admin, + ); - $form['settings']['active'] = array( - '#type' => 'radios', - '#title' => t('Poll status'), - '#default_value' => isset($node->active) ? $node->active : 1, - '#options' => $_active, - '#description' => t('When a poll is closed, visitors can no longer vote for it.') - ); - } + $form['settings']['active'] = array( + '#type' => 'radios', + '#title' => t('Poll status'), + '#default_value' => isset($node->active) ? $node->active : 1, + '#options' => $active, + '#description' => t('When a poll is closed, visitors can no longer vote for it.'), + '#access' => $admin, + ); $form['settings']['runtime'] = array( '#type' => 'select', '#title' => t('Poll duration'), '#default_value' => isset($node->runtime) ? $node->runtime : 0, - '#options' => $_duration, + '#options' => $duration, '#description' => t('After this period, the poll will be closed automatically.'), ); @@ -291,9 +292,7 @@ function poll_more_choices_submit($form, } } -function _poll_choice_form($delta, $value = '', $votes = 0) { - $admin = user_access('administer nodes'); - +function _poll_choice_form($delta, $value = '', $votes = 0, $order = 0) { $form = array( '#tree' => TRUE, ); @@ -304,19 +303,25 @@ function _poll_choice_form($delta, $valu '#type' => 'textfield', '#title' => t('Choice @n', array('@n' => ($delta + 1))), '#default_value' => $value, - '#parents' => array('choice', $delta,'chtext'), + '#parents' => array('choice', $delta, 'chtext'), ); - if ($admin) { - $form['chvotes'] = array( - '#type' => 'textfield', - '#title' => t('Votes for choice @n', array('@n' => ($delta + 1))), - '#default_value' => $votes, - '#size' => 5, - '#maxlength' => 7, - '#parents' => array('choice', $delta, 'chvotes'), - ); - } + $form['chvotes'] = array( + '#type' => 'textfield', + '#title' => t('Votes for choice @n', array('@n' => ($delta + 1))), + '#default_value' => $votes, + '#size' => 5, + '#maxlength' => 7, + '#parents' => array('choice', $delta, 'chvotes'), + '#access' => user_access('administer nodes'), + ); + + $form['chorder'] = array( + '#type' => 'weight', + '#title' => t('Weight for choice @n', array('@n' => ($delta + 1))), + '#default_value' => $order, + '#parents' => array('choice', $delta, 'chorder'), + ); return $form; } @@ -325,18 +330,10 @@ function _poll_choice_form($delta, $valu * Menu callback for AHAH additions. */ function poll_choice_js() { - $delta = count($_POST['choice']); - - // Build our new form element. - $form_element = _poll_choice_form($delta); - drupal_alter('form', $form_element, array(), 'poll_choice_js'); - // Add the new element to the stored form state. Without adding the element // to the form, Drupal is not aware of this new elements existence and will // not process it. We retreive the cached form, add the element, and resave. $cache = cache_get('form_'. $_POST['form_build_id'], 'cache_form'); - $cache->data['choice_wrapper']['choice'][$delta] = $form_element; - cache_set('form_'. $_POST['form_build_id'], $cache->data, 'cache_form', $cache->expire); // Build the new form. $form_state = array('submitted' => FALSE); @@ -345,13 +342,31 @@ function poll_choice_js() { '#post' => $_POST, '#programmed' => FALSE, ); + + $delta = count(element_children($form['choice_wrapper']['choice'])); + + // Find the greatest weight and add 1. + $greatest = -11; + foreach ($_POST['choice'] as $choice) { + if ($choice['chorder'] > $greatest) { + $greatest = $choice['chorder']; + } + } + + // Build our new form element. + $form_element = _poll_choice_form($delta, '', '0', ++$greatest); + drupal_alter('form', $form_element, array(), 'poll_choice_js'); + + $form['choice_wrapper']['choice'][$delta] = $form_element; + $form = form_builder('poll_node_form', $form, $form_state); + cache_set('form_'. $_POST['form_build_id'], $form, 'cache_form', $cache->expire); // Render the new output. $choice_form = $form['choice_wrapper']['choice']; - unset($choice_form['#prefix'], $choice_form['#suffix']); // Prevent duplicate wrappers. + // Prevent duplicate wrappers. + unset($choice_form['#prefix'], $choice_form['#suffix']); $choice_form[$delta]['#attributes']['class'] = empty($choice_form[$delta]['#attributes']['class']) ? 'ahah-new-content' : $choice_form[$delta]['#attributes']['class'] .' ahah-new-content'; - $choice_form[$delta]['chvotes']['#value'] = 0; $output = theme('status_messages') . drupal_render($choice_form); drupal_json(array('status' => TRUE, 'data' => $output)); @@ -438,10 +453,9 @@ function poll_insert($node) { db_query("INSERT INTO {poll} (nid, runtime, active) VALUES (%d, %d, %d)", $node->nid, $node->runtime, $node->active); - $i = 0; foreach ($node->choice as $choice) { if ($choice['chtext'] != '') { - db_query("INSERT INTO {poll_choices} (nid, chtext, chvotes, chorder) VALUES (%d, '%s', %d, %d)", $node->nid, $choice['chtext'], $choice['chvotes'], $i++); + db_query("INSERT INTO {poll_choices} (nid, chtext, chvotes, chorder) VALUES (%d, '%s', %d, %d)", $node->nid, $choice['chtext'], $choice['chvotes'], $choice['chorder']); } } } @@ -631,30 +645,33 @@ function poll_view_results(&$node, $teas return theme('poll_results', $node->title, $poll_results, $total_votes, isset($node->links) ? $node->links : array(), $block, $node->nid, isset($node->vote) ? $node->vote : NULL); } - /** * Theme the admin poll form for choices. */ function theme_poll_choices($form) { // Change the button title to reflect the behavior when using JavaScript. drupal_add_js('if (Drupal.jsEnabled) { $(document).ready(function() { $("#edit-poll-more").val("'. t('Add another choice') .'"); }); }', 'inline'); - + drupal_add_tabledrag('poll-choice-table', 'sort', 'sibiling', 'poll-chorder input'); + $rows = array(); $headers = array( t('Choice'), t('Vote count'), + t('Weight'), ); foreach (element_children($form) as $key) { // No need to print the field title every time. - unset($form[$key]['chtext']['#title'], $form[$key]['chvotes']['#title']); + unset($form[$key]['chtext']['#title'], $form[$key]['chvotes']['#title'], $form[$key]['chorder']['#title']); // Build the table row. $row = array( 'data' => array( array('data' => drupal_render($form[$key]['chtext']), 'class' => 'poll-chtext'), array('data' => drupal_render($form[$key]['chvotes']), 'class' => 'poll-chvotes'), + array('data' => drupal_render($form[$key]['chorder']), 'class' => 'poll-chorder'), ), + 'class' => 'draggable ', ); // Add additional attributes to the row, such as a class for this row. @@ -664,7 +681,7 @@ function theme_poll_choices($form) { $rows[] = $row; } - $output = theme('table', $headers, $rows); + $output = theme('table', $headers, $rows, array('id' => 'poll-choice-table')); $output .= drupal_render($form); return $output; }