1. EdY's Avatar
    Hi,
    I'm trying to implement an email button in my Cascades app but I want it to change the address according to a value lookup in a picker. Here's what I have so far... It seems to work *BUT* it is always 1 selection "behind" the actual picker item history. It is setting the URI to 1 previous selection behind, for some strange reason.



    Code:
    			Button
    				{
    				    // figure out where to send email...
    				        
      
                        id: emailbutton
                        text: "Send Email"
            			attachedObjects: [
            	        Invocation {
                         	id: invoke
                      	  	query: InvokeQuery {
                         		id: invq
                         	    mimeType: ""
                        		invokeTargetId: "sys.pim.uib.email.hybridcomposer"
                        		uri: "mailto:[email protected]?subject=Your%20App%20Name:%20Support"
                        		invokerIncluded: true
                        		onQueryChanged: invq.updateQuery()
                             }
                      }
            		 ]
            		 onClicked: {
               	  	       switch (emailpicker.selectedIndex(0)) {
                                    case (0):
                                        {
                                            invq.uri = qsTr("mailto:[email protected]?subject=Your%20App%20Name:%20Support")
                                            break;
                                        }
                                    case (1):
                                        {
                                            invq.uri = qsTr("mailto:[email protected]?subject=Your%20App%20Name:%20Support")
                                            break;
                                        }
                                    case (2):
                                        {
                                            invq.uri = qsTr("mailto:[email protected]?subject=Your%20App%20Name:%20Support")
                                            break;
                                        }
                                    case (3):
                                        {
                                            invq.uri = qsTr("mailto:[email protected]?subject=Your%20App%20Name:%20Support")
                                            break;
                                        }
                                    case (4):
                                        {
                                            invq.uri = qsTr("mailto:[email protected]?subject=Your%20App%20Name:%20Support")
                                            break;
                                        }
                                    case (5):
                                        {
                                            invq.uri = qsTr("mailto:[email protected]?subject=Your%20App%20Name:%20Support")
                                            break;
                                        }
                                    case (6):
                                        {
                                            invq.uri = qsTr("mailto:[email protected]?subject=Your%20App%20Name:%20Support")
                                            break;
                                        }
                                }
                                invq.updateQuery()
                                invoke.trigger("bb.action.SENDEMAIL")
                	   } 
    				}

    So if I drag the picker to item 2, and press the button, it will still email 0.
    Then when I drag the picker to item 3, and press the button, it will email 2.
    When I drag the picker to item 5, and then press the button, it will email 3.
    If I move the picker around but land back on 5, and press the button, it will email 5.

    So it seems to be lagging 1 selection "behind" what is actually showing on the picker.

    Somehow things are not updating or something needs to be called twice to update the URI. I'm just not getting it. Maybe this is a bad way to modify the URI dynamically anyways. Anyone have any ideas?
    07-18-13 06:15 PM
  2. EdY's Avatar
    I could just make 6 or 7 different buttons but I thought it would be more elegant to use a picker to set up the email address.

    I could even use an array rather than the switch to hold the different email addresses, and just have them listed in the same order as the picker so I can access it as:

    uri = emails[picker.selectedItem(0)]
    ... or something along those lines...

    I'm starting to get the hang of Cascades but there is a definite learning curve. Nice to be able to ask experts in the forums.

    Sent from my BlackBerry 9810 using Crackberry Tapatalk Forum app
    07-18-13 07:25 PM
  3. MasterOfBinary's Avatar
    I'm not familiar with the invocation framework and I might be wrong, but I don't think you should have to call invq.updateQuery() after the switch statement - that's what the onQueryChanged signal is for. The onQueryChanged signal is called (which calls updateQuery()) whenever any property is changed, which would include the URI, meaning you're calling updateQuery() twice. Either do one or the other.

    It probably won't fix your problem but just FYI.
    07-18-13 11:34 PM
  4. jadouber's Avatar
    I'm a bit rusty but maybe somehow you can fetch the new value just before the invocation of the mail functionality? Or pass it along with the function?

    Because it looks like the invocation checks the value first, grabs it and then sets the new one without notice of the new value

    Posted via CB10
    07-19-13 01:33 AM
  5. mikeo007's Avatar
    I'm not familiar with the invocation framework and I might be wrong, but I don't think you should have to call invq.updateQuery() after the switch statement - that's what the onQueryChanged signal is for. The onQueryChanged signal is called (which calls updateQuery()) whenever any property is changed, which would include the URI, meaning you're calling updateQuery() twice. Either do one or the other.

    It probably won't fix your problem but just FYI.
    This is on the right track I believe. Use the onChanged trigger for the selector and use your switch statement at that point rather then when you click the email button. Store it in a variable or something, with a default value the same as the default value for your picker (in case it never actually gets changed from the default).
    07-19-13 08:28 AM
  6. Bluenoser63's Avatar
    use onSelectedValueChanged for the picker to set the item
    07-19-13 08:34 AM
  7. EdY's Avatar
    Thanks so much for your help folks! Here's the solution, if anyone else wants to try this out.

    The invocation script in the button is stripped down to the basic example, without all that "switch" stuff. It looks like this (set to show the first email address on my picker list, or default):

    Code:
    Button
    {
              id: emailbutton
              text: "[email protected]"
     	    attachedObjects: [
                     Invocation {
                    	id: invoke
                      	  	query: InvokeQuery {
                         		id: invq
                         	    mimeType: ""
                        		invokeTargetId: "sys.pim.uib.email.hybridcomposer"
                        		uri: "mailto:[email protected]?Subject=Test"
                        		invokerIncluded: true
                        		onQueryChanged: invq.updateQuery()
                             }
                        }	
           		    ]
                     onClicked: {
               	  	       invoke.trigger("bb.action.SENDEMAIL")
                	   } 
    }


    However, as mentioned in this thread, the PICKER has to have in the onSelectedValueChanged section, the following:

    Code:
                        
    onSelectedValueChanged: {
                      	switch(emailpicker.selectedIndex(0)) 
                        	{
                        	    case (0): { emailbutton.text = "[email protected]"; break; }
                        	    case (1): { emailbutton.text = "[email protected]"; break; }
                                case (2): { emailbutton.text = "[email protected]"; break; }
                                case (3): { emailbutton.text = "[email protected]"; break; }
                                case (4): { emailbutton.text = "[email protected]"; break; }
                                case (5): { emailbutton.text = "[email protected]"; break; }
                            }	// end of switch
                        	invq.uri = "mailto:" + emailbutton.text + rest_of_header_and_message
                        }  /
    So when you play around with the picker, it changes the label of the button to the email address you selected in your picker. When you click on the button it will send to the appropriate address (whatever is written on the button). I am using the same message so I just add the rest of the message to the variable "rest_of_header_and_message", but this can also be customized depending on who it is going to.

    Thanks for all the help! I'm hoping to finish up my first Cascades app in the next week and look forward to sharing it with all of you. I've done WebWorks with and without bbUI and Native Marmalade in MS Visual C++, but this is my first foray into the world of Cascades and it's a learning experience. The first app in a new environment/language is always the hardest.
    07-19-13 02:37 PM
  8. EdY's Avatar
    Ok, so even though the email code works, I gave up on emailing because I am making a list of company support emails and turns out nobody uses email anymore. All the companies are using support login websites now. So I've switched to a dynamic browser URL launcher. Here's the code:

    Code:
    					attachedObjects: [
    					Invocation {
    					    id: webinvoke
    					    query: InvokeQuery {
    					        id: webinvq
    					        mimeType: "text/html"
                                invokeTargetId: "sys.browser"
                                uri: "http://www.blackberry.com"
    					        onQueryChanged: webinvq.updateQuery()
    					    }
    					}
    					]
                    
                        onClicked: {
                            webinvoke.trigger("bb.action.OPEN")
                        }
    This code is included in my button. Meanwhile, I have the picked above changing the company contact and upon changing picker selection, a switch modifies the webinvoke.uri to point to a new url as needed.
    07-20-13 01:18 PM
  9. EdY's Avatar
    I'm starting to enjoy the invoke capability with Cascades... I've used the email invoker above to allow users to email the developer. But one of the nicest features is that you can use the invoker with Blackberry World to point to your vendor page by supplying vendor id, and it will show all of your apps. Great way to market, and also it is always up-to-date with all the apps you have available.

    Regarding the Dynamic URI, it seems to work better for some types of invoked services and not for others. For example, I was having trouble with my email invoker getting to see the "&body=" part of my uri. When the email compose app pops up, it populates the subject but not always the body... This is sporadic, at least on the simulator. Also, QNX Momentics IDE is complaining on those lines where I am using the invoke that it is a readonly value that can't be changed or something along those lines. The code still compiles and works, but I am annoyed by those red X's on those lines and warnings.

    Hope to share my first Cascades app with everyone in a short while... Just finalizing my icon/splash graphics and hoping to compile a release build.
    07-22-13 04:16 PM
  10. EdY's Avatar
    Ok folks, the app which led to the questions in this thread and also the "Cascades Number Picker" thread is ready and posted to App World! This is my first app written in Cascades, having done mostly Webworks and some Marmalade. It was a fun exercise in learning, but I am liking Cascades... It is smooth once you get the hang of it, and gives you more power and control over the system with less work it seems.

    Check it out:

    BlackBerry World - Memory Calculator

    I have more ideas for improvements and can already see some minor changes I need to do, but there it is! My first relatively simple Cascades app, thanks to your help.
    07-25-13 11:10 AM

Similar Threads

  1. Cascades Number Picker
    By edyb in forum Developers Lounge
    Replies: 15
    Last Post: 10-05-14, 11:59 AM
  2. Cascades to other platforms?
    By EzioSaleh in forum Developers Lounge
    Replies: 3
    Last Post: 07-17-13, 08:30 AM
  3. Still Waiting on more Cascades features...
    By Yoox_II in forum BlackBerry 10 OS
    Replies: 15
    Last Post: 07-17-13, 04:32 AM
  4. Replies: 6
    Last Post: 07-16-13, 02:51 PM
  5. Cascades for Playbook? What about Pacemaker?
    By ThaSwapMeetPimp in forum BlackBerry PlayBook OS
    Replies: 4
    Last Post: 07-15-13, 05:41 PM
LINK TO POST COPIED TO CLIPBOARD