Issue
Currently the provided KRAD JavaScript is mostly implemented as global functions. This means methods cannot be overridden by applications. Converting to Object would allow this. In addition, moving to Objects would allow for more readable/maintainble script code.
Proposal
1) Convert functions in KRAD files to Objects:
krad.ajax.js - KradAjax
krad.message.js - KradMessage
krad.utility.js - KradUtility
krad.validatate.js - KradValidate
krad.widget.js - KradWidgets
(Note krad.variables.js is already an Object).
2) A global variable will be created with an instance of each object:
This variable should be used whenever one of the KRAD methods are needed.
3) Refactor as we move along introducing properties in the objects and possibly breaking down in smaller objects
Note: We should also strive to follow the SRP (Single Responsibility Principal) for our methods. Each method does one task only. This will allow for only overriding what is necessary.
Application Overridding
Suppose our KradMessage object had the following method:
In a custom application file (included through the View configuration), the method can simply be redefined:
Since all of the KRAD code is using the kradMessage variable, all calls will now invoke the custom application showAlert method.
This overriding can be done on a view bases, or application bases (by having a JavaScript file included for all views or a base view).