I am trying to pop up a Confirmation Dialog (dialog.confirm(options)) as soon as one clicks on Submit Button on my Suitelet. For this, I am using saveRecord Entrypoint in Clientscript. Below is the code
function saveRecord() {
//alert('Inside Save Record');
var options = {
title: "I am a Confirmation",
message: "Press OK or Cancel"
};
function success(result) {
console.log('Success with value ' + result);
}
function failure(reason) {
console.log('Failure: ' + reason);
}
dialog.confirm(options).then(success).catch(failure);
}
Upon execution, I am getting the dialog box, but on clicking OK I am unable to move further. (that is from Suitelet GET to Suitelet POST).
Please Note - I am using SuiteScript 2.0
Given the code provided when you press "Ok" there is no further actions (redirect to Suitelet) defined. If you want to trigger the Suitelet after user presses okay add the redirect to the success function. The "redirect.toSuitelet(options)" method is not available for Client scripts but you can use window.open(URL); to point the user to the suitelet.
On saveRecord, you either return true; to proceed or return false; to stay on the page.
If you return true from the success then it won't serve to confirm your saveRecord. It's returning from a different context. One workaround could be to use the native browser window.confirm as this executes synchronously.
Related
For some reason an RSVP promise I created in an action stopped working for me and I can't figure out what when wrong where to make it stop working.
I have a component that sends an action and waits for a response
// COMPONENT IN ITEM ROUTE
callAjaxAction() {
this.setProperties({working:true});
Ember.RSVP.cast(this.attrs.action()).finally(() => {
Ember.$('.draggable').animate({
left: 0
});
this.setProperties({working:false});
});
}
This particular instance of the component calls this action in the controller
// IN ITEM CONTROLLER
placeBid() {
return new Ember.RSVP.Promise((resolve,reject) => {
if(this.get('winning')) {
this.get('notification')._confirm({message: "You are currently the highest bidder, would you like to continue with your bid?",isConfirm: true}).then(()=>{
console.log('confirmed');
this.send('placeBidActual').then(()=>{
resolve();
}).catch(()=>{
reject();
});
return true;
}).catch(()=>{
resolve();
console.log('denied');
return false;
});
} else {
setTimeout(()=>{
this.send('placeBidActual').then(()=>{
resolve();
}).catch(()=>{
reject();
});
},500);
}
});
}
This action is calling a confirm method on a service and waiting for the user to hit yes in the case of the user already winning this item. Otherwise I'm just calling the actual ajax action right away, that action looks like this
// IN ITEM CONTROLLER
placeBidActual() {
return new Ember.RSVP.Promise((resolve,reject) => {
Ember.$.ajax({
...
}).then((response)=>{
(do some stuff with the response)
resolve();
}, (reason)=>{
(do something with rejection reason)
reject(reason);
});
});
}
In the console I'm getting the error
Uncaught TypeError: Cannot read property 'then' of undefined
On the line where it states this.send('placeBidActual')
UPDATE:
Here is maybe a better explanation to the expected process flow.
The user attempts to place a bid, the user swipes a component over to indicate they wish to bid. The UI at this point shows a loading indicator and waits for the ajax action to complete before it resets the UI.
If the user is not already the highest bidder of the item it will go straight to the ajax action and upon completion signifies to the component to reset the UI.
However, if the user is the highest bidder of the item it should instead show a confirm message (using the notification service I have setup) and wait for the user to either confirm or deny. If they deny it just cancels and signifies to the component to reset the UI. If the user confirms then it calls the ajax action and upon completion signifies to the component to reset the UI.
Updated answer:
This isn't working because send doesn't return the value of the action.
I suggest moving the placeBidActual action to a method on the controller and call it like any normal method. This way you will get the return value and be able to call .then on it.
You should pass a function, whithout invoke it.
Instead this:
Ember.RSVP.cast(this.attrs.action()).finally(() =>
Try it:
Ember.RSVP.cast(this.attrs.action).finally(() =>
Invoking the funcion this.attrs.action() does it pass undefined for the Promise.
Problem with field validation and two jQueryUI dialogs.
There is a registration form in the first jQUI dialog.
Field validation on the username field using AJAX. If field fails validation (already exists), PHP file returns a number > zero and an error message is displayed in a second jQueryUI dialog.
However, when user closes 2nd dialog, it immediately re-opens, forever.
Any thoughts?
$("#c_username").blur(function() {
var uu = ($(this).val()).toLowerCase();
$(this).val(uu); //in case user did not input as all lowercase
$.ajax({
type:'POST',
url: 'ajax/ax_all_ajax_fns.php',
data:'request=does_username_already_exist&username=' + uu,
success: function(data) {
if (data != 0) {
$('#alert').html('Username <span style="font-weight:bold;color:darkgreen;">' +uu+ '</span> already exists. Please enter another.');
$('#alert').dialog({
title: 'Username already exists:',
width: 400,
close: function() {
$(this).dialog('destroy');
}
});
$("#c_username").addClass('field_invalid').focus();
}else{
alert("Username is okay");
}
}
});
});
$("#c_username").addClass('field_invalid').focus(); focuses the input behind the dialog. When you click the close button on the dialog, the input's blur event is raised again, causing another ajax call, and another dialog to be opened.
Try moving the focus() call to the close callback on the dialog. You could also try displaying the message in a span next to the input instead of in a dialog so focus issues can't happen.
I'm new to lift, and want to implement following in my project:
There is a "delete" link in the page, when user clicks it, there will be a confirmation with text "are you sure to delete?". If user clicks on "yes", it will make an AJAX call to delete something on the server side, then show a notice "Operation complete", and after 3 seconds, the page will be reloaded.
How to implement this in lift? I have searched a lot, but not found an correct example.
I can only do this for now:
SHtml.a( ()=>Confirm("are you sure to delete", ???), "delete" )
The easiest way is to use the SHtml.ajaxInvoke in conjunction with JsCmds.Confirm. It will create a server side function and return a tuple with the functionId and JsCmd. So, something like this should do what you are looking to do:
SHtml.a( () => {
JsCmds.Confirm("Are you sure you want to delete?", {
SHtml.ajaxInvoke(() => {
//Logic here to delete
S.notice("Operation complete")
JsCmds.After(3 seconds, JsCmds.Reload) //or whatever javascript response you want, e.g. JsCmds.Noop
})._2
})
}, "delete")
In the above - clicking on the link will trigger the confirmation. If you select OK, then it will issue an ajax call to your function and display a notice. You can use that in any of the SHtml items that require a JsCmd.
If you want to have the page redirect after a timeout, you can just write a client-side javascript function to do what you need and use JsCmds.Run to call it.
Using reactive-web:
confirm("Are you sure you want to do that?") {
case true =>
// handle yes, if so desired
case false =>
// handle no, if so desired
}
See the scaladocs: http://reactive-web.tk/reactive-web-api/#reactive.web.package
I am using jConfirm for confirm dialog with success.
For first time i tried to call it inside the ajax success but seems to fail.
Here is the code:
success: function (j) {
if(j.status)
{
jConfirm('File Already exist.Are you sure you want to replace ?', 'File Exist', function(r) {
if (r==true)
{ }
else
{
//code for cancel
}
});
}
}//success
The problem is that the dialog is show but does not wait for user answer and continues.
When change to classic javascript confirm everything works fine!
jConfirm is an asynchronous method.
As you've noticed, it returns immediately, without waiting for the user to close the dialog.
You need to put all of your code in the jConfirm callback.
I am using static FBML but I am having trouble debugging a form validation problem. I get the dialog which to me seems like it should return false, but the form submits anyway. I am using Firebug and I see a brief message in Red that I have no chance to read. I appreciate the help :-)
var txt ='Enter Zipcode';
//...
function setError(){
var obj=document.getElementById('mapsearch');
obj.setValue(txt);
obj.setStyle('color', '#FF0000');
}
function valform(){
var obj=document.getElementById('mapsearch');
var val = obj.getValue();
if(val!='' && !isNaN(val) && val.length>2 ){
return true;
} else {
setError();
(new Dialog()).showMessage('Zip Required', 'Please enter your zip code.');
return false;
}
}
//...
Try the "Persist" button if the Firebug/javascript error message in Firebug disappears too quickly. This way all messages are kept between page loads until you click "Clear".