| 1 |
This directory in dojox/mvc/tests/controllers is used to show the differences when using different types of MVC Controllers. |
| 2 |
|
| 3 |
step1_test_mvc.html |
| 4 |
Just uses getStateful(), it does not use a controller. |
| 5 |
The getStateful call will take json data and make it Stateful. |
| 6 |
In this example a transform (transformAddress2Class) is used to hide the row for AddressLine2 if it is blank. |
| 7 |
'dojox/mvc/parserExtension' is required for this since the row being hidden is not a widget. |
| 8 |
The class attribute is bound to AddressLine2 with a direction and a transform. |
| 9 |
|
| 10 |
|
| 11 |
step2_test_mvc.html |
| 12 |
Step 2 of tests for Controllers, uses a ModelRefController. |
| 13 |
To move from getStateful to ModelRefController, the only change other than the call to require and call new ModelRefController, |
| 14 |
is to change the binding on the groups to use ctrl instead of model. |
| 15 |
|
| 16 |
This example also uses the transform (transformAddress2Class) to hide the row for AddressLine2 if it is blank. |
| 17 |
|
| 18 |
The ModelRefController constructor sets model to the results of the getStateful call which will take json data and make it Stateful |
| 19 |
|
| 20 |
|
| 21 |
step3_test_mvc.html |
| 22 |
Step 3 of test for Controllers, uses an EditModelRefController with holdModelUntilCommit: true. |
| 23 |
To move from ModelRefController to use EditModelRefController, need to require EditModelRefController. |
| 24 |
and on the new call use sourceModel instead of model. |
| 25 |
|
| 26 |
EditModelRefController adds support for reset() and commit(), so buttons were added to show Reset and Save (commit). |
| 27 |
|
| 28 |
With holdModelUntilCommit set to true, you will want to bind the output address for the group to |
| 29 |
"target: at(ctrl,'sourceModel')", if holdModelUntilCommit is false you can stay with model, sourceModel will also work. |
| 30 |
You can change holdModelUntilCommit to false to see how that works, updates will be reflected into the Verify section |
| 31 |
immediately upon focus changes, and Reset will revert back to the last saved model. |
| 32 |
The EditModelRefController constructor sets sourceModel to the results of the getStateful call which will take json data and create make it Stateful |
| 33 |
|
| 34 |
|
| 35 |
step4_test_mvc.html |
| 36 |
Step 4 of test for Controllers, uses a StoreRefController. |
| 37 |
To move from ModelRefController to use StoreRefController, need to require StoreRefController, Memory (store), and when |
| 38 |
Also needed to change the data to be valid for a store query. |
| 39 |
Setup StoreRefController and use ctrl.queryStore() to setup the models. |
| 40 |
|
| 41 |
Because of the queryStore call had to move the call to parser.parse inside the when to wait for it. |
| 42 |
The change in the data for queryStore required changes to the bindings, shad to add a group with target: at('rel:','0') |
| 43 |
for the bindings of fields. |
| 44 |
|
| 45 |
An exprchar:'%' was used for an mvc/Output just to show how it is used. |
| 46 |
|
| 47 |
|
| 48 |
step5_test_mvc.html |
| 49 |
Step 5 of test for Controllers, uses an EditStoreRefController with holdModelUntilCommit: true. |
| 50 |
To move from an EditModelRefController to use an EditStoreRefController, need to require EditStoreRefController, |
| 51 |
Memory, and when. Also needed to change the data to be valid for a store query. |
| 52 |
|
| 53 |
Because of the queryStore call had to move the call to parser.parse inside the when to wait for it. |
| 54 |
The change in the data for queryStore required changes to the bindings. had to add a group with target: at('rel:','0') |
| 55 |
for the bindings of fields. |
| 56 |
|
| 57 |
With holdModelUntilCommit set to true, you will want to bind the output address for the group to |
| 58 |
"target: at(ctrl,'sourceModel')", if holdModelUntilCommit is false you can stay with model, sourceModel will also work. |
| 59 |
You can change holdModelUntilCommit to false to see how that works, updates will be reflected into the Verify section |
| 60 |
immediately upon focus changes, and Reset will revert back to the last saved model. |
| 61 |
The EditStoreRefController constructor sets store to the memory store and uses queryStore() to setup the models. |
| 62 |
|
| 63 |
|
| 64 |
step6_test_mvc.html |
| 65 |
Step 6 of test for Controllers, uses a ListController. |
| 66 |
To move from ModelRefController to also use ListController, |
| 67 |
Need to require declare, and ListController, I also needed WidgetList and _InlineTemplateMixin. |
| 68 |
mvc/parserExtension is still needed to bind to class with data-mvc-bindings for 'AddressLine2' |
| 69 |
Decided to setup a ctrlclz with ListController to have the functions as part of the controller. |
| 70 |
The data had to be changed to be array data. |
| 71 |
The html was updated to use a WidgetList to show a radio button group with the choices, and to use a |
| 72 |
"cursor" binding for the selected address. |
| 73 |
Added a transform (transformRadioChecked) to change the cursorIndex when a different AddressName radio button is |
| 74 |
selected. Also added an addEmpty function to add a New Address to the list. |
| 75 |
|
| 76 |
|
| 77 |
step7_test_mvc.html |
| 78 |
Step 7 of test for Controllers, uses an EditModelRefController and ListController. |
| 79 |
To move from ModelRefController to also use EditModelRefController and a ListController, |
| 80 |
Need to require declare, and EditModelRefController, ListController, |
| 81 |
I also needed WidgetList and _InlineTemplateMixin. |
| 82 |
|
| 83 |
Needed to setup ctrlclz with EditModelRefController and ListController, and the data needs to be array data and the |
| 84 |
call to new ctrlclz uses sourceModel instead of model, and sets holdModelUntilCommit |
| 85 |
The html was updated to use a WidgetList to show a radio button group with the choices, and to use a |
| 86 |
"cursor" binding for the selected address. |
| 87 |
Added a transform (transformRadioChecked) to change the cursorIndex when a different AddressName radio button is |
| 88 |
selected. Also added an addEmpty function to add a New Address to the list. |
| 89 |
|
| 90 |
|
| 91 |
step8_test_mvc.html |
| 92 |
Step 8 of test for Controllers, uses an EditStoreRefListController with holdModelUntilCommit: false |
| 93 |
To move from ModelRefController with EditModelRefController and a ListController to a EditStoreRefListController |
| 94 |
Need to require the EditStoreRefListController, when, and Memory |
| 95 |
I also needed to change the data to be valid for a store query. |
| 96 |
Needed to setup ctrlclz with EditStoreRefListController, and use when and ctrl.queryStore() to setup the models. |
| 97 |
|
| 98 |
This test uses holdModelUntilCommit: false on the WidgetList, so updates to the address will immediately show-up in |
| 99 |
the verify section and in the select an address section, but changes can be "Reset" back to their last saved state. |
| 100 |
|
| 101 |
|
| 102 |
step9_test_mvc.html |
| 103 |
Step 9 of test for Controllers, uses an EditStoreRefListController with holdModelUntilCommit: true |
| 104 |
To move from EditStoreRefListController with holdModelUntilCommit: false to use holdModelUntilCommit: true |
| 105 |
I had to add the require for dojox/mvc/at and ListController |
| 106 |
|
| 107 |
This test uses holdModelUntilCommit: true on the WidgetList, so updates to the address will not show-up in |
| 108 |
the "Verify" section and in the "Select an address" section until "Save" is pressed. |
| 109 |
But using holdModelUntilCommit: true requires use of a second controller (ctrlSource) which is a ListController |
| 110 |
and is bound to the sourceModel and cursorIndex of the first controller (ctrl). |
| 111 |
|
| 112 |
The "Verify" section and the "Select an address" section are bound to at(ctrlSource,'cursor') and at(ctrlSource, 'model') respectively. |
| 113 |
To set the Radio buttons correctly, "Checked" has to be updated in ctrl.model inside the transformRadioChecked. |