6
6
7
7
use Atk4 \Data \Model ;
8
8
use Atk4 \Data \Model \UserAction ;
9
+ use Atk4 \Ui \Form \Control \Dropdown ;
9
10
10
11
class DemoActionsUtil
11
12
{
@@ -15,7 +16,7 @@ public static function setupDemoActions(Country $country): void
15
16
'callback ' ,
16
17
[
17
18
'description ' => 'Callback ' ,
18
- 'callback ' => function (Model $ model ) {
19
+ 'callback ' => function (Country $ model ) {
19
20
return 'callback execute using country ' . $ model ->getTitle ();
20
21
},
21
22
]
@@ -25,10 +26,10 @@ public static function setupDemoActions(Country $country): void
25
26
'preview ' ,
26
27
[
27
28
'description ' => 'Display Preview prior to run the action ' ,
28
- 'preview ' => function (Model $ model ) {
29
+ 'preview ' => function (Country $ model ) {
29
30
return 'Previewing country ' . $ model ->getTitle ();
30
31
},
31
- 'callback ' => function (Model $ model ) {
32
+ 'callback ' => function (Country $ model ) {
32
33
return 'Done previewing ' . $ model ->getTitle ();
33
34
},
34
35
]
@@ -54,7 +55,7 @@ public static function setupDemoActions(Country $country): void
54
55
'args ' => [
55
56
'age ' => ['type ' => 'integer ' , 'required ' => true ],
56
57
],
57
- 'callback ' => function (Model $ model , $ age ) {
58
+ 'callback ' => function (Country $ model , int $ age ) {
58
59
if ($ age < 18 ) {
59
60
$ text = 'Sorry not old enough to visit ' . $ model ->getTitle ();
60
61
} else {
@@ -71,8 +72,10 @@ public static function setupDemoActions(Country $country): void
71
72
[
72
73
'caption ' => 'Argument/Preview ' ,
73
74
'description ' => 'Ask for argument "Age" and display preview prior to execute ' ,
74
- 'args ' => ['age ' => ['type ' => 'integer ' , 'required ' => true ]],
75
- 'preview ' => function (Model $ model , $ age ) {
75
+ 'args ' => [
76
+ 'age ' => ['type ' => 'integer ' , 'required ' => true ],
77
+ ],
78
+ 'preview ' => function (Country $ model , int $ age ) {
76
79
return 'You age is: ' . $ age ;
77
80
},
78
81
'callback ' => function (Model $ model , $ age ) {
@@ -100,7 +103,9 @@ public static function setupDemoActions(Country $country): void
100
103
[
101
104
'caption ' => 'Exception ' ,
102
105
'description ' => 'Throw an exception when executing an action ' ,
103
- 'args ' => ['age ' => ['type ' => 'integer ' ]],
106
+ 'args ' => [
107
+ 'age ' => ['type ' => 'integer ' ],
108
+ ],
104
109
'preview ' => function () {
105
110
return 'Be careful with this action. ' ;
106
111
},
@@ -115,10 +120,12 @@ public static function setupDemoActions(Country $country): void
115
120
[
116
121
'caption ' => 'User Confirmation ' ,
117
122
'description ' => 'Confirm the action using a ConfirmationExecutor ' ,
118
- 'confirmation ' => function ($ a ) {
119
- return 'Are you sure you want to perform this action on: <b> ' . $ a ->getEntity ()->getTitle () . ' ( ' . $ a ->getEntity ()->iso3 . ')</b> ' ;
123
+ 'confirmation ' => function (UserAction $ a ) {
124
+ $ iso3 = $ a ->getEntity ()->get (Country::hinting ()->fieldName ()->iso3 );
125
+
126
+ return 'Are you sure you want to perform this action on: <b> ' . $ a ->getEntity ()->getTitle () . ' ( ' . $ iso3 . ')</b> ' ;
120
127
},
121
- 'callback ' => function (Model $ model ) {
128
+ 'callback ' => function (Country $ model ) {
122
129
return 'Confirm country ' . $ model ->getTitle ();
123
130
},
124
131
]
@@ -132,15 +139,24 @@ public static function setupDemoActions(Country $country): void
132
139
'args ' => [
133
140
'age ' => ['type ' => 'integer ' , 'required ' => true ],
134
141
'city ' => [],
135
- 'gender ' => ['type ' => 'string ' , /* TODO 'values' => ['m' => 'Male', 'f' => 'Female'], */ 'required ' => true , 'default ' => 'm ' ],
142
+ 'gender ' => [
143
+ 'type ' => 'string ' ,
144
+ 'required ' => true ,
145
+ 'default ' => 'm ' ,
146
+ 'ui ' => [
147
+ 'form ' => [
148
+ Dropdown::class, 'values ' => ['m ' => 'Male ' , 'f ' => 'Female ' ],
149
+ ],
150
+ ],
151
+ ],
136
152
],
137
153
'fields ' => [$ country ->fieldName ()->iso3 ],
138
- 'callback ' => function (Model $ model , $ age , $ city , $ gender ) {
154
+ 'callback ' => function (Country $ model , int $ age , string $ city , string $ gender ) {
139
155
$ n = $ gender === 'm ' ? 'Mr. ' : 'Mrs. ' ;
140
156
141
157
return 'Thank you ' . $ n . ' at age ' . $ age ;
142
158
},
143
- 'preview ' => function (Model $ model , $ age , $ city , $ gender ) {
159
+ 'preview ' => function (Country $ model , int $ age , string $ city , string $ gender ) {
144
160
return 'Gender = ' . $ gender . ' / Age = ' . $ age ;
145
161
},
146
162
]
0 commit comments