package test; // RUI Handler import com.ibm.egl.rui.mvc.Controller; import com.ibm.egl.rui.mvc.FormField; import com.ibm.egl.rui.mvc.FormManager; import com.ibm.egl.rui.mvc.MVC; import com.ibm.egl.rui.mvc.MVCLib; import com.ibm.egl.rui.widgets.Button; import com.ibm.egl.rui.widgets.GridLayout; import com.ibm.egl.rui.widgets.GridLayoutData; import com.ibm.egl.rui.widgets.TextLabel; import egl.javascript.Job; import egl.ui.rui.Event; import egl.ui.rui.Widget; import dojo.widgets.DojoDateTextBox; import dojo.widgets.DojoLib; import dojo.widgets.DojoTextField; import dojo.widgets.DojoValidationBase; import sos.dojo.widgets.DojoFilteringSelectWrapper; import sos.widgets.parts.ListItem; // // handler TestHandler2 type RUIhandler {initialUI = [ ui ],onConstructionFunction = start, cssFile="css/TestRui.css", title="TestHandler2"} private const ATTR_NAME string = "attrName"; ui GridLayout{ columns = 3, rows = 4, cellPadding = 4, children = [ buttonCommit, buttonPublish, buttonClear, model_ui ] }; model TestData; model_ui GridLayout { layoutData = new GridLayoutData{ row = 1, column = 1, horizontalSpan = 3 }, rows = 8, columns = 2, cellPadding = 4, children = [ model_key1_nameLabel,model_key1_field,model_text1_nameLabel,model_text1_field,model_int1_nameLabel,model_int1_field,model_amount1_nameLabel,model_amount1_field,model_date1_nameLabel,model_date1_textBox,model_code1_nameLabel,model_code1_select,model_date2_nameLabel,model_date2_textBox,model_code2_nameLabel,model_code2_select ] }; model_key1_nameLabel TextLabel { text="key1" , layoutData = new GridLayoutData { row = 1, column = 1} }; model_key1_field DojoTextField { constraints = new Dictionary{attrName="key1"}, layoutData = new GridLayoutData { row = 1, column = 2} }; model_key1_controller Controller { @MVC {model = model.key1, view = model_key1_field as Widget}, validators = [controllerValidator], validStateSetter = handleValidStateChange_model}; model_key1_formField FormField { controller = model_key1_controller, nameLabel = model_key1_nameLabel}; model_text1_nameLabel TextLabel { text="text1" , layoutData = new GridLayoutData { row = 2, column = 1} }; model_text1_field DojoTextField {constraints = new Dictionary{attrName="text1"}, layoutData = new GridLayoutData { row = 2, column = 2} }; model_text1_controller Controller { @MVC {model = model.text1, view = model_text1_field as Widget}, validators = [controllerValidator], validStateSetter = handleValidStateChange_model}; model_text1_formField FormField { controller = model_text1_controller, nameLabel = model_text1_nameLabel}; model_int1_nameLabel TextLabel { text="int1" , layoutData = new GridLayoutData { row = 3, column = 1} }; model_int1_field DojoTextField {constraints = new Dictionary{attrName="int1"}, layoutData = new GridLayoutData { row = 3, column = 2}, inputRequired = true }; model_int1_controller Controller { @MVC {model = model.int1, view = model_int1_field as Widget}, validators = [controllerValidator], validStateSetter = handleValidStateChange_model}; model_int1_formField FormField { controller = model_int1_controller, nameLabel = model_int1_nameLabel}; model_amount1_nameLabel TextLabel { text="amount1" , layoutData = new GridLayoutData { row = 4, column = 1} }; model_amount1_field DojoTextField {constraints = new Dictionary{attrName="amount1"}, layoutData = new GridLayoutData { row = 4, column = 2} }; model_amount1_controller Controller { @MVC {model = model.amount1, view = model_amount1_field as Widget}, validators = [controllerValidator], validStateSetter = handleValidStateChange_model}; model_amount1_formField FormField { controller = model_amount1_controller, nameLabel = model_amount1_nameLabel}; model_date1_nameLabel TextLabel { text="date1" , layoutData = new GridLayoutData { row = 5, column = 1} }; model_date1_textBox DojoDateTextBox { formatLength = DojoLib.DATEBOX_FORMAT_LONG, value = model.date1 , constraints = new Dictionary{attrName="date1"}, layoutData = new GridLayoutData { row = 5, column = 2} }; model_date1_controller Controller { @MVC {model = model.date1, view = model_date1_textBox as Widget}, validators = [controllerValidator], validStateSetter = handleValidStateChange_model}; model_date1_formField FormField { controller = model_date1_controller, nameLabel = model_date1_nameLabel}; model_code1_nameLabel TextLabel { text="code1" , layoutData = new GridLayoutData { row = 6, column = 1} }; model_code1_select DojoFilteringSelectWrapper {inputRequired = true, inputRequiredMessage = "verplicht", id="code1", placeholder="code1", constraints = new Dictionary{attrName="code1"}, layoutData = new GridLayoutData { row = 6, column = 2} }; model_code1_controller Controller { @MVC {model = model.code1, view = model_code1_select as Widget}, validators = [controllerValidator], validStateSetter = handleValidStateChange_model}; model_code1_formField FormField { controller = model_code1_controller, nameLabel = model_code1_nameLabel}; model_date2_nameLabel TextLabel { text="date2" , layoutData = new GridLayoutData { row = 7, column = 1} }; model_date2_textBox DojoDateTextBox { formatLength = DojoLib.DATEBOX_FORMAT_LONG, value = model.date2 , constraints = new Dictionary{attrName="date2"}, layoutData = new GridLayoutData { row = 7, column = 2} }; model_date2_controller Controller { @MVC {model = model.date2, view = model_date2_textBox as Widget}, validators = [controllerValidator], validStateSetter = handleValidStateChange_model}; model_date2_formField FormField { controller = model_date2_controller, nameLabel = model_date2_nameLabel}; model_code2_nameLabel TextLabel { text="code2" , layoutData = new GridLayoutData { row = 8, column = 1} }; model_code2_select DojoFilteringSelectWrapper {id="code2", placeholder="code2", constraints = new Dictionary{attrName="code2"}, layoutData = new GridLayoutData { row = 8, column = 2} }; model_code2_controller Controller { @MVC {model = model.code2, view = model_code2_select as Widget}, validators = [controllerValidator], validStateSetter = handleValidStateChange_model}; model_code2_formField FormField { controller = model_code2_controller, nameLabel = model_code2_nameLabel}; model_form FormManager {entries = [ model_key1_formField,model_text1_formField,model_int1_formField,model_amount1_formField,model_date1_formField,model_code1_formField,model_date2_formField,model_code2_formField ] }; buttonClear Button{ layoutData = new GridLayoutData{ row = 2, column = 1 }, text = "Clear", onClick ::= buttonClear_onClick }; buttonPublish Button{ layoutData = new GridLayoutData{ row = 2, column = 2 }, text = "Publish", onClick ::= buttonPublish_onClick }; buttonCommit Button{ layoutData = new GridLayoutData{ row = 2, column = 3 }, text = "Commit", onClick ::= buttonCommit_onClick }; function start() new Job{runFunction = postStartup}.schedule(0); end function postStartup() model_code1_select.values = [ new ListItem{itemLabel = "Euro", itemValue = "1"}, new ListItem{itemLabel = "Thai bath", itemValue = "2"}, new ListItem{itemLabel = "Dollar", itemValue = "3"} ]; model_code2_select.values = [ new ListItem{itemLabel = "Item 1", itemValue = "1"}, new ListItem{itemLabel = "Item 2", itemValue = "2"}, new ListItem{itemLabel = "Item 3", itemValue = "3"} ]; end function model_form_Submit(event Event in) if(model_form.isValid()) model_form.commit(); end end function model_form_Publish(event Event in) model_form.publish(); model_form_Validate(); end function model_form_Validate() model_form.isValid(); end function handleValidStateChange_model(view Widget in, valid boolean in) for (n int from model_form.entries.getSize() to 1 decrement by 1) entry FormField = model_form.entries[n]; if(entry.controller.view == view) if(valid) // TODO: handle valid value else msg String? = entry.controller.getErrorMessage(); // TODO: handle invalid value end end end end private function buttonClear_onClick(event Event in) emptyView TestData; model = emptyView; model_form.publish(); end private function buttonPublish_onClick(event Event in) newData TestData; newData.key1 = "key1"; newData.date1 = "01-01-2013"; newData.code1 = "1"; model = newData; model_form.publish(); end private function buttonCommit_onClick(event Event in) if(model_form.isValid()) model_form.commit(); SysLib.writeStdout("code 1: " :: model.code1); else model_code1_select.focus(); SysLib.writeStdout("Form not valid"); end end function controllerValidator(input String in) returns(string?) currentController Controller = MVCLib.getCurrentContext(); widget Widget = currentController.view; constraints Dictionary; case when (widget isa DojoTextField) constraints = (widget as DojoTextField).constraints; when (widget isa DojoDateTextBox) constraints = (widget as DojoDateTextBox).constraints; when (widget isa DojoFilteringSelectWrapper) constraints = (widget as DojoFilteringSelectWrapper).constraints; end if (constraints != null) if (constraints.containsKey(ATTR_NAME)) attrName string = constraints[ATTR_NAME]; SysLib.writeStdout("controllerValidator for " :: attrName); end end end end