

function addMemberToUserDropdown(trashIcon) {

    var memberId = $(trashIcon).parents("tr").find("input[name=\'memberId\']").val();
    var memberName = $(trashIcon).parents("tr").find("td").first().find("div").text();
    var dropdown = $(trashIcon).parents("table").find("tfoot select");
    var option = $("<option />").text(memberName).val(memberId);
    dropdown.append(option);
    dropdown.parents("tfoot").show();
}
    
agentDynamicGrid = new plDynamicGrid({
    gridId:"#QueueMonitor-grid",
    gridContainer: "#content",
    addRowSelector: ".addMember",
    newRowClass: "new-item-animated",
    prototypeRowClass: "hideRow",
    data:agentDynamicGridData,
    beforeAddRowCallback: function (addButton, data) {
        var dropdown = $(addButton).parents("tr").find("select");
        var ajaxData = {
            label:dropdown.find("option:selected").text(),
            userId:dropdown.find("option:selected").val(),
            queueId:data.queueId
        };

        $.ajax({
            url:data.addAgentUrl,
            data:ajaxData,
            type:"POST",
            dataType:"json",
            success:function(data){
            },
            error:function(error) {
                console.log("error");
            }
        });
    },
    addRowCallback: function(inputElement, index, data) {
        if (inputElement.id === "memberId" ) {
            var dropdown = $(inputElement).parents("table").find("tfoot select");
            inputElement.value = dropdown.val();
            $(inputElement).parent().find("div").text(dropdown.find("option:selected").text());
        }
        dropdown.find("option:selected").remove();
        if (dropdown.find("option").length === 0) {
            dropdown.parents("tfoot").hide();
        }
        $('#QueueMonitor-grid').yiiGridView('update');
        $("#Queue-general-data-grid").yiiGridView("update");
    }
});