Index: vud.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/vote_up_down/vud.module,v retrieving revision 1.1.2.36 diff -b -u -p -r1.1.2.36 vud.module --- vud.module 1 Nov 2010 04:57:25 -0000 1.1.2.36 +++ vud.module 14 Dec 2010 18:58:34 -0000 @@ -83,12 +83,13 @@ function vud_menu() { 'file' => 'vud.theme.inc', ); - $items['votereset/%/%/%/%'] = array( + $items['votereset/%/%/%/%/%'] = array( 'title' => 'Reset vote', 'page callback' => 'vud_reset', - 'page arguments' => array(1, 2, 3, 4), + 'page arguments' => array(1, 2, 3, 4, 5), 'access arguments' => array('reset vote up/down votes'), 'type' => MENU_CALLBACK, + 'file' => 'vud.theme.inc', ); $items['user/%user/votes'] = array( @@ -157,31 +158,6 @@ function vud_user_votes() { } /** - * Callback to reset votes on an object. - */ -function vud_reset($type, $content_id, $tag, $token) { - if (drupal_valid_token($token, "votereset/$type/$content_id/$tag", TRUE)) { - $uid = votingapi_current_user_identifier(); - $criteria = array( - 'content_type' => $type, - 'content_id' => $content_id, - 'tag' => $tag, - ); - $fullc = $criteria + $uid; - votingapi_delete_votes(votingapi_select_votes($fullc)); - votingapi_recalculate_results($type, $content_id); - - drupal_goto($_SERVER['HTTP_REFERER']); - } - else { - watchdog('vud', - 'Could not reset votes on @type @content_id, with value @value, tag @tag and token @token', - array('@type' => $type, '@content_id' => $content_id, '@value' => $value, '@tag' => $tag, '@token' => $token)); - drupal_set_message(t("Oops! There was an error in resetting your vote!", 'warning')); - } -} - -/** * Menu callback; show widget message. */ function vud_denied_vote($js = FALSE, $code=VUD_WIDGET_MESSAGE_ERROR) { Index: vud.theme.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/vote_up_down/vud.theme.inc,v retrieving revision 1.1.2.40 diff -b -u -p -r1.1.2.40 vud.theme.inc --- vud.theme.inc 5 Dec 2010 07:50:06 -0000 1.1.2.40 +++ vud.theme.inc 14 Dec 2010 18:58:34 -0000 @@ -132,6 +132,7 @@ function vud_widget_proxy($content_id, $ 'id' => 'widget-' . $type . '-' . $content_id, 'link_class_up' => 'vud-link-up', 'link_class_down' => 'vud-link-down', + 'link_class_reset' => 'vud-link-reset', ); global $user; @@ -155,18 +156,22 @@ function vud_widget_proxy($content_id, $ if ($user_vote > 0) { $variables['class_up'] = 'up-active'; $variables['class_down'] = 'down-inactive'; + $variables['class_reset'] = 'reset-active'; } elseif ($user_vote < 0) { $variables['class_up'] = 'up-inactive'; $variables['class_down'] = 'down-active'; + $variables['class_reset'] = 'reset-active'; } else { $variables['class_up'] = 'up-inactive'; $variables['class_down'] = 'down-inactive'; + $variables['class_reset'] = 'reset-inactive'; } $token_up = drupal_get_token("vote/$type/$content_id/1/$tag/$widget_theme"); $token_down = drupal_get_token("vote/$type/$content_id/-1/$tag/$widget_theme"); + $token_reset = drupal_get_token("votereset/$type/$content_id/$tag/$widget_theme"); $result_criteria = array( 'content_type' => $type, @@ -228,6 +233,7 @@ function vud_widget_proxy($content_id, $ $variables['readonly'] = $readonly; $link_up = url("vote/$type/$content_id/1/$tag/$widget_theme/$token_up"); $link_down = url("vote/$type/$content_id/-1/$tag/$widget_theme/$token_down"); + $link_reset = url("votereset/$type/$content_id/$tag/$widget_theme/$token_reset"); $message_on_deny = variable_get('vud_message_on_deny', FALSE); $variables['show_links'] = !$readonly || $message_on_deny; $variables['show_up_as_link'] = $variables['show_links'] && ($user_vote <= 0); @@ -235,27 +241,33 @@ function vud_widget_proxy($content_id, $ if ($readonly) { $variables['link_class_up'] .= ' denied'; $variables['link_class_down'] .= ' denied'; + $variables['link_class_reset'] .= ' denied'; if ($message_on_deny) { ctools_include('modal'); ctools_modal_add_js(); $variables['link_class_up'] .= ' ctools-use-modal'; $variables['link_class_down'] .= ' ctools-use-modal'; + $variables['link_class_reset'] .= ' ctools-use-modal'; $link_up = url(sprintf('vud/nojs/denied/%d', $widget_message_code)); $link_down = url(sprintf('vud/nojs/denied/%d', $widget_message_code)); + $link_reset = url(sprintf('vud/nojs/denied/%d', $widget_message_code)); } else { // no vote access, so avoid show the link at template $link_up = '#'; $link_down = '#'; + $link_reset = '#'; } } else { $variables['link_class_up'] .= ' ctools-use-ajax'; $variables['link_class_down'] .= ' ctools-use-ajax'; + $variables['link_class_reset'] .= ' ctools-use-ajax'; } $variables['link_up'] = $link_up; $variables['link_down'] = $link_down; + $variables['link_reset'] = $link_reset; $template_file = vud_pseudo_theming($type, 'widget', $plugin, $variables); @@ -420,3 +432,52 @@ function vud_vote($type, $content_id, $v drupal_goto($_SERVER['HTTP_REFERER']); } } + +/** + * Function for the reset handler with Ajax support. + */ +function vud_reset($type, $content_id, $tag, $widget, $token) { + if (drupal_valid_token($token, "votereset/$type/$content_id/$tag/$widget", TRUE)) { + $uid = votingapi_current_user_identifier(); + $criteria = array( + 'content_type' => $type, + 'content_id' => $content_id, + 'tag' => $tag, + ); + $fullc = $criteria + $uid; + votingapi_delete_votes(votingapi_select_votes($fullc)); + votingapi_recalculate_results($type, $content_id); + } + else { + watchdog('vud', + 'Could not reset votes on @type @content_id, tag @tag and token @token', + array('@type' => $type, '@content_id' => $content_id, '@tag' => $tag, '@token' => $token)); + drupal_set_message(t("Oops! There was an error in resetting your vote!", 'warning')); + } + + if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { + ctools_include('ajax'); + $plugin = vud_widget_get($widget); + + if ($function = ctools_plugin_get_function($plugin, 'ajax render')) { + $commands = $function($type, $content_id, $value, $tag, $token, $widget); + } + else { + $commands = array(); + if (!empty($plugin['widget template'])) { + $commands[] = ctools_ajax_command_replace("#widget-$type-$content_id", theme('vud_widget', $content_id, $type, $tag, $widget)); + } + + if (!empty($plugin['votes template'])) { + $commands[] = ctools_ajax_command_replace("#votes-$type-$content_id", theme('vud_votes', $content_id, $type, $tag, $widget)); + } + } + + // This is the default set of commands. It can be overridden by an individual + // widget if it wants to. + ctools_ajax_render($commands); + } + else { + drupal_goto($_SERVER['HTTP_REFERER']); + } +}