0

I really don't understand how to Update the content of a grid.

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!!!!!!

3 Replies
  • QUOTE (Alvaro @ May 5 2010, 03:56 AM) <{POST_SNAPBACK}>
    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.

    CODE
    // 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);
    },

    Hi Alvaro,
    A couple of things to try.

    First, don't use currentProfileData off the platform object, just call it as a global object.
    CODE
    var contacts = currentProfileData.get("contactList"));

    Second, information is stored in the global currentProfileData object as a string, so you must stringify it when setting it and parse it when getting it. Use the JSON object to do that. This post should get you started.

    - Ben
    0
  • QUOTE (Benjamin Toll @ May 7 2010, 01:34 PM) <{POST_SNAPBACK}>
    Hi Alvaro,
    A couple of things to try.

    First, don't use currentProfileData off the platform object, just call it as a global object.
    CODE
    var contacts = currentProfileData.get("contactList"));

    Second, information is stored in the global currentProfileData object as a string, so you must stringify it when setting it and parse it when getting it. Use the JSON object to do that. This post should get you started.

    - Ben


    Thank you very much, Ben. I did it!!!
    However, I have checked that, when changing the profile, if I enter into my widget, the data has not changed, and as a result, Im getting the same contacts for every profile, which is completely undesirable...

    My update view is the following

    CODEBOX
    updateView: function (){
    this.parent();
    var contacts=[];
    var myNames=[];
    var myPhones=[];
    var newName = KONtx.messages.fetch('contactName');
    var newPhone = KONtx.messages.fetch('contactPhone');


    if(newName!=null){
    names.push(newName);
    }

    if(newPhone!=null){
    phones.push(newPhone);
    }
    if(nombres[nombres.length-1]==''){
    nombres.splice(nombres.length-1,1);
    telefonos.splice(nombres.length-1,1);
    }
    KONtx.messages.remove('contacName');
    KONtx.messages.remove('contactPhone');
    for (var j=0;j<names.length;j++){
    contacts[j]={contact_name: names[j], contact_phone: phones[j] };
    }
    currentProfileData.set('listOfContacts',JSON.stringify(contacts));

    var list_of_contacts = JSON.parse(currentProfileData.get('listaOfContacts'));
    for(var i=0;i<list_of_contacts.length;i++){
    if(list_of_contacts[i].contact_name!=myNames[i]) {
    myNames.push(list_of_contacts[i].contact_name);
    myPhones.push(list_of_contacts[i].contact_phone);
    }
    }


    this.cache.imgData = id.slice(0,myNames.length).map(function(src,i) {
    return {
    name: myNames[i],
    label:myNames[i],
    phone: myPhones[i],

    }
    });

    this.controls.grid.changeDataset(this.cache.imgData);
    },


    Any idea about what I am doing wrong???

    Thank you very much!!!!!
    0
  • QUOTE (Alvaro @ May 11 2010, 10:47 AM) <{POST_SNAPBACK}>
    Thank you very much, Ben. I did it!!!
    However, I have checked that, when changing the profile, if I enter into my widget, the data has not changed, and as a result, Im getting the same contacts for every profile, which is completely undesirable...

    My update view is the following

    CODE
    updateView: function (){
    this.parent();
    var contacts=[];
    var myNames=[];
    var myPhones=[];
    var newName = KONtx.messages.fetch('contactName');
    var newPhone = KONtx.messages.fetch('contactPhone');


    if(newName!=null){
    names.push(newName);
    }

    if(newPhone!=null){
    phones.push(newPhone);
    }
    if(names[names.length-1]==''){
    names.splice(names.length-1,1);
    phones.splice(phones.length-1,1);
    }
    KONtx.messages.remove('contactName');
    KONtx.messages.remove('contactPhone');
    for (var j=0;j<names.length;j++){
    contacts[j]={contact_name: names[j], contact_phone: phones[j] };
    }
    currentProfileData.set('listOfContacts',JSON.stringify(contacts));

    var list_of_contacts = JSON.parse(currentProfileData.get('listOfContacts'));
    for(var i=0;i<list_of_contacts.length;i++){
    if(list_of_contacts[i].contact_name!=myNames[i]) {
    myNames.push(list_of_contacts[i].contact_name);
    myPhones.push(list_of_contacts[i].contact_phone);
    }
    }


    this.cache.imgData = id.slice(0,myNames.length).map(function(src,i) {
    return {
    name: myNames[i],
    label:myNames[i],
    phone: myPhones[i],

    }
    });

    this.controls.grid.changeDataset(this.cache.imgData);
    },


    Any idea about what I am doing wrong???

    Thank you very much!!!!!


    Btw, Ignore the mistakes in spelling, they were a result of translating my code into english...
    0

Recent Posts

in Getting Started / Beginners - Yahoo! TV Widgets