I have an important problem. I have implemented a grid so that in the moment I hit "Enter", a Dialog is displayed and gives me the possibility of deleting a row of the grid. It works in the simulator of the computer, but it doesn't work in the TV (a Samsung 1.2).
CODEBOX
createView: function() {
var __baseID = (this.id||this.ClassName||this._ktxID+'.ImageGrid');
this.controls = {};
this.controls.disabledButton = new KONtx.control.TextButton({
id: __baseID+'.disabledButton',
label: 'Contactos',
disabled: true,
styles: {
}
}).appendTo(this);
this.controls.pageindicator = new KONtx.control.PageIndicator({
id: __baseID+'.PageIndicator',
styles: {
height: 23,
vAlign: 'bottom',
vOffset: 296 + this.controls.disabledButton.height
}
}).appendTo(this);
this.controls.metadata = new KONtx.control.MetadataDisplay({
id: __baseID+'.Metadata',
styles: {
height: 23,
vAlign: 'bottom',
vOffset: 273 + this.controls.disabledButton.height
}
}).appendTo(this);
this.controls.grid = new KONtx.control.Grid({
id: __baseID+'.Grid',
rows: this.config.rows,
columns: this.config.columns,
styles: {
width: this.width,
height:listaHeight,
vOffset: this.controls.disabledButton.height
},
cellCreator: this.imageCellCreator,
cellUpdater: this.imageCellUpdater,
manageWaitIndicator: true
}).appendTo(this);
this.controls.addContactButton = new KONtx.control.TextButton({
label: 'Añadir Contacto',
textStyles: {
hAlign: 'center',
color: 'white',
fontSize: KONtx.utility.scale(16),
},
styles: {
width: this.width,
vOffset: this.controls.pageindicator.outerHeight + 10
},
events: {
onSelect: function(event) {
KONtx.application.loadView('view-addContact');
}
}
}).appendTo(this);
this.controls.addMisDatos = new KONtx.control.TextButton({
label: 'Mis datos',
textStyles: {
hAlign: 'center',
color: 'white',
fontSize: KONtx.utility.scale(16),
},
styles: {
width: this.width,
vOffset: this.controls.pageindicator.outerHeight + 40
},
events: {
onSelect: function(event) {
KONtx.application.loadView('view-MisDatos');
}
}
}).appendTo(this);
this.controls.grid.attachAccessories( this.controls.pageindicator, this.controls.metadata );
},
updateView: function (){
this.parent();
//var contactos=[];
var aux=[];
var misNombres=[];
var currentUser = profile.getCurrentProfile().name;
var usuarioNuevo='1';
var newName = KONtx.messages.fetch('NombreContacto');
var newPhone = KONtx.messages.fetch('TelefonoContacto');
misNombres.splice(0,misNombres.length);
try {
var usuarios=JSON.parse(currentAppConfig.get('usuarios'));
for (l=0;l<usuarios.length;l++){
misNombres[l]=push(usuarios[l].myName);
}
} catch(exception) {}
misNombres.push(currentUser);
for(var k=0;k<misNombres.length;k++){
if(misNombres[k].myName!=currentUser){
misNombres.splice(misNombres.length-1,1);
usuarioNuevo='0';
}
}
for (var k=0;k<misNombres.length;k++){
aux[k]={myName: misNombres[k]};
}
currentAppConfig.set('usuarios',JSON.stringify(aux));
nombres.splice(0,nombres.length);
telefonos.splice(0,telefonos.length);
if(usuarioNuevo=='0') {
try{
var lista_de_contactos = JSON.parse(currentProfileData.get('listaContactos'));
for(var i=0;i<lista_de_contactos.length;i++){
if(lista_de_contactos[i].nombre_contacto!=nombres[i]) {
nombres.push(lista_de_contactos[i].nombre_contacto);
telefonos.push(lista_de_contactos[i].telefono_contacto);
}
}
} catch (exception){}
}
if(newName!=null){
nombres.push(newName);
}
if(newPhone!=null){
telefonos.push(newPhone);
}
if(nombres[nombres.length-1]==''){
nombres.splice(nombres.length-1,1);
telefonos.splice(telefonos.length-1,1);
}
KONtx.messages.remove('NombreContacto');
KONtx.messages.remove('TelefonoContacto');
for (var j=0;j<nombres.length;j++){
contactos[j]={nombre_contacto: nombres[j], telefono_contacto:telefonos[j]};
}
currentProfileData.set('listaContactos',JSON.stringify(contactos));
contactos.splice(0,contactos.length);
this.cache.imgData = id.slice(0,nombres.length).map(function(src,i) {
return {
nombre: nombres[i],
label: nombres[i],
telefono: telefonos[i],
}
});
this.controls.grid.changeDataset(this.cache.imgData);
},
// Se crea la Cell
imageCellCreator: function () {
var cell = new KONtx.control.GridCell({
styles: {
},
events: {
onSelect: function (event){
celda=this;
new KONtx.dialogs.Alert({
title: "Borrar contacto",
message: "¿Está seguro de eliminar el contacto?",
buttons: [{label: "Ok", callback: function() {
nombres.splice(celda.getCellDataIndex(),1);
telefonos.splice(celda.getCellDataIndex(),1);
for (var j=0;j<nombres.length;j++){
contactos[j]={nombre_contacto: nombres[j], telefono_contacto:telefonos[j]};
}
currentProfileData.set('listaContactos',JSON.stringify(contactos));
KONtx.application.reloadView();
}},
{label: "Cancel", callback: function(){} }],
}).show();
}
}
});
cell.nombre = new KONtx.element.Text({
styles: {
label: 'Nombre',
color: 'white',
fontSize: '16px',
hOffset: 10,
width: this.width/2,
//vOffset: 11,
vAlign: 'center',
}
}).appendTo(cell);
cell.telefono = new KONtx.element.Text({
styles: {
label: 'Telefono',
color: 'white',
fontSize: '16px',
hOffset: this.width/2,
//vOffset: 30,
width: this.width/2 - 10,
vAlign: 'center',
textAlign: 'right',
},
}).appendTo(cell);
return cell;
},
imageCellUpdater: function (cell, dataitem) {
cell.nombre.data=dataitem.nombre;
cell.telefono.data = dataitem.telefono;
if ((cell.getCellDataIndex() % 2) == 1) {cell.setStyle('backgroundColor', '#38610B');}
else {cell.setStyle('backgroundColor','#088A08');}
},