how to open a url from the barcode scanner in phonegap build - phonegap-build

i'am using the Barcode Scanner for phonegap build, How would i retrieve the QR Codes URL data and display the webpage into a Iframe or div
$(document).ready(function(e) {
$("#scanner_mode").click(function() {
cordova.plugins.barcodeScanner.scan(
function (result) {
alert("We got a barcode\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n" +
"Cancelled: " + result.cancelled);
},
function (error) {
alert("Scanning failed: " + error);
}
);
});
});
Right i have tried this but its not working, so how would i get the src of a iframe to load result.text url
$(document).ready(function(e) {
$("#scanner_mode").click(function() {
cordova.plugins.barcodeScanner.scan(
function (result) {
document.getElementById("frame").src = result.text;
},
function (error) {
alert("Scanning failed: " + error);
}
);
});
});

yep so its working :)
$(document).ready(function(e) {
$("#scanner_mode").click(function() {
cordova.plugins.barcodeScanner.scan(
function (result) {
document.getElementById("frame").src = result.text;
},
function (error) {
alert("Scanning failed: " + error);
}
);
});
});
that works :)

Related

Parse Javascript Platform Change Password Error

I defined a cloud codeļ¼š
Parse.Cloud.define("updateUser", async (request) => {
const query = new Parse.Query("User");
query.get(request.params.id, {useMasterKey:true})
.then(function(user) {
user.set("username", request.params.username);
user.set("password", request.params.password);
user.set("gender", request.params.gender);
return user.save(null, {useMasterKey:true});
}).catch(function(error) {
console.error("Got an error " + error.code + " : " + error.message);
});
});
Return has been changed successfully.
But, using the new password to log in on the mobile app, the password is incorrect.
{"code":101, "stack": "Error": Invalide username/password}
I think you need to return the first promise. Also try to use setUsername and setPassword. It would be something like this:
Parse.Cloud.define("updateUser", async (request) => {
const query = new Parse.Query("User");
return query.get(request.params.id, {useMasterKey:true})
.then(function(user) {
user.setUsername(request.params.username);
user.setPassword(request.params.password);
user.set("gender", request.params.gender);
return user.save(null, {useMasterKey:true});
}).catch(function(error) {
console.error("Got an error " + error.code + " : " + error.message);
});
});

PhantomJS: Operation Canceled while loading resource via AJAX

This is my code:
page.onResourceRequested = function (requestData, networkRequest) {
console.log(requestData.url); // This message shows http://website-with-jquery-included.com/page.html!
}
page.onResourceError = function(resourceError) {
console.log('Unable to load resource (#' + resourceError.id + 'URL:' + resourceError.url + ')');
console.log('Error code: ' + resourceError.errorCode + '. Description: ' + resourceError.errorString);
};
page.open('http://website-with-jquery-included.com/', function(status) {
if (status === "success") {
page.evaluate(function() {
console.log('I can see this message');
$.ajax({url: 'http://website-with-jquery-included.com/page.html', success: function(resp) {
console.log('I cannot see this message!');
}});
});
}
});
Function page.onResourceError prints the error message:
Unable to load resource
(#35URL:http://website-with-jquery-included.com/page.html)
Error code: 5. Description: Operation canceled
Why is it canceled? I didn't cancel anything manually. It works well from the browser (Google Chrome).

Parse cloud code afterSave gets triggered twice

I have a aftersave on Parse cloud code. I have made changes to the table once but the aftersave hook triggers twice
1st Update (Actual update)
Input: {"object":{"addedBy":"tt","albumTitle":"ggh","approved":true,
"createdAt":"2015-12-14T03:07:27.253Z","image":
{"__type":"File","name":"tfss-e26ec608-5a0b-46a2-91db-33590139c4b3-
newImage.jpg","url":"http://files.parsetfss.com/0accbdba-e3f2-493d-
ac70-1c6bccc367b9/tfss-e26ec608-5a0b-46a2-91db-33590139c4b3-
newImage.jpg"},"objectId":"p4pLO70gQY","updatedAt":"2015-12-
14T03:07:37.733Z"}}
2nd Update (Shouldn't happen)
Input: {"object":{"addedBy":"tt","albumTitle":"ggh","approved":true,
"createdAt":"2015-12-14T03:07:27.253Z","image":
{"__type":"File","name":"tfss-e26ec608-5a0b-46a2-91db-33590139c4b3-
newImage.jpg","url":"http://files.parsetfss.com/0accbdba-e3f2-493d-
ac70-1c6bccc367b9/tfss-e26ec608-5a0b-46a2-91db-33590139c4b3-
newImage.jpg"},"objectId":"p4pLO70gQY","updatedAt":"2015-12-
14T03:07:38.038Z"}}
The only difference between the two updates is the updatedAt time. Will aftersave be triggered even if the update time changes?
How can I avoid the second aftersave execution?
Here is my cloud code :
Parse.Cloud.afterSave("Photos", function (request) {
var albumNameA = "";
var publicUser = "";
var albumOwner = "";
var photoUniqueId = "";
var isApproved = "";
albumNameA = request.object.get("albumTitle");
publicUser = request.object.get("addedBy");
photoUniqueId = request.object.id;
isApproved = request.object.get("approved");
if (request.object.get("createdAt").getTime() == request.object.get("updatedAt").getTime()) {
var getAlbumOwner = new Parse.Object.extend("Albums");
var q3 = new Parse.Query(getAlbumOwner);
q3.equalTo("title", albumNameA);
q3.first({
success: function (results) {
console.log("Checking for Creator name " + results.get("creatorName"));
albumOwner = results.get("creatorName");
console.log("Uploading a Photo Final " + albumNameA + "-by-" + publicUser + "--ownedby--" + albumOwner);
console.log("Uploading a Photo" + albumNameA + "-by-" + publicUser + "--" + photoUniqueId + "--" + isApproved);
var install = new Parse.Object.extend("Installation");
var q2 = new Parse.Query(install);
q2.equalTo("privacy", privateUserNo);
q2.equalTo("username", albumOwner);
q2.find({
success: function (results) {
if (!isApproved) {
Parse.Push.send({
where: q2, // Set our Installation query
data: {
alert: "New Photo uploaded by " + publicUser + " ,waiting for approval"
}
}, {
success: function () {
// Push was successful
console.log("Push success");
},
error: function (error) {
// Handle error
console.log("Push error");
}
})
}
},
error: function (error) {
console.log("Error: " + error.code + " " + error.message);
}
});
},
error: function (error) {
console.log("Error: " + error.code + " " + error.message);
}
});
} else if (!(request.object.get("createdAt").getTime() == request.object.get("updatedAt").getTime())) {
console.log("all case scenarios");
var getAlbumOwner1 = new Parse.Object.extend("Albums");
var q6 = new Parse.Query(getAlbumOwner1);
q6.equalTo("title", albumNameA);
q6.first({
success: function (results) {
albumOwner = results.get("creatorName");
var sendApproval = new Parse.Object.extend("Photos");
var q4 = new Parse.Query(sendApproval);
q4.descending("updatedAt");
q4.first({
success: function (results) {
var objectIDNeeded = results.id;
var isChanged = results.get("approved");
var currentUpdateTime = results.get("updatedTime");
console.log("Your Photo, " + publicUser + " ,has been approved by " + albumOwner);
var install = new Parse.Object.extend("Installation");
var q5 = new Parse.Query(install);
q5.equalTo("privacy", privateUserNo);
q5.equalTo("username", publicUser);
q5.find({
success: function (results) {
Parse.Push.send({
where: q5, // Set our Installation query
data: {
alert: "Your Photo has been approved by " + albumOwner
}
}, {
success: function () {
// Push was successful
console.log("Push success");
},
error: function (error) {
// Handle error
console.log("Push error");
}
})
},
error: function (error) {
console.log("Error: " + error.code + " " + error.message);
}
});
},
error: function (error) {
console.log("Error: " + error.code + " " + error.message);
}
});
},
error: function (error) {
console.log("Error: " + error.code + " " + error.message);
}
});
}
});

SMS sending in WebAPI with Samsung Gear S

Has anyone found a working example for integrating SMS in an app into a Samsung Gear S using the WebAPI?
I found two examples for tizen, but none of them worked with the Gear S. With minor adaptations they look like this:
First try:
function sendSMS(smsno)
{
if (bDebug)
alert("Versuche SMS (sendSMS) zu senden an " + smsno);
smsnumber = smsno;
try
{
var appControl = new tizen.ApplicationControl(
'http://tizen.org/appcontrol/operation/compose', 'sms:'
+ smsnumber);
tizen.application.launchAppControl(appControl, null, function()
{
}, function(e)
{
alert("SMS konnte nicht gesendet werden: " + e.message);
},
{
onsuccess : function()
{
},
onfailure : function(er)
{
alert("SMS konnte nicht gesendet werden: " + er.message);
}
});
}
catch (e)
{
alert("http://tizen.org/appcontrol/operation - " + e.message);
}
}
Second try:
// Define the success callback.
function messageSent(recipients)
{
if (bDebug)
alert("The SMS has been sent");
}
// Define the error callback.
function messageFailed(error)
{
alert("The SMS could not be sent " + error.message);
}
// Define service error callback.
function serviceErrorCB(error)
{
alert("Cannot get messaging service " + error.message);
}
// Define the success callback.
function serviceListCB(services)
{
try
{
if (services.length > 0)
{
var msg = new tizen.Message("messaging.sms",
{
plainBody : "Hilferuf von Nummer: " + smsnumber + ": "
+ vorname + " " + nachname + ": " + adresse,
to : [ smsnumber ]
});
// Send request
services[0].sendMessage(msg, messageSent, messageFailed);
}
}
catch (e)
{
alert("serviceListCB Problem - " + e.message);
}
}
function sendSMS_tizen(smsno)
{
if (bDebug)
alert("Versuche SMS zu senden an " + smsno);
smsnumber = smsno;
try
{
tizen.messaging.getMessageServices("messaging.sms", serviceListCB,
serviceErrorCB);
}
catch (e)
{
alert("tizen.messaging nicht definiert- " + e.message);
}
}
Unfortunately the Samsung documentation is very unspecific on this part.
ANy ideas welcome!
Both solutions are from Mobile profile. It will not work on Gear S. Unfortunately now there is now way to send sms from web api on Gear S. That is why there is no documentation on this ;)

MVC 3 & Uploadify - how to show custom error message?

After uploading a file, before I save it on the disk, I'm doing some validation.
If something fails, I want to show my custom error message to the user.
I've found something sililar here Uploadify: show error message from HTTP response
How to do this in MVC 3 ?
Tony,
Taken straight from ab mvc3 app that I'm working on right now:
<script type="text/javascript">
function initupLoadify() {
$("#fileInput").uploadify({
uploader: '#Url.Content("~/scripts/swf/uploadify.swf")',
script: '#Url.Action("Upload", "Home")',
cancelImg: '#Url.Content("~/Content/cancel.png")',
auto: true,
sizeLimit: 5500000,
fileDataName: 'fileData',
//scriptData: { 'propertyId': $("#PropertyID").val() },
buttonText: 'Add Schedule',
wmode: 'transparent',
//buttonImg: '#Url.Content("~/Content/button.png")', // make nice gradient image for button
onComplete: function (event, queueId, fileObj, response) {
$("#msg").html(response);
// do something
setTimeout(2000, window.location = '#Url.Action("Index")' + '?id=' + response);
return true;
},
onCancel: function (evt, queueId, fileObj, data) {
$("#msg").html("<br />Operation cancelled");
return true;
},
onOpen: function (evt, queueId, fileObj) {
$("#msg").html("<br />Upload in progress");
return true;
},
onError: function (event, queueId, fileObj, errorObj) {
$("#msg").html(fileObj.name + " was not uploaded ");
if (errorObj.status == 404)
$("#msg").html("Could not find upload script. Use a path relative to: " + "<?= getcwd() ?>");
else if (errorObj.type === "HTTP")
$("#msg").html("error " + errorObj.type + ": " + errorObj.status);
else if (errorObj.type === "File Size")
$("#msg").html(fileObj.name + " " + errorObj.type + " Limit: " + errorObj.info / 1000 + " KB");
else
$("#msg").html("error " + errorObj.type + ": " + errorObj.text);
}
});
};
</script>
hope this helps
Here is an MVC 3 example.
If you're using versions 3.0+ use onUploadComplete instead of onComplete (realize their parameters differ).

Resources