Alpha Video Training
Results 1 to 16 of 16

Thread: Display A Dialog box Xbasic during ajax call back

  1. #1
    Member
    Real Name
    Ivan Lozano
    Join Date
    Apr 2013
    Location
    Azusa, CA. LA County
    Posts
    398

    Default Display A Dialog box Xbasic during ajax call back

    Hello,

    I have an ajax call back that run as expected being called from a button, in the ajax call back i want it to display the result of rs.data(1) in a message box to the user that will then run another call back depending if the user selects YES. This callback works fine but I want to add a prompt showing the user what data it found before performing the next sql statement. Ive seen a lot of posts about using a5.messageBox.Show() but not sure how to use it. Here's what ive constructed so far:
    Code:
    function FindPreviousEvaluation as c ( e as p)
    
    	'Find Previous eval if it exists, and update current record
    	debug(1)
    	dim cn as sql::Connection
    	dim args as sql::Arguments
    	dim sqlUPDATE as c
    	dim EvalCount as n
    	dim rs as sql::resultset
    
    	args.set("arg0", e.dataSubmitted.EVALUATION_YEAR)
    	args.set("arg1", e.dataSubmitted.StaffID)
    	
    	flag = cn.open("::Name::StaffDB")
    		If flag = .f. then
    			FindPreviousEvaluation = "alert('Could Not Establish Connection');"
    		else
    			sql =	<<%sql%
    			SELECT MAX(EVALUATION_YEAR) AS PreviousEval
    			FROM evaluations_mgrs
    			WHERE STAFF_ID_FK = :arg1 AND EVALUATION_YEAR <> :arg0
    			%sql%
    			
    			cn.execute(sql, args)
    			rs = cn.resultSet
    			PreviousEvalYear = rs.data(1)
    			args.set("arg2", PreviousEvalYear)
    			cn.freeresult()
    			
    			If PreviousEvalYear = "" then
    				'Tell user no previous evaluation exists
    				FindPreviousEvaluation = "alert('No Previous Evaluation Exists.');"
    			else
    'THIS IS WHERE I NEED HELP				
    				'Display a prompt for the user asking how to proceed
    				'show message box as: "Last Eval year found: rs.data(1) that I previously placed in a variable -> {PreviousEvalYear}"
    				'Do you want to proceed? Yes button, Cancel button
    				'If "Yes button" = .t. then
    					sqlUPDATE = <<%sql%
    					UPDATE evaluations_mgrs t1 
    					INNER JOIN evaluations_mgrs t2 ON (t1.STAFF_ID_FK=:arg1 AND t2.STAFF_ID_FK=:arg1) 
    					SET t1.PREVIOUS_OVERVIEW = t2.CURRENT_OVERVIEW, 
    					t1.PREVIOUS_GOALS = t2.CURRENT_GOALS, 
    					t1.PREVIOUS_FOCUS = t2.CURRENT_FOCUS, 
    					t1.PREVIOUS_STRENGTHS = t2.CURRENT_OVERVIEW, 
    					t1.PREVIOUS_AREAS_OF_IMPROVEMENTS = t2.CURRENT_AREAS_OF_IMPROVEMENT, 
    					t1.PREVIOUS_INCIDENTS = t2.CURRENT_INCIDENTS, 
    					t1.PREVIOUS_ACCOMPLISHMENTS = t2.CURRENT_ACCOMPLISHMENTS 
    					WHERE t1.EVALUATION_YEAR = :arg0 AND t2.EVALUATION_YEAR=:arg2
    					%sql%
    					flag = cn.Execute(sqlUPDATE, args)
    				'else do nothing
    'HOW DO I ACCOMPLISH THIS				
    				end if
    			end if
    		end if
    	cn.Close()
    
    end function

  2. #2
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,562

    Default Re: Display A Dialog box Xbasic during ajax call back

    You can't interrupt a callback... so just split it up. If you need to do the 2nd part, then send control back to the client... ask your question... and then run another callback.

    You could run the same callback and put in code to test what stage you're at. The example attached uses 2 callbacks.
    Attached Files Attached Files

  3. #3
    Member
    Real Name
    Ivan Lozano
    Join Date
    Apr 2013
    Location
    Azusa, CA. LA County
    Posts
    398

    Default Re: Display A Dialog box Xbasic during ajax call back

    Thank you for the reply David,

    Maybe I am doing something wrong but when i try to add the file you attached into my web projects, it displays the component type as "Unknown", and when I open it, it is completely empty?

    I've tried adding it using the "Add File" button in alpha and also tried simply dragging and dropping the file into the web projects folder directly.

  4. #4
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,562

    Default Re: Display A Dialog box Xbasic during ajax call back

    Try this one. What Version and Build of Alpha are you using?
    Attached Files Attached Files

  5. #5
    Member
    Real Name
    Ivan Lozano
    Join Date
    Apr 2013
    Location
    Azusa, CA. LA County
    Posts
    398

    Default Re: Display A Dialog box Xbasic during ajax call back

    Well it took a while for me to comprehend what was going on and how you set this up and ive got to say... Wow! I'ts not as simple as I originally thought. Correct me if Im wrong here but this is how I understand it working:

    1. When button is pressed it performs an ajax call back that performs the "Find previous Eval".
    2. If it does not find a previous eval it informs the user that no record was found with a simple alert().
    3. If it does find a record, it performs a defined JavaScript function.
    4. The defined JavaScript function defines the xbasic dimmed var found by the callBack by using "askFindPrevEval('" + PreviousEvalYear + "');".
    5. Once the Defined Javascript function runs it then prompts the user with the record that it found.
    6. Depending on what the user selects (Yes, No, Cancel) it will perform another defined ajax callback to update the current record, or simply close the dialog and do nothing.

    I think thats about right... Right?

  6. #6
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,562

    Default Re: Display A Dialog box Xbasic during ajax call back

    Yup... you got it.

    You need info from the server... so you go get it.
    Based on what you find at the server, you send that info back to the user and ask if they want to do something with it.
    If they say Yes then you go back to the server to finish up.

    I'm not sure what you've written in #4. XBasic can return anything back to the client. In this case you're simply calling a javascript function. That function call, just the call, is built in XBasic and includes a parameter. The client-side gets the function call, and executes it. It's just a string returned to the client... and, essentially, Alpha knows what to do with it. The javascript function doesn't define an xbasic dimmed var... it just processes the parameter.

    You've not mentioned what Alpha version you're working with, but I believe the issue you had with the component concerns the UX property "Save component format" - which I had set to "formatted JSON" and your version of Alpha didn't understand. So I changed it to Binary and re-posted.

  7. #7
    Member
    Real Name
    Ivan Lozano
    Join Date
    Apr 2013
    Location
    Azusa, CA. LA County
    Posts
    398

    Default Re: Display A Dialog box Xbasic during ajax call back

    #4, yes I meant that xbasic passed the parameter to the javascript function by using askFindPrevEval('" + PreviousEvalYear + "');. Because xbasic defined the value of "PreviousEvalYear", and then javascript could see the value by using askFindPrevEval('" + PreviousEvalYear + "');... Right?

    I've never used JSON nor do I know how it can be used, I'm still struggling to understand Xbasic and JavaScript. Im using version 12.3 Build 2999-4519.

  8. #8
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,562

    Default Re: Display A Dialog box Xbasic during ajax call back

    Yes... exactly.

    And... your version makes sense as well... I don't think that UX property was available in 2999. You should mention up front in your post what version you're working with. 2999 is more than a year old.

  9. #9
    Member
    Real Name
    Ivan Lozano
    Join Date
    Apr 2013
    Location
    Azusa, CA. LA County
    Posts
    398

    Default Re: Display A Dialog box Xbasic during ajax call back

    Thank you for the advice, I will make sure to note that on my next post.

    Is it possible to pass more than one parameter? Say, if i wanted to pass the evaluation year and the ID of the record? Would that look like this:

    askFindPrevEval('" + PreviousEvalYear + "+" + RecordID + "');

  10. #10
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,562

    Default Re: Display A Dialog box Xbasic during ajax call back

    Yes... but you must follow the pretty much universal format for supplying params...

    Code:
    askFindPrevEval('" + PreviousEvalYear + "," + RecordID + "');
    And then, of course, change your js function to accept the 2nd param...

    Code:
    function askFindPrevEval(PreviousEvalYear,recordId){
    and I really should make a small cosmetic correction. On the Javascript side... case matters... and it's kinda common to use camelCase. So the Javascript function should be...

    Code:
    function askFindPrevEval(previousEvalYear,recordId){
    
    	var _msg = 'Last Eval year found: '+previousEvalYear+'.<br>Do you want to proceed?';
    	A5.msgBox.show('Previous Eval Year',_msg,'ync',function(button){
    	    if(button == 'yes'){
    		    {dialog.Object}.ajaxCallback('','','FindPrevEvalContinue','','__prevEvalYear='+previousEvalYear);
    	    }else{
    	        // nothing to do
    	    }
    	});
    
    }
    The change is just the lowercase 'p' on the param 'previousEvalYear'... used throughout the function.

  11. #11
    Member
    Real Name
    Ivan Lozano
    Join Date
    Apr 2013
    Location
    Azusa, CA. LA County
    Posts
    398

    Default Re: Display A Dialog box Xbasic during ajax call back

    Thank you David, youve been very helpful... Ive learned a lot

  12. #12
    Member
    Real Name
    Ivan Lozano
    Join Date
    Apr 2013
    Location
    Azusa, CA. LA County
    Posts
    398

    Default Re: Display A Dialog box Xbasic during ajax call back

    Hello again, I am trying to pass two varibales to the JS prompt but its not coming up properly. here is part of my xbasic code:
    Code:
    IF e.dataSubmitted.FK_PTO_TYPE_ID = "1" .OR. e.dataSubmitted.FK_PTO_TYPE_ID = "2" then
    			dim cn as sql::Connection
    			dim args as sql::Arguments
    			dim sqlSELECT as c
    			dim rs as sql::ResultSet
    			dim PunchCount as n
    			'-----------------------------------------------
    			'Check to how much Time-off Emplyee is alotted
    			'-----------------------------------------------
    			flag = cn.open("::Name::StaffDB")
    			args.set("EmployeeID", e.dataSubmitted.argEMPLOYEE_ID)
    			sqlSELECT = <<%sql%
    			SELECT
    			timeoff_vacation,
    			timeoff_personal
    			FROM staff
    			WHERE staff_id = :EmployeeID
    			%sql%
    			flag = cn.Execute(sqlSELECT, args)
    			rs = cn.ResultSet
    			VacationAlotted = rs.data(1)
    			PersonalAlotted = rs.data(2)
    			cn.FreeResult()
    			IF e.dataSubmitted.FK_PTO_TYPE_ID = "1" then
    				'-----------------------------------------------
    				'Check to how much VACATION Time-off Emplyee has used
    				'-----------------------------------------------
    				flag = cn.open("::Name::FINANCIAL")
    				args.set("EmployeeID", e.dataSubmitted.argEMPLOYEE_ID)
    				args.set("TodaysYear", e.dataSubmitted.argYear)
    				sqlSELECT = <<%sql%
    				SELECT COALESCE(SUM(t2.pto_hrs),0) as VacationUsed
    				FROM  timesheets t1
    				LEFT JOIN timesheets_pto t2 
    							ON t1.pk_timesheet_id = t2.fk_timesheets_id
    				WHERE t1.FK_STAFF_ID = :EmployeeID 
    						AND t2.FK_PTO_TYPE_ID = 1 
    						AND YEAR(t1.TODAYSDATE) = :TodaysYear
    				%sql%
    				flag = cn.Execute(sqlSELECT, args)
    				rs = cn.ResultSet
    				VacationUsed1 = rs.data(1)
    				cn.FreeResult()
    				'---------------------------------------------------------------------------------------
    				'VacationUsed1 is in hours, need to convert to Days, Vacation1 Divided by 8 = #of Days
    				'---------------------------------------------------------------------------------------
    				VacationUsed = (VacationUsed1 / 8)
    				'------------------------------------------------------------------
    				'Show user a prompt with Vacation alotted and vacation used so far
    				'------------------------------------------------------------------
    				IF VacationUsed < VacationAlotted then 
    					showTimeOff = "JSshowUserTimeOffVacation('" + VacationAlotted + "," + VacationUsed + "');"
    				else 
    					showTimeOff = "alert('You have exhausted your time-off, please edit record.');"
    				end if
    			else if e.dataSubmitted.FK_PTO_TYPE_ID = 2 then
    And this is my Javascript function:
    Code:
    function JSshowUserTimeOffVacation(VacationAlotted, VacationUsed){
    
    	var _msg = '<p align="center"><font size="4">Vacation Days Alotted: '+VacationAlotted+'.<br>Vacation Days Used: '+VacationUsed+'.<br><br>Do you want to continue?<br></font></p>';
    	A5.msgBox.show('TIME-OFF',_msg,'ync',function(button){
    	    if(button == 'yes'){
    		    {dialog.Object}.submit();
    	    }else{
    	        //alert('Action Cancelled by user.')
    	    }
    	});
    
    }
    My Problem is that the second parameter that i am trying to pass "VacationUsed" is coming up as undefined when the pop-up window shows and i dont understand why?
    Also, the first value, "VacationAlotted" is showing up as "20,4" when it should only be "4". Where did I go wrong?

    When I use the debugger "Debug(1)" all the values show up properly, but when the javascript that is suppose to show the user the info comes up it is incorrect?
    Capture.PNG

  13. #13
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,562

    Default Re: Display A Dialog box Xbasic during ajax call back

    That's because you're not passing 2 params... just one. Look at your code... and manually replace your vars and interpret it...

    showTimeOff = "JSshowUserTimeOffVacation('" + VacationAlotted + "," + VacationUsed + "');"

    "JSshowUserTimeOffVacation('" + VacationAlotted + "," + VacationUsed + "');"

    "JSshowUserTimeOffVacation('" + 29 + "," + 12 + "');"

    JSshowUserTimeOffVacation(' + 29 + , + 12 + ');

    JSshowUserTimeOffVacation('29,12');

    You're sending back 1 param.

    You're missing single quotes around the comma separating the params. You're statement should be...

    showTimeOff = "JSshowUserTimeOffVacation('" + VacationAlotted + "','" + VacationUsed + "');"

    JSshowUserTimeOffVacation('29','12');

  14. #14
    Member
    Real Name
    Ivan Lozano
    Join Date
    Apr 2013
    Location
    Azusa, CA. LA County
    Posts
    398

    Default Re: Display A Dialog box Xbasic during ajax call back

    That did the trick, I was following your example in post #10. In that post, it is missing the single quotes.

    Thank you as always!

  15. #15
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,562

    Default Re: Display A Dialog box Xbasic during ajax call back

    Oooops... easy to spot stuff you're not writing. The missing single quotes were really standing out in your post... never saw them in mine. I usually run the code I post... gotta be sure to do that in future. Cheers.

  16. #16
    "Certified" Alphaholic kingcarol's Avatar
    Real Name
    Carol King
    Join Date
    Jun 2010
    Posts
    1,512

    Default Re: Display A Dialog box Xbasic during ajax call back

    Just to let everybody here know. This thread really helped me and I wanted to say THANK YOU. I keep notes for myself about how to do something, and thought I'd just share my notes about this one.

    'HERE IS HOW TO DO A MESSAGE BOX THAT HAS DATA IN IT. You will need to pass in data via parameters from Xbasic function to a javascript function.

    Here is an example of an Xbasic function. You would probably set the variables to some result set info from sql query, or error message?
    Code:
    function TestMsgBoxWithData as c (e as p)
    
    dim Data1 as n
    Data1 = 45   'would probably be something like Data1 = rs.data(1) from a result set
    
    dim Data2 as c
    Data2 = "hello"  'would probably be something like Data1 = rs.data(2) from a result set
    
    'call a javascript function to show the message, in this one, we are passing in 2 parameters
    TestMsgBoxWithData = "JSshowMessageData('" + Data1 + "','" + Data2 + "');"
    	
    end function
    '

    Here is an example of the javascript function that opens an OK message box with the data in it:
    Code:
    function JSshowMessageData(Data1, Data2){
    
    	var _msg = '<div style="height: 1.5in; width: 2in; padding: 15pt;">Here is the message.<br><br>This is Data1: '+Data1+'.<br>This is Data2: '+Data2+'.</div>';
    	A5.msgBox.show('Resulting Message',_msg,'o',function(button){
    	    if(button == 'ok'){
    		    //alert('OK button clicked');
    	    }else{
    	        //alert('Action Cancelled by user.')
    	    }
    	});
    
    }
    Here is an example of the javascript function that opens a Yes/No message box with data in it:

    Code:
    function JSshowMessageData(Data1, Data2){
    
    	var _msg = '<div style="height: 1.5in; width: 2in; padding: 15pt;">Here is the message.<br><br>This is Data1: '+Data1+'.<br>This is Data2: '+Data2+'.<br><br>Is it OK to do something?</div>';
    	A5.msgBox.show('Resulting Message',_msg,'yn',function(button){
    	    if(button == 'yes'){
    		    alert('programmer needs to put some action here');
    	    }else{
    	        //alert('Action Cancelled by user.')
    	    }
    	});
    
    }
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

Similar Threads

  1. Submit form using ajax call back
    By Gustavo1478 in forum Mobile & Browser Applications
    Replies: 7
    Last Post: 09-15-2016, 04:13 PM
  2. Replies: 2
    Last Post: 02-12-2015, 10:06 PM
  3. Ajax Call Back - Add record issue
    By SteveK3003 in forum Application Server Version 11 - Web/Browser Applications
    Replies: 12
    Last Post: 09-05-2012, 11:10 AM
  4. refresh embedded grid in dialog as result of ajax call back not possible?
    By cptutrecht in forum Application Server Version 11 - Web/Browser Applications
    Replies: 1
    Last Post: 06-13-2012, 05:32 AM
  5. Ajax Call back problem with 'e.V'
    By cFlat7 in forum Application Server Version 10 - Web/Browser Applications
    Replies: 2
    Last Post: 11-04-2010, 05:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •