APEX 5: Convert Skillbuilder’s Modal to Universal Theme
If you have implemented the Skillbuilder’s Modal Page Plugin in an application of a previous version of APEX, and want to move to the APEX 5 Universal Theme, you will need to make some modifications. If you continue in an older theme, the plugin should continue to work as normal.
Since the APEX 5 Universal Theme has a modal page type, the plugin is no longer needed. The steps below allow you to convert the Skillbuilder’s Modal Plugin to the Universal Theme modal page. The steps outline the changes needed to make to the application, the modal page, and the parent page (the one that calls the modal page).
Application:
Change theme to Universal Theme.
- Go to Shared Components -> Themes.
- Click Create Theme.
- Select From the Repository, then click Next.
- Choose User Interface Desktop, then click Next.
- Select Theme Type Standard Themes, Theme Universal Theme, click Next.
- Click Create.
- After theme is created select Switch Theme.
- Select the current theme in the top select list and the Universal Theme in the bottom select list.
- Depending on your application select a Reset Grid option. Click Next.
- On the Verify Compatibility page, make the necessary adjustments for your page and click Next.
- Click Switch Theme.
The Universal Theme should now be the current theme of your application.
Modal Page:
- Page Attributes
- Change page mode to Modal Dialog.
- Change Dialog Template to Modal Dialog.
- Cancel Button
- Page Processes and Branches
Parent Page
- Remove Dynamic Actions
If you followed my previous post, the parent page will have three dynamic actions to handle the Skillbuilder’s Modal page: One that fires on the Create button, one that fires on the report’s edit link, and one that handles the Auto Close of the modal in order to refresh the report on the parent page.
All dynamic actions that have to do with the plugin will need to be removed. - Create Button
- Edit Links
In this example there is a report on the EMP table. Each row of the report contains an edit link which opens the modal page (2) to allow editing of the data. In my previous blog post I explained the changes you have to make in order to make the Skillbuilder’s Modal to pop-up. We now need to undo these changes and use the new APEX 5 methodology. In this example, the edit link exists on the EMPNO column. - Dynamic Actions to handle report refresh on modal close.
Create a dynamic action that fires on the new Dialog Closed event. This action needs to be attached to the report region. - Dynamic Action to handle the success message on modal close.
To do this we need some JavaScript to capture the success message, and create a new div to display the message on the parent page.- Right-click on the report region and select Create Dynamic Action from the context menu.
- Create a true action of type JavaScript to display the success message. Add the following code to the true action:
[sourcecode language=”javascript”]//Capture success message
var lSuccessMsg;if ( this.data.successMessage ) {
lSuccessMsg = this.data.successMessage.text;
} else {
/* Fallback for 5.0.0 */
lSuccessMsg = unescape(this.data.APEX_SUCCESS_MESSAGE);//Remove checksum
lSuccessMsg = lSuccessMsg.substr(0,lSuccessMsg.indexOf(‘/’));
}//Construct HTML to emulate standard success message alert
var successHTML;successHTML = ‘<div class="t-Body-alert" id="customSuccessMessage">’;
successHTML += ‘ <div class="t-Alert t-Alert–defaultIcons t-Alert–success t-Alert–horizontal t-Alert–page t-Alert–colorBG is-visible" id="t_Alert_Success" role="alert">’;
successHTML += ‘ <div class="t-Alert-wrap">’;
successHTML += ‘ <div class="t-Alert-icon">’;
successHTML += ‘ <span class="t-Icon"></span>’;
successHTML += ‘ </div>’;
successHTML += ‘ <div class="t-Alert-content">’;
successHTML += ‘ <div class="t-Alert-header">’;
successHTML += ‘ <h2 class="t-Alert-title">’+lSuccessMsg+'</h2>’;
successHTML += ‘ </div>’;
successHTML += ‘ </div>’;
successHTML += ‘ <div class="t-Alert-buttons">’;
successHTML += ‘ <a href="javascript:void(0);" onclick="$(\’#customSuccessMessage\’).remove();" class="t-Button t-Button–noUI t-Button–icon t-Button–closeAlert" type="button" title="Close">’;
successHTML += ‘ <span class="t-Icon icon-close"></span>’;
successHTML += ‘ </a>’;
successHTML += ‘ </div>’;
successHTML += ‘ </div>’;
successHTML += ‘ </div>’;
successHTML += ‘</div>’;// Display Success Message
$(‘#t_Body_content’).after(successHTML);[/sourcecode]
- Right-click on the report region and select Create Dynamic Action from the context menu.
All the pieces should now be in place to have the Universal Theme modal windows behave like the Skillbuilder’s Modal Plugin.
Hi Christoph,
can you update the JavaScript part of your blog posting please. It’s referencing the undocumented APEX_SUCCESS_MESSAGE which will be removed in 5.1. In APEX 5.0.1 we introduce a supported way where someone will not have to remove the checksum. Customers should use the following code which is more future prove.
//Capture success message
var lSuccessMsg;
if ( this.data.successMessage ) {
lSuccessMsg = this.data.successMessage.text;
} else {
/* Fallback for 5.0.0 */
lSuccessMsg = unescape(this.data.APEX_SUCCESS_MESSAGE);
//Remove checksum
lSuccessMsg = lSuccessMsg.substr(0,lSuccessMsg.indexOf(‘/’));
}
Regards
Patrick
Thanks for the correction Patrick!
This is insulting… 😉