$()

in src/VstsDemoBuilder/Scripts/AppScripts/create.js [487:642]


$('#btnSubmit').click(function () {
    var forkGitHub = false;
    var gitHubFork = $('input[id="gitHubCheckbox"]').prop('checked');
    if (gitHubFork === true) {
        forkGitHub = true;
    }
    statusCount = 0;
    $("#txtALertContainer").hide();
    $('#status-messages').hide();
    $("#finalLink").removeClass("d-block").addClass("d-none");

    var projectName = $.trim($("#txtProjectName").val());
    var template = templateFolder;
    var accountName = $('#ddlAcccountName option:selected').val();
    var token = $('#hiddenAccessToken').val();
    var email = $('#emailID').val();
    var regex = /^[A-Za-z0-9 -_]*[A-Za-z0-9][A-Za-z0-9 -_]*$/;
    if (accountName === "" || accountName === "Select Organization") {
        $("#ddlAcccountName_Error").text("Please choose an organization first!");
        $("#ddlAcccountName_Error").removeClass("d-none").addClass("d-block");
        $("#ddlAcccountName").focus();
        return false;
    }
    //checking for session templatename and templateID
    if (projectName === "") {
        $("#txtProjectName_Error").text("Please provide a project name");
        $("#txtProjectName_Error").removeClass("d-none").addClass("d-block");
        return false;
    }
    if (!(regex.test(projectName))) {
        $("#txtAlert").text("Special characters are not allowed for project name");
        $("#txtALertContainer").show();
        $("#txtProjectName").focus();
        return false;
    }
    if (template === "") {
        $("#ddlTemplates_Error").text("Please select Project template");
        $("#ddlTemplates_Error").removeClass("d-none").addClass("d-block");
        return false;
    }

    if (template === "Octopus") {
        var octopusURL = $('#txtOctopusURL').val();
        var octopusAPIkey = $('#txtAPIkey').val();
        if (octopusURL !== "") {
            var pattern = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]\$&'\(\)\*\+,;=.]+$/;

            if (!(pattern.test(octopusURL))) {
                $("#txtOctopusURL_Error").text("Please enter a valid URL.");
                $("#txtOctopusURL_Error").removeClass("d-none").addClass("d-block");
                return false;
            }
        }
        else {
            $("#txtOctopusURL_Error").text("Please enter a valid URL.");
            $("#txtOctopusURL_Error").removeClass("d-none").addClass("d-block");
            return false;
        }
        if (octopusAPIkey === "") {
            $("#txtAPIkey_Error").text("Please enter a valid Octopus Key.");
            $("#txtAPIkey_Error").removeClass("d-none").addClass("d-block");
            return false;
        }
    }

    if (template === "SonarQube") {
        var ServerDNS = $("#txtSonarServerDNSName").val();
        if (ServerDNS === "") {
            $("#txtSonarServerDNSName_Error").text("Please enter sonar server DNS name");
            $("#txtSonarServerDNSName_Error").removeClass("d-none").addClass("d-block");
            return false;
        }
    }

    //get userMethod and selected users
    var SelectedUsers = '';
    var userMethod = $("input[type='radio']:checked").val();
    if (userMethod === "Select") {
        $(".checkbox").each(function () {
            if (this.checked) {
                SelectedUsers = SelectedUsers + this.value + ',';
            }
        });

        if (SelectedUsers.length === 0) {
            $("#txtAlert").text("Please select organiaztion users");
            $("#txtALertContainer").show();
            return false;
        }
    }

    $('#status-messages').html('');
    $('#status-messages').show();
    $("#btnSubmit").prop("disabled", true).removeClass('btn-primary');
    $("#templateselection").prop("disabled", true).removeClass('btn-primary');
    var Parameters = {};
    $.each($('.project-parameters'), function (index, item) {
        Parameters[$("#" + item['id']).attr('proj-parameter-name')] = item["value"];
    });

    var privateTemplateName = $('#PrivateTemplateName').val();
    var privateTemplatePath = $('#PrivateTemplatePath').val();
    if (privateTemplatePath !== '') {
        selectedTemplate = privateTemplateName;
    } else {
        selectedTemplate = template;
    }

    var websiteUrl = window.location.href;
    var projData = {
        "ProjectName": projectName, "SelectedTemplate": selectedTemplate, "id": uniqueId, "Parameters": Parameters, "selectedUsers": SelectedUsers, "UserMethod": userMethod, "SonarQubeDNS": ServerDNS, "isExtensionNeeded": isExtensionNeeded, "isAgreeTerms": isAgreedTerms, "websiteUrl": websiteUrl, "accountName": accountName, "accessToken": token, "email": email, "GitHubFork": forkGitHub, "PrivateTemplateName": privateTemplateName, "PrivateTemplatePath": privateTemplatePath
    };
    $.post("StartEnvironmentSetupProcess", projData, function (data) {
        if (data !== "True") {
            //var queryTemplate = '@Request.QueryString["queryTemplate"]';
            //window.location.href = "~/Account/Verify?template=" + queryTemplate;
            //return;
            if (confirm("Session expired! click OK to reload")) {
                window.location.href = "../account/index";
            }
            else {
                window.location.href = "../";
            }
        }
        else if (data === false) {
            if (confirm("Session expired! click OK to reload")) {
                window.location.href = "../account/index";
            }
            else {
                window.location.href = "../";
            }
        }
        $('input[id="gitHubCheckbox"]').prop('disabled', true);
        appInsights.trackEvent("Create button clicked");
        appInsights.trackEvent("Created project using" + selectedTemplate + " template");
        ga('send', 'event', selectedTemplate, 'selected');
        appInsights.trackEvent("User method" + userMethod);

        $('#ddlGroups').attr("disabled", "disabled");

        $("#ddlAcccountName").attr("disabled", "disabled");
        $("#txtProjectName").attr("disabled", "disabled");
        $("#templateselection").prop("disabled", true);
        $("input.terms").attr("disabled", true);
        $("#txtALertContainer").hide();
        $("#accountLink").html('');
        $("#errorNotify").removeClass("d-block").addClass("d-none");
        projectNameForLink = projectName;
        AccountNameForLink = accountName;
        ErrorData = '';
        getStatus();
        $('#dvProgress').removeClass("d-none").addClass("d-block");
        $('#textMuted').removeClass("d-none").addClass("d-block");
    });
    event.preventDefault;
});