Created
November 7, 2012 01:10
-
-
Save ricardoalcocer/4028889 to your computer and use it in GitHub Desktop.
Puerto Rico Elections 2012 - Quick and Dirty Titanium App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Based on Alloy | |
============================== | |
index.js | |
============================== | |
var h=require('http').HTTP; | |
var http=new h(); | |
http.get('http://div1.ceepur.org/REYDI_NocheDelEvento/data/GOBERNADOR_ISLA.xml',function(data){ | |
try{ | |
var doc=Ti.XML.parseString(data); | |
var options = doc.getElementsByTagName("option"); | |
var tv=$.tv; | |
var tvdata=[]; | |
for(var i=0;i<options.length;i++){ | |
var name=options.item(i).getElementsByTagName("es").item(0).text; | |
var votes=options.item(i).getElementsByTagName("votes").item(0).text; | |
//Ti.API.info(name + ':' + votes); | |
tvdata.push({title:name + ':' + votes}) | |
} | |
tv.data=tvdata; | |
}catch(e){ | |
alert(e); | |
} | |
}) | |
$.index.open(); | |
index.xml | |
============================== | |
<Alloy> | |
<Window class="container"> | |
<TableView id="tv"> | |
</TableView> | |
</Window> | |
</Alloy> | |
index.tss | |
============================== | |
".container": { | |
backgroundColor:"white", | |
layout: 'vertical' | |
}, | |
"Label": { | |
width: Ti.UI.SIZE, | |
height: "50dp", | |
color: "#000" | |
}, | |
"mainview":{ | |
layout: 'vertical', | |
top:0, | |
height: 'auto', | |
width: 'auto' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http=function(){ | |
this.xhr=Titanium.Network.createHTTPClient(); | |
} | |
http.prototype.get=function(url,callback){ | |
try { | |
this.xhr.onload = function(){ | |
//alert(this.responseStatus); | |
htmlData = this.responseText; | |
callback(htmlData); | |
}; | |
this.xhr.onerror = function(e){ | |
htmlData = 'ERROR'; | |
callback(htmlData); | |
}; | |
this.xhr.setRequestHeader('Content-Type', 'text/plain; charset=utf-8'); | |
this.xhr.open("GET", url, false); | |
this.xhr.send(); | |
} catch(err){ | |
Titanium.UI.createAlertDialog({ | |
title : "Error", | |
message : String(err), | |
buttonNames : ['OK'] | |
}).show(); | |
} | |
} | |
http.prototype.post=function(url,payload,callback){ | |
try { | |
this.xhr.onload = function(){ | |
htmlSource=this.responseText; | |
callback(htmlSource); | |
}; | |
this.xhr.onerror = function(e){ | |
htmlData = 'ERROR'; | |
callback(htmlData); | |
}; | |
this.xhr.open("POST",url,false); | |
this.xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); | |
this.xhr.send(payload); | |
}catch(err){ | |
Titanium.UI.createAlertDialog({ | |
title : "Error", | |
message : String(err), | |
buttonNames : ['OK'] | |
}).show(); | |
} | |
} | |
http.prototype.getData=function(url,callback){ | |
try{ | |
this.xhr.onload = function(){ | |
//alert(this.responseStatus); | |
htmlData = this.responseText; | |
callback(htmlData); | |
}; | |
this.xhr.onerror = function(e){ | |
htmlData = 'ERROR'; | |
callback(htmlData); | |
}; | |
this.xhr.open("GET", url, false); | |
this.xhr.send(); | |
}catch(err){ | |
Titanium.UI.createAlertDialog({ | |
title : "Error", | |
message : String(err), | |
buttonNames : ['OK'] | |
}).show(); | |
} | |
} | |
exports.HTTP=http |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment