<commit_before>function drawPage() {

    $("#gadgetBody").empty();
    if (json != null) {

        var top =
                "    <div class=\"col-lg-12 content-section\">\n" +
                "        <table class=\"table table-bordered\">\n" +
                "            <thead>\n" +
                "                <tr>\n" +
                "                    <th class='txtAlnCen width27p'>Domain</th>\n" +
                "                    <th class='txtAlnCen width27p'>Tenant Domain</th>\n" +
                "                    <th class='txtAlnCen width26p'>User Name</th>\n" +
                "                    <th class='txtAlnCen'>Action</th>\n" +
                "                </tr>\n" +
                "            </thead>\n" +
                "            <tbody>\n";

        var middle = "";
        if (isArray(json)) {
            for (var i in json) {
                middle = middle +
                         "                <tr>\n" +
                         "                    <td>" + json[i].domain + "</td>\n" +
                         "                    <td>" + json[i].tenantDomain + "</td>\n" +
                         "                    <td>" + json[i].username + "</td>\n";

                var connectedAccount = json[i].username;
                if ('PRIMARY' != json[i].domain) {
                    connectedAccount = json[i].domain + "/" + connectedAccount;
                }
                if ('carbon.super' != json[i].tenantDomain) {
                    connectedAccount = connectedAccount + '@' + json[i].tenantDomain;
                }

                middle = middle +
                         "                    <td class='txtAlnCen'>\n" +
                         "                        <a title=\"\" onclick=\"deleteUserAccountConnection('" + connectedAccount + "');\" href=\"javascript:void(0)\"><i class=\"icon-trash\"></i> \n" + "Remove</a>\n" +
                         "                    </td>\n" +
                         "                </tr>\n";
            }
        }

        var end =
                "            </tbody>\n" +
                "        </table>\n" +
                "    </div>";

        var output = top + middle + end;
        $("#gadgetBody").append(output);

    }
}

function isArray(element) {
    return Object.prototype.toString.call(element) === '[object Array]';
}

function deleteUserAccountConnection(delUser) {

    var msg = "You are about to remove account '" + delUser + "'. Do you want to proceed?";
    message({content: msg, type: 'confirm', okCallback: function () {
        $.ajax({
                   url: "/portal/gadgets/connected_accounts/index.jag",
                   type: "POST",
                   data: "&cookie=" + cookie + "&userName=" + delUser + "&action=delete",
                   success: function (data) {
                       var resp = $.parseJSON(data);
                       if (resp.success == true) {
                           reloadGrid();
                       } else {
                           if (typeof resp.reLogin != 'undefined' && resp.reLogin == true) {
                               window.top.location.href = window.location.protocol + '//' + serverUrl + '/dashboard/logout.jag';
                           } else {
                               if (resp.message != null && resp.message.length > 0) {
                                   message({content: resp.message, type: 'error', cbk: function () {
                                   }});
                               } else {
                                   message({content: 'Error occurred while deleting user account.', type: 'error', cbk: function () {
                                   }});
                               }
                           }
                       }
                   },
                   error: function (e) {
                       message({content: 'Error occurred while deleting user account.', type: 'error', cbk: function () {
                       }});
                   }
               });
    }, cancelCallback: function () {
    }});
}

function reloadGrid() {
    $.ajax({
               url: "/portal/gadgets/connected_accounts/index.jag",
               type: "GET",
               data: "&cookie=" + cookie + "&action=list",
               success: function (data) {
                   var resp = $.parseJSON(data);
                   if (resp.success == true) {
                       json = resp.data;
                       drawPage();
                       changeDropDownMenu();
                   } else {

                       if (typeof resp.reLogin != 'undefined' && resp.reLogin == true) {
                           window.top.location.href = window.location.protocol + '//' + serverUrl + '/dashboard/logout.jag';
                       } else {
                           if (resp.message != null && resp.message.length > 0) {
                               message({content: resp.message, type: 'error', cbk: function () {
                               }});
                           } else {
                               message({content: 'Error occurred while loading values for the grid.', type: 'error', cbk: function () {
                               }});
                           }
                       }
                   }
               },
               error: function (e) {
                   message({content: 'Error occurred while loading values for the grid.', type: 'error', cbk: function () {
                   }});
               }
           });
}

function changeDropDownMenu(){
    if(json != null){
        if(isArray(json)){
<<<<<<< HEAD
            var htmlContent =  '<div class="dropdown_separator"><span>Switch To</span></div>';
=======
            var htmlContent =  '<div class="dropdown_separator"><span class="switch_to_div">Switch To :</span></div>';
>>>>>>> b1dd18c... Committing user account association feature
            for(var i in json){
                htmlContent += '<li class="associated_accounts"><a href="javascript:void(0)" onclick="switchAccount(\'' +
                               (json[i].indexOf("@carbon.super") >= 0 ? json[i].split("@carbon.super")[0] : json[i]) +
                               '\');"><i class="icon-user pdR2p"></i>' + (json[i].indexOf("@carbon.super") >= 0 ? json[i].split("@carbon.super")[0] : json[i]) + '</a></li>';

            }
            if($('.dropdown-account', window.parent.document).find('.dropdown_separator') != null){
                $('.dropdown-account', window.parent.document).find('.dropdown_separator').remove();
                $('.dropdown-account', window.parent.document).find('.associated_accounts').remove();
            }
            $('.dropdown-account', window.parent.document).append(htmlContent);
        }
    } else {
        if($('.dropdown-account', window.parent.document).find('.dropdown_separator') != null){
            $('.dropdown-account', window.parent.document).find('.dropdown_separator').remove();
            $('.dropdown-account', window.parent.document).find('.associated_accounts').remove();
        }
    }

    var sessionRefresherUrl = window.location.protocol + '//' + serverUrl + '/dashboard/refresh.jag';

    $.ajax({
               url: sessionRefresherUrl,
               type: "POST",
               data: "&userList=" +JSON.stringify(json)<commit_msg>Fixing user accounts drop-down refreshing issue<commit_after>function drawPage() {

    $("#gadgetBody").empty();
    if (json != null) {

        var top =
                "    <div class=\"col-lg-12 content-section\">\n" +
                "        <table class=\"table table-bordered\">\n" +
                "            <thead>\n" +
                "                <tr>\n" +
                "                    <th class='txtAlnCen width27p'>Domain</th>\n" +
                "                    <th class='txtAlnCen width27p'>Tenant Domain</th>\n" +
                "                    <th class='txtAlnCen width26p'>User Name</th>\n" +
                "                    <th class='txtAlnCen'>Action</th>\n" +
                "                </tr>\n" +
                "            </thead>\n" +
                "            <tbody>\n";

        var middle = "";
        if (isArray(json)) {
            for (var i in json) {
                middle = middle +
                         "                <tr>\n" +
                         "                    <td>" + json[i].domain + "</td>\n" +
                         "                    <td>" + json[i].tenantDomain + "</td>\n" +
                         "                    <td>" + json[i].username + "</td>\n";

                var connectedAccount = json[i].username;
                if ('PRIMARY' != json[i].domain) {
                    connectedAccount = json[i].domain + "/" + connectedAccount;
                }
                if ('carbon.super' != json[i].tenantDomain) {
                    connectedAccount = connectedAccount + '@' + json[i].tenantDomain;
                }

                middle = middle +
                         "                    <td class='txtAlnCen'>\n" +
                         "                        <a title=\"\" onclick=\"deleteUserAccountConnection('" + connectedAccount + "');\" href=\"javascript:void(0)\"><i class=\"icon-trash\"></i> \n" + "Remove</a>\n" +
                         "                    </td>\n" +
                         "                </tr>\n";
            }
        }

        var end =
                "            </tbody>\n" +
                "        </table>\n" +
                "    </div>";

        var output = top + middle + end;
        $("#gadgetBody").append(output);

    }
}

function isArray(element) {
    return Object.prototype.toString.call(element) === '[object Array]';
}

function deleteUserAccountConnection(delUser) {

    var msg = "You are about to remove account '" + delUser + "'. Do you want to proceed?";
    message({content: msg, type: 'confirm', okCallback: function () {
        $.ajax({
                   url: "/portal/gadgets/connected_accounts/index.jag",
                   type: "POST",
                   data: "&cookie=" + cookie + "&userName=" + delUser + "&action=delete",
                   success: function (data) {
                       var resp = $.parseJSON(data);
                       if (resp.success == true) {
                           reloadGrid();
                       } else {
                           if (typeof resp.reLogin != 'undefined' && resp.reLogin == true) {
                               window.top.location.href = window.location.protocol + '//' + serverUrl + '/dashboard/logout.jag';
                           } else {
                               if (resp.message != null && resp.message.length > 0) {
                                   message({content: resp.message, type: 'error', cbk: function () {
                                   }});
                               } else {
                                   message({content: 'Error occurred while deleting user account.', type: 'error', cbk: function () {
                                   }});
                               }
                           }
                       }
                   },
                   error: function (e) {
                       message({content: 'Error occurred while deleting user account.', type: 'error', cbk: function () {
                       }});
                   }
               });
    }, cancelCallback: function () {
    }});
}

function reloadGrid() {
    $.ajax({
               url: "/portal/gadgets/connected_accounts/index.jag",
               type: "GET",
               data: "&cookie=" + cookie + "&action=list",
               success: function (data) {
                   var resp = $.parseJSON(data);
                   if (resp.success == true) {
                       json = resp.data;
                       drawPage();
                       changeDropDownMenu();
                   } else {

                       if (typeof resp.reLogin != 'undefined' && resp.reLogin == true) {
                           window.top.location.href = window.location.protocol + '//' + serverUrl + '/dashboard/logout.jag';
                       } else {
                           if (resp.message != null && resp.message.length > 0) {
                               message({content: resp.message, type: 'error', cbk: function () {
                               }});
                           } else {
                               message({content: 'Error occurred while loading values for the grid.', type: 'error', cbk: function () {
                               }});
                           }
                       }
                   }
               },
               error: function (e) {
                   message({content: 'Error occurred while loading values for the grid.', type: 'error', cbk: function () {
                   }});
               }
           });
}

function changeDropDownMenu(){
    if(json != null){
        if(isArray(json)){
<<<<<<< HEAD
            var htmlContent =  '<div class="dropdown_separator"><span>Switch To</span></div>';
=======
            var htmlContent =  '<div class="dropdown_separator"><span class="switch_to_div">Switch To :</span></div>';
>>>>>>> b1dd18c... Committing user account association feature
            for(var i in json){
                var connectedAccount = json[i].username;
                if ('PRIMARY' != json[i].domain) {
                    connectedAccount = json[i].domain + "/" + connectedAccount;
                }
                if ('carbon.super' != json[i].tenantDomain) {
                    connectedAccount = connectedAccount + '@' + json[i].tenantDomain;
                }
                htmlContent += '<li class="associated_accounts"><a href="javascript:void(0)" onclick="switchAccount(\'' +
                               connectedAccount + '\');"><i class="icon-user pdR2p"></i>' + connectedAccount + '</a></li>';

            }
            if($('.dropdown-account', window.parent.document).find('.dropdown_separator') != null){
                $('.dropdown-account', window.parent.document).find('.dropdown_separator').remove();
                $('.dropdown-account', window.parent.document).find('.associated_accounts').remove();
            }
            $('.dropdown-account', window.parent.document).append(htmlContent);
        }
    } else {
        if($('.dropdown-account', window.parent.document).find('.dropdown_separator') != null){
            $('.dropdown-account', window.parent.document).find('.dropdown_separator').remove();
            $('.dropdown-account', window.parent.document).find('.associated_accounts').remove();
        }
    }

    var sessionRefresherUrl = window.location.protocol + '//' + serverUrl + '/dashboard/refresh.jag';

    $.ajax({
               url: sessionRefresherUrl,
               type: "POST",
               data: "&userList=" +JSON.stringify(json)
{'fraction_non_alphanumeric': 0.14878064987706824, 'fraction_numerical': 0.00239218552727756, 'mean_word_length': 1.1948373924456759, 'pattern_counts': {'":': 0, '<': 109, '<?xml version=': 0, '>': 115, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 60, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1373324', 'n_tokens_mistral': 3841, 'n_tokens_neox': 3629, 'n_words': 703}