Secured application is highly recommended in every business. How we can make our application secure? There are many ways to secure an application. Today I'm going to discuss a way to secure page process. I assume, you have a complete functionsl page in your application. I choose page 47 in my APEX application to illustrate the process. You can choose your suitable page to implement this process. For visual assistance, you can follow this tutorial.
Now I'm going to discuss this process step by step-
STEP 1: Select page and open "Header Text" code Editor. Paste the below code here-
<div id="pageSpinnerOverlay">
<div class="spinner"></div>
<div class="msg"></div>
</div>
STEP 2: Open CSS > Inline code editor and paste the below css here-
/*Display the overlay block*/
#pageSpinnerOverlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.4);
z-index: 9999;
}
#pageSpinnerOverlay .spinner {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border: 8px solid #f3f3f3;
border-radius: 50%;
width: 60px;
height: 60px;
animation: spin 1s linear infinite;
border-top: 8px solid #3498db;
}
@keyframes spin {
0% {
transform: translate(-50%, -50%) rotate(0deg);
}
100% {
transform: translate(-50%, -50%) rotate(360deg);
}
}
#pageSpinnerOverlay .msg {
position: absolute;
padding: 8px;
font-size: 12px;
font-family: "Times New Roman";
font-style: italic;
text-align: center;
color: #000;
letter-spacing: 3px;
top: 58%;
left: 50%;
transform: translate(-50%, -55%);
}
STEP 3: Open JavaScript > "Function and Global Variable Declaration" code editor and paste the below code here-
function showSpinner(msg) {
let msgContainer = document.getElementsByClassName('msg');
msgContainer[0].innerHTML = msg;
$('#pageSpinnerOverlay').css('display', 'flex');
$('#pageSpinnerOverlay').css('flex-direction', 'column');
$('#pageSpinnerOverlay').show();
};
function hideSpinner() {
$('#pageSpinnerOverlay').hide();
};
STEP 4: Create Ajax Callback Process to perform your DML operation. Suppose, you want to increase employee salary by 10%. So, create a new Ajax Callback process and set it properties like-
Name: UPDATE_SALARY
PL/SQL Code: UPDATE employees
SET salary = salary + (Salary * .1);
STEP 5: Go to "Navigation" tab and select page. Open JavaScript > "Function and Global Variable Declaration" code editor. Paste the below code here-
function updateSalary() {
apex.message.clearErrors();
showSpinner('Data is uder processing. Please wait...');
apex.server.process(
'UPDATE_SALARY'
, {}
, {
dataType: 'text',
success: function() {
apex.message.showPageSucess('Update Salary successful');
}
}
);
hideSpinner();
}
Note: You can't noticed anything using this simple process because the process finished within a nano-second. If your process took a little bit longer time then you can notice its effect.
STEP 6: Select the button which is responsible to perform DML operation. Change it properties like-
Behaviour:
Action: Defined by Dynamic Action
STEP 7: Create a dynamic action under this button and set the action name as your choice. Select true action and set it properties like-
Action: Execute JavaScript Code
Code: updateSalary();
Save your page and run. Hope, you can cofigure your page successfully. This process will secure your page from intentionally click/execute another process when a process is already running. This process force the user to wait untill the executed process not finished. Let's enjoy.