CakePHP 3: "Breaks" in ajax requests related to "onclick confirm" - ajax

In CakePHP 3, I am having troubles with "breaks" in ajax requests. The specific page is reload (if needed) by ajax requests, called every 5 seconds. The page is correctly refreshed.
The problem appears if a logged user (to his own account) clicks a "delete" button on a selected element. If the button uses javascript "onclick confirm" and the user waits more than 5 seconds before he clicks "OK" as a confirmation, he is completely logged out from his account.
echo $this->Html->link($this->Html->image("../img/btn/btn_usun.png"),
array('controller'=>'offers','action'=>'delete/'.$this->Encrypt->encryptID($id_rekordu)),
array('escape'=>false,'onclick'=>'return confirm(\''.__d('offer','Czy usunac oferte',true).'\');',
'title'=>__d('default','Usun',true))
);
If the button does not have the "onclick confirm" - the element is deleted, page is refreshed and it works correctly
echo $this->Html->link($this->Html->image("../img/btn/btn_usun.png"),
array('controller'=>'offers','action'=>'delete/'.$this->Encrypt->encryptID($id_rekordu))
);
What can be a solution to use both the ajax refresh at the background, and "onclick confirm" before deleting, and do not logout the user if he is slow to click "OK" in the confirmation?

Seem like you need to intersect while waiting before user click OK on confirmation popup. I believe that default jquery confirmation may not intersect while popup showing unless you use another library. I would like to recommend the following library. Basically if popup is showing on screen, you can intersect like clearInterval or reset interval after you click confirm. Hope this help for you.
https://craftpip.github.io/jquery-confirm/#callbacks

Related

Can we have multiple submit buttons on the same page in oracle apex?

I have created a page in oracle apex where I have multiple regions and each region has a Submit page button.
Each submit has an ajax callback associated with it.
Will clicking on any one submit, also execute the other ajax callbacks?
In other words, when we click a Submit page button in one region, is it exclusive only to that regions ajax callback or will it execute all ajax callbacks of that page?
Button name determines value of the REQUEST attribute. If you look at the process values, you can set the "Editable Region" (which shows which region is associated with this process), as well as the request itself (under the "Server-side condition" properties; see the "When button pressed" and "Type").
So, if you create your own process which does something and set properties described above, each SUBMIT button should affect only its own region.
Unless I'm wrong, if there's only one SUBMIT button (created with its default settings) on the page, it'll affect all regions.

How do I display a submit button after 3 images are clicked?

so I'm running a Runescape Private Server and my java code for voting in it is if the link = www.clearpkz.webs.com/votevote?Username= + username entered is active, then it allows users to do ::claim to get a reward. But how can I make it so the Submit button to enter their username only displays if they click on every image first? Or can I only make it display once every 24 hours even if the page is refreshed?
Here is my current code:
http://pastebin.com/rfQeVkfT
Here is my voting website: www.clearpkz.webs.com/vote
You must disable with jQuery a submit function and check if user clicked on image then you can enable a button for submit.
Also:
1. If you show page> $("input[type=submit]").attr("disabled", "disabled");
2. You need one variable for click test. if user clicked on image COUNTER++
3. If COUNTER > 0 then $("input[type=submit]").removeAttr("disabled");

Refreshing entire page jqGrid paging

When a user double clicks on a row on my page, I navigate them to an edit screen which shows them some important information. When they submit that patient I gerimander jqGrid to take them page to the page that they were just viewing...
serializeGridData: function (postData) {
//debugger;
var pagInfo = $(this).se
debugger;
if ((rowFromTemp != "") && (pageFromTemp != "")) {
//debugger;
postData.page = pageFromTemp;
pageFromTemp = "";
rowFromTemp = "";
}
return postData;
},
I basically edited the postData in the serializeGridData function.
My question is, when I navigate to a different page lets say page 3 of 10 after I have edited information and returned to the correct page, when I click refresh of the whole page...
I want the user to return to the page that they just navigated to. Right now, it will return them back to the page that they initially returned from after editing information. So If I were to construct a timeline of events...
1) user see's paged information...
2) user selects row to edit
3) user navigates to edit page and does his thing then submits
4) user now is sent back to page where he came from...
5) user goes to a different page (either next or last)
6) user refreshes page
7) !! user is sent to page X from step 3 and 4 and Not 5 !!
I was hoping to to some kind of refresh of page event and set the correct page in there.
Is my methodology or thinking in correct here? Is there a way to ensure that the correct page is selected no matter what?
I just checked again. It would seem that if a user
1) navigates to page X
3) refreshes a page
he will be sent to page 1.
Maybe I am setting an unrealistic expectation. Maybe if they reload the whole page, they should expect to go back to page 1.
Well even so, how could I accomplish that task with the first workflow
In my opinion the real problem which you have is the usage of step 3: "user navigates to edit page and does his thing then submits". The step makes all the problems which you try to solve. Instead of going to another page one can create dynamically some controls which allows to edit the selected row. jqGrid provide inline editing or form editing for the purpose. You need just include editable: true property in the columns which you need to edit implement starting of inline/form editing on select of row or on double click. Alternatively you can use buttons from the navigator bar (see navGrid and inlineNav) or in addition column of the grid (see formatter: "actions").
If you still don't want to use any editing mode which provide jqGrid you can just place the whole content of the body of the main page inside of a div. You can hide the div using jQuery.hide instead of redirection to "edit page". You can load the content of "edit page" on the same main page (per jQuery.load for example). Then you can remove the loaded "edit page" and show the original main page. As the result the main page will be shown in exactly the same form as it was before starting of editing.

Joomla handling multiple ajax forms on the same page

I'm using Joomla to develop a user profile management component with AJAX.
The goal is to allow the user to edit his own user information. There is a lot of information so instead of having one massive form, I decided to make "subforms" or sections. And for the whole thing to be user-friendly I want to send the forms and refresh the user information with AJAX.
Here's an example :
There are two sections, "Basic user info" which displays the first name, the last name and the age of the person and "Extended user info" which displays the occupation, the company and the skills of the person. Each section has an "edit" link (or button) which turns the content into a form (AJAX) allowing the user to modify the presented information. You can only edit one section's information at a time. When the user has finished modifying the data, he sends the form with a "send" link (or button) and the section gets back to simply displaying the information of the section (with the updates that were just made).
So I need to know what is the most efficient way to develop such a component. I thought of two approaches :
1) In the "tmpl" directory of the main component view we the following files :
default_basic.php (displays the basic user information),
default_basic_edit.php (displays the form which allows the user to edit the basic information)
default_extended.php (displays the extended user information),
default_extended_edit.php (displays the form which allows the user to edit the extended info)
default.php (loads each of the display subtemplates with calls to JView::loadTemplate($subtemplate))
When the user clicks on an edit link, an AJAX call is made to the following URI index.php?option=com_userinfo&view=userinfo&subview=basic_edit&format=ajax, which causes the view class to call $this->loadTemplate('basic_edit') after assigning the user information to it.
If the user clicks cancel the same process is used to load the 'basic' template again. And if the user modifies the information and clicks the send link, the form is sent and then the 'basic' template is loaded too.
2) There is only a "default.php" file in the "tmpl" directory which holds the edit version and the display version of each section. But all the edit versions are hidden at first. And when the user clicks on the edit link the display version of the section becomes hidden and the edit version is displayed (using display:none and display:block). Then, if the user clicks the cancel button we do the opposite. And if the user clicks the send button we send an AJAX request to update the data in the database and return the updated user info which will be loaded into the display version of the section. And we finally replace the edit version of the section with its display version.
I know there's a lot of text but in the end it goes down to choosing between refreshing full HTML blocks with AJAX, or just sending the updated info and modifying the content of hidden blocks and then make them appear. So what do you think is the most logical approach, knowing that we are in a Joomla 1.5 environment ? How would you procede ? (maybe there are other ways to create such a component ?)
(I tried both ways and I couldn't entirely make it work so I decided to ask to see if it is a matter of conception...)
Thank you for taking the time to read all the text.
My answer is: why even refresh parts when it can be done without it?
For example when we are talking about basic form elements like text fields and check/radio buttons I would prefer the following: on a successful save/send simply display a nice message like "Profile saved" for some seconds and the user is sure that the changes are save and sound.
In case I msissed somthing let me know.
I have tried both solutions and #2 is the only one that worked for me.

ASP.NET MVC 3.0 - User Hammering Submit Button

Even using the Post/Redirect/Get method, and including javascript to disable a button after it has been clicked, I am having a problem with users being able to just rapidly hammer a submit button and get multiple form posts in before server side validation can stop it.
Is there any way to stop this? I've even tried this method : how to implment click-once submit button in asp.net mvc 2?
And I've tried outright blocking the UI with jquery blockUI. I have BOTH client side and server side validation in place, and they work perfectly - but a user smashing the submit button twenty times in under a second just seems to keep breaking it.
Use javascript to wire the onclick event to disable the button.
If you are already doing that and you can still get multiple form posts, then the problem is a delay between the clicking of the button and the button being disabled, and you must be submitting the form multiple times during this delay.
To fix this, make the onclick event first make a call to stopPropagation() to stop the submit event. Then validate that the form is not in submission-blocked state. You can do this by creating a page-scoped javascript variable with a boolean value like can_submit. Test for can_submit being true before submitting the form. Set the can_submit = false when the button is disabled, so even if the button is not disabled fast enough, the form will not submit if the value has already been set to false.
In most cases I'd say that this isn't worth fixing - if a user is going to do something as silly as clicking submit 20 times they should expect to get an error.
The only real fix for this is to set up your action to only accept the same form once - add a hidden field that is set to a random value when the form is loaded. When the form is posted, save that value somewhere temporarily and if it is already there you have a duplicate request that shouldn't do anything.

Resources