Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom Fomantic-UI Modal.onHidden callback #1938

Merged
merged 1 commit into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/src/services/api.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ApiService {
* To avoid conflict, property name in response was change from eval to atkjs.
* Which mean response.atkjs now contains code to be eval.
*/
onSuccess(response, element) {
onSuccess(response) {
try {
if (response.success) {
if (response.html && response.id) {
Expand Down
27 changes: 3 additions & 24 deletions js/src/services/popup.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,21 @@ class PopupService {
{
},
{
onCreate: this.onCreate,
onShow: this.onShow,
onHide: this.onHide,
onRemove: this.onRemove,
},
];
}

/**
* OnShow callback when a popup is trigger.
* Will check if popup needs to be setup dynamically using a callback.
* Check if popup needs to be setup dynamically using a callback.
*/
onShow($module) {
const $popup = this;
const data = $popup.data();
if (data.url !== '' && data.url !== undefined) {
// Only load if we are not using data.cache or content has not been loaded yet.
// only load if we are not using data.cache or content has not been loaded yet
if (!data.cache || !data.hascontent) {
// display default loader while waiting for content.
// display default loader while waiting for content
$popup.html(atk.popupService.getLoaderHtml());
$popup.api({
on: 'now',
Expand All @@ -50,23 +46,6 @@ class PopupService {
}
}

onHide() {}

/**
* Only call when popup are created from metadata
* and trigger action is fired.
*/
onCreate() {
// console.log('onCreate');
}

/**
* Called only if onCreate was called.
*/
onRemove() {
// console.log('onRemove');
}

getLoaderHtml() {
return '<div class="ui active inverted dimmer">'
+ '<div class="ui mini text loader"></div>'
Expand Down
10 changes: 10 additions & 0 deletions js/src/setup-fomantic-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ $.extend = $.fn.extend = new Proxy($.fn.extend, { // eslint-disable-line no-mult
origValue(errorMessage, $module, xhr);
return value.call(this, errorMessage, $module, xhr);
};
} else if (name === 'form' && prop === 'onSuccess') {
obj[prop] = function (event, values) {
origValue(event, values);
return value.call(this, event, values);
};
} else if (name === 'modal' && prop === 'onHidden') {
obj[prop] = function (element) {
origValue(element);
return value.call(element);
};
} else {
throw new Error('Fomantic-UI "' + name + '.' + prop + '" setting cannot be customized outside atk');
}
Expand Down
40 changes: 15 additions & 25 deletions public/js/atkjs-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1967,7 +1967,7 @@ class ApiService {
* To avoid conflict, property name in response was change from eval to atkjs.
* Which mean response.atkjs now contains code to be eval.
*/
onSuccess(response, element) {
onSuccess(response) {
try {
if (response.success) {
if (response.html && response.id) {
Expand Down Expand Up @@ -3146,24 +3146,20 @@ __webpack_require__.r(__webpack_exports__);
class PopupService {
getDefaultFomanticSettings() {
return [{}, {
onCreate: this.onCreate,
onShow: this.onShow,
onHide: this.onHide,
onRemove: this.onRemove
onShow: this.onShow
}];
}

/**
* OnShow callback when a popup is trigger.
* Will check if popup needs to be setup dynamically using a callback.
* Check if popup needs to be setup dynamically using a callback.
*/
onShow($module) {
const $popup = this;
const data = $popup.data();
if (data.url !== '' && data.url !== undefined) {
// Only load if we are not using data.cache or content has not been loaded yet.
// only load if we are not using data.cache or content has not been loaded yet
if (!data.cache || !data.hascontent) {
// display default loader while waiting for content.
// display default loader while waiting for content
$popup.html(atk__WEBPACK_IMPORTED_MODULE_0__["default"].popupService.getLoaderHtml());
$popup.api({
on: 'now',
Expand All @@ -3185,22 +3181,6 @@ class PopupService {
}
}
}
onHide() {}

/**
* Only call when popup are created from metadata
* and trigger action is fired.
*/
onCreate() {
// console.log('onCreate');
}

/**
* Called only if onCreate was called.
*/
onRemove() {
// console.log('onRemove');
}
getLoaderHtml() {
return '<div class="ui active inverted dimmer">' + '<div class="ui mini text loader"></div>' + '</div>';
}
Expand Down Expand Up @@ -3602,6 +3582,16 @@ const fomanticServicesMap = {
origValue(errorMessage, $module, xhr);
return value.call(this, errorMessage, $module, xhr);
};
} else if (name === 'form' && prop === 'onSuccess') {
obj[prop] = function (event, values) {
origValue(event, values);
return value.call(this, event, values);
};
} else if (name === 'modal' && prop === 'onHidden') {
obj[prop] = function (element) {
origValue(element);
return value.call(element);
};
} else {
throw new Error('Fomantic-UI "' + name + '.' + prop + '" setting cannot be customized outside atk');
}
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.