Build a selector - jquery-selectors

i try to build my own selector but I get errors.
firebug tell me:
missing ) after argument list
$("#for_" + $(this)attr('id') + "").click(function() {
alert($(this).attr("id"));
});
could somebody help me plaese?

$("#for_" + $(this)attr('id') + "").click(function() {
^---
You're missing a .. at the indicated spot. Should be
$("#for_" + $(this).attr('id') + "").click(function() {

$("#for_" + $(this).attr('id')).click(function() {
alert($(this).attr("id"));
});
Didnt you forget "." before attr?

Related

How to replace deprecated jQuery functions?

I am trying to display a map in my UI5 app using a formatter.js where I need to put the address with the map URL together.
In the old world the code should look like the following:
formatMapUrl: function(sStreet, sZIP, sCity, sCountry) {
return "https://maps.googleapis.com/maps/api/staticmap?zoom=13&size=640x640&markers="
+ jQuery.sap.encodeURL(sStreet + ", " + sZIP + " " + sCity + ", " + sCountry);
},
How should I replace the deprecated function? Where should I add the new code?
If you look at the API documentation for jQuery.sap.encodeURL, you see it states to use the module sap/base/security/encodeURL now.
Usage example from documentation:
sap.ui.require(["sap/base/security/encodeURL"], function(encodeURL) {
var sEncoded = encodeURL("a/b?c=d&e");
console.log(sEncoded); // a%2fb%3fc%3dd%26e
});
Usage in the formatter.js:
sap.ui.define([
"sap/base/security/encodeURL"
], function (encodeURL) {
"use strict";
return {
formatMapUrl: function(sStreet, sZIP, sCity, sCountry) {
var sBaseUrl = "https://maps.googleapis.com/maps/api/staticmap?zoom=13&size=640x640&markers=";
var sEncodedString = encodeURL(sStreet + ", " + sZIP + " " + sCity + ", " + sCountry);
return sBaseUrl + sEncodedString;
}
};
});

Present Time Range in Grafana's Text Panel

Is there a way to show timeRange.from and timeRange.to in Grafana's Text panel or may be in an another panel?
I tried text-panels with markdown mode:
# Time From: $__interval
with different variables but no one did work. Neither did it if I defined a variable in Settings. The interval or timestamp is not showing.
I'm currently working on an HTML solution, but wondering if there is a simplier/proper way to present the time ranges?
My HTML-solution, in case somebody faces the same issue
(got the main part from maxreb's solution from: https://github.com/grafana/grafana/issues/1909) :
<script type="text/javascript">
refreshTimeFrom();
refreshTimeTo();
angular.element('grafana-app').injector().get('timeSrv').$rootScope.$on('refresh', function(event, data) { refreshTimeFrom(); });
function refreshTimeFrom( )
{
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var ts = new Date(angular.element('grafana-app').injector().get('timeSrv').timeRange().from);
document.getElementById("timeFrom").innerHTML = days[ts.getUTCDay() ] + " "
+ ts.getUTCDate() + "." + (ts.getUTCMonth()+1) + "."
+ ts.getUTCFullYear() + " " + ts.getUTCHours() + ":"
+ ts.getUTCMinutes() + ":" + ts.getUTCSeconds();
}
function refreshTimeTo( )
{
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var ts = new Date(angular.element('grafana-app').injector().get('timeSrv').timeRange().to);
document.getElementById("timeTo").innerHTML = days[ts.getUTCDay() ] + " "
+ ts.getUTCDate() + "." + (ts.getUTCMonth()+1) + "."
+ ts.getUTCFullYear() + " " + ts.getUTCHours() + ":"
+ ts.getUTCMinutes() + ":" + ts.getUTCSeconds();
}
</script>
<font size = "3"><b> From:</b> <span id="timeFrom" /></br></font>
<font size = "3"><b> To: </b> <span id="timeTo" /> </font>

NodeRed Function Node Crashes - [red] Uncaught Exception:

I am having a hard time understanding why my Node-Red Flow keeps crashing with an [RED] Uncaught Exception. It almost seems like the function node is crashing and my code inside of the function node never has a chance to catch it.
I have a very simple Node-Red flow that executes a IBMDB node.js library to insert data into my database. In order to use the IBMDB library, I had to add the package to the list of packages in my packages.json file. I also had to setup a global context variable inside the Bluemix-setings.js file. I named this global context variable IBMDB, which is the equivalent to the require statement. Once that was done, I am able to make use of the library inside a function node.
** Here is the Node.js IBMDB library, I am using.
https://github.com/ibmdb/node-ibm_db
** Here is the Flow
** Here is the code inside the function.
try {
context.global.ibmdb.open("DATABASE=database;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=username;PWD=password;", function (err,conn) {
conn.beginTransaction(function (err) {
if (err) {
//could not begin a transaction for some reason.
console.log(err);
return conn.closeSync();
}
for (i = 0; i < msg.payload.Readings.length; i++)
{
var result = conn.querySync("INSERT INTO db2.table (" +
"I_ID," +
"D_ID," +
"field1," +
"field2," +
"field3," +
"field4," +
"field5," +
"field6," +
"field7," +
"field8," +
"field9," +
"field10)" +
"values (" +
"1A," +
"'"+ msg.payload.field1 + "',"+
"'" + JSON.stringify(msg.payload.Readings[i].field2) + "'," +
msg.payload.Readings[i].field3 + ","+
msg.payload.Readings[i].field4 + ","+
msg.payload.Readings[i].field5 + ","+
msg.payload.Readings[i].field6 + ","+
msg.payload.Readings[i].field7 + ","+
msg.payload.Readings[i].field8 + ","+
msg.payload.Readings[i].field9 + ","+
msg.payload.Readings[i].field10 + ","+
"'2016-05-31 22:28:51.000000'" +
");");
}
conn.commitTransaction(function (err) {
if (err) {
//error during commit
console.log("****ERROR: " + err);
node.error("**** ERROR: ", err);
//return conn.closeSync();
}
//Close the connection
conn.closeSync();
});
});
});
} catch (e) {
node.error("**** ERROR: ", err);
}
When I run this with a valid SQL statement and all the data types are correctly sent, I get no errors. Everything works!!
*** The issue: When I did some testing to force a SQL error, the Node-Red instance crashes. I forced the error by sending a valid SQL statement, but the data elements in one of the fields is a non-numeric value where the table definition is expecting numeric only. I see in the error logs (console out) two lines..
The error SQL error message displayed is exactly what I was expecting to catch in my application. Instead the application just crashes.
[red] Uncaught Exception: Error: [IBM][CLI Driver][DB2/LINUXX8664]
SQL0103N The numeric literal "1A" is not valid. SQLSTATE=42604
Any insight on what is really happening would be greatly appreciated. I am wondering if I put this code inside a custom built node would I be able to catch the error. Could this be a limitation of using the function node as a wrapper to my code. ????
*
Try wrapping the conn.querySync call in it's own try/catch block. The current block is out of scope because the call happens in another function (the one passed into beginTransaction).
e.g.
try {
context.global.ibmdb.open("DATABASE=database;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=username;PWD=password;", function (err,conn) {
conn.beginTransaction(function (err) {
if (err) {
//could not begin a transaction for some reason.
console.log(err);
return conn.closeSync();
}
for (i = 0; i < msg.payload.Readings.length; i++)
{
try {
var result = conn.querySync("INSERT INTO db2.table (" +
"I_ID," +
"D_ID," +
"field1," +
"field2," +
"field3," +
"field4," +
"field5," +
"field6," +
"field7," +
"field8," +
"field9," +
"field10)" +
"values (" +
"1A," +
"'"+ msg.payload.field1 + "',"+
"'" + JSON.stringify(msg.payload.Readings[i].field2) + "'," +
msg.payload.Readings[i].field3 + ","+
msg.payload.Readings[i].field4 + ","+
msg.payload.Readings[i].field5 + ","+
msg.payload.Readings[i].field6 + ","+
msg.payload.Readings[i].field7 + ","+
msg.payload.Readings[i].field8 + ","+
msg.payload.Readings[i].field9 + ","+
msg.payload.Readings[i].field10 + ","+
"'2016-05-31 22:28:51.000000'" +
");");
} catch (excp) {
//do stuff
}
}
conn.commitTransaction(function (err) {
if (err) {
//error during commit
console.log("****ERROR: " + err);
node.error("**** ERROR: ", err);
//return conn.closeSync();
}
//Close the connection
conn.closeSync();
});
});
});
} catch (e) {
node.error("**** ERROR: ", e);
}

How to control the flow of methods that don't return promise in protractor test

I've got a spec where I'm grabbing a screenshot that also requires a dynamic path be created. makeDir does not return a promise, so it fires at the same time (after) saveScreenshot. What's the best way to ensure makeDir is called first?
getPath().then(function(path) {
makeDir(baseUrl + '/' + path);
saveScreenshot(baseUrl + '/' + path + '/' + filename);
})
You should be able to just chain another then() and do the second operation in there.
getPath().then(function(path) {
makeDir(baseUrl + '/' + path);
var screenshotpath = baseUrl + '/' + path + '/' + filename;
return screenshotpath;
}).then(function(screenshotpath) {
saveScreenshot(screenshotpath);
});

Getting null value while displaying contacts in iphone phonegap application

I am working on Phonegap application and trying to get the contacts of the device.
What I have done from this reference is as follows :
function onDeviceReady() {
var options = new ContactFindOptions();
options.filter=""; // empty search string returns all contacts
options.multiple=true; // return multiple results
filter = ["displayName"];
navigator.contacts.find(filter, onSuccess, onError, options);
}
// contacts Methods
function onSuccess(contacts) {
for (var i=0; i<contacts.length; i++) {
for (var j=0; j<contacts[i].addresses.length; j++) {
alert("Pref: " + contacts[i].addresses[j].pref + "\n" +
"Type: " + contacts[i].addresses[j].type + "\n" +
"Formatted: " + contacts[i].addresses[j].formatted + "\n" +
"Street Address: " + contacts[i].addresses[j].streetAddress + "\n" +
"Locality: " + contacts[i].addresses[j].locality + "\n" +
"Region: " + contacts[i].addresses[j].region + "\n" +
"Postal Code: " + contacts[i].addresses[j].postalCode + "\n" +
"Country: " + contacts[i].addresses[j].country);
}
}
};
// onError: Failed to get the contacts
function onError(contactError){
alert('onError!');
}
In console while printing the contacts I am getting this error-
[INFO] Error in success callback: Contacts1 = TypeError: 'null' is not an object
There are contacts in my simulator and contact information is not null still I am getting null. Not sure about the reason.
Please help me.
EDIT : same thing is happening when I am playing audio files ..
Any one have idea why this is happening ??