Adding and optional call to cast Plugin Result

This commit is contained in:
macdonst
2010-11-18 06:37:27 +08:00
parent 46babe7a48
commit c1a87ebaaa
2 changed files with 32 additions and 5 deletions
+15 -4
View File
@@ -421,12 +421,13 @@ PhoneGap.callbackStatus = {
* @param {String} service The name of the service to use
* @param {String} action Action to be run in PhoneGap
* @param {String[]} [args] Zero or more arguments to pass to the method
* @param {String} jsClass The class to cast the return as
*/
PhoneGap.exec = function(success, fail, service, action, args) {
PhoneGap.exec = function(success, fail, service, action, args, cast) {
try {
var callbackId = service + PhoneGap.callbackId++;
if (success || fail) {
PhoneGap.callbacks[callbackId] = {success:success, fail:fail};
PhoneGap.callbacks[callbackId] = {success:success, fail:fail, cast:cast};
}
// Note: Device returns string, but for some reason emulator returns object - so convert to string.
@@ -442,7 +443,12 @@ PhoneGap.exec = function(success, fail, service, action, args) {
// If there is a success callback, then call it now with returned value
if (success) {
try {
success(v.message);
if (cast) {
success(cast(v.message));
}
else {
success(v.message);
}
}
catch (e) {
console.log("Error in success callback: "+callbackId+" = "+e);
@@ -504,7 +510,12 @@ PhoneGap.callbackSuccess = function(callbackId, args) {
if (args.status == PhoneGap.callbackStatus.OK) {
try {
if (PhoneGap.callbacks[callbackId].success) {
PhoneGap.callbacks[callbackId].success(args.message);
if (PhoneGap.callbacks[callbackId].cast) {
PhoneGap.callbacks[callbackId].success(PhoneGap.callbacks[callbackId].cast(args.message));
}
else {
PhoneGap.callbacks[callbackId].success(args.message);
}
}
}
catch (e) {