Only in decisions: LICENSE.txt
diff -r decisions/decisions.info decisions/decisions.info
7,13d6
< 
< ; Information added by drupal.org packaging script on 2010-04-28
< version = "6.x-1.7"
< core = "6.x"
< project = "decisions"
< datestamp = "1272432004"
< 
diff -r decisions/decisions.module decisions/decisions.module
15c15
< // $Id: decisions.module,v 1.252 2010/04/28 05:07:29 anarcat Exp $
---
> // $Id: decisions.module,v 1.255 2010/06/01 15:14:35 ezrag Exp $
881,882c881
<   // compute number of people that have cast their vote
<   $num_voters = _decisions_count_voters($node);
---
>   $num_voters = 0;
883a883,888
>   // If the minimum required number of voters is 0,
>   // no reason to find out how many have voted. 
>   if (!empty($quorum)) {
>     // compute number of people that have cast their vote
>     $num_voters = _decisions_count_voters($node);
>   }
937a943,945
>   if (empty($node->quorum_abs) && empty($node->quorum_percent)) {
>     return 0;
>   }
982c990
<   if(!user_access('vote on decisions')) {
---
>   if (!user_access('vote on decisions')) {
1411c1419
<   if (arg(2) != 'results' && _decisions_can_vote($node)) {
---
>   if (arg(2) != 'decision-results' && _decisions_can_vote($node)) {
1839a1848,1860
> 
> /*
>  * Implementation of hook_votingapi_relationships().
>  */
> function decisions_votingapi_relationships() {
>   $relationships[] = array(
>     'description' => t('Decisions'),
>     'content_type' => 'decisions',
>     'base_table' => 'node',
>     'content_id_column' => 'nid',
>   );
>   return $relationships;
> }
\ No newline at end of file
diff -r decisions/modes/ranking.info decisions/modes/ranking.info
8,14d7
< 
< ; Information added by drupal.org packaging script on 2010-04-28
< version = "6.x-1.7"
< core = "6.x"
< project = "decisions"
< datestamp = "1272432004"
< 
diff -r decisions/modes/selection.css decisions/modes/selection.css
2,4c2,5
< .decisions_selection_1click {
<   text-align: center;
<   font-weight: bold;
---
> form.decisions-selection-voting-form {
>   position: relative;
>   top: 0px;
>   left: 0px;
7,11c8
< a.decisions_selection_vote {
<   margin: 0px 8px 0px 8px
< }
< 
< .decisions_selection_voting span.error{
---
> form.decisions-selection-voting-form .decisions_selection_error span.error {
14d10
< 
15a12,20
> 
> form.decisions-selection-voting-form .decisions_spinner {
>   position: absolute;
>   top: 0px;
>   left: 0px;
>   width: 100%;
>   background: #EEF3F7 url('../modes/spinner.gif') no-repeat center 50%;
>   min-height: 100px;
> }
\ No newline at end of file
diff -r decisions/modes/selection.info decisions/modes/selection.info
8,14d7
< 
< ; Information added by drupal.org packaging script on 2010-04-28
< version = "6.x-1.7"
< core = "6.x"
< project = "decisions"
< datestamp = "1272432004"
< 
diff -r decisions/modes/selection.js decisions/modes/selection.js
1,27c1,27
< $(document).ready(function(){  
<   $("a.decisions_selection_vote").click(function() {
<     var link = this;
<     var path = $(this).attr('href');
<     var votingDiv = $(link).parents("div.decisions_selection_voting");
<     var resultsDiv =  $(link).parents(".decisions_selection_voting").siblings(".decisions_selection_results");
<     $.ajax({
<       type: "GET",
<       global: false,
<       data: 'ajax=true',
<       dataType: 'string',
<       url: path,
<       beforeSend:function() {
<         $(votingDiv).queue(function() {
<           $(votingDiv).fadeOut('slow').dequeue();
<         });
<       },
<       success: function(response) {
<         $(resultsDiv).html(response);
<         //If the page is a WSOD with an HTTP 200 response, that's not successful. This check could be expanded if necessary.
<         if (response == '') {
<           decisionsErrorText(votingDiv);
<         }
<         else {
<           $(votingDiv).queue(function(){
<             resultsDiv.fadeIn('slow');
<             $(votingDiv).dequeue();
---
> Drupal.behaviors.decisionsSelection1Click = function(context) {
>   var options = Drupal.settings.decisionsSelection;
>   $(context).find('form.decisions-selection-voting-form').each(function() {
>     var form = $(this);
>     
>     form.find('input[type=submit]').click(function() {
>       var data = form.serialize() + '&op=' + $(this).val();
> 
>       $.ajax({
>         type: 'POST',
>         global: false,
>         data: data,
>         dataType: 'json',
>         url: options.path,
>         beforeSend:function() {
>           // If we don't have a spinner, create it.
>           if (form.find('.decisions_spinner').length == 0) {
>             form.append($('<div class="decisions_spinner"></div>').hide());
>           }
> 
>           // Show the spinner; hide the form contents.
>           form.queue(function() {
>             // Lock the form height.
>             form.css('height', form.height());
>             form.find('.decisions_spinner').show();
>             $('> div:not(.decisions_spinner)', form).fadeOut('slow');
>             form.dequeue();
28a29,53
>         },
>         success: function(response) {
>           // Hide the spinner.
>           form.find('.decisions_spinner').hide();
> 
>           if (response.status == false) {
>             // Display the error, and reveal the form content.
>             decisionsErrorText(form, response.data);
>           }
>           else {
>             var results_div = $('<div class="decisions_selection_results"></div>')
>               .html(response.data)
>               .hide();
> 
>             form.append(results_div);
>             form.queue(function(){
>               results_div.fadeIn('slow');
>               form.css('height', 'auto'); // Unlock height.
>               form.dequeue();
>             });
>           }
>         },
>         error: function() {
>           form.find('.decisions_spinner').hide();
>           decisionsErrorText(form);
30,33c55,57
<       },
<       error: function() {
<         decisionsErrorText(votingDiv);
<       }
---
>       });
> 
>       return false;
35d58
<     return false;
37,41c60,76
<   function decisionsErrorText(votingDiv) {
<     $(votingDiv).queue(function(){
<       $(votingDiv).children(".decisions_selection_error").html('<span class="error">' + Drupal.t('An error occured. Please try voting again.') + '</span>');
<       votingDiv.fadeIn('slow');
<       $(votingDiv).dequeue();
---
> 
>   function decisionsErrorText(form, error_msg) {
>     if (form.find('.decisions_selection_error').length == 0) {
>       form.prepend($('<div class="decisions_selection_error"></div>').hide());
>     }
> 
>     if (!error_msg) {
>       error_msg = 'An error occured. Please try voting again.';
>     }
> 
>     form.find('.decisions_selection_error').html('<span class="error">' + Drupal.t(error_msg) + '</span>');
> 
>     // $.queue() is to make sure only one thing is happening at the same time.
>     form.queue(function() {
>       $('> div:not(.decisions_spinner)', form).fadeIn('slow');
>       form.css('height', 'auto'); // Unlock height
>       form.dequeue();
44c79
< });
\ No newline at end of file
---
> };
\ No newline at end of file
diff -r decisions/modes/selection.module decisions/modes/selection.module
2c2
< // $Id: selection.module,v 1.31 2010/04/12 17:57:22 ezrag Exp $
---
> // $Id: selection.module,v 1.35 2010/07/02 05:38:36 ezrag Exp $
29c29
<       'arguments' => array('node' => NULL, 'teaser' => FALSE, 'page' => FALSE, 'this_vote' => array()),
---
>       'arguments' => array('node' => NULL, 'teaser' => FALSE, 'page' => FALSE),
32a33
> 
63,64d63
<  * @param $cid
<  * The choice ID used in the vote.
68c67
< function selection_vote($node, $cid) {
---
> function selection_vote($node) {
70,117c69,79
<   $new_vote = array();
<   if (selection_check_token($_REQUEST['token'], $node->nid, $cid)) {
<     $valid_cid = !empty($node->choice[$cid]['label']);
<     if (empty($valid_cid)) {
<       if (empty($_REQUEST['ajax'])) {
<         drupal_goto(drupal_get_destination());
<       }
<       else {
<         exit();
<       }
<     }
<     if (empty($voted)) {
<       $new_vote = array(
<         'value' => 1,
<         'tag' => $cid,
<         'value_type' => 'option',
<         'content_type' => 'decisions',
<         'content_id' => $node->nid,
<       );
<       $votes[] = $new_vote;
<       votingapi_add_votes($votes);
<       votingapi_recalculate_results('decisions', $node->nid);
<     }
<     else {
<       if (empty($_REQUEST['ajax'])) {
<         drupal_set_message(t("You have already voted."));
<         drupal_goto(drupal_get_destination());
<       }
<       else {
<         exit();
<       }
<     }
<     // Render the results
<     if (empty($_REQUEST['ajax'])) {
<       // Vote confirmation is displayed in the results so that the degradable behavior matches the AHAH behavior.
<       drupal_goto(drupal_get_destination());
<     }
<     else {
<       // We pass along the vote cast in this request so that the user's choice
<       // can be displayed along with the results.
<       print theme('selection_decisions_view_results', $node, FALSE, FALSE, $new_vote);
<       exit();
<     }
<   }
<   // Invalid token.
<   if (empty($_REQUEST['ajax'])) {
<     drupal_set_message(t("Invalid token. Please try voting again."));
<     drupal_goto(drupal_get_destination());
---
> 
>   $form_state = array();
>   $form_state['values'] = $_POST;
>   drupal_execute('decisions_selection_voting_form', $form_state, $node);
> 
>   $data = new stdClass();
>   
>   $msgs = drupal_get_messages();
>   if (isset($msgs['error']) && count($msgs['error']) > 0) {
>     $data->status = FALSE;
>     $data->data = implode('<br />', $msgs['error']);
120c82,86
<     exit();
---
>     // Update node with user's vote;
>     $node->vote = decisions_get_vote($node->nid, $user->uid);
> 
>     $data->status = TRUE;
>     $data->data = theme('selection_decisions_view_results', $node);
122d87
< }
124,131c89,91
< /*
<  * Generates a token for use with AJAX voting.
<  */
< function selection_get_token($nid = 0, $cid = 0) {
<   global $user;
<   $session_id = isset($user->uid) && $user->uid > 0 ? session_id() : '';
<   $private_key = drupal_get_private_key();
<   return md5($session_id . "selection-vote-$nid-$cid" . $private_key);
---
>   drupal_json($data);
>   // We never want to cache this, so let's just exit here.
>   exit(0);
134,228c94,95
< /*
<  * Checks a token for use with AJAX voting.
<  */
< function selection_check_token($token, $nid = 0, $cid = 0) {
<   return selection_get_token($nid, $cid) == $token;
< }
< 
< /**
<  * Implementation of decisions_hook_voting_form.
<  * Presents a list of choices for the user to vote on.
<  */
< function decisions_selection_voting_form($form_state, $node, $teaser, $page) {
<   $one_click = variable_get('decisions_1click', 0);
<   global $user;
<   $form['node'] = array(
<     '#type' => 'value',
<     '#value' => $node,
<   );
<   $form['#prefix'] = '<div class="decisions_selection_voting"><div class="decisions_selection_error"></div>';
<   //The decisions_selection_results div exists as a workaround for 1click voting when jQuery 1.3+'s live() is unavailable.
<   $form['#suffix'] = '</div><div class="decisions_selection_results" style="display: none;"></div>';
< 
<   if ($node->choice) {
<     $list = array();
<     // Put options in random order if randomize option
<     // selected on node create/edit form.
<     if ($node->randomize) {
<       $node->choice = _decisions_randomize_options($node->choice, $node->choices);
<     }
<     //Single choice, "Plurality" voting.
<     if ($node->maxchoices == 1) {
<       //Are we using the 1-click form?
<       if ($one_click == 1) {
<         drupal_add_css(drupal_get_path('module', 'selection') . '/selection.css', 'module');
<         $links = '';
< 
<         foreach ($node->choice as $i => $choice) {
<           $links[$i]['attributes']['class'] = 'decisions_selection_vote';
<           $links[$i]['query'] = drupal_get_destination() . '&token='. selection_get_token($node->nid, $i);
<           $links[$i]['title'] = check_plain($choice['label']);
<           $links[$i]['href'] = "decisions_selection/vote/$node->nid/$i/";
<         }
<         
<         if (!empty($links)) {
<           $output = '';
<           $output .= '<div class="decisions_selection_1click">';
<           $output .= theme('links', $links, array('class' => 'decisions_selection_1click'));
<           $output .= '</div>';
<         }
<         $form['choices']['1click'] = array(
<           '#value' => $output,
<         );
< 
<         //If asynchronous voting is enabled, add the necessary JS.
<         if (variable_get('decisions_ahah', 0) == 1) {
<           drupal_add_js(drupal_get_path('module', 'selection') . '/selection.js');
<         }
<         //At this point, we can return the form since 1-click uses its own callback for vote submission.
<         return $form;
<       }
<       //Not using 1-click. Use radios.
<       else {
<         foreach ($node->choice as $i => $choice) {
<           if ($choice['label']) {
<             $list[$i] = check_plain($choice['label']);
<           }
<         }
<       }
<       $form['choice'] = array(
<         '#type' => 'radios',
<         '#title' => $page ? '' : check_plain($node->title),
<         '#default_value' => -1,
<         '#options' => $list,
<       );
<     }
<     //Approval/multiple-choice voting.
<     else {
<       foreach ($node->choice as $i => $choice) {
<         if ($choice['label']) {
<           $list[$i] = check_plain($choice['label']);
<         }
<       }
<       $form['choice'] = array(
<         '#type' => 'checkboxes',
<         '#title' => $page ? '' : check_plain($node->title),
<         '#options' => $list,
<       );
<     }
<   }
<   //Add the submit button. 1click has already returned the form by this point.
<   $form['vote'] = array(
<     '#type' => 'submit',
<     '#value' => t('Vote'),
<   );
<   return $form;
---
> function theme_selection_decisions_view_results($node = NULL, $teaser = FALSE, $page = FALSE) {
>   return selection_decisions_view_results($node, $teaser, $page);
235,237c102,108
< function selection_decisions_view_results($node, $teaser, $page, $new_vote = array()) {
<   global $user;
<   $vote = !empty($new_vote) ? $new_vote : $node->vote;
---
> function selection_decisions_view_results($node, $teaser, $page) {
>   if (!isset($node) || $node->nid == 0) {
>     return '';
>   }
> 
>   $current_vote = $node->vote;
>   
242a114
>   // Gather votes.
244d115
< 
252c123
<     $votes[$voteval]+=$result['value'];
---
>     $votes[$voteval] += $result['value'];
254a126
>   // Gather possible choices.
268,274c140,142
<     //If AHAH and 1click are enabled, ensure that the fallback behavior shows the same vote confirmation.
<     if (variable_get('decisions_1click', 0) && ($node->maxchoices == 1)) {
<       if (!empty($new_vote)) {
<         //Fallback behavior.
<         $vote = $new_vote;
<       }
<       $vote_label = $node->choice[$vote['tag']]['label'];
---
>     // If AHAH and 1click are enabled, ensure that the fallback behavior shows the same vote confirmation.
>     if (variable_get('decisions_1click', 0) && $node->maxchoices == 1) {
>       $vote_label = $node->choice[ $current_vote['tag'] ]['label'];
294c162
<  * implementation of the format_votes() hook.
---
>  * Implementation of the format_votes() hook.
310a179
> 
312c181,182
<  * Registers the vote as a key for this node using votingapi_set_vote().
---
>  * Implementation of decisions_hook_voting_form.
>  * Presents a list of choices for the user to vote on.
314,315c184
< function decisions_selection_voting_form_submit($form, &$form_state) {
<   $node = $form_state['values']['node'];
---
> function decisions_selection_voting_form($form_state, $node, $teaser, $page) {
317,340c186,242
<   global $user;
<   $node = $form_state['values']['node'];
<   $votes = array();
<   if ($node->maxchoices == 1) {
<     // plurality voting
<     $vote = array(
<       'value' => 1,
<       'tag' => $form_state['values']['choice'],
<       'value_type' => 'option',
<       'content_type' => 'decisions',
<       'content_id' => $node->nid,
<     );
<     $votes[] = $vote;
<   }
<   else {
<     // approval voting
<     foreach ($node->choice as $key => $choice) {
<       if (isset($form_state['values']['choice'][$key]) && $form_state['values']['choice'][$key]) {
<         $vote = array(
<           'value' => 1,
<           'value_type' => 'option',
<           'tag' => $key,
<           'content_type' => 'decisions',
<           'content_id' => $node->nid,
---
> 
>   $form = array();
> 
>   $form['node'] = array(
>     '#type' => 'value',
>     '#value' => $node,
>   );
> 
>   $form['#attributes'] = array('class' => 'decisions-selection-voting-form');
> 
>   if ($node->choice) {
>     $list = array();
>     // Put options in random order if randomize option
>     // selected on node create/edit form.
>     if ($node->randomize) {
>       $node->choice = _decisions_randomize_options($node->choice, $node->choices);
>     }
>     // Single choice, "Plurality" voting.
>     if ($node->maxchoices == 1) {
>       // Are we using the 1-click form?
>       if ($one_click == 1) {
>         $form['choices'] = array(
>           '#type'    => 'fieldset',
>           '#title' => $page ? '' : check_plain($node->title),
>         );
>         foreach ($node->choice as $i => $choice) {
>           $form['choices'][$i]['choice'] = array(
>             '#type'       => 'submit',
>             '#value'      => $choice['label'],
>           );
>         }
> 
>         // If asynchronous voting is enabled, add the necessary JS.
>         if (variable_get('decisions_ahah', 0) == 1) {
>           drupal_add_css(drupal_get_path('module', 'selection') . '/selection.css', 'module');
>           drupal_add_js(drupal_get_path('module', 'selection') . '/selection.js');
>           
>           $settings = array();
>           $settings['path'] = url('decisions_selection/vote/' . $node->nid);
> 
>           drupal_add_js(array('decisionsSelection' => $settings), 'setting');
>         }
>         // At this point, we can return the form since 1-click uses its own callback for vote submission.
>         return $form;
>       }
>       // Not using 1-click. Use radios.
>       else {
>         foreach ($node->choice as $i => $choice) {
>           if ($choice['label']) {
>             $list[$i] = check_plain($choice['label']);
>           }
>         }
>         $form['choice'] = array(
>           '#type' => 'radios',
>           '#title' => $page ? '' : check_plain($node->title),
>           '#default_value' => -1,
>           '#options' => $list,
342d243
<         $votes[] = $vote;
344a246,258
>     // Approval/multiple-choice voting.
>     else {
>       foreach ($node->choice as $i => $choice) {
>         if ($choice['label']) {
>           $list[$i] = check_plain($choice['label']);
>         }
>       }
>       $form['choice'] = array(
>         '#type' => 'checkboxes',
>         '#title' => $page ? '' : check_plain($node->title),
>         '#options' => $list,
>       );
>     }
346,349c260,265
<   votingapi_add_votes($votes);
<   //If this becomes a performance problem, we use votingapi_set_votes and the site-wide recalculation time.
<   votingapi_recalculate_results('decisions', $node->nid);
<   drupal_set_message(t('Your vote was registered.'));
---
>   // Add the submit button. 1click has already returned the form by this point.
>   $form['vote'] = array(
>     '#type' => 'submit',
>     '#value' => t('Vote'),
>   );
>   return $form;
353c269
<  * implementation of the vote_validate() hook
---
>  * Implementation of the vote_validate() hook
360a277,278
>   $one_click = variable_get('decisions_1click', 0);
> 
362c280,296
<     if (!array_key_exists($form_state['values']['choice'], $node->choice)) {
---
>     // One-Click uses multiple submits with the same name, so let's look through
>     // the valid choices and see if any is the button that was clicked.
>     if ($one_click) {
>       $form_state['values']['choice'] = FALSE;
>       foreach ($node->choice as $key => $choice) {
>         if (check_plain($choice['label']) == $form_state['clicked_button']['#value']) {
>           // We set the choice value to the vote_offset.  We must do this because
>           // we can't set the value on the form element, as it is a submit button.
>           $form_state['values']['choice'] = $key;
>         }
>       }
> 
>       if ($form_state['values']['choice'] === FALSE) {
>         form_set_error('choice', 'At least one choice must be selected.');
>       }
>     }
>     elseif (!array_key_exists($form_state['values']['choice'], $node->choice)) {
367,368c301,302
<     //Approval/Multiple-choice voting
<     // array used to check which values are set
---
>     // Approval/Multiple-choice voting
>     // array used to check which values are set.
371c305
<       // see if the box is checked
---
>       // See if the box is checked.
377c311
<     // too many choices ranked
---
>     // Too many choices ranked.
386c320
<     // not enough choices ranked
---
>     // Not enough choices ranked.
394,396c328,365
< function theme_selection_decisions_view_results($node = NULL, $teaser = FALSE, $page = FALSE, $new_vote = array()) {
<   return selection_decisions_view_results($node, $teaser, $page, $new_vote);
< }
\ No newline at end of file
---
> /**
>  * Registers the vote as a key for this node using votingapi_set_vote().
>  */
> function decisions_selection_voting_form_submit($form, &$form_state) {
>   $node = $form_state['values']['node'];
> 
>   $votes = array();
>   if ($node->maxchoices == 1) {
>     // plurality voting
>     $vote = array(
>       'value' => 1,
>       'tag' => $form_state['values']['choice'],
>       'value_type' => 'option',
>       'content_type' => 'decisions',
>       'content_id' => $node->nid,
>     );
>     $votes[] = $vote;
>   }
>   else {
>     // approval voting
>     foreach ($node->choice as $key => $choice) {
>       if (isset($form_state['values']['choice'][$key]) && $form_state['values']['choice'][$key]) {
>         $vote = array(
>           'value' => 1,
>           'value_type' => 'option',
>           'tag' => $key,
>           'content_type' => 'decisions',
>           'content_id' => $node->nid,
>         );
>         $votes[] = $vote;
>       }
>     }
>   }
>   votingapi_add_votes($votes);
>   // If this becomes a performance problem, we use votingapi_set_votes and the site-wide recalculation time.
>   votingapi_recalculate_results('decisions', $node->nid);
>   drupal_set_message(t('Your vote was registered.'));
> }
Only in decisions/modes: spinner.gif
