Runner.buttonEvents['397511'] = function( pageObj, proxy, pageid ) {
	var gid = '397511';
	//register a new button
	pageObj.buttonNames[ pageObj.buttonNames.length ] = gid;
		
	if ( !pageObj.buttonEventBefore[ gid ] ) {
		pageObj.buttonEventBefore[ gid ] = function( params, ctrl, pageObj, proxy, pageid, rowData, row, submit ) {		
			var ajax = ctrl;
			params["donation_receiving_detail_id"] = row.getFieldValue("donation_receiving_detail_id");

if (!params["donation_receiving_detail_id"]) {
    swal("Error", "Unable to get donation receiving detail ID from this row.", "error");
    return false;
}

return true;			
		}
	}

	if ( !pageObj.buttonEventAfter[ gid ] ) {
		pageObj.buttonEventAfter[ gid ] = function( result, ctrl, pageObj, proxy, pageid, rowData, row, params ) {
			var ajax = ctrl;
			if (result && result.success) {

    swal("Success", result.message, "success").then(function() {

        if (result.qa_id) {
            window.location.href = "qa_incoming_goods_edit.php?editid1=" + result.qa_id;
        } else {
            location.reload();
        }

    });

} else {

    swal(
        "Notice",
        result && result.message ? result.message : "Unable to create QA Incoming Goods.",
        "warning"
    );

}
		}
	}

	$('a[data-event=' + gid + ']').each( function() {
		if ( $(this).closest('.gridRowAdd').length ) {
			return;
		}
		var rowId = Runner.genId();
		var eventId = gid + "_" + rowId;
		$(this).attr( 'data-event', eventId );
		this.id = this.id + "_" + Runner.genId();
		var buttonObj = new Runner.form.Button({
			id: eventId,
			btnName: gid
		});
		buttonObj.init( {args: [ pageObj, proxy, pageid ]} );
	});

};

