
//\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\//
// Popup floating modeless "edit" window
// "Edit", "Delete" buttons
// Operate on the selected cells
//\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\//

// Timer to auto-close dlg
var CloseGridEditPopupTimerID = 0;
var GridEditPopupGridId = null;
var PreventNextGridEditPopup = new Date();

/**
 * Popup a small modeless dialog to assist in editing the selected cell
 * Click "Edit" button to go into edit text edit mode
 * Click "Delete" button to delete the selected cell contents (normally for timesheet entries)
 * @param {any} Grid
 */
function GridCellSelectionChangedPopup(event, GridId) {

    // Popup a small modeless dialog to assist in editing the selected cell
    // Click "Edit" button to go into edit text edit mode for selected cell
    // Click "Delete" button to delete the selected cell contents (normally for timesheet entries)
    // What is selected?
    GridEditPopupGridId = GridId;
    if (!GridId)
        return;

    // Prevent the next popup
    var Now = new Date();
    var millisecondsSincePrevent = Now.getTime() - PreventNextGridEditPopup.getTime();
    if (millisecondsSincePrevent < 500)
        return;

    // Do not open while actively editing a grid cell
    // This popup is too disruptive to the editing process
    if (IsGridInEditMode())
        return;

    var nDlgWidth = 124;
    var nDlgHeight = 24;

    // Open the dialog
    // https://igniteui.com/help/igdialog-property-reference
    $("#igDialogGridEditPopup").igDialog({ modal: false, headerText: "Edit", width: nDlgWidth, minWidth: nDlgWidth, minHeight: nDlgHeight, resizable: false, /*showCloseButton: false,*/ closeOnEscape: true, /*openAnimation: "",*/ closeAnimation: "fade" });
    $("#igDialogGridEditPopup").igDialog("open");
    bGridEditPopupDialogIsOpen = true;

    //PositionDialogLowerRight("igDialogGridEditPopup");
    PositionDialogOffsetFromMouse("igDialogGridEditPopup", 30/*offsetX*/, 30/*offsetY*/);

    // Auto-close dialog because user probably doesn't need it
    if (CloseGridEditPopupTimerID) {
        clearTimeout(CloseGridEditPopupTimerID);
        CloseGridEditPopupTimerID = 0;
    }
    CloseGridEditPopupTimerID = setTimeout(AutocloseGridEditPopupTimer, 4000);
}


function AutocloseGridEditPopupTimer() {

    // Auto-close dialog because user probably doesn't need it

    // Clear the ID for this timer
    CloseGridEditPopupTimerID = 0;

    CloseGridEditPopupDialog();

}

//\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\//
// Close the dialog
//\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\//
var bGridEditPopupDialogIsOpen = false;
function CloseGridEditPopupDialog() {

    if (!bGridEditPopupDialogIsOpen)
        return;
    var DialogGridEditPopup = $("#igDialogGridEditPopup");
    if (!DialogGridEditPopup)
        return;

    $("#igDialogGridEditPopup").igDialog("close");
    bGridEditPopupDialogIsOpen = false;
}

function IsGridEditPopupDialogOpen() {
    return bGridEditPopupDialogIsOpen;
}
