SHARE
TWEET

Untitled

a guest Oct 12th, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { api } from "../../../../assets/scripts/js/api";
  2. import dispatcher from '../_shared/FluxAppDispatcher';
  3. import constants from '../_shared/FluxAppConstants';
  4.  
  5. export function initScoreCardData(props){
  6.     dispatcher.dispatch({
  7.         type:constants.score_card_init_data,
  8.         payload: {
  9.             index: props.postId,
  10.             object: props,
  11.         }
  12.     });
  13. }
  14.  
  15. export function updateCategoryScore(post_id, category_index, score) {
  16.     dispatcher.dispatch({
  17.         type: constants.score_card_update_category_score,
  18.         payload: {
  19.             postId: post_id,
  20.             category_index:   category_index,
  21.             score:   score,
  22.         }
  23.     });
  24. }
  25.  
  26. export function submitScore(post_id, scoring) {
  27.  
  28.     dispatcher.dispatch({
  29.         type: constants.score_card_show_loader,
  30.         payload: {
  31.             postId: post_id
  32.         }
  33.     });
  34.  
  35.     api.post('/voting/api/url', {
  36.         post_id: post_id,
  37.  
  38.         vote_data: this.formatUserScoresForBackend(scoring)
  39.  
  40.     }).done((response) => {
  41.  
  42.         let revealEvent = new Event('reveal-author-and-score', { bubbles: true });
  43.  
  44.         this.wrapperElement.dispatchEvent(revealEvent);
  45.  
  46.         dispatcher.dispatch({
  47.             type: constants.score_card_finish_scoring,
  48.             payload: {
  49.                 postId: post_id,
  50.                 currentResults: {
  51.                     totalNumberOfVotes: response.data.totalNumberOfVotes,
  52.                     averageCommunityScore: response.data.averageCommunityScore,
  53.                     currentUserScore: response.data.currentUserScore,
  54.                 },
  55.                 currentUserCanVote: false,
  56.                 isLoading: false,
  57.             }
  58.         });
  59.  
  60.     });
  61.  
  62. }
  63.  
  64. export function restartScoring(post_id) {
  65.     dispatcher.dispatch({
  66.         type: constants.score_card_restart_scoring,
  67.         payload: {
  68.             postId: post_id,
  69.         }
  70.     });
  71.  
  72. }
RAW Paste Data
Top