
Runner.pages.PageSettings.addPageEvent( 
	"production_output", 
	"add", 
	"afterPageReady", 
	function(pageObj, proxy, pageid, inlineRow, inlineObject, row ) {
		var ctrlStatus = Runner.getControl(
    pageid,
    "status"
);

var ctrlStep = Runner.getControl(
    pageid,
    "current_active_step_name"
);


function updateActiveStep()
{
    var status = ctrlStatus.getValue();

    if (status == "Processing")
    {
        // Processing selected:
        // allow user to choose the active step
        ctrlStep.setEnabled();
    }
    else
    {
        // No status / Pending Approval /
        // Pending Fulfillment
        ctrlStep.clear();
        ctrlStep.setDisabled();
    }
}


// Apply immediately when page opens
updateActiveStep();


// Apply whenever Status changes
ctrlStatus.on(
    "change",
    function()
    {
        updateActiveStep();
    }
);
});


Runner.pages.PageSettings.addPageEvent( 
	"production_output", 
	"edit", 
	"afterPageReady", 
	function(pageObj, proxy, pageid, inlineRow, inlineObject, row ) {
		var ctrlStatus = Runner.getControl(
    pageid,
    "status"
);

var ctrlStep = Runner.getControl(
    pageid,
    "current_active_step_name"
);

function refreshCurrentStep() {

    if (!ctrlStatus || !ctrlStep) {
        return;
    }

    if (ctrlStatus.getValue() === "Processing") {

        ctrlStep.show();

    } else {

        ctrlStep.setValue("");
        ctrlStep.hide();
    }
}

refreshCurrentStep();

ctrlStatus.on(
    "change",
    function () {
        refreshCurrentStep();
    }
);
});







