var AjaxMethod;
(function (AjaxMethod) {
    AjaxMethod["POST"] = "POST";
    AjaxMethod["GET"] = "GET";
})(AjaxMethod || (AjaxMethod = {}));
var AjaxOptions = (function () {
    function AjaxOptions(fileds) {
        if (fileds) {
            Object.assign(this, fileds);
        }
    }
    return AjaxOptions;
}());
var AjaxService = (function () {
    function AjaxService() {
    }
    AjaxService.prototype.send = function (options) {
        var that = this;
        var call = $.ajax({
            url: options.url,
            type: options.method,
            data: options.data,
            success: function (d) {
                if (options.callback) {
                    options.callback(d);
                }
                if (options.successMsg) {
                    DevExpress.ui.notify(options.successMsg, "success", 5000);
                }
            },
            error: function (d) {
                if (options.errorCallback) {
                    options.errorCallback(d);
                }
                if (options.errorMsg) {
                    DevExpress.ui.notify(options.errorMsg, "error", 5000);
                }
            }
        });
        return call;
    };
    return AjaxService;
}());

var BaseView = (function () {
    function BaseView() {
        this.BindLayoutMenu();
        this.LogDbCallsErrors();
    }
    BaseView.prototype.BindLayoutMenu = function () {
        if (document.location.href.indexOf('Scheduler') <= -1 && (document.location.href.indexOf('Reports') > -1 || document.location.href.indexOf('Visualize') > -1)) {
            $('#reportsMenuDx').addClass('active');
            $('#usersMenuDx').removeClass('active');
            $('#logsMenuDx').removeClass('active');
            if (this.IsDefined($('#scheduleMenuDx'))) {
                $('#scheduleMenuDx').removeClass('active');
            }
        }
        else if (document.location.href.indexOf('Management') > -1 ||
            document.location.href.indexOf('ConnectionProfiles') > -1 ||
            document.location.href.indexOf('Settings') > -1) {
            $('#reportsMenuDx').removeClass('active');
            $('#usersMenuDx').addClass('active');
            $('#logsMenuDx').removeClass('active');
            if (this.IsDefined($('#scheduleMenuDx'))) {
                $('#scheduleMenuDx').removeClass('active');
            }
        }
        else if (document.location.href.indexOf('Logs') > -1) {
            $('#reportsMenuDx').removeClass('active');
            $('#usersMenuDx').removeClass('active');
            $('#logsMenuDx').addClass('active');
            if (this.IsDefined($('#scheduleMenuDx'))) {
                $('#scheduleMenuDx').removeClass('active');
            }
        }
        else if (document.location.href.indexOf('Scheduler') > -1) {
            $('#reportsMenuDx').removeClass('active');
            $('#usersMenuDx').removeClass('active');
            $('#logsMenuDx').removeClass('active');
            if (this.IsDefined($('#scheduleMenuDx'))) {
                $('#scheduleMenuDx').addClass('active');
            }
        }
        $('#reportsMenuDx').on("click", function (e) {
            document.location.href = "/Reports/Index";
        });
        $('#usersMenuDx').on("click", function (e) {
            document.location.href = "/Management/Index";
        });
        $('#logsMenuDx').on("click", function (e) {
            document.location.href = "/Logs/Index";
        });
        if (this.IsDefined($('#scheduleMenuDx'))) {
            $('#scheduleMenuDx').on("click", function (e) {
                document.location.href = "/Reports/Scheduler";
            });
        }
    };
    BaseView.prototype.IsNotEmpty = function (obj) {
        return this.IsDefined(obj) && obj !== "" && obj !== " ";
    };
    BaseView.prototype.IsDefined = function (obj) {
        return typeof obj !== 'undefined' && obj !== null;
    };
    BaseView.prototype.LogDbCallsErrors = function () {
        var that = this;
        DevExpress.data.setErrorHandler(function (error) {
            that.StatusCheck().done(function () {
                DevExpress.ui.notify("Error occured: " + error.message, "error", 5500);
            });
        });
    };
    BaseView.prototype.StatusCheck = function () {
        return $.ajax({
            url: '/Visualize/StatusCheck',
            type: "GET",
            statusCode: {
                401: function () {
                    window.location.reload();
                }
            }
        });
    };
    BaseView.prototype.LogError = function (msg, time, height) {
        DevExpress.ui.notify({ message: msg, height: height }, "error", time != null ? time : 5500);
    };
    BaseView.prototype.Info = function (msg, time, height) {
        DevExpress.ui.notify({ message: msg, height: height }, "info", this.IsDefined(time) ? time : 5500);
    };
    BaseView.prototype.Loading = function (text) {
        var loadingPanel = $('#wrLoadingPanel').dxLoadPanel("instance");
        return loadingPanel;
    };
    BaseView.prototype.IsMobile = function () {
        var currentWidth = $(window).width();
        return currentWidth < 992;
    };
    return BaseView;
}());
document.addEventListener("DOMContentLoaded", function documentReady() {
    this.removeEventListener("DOMContentLoaded", documentReady);
    var view = new BaseView();
});

var ParameterViewModel = (function () {
    function ParameterViewModel() {
    }
    return ParameterViewModel;
}());

var ReportViewModel = (function () {
    function ReportViewModel() {
    }
    return ReportViewModel;
}());

var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var ParameterType;
(function (ParameterType) {
    ParameterType["COMBOBOX"] = "Combobox";
    ParameterType["VALUE"] = "Value";
    ParameterType["DATETIMEPICKER"] = "DateTimePicker";
    ParameterType["IN"] = "IN";
    ParameterType["IN_NO_PARENTHESIS"] = "INNoParenthesis";
})(ParameterType || (ParameterType = {}));
var ParametersPopupType;
(function (ParametersPopupType) {
    ParametersPopupType[ParametersPopupType["Report"] = 0] = "Report";
    ParametersPopupType[ParametersPopupType["InMemory"] = 1] = "InMemory";
    ParametersPopupType[ParametersPopupType["Download"] = 2] = "Download";
    ParametersPopupType[ParametersPopupType["Scheduled"] = 3] = "Scheduled";
})(ParametersPopupType || (ParametersPopupType = {}));
var ParametersView = (function (_super) {
    __extends(ParametersView, _super);
    function ParametersView(containerId, reportDetails, type, paramtersForScheduler) {
        if (type === void 0) { type = ParametersPopupType.Report; }
        if (paramtersForScheduler === void 0) { paramtersForScheduler = false; }
        var _this = _super.call(this) || this;
        _this.callController = "/Parameters";
        _this.currentPage = 1;
        _this.dynamicGridPages = [];
        _this.backBtnId = "#backPageDx";
        _this.nextBtnId = "#nextPageDx";
        _this.submitBtnId = "#submitParamsDx";
        _this.type = ParametersPopupType.Report;
        _this.paramtersForScheduler = false;
        _this.callVariableExec = [];
        _this.callVariableFilter = false;
        _this.popupId = containerId;
        _this.reportDetails = reportDetails;
        _this.currentPage = 1;
        _this.dynamicGridPages = [];
        _this.type = type;
        _this.paramtersForScheduler = paramtersForScheduler;
        _this.ajaxService = new AjaxService();
        return _this;
    }
    ParametersView.prototype.CallVariableFilter = function (e, clientId, isVariableCheck) {
        if (isVariableCheck === void 0) { isVariableCheck = true; }
        var that = this;
        var variableFilterValue = "_VariableFilterValue";
        var value = null;
        if (e && e.value) {
            value = e.value;
        }
        else if (e && e.selectedItem && e.selectedItem.Value) {
            value = e.selectedItem.Value;
        }
        else if (e && e.component) {
            value = e.component.option('value');
        }
        else {
            value = null;
        }
        if (value != null && Array.isArray(e.value)) {
            value = e.value.join('|,|');
        }
        if (value && clientId) {
            that.callVariableExec.push(clientId);
            that.CheckPageStatus();
            this.callVariableFilter = true;
            var decomposition = clientId.split("_");
            var viewModel = new ParameterViewModel();
            viewModel.ClientId = clientId;
            viewModel.Value = value;
            viewModel.VariableFilter = true;
            viewModel.VariableFilterValue = value;
            $('#' + clientId + variableFilterValue).val(value);
            var callUrl = this.callController + (isVariableCheck ? '/VariableFilterCheck' : '/ByParameterCheck');
            var data = {
                __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
                parameterValue: viewModel,
                reportName: that.reportDetails.Name,
                conID: that.reportDetails.ConnectionId
            };
            var callOptions = new AjaxOptions({
                url: callUrl,
                method: AjaxMethod.POST,
                data: data,
                callback: function (result) {
                    var that2 = that;
                    if (Array.isArray(result)) {
                        var models = result;
                        for (var i = 0; i < models.length; i++) {
                            var disabled = !models[i].EnabledByParameter;
                            var containerId = models[i].ClientId + '_Container';
                            var containerCss = disabled ? 'none' : '';
                            var updateValue = models[i].UpdateDefaultValue;
                            $("#" + containerId).css('display', containerCss);
                            switch (models[i].ClientType) {
                                case ParameterType.COMBOBOX:
                                    $("#" + models[i].ClientId).dxSelectBox("instance").option("disabled", disabled);
                                    $("#" + models[i].ClientId).dxSelectBox("instance").option("visible", !disabled);
                                    if (updateValue) {
                                        $("#" + models[i].ClientId).dxSelectBox("instance").option("value", models[i].DefaultValue);
                                    }
                                    break;
                                case ParameterType.DATETIMEPICKER:
                                    $("#" + models[i].ClientId).dxDateBox("instance").option("disabled", disabled);
                                    $("#" + models[i].ClientId).dxDateBox("instance").option("visible", !disabled);
                                    if (updateValue) {
                                        $("#" + models[i].ClientId).dxDateBox("instance").option("value", models[i].DefaultValue);
                                    }
                                    break;
                                case ParameterType.VALUE:
                                    $("#" + models[i].ClientId).dxTextBox("instance").option("disabled", disabled);
                                    $("#" + models[i].ClientId).dxTextBox("instance").option("visible", !disabled);
                                    if (updateValue) {
                                        $("#" + models[i].ClientId).dxTextBox("instance").option("value", models[i].DefaultValue);
                                    }
                                    break;
                                case ParameterType.IN:
                                case ParameterType.IN_NO_PARENTHESIS:
                                    $("#" + models[i].ClientId).dxList("instance").option("disabled", disabled);
                                    $("#" + models[i].ClientId + "Values").dxDataGrid("instance").option("disabled", disabled);
                                    $("#" + models[i].ClientId + "newText").dxTextBox("instance").option("disabled", disabled);
                                    $("#" + models[i].ClientId + "newValue").dxButton("instance").option("disabled", disabled);
                                    $("#" + models[i].ClientId + "addValue").dxButton("instance").option("disabled", disabled);
                                    $("#" + models[i].ClientId + "addAll").dxButton("instance").option("disabled", disabled);
                                    $("#" + models[i].ClientId + "delAll").dxButton("instance").option("disabled", disabled);
                                    $("#" + models[i].ClientId + "delValue").dxButton("instance").option("disabled", disabled);
                                    $("#" + models[i].ClientId).dxList("instance").option("visible", !disabled);
                                    $("#" + models[i].ClientId + "Values").dxDataGrid("instance").option("visible", !disabled);
                                    $("#" + models[i].ClientId + "newText").dxTextBox("instance").option("visible", !disabled);
                                    $("#" + models[i].ClientId + "newValue").dxButton("instance").option("visible", !disabled);
                                    $("#" + models[i].ClientId + "addValue").dxButton("instance").option("visible", !disabled);
                                    $("#" + models[i].ClientId + "addAll").dxButton("instance").option("visible", !disabled);
                                    $("#" + models[i].ClientId + "delAll").dxButton("instance").option("visible", !disabled);
                                    $("#" + models[i].ClientId + "delValue").dxButton("instance").option("visible", !disabled);
                                default:
                                    break;
                            }
                        }
                    }
                    that.callVariableFilter = false;
                    that.callVariableExec.pop();
                    that.CheckPageStatus();
                },
                errorCallback: function (result) {
                    that.callVariableExec.pop();
                    that.CheckPageStatus();
                },
                errorMsg: "Error occurs during operation",
            });
            this.ajaxService.send(callOptions);
        }
    };
    ParametersView.prototype.GetDonwloadType = function () {
        return this.donwloadType;
    };
    ParametersView.prototype.SubmitParamters = function () {
        var that = this;
        this.Loading().show();
        var paramters = this.GetWizardParameters();
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
            viewParameters: paramters,
            reportQuery: that.reportDetails
        };
        if (this.type === ParametersPopupType.Download && this.IsDefined($("#downloadFileTypeDx").dxSelectBox('instance'))) {
            data["downloadType"] = $("#downloadFileTypeDx").dxSelectBox('instance').option('value');
        }
        if (this.paramtersForScheduler) {
            if (this.type === ParametersPopupType.Download && this.IsDefined($("#downloadFileTypeDx").dxSelectBox('instance'))) {
                this.donwloadType = $("#downloadFileTypeDx").dxSelectBox('instance').option('value');
            }
            that.GetPopup().hide();
            that.Loading().hide();
            return;
        }
        var callOptions = new AjaxOptions({
            url: this.GetSubmitAction(this.type),
            method: AjaxMethod.POST,
            data: data,
            callback: function (d) {
                that.GetPopup().hide();
                that.GetPopup().option('contentTemplate', null);
                if (that.type === ParametersPopupType.InMemory) {
                    DevExpress.ui.notify("Please Wait. Report will soon finish execution and redirect you to result page", "success", 15000);
                    document.location.href = d;
                }
                else {
                    that.Loading().hide();
                }
            },
            errorCallback: function (d) {
                DevExpress.ui.notify("Error running report. Check error logs for additional information.", "error", 5000);
                that.Loading().hide();
            },
            successMsg: that.type === ParametersPopupType.InMemory ? null : "The report has been sent for execution and will be on the Completed page when available.",
        });
        this.ajaxService.send(callOptions);
    };
    ParametersView.prototype.GetSubmitAction = function (type) {
        switch (type) {
            case ParametersPopupType.InMemory:
                return this.callController + '/Execute';
            case ParametersPopupType.Download:
                return this.callController + '/Download';
            case ParametersPopupType.Report:
                return this.callController + '/Submit';
            default:
                throw new Error('Not supported ParametersPopupType');
        }
    };
    ParametersView.prototype.GetWizardParameters = function () {
        var variableFilter = "_VariableFilter";
        var order = "_Order";
        var variableFilterValue = "_VariableFilterValue";
        var dynamicDefault = "_IsDynamicDefault";
        var defaultValue = "_DefaultValue";
        var parameterPage = "_Page";
        var parameterType = "_Type";
        var ctrls = $('input[id*="parameterClientId"]');
        var paramters = [];
        if (ctrls.length > 0) {
            ctrls.each(function (i) {
                var ctrlName = $(ctrls[i]).val().toString();
                var decomposition = ctrlName.split("_");
                if (decomposition.length > 0 && decomposition.length === 3) {
                    var value = null;
                    try {
                        switch (decomposition[1]) {
                            case ParameterType.COMBOBOX:
                                value = $("#" + ctrlName).dxSelectBox("instance").option("value");
                                break;
                            case ParameterType.DATETIMEPICKER:
                                value = $("#" + ctrlName).dxDateBox("instance").option("value");
                                break;
                            case ParameterType.VALUE:
                                value = $("#" + ctrlName).dxTextBox("instance").option("value");
                                break;
                            case ParameterType.IN:
                            case ParameterType.IN_NO_PARENTHESIS:
                                value = $("#" + ctrlName).dxList("instance").option("items").join('|,|');
                                break;
                            default:
                                break;
                        }
                        var viewModel = new ParameterViewModel();
                        viewModel.ClientId = ctrlName;
                        viewModel.Value = value;
                        viewModel.Order = parseInt($('#' + ctrlName + order).val().toString());
                        viewModel.VariableFilter = $('#' + ctrlName + variableFilter).val() === "True";
                        viewModel.VariableFilterValue = $('#' + ctrlName + variableFilterValue).val().toString();
                        viewModel.IsDynamicDefault = $('#' + ctrlName + dynamicDefault).val() === "True";
                        viewModel.DefaultValue = $('#' + ctrlName + defaultValue).val().toString();
                        viewModel.Page = parseInt($('#' + ctrlName + parameterPage).val().toString());
                        viewModel.ClientType = $('#' + ctrlName + parameterType).val().toString();
                        paramters.push(viewModel);
                    }
                    catch (err) {
                        console.log(err);
                    }
                }
            });
        }
        return paramters;
    };
    ParametersView.prototype.GetCurrentReportName = function () {
        return this.reportDetails.Name;
    };
    ParametersView.prototype.GetCurrentConnectionProfile = function () {
        return this.reportDetails.ConnectionId;
    };
    ParametersView.prototype.AddAll = function (gridId, listId) {
        if (gridId && listId) {
            var grid_1 = $('#' + gridId).dxDataGrid("instance");
            var list_1 = $('#' + listId).dxList("instance");
            if (grid_1 && list_1) {
                grid_1.option('remoteOperations', false);
                grid_1.option('scrolling.mode', 'standard');
                grid_1.getDataSource().load().done(function (data) {
                    var items = data.map(function (m) { return m.Value; });
                    var existedItems = list_1.option('items');
                    if (existedItems.length > 0) {
                        for (var i = 0; i < existedItems.length; i++) {
                            if (items.indexOf(existedItems[i]) === -1) {
                                items.push(existedItems[i]);
                            }
                        }
                    }
                    list_1.option('items', []);
                    list_1.option('items', items);
                    grid_1.option('remoteOperations', true);
                    grid_1.option('scrolling.mode', 'infinite');
                }).fail(function () {
                    grid_1.option('remoteOperations', true);
                    grid_1.option('scrolling.mode', 'infinite');
                });
            }
        }
    };
    ParametersView.prototype.AddNewValue = function (textId, listId, gridId, RestrictedList) {
        if (textId && listId) {
            var newText = $('#' + textId).dxTextBox("instance");
            var list = $('#' + listId).dxList("instance");
            var grid = $('#' + gridId).dxDataGrid("instance");
            if (newText && list) {
                var value = newText.option('value');
                var items_1 = list.option('items');
                var restrictedItems_1 = [];
                var existedItems_1 = [];
                if (RestrictedList == true) {
                    grid.getDataSource().load().done(function (data) {
                        existedItems_1 = data.map(function (m) { return m.Value; });
                    }).fail(function () {
                    });
                }
                if (value) {
                    if (value.includes(',')) {
                        var individualValues = value.split(',');
                        individualValues.forEach(function (individualValue) {
                            var trimmedValue = individualValue.trim();
                            var upperValue = trimmedValue.toUpperCase();
                            if (items_1.indexOf(trimmedValue) === -1) {
                                if (RestrictedList === true) {
                                    var match = existedItems_1.find(function (ei) { return ei.toUpperCase() === upperValue; });
                                    if (match) {
                                        items_1.push(match);
                                    }
                                    else {
                                        restrictedItems_1.push(trimmedValue);
                                    }
                                }
                                else {
                                    items_1.push(trimmedValue);
                                }
                            }
                        });
                    }
                    else {
                        var trimmedValue = value.trim();
                        if (items_1.indexOf(trimmedValue) === -1) {
                            var upperValue_1 = trimmedValue.toUpperCase();
                            if (RestrictedList === true) {
                                var match = existedItems_1.find(function (ei) { return ei.toUpperCase() === upperValue_1; });
                                if (match) {
                                    items_1.push(match);
                                }
                                else {
                                    restrictedItems_1.push(trimmedValue);
                                }
                            }
                            else {
                                items_1.push(trimmedValue);
                            }
                        }
                    }
                    list.option('items', items_1);
                    if (restrictedItems_1.length > 0) {
                        var itemsShowing = restrictedItems_1.slice(0, 10).join(', ');
                        DevExpress.ui.dialog.alert("There were ".concat(restrictedItems_1.length, " values restricted. Up to 10 of the values will be shown: ").concat(itemsShowing, "."), "Restricted Items");
                    }
                }
            }
        }
    };
    ParametersView.prototype.AddValue = function (gridId, listId) {
        if (gridId && listId) {
            var grid = $('#' + gridId).dxDataGrid("instance");
            var list = $('#' + listId).dxList("instance");
            if (grid && list) {
                var values = grid.getSelectedRowsData().map(function (m) { return m.Value; });
                var items = list.option('items');
                if (values.length > 0) {
                    for (var i = 0; i < values.length; i++) {
                        if (items.indexOf(values[i]) === -1) {
                            items.push(values[i]);
                        }
                    }
                    list.option('items', items);
                }
            }
        }
    };
    ParametersView.prototype.RemoveValue = function (gridId, listId) {
        if (gridId && listId) {
            var grid = $('#' + gridId).dxDataGrid("instance");
            var list = $('#' + listId).dxList("instance");
            if (grid && list) {
                var items = list.option('items');
                var toremove = list.option('selectedItems');
                if (toremove.length > 0) {
                    for (var i = 0; i < toremove.length; i++) {
                        var index = items.indexOf(toremove[i]);
                        if (index !== -1) {
                            items.splice(index, 1);
                        }
                    }
                    list.option('items', items);
                }
            }
        }
    };
    ParametersView.prototype.RemoveAll = function (gridId, listId) {
        if (gridId && listId) {
            var grid = $('#' + gridId).dxDataGrid("instance");
            var list = $('#' + listId).dxList("instance");
            if (grid && list) {
                list.option('items', []);
            }
        }
    };
    ParametersView.prototype.GetParameters = function () {
        var that = this;
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
            reportName: this.reportDetails.Name,
            conID: this.reportDetails.ConnectionId
        };
        var callOptions = new AjaxOptions({
            url: that.type === ParametersPopupType.Download ? this.callController + '/GetParametersForDownloads' : this.callController + '/GetParameters',
            method: AjaxMethod.POST,
            data: data,
            callback: function (d) { that.PopupForm.call(that, d, "Parameters"); that.Loading().hide(); },
            errorMsg: "Error occurs during operation"
        });
        if (this.type !== ParametersPopupType.Download && this.reportDetails.Name) {
            var callOptionsForCheck = new AjaxOptions({
                url: this.callController + '/HasParameters',
                method: AjaxMethod.POST,
                data: data,
                callback: function (d) {
                    if (!d) {
                        that.SubmitParamters();
                    }
                    else {
                        that.ajaxService.send(callOptions);
                    }
                    that.Loading().show();
                },
                errorMsg: "Error occurs during operation"
            });
            this.ajaxService.send(callOptionsForCheck);
        }
        if (this.type === ParametersPopupType.Download && this.reportDetails.Name) {
            this.ajaxService.send(callOptions);
        }
    };
    ParametersView.prototype.PopupForm = function (content, title, show) {
        if (show === void 0) { show = true; }
        var popup = this.GetPopup();
        if (this.IsMobile()) {
            popup.option('width', '700px');
            popup.option('height', '370px');
        }
        popup.option('contentTemplate', null);
        popup.option('contentTemplate', $(content));
        if (show) {
            popup.show();
        }
        this.SetupPaging();
    };
    ParametersView.prototype.GetPopup = function () {
        var popup = $(this.popupId).dxPopup("instance");
        return popup;
    };
    ParametersView.prototype.ValidateList = function (listId, listValidatorId, group) {
        if (listId && listValidatorId) {
            $("#" + listValidatorId).dxValidator({
                validationGroup: group,
                adapter: {
                    getValue: function () {
                        var list = $("#" + listId).dxList("option", "items");
                        return list.length > 0 || $("#" + listId).dxList("option", "disabled");
                    },
                    applyValidationResults: function (e) {
                        $("#" + listId).css({ "border": e.isValid ? "none" : "1px solid red" });
                    },
                },
                validationRules: [{
                        type: "required",
                        message: 'Specify at least one item!'
                    }]
            });
        }
    };
    ParametersView.prototype.SetDynamicPage = function (skipId, gridId, pageId, listId) {
        var that = this;
        var grid = $("#" + gridId).dxDataGrid("instance");
        $('#' + listId).on("dxdblclick", function (e) {
            that.RemoveValueFromList(e.currentTarget.id);
        });
        var firstCallEnd = $('#skipFirstCallFor' + skipId).val() === 'True';
        if (firstCallEnd && this.IsNotEmpty(skipId) && this.IsNotEmpty(gridId) && this.IsNotEmpty(pageId)) {
            $('#skipFirstCallFor' + skipId).val('False');
            this.dynamicGridPages.push({ page: parseInt(pageId), grid: gridId });
            if (pageId === "1") {
                grid.refresh().done(function () { that.CheckColumnVisibility("#" + gridId); });
            }
        }
        grid.repaint();
    };
    ParametersView.prototype.RemoveValueFromList = function (listId) {
        if (listId) {
            var list = $('#' + listId).dxList("instance");
            var toRemove = list.option('selectedItems');
            if (list && toRemove.length > 0) {
                var items = list.option('items');
                var index = items.indexOf(toRemove[0]);
                if (index !== -1) {
                    items.splice(index, 1);
                }
                list.option('items', items);
            }
        }
    };
    ParametersView.prototype.AddValueToList = function (e, listId) {
        if (e && e.data && listId) {
            var list = $('#' + listId).dxList("instance");
            if (list) {
                var items = list.option('items');
                if (items.indexOf(e.data.Value) === -1) {
                    items.push(e.data.Value);
                }
                list.option('items', items);
            }
        }
    };
    ParametersView.prototype.CheckColumnVisibility = function (gridId) {
        var _this = this;
        var grid = $(gridId).dxDataGrid("instance");
        var descriptionExsits = grid.getDataSource().items().filter(function (d) { return _this.IsNotEmpty(d.Description); });
        if (this.IsDefined(descriptionExsits) && descriptionExsits.length > 0) {
            grid.columnOption("Description", "visible", true);
            grid.repaint();
        }
    };
    ParametersView.prototype.SetupPaging = function () {
        var _this = this;
        var that = this;
        this.backBtn = $(this.backBtnId).dxButton("instance");
        this.backBtn.option("onClick", function (e) {
            var that2 = that;
            $('#page' + that.currentPage).css("display", "none");
            that.currentPage--;
            if (that.currentPage <= 0) {
                that.currentPage = 1;
            }
            if (that.currentPage != 1) {
                var Parameterfound = void 0;
                for (var i = that.currentPage + 1; i >= 1; i--) {
                    var paramtersOnPage = that.GetWizardParameters().filter(function (m) { return m.Page == that.currentPage; });
                    if (!paramtersOnPage || paramtersOnPage.length <= 0) {
                        that.currentPage--;
                    }
                    else {
                        for (var j = 0; j < paramtersOnPage.length; j++) {
                            var visible = that.GetParamterVisibility(paramtersOnPage[j]);
                            if (!visible) {
                                continue;
                            }
                            else {
                                Parameterfound = true;
                                break;
                            }
                        }
                        if (!Parameterfound) {
                            that.currentPage--;
                        }
                        else {
                            break;
                        }
                    }
                }
            }
            if (that.currentPage <= 1) {
                that.currentPage = 1;
            }
            var dynamicPage = that.dynamicGridPages.filter(function (m) { return m.page === that.currentPage; });
            if (dynamicPage && dynamicPage.length > 0) {
                var interval = setInterval(function () {
                    if (!that.callVariableFilter) {
                        for (var i = 0; i < dynamicPage.length; i++) {
                            var id = "#" + dynamicPage[i].grid;
                            var grid = $(id).dxDataGrid("instance");
                            if (grid && !grid.option('disabled')) {
                                var newIdToCall = id;
                                clearInterval(interval);
                                grid.refresh().done(function () {
                                    that2.CheckColumnVisibility(newIdToCall);
                                });
                            }
                        }
                    }
                }, 250);
            }
            $('#page' + that.currentPage).css("display", "flex");
            that.CheckPageStatus();
        });
        this.nextBtn = $(this.nextBtnId).dxButton("instance");
        this.nextBtn.option("onClick", function (e) {
            var that2 = that;
            if (that.IsValidationSuccessful(that.currentPage)) {
                $('#page' + that.currentPage).css("display", "none");
                var lastPage = parseInt($('#lastPage').val().toString());
                that.currentPage++;
                var Parameterfound = void 0;
                for (var i = that.currentPage - 1; i <= lastPage; i++) {
                    var paramtersOnPage = that.GetWizardParameters().filter(function (m) { return m.Page == that.currentPage; });
                    if (!paramtersOnPage || paramtersOnPage.length <= 0) {
                        that.currentPage++;
                    }
                    else {
                        for (var j = 0; j < paramtersOnPage.length; j++) {
                            var visible = that.GetParamterVisibility(paramtersOnPage[j]);
                            if (!visible) {
                                continue;
                            }
                            else {
                                Parameterfound = true;
                                break;
                            }
                        }
                        if (!Parameterfound) {
                            that.currentPage++;
                        }
                        else {
                            break;
                        }
                    }
                }
                if (that.currentPage >= lastPage) {
                    that.currentPage = lastPage;
                }
                var dynamicPage = that.dynamicGridPages.filter(function (m) { return m.page === that.currentPage; });
                if (dynamicPage && dynamicPage.length > 0) {
                    var interval = setInterval(function () {
                        if (!that.callVariableFilter) {
                            for (var i = 0; i < dynamicPage.length; i++) {
                                var id = "#" + dynamicPage[i].grid;
                                var grid = $(id).dxDataGrid("instance");
                                if (grid && !grid.option('disabled')) {
                                    var newIdToCall = id;
                                    clearInterval(interval);
                                    grid.refresh().done(function () {
                                        that2.CheckColumnVisibility(newIdToCall);
                                    });
                                }
                            }
                        }
                    }, 250);
                }
                $('#page' + that.currentPage).css("display", "flex");
                that.CheckPageStatus();
            }
            else {
                DevExpress.ui.notify("Enter required value(s) on page", "error", 3000);
            }
        });
        this.submitBtn = $(this.submitBtnId).dxButton("instance");
        this.submitBtn.option("onClick", function (e) {
            var that = _this;
            if (that.IsValidationSuccessful(that.currentPage)) {
                that.SubmitParamters();
                if (!_this.paramtersForScheduler) {
                    that.CheckPageStatus();
                }
            }
        });
        if (this.paramtersForScheduler) {
            this.submitBtn.option('text', 'Schedule');
        }
        this.CheckPageStatus();
    };
    ParametersView.prototype.GetParamterVisibility = function (paramter) {
        var containerId = paramter.ClientId + '_Container';
        var temp = $("#" + containerId).css('display');
        var isVisible = $("#" + containerId).css('display') == 'none';
        return !isVisible;
    };
    ParametersView.prototype.IsValidationSuccessful = function (currentPage) {
        var groups = DevExpress.validationEngine.groups;
        if (groups) {
            var groupExists = groups.find(function (g) { return g.group === currentPage.toString(); });
            if (groupExists) {
                var result = DevExpress.validationEngine.validateGroup(currentPage.toString());
                return result.isValid;
            }
            else {
                return true;
            }
        }
        else {
            console.log("Parameters: Validation groups not setup.");
            return true;
        }
    };
    ParametersView.prototype.CheckPageStatus = function () {
        var lastPage = parseInt($('#lastPage').val().toString());
        $('#currentPage').val(this.currentPage);
        if (this.backBtn) {
            this.backBtn.option('disabled', this.currentPage === 1);
        }
        if (this.nextBtn) {
            this.nextBtn.option('disabled', lastPage === this.currentPage || this.callVariableExec.length !== 0);
        }
        if (this.submitBtn) {
            this.submitBtn.option('disabled', !(lastPage === this.currentPage));
        }
    };
    return ParametersView;
}(BaseView));
