<commit_before>﻿import {JsonObject} from "./jsonobject";
import {Base, ISurvey, HashTable, IQuestion, IElement, IConditionRunner, IPage, SurveyError, Event} from "./base";
import {ISurveyTriggerOwner, SurveyTrigger} from "./trigger";
import {PageModel} from "./page";
import {TextPreProcessor} from "./textPreProcessor";
import {ProcessValue} from "./conditionProcessValue";
import {dxSurveyService} from "./dxSurveyService";
import {JsonError} from "./jsonobject";
import {surveyLocalization} from "./surveyStrings";
import {QuestionBase} from "./questionbase";
import {CustomError} from "./error";
import {CustomWidgetCollection} from './questionCustomWidgets';
import {ILocalizableOwner, LocalizableString} from "./localizablestring";

/**
 * Survey object contains information about the survey. Pages, Questions, flow logic and etc.
 */
export class SurveyModel extends Base implements ISurvey, ISurveyTriggerOwner, ILocalizableOwner {
    /**
     * Set this property to automatically load survey Json from [dxsurvey.com](http://www.dxsurvey.com) service.
     * @see loadSurveyFromService
     */
    public surveyId: string = null;
    /**
     * Set this property to automatically save the data into the [dxsurvey.com](http://www.dxsurvey.com) service.
     * @see onComplete
     */
    public surveyPostId: string = null;
    public surveyShowDataSaving: boolean = false;
    /**
     * Use this property as indentificator for a user, for example e-mail or unique customer id in your web application. If you are loading survey or posting survey results  from/to [dxsurvey.com](http://www.dxsurvey.com) service, then the library do not allow to run the same survey the second time. On the second run, the user will see the 'Thank you' page.
     */
    public clientId: string = null;
    /**
     * If the property is not empty, before starting to run the survey, the library checkes if the cookie with this name exists. If it is true, the survey goes to complete mode and an user sees the 'Thank you' page. On completing the survey the cookie with this name is created.
     */
    public cookieName: string = null;
    /**
     * Set it to true, to save results on completing every page. onPartialSend event is fired.
     * @see onPartialSend
     * @see clientId
     */
    public sendResultOnPageNext: boolean = false;
    /**
     * You may show comments input for the most of questions. The entered text in the comment input will be saved as 'question name' + 'commentPrefix'.
     * @see data
     */
    public commentPrefix: string = "-Comment";
    /**
     * On showing the next or previous page, a first input is focused, if the property set to true.
     */
    public focusFirstQuestionAutomatic: boolean = true;
    /**
     * Set it to false to hide 'Prev', 'Next' and 'Complete' buttons. It makes sense if you are going to create a custom navigation or have just one page or on setting goNextPageAutomatic property.
     * @see goNextPageAutomatic
     */
    public showNavigationButtons: boolean = true;
    /**
     * Set it to false hide survey title.
     * @see title
     */
    public showTitle: boolean = true;
    /**
     * Set it to false to hide page titles.
     * @see PageModel.title
     */
    public showPageTitles: boolean = true;
    /**
     * On finishing the survey the 'Thank you', page on complete, is shown. Set the property to false, to hide the 'Thank you' page.
     * @see data
     * @see onComplete
     */
    public showCompletedPage: boolean = true;
    /**
     * A char/string that will be rendered in the title required questions.
     * @see QuestionBase.title
     */
    public requiredText: string = "*";
    /**
     * By default the first question index is 1. You may start it from 100 or from 'A', by setting 100 or 'A' to this property.
     * @see QuestionBase.title
     * @see requiredText
     */
    public questionStartIndex: string = "";
    private showProgressBarValue: string = "off";
    /**
     * By default the entered text in the others input in the checkbox/radiogroup/dropdown are stored as "question name " + "-Comment". The value itself is "question name": "others". Set this property to false, to store the entered text directly in the "question name" key.
     * @see commentPrefix
     */
    public storeOthersAsComment: boolean = true;
    /**
     * Set it true if you want to go to the next page without pressing 'Next' button when all questions are anwered.
    * @see showNavigationButtons 
     */
    public goNextPageAutomatic: boolean = false;
    /**
     * The list of all pages in the survey, including invisible.
     * @see PageModel
     * @see visiblePages
     */
    public pages: Array<PageModel> = new Array<PageModel>();
    /**
     * The list of triggers in the survey.
     * @see SurveyTrigger
     */
    public triggers: Array<SurveyTrigger> = new Array<SurveyTrigger>();
    /**
     * Set it to true, to remove from data property values of invisible questions on survey complete. In this case, the invisible questions will not be stored on the server.
     * @see QuestionBase.visible
     * @see oncComplete
     */
    public clearInvisibleValues: boolean = false;

    private locTitleValue : LocalizableString;
    private locCompletedHtmlValue : LocalizableString;
    private locPagePrevTextValue : LocalizableString;
    private locPageNextTextValue : LocalizableString;
    private locCompleteTextValue : LocalizableString;
    private locQuestionTitleTemplateValue: LocalizableString;

    private currentPageValue: PageModel = null;
    private valuesHash: HashTable<any> = {};
    private variablesHash: HashTable<any> = {};
    private pagePrevTextValue: string;
    private pageNextTextValue: string;
    private completeTextValue: string;
    private showPageNumbersValue: boolean = false;
    private showQuestionNumbersValue: string = "on";
    private questionTitleLocationValue: string = "top";
    private localeValue: string = "";
    private isCompleted: boolean = false;
    private isLoading: boolean = false;
    private processedTextValues: HashTable<any> = {};
    private textPreProcessor: TextPreProcessor;
    private isValidatingOnServerValue: boolean = false;
    private modeValue: string = "edit";
    private isDesignModeValue: boolean = false;
    private completedStateValue: string = "";
    private completedStateTextValue: string = "";
    /**
     * The event is fired after a user click on 'Complete' button and finished the survey. You may use it to send the data to your web server.
     * @see data
     * @see clearInvisibleValues<commit_msg>Update docs in comments, related to this feature: https://github.com/surveyjs/surveyjs/issues/473<commit_after>﻿import {JsonObject} from "./jsonobject";
import {Base, ISurvey, HashTable, IQuestion, IElement, IConditionRunner, IPage, SurveyError, Event} from "./base";
import {ISurveyTriggerOwner, SurveyTrigger} from "./trigger";
import {PageModel} from "./page";
import {TextPreProcessor} from "./textPreProcessor";
import {ProcessValue} from "./conditionProcessValue";
import {dxSurveyService} from "./dxSurveyService";
import {JsonError} from "./jsonobject";
import {surveyLocalization} from "./surveyStrings";
import {QuestionBase} from "./questionbase";
import {CustomError} from "./error";
import {CustomWidgetCollection} from './questionCustomWidgets';
import {ILocalizableOwner, LocalizableString} from "./localizablestring";

/**
 * Survey object contains information about the survey. Pages, Questions, flow logic and etc.
 */
export class SurveyModel extends Base implements ISurvey, ISurveyTriggerOwner, ILocalizableOwner {
    /**
     * Set this property to automatically load survey Json from [dxsurvey.com](http://www.dxsurvey.com) service.
     * @see loadSurveyFromService
     */
    public surveyId: string = null;
    /**
     * Set this property to automatically save the data into the [dxsurvey.com](http://www.dxsurvey.com) service.
     * @see onComplete
     * @see surveyShowDataSaving
     */
    public surveyPostId: string = null;
    /**
     * Set this property to true, to show the progress on saving/sending data into the [dxsurvey.com](http://www.dxsurvey.com) service.
     * @see surveyPostId
     */
    public surveyShowDataSaving: boolean = false;
    /**
     * Use this property as indentificator for a user, for example e-mail or unique customer id in your web application. If you are loading survey or posting survey results  from/to [dxsurvey.com](http://www.dxsurvey.com) service, then the library do not allow to run the same survey the second time. On the second run, the user will see the 'Thank you' page.
     */
    public clientId: string = null;
    /**
     * If the property is not empty, before starting to run the survey, the library checkes if the cookie with this name exists. If it is true, the survey goes to complete mode and an user sees the 'Thank you' page. On completing the survey the cookie with this name is created.
     */
    public cookieName: string = null;
    /**
     * Set it to true, to save results on completing every page. onPartialSend event is fired.
     * @see onPartialSend
     * @see clientId
     */
    public sendResultOnPageNext: boolean = false;
    /**
     * You may show comments input for the most of questions. The entered text in the comment input will be saved as 'question name' + 'commentPrefix'.
     * @see data
     */
    public commentPrefix: string = "-Comment";
    /**
     * On showing the next or previous page, a first input is focused, if the property set to true.
     */
    public focusFirstQuestionAutomatic: boolean = true;
    /**
     * Set it to false to hide 'Prev', 'Next' and 'Complete' buttons. It makes sense if you are going to create a custom navigation or have just one page or on setting goNextPageAutomatic property.
     * @see goNextPageAutomatic
     */
    public showNavigationButtons: boolean = true;
    /**
     * Set it to false hide survey title.
     * @see title
     */
    public showTitle: boolean = true;
    /**
     * Set it to false to hide page titles.
     * @see PageModel.title
     */
    public showPageTitles: boolean = true;
    /**
     * On finishing the survey the 'Thank you', page on complete, is shown. Set the property to false, to hide the 'Thank you' page.
     * @see data
     * @see onComplete
     */
    public showCompletedPage: boolean = true;
    /**
     * A char/string that will be rendered in the title required questions.
     * @see QuestionBase.title
     */
    public requiredText: string = "*";
    /**
     * By default the first question index is 1. You may start it from 100 or from 'A', by setting 100 or 'A' to this property.
     * @see QuestionBase.title
     * @see requiredText
     */
    public questionStartIndex: string = "";
    private showProgressBarValue: string = "off";
    /**
     * By default the entered text in the others input in the checkbox/radiogroup/dropdown are stored as "question name " + "-Comment". The value itself is "question name": "others". Set this property to false, to store the entered text directly in the "question name" key.
     * @see commentPrefix
     */
    public storeOthersAsComment: boolean = true;
    /**
     * Set it true if you want to go to the next page without pressing 'Next' button when all questions are anwered.
    * @see showNavigationButtons 
     */
    public goNextPageAutomatic: boolean = false;
    /**
     * The list of all pages in the survey, including invisible.
     * @see PageModel
     * @see visiblePages
     */
    public pages: Array<PageModel> = new Array<PageModel>();
    /**
     * The list of triggers in the survey.
     * @see SurveyTrigger
     */
    public triggers: Array<SurveyTrigger> = new Array<SurveyTrigger>();
    /**
     * Set it to true, to remove from data property values of invisible questions on survey complete. In this case, the invisible questions will not be stored on the server.
     * @see QuestionBase.visible
     * @see oncComplete
     */
    public clearInvisibleValues: boolean = false;

    private locTitleValue : LocalizableString;
    private locCompletedHtmlValue : LocalizableString;
    private locPagePrevTextValue : LocalizableString;
    private locPageNextTextValue : LocalizableString;
    private locCompleteTextValue : LocalizableString;
    private locQuestionTitleTemplateValue: LocalizableString;

    private currentPageValue: PageModel = null;
    private valuesHash: HashTable<any> = {};
    private variablesHash: HashTable<any> = {};
    private pagePrevTextValue: string;
    private pageNextTextValue: string;
    private completeTextValue: string;
    private showPageNumbersValue: boolean = false;
    private showQuestionNumbersValue: string = "on";
    private questionTitleLocationValue: string = "top";
    private localeValue: string = "";
    private isCompleted: boolean = false;
    private isLoading: boolean = false;
    private processedTextValues: HashTable<any> = {};
    private textPreProcessor: TextPreProcessor;
    private isValidatingOnServerValue: boolean = false;
    private modeValue: string = "edit";
    private isDesignModeValue: boolean = false;
    private completedStateValue: string = "";
    private completedStateTextValue: string = "";
    /**
     * The event is fired after a user click on 'Complete' button and finished the survey. You may use it to send the data to your web server.
     * @param sender the survey object that fires the event
     * @param options.showDataSaving(text) call this method to show that the survey is saving the data on your server. The text is an optional parameter to show your message instead of default.
     * @param options.showDataSavingError(text) call this method to show that there is an error on saving the data on your server. If you want to show a custom error, use an optional text parameter.
     * @param options.showDataSavingSuccess(text) call this method to show that the data were successful saved on the server. 
     * @param options.showDataSavingClear call this method to hide the text about the saving progress.
     * @see data
     * @see clearInvisibleValues
{'fraction_non_alphanumeric': 0.08502850707397762, 'fraction_numerical': 0.0011965932286900824, 'mean_word_length': 3.3224825068451476, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 7, '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': '5673302', 'n_tokens_mistral': 3692, 'n_tokens_neox': 3655, 'n_words': 1571}