Created
January 29, 2014 01:31
-
-
Save arturoleon/8680024 to your computer and use it in GitHub Desktop.
Aplicación de ejemplo: Mapas
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
//http://j.mp/ejemplomodulos | |
(function(){ | |
var db = Titanium.Database.open('tabla'); | |
db.execute('CREATE TABLE IF NOT EXISTS favoritos (fila INTEGER)'); | |
var tabla = require('tabla'); | |
var favoritos = require('favoritos'); | |
var mapa = require('mapa'); | |
var tabGroup = Ti.UI.createTabGroup(); | |
var win1 = mapa(), | |
win2 = favoritos(); | |
var tab1 = Ti.UI.createTab({ | |
title: 'Mapa', | |
icon: '/images/KS_nav_ui.png', | |
window: win1 | |
}); | |
win1.containingTab = tab1; | |
var tab2 = Ti.UI.createTab({ | |
title: 'Favoritos', | |
icon: '/images/KS_nav_views.png', | |
window: win2 | |
}); | |
win2.containingTab = tab2; | |
tabGroup.addTab(tab1); | |
tabGroup.addTab(tab2); | |
tabGroup.open(); | |
})(); |
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
//http://pastebin.com/M3BkteFa | |
function detalle(id){ | |
var favorito = false; | |
var self = Ti.UI.createWindow({ | |
backgroundColor: 'white' | |
}); | |
var botonCerrar = Ti.UI.createButton({ | |
title: 'Cerrar', | |
top: 25, | |
right: 15 | |
}); | |
botonCerrar.addEventListener('click',function(){ | |
self.close(); | |
}); | |
self.add(botonCerrar); | |
var etiqueta = Ti.UI.createLabel({ | |
text: 'Detalle fila '+id, | |
top: 180 | |
}); | |
self.add(etiqueta); | |
var boton = Ti.UI.createButton({ | |
title: 'Agregar a favoritos' | |
}); | |
self.add(boton); | |
var db = Titanium.Database.open('tabla'); | |
var filas = db.execute('SELECT * FROM favoritos WHERE fila = ?',id); | |
if(filas.getRowCount()){ | |
boton.title = 'Quitar de favoritos'; | |
favorito=true; | |
} | |
boton.addEventListener('click',function(){ | |
if(favorito){ | |
db.execute('DELETE FROM favoritos WHERE fila = ?',id); | |
boton.title = 'Agregar a favoritos'; | |
favorito=false; | |
}else{ | |
db.execute('INSERT INTO favoritos ( fila ) VALUES (?)',id); | |
boton.title = 'Quitar de favoritos'; | |
favorito=true; | |
} | |
}); | |
return self; | |
} | |
module.exports = detalle; |
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
function favoritos(){ | |
var db = Titanium.Database.open('tabla'); | |
var ventana = Ti.UI.createWindow({ | |
title:'Favoritos' | |
}); | |
var tabla = Ti.UI.createTableView(); | |
var vistaDetalle = require('detalle'); | |
var actualizar = function(){ | |
tabla.setData([]); | |
var entradas = db.execute('SELECT * FROM favoritos;'); | |
while (entradas.isValidRow()) | |
{ | |
tabla.appendRow(Ti.UI.createTableViewRow({ | |
title: 'Fila '+entradas.fieldByName('fila'), | |
id: entradas.fieldByName('fila') | |
})); | |
entradas.next(); | |
} | |
entradas.close(); | |
}; | |
tabla.addEventListener('click',function(e){ | |
vistaDetalle(e.source.id).open(); | |
}); | |
ventana.add(tabla); | |
ventana.addEventListener('focus', function() | |
{ | |
actualizar(); | |
}); | |
return ventana; | |
} | |
module.exports = favoritos; |
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
function mapa(){ | |
var Map = require('ti.map'); | |
var ventana = Ti.UI.createWindow({ | |
title: 'Mapa' | |
}); | |
var datos = [ | |
{id: 0, latitud:'20.67359' ,longitud:'-103.343803'}, | |
{id: 1, latitud:'20.71939' ,longitud:'-103.391696'}, | |
{id: 2, latitud:'20.70948' ,longitud:'-103.405847'}, | |
{id: 3, latitud:'20.653606' ,longitud:'-103.388901'}, | |
{id: 4, latitud:'20.6471' ,longitud:'-103.405466'}, | |
]; | |
var mapa = Map.createView({mapType:Map.NORMAL_TYPE}); | |
for(var dato in datos){ | |
dato = datos[dato]; | |
var anotacion = Map.createAnnotation({ | |
latitude:dato.latitud, | |
longitude:dato.longitud, | |
title:"Anotacion ID "+dato.id, | |
pincolor:Map.ANNOTATION_RED, | |
myid:dato.id | |
}); | |
mapa.addAnnotation(anotacion); | |
} | |
ventana.add(mapa); | |
return ventana; | |
} | |
module.exports = mapa; |
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
function tabla(){ | |
var ventana = Ti.UI.createWindow({ | |
title:'Lista' | |
}); | |
var tabla = Ti.UI.createTableView(); | |
var vistaDetalle = require('detalle'); | |
for(var i=1;i<=10;i++){ | |
var fila = Ti.UI.createTableViewRow({ | |
title: 'Fila '+i, | |
id:i | |
}); | |
tabla.appendRow(fila); | |
} | |
tabla.addEventListener('click',function(e){ | |
vistaDetalle(e.source.id).open(); | |
}); | |
ventana.add(tabla); | |
return ventana; | |
} | |
module.exports = tabla; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment