Skip to content

Commit

Permalink
Simplify configuration for confirmation dialogs in action menus (CFM-…
Browse files Browse the repository at this point in the history
…314) (#115)
  • Loading branch information
arlen authored Aug 4, 2023
1 parent e892c37 commit 08e1973
Show file tree
Hide file tree
Showing 12 changed files with 194 additions and 131 deletions.
12 changes: 12 additions & 0 deletions app/resources/locales/en_US/operation.po
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ msgstr "Are you sure you wish to generate a new API Key?"
msgid "applySchema"
msgstr "Apply Database Schema"

msgid "assign"
msgstr "Assign"

msgid "cancel"
msgstr "Cancel"

Expand All @@ -57,6 +60,9 @@ msgstr "Close"
msgid "confirm"
msgstr "Confirm"

msgid "confirm.generic"
msgstr "Are you sure you want to confirm this action?"

msgid "configure.a"
msgstr "Configure {0}"

Expand Down Expand Up @@ -99,6 +105,9 @@ msgstr "Go"
msgid "identifiers.assign"
msgstr "Assign Identifiers"

msgid "identifiers.assign.confirm"
msgstr "Are you sure you want to assign identifiers to this record ({0})?"

msgid "last"
msgstr "Last"

Expand Down Expand Up @@ -138,6 +147,9 @@ msgstr "Add/Restore Default Types"
msgid "reconcile"
msgstr "Reconcile"

msgid "reconcile.confirm"
msgstr "Are you sure you want to reconcile this group ({0})?"

msgid "remove"
msgstr "Remove"

Expand Down
11 changes: 4 additions & 7 deletions app/templates/Groups/columns.inc
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,12 @@ $rowActions = [
'action' => 'index',
'icon' => 'history'
],
[
'controller' => 'identifiers',
'action' => 'index',
'icon' => 'label',
'if' => 'notAutomatic'
],
[
'action' => 'reconcile',
'icon' => 'sync'
'icon' => 'sync',
'confirm' => [
'dg_confirm_btn' => __d('operation', 'reconcile')
]
]
];

Expand Down
9 changes: 9 additions & 0 deletions app/templates/Groups/fields-nav.inc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ $topLinks = [
'group_id' => $vv_obj->id
]
],
'if' => 'notAutomatic',
'confirm' => [
'dg_body_txt' => __d('operation', 'identifiers.assign.confirm',[$vv_obj->id]),
'dg_confirm_btn' => __d('operation', 'assign')
],
'class' => ''
],
[
Expand All @@ -83,6 +88,10 @@ $topLinks = [
'action' => 'reconcile',
$vv_obj->id
],
'confirm' => [
'dg_body_txt' => __d('operation', 'reconcile.confirm', [$vv_obj->id]),
'dg_confirm_btn' => __d('operation', 'reconcile')
],
'class' => ''
]
];
Expand Down
9 changes: 6 additions & 3 deletions app/templates/IdentifierAssignments/columns.inc
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ $rowActions = [
'icon' => 'electrical_services'
]
];

// TODO: develop $bulkActions. For now, use a placeholder.

/*
// When the $bulkActions variable exists in a columns.inc config, the "Bulk edit" switch will appear in the index.
$bulkActions = [
// TODO: develop bulk actions. For now, use a placeholder.
'delete' => true
];
];
*/
4 changes: 4 additions & 0 deletions app/templates/People/fields-nav.inc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ $topLinks = [
'person_id' => $vv_obj->id
]
],
'confirm' => [
'dg_body_txt' => __d('operation', 'identifiers.assign.confirm', [$vv_obj->id]),
'dg_confirm_btn' => __d('operation', 'assign')
],
'class' => ''
]
];
Expand Down
14 changes: 9 additions & 5 deletions app/templates/ProvisioningTargets/status.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,31 @@
[
'order' => $this->Menu->getMenuOrder('Default'),
'icon' => 'start',
'url' => $this->Url->build([
'url' => [
'controller' => $vv_primary_link_model,
'action' => 'provision',
$vv_primary_link_obj->id,
'?' => [
'provisioning_target_id' => $p['target']->id
]
]),
'label' => __d('operation', 'provision')
],
'label' => __d('operation', 'provision'),
'confirm' => [
'dg_body_txt' => __d('operation', 'provision.confirm'),
'dg_confirm_btn' => __d('operation', 'provision')
]
],
[
'order' => $this->Menu->getMenuOrder('Default'),
'icon' => 'history',
'url' => $this->Url->build([
'url' => [
'controller' => 'provisioning_history_records',
'action' => 'index',
'?' => [
'provisioning_target_id' => $p['target']->id,
StringUtilities::entityToForeignKey($vv_primary_link_obj) => $vv_primary_link_obj->id
]
]),
],
'label' => __d('controller', 'ProvisioningHistoryRecords', [99])
]
];
Expand Down
27 changes: 12 additions & 15 deletions app/templates/Standard/add-edit-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,32 +125,29 @@
$action_args['vv_actions'][] = [
'order' => $this->Menu->getMenuOrder($t['order']),
'icon' => $this->Menu->getMenuIcon($t['icon']),
'url' => $this->Url->build($t['link']),
'url' => $t['link'],
'label' => $t['label'],
'class' => !empty($t['class']) ? $t['class'] : '',
'confirm' => !empty($t['confirm']) ? $t['confirm'] : []
];
}
}

// Delete
if($vv_action != 'add' && !empty($vv_obj->id) && $vv_permissions['delete']) {
$actionPostBtnArray = ['action' => 'delete', $vv_obj->id];
$actionUrl = $this->Url->build(['action' => 'delete', $vv_obj->id]);
$action_args['vv_actions'][] = array(
$action_args['vv_actions'][] = [
'order' => $this->Menu->getMenuOrder('Delete'),
'icon' => $this->Menu->getMenuIcon('Delete'),
'url' => 'javascript:void(0);',
'url' => ['action' => 'delete', $vv_obj->id],
'label' => __d('operation', 'delete'),
'class' => 'deletebutton nospin',
'onclick' => array(
'dg_bd_txt' => __d('operation', 'delete.confirm', [$vv_obj->id]),
'dg_post_btn_array' => $actionPostBtnArray,
'dg_url' => $actionUrl,
'dg_conf_btn' => __d('operation', 'remove'),
'dg_cancel_btn' => __d('operation', 'cancel'),
'class' => 'deletebutton',
'confirm' => [
'method' => 'post',
'dg_title' => __d('operation', 'remove'),
'dg_bd_txt_repl_str' => ''
)
);
'dg_body_txt' => __d('operation', 'delete.confirm', [$vv_obj->id]),
'dg_confirm_btn' => __d('operation', 'remove')
]
];
}

if(!empty($action_args['vv_actions'])) {
Expand Down
111 changes: 53 additions & 58 deletions app/templates/Standard/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,11 @@
$action_args['vv_actions'][] = [
'order' => $this->Menu->getMenuOrder('Add'),
'icon' => $this->Menu->getMenuIcon('Add'),
'url' => $this->Url->build(
[
'controller' => $modelsName,
'action' => 'add',
'?' => $linkFilter
]
),
'url' => [
'controller' => $modelsName,
'action' => 'add',
'?' => $linkFilter
],
'label' => __d('operation', 'add.a', __d('controller', $modelsName, [1])),
];
}
Expand All @@ -128,8 +126,10 @@
$action_args['vv_actions'][] = [
'order' => $this->Menu->getMenuOrder($t['order']),
'icon' => $this->Menu->getMenuIcon($t['icon']),
'url' => $this->Url->build($t['link']),
'url' => $t['link'],
'label' => $t['label'],
'class' => !empty($t['class']) ? $t['class'] : '',
'confirm' => !empty($t['confirm']) ? $t['confirm'] : []
];
}
}
Expand Down Expand Up @@ -260,65 +260,60 @@
$actionIcon = !empty($a['icon']) ? $a['icon'] : $this->Menu->getMenuIcon('Default');
$actionIconClass = !empty($a['iconClass']) ? $a['iconClass'] : '';
$actionClass = !empty($a['class']) ? $a['class'] : '';
$actionUrl = '';
$actionLabel = '';
$actionOnClick = []; // used for confirmation dialog
$actionUrl = ['action' => $a['action'], $entity->id];
$actionLabel = !empty($a['label']) ? $a['label'] : __d('operation', $a['action']);

// Generate the link text and urls:

// If we have a .confirm text, we need to generate a confirm dialog box
$confirmKey = $a['action'].'.confirm';
$confirmTxt = __d('operation', $confirmKey);
if (!empty($a['controller'])) {
// We're linking into a related controller
$actionLabel = !empty($a['label']) ? $a['label'] : __d('controller', Inflector::camelize(Inflector::pluralize($a['controller'])), [99]);
$actionUrl = [
'controller' => $a['controller'],
'action' => $a['action'],
'?' => [$tableFK => $entity->id]
];
}

if($confirmTxt != $confirmKey) {
// We found the localized string
$actionPostBtnArray = ['action' => $a['action'], $entity->id];
$actionUrl = $this->Url->build(['action' => $a['action'], $entity->id]);
// XXX should be configurable which field we put in, maybe displayField?
// Generate the link text and urls:

if(!empty($a['confirm'])) {
// Gather the default confirmation body text. By convention this is named
// [action].confirm in the operation.po file but can be overridden in the actions array.
$confirmKey = $a['action'].'.confirm';
$confirmTxt = __d('operation', $confirmKey, [$entity->id]);

// Gather the dialog text - we need to expand these (here) so we can provide the default confirmTxt when appropriate
$dialogBodyText = !empty($a['confirm']['dg_body_txt']) ? $a['confirm']['dg_body_txt'] : $confirmTxt;
$dialogTitle = !empty($a['confirm']['dg_title']) ? $a['confirm']['dg_title'] : $actionLabel;
$confirmButtonText = !empty($a['confirm']['dg_confirm_btn']) ? $a['confirm']['dg_confirm_btn'] : __d('operation','confirm');
$cancelButtonText = !empty($a['confirm']['dg_cancel_btn']) ? $a['confirm']['dg_cancel_btn'] : __d('operation','cancel');
$replacements = !empty($a['confirm']['dg_body_txt_replacements']) ? $a['confirm']['dg_body_txt_replacements'] : '';

$action_args['vv_actions'][] = array(
'order' => $actionOrder,
'icon' => $actionIcon,
'url' => 'javascript:void(0);',
'label' => __d('operation', $a['action']),
'iconClass' => $actionIconClass,
'url' => $actionUrl,
'label' => $actionLabel,
'class' => !empty($actionClass) ? $actionClass . ' nospin' : 'nospin',
'onclick' => array(
'dg_bd_txt' => __d('operation', $confirmKey, [$entity->id]), // dialog body text
'dg_post_btn_array' => $actionPostBtnArray, // postButton array for building the postButton
'dg_url' => $actionUrl, // action url for building a unique ID
'dg_conf_btn' => __d('operation', 'confirm'), // dialog confirm button text
'dg_cancel_btn' => __d('operation', 'cancel'), // dialog cancel button text
'dg_title' => __d('operation', 'confirm'), // dialog box title
'dg_bd_txt_repl_str' => '' // dialog body text replacement strings
),
);
} elseif(!empty($a['controller'])) {
// We're linking into a related controller
$actionLabel = __d('controller', Inflector::camelize(Inflector::pluralize($a['controller'])), [99]);
$actionUrl = $this->Url->build(
['controller' => $a['controller'],
'action' => $a['action'],
'?' => [ $tableFK => $entity->id] ]
'confirm' => [
'dg_title' => $dialogTitle,
'dg_body_txt' => $dialogBodyText,
'dg_confirm_btn' => $confirmButtonText,
'dg_cancel_btn' => $cancelButtonText,
'dg_body_txt_replacements' => $replacements
]
);
} else {
$actionLabel = __d('operation', $a['action']);
$actionUrl = $this->Url->build(['action' => $a['action'], $entity->id]);
}

// If a specific label is sent in the config, use it instead
if(!empty($a['label'])) {
$actionLabel = $a['label'];
// Set the action link configuration
$action_args['vv_actions'][] = array(
'order' => $actionOrder,
'icon' => $actionIcon,
'iconClass' => $actionIconClass,
'url' => $actionUrl,
'label' => $actionLabel,
'class' => $actionClass
);
}

// Set the action link configuration
$action_args['vv_actions'][] = array(
'order' => $actionOrder,
'icon' => $actionIcon,
'iconClass' => $actionIconClass,
'url' => $actionUrl,
'label' => $actionLabel,
'class' => $actionClass,
'onclick' => $actionOnClick
);
}
}

Expand Down
Loading

0 comments on commit 08e1973

Please sign in to comment.