<commit_before>﻿var OperationManager = function(_options) {
    this.options = $.extend({
        prefix: "",
        operationKey: null,
        isLite: false,
        controllerUrl: null,
        validationControllerUrl: null,
        avoidValidation: false,
        onOk: null,
        onCancelled: null,
        onOperationSuccess: null,
        multiStep: false,
        navigateOnSuccess: false,
        closePopupOnSuccess: false,
        confirmMsg: null,
        requestExtraJsonData: null,
    }, _options);
};

OperationManager.prototype = {

    runtimeInfo: function() {
        return RuntimeInfoFor(this.options.prefix);
    },

    pf: function(s) {
        return "#" + this.options.prefix + s;
    },

    newPrefix: function() {
        return this.options.prefix + "_New";
    },

    requestData: function(newPrefix) {
        log("OperationManager requestData");
        var formChildren = "";
        if (isFalse(this.options.isLite)) {
            if (empty(this.options.prefix)) //NormalWindow 
                formChildren = $("form *");
            else //PopupWindow
                formChildren = $(this.pf("panelPopup *") + ", #" + sfReactive + ", #" + sfTabId);
        }
        else {
            formChildren = $('#' + sfTabId);
        }
        formChildren = formChildren.not(".searchControl *");
        var requestData = formChildren.serialize();
        
        var info = this.runtimeInfo();
        var runtimeType = info.runtimeType();

        if (requestData.indexOf(this.options.prefix + sfRuntimeInfo) < 0)
        {
            if (empty(runtimeType))
                requestData += qp(this.options.prefix + sfRuntimeInfo, info.createValue(StaticInfoFor(this.options.prefix).staticType(), info.id(), info.isNew(), info.ticks()));
            else
                requestData += qp(this.options.prefix + sfRuntimeInfo, info.find().val());
        }
        requestData += qp("isLite", this.options.isLite)
                     + qp("sfRuntimeType", empty(runtimeType) ? StaticInfoFor(this.options.prefix).staticType() : runtimeType)
                     + qp("sfId", info.id())
                     + qp("sfOperationFullKey", this.options.operationKey)
                     + qp(sfPrefix, newPrefix)
                     + qp("sfOldPrefix", this.options.prefix)
                     + qp("sfOnOk", singleQuote(this.options.onOk));

        if (!empty(this.options.requestExtraJsonData)) {
            for (var key in this.options.requestExtraJsonData) {
                if (jQuery.isFunction(this.options.requestExtraJsonData[key]))
                    requestData += qp(key, this.options.requestExtraJsonData[key]());
                else
                    requestData += qp(key, this.options.requestExtraJsonData[key]);
            }
        }
        
        return requestData;
    },

    entityIsValid: function() {
        log("OperationManager entityIsValid");
        var info = this.runtimeInfo();
        var isValid = null;
        if (empty(this.options.prefix))
            isValid = new Validator({ controllerUrl: this.options.validationControllerUrl }).validate();
        else
            isValid = new PartialValidator({ controllerUrl: this.options.validationControllerUrl, prefix: this.options.prefix, type: info.runtimeType(), id: info.id() }).validate().isValid;
        if (!isValid) {
            window.alert(lang['popupErrorsStop']);
            return false;
        }
        return true;
    },

    executedSuccessfully: function(operationResult) {
        log("OperationManager executedSuccessfully");
        if (operationResult.indexOf("ModelState") < 0)
            return true;

        eval('var result=' + operationResult);
        var modelState = result["ModelState"];
        if (empty(this.options.prefix))
            new Validator().showErrors(modelState);
        else {
            var info = this.runtimeInfo();
            new PartialValidator({ prefix: this.options.prefix, type: info.runtimeType(), id: info.id() }).showErrors(modelState);
        }
        return false;
    },

    post: function() {
        log("OperationManager post");
        if (!empty(this.options.confirmMsg) && !confirm(this.options.confirmMsg))
            return;

        NotifyInfo(lang['executingOperation']);

        if (!this.options.avoidValidation && isFalse(this.options.isLite)) {
            if (!this.entityIsValid())
                return;
        }

        var info = this.runtimeInfo();
        if (info.find().length > 0)
        {
            $("form").append(hiddenInput('sfRuntimeType', info.runtimeType()) +
                hiddenInput('sfId', info.id()));
        }
        $("form").append(hiddenInput('isLite', this.options.isLite) +
            hiddenInput('sfOperationFullKey', this.options.operationKey) +
            hiddenInput(sfPrefix, this.options.prefix));
            
        if (!empty(this.options.requestExtraJsonData)) {
            for (var key in this.options.requestExtraJsonData) {
                if (jQuery.isFunction(this.options.requestExtraJsonData[key]))
                    $("form").append(hiddenInput(key, this.options.requestExtraJsonData[key]()));
                else<commit_msg>citas calendario<commit_after>﻿var OperationManager = function(_options) {
    this.options = $.extend({
        prefix: "",
        operationKey: null,
        isLite: false,
        controllerUrl: null,
        validationControllerUrl: null,
        avoidValidation: false,
        onOk: null,
        onCancelled: null,
        onOperationSuccess: null,
        multiStep: false,
        navigateOnSuccess: false,
        closePopupOnSuccess: false,
        confirmMsg: null,
        requestExtraJsonData: null,
    }, _options);
};

OperationManager.prototype = {

    runtimeInfo: function() {
        return RuntimeInfoFor(this.options.prefix);
    },

    pf: function(s) {
        return "#" + this.options.prefix + s;
    },

    newPrefix: function() {
        return this.options.prefix + "_New";
    },

    requestData: function(newPrefix) {
        log("OperationManager requestData");
        var formChildren = "";
        if (isFalse(this.options.isLite)) {
            if (empty(this.options.prefix)) //NormalWindow 
                formChildren = $("form *");
            else //PopupWindow
                formChildren = $(this.pf("panelPopup *") + ", #" + sfReactive + ", #" + sfTabId);
        }
        else {
            formChildren = $('#' + sfTabId);
        }
        formChildren = formChildren.not(".searchControl *");
        var requestData = formChildren.serialize();
        
        var info = this.runtimeInfo();
        var runtimeType = info.runtimeType();

        if (requestData.indexOf(this.options.prefix + sfRuntimeInfo) < 0)
        {
            if (empty(runtimeType))
                requestData += qp(this.options.prefix + sfRuntimeInfo, info.createValue(StaticInfoFor(this.options.prefix).staticType(), info.id(), info.isNew(), info.ticks()));
            else
                requestData += qp(this.options.prefix + sfRuntimeInfo, info.find().val());
        }
        requestData += qp("isLite", this.options.isLite)
                     + qp("sfRuntimeType", empty(runtimeType) ? StaticInfoFor(this.options.prefix).staticType() : runtimeType)
                     + qp("sfId", info.id())
                     + qp("sfOperationFullKey", this.options.operationKey)
                     + qp(sfPrefix, newPrefix)
                     + qp("sfOldPrefix", this.options.prefix)
                     + qp("sfOnOk", singleQuote(this.options.onOk));

        if (!empty(this.options.requestExtraJsonData)) {
            for (var key in this.options.requestExtraJsonData) {
                if (jQuery.isFunction(this.options.requestExtraJsonData[key]))
                    requestData += qp(key, this.options.requestExtraJsonData[key]());
                else
                    requestData += qp(key, this.options.requestExtraJsonData[key]);
            }
        }
        
        return requestData;
    },

    entityIsValid: function() {
        log("OperationManager entityIsValid");
        var info = this.runtimeInfo();
        var isValid = null;
        if (empty(this.options.prefix))
            isValid = new Validator({ controllerUrl: this.options.validationControllerUrl }).validate();
        else
            isValid = new PartialValidator({ controllerUrl: this.options.validationControllerUrl, prefix: this.options.prefix, type: info.runtimeType(), id: info.id() }).validate().isValid;
        if (!isValid) {
            window.alert(lang['popupErrorsStop']);
            return false;
        }
        return true;
    },

    executedSuccessfully: function(operationResult) {
        log("OperationManager executedSuccessfully");
        if (operationResult.indexOf("ModelState") < 0)
            return true;

        eval('var result=' + operationResult);
        var modelState = result["ModelState"];
        if (empty(this.options.prefix))
            new Validator().showErrors(modelState);
        else {
            var info = this.runtimeInfo();
            new PartialValidator({ prefix: this.options.prefix, type: info.runtimeType(), id: info.id() }).showErrors(modelState);
        }
        return false;
    },

    post: function() {
        log("OperationManager post");
        if (!empty(this.options.confirmMsg) && !confirm(this.options.confirmMsg))
            return;

        NotifyInfo(lang['executingOperation']);

        if (!this.options.avoidValidation && isFalse(this.options.isLite)) {
            if (!this.entityIsValid())
                return;
        }

        var info = this.runtimeInfo();
        if (info.find().length > 0)
        {
            $("form").append(hiddenInput('sfRuntimeType', info.runtimeType()) +
                hiddenInput('sfId', info.id()));
        }
        $("form").append(hiddenInput('isLite', this.options.isLite) +
            hiddenInput('sfOperationFullKey', this.options.operationKey) +
            hiddenInput("sfOldPrefix", this.options.prefix));
            
        if (!empty(this.options.requestExtraJsonData)) {
            for (var key in this.options.requestExtraJsonData) {
                if (jQuery.isFunction(this.options.requestExtraJsonData[key]))
                    $("form").append(hiddenInput(key, this.options.requestExtraJsonData[key]()));
                else
{'fraction_non_alphanumeric': 0.1297680659382787, 'fraction_numerical': 0.0005750431282346176, 'mean_word_length': 2.144966847498493, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4873276', 'n_tokens_mistral': 2784, 'n_tokens_neox': 2725, 'n_words': 498}