<commit_before>/*globals console sparks $ breadModel getBreadBoard */

(function() {
  
  sparks.SparksQuestionView = function(question){
    this.question = question;
    this.$view = null;
  };
  
  sparks.SparksQuestionView.prototype = {
    
    getView: function() {
      var question = this.question;
      
      var $question = $("<div>").addClass("question");

      if (!!question.image){
        var $div = $("<div>").addClass("question-image");
        $div.append(
          $("<img>").attr('src', this._getImgSrc(question.image))
        );
        $question.append($div);
      }
      
      var prompt = question.isSubQuestion ? question.prompt : (question.shownId+1) + ".  " + question.prompt;

      $question.append(
        $("<span>").addClass("prompt").html(prompt), "   "
      );

      var self = this;
      
      if (!question.options){
        var $input = $("<input>").attr("id",question.id+"_input");
        $question.append($input);
        $input.change(function(args){
          self.valueChanged(args);
        });
      } else {
        if (!!question.checkbox || !!question.radio){
          $.each(question.options, function(i,answer_option){
            if (!answer_option.option){
              // answer_option = sparks.mathParser.calculateMeasurement(answer_option);
            } else {
              // answer_option = sparks.mathParser.calculateMeasurement(answer_option.option);
              answer_option = answer_option.option;
            }
            
            var type = question.checkbox ? "checkbox" : "radio";
            
            var groupName = type + "Group" + question.id;
            
            $question.append($("<br>"));
            var $input = $("<input>").attr("type", type).attr("name", groupName).attr("value", answer_option);
            $question.append($input);	
            $question.append("<span> " + answer_option + "</span>");
            
            $input.change(function(args){
              self.valueChanged(args);
            });
          });
          $question.append('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
        } else {
          var $select = $("<select>").attr("id",question.id+"_options");
          
          $select.append($("<option>").attr("value", "").html("").attr("defaultSelected",true));	
          
          console.log("question.keepOrder = "+question.keepOrder);
          if (!question.keepOrder){
            question.options = sparks.util.shuffle(question.options);
          }
           
          $.each(question.options, function(i,answer_option){
            if (!answer_option.option){
              answer_option = sparks.mathParser.calculateMeasurement(answer_option);
            } else {
              answer_option = sparks.mathParser.calculateMeasurement(answer_option.option);
            }
            $select.append($("<option>").attr("value", answer_option).html(answer_option).attr("defaultSelected",false));	
          });
          $question.append($select, "   ");
          $select.change(function(args){
            self.valueChanged(args);<commit_msg>Shuffle questions correctly, even if radio or checkbox<commit_after>/*globals console sparks $ breadModel getBreadBoard */

(function() {
  
  sparks.SparksQuestionView = function(question){
    this.question = question;
    this.$view = null;
  };
  
  sparks.SparksQuestionView.prototype = {
    
    getView: function() {
      var question = this.question;
      
      var $question = $("<div>").addClass("question");

      if (!!question.image){
        var $div = $("<div>").addClass("question-image");
        $div.append(
          $("<img>").attr('src', this._getImgSrc(question.image))
        );
        $question.append($div);
      }
      
      var prompt = question.isSubQuestion ? question.prompt : (question.shownId+1) + ".  " + question.prompt;

      $question.append(
        $("<span>").addClass("prompt").html(prompt), "   "
      );

      var self = this;
      
      if (!question.options){
        var $input = $("<input>").attr("id",question.id+"_input");
        $question.append($input);
        $input.change(function(args){
          self.valueChanged(args);
        });
      } else {
        
        if (!question.keepOrder){
          question.options = sparks.util.shuffle(question.options);
        }
        
        if (!!question.checkbox || !!question.radio){
          $.each(question.options, function(i,answer_option){
            if (!answer_option.option){
              // answer_option = sparks.mathParser.calculateMeasurement(answer_option);
            } else {
              // answer_option = sparks.mathParser.calculateMeasurement(answer_option.option);
              answer_option = answer_option.option;
            }
            
            var type = question.checkbox ? "checkbox" : "radio";
            
            var groupName = type + "Group" + question.id;
            
            $question.append($("<br>"));
            var $input = $("<input>").attr("type", type).attr("name", groupName).attr("value", answer_option);
            $question.append($input);	
            $question.append("<span> " + answer_option + "</span>");
            
            $input.change(function(args){
              self.valueChanged(args);
            });
          });
          $question.append('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
        } else {
          var $select = $("<select>").attr("id",question.id+"_options");
          
          $select.append($("<option>").attr("value", "").html("").attr("defaultSelected",true));
           
          $.each(question.options, function(i,answer_option){
            if (!answer_option.option){
              answer_option = sparks.mathParser.calculateMeasurement(answer_option);
            } else {
              answer_option = sparks.mathParser.calculateMeasurement(answer_option.option);
            }
            $select.append($("<option>").attr("value", answer_option).html(answer_option).attr("defaultSelected",false));	
          });
          $question.append($select, "   ");
          $select.change(function(args){
            self.valueChanged(args);
{'fraction_non_alphanumeric': 0.16316300129366107, 'fraction_numerical': 0.0003234152652005175, 'mean_word_length': 2.1395939086294415, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '7142404', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1685, 'n_words': 232}