<commit_before>/* Javascript for PeerInstructionXBlock. */

// A unique XBlockID allowing us to have multiple instances of this XBlock on a page
var PIXBlockID = 0;

/**
 * Generate a unique ID. Uses the global PIXBlockID and adds on each time it is called
 *
 * @since 0.4.0
 *
 * @param null
 * @return (string) A unique XBlock ID of the form 'ubcpi_#'
 */

function generatePIXBlockID() {

    // Cache the global internally
    var internalID = PIXBlockID;

    // A prefix for the string
    var IDPrefix = 'ubcpi_';

    internalID += 1;
    PIXBlockID = internalID;

    return IDPrefix + internalID;

}/* generatePIXBlockID() */


/**
 * Set the statuses for new, answered and revised
 *
 * @since 1.0.0
 *
 * @param (object) self - The whole 'this' object
 * @return (object) Modified self object
 */

function setDefaultStatuses( self ) {

    self.STATUS_NEW      = 0;
    self.STATUS_ANSWERED = 1;
    self.STATUS_REVISED  = 2;

    return self;

}


/**
 * Set the default Maximum rationale size
 *
 * @since 1.0.0
 *
 * @param (object) self - The whole 'this' object
 * @return (object) Modified self object
 */

function setDefaultMaxRationaleSize( self ) {

    self.MAX_RATIONALE_SIZE = 32000;

}/* setDefaultMaxRationaleSize */


/**
 * Based on the answers provided, return which status the problem is currently in
 * If the original answer is null/undef then we're at the start
 * If the original answer is not null/undef but the revised answer is, we're at step 2
 * If both the original answer and revised answer is not null/undef then we're at step 3
 *
 * @since 1.0.0
 *
 * @param (string) answer_original - What, if anything, the student has answered initially
 * @param (string) answer_revised - What, if anything, the student has answered after revision
 * @param (object) self - The whole 'this' object
 * @return (int) the status as set by setDefaultStatuses based on the passed answers
 */

function getStatus( answer_original, answer_revised, self ) {

    if ( typeof answer_original === 'undefined' || answer_original === null ) {
        return self.STATUS_NEW;
    } else if ( typeof answer_revised === 'undefined' || answer_revised === null ) {
        return self.STATUS_ANSWERED;
    } else {
        return self.STATUS_REVISED;
    }

}/* getStatus() */


/**
 * Determine if the submit button should be disabled
 * If we have an answer selected, a rationale that is large enough and we are not already submitting, we ENable
 * the submit button. For all other scenarios, we disable it.
 *
 * @since 1.0.0
 *
 * @param (obect) self - The entire 'this' object
 * @param (object) $scope - the scope context
 * @return (bool) true if the button should be disabled, false otherwise
 */

function disableSubmit( self, $scope ) {

    // Do we have an answer selected?
    var haveAnswer = typeof self.answer !== "undefined" && self.answer !== null;

    // If we don't have a rationale, it's disabled
    if ( typeof self.rationale === "undefined" || self.rationale === null ) {
        return true;
    }

    // How long is the rationale?
    var size = self.rationale.length;

    // Do we have a rationale and is it longer the the minimum length and shorter than the maximum length
    var haveRationale = ( ( size >= $scope.rationale_size.min ) && ( size <= $scope.rationale_size.max ) );

    // Should the button be ENabled?
    var enable = haveAnswer && haveRationale && !self.submitting;

    // We're determining if it should be disabled, so reverse of logic above
    return !enable;

}/* disableSubmit() */


function PeerInstructionXBlock(runtime, element, data) {
    "use strict";
    var notify;

    // The workbench doesn't support notifications.
    notify = $.proxy(runtime.notify, runtime) || function(){};

    $(function ($) {
        var appId = generatePIXBlockID();

        var app = angular.module(appId, ['nvd3ChartDirectives', 'ngSanitize']);
        app.run(function($http) {
            // set up CSRF Token from cookie. This is needed by all post requests
            $http.defaults.headers.post['X-CSRFToken'] = $.cookie('csrftoken');
        });

        app.directive('integer', function(){
            return {
                require: 'ngModel',
                link: function(scope, ele, attr, ctrl){
                    ctrl.$parsers.unshift(function(viewValue){
                        return parseInt(viewValue, 10);
                    });
                }
            };
        });

        app.controller('ReviseController', function ($scope, $http) {
            var self = this;

            $scope.appId = appId;
            $scope.question_text = data.question_text;
            $scope.options = data.options;
            $scope.rationale_size = data.rationale_size;
            $scope.chartDataOriginal = [
                {
                    'key': 'Original',
                    'color': '#33A6DC',
                    'values': []
                }
            ];
            $scope.chartDataRevised = [
                {
                    'key': 'Revised',
                    'color': '#50C67B',
                    'values': []
                }
            ];

            // Set statuses. Makes it testable.
            setDefaultStatuses( self );

            // Set default max rationale size
            setDefaultMaxRationaleSize( self );

            self.answer_original = data.answer_original;
            self.rationale_original = data.rationale_original;<commit_msg>FIXED the self variable when setting statuses and rationale sizes<commit_after>/* Javascript for PeerInstructionXBlock. */

// A unique XBlockID allowing us to have multiple instances of this XBlock on a page
var PIXBlockID = 0;

/**
 * Generate a unique ID. Uses the global PIXBlockID and adds on each time it is called
 *
 * @since 0.4.0
 *
 * @param null
 * @return (string) A unique XBlock ID of the form 'ubcpi_#'
 */

function generatePIXBlockID() {

    // Cache the global internally
    var internalID = PIXBlockID;

    // A prefix for the string
    var IDPrefix = 'ubcpi_';

    internalID += 1;
    PIXBlockID = internalID;

    return IDPrefix + internalID;

}/* generatePIXBlockID() */


/**
 * Set the statuses for new, answered and revised
 *
 * @since 1.0.0
 *
 * @param (object) self - The whole 'this' object
 * @return (object) Modified self object
 */

function setDefaultStatuses( self ) {

    self.STATUS_NEW      = 0;
    self.STATUS_ANSWERED = 1;
    self.STATUS_REVISED  = 2;

    return self;

}


/**
 * Set the default Maximum rationale size
 *
 * @since 1.0.0
 *
 * @param (object) self - The whole 'this' object
 * @return (object) Modified self object
 */

function setDefaultMaxRationaleSize( self ) {

    self.MAX_RATIONALE_SIZE = 32000;

    return self;

}/* setDefaultMaxRationaleSize */


/**
 * Based on the answers provided, return which status the problem is currently in
 * If the original answer is null/undef then we're at the start
 * If the original answer is not null/undef but the revised answer is, we're at step 2
 * If both the original answer and revised answer is not null/undef then we're at step 3
 *
 * @since 1.0.0
 *
 * @param (string) answer_original - What, if anything, the student has answered initially
 * @param (string) answer_revised - What, if anything, the student has answered after revision
 * @param (object) self - The whole 'this' object
 * @return (int) the status as set by setDefaultStatuses based on the passed answers
 */

function getStatus( answer_original, answer_revised, self ) {

    if ( typeof answer_original === 'undefined' || answer_original === null ) {
        return self.STATUS_NEW;
    } else if ( typeof answer_revised === 'undefined' || answer_revised === null ) {
        return self.STATUS_ANSWERED;
    } else {
        return self.STATUS_REVISED;
    }

}/* getStatus() */


/**
 * Determine if the submit button should be disabled
 * If we have an answer selected, a rationale that is large enough and we are not already submitting, we ENable
 * the submit button. For all other scenarios, we disable it.
 *
 * @since 1.0.0
 *
 * @param (obect) self - The entire 'this' object
 * @param (object) $scope - the scope context
 * @return (bool) true if the button should be disabled, false otherwise
 */

function disableSubmit( self, $scope ) {

    // Do we have an answer selected?
    var haveAnswer = typeof self.answer !== "undefined" && self.answer !== null;

    // If we don't have a rationale, it's disabled
    if ( typeof self.rationale === "undefined" || self.rationale === null ) {
        return true;
    }

    // How long is the rationale?
    var size = self.rationale.length;

    // Do we have a rationale and is it longer the the minimum length and shorter than the maximum length
    var haveRationale = ( ( size >= $scope.rationale_size.min ) && ( size <= $scope.rationale_size.max ) );

    // Should the button be ENabled?
    var enable = haveAnswer && haveRationale && !self.submitting;

    // We're determining if it should be disabled, so reverse of logic above
    return !enable;

}/* disableSubmit() */


function PeerInstructionXBlock(runtime, element, data) {
    "use strict";
    var notify;

    // The workbench doesn't support notifications.
    notify = $.proxy(runtime.notify, runtime) || function(){};

    $(function ($) {
        var appId = generatePIXBlockID();

        var app = angular.module(appId, ['nvd3ChartDirectives', 'ngSanitize']);
        app.run(function($http) {
            // set up CSRF Token from cookie. This is needed by all post requests
            $http.defaults.headers.post['X-CSRFToken'] = $.cookie('csrftoken');
        });

        app.directive('integer', function(){
            return {
                require: 'ngModel',
                link: function(scope, ele, attr, ctrl){
                    ctrl.$parsers.unshift(function(viewValue){
                        return parseInt(viewValue, 10);
                    });
                }
            };
        });

        app.controller('ReviseController', function ($scope, $http) {
            var self = this;

            $scope.appId = appId;
            $scope.question_text = data.question_text;
            $scope.options = data.options;
            $scope.rationale_size = data.rationale_size;
            $scope.chartDataOriginal = [
                {
                    'key': 'Original',
                    'color': '#33A6DC',
                    'values': []
                }
            ];
            $scope.chartDataRevised = [
                {
                    'key': 'Revised',
                    'color': '#50C67B',
                    'values': []
                }
            ];

            // Set statuses. Makes it testable.
            self = setDefaultStatuses( self );

            // Set default max rationale size
            self = setDefaultMaxRationaleSize( self );

            self.answer_original = data.answer_original;
            self.rationale_original = data.rationale_original;
{'fraction_non_alphanumeric': 0.10646973541138094, 'fraction_numerical': 0.006705328017397608, 'mean_word_length': 2.3174030658250677, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '492462', 'n_tokens_mistral': 3201, 'n_tokens_neox': 3023, 'n_words': 1050}