|
| 1 | +-- ============================================================================ |
| 2 | +-- Action confirmation — Studio Pro's "Ask confirmation" |
| 3 | +-- ============================================================================ |
| 4 | +-- |
| 5 | +-- A call-microflow or call-nanoflow action can ask the user before it runs: |
| 6 | +-- Studio Pro's "Ask confirmation" checkbox, stored as Forms$ConfirmationInfo |
| 7 | +-- (question, proceed caption, cancel caption). |
| 8 | +-- |
| 9 | +-- Confirmation: 'question' -- turns it on; the question text |
| 10 | +-- ConfirmationProceed: 'caption' -- optional, defaults to 'Proceed' |
| 11 | +-- ConfirmationCancel: 'caption' -- optional, defaults to 'Cancel' |
| 12 | +-- |
| 13 | +-- Works on an action button, a link button, and a clickable container — any |
| 14 | +-- widget whose Action: / OnClick: calls a microflow or a nanoflow. `describe` |
| 15 | +-- prints the properties back, leaving out captions equal to the defaults. |
| 16 | +-- |
| 17 | +-- Mendix stores NO confirmation on the other client actions (Delete, Save, |
| 18 | +-- Close page, Show page, …), so `Confirmation:` there is refused — by `check` |
| 19 | +-- as MDL-WIDGET35 and by `exec` — instead of being dropped. To confirm a delete, |
| 20 | +-- call a microflow that deletes, as the pages below do. |
| 21 | +-- |
| 22 | +-- ============================================================================ |
| 23 | + |
| 24 | +create module ConfirmTest; |
| 25 | + |
| 26 | +create persistent entity ConfirmTest.Item ( |
| 27 | + Name: string(200) not null, |
| 28 | + IsArchived: boolean default false |
| 29 | +); |
| 30 | + |
| 31 | +/** |
| 32 | + * Deletes one item. Called from the pages below with a confirmation, which is |
| 33 | + * how a delete asks first: the Delete client action itself cannot. |
| 34 | + * |
| 35 | + * @param $Item The item to delete |
| 36 | + */ |
| 37 | +create microflow ConfirmTest.ACT_Item_Delete ( |
| 38 | + $Item: ConfirmTest.Item |
| 39 | +) |
| 40 | +begin |
| 41 | + delete $Item; |
| 42 | +end; |
| 43 | +/ |
| 44 | + |
| 45 | +/** |
| 46 | + * Archives one item, client-side. |
| 47 | + * |
| 48 | + * @param $Item The item to archive |
| 49 | + */ |
| 50 | +create nanoflow ConfirmTest.ACT_Item_Archive ( |
| 51 | + $Item: ConfirmTest.Item |
| 52 | +) |
| 53 | +begin |
| 54 | + change $Item (IsArchived = true) refresh; |
| 55 | +end; |
| 56 | +/ |
| 57 | + |
| 58 | +-- MARK: Buttons |
| 59 | + |
| 60 | +/** |
| 61 | + * Action buttons and a link button with a confirmation. |
| 62 | + * |
| 63 | + * - btnDelete: question plus a custom proceed caption; cancel keeps Studio |
| 64 | + * Pro's default 'Cancel'. |
| 65 | + * - btnArchive: a nanoflow action; both captions custom. |
| 66 | + * - lnkDelete: the same on a link button, captions left at their defaults. |
| 67 | + * |
| 68 | + * @param $Item The item shown on the page |
| 69 | + */ |
| 70 | +create page ConfirmTest.Item_Detail |
| 71 | +( |
| 72 | + params: { $Item: ConfirmTest.Item }, |
| 73 | + title: 'Item', |
| 74 | + layout: Atlas_Core.PopupLayout |
| 75 | +) |
| 76 | +{ |
| 77 | + layoutgrid lgItem { |
| 78 | + row row1 { |
| 79 | + column col1 (desktopwidth: autofill) { |
| 80 | + dataview dvItem (datasource: $Item) { |
| 81 | + textbox txtName (label: 'Name', attribute: Name) |
| 82 | + footer footer1 { |
| 83 | + actionbutton btnDelete ( |
| 84 | + caption: 'Delete', |
| 85 | + action: microflow ConfirmTest.ACT_Item_Delete(Item: $Item), |
| 86 | + buttonstyle: danger, |
| 87 | + confirmation: 'Delete this item? This cannot be undone.', |
| 88 | + confirmationproceed: 'Delete' |
| 89 | + ) |
| 90 | + actionbutton btnArchive ( |
| 91 | + caption: 'Archive', |
| 92 | + action: nanoflow ConfirmTest.ACT_Item_Archive(Item: $Item), |
| 93 | + confirmation: 'Archive this item?', |
| 94 | + confirmationproceed: 'Archive', |
| 95 | + confirmationcancel: 'Keep' |
| 96 | + ) |
| 97 | + linkbutton lnkDelete ( |
| 98 | + caption: 'Delete (link)', |
| 99 | + action: microflow ConfirmTest.ACT_Item_Delete(Item: $Item), |
| 100 | + confirmation: 'Delete this item?' |
| 101 | + ) |
| 102 | + actionbutton btnClose (caption: 'Close', action: close_page) |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +-- MARK: Clickable container |
| 111 | + |
| 112 | +/** |
| 113 | + * A clickable container asks the same way: the confirmation goes on the |
| 114 | + * container that carries the action. |
| 115 | + */ |
| 116 | +create page ConfirmTest.Item_Overview |
| 117 | +( |
| 118 | + title: 'Items', |
| 119 | + layout: Atlas_Core.Atlas_Default |
| 120 | +) |
| 121 | +{ |
| 122 | + listview lvItems (datasource: database ConfirmTest.Item) { |
| 123 | + container cntItem ( |
| 124 | + class: 'card clickable', |
| 125 | + action: microflow ConfirmTest.ACT_Item_Delete(Item: $currentObject), |
| 126 | + confirmation: 'Delete this item?', |
| 127 | + confirmationproceed: 'Delete' |
| 128 | + ) { |
| 129 | + dynamictext txtItemName (content: '{1}', contentparams: [{1} = Name]) |
| 130 | + } |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +-- MARK: Describe |
| 135 | + |
| 136 | +-- Prints the Confirmation / ConfirmationProceed / ConfirmationCancel lines back. |
| 137 | +describe page ConfirmTest.Item_Detail; |
| 138 | +describe page ConfirmTest.Item_Overview; |
| 139 | + |
| 140 | +-- Refused — Mendix has no confirmation on a Delete client action (MDL-WIDGET35): |
| 141 | +-- |
| 142 | +-- actionbutton btnDeleteDirect (caption: 'Delete', action: delete, |
| 143 | +-- confirmation: 'Delete this item?') |
| 144 | +-- |
| 145 | +-- Call a microflow that deletes instead, as btnDelete above does. |
0 commit comments