Saturday, March 15, 2014

/*==== Created By : Rubol


========================================*/

var queueContent = {};

queueContent = {

    addQueue: function () {
        util.ShowIDPDialog(util.FullURLByAction('Queue/Create'), 600, 'Queue', 'Queue', null,180);
        //$("#divQueue").window({
        //    title: 'Queue',
        //    width: 400,
        //    height: 200,
        //    closed: false,
        //    cache: false,
        //    minimizable: true,
        //    maximizable: true,
        //    collapsible: true,
        //    draggable: true,
        //    shadow: false,          
        //    modal: false,
        //    href:util.FullURLByAction('Queue/Create')
        //    //toolbar: [{
        //    //    iconCls: 'delete-icon',
        //    //    text: 'Delete',
        //    //    handler: function () {
        //    //        queueContent.deleteQueue(null)
        //    //    }

        //    //}, {
        //    //    iconCls: 'save-icon',
        //    //    text: 'Save',
        //    //    handler: function () {
        //    //        queueContent.SaveQueue(null)
        //    //    }
        //    //}],
       // });

    },
    ReloadQueueTable: function () {

        var grid = $("#grid-Queue").data("kendoGrid");
        grid.dataSource.read();
        grid.refresh();

       /// $('#grid-Queue').datagrid('reload');
    },

    AttachDialogEvents: function () {

        $("#lnkQueueSave").click(function () {
            // var action;
              var action = 'Queue/SaveQueue';
            if ($("input[id='Id']").val() == '00000000-0000-0000-0000-000000000000') {
             
                queueContent.SaveQueue(action);
                $("#divQueue").window("close");
            }
            else {
                $.messager.confirm('Confirm', 'Are you sure you want to save record?', function (r) {
                    if (r) {
                        action = 'Queue/SaveQueue';
                        queueContent.SaveQueue(action);
                    }
                    else {
                        return false;
                    }
                });
            }
        });

        $("a[id=lnkQueueDelete]").click(function () {

            var queueId = $(":input[name='Id']").val();
            queueContent.deleteQueueById(queueId);
        });
    },
    SaveQueue: function (action) {
        action = util.FullURLByAction(action);
        $.ajax({
            url: action,
            type: 'POST',
            data: $('#QueueForm').serialize(),
            dataType: 'json',
            async: false,
            success: function (result) {
                $("#divQueue").dialog("close");
                if (result) {
                    util.CallParentFunction('queueContent.reloadQueueItems');
                    util.CloseIFrame(this);
                }
                else {
                    return false;
                }
            }
        });

    },
    editQueue: function (id) {

        //var node = $tg.datagrid('getSelected');

        if (id) {
            util.ShowIDPDialog(util.FullURLByAction('Queue/Edit/' + id), 600, 'Queue', 'NULL', id, 180);
           
        }
        else {
            $.messager.alert('Information', 'Please select a row to edit.');
        }

    },
    //deleteQueue: function ($tg) {
    //    debugger;
    //    var node = $tg.datagrid('getSelected');
    //    if (node) {
    //        $.messager.confirm('Confirm', 'Are you sure you want to delete the record?', function (r) {
    //            if (r) {
    //                $.ajax({
    //                    url: 'Queue/DeleteQueue',
    //                    type: 'POST',
    //                    data: { Id: node.Id },
    //                    dataType: 'json',
    //                    success: function (result) {
    //                        $("#divQueue").window("close");
    //                        var index = $tg.datagrid('getRowIndex', node);
    //                        $tg.datagrid('deleteRow', index);
    //                        var lIndex = $tg.datagrid('getRows').length - 1;

    //                        if (index > lIndex)
    //                            index = lIndex;

    //                        $tg.datagrid('selectRow', index);
    //                    }
    //                });
    //            }
    //        });
    //    }
    //},

    reloadQueueItems: function () {
        var grid = $("#grid-Queue").data("kendoGrid");
        grid.dataSource.read();
        grid.refresh();
    },

 

    deleteQueueById: function (id) {
        $.messager.confirm('confirm', 'Are you sure, you want to delete this Record?', function (r) {

            if (r) {
                $.ajax({
                    url: util.FullURLByAction('Queue/DeleteQueueById/' + id),
                    type: 'POST',
                    async: false,
                    success: function (result) {
                        if (result == "True") {
                            util.CallParentFunction('queueContent.reloadQueueItems');
                            util.CloseIFrame();
                        }
                    }
                });
            }
            else {
                alert("failed to delete item.");
            }
        });
       
    },

    //refreshQueue: function (result) {
    //    var grd = $('#grid-Queue');
    //    if (result.NewModel) {
    //        grd.datagrid('appendRow', result.Response
    //        );

    //        grd.datagrid('selectRow', grd.datagrid('getRows').length - 1);
    //    }
    //    else {
    //        var node = grd.datagrid('getSelected');
    //        var response = result.Response;
    //        grd.datagrid('updateRow', {
    //            index: grd.datagrid('getRowIndex', node),
    //            row: result.Response
    //        });
    //    }
    //}

};
$(document).ready(function () {

    //$("#grid-Queue").datagrid({
    //    rowStyler: function (index, row) {
    //        if (index % 2 != 0) {
    //            return 'background-color:' + alternateBackgroundColor;
    //        }
    //    },
    //    onDblClickCell: function (index, field, value) {
    //        queueContent.editQueue($('#grid-Queue'));
    //    }
    //});

    $("#add-Queue").click(function () {
        queueContent.addQueue();
    });

    $("#edit-Queue").click(function ( ) {
        var grid = $("#grid-Queue").data("kendoGrid");
        var row = grid.select();
        var dataItem = grid.dataItem(row);
        if (!dataItem) $.messager.confirm('Warning', 'Please select a row first.');
        var id = dataItem.Id;
        queueContent.editQueue(id);
        

        //var grid = $(this).data("kendoGrid");
        //var selectedRows = grid.select();
        //var selectedDataItems = [];
        //for (var i = 0; i < selectedRows.length; i++) {
        //    var dataItem = grid.dataItem(selectedRows[i]);
        //    selectedDataItems.push(dataItem);
        //}
        //queueContent.editQueue(selectedDataItems[0]);
    });

    $("#grid-Queue", this).dblclick(function (e) {

        var grid = $("#grid-Queue").data("kendoGrid");
        var row = grid.select();
        var dataItem = grid.dataItem(row);
        var id = dataItem.Id;
        queueContent.editQueue(id);




        //var grid = $(this).data("kendoGrid");
        //var selectedRows = grid.select();
        //var selectedDataItems = [];
        //for (var i = 0; i < selectedRows.length; i++) {
        //    var dataItem = grid.dataItem(selectedRows[i]);
        //    selectedDataItems.push(dataItem);
        //}
        //queueContent.editQueue(selectedDataItems[0]);

    });

    //$("#delete-Queue").click(function () {

    //    queueContent.deleteQueue($('#grid-Queue'));
    //});




});

No comments:

Post a Comment