<commit_before>// TODO: this shouldn't be a mixin (wtf)

import React from 'react';
import ReactDOM from 'react-dom';
import bem, {makeBem} from 'js/bem';
import dkobo_xlform from '../../xlform/src/_xlform.init';
import _ from 'underscore';
import envStore from 'js/envStore';

bem.CascadePopup = makeBem(null, 'cascade-popup');
bem.CascadePopup__message = makeBem(bem.CascadePopup, 'message');
bem.CascadePopup__buttonWrapper = makeBem(bem.CascadePopup, 'buttonWrapper');
bem.CascadePopup__button = makeBem(bem.CascadePopup, 'button', 'button');

const CHOICE_LIST_SUPPORT_URL = 'cascading_select.html';

export const cascadeMixin = {
  toggleCascade () {
    var lastSelectedRow = _.last(this.app.selectedRows()),
        lastSelectedRowIndex = lastSelectedRow ? this.app.survey.rows.indexOf(lastSelectedRow) : -1;
    this.setState({
      showCascadePopup: !this.state.showCascadePopup,
      cascadeTextareaValue: '',
      cascadeLastSelectedRowIndex: lastSelectedRowIndex,
    });
  },
  cancelCascade () {
    this.setState({
      cascadeError: false,
      cascadeReady: false,
      cascadeReadySurvey: false,
      addCascadePopup: false,
      cascadeTextareaValue: '',
      cascadeStr: '',
      showCascadePopup: false,
    });
  },
  cascadePopopChange (evt) {
    var s = {
      cascadeTextareaValue: ReactDOM.findDOMNode(this.refs.cascade).value,
    }
    // if (s.cascadeTextareaValue.length === 0) {
    //   return this.cancelCascade();
    // }
    try {
      var inp = dkobo_xlform.model.utils.split_paste(s.cascadeTextareaValue);
      var tmpSurvey = new dkobo_xlform.model.Survey({
        survey: [],
        choices: inp
      });
      if (tmpSurvey.choices.length === 0) {
        throw new Error('Paste your formatted table from excel in the box below.');
      }
      tmpSurvey.choices.at(0).create_corresponding_rows();
      /*
      tmpSurvey._addGroup({
        __rows: tmpSurvey.rows.models,
        label: '',
      });
      */
      var rowCount = tmpSurvey.rows.length;
      if (rowCount === 0) {
        throw new Error('Paste your formatted table from excel in the box below.');
      }
      s.cascadeReady = true;
      s.cascadeReadySurvey = tmpSurvey;<commit_msg>Restore translations to a few `throw`s<commit_after>// TODO: this shouldn't be a mixin (wtf)

import React from 'react';
import ReactDOM from 'react-dom';
import bem, {makeBem} from 'js/bem';
import dkobo_xlform from '../../xlform/src/_xlform.init';
import _ from 'underscore';
import envStore from 'js/envStore';

bem.CascadePopup = makeBem(null, 'cascade-popup');
bem.CascadePopup__message = makeBem(bem.CascadePopup, 'message');
bem.CascadePopup__buttonWrapper = makeBem(bem.CascadePopup, 'buttonWrapper');
bem.CascadePopup__button = makeBem(bem.CascadePopup, 'button', 'button');

const CHOICE_LIST_SUPPORT_URL = 'cascading_select.html';

export const cascadeMixin = {
  toggleCascade () {
    var lastSelectedRow = _.last(this.app.selectedRows()),
        lastSelectedRowIndex = lastSelectedRow ? this.app.survey.rows.indexOf(lastSelectedRow) : -1;
    this.setState({
      showCascadePopup: !this.state.showCascadePopup,
      cascadeTextareaValue: '',
      cascadeLastSelectedRowIndex: lastSelectedRowIndex,
    });
  },
  cancelCascade () {
    this.setState({
      cascadeError: false,
      cascadeReady: false,
      cascadeReadySurvey: false,
      addCascadePopup: false,
      cascadeTextareaValue: '',
      cascadeStr: '',
      showCascadePopup: false,
    });
  },
  cascadePopopChange (evt) {
    var s = {
      cascadeTextareaValue: ReactDOM.findDOMNode(this.refs.cascade).value,
    }
    // if (s.cascadeTextareaValue.length === 0) {
    //   return this.cancelCascade();
    // }
    try {
      var inp = dkobo_xlform.model.utils.split_paste(s.cascadeTextareaValue);
      var tmpSurvey = new dkobo_xlform.model.Survey({
        survey: [],
        choices: inp
      });
      if (tmpSurvey.choices.length === 0) {
        throw new Error(
          // this message is presented to the user
          t('Paste your formatted table from excel in the box below.')
        );
      }
      tmpSurvey.choices.at(0).create_corresponding_rows();
      /*
      tmpSurvey._addGroup({
        __rows: tmpSurvey.rows.models,
        label: '',
      });
      */
      var rowCount = tmpSurvey.rows.length;
      if (rowCount === 0) {
        throw new Error(
          // this message is presented to the user
          t('Paste your formatted table from excel in the box below.')
        );
      }
      s.cascadeReady = true;
      s.cascadeReadySurvey = tmpSurvey;
{'fraction_non_alphanumeric': 0.1229098805646037, 'fraction_numerical': 0.002171552660152009, 'mean_word_length': 2.9844290657439445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7542861', 'n_tokens_mistral': 1529, 'n_tokens_neox': 1506, 'n_words': 306}