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 __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 ManagmentView = (function (_super) {
    __extends(ManagmentView, _super);
    function ManagmentView() {
        var _this = _super.call(this) || this;
        _this.callController = "/Management";
        _this.selectedRole = null;
        _this.reportsManagementSelectedIndex = -1;
        _this.ajaxService = new AjaxService();
        _this.SetupGridsInstances();
        _this.SetupGridsCmds();
        return _this;
    }
    ManagmentView.prototype.GetLoadPanelInstance = function () {
        return $("#loadingDx").dxLoadPanel("instance");
    };
    ManagmentView.prototype.RoleUsersGridLoaded = function (s, e) {
        if (s && s.length > 0) {
            var toSelect = s.filter(function (m) { return m.IsInRole; }).map(function (r) { return r.CurrentId; });
            if (toSelect && toSelect.length > 0) {
                $("#roleUsersGridDx").dxDataGrid("instance").option('selectedRowKeys', toSelect);
            }
        }
    };
    ManagmentView.prototype.AssignUsersToRole = function () {
        var that = this;
        this.GetLoadPanelInstance().show();
        var callUrl = this.callController + '/AssignUsersToRole';
        var selectedRowKeys = $("#roleUsersGridDx").dxDataGrid("instance").option('selectedRowKeys');
        var delimitedString = selectedRowKeys.join(',');
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
            roleId: $('#RoleId').val(),
            selectedUsersIds: delimitedString
        };
        var callOptions = new AjaxOptions({
            url: callUrl,
            method: AjaxMethod.POST,
            data: data,
            callback: function (d) {
                that.GetPopup().hide();
                that.userGridDx.refresh();
                that.GetLoadPanelInstance().hide();
            },
            errorCallback: function (r) {
                that.GetLoadPanelInstance().hide();
            },
            errorMsg: "Error occurs during operation",
            successMsg: "Users accounts successfully asigned to role"
        });
        this.ajaxService.send(callOptions);
    };
    ManagmentView.prototype.AssignDomainUsers = function () {
        var that = this;
        this.GetLoadPanelInstance().show();
        var callUrl = this.callController + '/AssignDomainUsers';
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
            selectedUsersIds: $("#domainUsersGridDx").dxDataGrid("instance").option('selectedRowKeys'),
            roles: $("#usersADRolesDx").dxDropDownBox("instance").option('value')
        };
        var callOptions = new AjaxOptions({
            url: callUrl,
            method: AjaxMethod.POST,
            data: data,
            callback: function (d) {
                that.GetPopup().hide();
                that.userGridDx.refresh();
                that.GetLoadPanelInstance().hide();
            },
            errorCallback: function (r) {
                that.GetLoadPanelInstance().hide();
            },
            errorMsg: "Error occurs during operation",
            successMsg: "Users accounts successfully asigned"
        });
        this.ajaxService.send(callOptions);
    };
    ManagmentView.prototype.AddDomainUsers = function () {
        var that = this;
        var callUrl = this.callController + '/AddDomainUsers';
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
        };
        var callOptions = new AjaxOptions({
            url: callUrl,
            method: AjaxMethod.POST,
            data: data,
            callback: function (d) { that.PopupForm.call(that, d, "Add Users from Domain", true, true); },
            errorMsg: "Error occurs during operation"
        });
        this.ajaxService.send(callOptions);
    };
    ManagmentView.prototype.AddUsersToRole = function (e) {
        var that = this;
        var callUrl = this.callController + '/AddUsersToRole';
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
            roleId: e.row.data.Id,
            roleName: e.row.data.Name
        };
        var callOptions = new AjaxOptions({
            url: callUrl,
            method: AjaxMethod.POST,
            data: data,
            callback: function (d) { that.PopupForm.call(that, d, "Add Users To Role", true, true); },
            errorMsg: "Error occurs during operation"
        });
        this.ajaxService.send(callOptions);
    };
    ManagmentView.prototype.ReportsManagement = function (e) {
        var that = this;
        var callUrl = this.callController + '/ReportsManagement';
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
        };
        var callOptions = new AjaxOptions({
            url: callUrl,
            method: AjaxMethod.POST,
            data: data,
            callback: function (d) { that.PopupForm.call(that, d, null, true, true); },
            errorMsg: "Error occurs during operation"
        });
        this.ajaxService.send(callOptions);
    };
    ManagmentView.prototype.ReportsManagementEdit = function (e) {
        var that = this;
        var update = "Update";
        var edit = "Edit Selected";
        var btnUpdateMode = $("#editRowManagmentDx").dxButton("instance").option("text") === update;
        if (btnUpdateMode) {
            $("#reportsManagementGridDx").dxDataGrid("instance").saveEditData().done(function () {
                $("#reportsManagementGridDx").dxDataGrid("instance").deselectAll();
            });
            $("#editRowManagmentDx").dxButton("instance").option("text", edit);
            $("#cancelRowManagmentDx").dxButton("instance").option("disabled", true);
            this.reportsManagementSelectedIndex = -1;
        }
        else {
            if (this.reportsManagementSelectedIndex >= 0) {
                $("#reportsManagementGridDx").dxDataGrid("instance").editRow(this.reportsManagementSelectedIndex);
                $("#editRowManagmentDx").dxButton("instance").option("text", update);
                $("#cancelRowManagmentDx").dxButton("instance").option("disabled", false);
            }
        }
    };
    ManagmentView.prototype.ReportsManagementDelete = function (e) {
        var that = this;
        if (this.reportsManagementSelectedIndex >= 0) {
            var result = DevExpress.ui.dialog.confirm("<strong>Are you sure?</strong>", "Delete");
            result.done(function (dialogResult) {
                if (dialogResult) {
                    $("#reportsManagementGridDx").dxDataGrid("instance").deleteRow(that.reportsManagementSelectedIndex);
                    that.reportsManagementSelectedIndex = -1;
                }
            });
            $("#cancelRowManagmentDx").dxButton("instance").option("disabled", true);
        }
    };
    ManagmentView.prototype.ReportsManagementCancel = function (e) {
        var that = this;
        var edit = "Edit Selected";
        $("#editRowManagmentDx").dxButton("instance").option("text", edit);
        $("#reportsManagementGridDx").dxDataGrid("instance").cancelEditData();
        $("#cancelRowManagmentDx").dxButton("instance").option("disabled", true);
    };
    ManagmentView.prototype.ReportsManagementOnSelectionChanged = function (e) {
        if (e.selectedRowKeys && e.selectedRowKeys[0]) {
            $("#editRowManagmentDx").dxButton("instance").option("disabled", false);
            $("#deleteRowManagmentDx").dxButton("instance").option("disabled", false);
            var key = e.selectedRowKeys[0];
            var rowIndex = $("#reportsManagementGridDx").dxDataGrid("instance").getRowIndexByKey(key);
            this.reportsManagementSelectedIndex = rowIndex;
        }
        else {
            $("#editRowManagmentDx").dxButton("instance").option("disabled", true);
            $("#deleteRowManagmentDx").dxButton("instance").option("disabled", true);
            this.reportsManagementSelectedIndex = -1;
        }
    };
    ManagmentView.prototype.InviteUsers = function (e) {
        var that = this;
        var callUrl = this.callController + '/InviteUsers';
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
        };
        var callOptions = new AjaxOptions({
            url: callUrl,
            method: AjaxMethod.POST,
            data: data,
            callback: function (d) { that.PopupFormCustom.call(that, d, "Invite Users", true, '425px', '745px'); },
            errorMsg: "Error occurs during operation"
        });
        this.ajaxService.send(callOptions);
    };
    ManagmentView.prototype.InviteUsersSubmit = function (e) {
        var that = this;
        this.GetLoadPanelInstance().show();
        var callUrl = this.callController + '/InviteUsersSubmit';
        var selectedConnProfiles = $("#publisherConnProfilesDx").dxDropDownBox("instance").option('value') &&
            $("#publisherConnProfilesDx").dxDropDownBox("instance").option('value').length > 0
            ? $("#publisherConnProfilesDx").dxDropDownBox("instance").option('value')
            : [];
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
            emails: $("#emailsDx").dxTextArea("instance").option('value'),
            roles: $("#usersInviteRolesDx").dxDropDownBox("instance").option('value'),
            selectedConnectionProfiles: selectedConnProfiles
        };
        var callOptions = new AjaxOptions({
            url: callUrl,
            method: AjaxMethod.POST,
            data: data,
            callback: function (d) {
                that.GetPopup().hide();
                that.userGridDx.refresh();
                that.GetLoadPanelInstance().hide();
            },
            errorCallback: function (r) {
                if (r.responseText) {
                    that.GetPopup().option('contentTemplate', $(r.responseText));
                }
                that.GetLoadPanelInstance().hide();
            },
            errorMsg: "Error occurs during operation",
            successMsg: "Users accounts created successfully, invitation emails have been scheduled for send"
        });
        this.ajaxService.send(callOptions);
    };
    ManagmentView.prototype.UserPasswordChange = function (e) {
        var that = this;
        var callUrl = this.callController + '/UserPasswordChange';
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
            userId: e.row.data.CurrentId
        };
        var callOptions = new AjaxOptions({
            url: callUrl,
            method: AjaxMethod.POST,
            data: data,
            callback: function (d) { that.PopupForm.call(that, d, "Change password"); },
            errorMsg: "Error occurs during operation"
        });
        this.ajaxService.send(callOptions);
    };
    ManagmentView.prototype.CheckUserReportScheduler = function (e) {
        var that = this;
        var callUrl = this.callController + '/CheckUserReportScheduler';
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
            userId: e.row.data.CurrentId
        };
        var callOptions = new AjaxOptions({
            url: callUrl,
            method: AjaxMethod.POST,
            data: data,
            callback: function (d) { that.PopupForm.call(that, d, "Delete User"); },
            errorMsg: "Error occurs during operation"
        });
        this.ajaxService.send(callOptions);
    };
    ManagmentView.prototype.DeleteUser = function (e) {
        var that = this;
        var hasAssigment = $('#UserHasReportsAssignments').val() === 'True';
        var callUrl = this.callController + '/DeleteUserAndReassignReportScheduler';
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
            userId: $('#UserId').val(),
            reassign: hasAssigment ? $("#confirmUserReassignmentDx").dxCheckBox("instance").option('value') : null,
            newUserId: hasAssigment ? $("#newUserForReportsDx").dxDropDownBox("instance").option('value') : false
        };
        var callOptions = new AjaxOptions({
            url: callUrl,
            method: AjaxMethod.POST,
            data: data,
            callback: function (d) {
                that.GetPopup().hide();
                that.userGridDx.refresh();
            },
            errorCallback: function (r) {
                if (r.responseText) {
                    that.GetPopup().option('contentTemplate', $(r.responseText));
                }
            },
            errorMsg: "Error occurs during operation",
            successMsg: "User deleted successfully"
        });
        this.ajaxService.send(callOptions);
    };
    ManagmentView.prototype.ResetMFA = function (currentUserId) {
        var that = this;
        var callUrl = this.callController + '/ResetMFA';
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
            userId: currentUserId
        };
        var callOptions = new AjaxOptions({
            url: callUrl,
            method: AjaxMethod.POST,
            data: data,
            successMsg: "User MFA reseted successfully",
            errorMsg: "Error occurs during operation"
        });
        this.ajaxService.send(callOptions);
    };
    ManagmentView.prototype.UserPasswordChangeSubmit = function (e) {
        var that = this;
        var callUrl = this.callController + '/UserPasswordChangeSubmit';
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
            UserId: $('#UserId').val(),
            Password: $("#passwordDx").dxTextBox("instance").option('value'),
            RePassword: $("#passwordReDx").dxTextBox("instance").option('value')
        };
        var callOptions = new AjaxOptions({
            url: callUrl,
            method: AjaxMethod.POST,
            data: data,
            callback: function (d) {
                that.GetPopup().hide();
                that.userGridDx.refresh();
            },
            errorCallback: function (r) {
                if (r.responseText) {
                    that.GetPopup().option('contentTemplate', $(r.responseText));
                }
            },
            errorMsg: "Error occurs during operation",
            successMsg: "User updated successfully"
        });
        this.ajaxService.send(callOptions);
    };
    ManagmentView.prototype.UserUpdate = function (e) {
        var that = this;
        var callUrl = this.callController + '/UserUpdate';
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
            userId: e.row.data.CurrentId
        };
        var callOptions = new AjaxOptions({
            url: callUrl,
            method: AjaxMethod.POST,
            data: data,
            callback: function (d) { that.PopupForm.call(that, d, "Update user"); },
            errorMsg: "Error occurs during operation",
        });
        this.ajaxService.send(callOptions);
    };
    ManagmentView.prototype.GetNewUserDefinedFields = function () {
        var selectedFields = [];
        var grid = $("#userDefinedFieldsGridDx1a").dxDataGrid("instance");
        if (grid) {
            var selectedRowsData = grid.getSelectedRowsData();
            if (selectedRowsData.length > 0) {
                selectedRowsData.forEach(function (v, i, a) {
                    var value = $("#dfAddValueDx" + v.Id).dxTextBox("instance").option('value');
                    if (value) {
                        selectedFields.push({ IdExp: v.Id, Value: value });
                    }
                });
            }
        }
        return selectedFields;
    };
    ManagmentView.prototype.UserUpdateSubmit = function (e) {
        var that = this;
        var callUrl = this.callController + '/UserUpdateSubmit';
        var selectedFields = [];
        var grid = $("#userDefinedFieldsGridDx").dxDataGrid("instance");
        if (grid) {
            var selectedRowsData = grid.getSelectedRowsData();
            if (selectedRowsData.length > 0) {
                selectedRowsData.forEach(function (v, i, a) {
                    var value = $("#dfValueDx" + v.Id).dxTextBox("instance").option('value');
                    if (value) {
                        selectedFields.push({ IdExp: v.Id, Value: value });
                    }
                });
            }
        }
        var currentUDFs = $("#userDefinedFieldsDx").dxDropDownBox("instance").option('value');
        var selectedUdfs = currentUDFs && currentUDFs.length > 0 ? currentUDFs : [];
        var selectedConnProfiles = $("#publisherConnProfilesDx").dxDropDownBox("instance").option('value') &&
            $("#publisherConnProfilesDx").dxDropDownBox("instance").option('value').length > 0
            ? $("#publisherConnProfilesDx").dxDropDownBox("instance").option('value')
            : [];
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
            UserId: $('#UserId').val(),
            Name: $("#nameDx").dxTextBox("instance").option('value'),
            Email: $("#userChangeEmailDx").dxTextBox("instance").option('value'),
            Roles: $("#userChangeRolesDx").dxDropDownBox("instance").option('value'),
            NewDefineFieldsIds: selectedFields,
            SelectedDefineFieldsIds: selectedUdfs,
            SelectedConnectionProfiles: selectedConnProfiles
        };
        var callOptions = new AjaxOptions({
            url: callUrl,
            method: AjaxMethod.POST,
            data: data,
            callback: function (d) {
                that.GetPopup().hide();
                that.userGridDx.refresh();
            },
            errorCallback: function (r) {
                if (r.responseText) {
                    that.GetPopup().option('contentTemplate', $(r.responseText));
                }
            },
            errorMsg: "Error occurs during operation",
            successMsg: "User updated successfully"
        });
        this.ajaxService.send(callOptions);
    };
    ManagmentView.prototype.ReportAssignment = function (e) {
        var that = this;
        var callUrl = this.callController + '/ReportAssignment';
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
        };
        var callOptions = new AjaxOptions({
            url: callUrl,
            method: AjaxMethod.POST,
            data: data,
            callback: function (d) { that.PopupForm.call(that, d, "Add Report Assignment"); },
            errorMsg: "Error occurs during operation"
        });
        this.ajaxService.send(callOptions);
    };
    ManagmentView.prototype.ReportAssignmentSubmit = function (e) {
        var that = this;
        var callUrl = this.callController + '/ReportAssignmentSubmit';
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
            Name: $("#assignmentReportNameDx").dxSelectBox("instance").option('value'),
            Connections: $("#assignmentConDx").dxDropDownBox("instance").option('value') || [],
            Roles: $("#assignmentRolesDx").dxDropDownBox("instance").option('value') || [],
            Types: $("#assignmentTypeDx").dxDropDownBox("instance").option('value') || [],
            Expiration: $("#expirationDaysDx").dxNumberBox("instance").option('value') || null
        };
        var callOptions = new AjaxOptions({
            url: callUrl,
            method: AjaxMethod.POST,
            data: data,
            callback: function (d) {
                that.GetPopup().hide();
                that.assignmentGridDx.refresh();
            },
            errorCallback: function (r) {
                if (r.responseText) {
                    that.GetPopup().option('contentTemplate', $(r.responseText));
                }
            },
            errorMsg: "Error occurs during operation",
            successMsg: "Assignment registered successfully"
        });
        this.ajaxService.send(callOptions);
    };
    ManagmentView.prototype.DeleteReportAssignment = function (ids) {
        var that = this;
        var callUrl = this.callController + '/DeleteReports';
        if (ids && ids.length > 0) {
            var result = DevExpress.ui.dialog.confirm("<strong>Are you sure you want to delete the selected assignments?</strong>", "Delete");
            result.done(function (dialogResult) {
                if (dialogResult) {
                    that.DeleteActions(that.callController + '/CheckReportsAssignments', ids, true);
                }
            });
        }
    };
    ManagmentView.prototype.DeleteActions = function (url, ids, check) {
        var that = this;
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
            keys: ids.join(',')
        };
        var callOptions = new AjaxOptions({
            url: url,
            method: AjaxMethod.POST,
            data: data,
            callback: function (response) {
                if (!check) {
                    that.assignmentGridDx.refresh();
                }
                else {
                    if (response) {
                        var result2 = DevExpress.ui.dialog.confirm("<strong>Selected assignments contain Completed results. Are you sure to delete selected assignments?</strong>", "Delete");
                        result2.done(function (dialogResult2) {
                            if (dialogResult2) {
                                that.DeleteActions(that.callController + '/DeleteReports', ids, false);
                            }
                        });
                    }
                    else {
                        that.DeleteActions(that.callController + '/DeleteReports', ids, false);
                    }
                }
            },
            errorCallback: function (r) {
                if (r.responseText) {
                    DevExpress.ui.notify(r.responseText, "error", 5000);
                }
            },
            successMsg: check ? null : "Assignments deleted successfully"
        });
        this.ajaxService.send(callOptions);
    };
    ManagmentView.prototype.SyncAction = function () {
        var that = this;
        $("#syncUserDx").dxButton("instance").option('disabled', true);
        that.GetLoadPanelInstance().show();
        DevExpress.ui.notify("Synchronization process may take a while, please wait ...", "info", 5000);
        var data = {
            __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val()
        };
        var callUrl = this.callController + '/SyncUsers';
        var callOptions = new AjaxOptions({
            url: callUrl,
            method: AjaxMethod.POST,
            data: data,
            callback: function (response) {
                that.selectedRole = null;
                that.userGridDx.clearSelection();
                that.userGridDx.option("focusedRowIndex", -1);
                that.userGridDx.refresh();
                that.GetLoadPanelInstance().hide();
                $("#syncUserDx").dxButton("instance").option('disabled', false);
            },
            errorCallback: function (r) {
                if (r.responseText) {
                    DevExpress.ui.notify(r.responseText, "error", 5000);
                }
                that.GetLoadPanelInstance().hide();
                $("#syncUserDx").dxButton("instance").option('disabled', false);
            },
            successMsg: "Syncing successfully"
        });
        this.ajaxService.send(callOptions);
    };
    ManagmentView.prototype.PopupForm = function (content, title, show, large) {
        if (show === void 0) { show = true; }
        if (large === void 0) { large = false; }
        var popup = this.GetPopup();
        if (large === true) {
            large = !this.IsMobile();
        }
        popup.option('contentTemplate', null);
        if (large) {
            popup.option('width', '1000px');
            popup.option('height', '580px');
        }
        else {
            popup.option('width', '700px');
            popup.option('height', '370px');
        }
        popup.option("title", title);
        popup.option('contentTemplate', $(content));
        if (show) {
            popup.show();
        }
    };
    ManagmentView.prototype.PopupFormCustom = function (content, title, show, height, width) {
        if (show === void 0) { show = true; }
        if (height === void 0) { height = '370px'; }
        if (width === void 0) { width = '700px'; }
        var popup = this.GetPopup();
        popup.option('contentTemplate', null);
        popup.option('width', width);
        popup.option('height', height);
        popup.option("title", title);
        popup.option('contentTemplate', $(content));
        if (show) {
            popup.show();
        }
    };
    ManagmentView.prototype.GetPopup = function () {
        var popup = $("#userEditPopup").dxPopup("instance");
        return popup;
    };
    ManagmentView.prototype.SetupGridsInstances = function () {
        var that = this;
        this.roleGridDx = $("#roleGridDx").dxDataGrid("instance");
        this.userGridDx = $("#userGridDx").dxDataGrid("instance");
        this.assignmentGridDx = $("#assignmentGridDx").dxDataGrid("instance");
        this.assignmentGridDx.option().onSelectionChanged = function (e) {
            $("#deleteAssignmentDx").dxButton("instance").option('disabled', e.selectedRowKeys.length <= 0);
        };
        this.assignmentGridDx.option().onRowClick = function (e) {
            if (e.data && e.data.Id) {
                that.assignmentGridDx.selectRows([e.data.Id], false);
            }
        };
        this.assignmentGridDx.option().onCellPrepared = function (e) {
            if (e.rowType === 'header' && e.column.command == "select") {
                var commandCell = e.cellElement;
                commandCell.html("Delete");
            }
        };
        if (this.IsDefined(this.roleGridDx)) {
            this.roleGridDx.option().onRowClick = function (e) {
                if (e.data && e.data.Id) {
                }
            };
        }
    };
    ManagmentView.prototype.SetupGridsCmds = function () {
        var that = this;
        this.userGridDx.option('onFocusedRowChanged', function (e) {
            if (e.row) {
                that.selectedRole = e.row.data.Role;
            }
            else {
                that.selectedRole = null;
            }
            that.assignmentGridDx.refresh();
        });
        var inviteUserAction = $("#inviteUserDx").dxButton("instance");
        if (this.IsDefined(inviteUserAction)) {
            inviteUserAction.option().onClick = function (e) {
                that.InviteUsers(e);
            };
        }
        var resetMFAAction = $("#resetMFADx").dxButton("instance");
        if (this.IsDefined(resetMFAAction)) {
            resetMFAAction.option().onClick = function (e) {
                var userId = that.userGridDx.option("focusedRowKey");
                if (userId) {
                    that.ResetMFA(userId);
                }
            };
        }
        var addUserAction = $("#addUserDx").dxButton("instance");
        if (this.IsDefined(addUserAction)) {
            addUserAction.option().onClick = function (e) {
                that.userGridDx.addRow();
            };
        }
        var addDomainUserAction = $("#addDomainUserDx").dxButton("instance");
        if (this.IsDefined(addDomainUserAction)) {
            addDomainUserAction.option().onClick = function (e) {
                that.AddDomainUsers();
            };
        }
        var refreshUserAction = $("#refreshUserDx").dxButton("instance");
        if (this.IsDefined(refreshUserAction)) {
            refreshUserAction.option().onClick = function (e) {
                that.selectedRole = null;
                that.userGridDx.clearSelection();
                that.userGridDx.option("focusedRowIndex", -1);
                that.userGridDx.refresh();
            };
        }
        var syncUserAction = $("#syncUserDx").dxButton("instance");
        if (this.IsDefined(syncUserAction)) {
            syncUserAction.option().onClick = function (e) {
                that.SyncAction();
            };
        }
        var addRoleAction = $("#addRoleDx").dxButton("instance");
        addRoleAction.option().onClick = function (e) {
            that.roleGridDx.addRow();
        };
        var refreshRoleAction = $("#refreshRoleDx").dxButton("instance");
        refreshRoleAction.option().onClick = function (e) {
            that.roleGridDx.refresh();
        };
        var addAssignmentAction = $("#addAssignmentDx").dxButton("instance");
        addAssignmentAction.option().onClick = function (e) {
            that.ReportAssignment(e);
        };
        var refreshAssignmentAction = $("#refreshAssignmentDx").dxButton("instance");
        refreshAssignmentAction.option().onClick = function (e) {
            that.assignmentGridDx.refresh();
        };
        var deleteAssignment = $("#deleteAssignmentDx").dxButton("instance");
        deleteAssignment.option('disabled', this.assignmentGridDx.getSelectedRowKeys().length <= 0);
        deleteAssignment.option().onClick = function (e) {
            that.DeleteReportAssignment(that.assignmentGridDx.getSelectedRowKeys());
        };
        var reportsManagementDx = $("#reportsManagementDx").dxButton("instance");
        reportsManagementDx.option().onClick = function (e) {
            that.ReportsManagement(e);
        };
    };
    ManagmentView.prototype.EnableConnectionProfilesInRole = function (roleListDx, connProfileDropDownId) {
        if (roleListDx && this.IsDefined($("#" + connProfileDropDownId)) && $("#" + connProfileDropDownId).dxDropDownBox("instance")) {
            var selectedData = roleListDx.option('selectedItems');
            var containsPublisher = false;
            if (selectedData.length > 0) {
                for (var i = 0; i < selectedData.length; i++) {
                    if (selectedData[i].Value === "Publisher") {
                        $("#" + connProfileDropDownId).dxDropDownBox("instance").option('disabled', false);
                        containsPublisher = true;
                        break;
                    }
                    else {
                        containsPublisher = false;
                        $("#" + connProfileDropDownId).dxDropDownBox("instance").option('disabled', true);
                    }
                }
            }
            else {
                containsPublisher = false;
            }
            if (!containsPublisher) {
                $("#" + connProfileDropDownId).dxDropDownBox("instance").option('value', null);
            }
        }
    };
    ManagmentView.prototype.GetNewUserPublisherRoleConnectionProfiles = function (gridId) {
        var selectedConnProfiles = [];
        var grid = $("#" + gridId).dxDataGrid("instance");
        if (grid) {
            var selectedRowsData = grid.getSelectedRowsData();
            if (selectedRowsData.length > 0) {
                for (var i = 0; i < selectedRowsData.length; i++) {
                    selectedConnProfiles.push(selectedRowsData[i].ConnectionProfileId);
                }
            }
        }
        return selectedConnProfiles;
    };
    return ManagmentView;
}(BaseView));
var View = window.View || {};
document.addEventListener("DOMContentLoaded", function documentReady() {
    this.removeEventListener("DOMContentLoaded", documentReady);
    View = window.View = new ManagmentView();
});
