Kitchen Sink Sample App
The Kitchen Sink Sample App:
- Used to demonstrate how you can open/close views in different target zones.
- Give access for the attachment URL of an email to your App.
- Get properties of the view which initiated the call.
- Access per-user-per-app persistent store.
Try It Out
See Quick Start to learn how to get the full source for this example, install it, and run it in Yahoo! Mail.
Create Your Kitchen Sink App
Below, we create an app based on the Kitchen Sink sample.
> ymdt create ksink -S 'Kitchen Sink' Yahoo! Mail Development Tool Version 1.31 Developer server: developer.mail.yahoo.com create: Getting sample 'Kitchen Sink' into ksink/: changed appid to 38e32c5j3gopl. downloading ksink//config.xml. . . downloading ksink//auth.xml. . . downloading ksink//icon.png. . . downloading ksink//thumbnail.png. . . downloading ksink//views/compose.html. . . downloading ksink//views/ksink.html. . . downloading ksink//views/load.html. . . downloading ksink//views/mrd.html. . . downloading ksink//views/uninstall.html. . . downloading ksink//assets/gb.gif. . . downloading ksink//assets/ksink.js. . . downloading ksink//assets/logo.gif. . . downloading ksink//assets/mx.gif. . . downloading ksink//assets/styleme.css. . . downloading ksink//assets/trap_liam.swf. . . downloading ksink//assets/us.gif. . . downloading ksink//assets/warning.jpg. . . Done all gets for ksink/. Application '32ohi6ph68cpm' created. NOTE: Your application has been created. You no longer need to run ymdt create for this application. Use ymdt put to upload files instead. Starting operation at 14:27:26 uploading ksink/auth.xml. . . uploading ksink/config.xml. . . uploading ksink/icon.png. . . uploading ksink/thumbnail.png. . . uploading ksink/assets/gb.gif. . . uploading ksink/assets/ksink.js. . . uploading ksink/assets/logo.gif. . . uploading ksink/assets/mx.gif. . . uploading ksink/assets/styleme.css. . . uploading ksink/assets/trap_liam.swf. . . uploading ksink/assets/us.gif. . . uploading ksink/assets/warning.jpg. . . uploading ksink/views/compose.html. . . uploading ksink/views/ksink.html. . . uploading ksink/views/load.html. . . uploading ksink/views/mrd.html. . . uploading ksink/views/uninstall.html. . . Done all puts for ksink/.
> ymdt create ksink -S 'Kitchen Sink'
Yahoo! Mail Development Tool Version 1.31
Developer server: developer.mail.yahoo.com
create:
Getting sample 'Kitchen Sink' into ksink/:
changed appid to 38e32c5j3gopl.
downloading ksink//config.xml. . .
downloading ksink//auth.xml. . .
downloading ksink//icon.png. . .
downloading ksink//thumbnail.png. . .
downloading ksink//views/compose.html. . .
downloading ksink//views/ksink.html. . .
downloading ksink//views/load.html. . .
downloading ksink//views/mrd.html. . .
downloading ksink//views/uninstall.html. . .
downloading ksink//assets/gb.gif. . .
downloading ksink//assets/ksink.js. . .
downloading ksink//assets/logo.gif. . .
downloading ksink//assets/mx.gif. . .
downloading ksink//assets/styleme.css. . .
downloading ksink//assets/trap_liam.swf. . .
downloading ksink//assets/us.gif. . .
downloading ksink//assets/warning.jpg. . .
Done all gets for ksink/.
Application '32ohi6ph68cpm' created.
NOTE: Your application has been created.
You no longer need to run ymdt create for this application.
Use ymdt put to upload files instead.
Starting operation at 14:27:26
uploading ksink/auth.xml. . .
uploading ksink/config.xml. . .
uploading ksink/icon.png. . .
uploading ksink/thumbnail.png. . .
uploading ksink/assets/gb.gif. . .
uploading ksink/assets/ksink.js. . .
uploading ksink/assets/logo.gif. . .
uploading ksink/assets/mx.gif. . .
uploading ksink/assets/styleme.css. . .
uploading ksink/assets/trap_liam.swf. . .
uploading ksink/assets/us.gif. . .
uploading ksink/assets/warning.jpg. . .
uploading ksink/views/compose.html. . .
uploading ksink/views/ksink.html. . .
uploading ksink/views/load.html. . .
uploading ksink/views/mrd.html. . .
uploading ksink/views/uninstall.html. . .
Done all puts for ksink/.Install and Run Your App in Yahoo! Mail Beta
This app only works in the new Yahoo! Mail beta. If you are not already using Yahoo! Mail beta, go to http://features.mail.yahoo.com and click on 'TRY IT NOW' button. Logout and Login into your Yahoo! Mail beta and agree to the terms to start using beta.
After logging into Yahoo! Mail, notice the Applications Pane in
the lower left corner of the page. Click the
in the upper right-hand corner of the Applications Pane.
This launches the Yahoo! Mail Gallery. Find the app named 'Kitchen Sink (private)' with your Yahoo! ID listed as the developer. It is marked '(private)' because only you can see it while it's under development.
Click the 'Add' button, then close the Gallery. You should now see a 'Kitchen Sink (private)' app in the Applications Pane. Click its icon and the app should show show you a tab with the App opened.
Close/Open Views in App
You can use our Application.closeView API and Application.openView API to open/close Views in different target zones. If the view object passed to closeView function is NULL, it will close the view intiating the call.
A few examples to open/close views in different target zones are listed below. You can try them out, by clicking on the buttons 'Close', 'Open Dialog', 'Open Tab', 'Close that tab' and 'Close Dialog' after launching the App from the Applications pane.
Compose an email to joe: <input id="body"><button onclick="openmail.Mail.compose({ to: 'joe@joe.joe', subject: 'hi joe', body: document.getElementById('body').value })">Compose</button> <hr> Close self: <button onclick="openmail.Application.closeView()">Close</button> <hr> Open another tab with different content: <button onclick='openmail.Application.openView( { id: "otherTab", view: "ksink.html", target: "tab", title:"Y! Groups", context:"tab", parameters: {text:"data for the tab"} } )'>Open Tab </button> <br> Open a dialog: <button onclick='openmail.Application.openView( { id: "otherDialog", view: "ksink.html", target: "dialog", height: 500, parameters: {textData:"some data for the dialog"}, title:"Bunny!", context:"dialog" } )'>Open Dialog </button> <br> Open a dialog and close it 10s later: <button onclick='openmail.Application.openView( { id:"otherDialog", view: "ksink.html", target: "dialog", parameters: {textdata:"this dialog will close itself"}, title:"Self Closing", context: "dialog self-closed"} ); setTimeout("openmail.Application.closeView({ id: \"otherDialog\" })",10000 )'>Open Dialog </button><br> <hr> <button onclick='openmail.Application.closeView({ id: "otherTab" })'>Close that tab</button> <button onclick='openmail.Application.closeView({ id: "otherDialog" })'>Close Dialog</button><br> <hr>
Compose an email to joe: <input id="body"><button onclick="openmail.Mail.compose({ to: 'joe@joe.joe', subject: 'hi joe', body: document.getElementById('body').value })">Compose</button> <hr> Close self: <button onclick="openmail.Application.closeView()">Close</button> <hr> Open another tab with different content: <button onclick='openmail.Application.openView( { id: "otherTab", view: "ksink.html", target: "tab", title:"Y! Groups", context:"tab", parameters: {text:"data for the tab"} } )'>Open Tab </button> <br> Open a dialog: <button onclick='openmail.Application.openView( { id: "otherDialog", view: "ksink.html", target: "dialog", height: 500, parameters: {textData:"some data for the dialog"}, title:"Bunny!", context:"dialog" } )'>Open Dialog </button> <br> Open a dialog and close it 10s later: <button onclick='openmail.Application.openView( { id:"otherDialog", view: "ksink.html", target: "dialog", parameters: {textdata:"this dialog will close itself"}, title:"Self Closing", context: "dialog self-closed"} ); setTimeout("openmail.Application.closeView({ id: \"otherDialog\" })",10000 )'>Open Dialog </button><br> <hr> <button onclick='openmail.Application.closeView({ id: "otherTab" })'>Close that tab</button> <button onclick='openmail.Application.closeView({ id: "otherDialog" })'>Close Dialog</button><br> <hr>
getAttachmentUrl in App
Use our
getAttachmentUrl API to access the time sensitive URL
of a message's attachment content. To get to the attachment content,
look for 'disposition' value 'attachment' in message's mime part
and retrieve the static 'url' value. 'url' can then be used with getAttachmentUrl API
to get to the actual content. You must specify <format>full</format> in your config,
for the <data><mail_message>, to get access to the data in response.data.part array.
The view's load handler uses getParameters() to retrieve the context and parameters
arguments originally passed to openView().
function getAttachmentUrl(){ openmail.Application.getParameters(function(o){ if (!o){ alert("Response failed"); return; } if (o.data && o.data.part){ var part, url; for ( part in o.data.part){ if (o.data.part[part].disposition == "attachment"){ url = o.data.part[part].url; var args = {url: url}; YAHOO.util.Dom.get('attachurl').value = "Fetching..."; openmail.Application.getAttachmentUrl(args , function(data){ YAHOO.util.Dom.get('attachurl').value = data.url ? data.url : (data.error? data.error : "error"); }); return; } //if }//for YAHOO.util.Dom.get('attachurl').value = "There is no attachment data."; } //if }); }
function getAttachmentUrl(){ openmail.Application.getParameters(function(o){ if (!o){ alert("Response failed"); return; } if (o.data && o.data.part){ var part, url; for ( part in o.data.part){ if (o.data.part[part].disposition == "attachment"){ url = o.data.part[part].url; var args = {url: url}; YAHOO.util.Dom.get('attachurl').value = "Fetching..."; openmail.Application.getAttachmentUrl(args , function(data){ YAHOO.util.Dom.get('attachurl').value = data.url ? data.url : (data.error? data.error : "error"); }); return; } //if }//for YAHOO.util.Dom.get('attachurl').value = "There is no attachment data."; } //if }); }
getParameters in App
Use our getParameters API to retrieve properties associated with the view that invoked the function.
Code for this view includes a button that opens another instance of itself,
with application-defined context and additional parameters.
The view's load handler uses getParameters() to retrieve the context and parameters
arguments originally passed to openView().
<body> ... <button onclick='openmail.Application.openView({ id:"otherDialog", view:"full", target:"dialog", title:"Bunny!", context:"button-launched view", parameters:{ my: 1; custom: "JSON"; stuff:null } })'> Open Dialog </button> </body> <script> ... //load handler function refresh() { openmail.Application.getParameters(function(args){ // if view opened by button above: // args.context is "button-launched view" // args.data is { my: 1; custom: "JSON"; stuff:null } var ta = document.createElement("textarea"); ta.value = YAHOO.lang.JSON.stringify(args); ta.style.width="100%"; ta.style.height="100px"; document.getElementById("params").appendChild(ta); }); } ... </script>
<body> ... <button onclick='openmail.Application.openView({ id:"otherDialog", view:"full", target:"dialog", title:"Bunny!", context:"button-launched view", parameters:{ my: 1; custom: "JSON"; stuff:null } })'> Open Dialog </button> </body> <script> ... //load handler function refresh() { openmail.Application.getParameters(function(args){ // if view opened by button above: // args.context is "button-launched view" // args.data is { my: 1; custom: "JSON"; stuff:null } var ta = document.createElement("textarea"); ta.value = YAHOO.lang.JSON.stringify(args); ta.style.width="100%"; ta.style.height="100px"; document.getElementById("params").appendChild(ta); }); } ... </script>
getData, setData and removeData in App
Use our getData, setData and removeData APIs to manipulate the keys in the per-app-per-user persistent store.
You can try these options by clicking on 'get test data', 'set test data' and 'remove test data' buttons when you lauch the app.
<html> Set Example Data (mykey1=myval1, mykey2=myval2, mykey3=myval3), mykey2 set to expire in 30s: <button onclick='testSetData()'>set test data</button><br> Get Example Data : <button onclick='testGetData()'>get test data</button><br> Remove Example Data (remove mykey3): <button onclick='testRemoveData()'>remove test data</button><br> </html> ... function testSetData() { var ttl = 30; openmail.Application.setData( { keys: { mykey1: "myval1", mykey2: "myval2", mykey3: "myval3" }, ttl: { mykey2: ttl } }, function(result) { if(result.error && result.error != YAHOO.openmail.ERR_NONE) alert("Error calling setData(): " + result.errorMsg + "\n"); else alert("Called setData with:" + "\n" + "mykey1=myval1" + "\n" + "mykey2=myval2 with ttl=" + ttl + "\n" + "mykey3=myval3" ); } ); } function testGetData() { openmail.Application.getData( { keys: ["mykey1", "mykey2", "mykey3" ] }, function(result) { var errors = result.errorCode; alert( "mykey1=" + result.data["mykey1"] + ", errorCode=" + errors["mykey1"] + "\n" + "mykey2=" + result.data["mykey2"] + ", errorCode=" + errors["mykey2"] + "\n" + "mykey3=" + result.data["mykey3"] + ", errorCode=" + errors["mykey3"] + "\n" ); } ); } function testRemoveData() { openmail.Application.removeData( { keys: ["mykey3"] }, function(result) { if(result.error && result.error != YAHOO.openmail.ERR_NONE) alert("Error calling removeData(): " + result.errorMsg + "\n"); else alert("No error detected calling removeData()."); } ); }
<html> Set Example Data (mykey1=myval1, mykey2=myval2, mykey3=myval3), mykey2 set to expire in 30s: <button onclick='testSetData()'>set test data</button><br> Get Example Data : <button onclick='testGetData()'>get test data</button><br> Remove Example Data (remove mykey3): <button onclick='testRemoveData()'>remove test data</button><br> </html> ... function testSetData() { var ttl = 30; openmail.Application.setData( { keys: { mykey1: "myval1", mykey2: "myval2", mykey3: "myval3" }, ttl: { mykey2: ttl } }, function(result) { if(result.error && result.error != YAHOO.openmail.ERR_NONE) alert("Error calling setData(): " + result.errorMsg + "\n"); else alert("Called setData with:" + "\n" + "mykey1=myval1" + "\n" + "mykey2=myval2 with ttl=" + ttl + "\n" + "mykey3=myval3" ); } ); } function testGetData() { openmail.Application.getData( { keys: ["mykey1", "mykey2", "mykey3" ] }, function(result) { var errors = result.errorCode; alert( "mykey1=" + result.data["mykey1"] + ", errorCode=" + errors["mykey1"] + "\n" + "mykey2=" + result.data["mykey2"] + ", errorCode=" + errors["mykey2"] + "\n" + "mykey3=" + result.data["mykey3"] + ", errorCode=" + errors["mykey3"] + "\n" ); } ); } function testRemoveData() { openmail.Application.removeData( { keys: ["mykey3"] }, function(result) { if(result.error && result.error != YAHOO.openmail.ERR_NONE) alert("Error calling removeData(): " + result.errorMsg + "\n"); else alert("No error detected calling removeData()."); } ); }
You can get the complete source for the Kitchen Sink app by running ymdt get -S 'Kitchen Sink'.