var userRoleList = JSON.parse($("#hfUserRoleList").val());
var code = getQuery("code");
$(document).ready(function () {
    $("#hfUserRoleList").remove();
    $("[data-mask='mobile']").inputmask("9999999999");
    $("#ddlSelectRole").selectize({
        plugins: ['remove_button'],
        sortField: 'text'
    });
    if (code)
        $("#ddlSelectRole").selectize()[0].selectize.setValue(userRoleList.map(function (item) { return item.Code }));
});
async function getEventLookupCombo($combo, search, code) {
    await ajax({
        url: "GeneralApi/GetCustomerList",
        data: {
            type: 2,
            search: search,
            pageNo: 1,
            selectedCode: code
        },
        success: function (result) {
            $combo.lookupBuilder().bindData(result);
        }
    });
}
function save() {
    var role = [];
    var data = getJsonValue("");
    var error = checkValidation("");
    if (error === "") {
        //if ((getQuery('code') == '' || data.PassWord != null) && !validatePass(data.PassWord)) {
        //    showMsgModal(0, 'کلمه عبور بایستی شامل حداقل 4 کاراکتر باشد.');
        //}
        //else
        {
            if (data.UserRoleList && data.UserRoleList.length > 0) {
                $(data.UserRoleList).each(function (index, item) {
                    role.push({ Code: item });
                });
            }
            data["UserRoleList"] = role;
            data["FileImage"] = $('.picture-img>img').attr('src');
            if (code)
                data["UserCode"] = code;
            else
                data["UserCode"] = -1;
            ajax({
                loading: true,
                url: "GeneralApi/" + (code ? "UpdateUser" : "SaveUser"),
                data: data,
                success: function (result) {
                    showMsgModal(2, window.top.savedSuccessfully);
                    refreshParent('refresh();');
                    closeTopModal();

                }
            });
        }
    }
    else {
        showMsgModal(0, error);
    }
}

