Skip to content

Commit

Permalink
Fix multi step executor args passing /wo preview (#2060)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed May 31, 2023
1 parent a45717b commit a640009
Show file tree
Hide file tree
Showing 22 changed files with 152 additions and 158 deletions.
2 changes: 1 addition & 1 deletion demos/_includes/DemoActionsUtil.php
Expand Up @@ -56,7 +56,7 @@ public static function setupDemoActions(Country $country): void
},
]);

$country->addUserAction('edit_argument_prev', [
$country->addUserAction('edit_argument_preview', [
'caption' => 'Argument/Preview',
'description' => 'Ask for argument "Age" and display preview prior to execute',
'args' => [
Expand Down
4 changes: 2 additions & 2 deletions demos/data-action/factory-view.php
Expand Up @@ -26,7 +26,7 @@
'callback' => 'sync',
'preview' => 'eye',
'edit_argument' => 'user edit',
'edit_argument_prev' => 'pen square',
'edit_argument_preview' => 'pen square',
'edit_iso' => 'pencil',
'confirm' => 'check circle',
'multi_step' => 'window maximize outline',
Expand Down Expand Up @@ -63,7 +63,7 @@ protected function getCardButton(Model\UserAction $action)
$cardActions = Card::addTo($app, ['useLabel' => true, 'executorFactory' => new $myFactory()]);
$cardActions->setModel($country);
foreach ($country->getModel()->getUserActions() as $action) {
$showActions = ['callback', 'preview', 'edit_argument', 'edit_argument_prev', 'edit_iso', 'confirm', 'multi_step'];
$showActions = ['callback', 'preview', 'edit_argument', 'edit_argument_preview', 'edit_iso', 'confirm', 'multi_step'];
if (in_array($action->shortName, $showActions, true)) {
$cardActions->addClickAction($action);
}
Expand Down
26 changes: 12 additions & 14 deletions demos/interactive/modal.php
Expand Up @@ -166,23 +166,23 @@

// Add buttons to modal for next and previous actions.
$action = new View(['ui' => 'buttons']);
$prevAction = new Button(['Prev', 'icon' => 'left arrow']);
$previousAction = new Button(['Previous', 'icon' => 'left arrow']);
$nextAction = new Button(['Next', 'iconRight' => 'right arrow']);

$action->add($prevAction);
$action->add($previousAction);
$action->add($nextAction);

$stepModal->addButtonAction($action);

// Set modal functionality. Will changes content according to page being displayed.
$stepModal->set(function (View $p) use ($session, $prevAction, $nextAction) {
$stepModal->set(function (View $p) use ($session, $previousAction, $nextAction) {
$page = $session->recall('page', 1);
$success = $session->recall('success', false);
if (isset($_GET['move'])) {
if ($_GET['move'] === 'next' && $success) {
++$page;
}
if ($_GET['move'] === 'prev' && $page > 1) {
if ($_GET['move'] === 'previous' && $page > 1) {
--$page;
}
$session->memorize('success', false);
Expand All @@ -194,9 +194,9 @@
if ($page === 1) {
Message::addTo($p)->set('Thanks for choosing us. We will be asking some questions along the way.');
$session->memorize('success', true);
$p->js(true, $prevAction->js()->show());
$p->js(true, $previousAction->js()->show());
$p->js(true, $nextAction->js()->show());
$p->js(true, $prevAction->js()->addClass('disabled'));
$p->js(true, $previousAction->js()->addClass('disabled'));
$p->js(true, $nextAction->js()->removeClass('disabled'));
} elseif ($page === 2) {
$modelRegister = new Model(new Persistence\Array_());
Expand All @@ -219,25 +219,23 @@

return $js;
});
$p->js(true, $prevAction->js()->removeClass('disabled'));
$p->js(true, $previousAction->js()->removeClass('disabled'));
$p->js(true, $nextAction->js()->addClass('disabled'));
} elseif ($page === 3) {
$name = $session->recall('name');
Message::addTo($p)->set("Thank you {$name} for visiting us! We will be in touch");
$session->memorize('success', true);
$p->js(true, $prevAction->js()->hide());
$p->js(true, $previousAction->js()->hide());
$p->js(true, $nextAction->js()->hide());
}
});

// Bind next action to modal next button.
$nextAction->on('click', $stepModal->js()->atkReloadView(
['url' => $stepModal->cb->getJsUrl(), 'urlOptions' => ['move' => 'next']]
$previousAction->on('click', $stepModal->js()->atkReloadView(
['url' => $stepModal->cb->getJsUrl(), 'urlOptions' => ['move' => 'previous']]
));

// Bin prev action to modal previous button.
$prevAction->on('click', $stepModal->js()->atkReloadView(
['url' => $stepModal->cb->getJsUrl(), 'urlOptions' => ['move' => 'prev']]
$nextAction->on('click', $stepModal->js()->atkReloadView(
['url' => $stepModal->cb->getJsUrl(), 'urlOptions' => ['move' => 'next']]
));

// Bind display modal to page display button.
Expand Down
2 changes: 1 addition & 1 deletion demos/interactive/wizard.php
Expand Up @@ -43,7 +43,7 @@
});
});

// Alternatvely, you may access buttonNext , buttonPrev properties of a wizard
// Alternatvely, you may access buttonNext, buttonPrevious properties of a wizard
// and set a custom JS action or even set a different link. You can use recall()
// to access some values that were recorded on another steps.
$wizard->addStep(['Select Model', 'description' => '"Country" or "Stat"', 'icon' => 'table'], function (Wizard $wizard) {
Expand Down
4 changes: 2 additions & 2 deletions docs/wizard.rst
Expand Up @@ -81,12 +81,12 @@ started with 0.
When Wizard is initialized, it will set currentStep to a number (0, 1, 2, ..) corresponding to your steps
and finish callback, if you have specified it.

.. php:attr:: buttonPrev
.. php:attr:: buttonPrevious
.. php:attr:: buttonNext
.. php:attr:: buttonFinish
Those properties will be initialized with the buttons, but some of them may be destroyed by the render step,
if the button is not applicable. For example, first step should not have "prev" button. You can change label
if the button is not applicable. For example, first step should not have "Previous" button. You can change label
or icon on existing button.


Expand Down
8 changes: 7 additions & 1 deletion js/.eslintrc.js
Expand Up @@ -45,7 +45,13 @@ module.exports = {
'jsdoc/require-param-description': 'off',
'jsdoc/require-returns': 'off',
'jsdoc/require-returns-description': 'off',
'jsdoc/tag-lines': ['error', 'never', {
'jsdoc/sort-tags': ['error', {
tagSequence: [
{ tags: ['param'] },
{ tags: ['returns'] },
],
}],
'jsdoc/tag-lines': ['error', 'any', {
startLines: 1,
}],
'linebreak-style': ['error', 'unix'],
Expand Down
1 change: 1 addition & 0 deletions js/src/plugins/atk.plugin.js
Expand Up @@ -29,6 +29,7 @@ export default class AtkPlugin {
*
* @param {string} fn string representing the method name to execute.
* @param {Array.<*>} args array of arguments need for the method to execute.
*
* @returns {*}
*/
call(fn, args) {
Expand Down
16 changes: 8 additions & 8 deletions js/src/plugins/js-search.plugin.js
Expand Up @@ -11,7 +11,7 @@ export default class AtkJsSearchPlugin extends AtkPlugin {
this.searchAction = this.$el.find('.atk-search-button');
this.searchIcon = this.searchAction.find('i.atk-search-icon');
this.removeIcon = this.searchAction.find('i.atk-remove-icon').hide();
this.$el.data('preValue', '');
this.$el.data('previousValue', '');

this.setInputAction();
this.setSearchAction();
Expand Down Expand Up @@ -46,13 +46,13 @@ export default class AtkJsSearchPlugin extends AtkPlugin {
this.setFilterState(false);
this.textInput.val('');
});
} else if (e.target.value !== this.$el.data('preValue')) {
} else if (e.target.value !== this.$el.data('previousValue')) {
this.doSearch(this.settings.url, e.target.value, options, () => {
this.setButtonState(true);
this.setFilterState(true);
});
}
this.$el.data('preValue', e.target.value);
this.$el.data('previousValue', e.target.value);
}, this.settings.timeOut));
}

Expand All @@ -67,15 +67,15 @@ export default class AtkJsSearchPlugin extends AtkPlugin {
this.setButtonState(true);
this.setFilterState(true);
});
this.$el.data('preValue', e.target.value);
this.$el.data('previousValue', e.target.value);
} else if ((e.keyCode === 27 && e.target.value) || (e.keyCode === 13 && e.target.value === '')) {
this.doSearch(this.settings.url, null, options, () => {
this.setButtonState(false);
this.setFilterState(false);
});
this.$el.data('preValue', '');
this.$el.data('previousValue', '');
this.textInput.val('');
} else if (this.$el.data('preValue') !== e.target.value) {
} else if (this.$el.data('previousValue') !== e.target.value) {
this.setButtonState(false);
}
});
Expand Down Expand Up @@ -109,7 +109,7 @@ export default class AtkJsSearchPlugin extends AtkPlugin {
this.setFilterState(false);
});
this.textInput.val('');
this.$el.data('preValue', '');
this.$el.data('previousValue', '');
}

if (!this.state.button && this.textInput.val()) {
Expand All @@ -131,7 +131,7 @@ export default class AtkJsSearchPlugin extends AtkPlugin {
this.textInput.val(text);
this.setButtonState(true);
this.setFilterState(true);
this.$el.data('preValue', text);
this.$el.data('previousValue', text);
}

/**
Expand Down
1 change: 1 addition & 0 deletions js/src/services/api.service.js
Expand Up @@ -171,6 +171,7 @@ class ApiService {
*
* @param {string} url the URL to fetch data
* @param {object} settings the Fomantic-UI api settings object.
*
* @returns {Promise<any>}
*/
suiFetch(url, settings = {}, el = 'body') {
Expand Down
1 change: 1 addition & 0 deletions js/src/services/form.service.js
Expand Up @@ -84,6 +84,7 @@ class FormService {
* @param {$} $form Form containing the field.
* @param {string} fieldName Name of field
* @param {string|object} rule Rule to apply test.
*
* @returns {*|false}
*/
validateField($form, fieldName, rule) {
Expand Down
22 changes: 11 additions & 11 deletions js/src/services/modal.service.js
Expand Up @@ -67,11 +67,11 @@ class ModalService {
addModal($modal) {
// hide other modals
if (this.modals.length > 1) {
const $prevModal = $(this.modals.at(-2));
if ($prevModal.hasClass('visible')) {
$prevModal.css('visibility', 'hidden');
$prevModal.addClass('__hiddenNotFront');
$prevModal.removeClass('visible');
const $previousModal = $(this.modals.at(-2));
if ($previousModal.hasClass('visible')) {
$previousModal.css('visibility', 'hidden');
$previousModal.addClass('__hiddenNotFront');
$previousModal.removeClass('visible');
}
}

Expand Down Expand Up @@ -132,14 +132,14 @@ class ModalService {

// hide other modals
if (this.modals.length > 0) {
const $prevModal = $(this.modals.at(-1));
if ($prevModal.hasClass('__hiddenNotFront')) {
$prevModal.css('visibility', '');
$prevModal.addClass('visible');
$prevModal.removeClass('__hiddenNotFront');
const $previousModal = $(this.modals.at(-1));
if ($previousModal.hasClass('__hiddenNotFront')) {
$previousModal.css('visibility', '');
$previousModal.addClass('visible');
$previousModal.removeClass('__hiddenNotFront');
// recenter modal, needed even with observeChanges enabled
// https://github.com/fomantic/Fomantic-UI/issues/2476
$prevModal.modal('refresh');
$previousModal.modal('refresh');
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon.dist
Expand Up @@ -381,6 +381,9 @@ parameters:
-
path: 'src/Wizard.php'
message: '~^Property Atk4\\Ui\\Form::\$buttonSave \(array\|Atk4\\Ui\\Button\|false\) does not accept null\.$~'
-
path: 'src/Wizard.php'
message: '~^Property Atk4\\Ui\\Wizard::\$steps \(array<int, Atk4\\Ui\\WizardStep>\) does not accept array<int, Atk4\\Ui\\AbstractView>\.$~'

# TODO these rules are generated, this ignores should be fixed in the code
# for level = 5
Expand Down
41 changes: 22 additions & 19 deletions public/js/atkjs-ui.js
Expand Up @@ -307,6 +307,7 @@ class AtkPlugin {
*
* @param {string} fn string representing the method name to execute.
* @param {Array.<*>} args array of arguments need for the method to execute.
*
* @returns {*}
*/
call(fn, args) {
Expand Down Expand Up @@ -1007,7 +1008,7 @@ class AtkJsSearchPlugin extends _atk_plugin__WEBPACK_IMPORTED_MODULE_7__["defaul
this.searchAction = this.$el.find('.atk-search-button');
this.searchIcon = this.searchAction.find('i.atk-search-icon');
this.removeIcon = this.searchAction.find('i.atk-remove-icon').hide();
this.$el.data('preValue', '');
this.$el.data('previousValue', '');
this.setInputAction();
this.setSearchAction();
this.onEscapeKeyAction();
Expand Down Expand Up @@ -1041,13 +1042,13 @@ class AtkJsSearchPlugin extends _atk_plugin__WEBPACK_IMPORTED_MODULE_7__["defaul
this.setFilterState(false);
this.textInput.val('');
});
} else if (e.target.value !== this.$el.data('preValue')) {
} else if (e.target.value !== this.$el.data('previousValue')) {
this.doSearch(this.settings.url, e.target.value, options, () => {
this.setButtonState(true);
this.setFilterState(true);
});
}
this.$el.data('preValue', e.target.value);
this.$el.data('previousValue', e.target.value);
}, this.settings.timeOut));
}

Expand All @@ -1062,15 +1063,15 @@ class AtkJsSearchPlugin extends _atk_plugin__WEBPACK_IMPORTED_MODULE_7__["defaul
this.setButtonState(true);
this.setFilterState(true);
});
this.$el.data('preValue', e.target.value);
this.$el.data('previousValue', e.target.value);
} else if (e.keyCode === 27 && e.target.value || e.keyCode === 13 && e.target.value === '') {
this.doSearch(this.settings.url, null, options, () => {
this.setButtonState(false);
this.setFilterState(false);
});
this.$el.data('preValue', '');
this.$el.data('previousValue', '');
this.textInput.val('');
} else if (this.$el.data('preValue') !== e.target.value) {
} else if (this.$el.data('previousValue') !== e.target.value) {
this.setButtonState(false);
}
});
Expand Down Expand Up @@ -1103,7 +1104,7 @@ class AtkJsSearchPlugin extends _atk_plugin__WEBPACK_IMPORTED_MODULE_7__["defaul
this.setFilterState(false);
});
this.textInput.val('');
this.$el.data('preValue', '');
this.$el.data('previousValue', '');
}
if (!this.state.button && this.textInput.val()) {
this.doSearch(this.settings.url, this.textInput.val(), options, () => {
Expand All @@ -1124,7 +1125,7 @@ class AtkJsSearchPlugin extends _atk_plugin__WEBPACK_IMPORTED_MODULE_7__["defaul
this.textInput.val(text);
this.setButtonState(true);
this.setFilterState(true);
this.$el.data('preValue', text);
this.$el.data('previousValue', text);
}

/**
Expand Down Expand Up @@ -2081,6 +2082,7 @@ class ApiService {
*
* @param {string} url the URL to fetch data
* @param {object} settings the Fomantic-UI api settings object.
*
* @returns {Promise<any>}
*/
suiFetch(url) {
Expand Down Expand Up @@ -2406,6 +2408,7 @@ class FormService {
* @param {$} $form Form containing the field.
* @param {string} fieldName Name of field
* @param {string|object} rule Rule to apply test.
*
* @returns {*|false}
*/
validateField($form, fieldName, rule) {
Expand Down Expand Up @@ -2559,11 +2562,11 @@ class ModalService {
addModal($modal) {
// hide other modals
if (this.modals.length > 1) {
const $prevModal = external_jquery__WEBPACK_IMPORTED_MODULE_5___default()(this.modals.at(-2));
if ($prevModal.hasClass('visible')) {
$prevModal.css('visibility', 'hidden');
$prevModal.addClass('__hiddenNotFront');
$prevModal.removeClass('visible');
const $previousModal = external_jquery__WEBPACK_IMPORTED_MODULE_5___default()(this.modals.at(-2));
if ($previousModal.hasClass('visible')) {
$previousModal.css('visibility', 'hidden');
$previousModal.addClass('__hiddenNotFront');
$previousModal.removeClass('visible');
}
}
const data = $modal.data();
Expand Down Expand Up @@ -2620,14 +2623,14 @@ class ModalService {

// hide other modals
if (this.modals.length > 0) {
const $prevModal = external_jquery__WEBPACK_IMPORTED_MODULE_5___default()(this.modals.at(-1));
if ($prevModal.hasClass('__hiddenNotFront')) {
$prevModal.css('visibility', '');
$prevModal.addClass('visible');
$prevModal.removeClass('__hiddenNotFront');
const $previousModal = external_jquery__WEBPACK_IMPORTED_MODULE_5___default()(this.modals.at(-1));
if ($previousModal.hasClass('__hiddenNotFront')) {
$previousModal.css('visibility', '');
$previousModal.addClass('visible');
$previousModal.removeClass('__hiddenNotFront');
// recenter modal, needed even with observeChanges enabled
// https://github.com/fomantic/Fomantic-UI/issues/2476
$prevModal.modal('refresh');
$previousModal.modal('refresh');
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion public/js/atkjs-ui.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/atkjs-ui.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/atkjs-ui.min.js.map

Large diffs are not rendered by default.

0 comments on commit a640009

Please sign in to comment.