hi
I'm working on desarrolllo a survey where each question has different types of responses .... then I have a button at the end of the survey that saves all the results in a table.
I wanted to see if this well-written, if the code is well written and if you follow the good practice to not consume much memory when compiling.
Suggestions are welcomed, thanks
Working with these specifications:
titanium sdk 3.3.0 for android 4.1
This file is the window that contains all the elements.
//Developer Antonio Medel @2014 exports.create = function() { var win = Ti.UI.createWindow({ backgroundColor:'white', navBarHidden:true }); var welcome = Ti.UI.createLabel({ text:Ti.App.Properties.getString("branche"), left:0, top:0, width:'100%', backgroundColor:'#222', height:'30dp', color:'#FFF', textAlign:'center', font:{ fontSize:'20%', fontFamily:'Cicle_Semi' } }); win.add(welcome); var body = Ti.UI.createView({ width:'100%', top:'30dp', }); win.add(body); var guardar = Ti.UI.createLabel({ text:L('fin'), textAlign:'center', bottom:'10dp', font:{ fontSize:'25dp', fontFamily:'Cicle_Semi' }, color:'#FFF', width:'90%', height:'50dp', backgroundColor:'#333', borderRadius:5 }); body.add(guardar); var scrollView = Ti.UI.createScrollView({ contentHeight: 'auto', layout: 'vertical', width:'100%', top:0, bottom:'80dp', showVerticalScrollIndicator:true }); body.add(scrollView); var rows = require('addrow'); rows({ scrollView:scrollView, win:win }); guardar.addEventListener('click', function() { }); win.addEventListener('android:back', function(e) { }); return win; };This is the file that creates all rows with questions
module.exports = function(args) { //LLAMANDO AL MODULO DE LOS INPUTS var inputs = require('inputs'); var addRow = function(obj) { var view = Ti.UI.createView({ width:'100%', height:'100dp', top:0, left:0, id:obj.id, backgroundGradient: { type: 'linear', startPoint: { x: '0%', y: '0%' }, endPoint: { x: '0%', y: '100%' }, colors: [ { color: '#FFF', offset: 0.0}, { color: '#ddd', offset: 1.0 } ], } }); var boxCount = Ti.UI.createLabel({ touchEnabled:false, text:obj.id, backgroundColor:'#333', color:'#FFF', height:'20dp', width:'20dp', textAlign:'center', top:0, left:0, font:{ fontSize:'13dp' } }); var category = Ti.UI.createLabel({ touchEnabled:false, text:obj.categoria, top:'3dp', left:'30dp', color:'#333', font:{ fontSize:'15dp', fontFamily:'ubuntu' } }); var item = Ti.UI.createLabel({ touchEnabled:false, left:'30dp', top:'35dp', width:'80%', text:obj.item, color:'#333', font:{ fontSize:'15dp', fontFamily:'Cicle_Semi' } }); //ElEMENTOS INPUTS var container = Ti.UI.createTableView({ top:'100dp', headerTitle:'Respuestas Disponibles', separatorColor:'#ccc', backgroundColor:'white' }); inputs.create({ input:obj.inputs, container:container, valores:obj.valores, win:args.win }); view.add(boxCount); view.add(category); view.add(item); view.add(container); return view; }; //MOSTRAR REGISTROS var db = Ti.Database.open("elite.db","elite"), sqlInput = db.execute("SELECT T.* FROM cadena AS C INNER JOIN pregunta_cadena AS PC ON C.id = PC.id_cadena INNER JOIN TEMPLATE AS T ON T.id = PC.id_pregunta WHERE C.id = "+Ti.App.Properties.getString('id_cadena')+" order by T.orden"); section = []; i = 0; while(sqlInput.isValidRow()) { i++; var row = addRow({ categoria:sqlInput.fieldByName('categoria'), item:sqlInput.fieldByName('item'), inputs:sqlInput.fieldByName('input'), valores:sqlInput.fieldByName('valores'), id:i }); section.push(row); args.scrollView.add(row); sqlInput.next(); row = null; } sqlInput.close(); db.close(); //FINALIZAR SQL CON REGISTROS //var view = section.length; args.scrollView.addEventListener('click', function(e) { if(e.source.id) { if(e.source.height === '100dp') { e.source.height = Ti.UI.SIZE; }else { e.source.height = '100dp'; } } }); };This is the file that contains all types of inputs (textarea, picker, etc)
//MODULO PARA CREAR LOS DISTINTOS INPUTS DE CADA ITEM. exports.create = function(obj) { var input = obj.input, valoresInput = obj.valores, container = obj.container, upCamera = require('event/camera'); inpuRow = input.length; var addInput = function(args) { var fila = Ti.UI.createTableViewRow({ touchEnabled:false }); var select, foto, textarea; switch(args.type) { case 'select': select = Ti.UI.createPicker({ width:'90%', top:'5dp', bottom:'5dp' }); fila.add(select); var array = args.values.split(','); array.forEach(function(entry) { Ti.API.info(entry); var row = Ti.UI.createPickerRow({title:entry, color:'#333'}); select.add(row); row = null; }); break; case 'foto': foto = Ti.UI.createImageView({ left:'5%', top:'3dp', bottom:'3dp', image:'/images/cam.png', height:'40dp', width:'40dp' }); fila.add(foto); upCamera({ foto:foto, win:obj.win }); break; case 'textarea': textarea = Ti.UI.createTextArea({ width:'90%', height:'40dp', top:'5dp', hintText:'Comentario' }); fila.add(textarea); break; } return fila; }; var array = input.split(','), section = []; array.forEach(function(entry) { Ti.API.info(entry); var row = addInput({ type:entry, values:valoresInput }); section.push(row); row = null; }); container.setData(section); };