
Runner.pages.PageSettings.addPageEvent( 
	"augmentation_request_item_for_approval", 
	"add", 
	"afterPageReady", 
	function(pageObj, proxy, pageid, inlineRow, inlineObject, row ) {
		(function () {

    var dromicFields = [
        "dromic_line_no",
        "dromic_category",
        "dromic_requested_item_description",
        "dromic_original_unit",
        "dromic_original_quantity",
        "dromic_payload_json"
    ];

    var dromicLabels = [
        "Dromic Line No",
        "Dromic Category",
        "Dromic Requested Item Description",
        "Dromic Original Unit",
        "Dromic Original Quantity",
        "Dromic Payload Json"
    ];

    function hideDromicFields() {

        dromicFields.forEach(function (field) {

            /*
                Normal Add/Edit PHPRunner controls
            */
            try {
                var ctrl = Runner.getControl(pageid, field);
                if (ctrl) {
                    ctrl.hide();
                }
            } catch (e) {
                // ignore if field is not on this specific page
            }

            /*
                Bootstrap / PHPRunner layout containers
            */
            $("[data-field='" + field + "']").hide();
            $("[data-fieldname='" + field + "']").hide();

            $("input[name='" + field + "'], textarea[name='" + field + "'], select[name='" + field + "']")
                .closest("td, th, .form-group, .r-integrated-field, .rnr-control, .bs-gridcell")
                .hide();

            $("[id^='label_" + field + "_'], [id^='value_" + field + "_']")
                .closest("td, th, .form-group, .r-integrated-field, .rnr-control, .bs-gridcell")
                .hide();
        });

        /*
            Inline Add grid fallback:
            Hide whole column based on column header text.
            This is for the child inline add like your screenshot.
        */
        $("th").each(function () {

            var headerText = $.trim($(this).text());

            if (dromicLabels.indexOf(headerText) >= 0) {

                var colIndex = $(this).index() + 1;
                var table = $(this).closest("table");

                table.find("tr").each(function () {
                    $(this).children(":nth-child(" + colIndex + ")").hide();
                });
            }
        });
    }

    /*
        Run immediately
    */
    hideDromicFields();

    /*
        Run again because inline add/detail grids sometimes load after page load
    */
    setTimeout(hideDromicFields, 300);
    setTimeout(hideDromicFields, 800);
    setTimeout(hideDromicFields, 1500);

    /*
        Also watch for dynamically added inline rows
    */
    if (window.MutationObserver) {
        var observer = new MutationObserver(function () {
            hideDromicFields();
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true
        });

        setTimeout(function () {
            observer.disconnect();
        }, 5000);
    }

})();
});


Runner.pages.PageSettings.addPageEvent( 
	"augmentation_request_item_for_approval", 
	"edit", 
	"afterPageReady", 
	function(pageObj, proxy, pageid, inlineRow, inlineObject, row ) {
		(function () {

    var dromicFields = [
        "dromic_line_no",
        "dromic_category",
        "dromic_requested_item_description",
        "dromic_original_unit",
        "dromic_original_quantity",
        "dromic_payload_json"
    ];

    var dromicLabels = [
        "Dromic Line No",
        "Dromic Category",
        "Dromic Requested Item Description",
        "Dromic Original Unit",
        "Dromic Original Quantity",
        "Dromic Payload Json"
    ];

    function hideDromicFields() {

        dromicFields.forEach(function (field) {

            /*
                Normal Add/Edit PHPRunner controls
            */
            try {
                var ctrl = Runner.getControl(pageid, field);
                if (ctrl) {
                    ctrl.hide();
                }
            } catch (e) {
                // ignore if field is not on this specific page
            }

            /*
                Bootstrap / PHPRunner layout containers
            */
            $("[data-field='" + field + "']").hide();
            $("[data-fieldname='" + field + "']").hide();

            $("input[name='" + field + "'], textarea[name='" + field + "'], select[name='" + field + "']")
                .closest("td, th, .form-group, .r-integrated-field, .rnr-control, .bs-gridcell")
                .hide();

            $("[id^='label_" + field + "_'], [id^='value_" + field + "_']")
                .closest("td, th, .form-group, .r-integrated-field, .rnr-control, .bs-gridcell")
                .hide();
        });

        /*
            Inline Add grid fallback:
            Hide whole column based on column header text.
            This is for the child inline add like your screenshot.
        */
        $("th").each(function () {

            var headerText = $.trim($(this).text());

            if (dromicLabels.indexOf(headerText) >= 0) {

                var colIndex = $(this).index() + 1;
                var table = $(this).closest("table");

                table.find("tr").each(function () {
                    $(this).children(":nth-child(" + colIndex + ")").hide();
                });
            }
        });
    }

    /*
        Run immediately
    */
    hideDromicFields();

    /*
        Run again because inline add/detail grids sometimes load after page load
    */
    setTimeout(hideDromicFields, 300);
    setTimeout(hideDromicFields, 800);
    setTimeout(hideDromicFields, 1500);

    /*
        Also watch for dynamically added inline rows
    */
    if (window.MutationObserver) {
        var observer = new MutationObserver(function () {
            hideDromicFields();
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true
        });

        setTimeout(function () {
            observer.disconnect();
        }, 5000);
    }

})();
});







