extjs 4.0 retrieve grid values - grid

The code below is for getting a Json string for the selected rows in a grid.
However this feels rather clumsy or is the way to go for extjs 4?
var json = "[";
var selrows = g.getView().getSelectionModel().getSelection();
for (var r=0; r<selrows.length; r++) {
var selrow = selrows[r];
json += "{";
for (var f=0; f<selrow.fields.length; f++) {
var n = selrow.fields.items[f].name;
var v = selrow.data[n];
json += "'" + n + "' : '" + v + "',";
}
json += "},";
}
json += "]";
alert(json);
In Firebug I see a json-alike representation of the selrow var but I can't seem to get hold of it in javascript.

Try this:
json = Ext.JSON.encode(g.getView().getSelectionModel().getSelection().map(function(e){ return e.data; }));
alert(json);

Related

Script not running in google chrome

I have a page in aspx which uses the following code. The issue is that it fetches the values from SQL and put into boxes using internet explorer but not doing using chrome
var element = document.getElementById("ctl00$pagecontent$Flexibleselect_Reol$ctl01");
//alert(element);
//alert('<%=Flexibleselect_Reol.Controls[1].ClientID %>');
element.onchange = (function(onchange) {
return function(evt) {
// reference to event to pass argument properly
evt = evt || event;
// new code "injection"
var puselectobj = document.getElementById('ctl00$pagecontent$Flexibleselect_Reol$ctl01');
var paramVal = puselectobj.value;
// alert(paramVal);
var newUrl = updateURLParameter('ProcessUnit', paramVal);
theForm.action = newUrl;
if (onchange) {
onchange(evt);
}
}
})(element.onchange);
// alert(element.onchange);
function updateURLParameter(param, value) {
var url = theForm.action;
var newAdditionalURL = "";
var tempArray = url.split("?");
var baseURL = tempArray[0];
var additionalURL = tempArray[1];
var temp = "";
if (additionalURL) {
tempArray = additionalURL.split("&");
for (i = 0; i < tempArray.length; i++) {
if (tempArray[i].split('=')[0] != param) {
newAdditionalURL += temp + tempArray[i];
temp = "&";
}
}
}
var paramVal = value;
var rows_txt = temp + "" + param + "=" + paramVal;
var querystr = "?" + newAdditionalURL + rows_txt;
return baseURL + querystr;
}
I am getting the following error when running in chrome
"Uncaught TypeError: Cannot read properties of null (reading 'onchange')"

How do scrape table from the provided website using casperjs?

The final goal is to retrieve stock data in table form from provided broker website and save it to some text file. Here is the code, that I managed to compile so far by reading few tutorials:
var casper = require("casper").create();
var url = 'https://iqoption.com/en/historical-financial-quotes?active_id=1&tz_offset=60&date=2016-12-19-21-59';
var terminate = function() {
this.echo("Exiting ...").exit();
};
var processPage = function() {
var rows = document.querySelectorAll('#mCSB_3_container > table'); //get table from broker site (copy/paste via copy selector in chrome tools)
//var nodes = document.getElementsByClassName('mCSB_container');
this.echo(rows);
this.echo(rows.length);
for (var i = 0; i < rows.length; i++)
{
var cell = rows[i].querySelector('.quotes-table-result__date');
this.echo(cell); //print each cell
}
};
casper.start(url);
casper.waitForSelector('#mCSB_3_container', processPage, terminate);
casper.run();
This code should retrieve the stock price table and print out each cell. However, all what I get is 'undefined', which likely means that I got no objects returned by queryselector call. And please assume that I don't know any web programming (HTML,CSS).
First of all, on problem is that the waitFor wasn't set so good, you have to wait for the rows/cells.
The Nodes you get out on this page are a bit wired,if anybody got a more abstract solution where ChildNodes are better handled that in my solution i would be really interested:
var casper = require('casper').create();
var url = 'https://eu.iqoption.com/en/historical-financial-quotes?active_id=1&tz_offset=60&date=2016-12-19-21-59';
var length;
casper.start(url);
casper.then(function() {
this.waitForSelector('#mCSB_3_container table tbody tr');
});
function getCellContent(row, cell) {
cellText = casper.evaluate(function(row, cell) {
return document.querySelectorAll('table tbody tr')[row].childNodes[cell].innerText.trim();
}, row, cell);
return cellText;
}
casper.then(function() {
var rows = casper.evaluate(function() {
return document.querySelectorAll('table tbody tr');
});
length = rows.length;
this.echo("table length: " + length);
});
// This part can be done nicer, but it's the way it should work ...
casper.then(function() {
for (var i = 0; i < length; i++) {
this.echo("Date: " + getCellContent(i, 0));
this.echo("Bid: " + getCellContent(i, 1));
this.echo("Ask: " + getCellContent(i, 2));
this.echo("Quotes: " + getCellContent(i, 3));
}
});
casper.run();

jquerymobile selectmenu fails

i'm trying to create a categories list with Jquerymobile-html5 and websql/sqlite.
i post my code here to hope someone sees what i do wrong.
//load the cats to choose a cat
function loadCatOptions() {
var option_str='';
option_str += '<option value="0" data-placeholder="true">Choose categorie</option>';
//option_str += '<option value="0">Top/ParentiD</option>';
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM categories', [], function (tx, results) {
var len = results.rows.length, i;
for (i = 0; i < len; i++) {
var r = results.rows.item(i);
var catID = r.categories_id;
}
var count =0;
while (count < catID+1){
count;
tx.executeSql('SELECT c.parent_id, c.categories_id, cd.categories_name, c.categories_image FROM categories c, categories_description cd WHERE c.categories_id ='+ count +' AND cd.categories_id ='+ count +' and cd.language_id ="1" ORDER BY sort_order, cd.categories_name', [], function (tx, results) {
var len = results.rows.length, i;
for (i = 0; i < len; i++) {
var r2 = results.rows.item(i);
option_str += "<option value=" + r2['categories_id'] + ">" + r2['categories_name'] + "</option>";
console.log('categoriesname='+ r2['categories_name']);
$("#parent_id").html(option_str).selectmenu('refresh', true);
}
});
count++;
}
});
});
}
The consolelog shows all items by its name, so i'm sure that the database query is correct.
I might have spend days to someting what wasnt the problem at all.
if i take only the SELECT * query and call the selectmenu, i can see all categorie_id's in the list (ofcourse replace categories_name by categories_id to got that to work).
So the problem now is with jquerymobile??????????????
It wont read the option_str += inside the second database query!
aaargg
Code above is updated with the fix.
From your question:
Problem fixed
old code:
option_str += "<option value=" + r2['categories_id'] + ">" + r2['categories_name'] + "</option>";
console.log('categoriesname='+ r2['categories_name']);
}
});
count++;
}
$("#parent_id").html(option_str).selectmenu('refresh', true);//Moved below closing tag of count++
});
});
}

Flex: Getting feedback from URLLoader after sending information to a coldfusion file

I have a scheduling application that allows users to save any changes. When the user clicks the save button, Flex sends all the information to a coldfusion script which picks the information apart and sends saves it to the database. That all works well and good, but I would like to be able to display some sort of text to the user saying something like "Your file was successfully saved" or "There has been an error. Please contact the administrator".
My AS function is as follows:
import flash.net.URLLoader;
import flash.net.URLRequest;
private function save():void
{
var tempString:String = new String;
// Set up a URL request, loader, and variables
var progressOutURL:URLRequest = new URLRequest("saveSchedule.cfm");
var progressOutLoader:URLLoader = new URLLoader();
var progressOutVars:URLVariables = new URLVariables(); // Set the variables to be sent out
for (var i:int = 0; i < wholeProject.length; i++)
{
tempString = new String;
tempString = wholeProject[i].projectTitle + "|" + wholeProject[i].workingTitle + "|" + wholeProject[i].startDate + "|";
for (var j:int = 0; j < wholeProject[i].thisBlock.length; j++)
{
tempString = tempString + wholeProject[i].thisBlock[j].startOffset + "," + wholeProject[i].thisBlock[j].numDays + "," + wholeProject[i].thisBlock[j].role + "," + wholeProject[i].thisBlock[j].sID + "," + wholeProject[i].thisBlock[j].isConflict + "," + wholeProject[i].thisBlock[j].positionType + ";";
}
progressOutVars["project" + i] = tempString;
}
progressOutURL.method = URLRequestMethod.POST;
progressOutURL.data = progressOutVars;
progressOutLoader.load (progressOutURL);
}
And my coldfusion file is as follows (right now it just saves a cfdump of the information so that I can be sure the data was sent):
<cfsavecontent variable="toOutput">
<cfdump var="#FORM#" />
</cfsavecontent>
<cffile action="write" file="#GetDirectoryFromPath(GetCurrentTemplatePath())#output.html" output="#toOutput#" />
Is there any way that the "progressOutLoader.load(progressOutURL);" returns a boolean or something saying whether or not the send was successful?
progressOutLoader.addEventListener(Event.COMPLETE,resultHandler);
public function resultHandler(event:Event):void {
Alert.show("Success");
}
Similarly handle other events too.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html
Why are you not using Flex HTTPService? instead of URLLoader

Dynamically change colour of KML polygon in Google Maps API v3

I'm using Google Maps v3 API to load a KML layer and want to be able to change the colour of the KML from its default blue without having to edit the KML file itself. Is this possible using JavaScript or some other means?
Unfortunately can't post a link, but it's pretty standard stuff.
var map = new google.maps.Map(document.getElementById("mymap"), { some options });
var regionLayer = new google.maps.KmlLayer("http://.../some.kml");
regionLayer.setMap(map);
From my understanding of the documentation, 'no', but it's not especially clear. I'm trying to do a similar thing (but update the colour of mouseover/mouseout).
The KML file is loaded by the Google servers, parsed and sent along to your javascript object to be applied to the map, so, by the time your javascript KMLLayer sees it, it's all sorted out.
You may be able to do something with Styles and styleUrl. This is supposed to allow you to set a number of different styles that can then be applied at runtime, however, I haven't got it working.
I have done this by creating a web service which reads in a KML file to a string, inserts a style section to the beginning of the KML string, and also a styleURL to each uniquely named placemark. It's fairly simple to amend the markup using a .net web service and write it back out to the server you have hosting the web service.
For example this uses a class which contains placemark IDs and a colour flag:
public string KMLStyler(string URL, string URLName, Data[] MyData)
{
try
{
ReadFile(URL);
string NewKML = ReadFile(URL);
string RedStyle = "<Style id=\"red\"><LineStyle><color>7F7F7F7F</color><width>2</width></LineStyle><PolyStyle><color>7F0000FF</color><fill>1</fill><outline>1</outline></PolyStyle></Style>";
string BlackStyle = "<Style id=\"black\"><LineStyle><color>7F7F7F7F</color><width>2</width></LineStyle><PolyStyle><color>7F7F7F7F</color><fill>1</fill><outline>1</outline></PolyStyle></Style>";
string GreenStyle = "<Style id=\"green\"><LineStyle><color>7F7F7F7F</color><width>2</width></LineStyle><PolyStyle><color>7F00FF00</color><fill>1</fill><outline>1</outline></PolyStyle></Style>";
string BlueStyle = "<Style id=\"blue\"><LineStyle><color>7F7F7F7F</color><width>2</width></LineStyle><PolyStyle><color>7F7F7F7F</color><fill>1</fill><outline>1</outline></PolyStyle></Style>";
//add styles to top
int EndID = 0;
EndID = NewKML.IndexOf("</name>") + 7;
NewKML = NewKML.Insert(EndID, RedStyle);
EndID = NewKML.IndexOf("</name>") + 7;
NewKML = NewKML.Insert(EndID, BlackStyle);
EndID = NewKML.IndexOf("</name>") + 7;
NewKML = NewKML.Insert(EndID, GreenStyle);
EndID = NewKML.IndexOf("</name>") + 7;
NewKML = NewKML.Insert(EndID, BlueStyle);
//add each style to each placemark
foreach (Data MyDataSingle in MyData)
{
int NamePos = NewKML.IndexOf(MyDataSingle.Name);
if (NamePos == -1) throw new Exception("Did not find '" + MyDataSingle.Name + "' within File");
NamePos += MyDataSingle.Name.Length + 7;
int MultiGeometryStartPos = NewKML.IndexOf("<MultiGeometry>", NamePos);
int MultiGeometryEndPos = NewKML.IndexOf("</MultiGeometry>", NamePos);
int PolygonStartPos = NewKML.IndexOf("<Polygon>", NamePos);
int InsertPos = 0;
if (MultiGeometryStartPos < PolygonStartPos)
{
if (MultiGeometryStartPos != -1)
{
InsertPos = MultiGeometryStartPos;
}
else
{
InsertPos = PolygonStartPos;
}
}
else
{
InsertPos = PolygonStartPos;
}
if (MyDataSingle.Red)
{
NewKML = NewKML.Insert(InsertPos, "<styleUrl>#red</styleUrl>");
}
if (MyDataSingle.Black)
{
NewKML = NewKML.Insert(InsertPos, "<styleUrl>#black</styleUrl>");
}
if (MyDataSingle.Green)
{
NewKML = NewKML.Insert(InsertPos, "<styleUrl>#green</styleUrl>");
}
if (MyDataSingle.Blue)
{
NewKML = NewKML.Insert(InsertPos, "<styleUrl>#blue</styleUrl>");
}
}
string NewFileName = WriteFile(NewKML, URLName);
return NewFileName;
}
catch (Exception ex)
{
return ex.ToString();
}
}
public string WriteFile(string KMLData, string URLName)
{
string FileName = "http:\\blah.co.uk\blah.kml";
StreamWriter writer = new StreamWriter("C:/inetpub/blah.kml");
writer.Write(KMLData);
writer.Flush();
writer.Close();
return FileName;
}
public string ReadFile(string URL)
{
string File = "";
StreamReader reader = new StreamReader(WebRequest.Create(URL).GetResponse().GetResponseStream());
string line;
while ((line = reader.ReadLine()) != null)
{
File += line;
}
return File;
}

Resources