I've made a small script for hiding fields in the modal window of a child table. This is very useful when you use the same child table in multiple parent tables to hide the other parents IDs or any other field you want. I have a child table that is an actual storehouse table and I've wanted to fill the storehouse in different ways for example with products from production, import, special manipulations like packaging, commissioning etc (and to use different parent table interfaces for this). I want to use these products in recipes for additional production which will be stored in the same storehouse table. This way I can have infinite virtual storehouses (attached to each record in the storehouse table) and I can make production and further production multiple times easily.
The script works as follows: I've added a click function to the "Add New" button in the child table but I need to wait for the entire page to load using "window onload" because "document ready" is too early and child tables are not loaded. The "click" function calls another function that hides the needed fields in the child modal window using "contents find". On any ajax call the click function is lost so I'm adding the "click" function again after any ajax call using "ajaxComplete".
If anyone has better more robust solution I'll be happy to see it.
Code: Select all
var dv = AppGiniHelper.DV;
// hide multiple columns from children tab
dv.getChildrenTabs().hide("slaughterhouse_storehouse", ["production_id", "external_id", "export_id"]);
//waiting for full page load to add click function in child tab button "Add New"
$j(window).on("load", addClickFunction );
//add click function for first child tab add new button
function addClickFunction () {
$j("#panel_slaughterhouse_storehouse-cutting_id a:first-child").click(hideStorehouseFields);
//add again the click function after each ajax call (data refresh)
$j(document).ajaxComplete(addClickFunction);
}
//hide fields in child modal window
function hideStorehouseFields() {
$j("iframe").on("load", function() {
$j(this).contents().find('.slaughterhouse_storehouse-production_id, .slaughterhouse_storehouse-external_id, .slaughterhouse_storehouse-export_id').hide();
});
}