Exercise says so:
List the created notes; if none , the list will be empty . Show a button " add new note " to launch the window with the insertion form . Indicate the title and body text for each note. SQLite store notes . The table fields are: the note identifier , the title , body text and the date of the note. Modify the notes to select them in the list and that update the database. Indicate the background color of the note to be displayed in the list
I have this moment :
App.js
(function(e){
var tabGroup = Ti.UI.createTabGroup(); win_notas = Ti.UI.createWindow({ url:'./notas.js' });
var tab_notas = Ti.UI.createTab({ window:win_notas, title:'Block de notas' });
tabGroup.addTab(tab_notas);
tabGroup.open(); })();
Notas.js
//CUADERNO DE NOTAS function win(){ var win=Titanium.UI.currentWindow({ win.title='Mis Notas'; var tabla = Titanium.UI.createTableView({ backgroundColor:'#999', top:0, width:'100%',height:'88%' });
var button=Ti.UI.createButton({ title:'Añadir nueva nota', bottom:'1%', width:'90%', height:'10%', borderRadius:6,borderWidth:6, backgroundColor:'#336699', color:'#fff', font:{fontSize:16, fontWeight:'bold'} });
win.add(tabla); win.add(button);
/FUNCTIÓN THE BOTÓM/
button.addEventListener('click',function(e){ var form_win=Titanium.UI.createWindow({ title:'Crear nueva nota', width:'100%',height:'100%', backgroundColor:'#000', opacity:0.8 });
var view =Titanium.UI.createView({ width:'80%',height:'80%', backgroundColor:'#fff', borderRAdius:6, borderWidth:6, borderColor:'#666' });
var label =Titanium.UI.createLabel({ text:'Introduce tu nota', top:16, left:'6%', color:'#000', font:{fontSize:18} });
//TITEL var textarea=Titanium.UI.createTextArea({ widht:'10%', top:10, bottom:24 });
//BODY TEXT var textarea2=Titanium.UI.createTextArea({ widht:'92%', top:60, bottom:48 });
// add list of colors
var picker=Titanium.UI.createPicker();
var data = [];
data[0]=Ti.UI.createPickerRow({id:'0', title:'First row'}); data[1]=Ti.UI.createPickerRow({id:'1', title:'Second row'}); data[2]=Ti.UI.createPickerRow({id:'2', title:'Third row'});
picker.add(data);
picker.getSelectedRow(0).id;
//BOTÓM SAFE var guardar=Ti.UI.createButton({ title:'Guardar', width:160, height:32, bottom:16, color:'#fff', borderRadius:6, borderWidth:6, backgroundColor:'#336699' }); guardar.addEventListener('click',function(e){ guardarNota(textarea,form_win); var db = Ti.Database.open('cuaderno_bitacora'); var query = 'INSERT INTO notas (nota) VALUES(?,?)';
db.execute(query, textarea.value); var id_nota_current = db.lastInsertRowID; db.close();
}
guardar.addEventListener('click', function(e) { guardaNota(textarea, form_win); });
}); view.add(label); view.add(textarea); view.add(textarea2); view.add(guardar); form_win.add(view); form_win.open({'modal':true});
});
cargaNotas();
//ORDER LIST OF HOME
function cargaNotas(){ var db=Ti.Database.open('cuaderno de notas'); var query='SELECT * FROM notas ORDER BY fecha DESC'; var res=db.execute(query);
var filas=[]; while(res.isValidRow()){ var fecha_txt=res.fieldByName('fecha'); var nota_txt=res.fieldByName('nota');
var fecha_label=Ti.UI.createLabel({ text:fecha_txt, top:8, width:'90%', height:18, color:'#000' font:{fontWeight:'bold',fontSize:16} });
var nota_label=Ti.UI.createLabel({ text:nota_txt, top:24, width:'90%',height:64, color:'#333', font:{fontWeight:'normal',fontSize:18} });
var nota_view=Ti.UI.createView({ width:'100%',height:88 });
nota_view.add(fecha_label); nota_view.add(nota_label); var fila_tabla=Ti.UI.createTableViewRow({ selectedColor:'black', height:88 });
fila_tabla.add(nota_view); filas.push(fila_tabla); res.next(); } res.close(); db.close(); tabla.setData(filas);
}
DataBase.js
function cargaNotas(){
var db=Ti.Database.open('Cuaderno de notas'); var query = 'CREATE TABLE IF NOT EXISTS notas (id_nota INTEGER PRIMARY KEY AUTOINCREMENT, nota TEXT, fecha DATETIME DEFAULT CURRENT_TIMESTAMP, titulo TEXT,color COLOR);'; db.execute(query);
db.close();
thanks in advance