Hey,
I beg you some help. I am trying to create a grid followed by a button "Add Contact", which will bring me to an "AddContactView", consisting in 2 TextEntry buttons which create the contact, and store the values in currentProfileData (I want to have a list of contacts for each profile, available for some widgets). However, I really don't know how to refresh the grid in order to make the contacts appear... in fact, I really dont know how to do it...
I have read some threads of the forum regarding this item, but unfortunately, I have not understood them at all, so I really want to ask... how can I create a Grid ith the contacts I add from the AddContactView???? I attach the code I have written til the moment.
CODEBOX
var AgendaView = new KONtx.Class({
ClassName: 'AgendaView',
Extends: KONtx.system.SidebarView,
config: {rows: 5,
columns: 1
},
createView: function() {
var __baseID = 'Agenda';
this.controls = {};
this.controls.pageindicator = new KONtx.control.PageIndicator({
id: __baseID+'.PageIndicator',
styles: {
vAlign: 'bottom',
vOffset: this.height
}
}).appendTo(this);
this.controls.metadata = new KONtx.control.MetadataDisplay({
id: __baseID+'.Metadata',
styles: {
height: 23,
vAlign: 'bottom',
vOffset: this.height - this.controls.pageindicator.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: this.height -
this.controls.addContactButton.height -
this.controls.pageindicator.height -
this.controls.metadata.height,
},
cellCreator: this.imageCellCreator,
cellUpdater: this.imageCellUpdater,
manageWaitIndicator: true
}).appendTo(this);
this.controls.addContactButton = new KONtx.control.TextButton({
label: 'Add Contact',
styles: {
hAlign: 'center',
vOffset: this.controls.grid.outerHeight
},
events: {
onSelect: function(event) {
KONtx.application.loadView('view-addContact');
}
}
}).appendTo(this);
this.controls.grid.attachAccessories( this.controls.pageindicator, this.controls.metadata );
},
// I KNOW THIS IS WRONG, BUT I REALLY DONT KNOW WHAT TO INCLUDE IN HERE...
updateView: function (){
var contacts = platform.currentProfileData.get("contactList"));
log("CONTACTS ARRAY: " + contacts);
this.controls.grid.changeDataset(contacts);
},
imageCellCreator: function () {
var cell = new KONtx.control.GridCell({
styles: {
//bgColor: restaurantePatrocinado(this.getCellDataIndex())
bgColor: 'blue'
},
events: {
onSelect: function (event){
//KONtx.application.loadView("view-ContactDetailView",{
}
}
});
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: '12px',
hOffset: this.width/2,
//vOffset: 30,
width: this.width/2,
vAlign: 'center'
}
}).appendTo(cell);
return cell;
},
imageCellUpdater: function (cell, dataitem) {
cell.nombre.data = dataitem.nombre;
cell.telefono.data = dataitem.telefono;
},
});
and the AddContactView
CODEBOX
var AddContactView = new KONtx.Class({
ClassName: 'AddContactView',
Extends: KONtx.system.SidebarView,
createView: function() {
var numeroDeContactos=0;
var nameOfContact='';
var phoneOfContact='';
this.controls = {};
this.controls.backbutton = new KONtx.control.BackButton({
label: "Volver",
}).appendTo(this);
this.controls.nombreContacto = new KONtx.control.TextEntryButton({
guid: 'NombreContacto',
label: 'Nombre',
defaultValue: 'Nombre del nuevo contacto',
styles: {
vOffset: this.controls.backbutton.height
},
events: {
onSubmit: function(event) {
nameOfContact=event.payload.value;
//KONtx.messages.store(this.config.guid,event.payload.value);
log("value set!")
}
}
}).appendTo(this);
this.controls.telefonoContacto = new KONtx.control.TextEntryButton({
guid: 'TelefonoContacto',
label: 'Telefono',
defaultValue: 'Telefono del nuevo contacto',
styles: {
vOffset: this.controls.nombreContacto.vOffset + this.controls.nombreContacto.height
},
keyboard:{
layout: 'pinentry',
maxLength: 9
},
events: {
onSubmit: function(event) {
phoneOfContact=event.payload.value;
//KONtx.messages.store(this.config.guid,event.payload.value);
log("value set!")
}
}
}).appendTo(this);
this.controls.doneButton = new KONtx.control.TextButton({
label: 'Done',
styles: {
vOffset: this.controls.telefonoContacto.outerHeight + 30
},
events: {
onSelect: function() {
numeroDeContactos = numeroDeContactos + 1;
platform.currentProfileData.set("contactList",{nombre: nameOfContact, telefono: phoneOfContact});
KONtx.application.previousView();
}
}
}).appendTo(this);
//
this.controls.cancelButton = new KONtx.control.TextButton({
label: 'Cancel',
styles: {
vOffset: this.controls.doneButton.outerHeight
},
events: {
onSelect: function() {
KONtx.application.previousView();
}
}
}).appendTo(this);
},
});
Thank you very very much, I'm completely stuck!!!!!!