Last active
January 3, 2016 13:09
-
-
Save arturoleon/8467601 to your computer and use it in GitHub Desktop.
Ejemplo de módulos
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 tabGroup = Ti.UI.createTabGroup(); | |
var win1 = tabla(), | |
win2 = favoritos(); | |
var tab1 = Ti.UI.createTab({ | |
title: 'Lista', | |
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
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 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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment