0

Problem with CustomMetadataDisplay

Hi.

I am trying to have a custom KONtx.control.MetadataDisplay to show information about a grid cell. I have started by making a copy of the original "KONtx.control.MetadataDisplay" and just making this change cause the display not to work.

Is there anything tied to KONtx.control that I am missing and that would explain this ?

In the example below, changing the class is enough to make it work.


CODE
var CustomMetadataDisplay = new KONtx.Class({

ClassName: 'CustomMetadataDisplay',

Extends: KONtx.control.Button,

config: {
focus: false
},

initialize: function () {
// KONtx_automation_log("function","KONtx.control.MetadataDisplay","initialize");
this.parent();

var source = this.config.sourceElement || this.config.source;
if (source) this.attachToSource(source);

this.config.source = null;
delete this.config.source;
this.config.sourceElement = null;
delete this.config.sourceElement;
},

_createContent: function () {
// KONtx_automation_log("function","KONtx.control.MetadataDisplay","_createContent");
var tk = this.ClassName+'Text',
ts = Theme.getStyles(tk);

this.content = new KONtx.element.Text({
id: (this.config.id||this._ktxID)+'.content',
styles: this.config.textStyles || ts
}).appendTo(this);
},

attachToSource: function (source) {
// KONtx_automation_log("function","KONtx.control.MetadataDisplay","attachToSource");
if (source === this.source) return this.update();
this.source = source;
this._onSourceUpdated.subscribeTo(this.source, ['onStateUpdated','onFocus','onBlur'], this);
return this._updateContent();
},

_onSourceUpdated: function (event) {
// KONtx_automation_log("function","KONtx.control.MetadataDisplay","_onSourceUpdated");
switch (event.type) {
case 'onStateUpdated':
return this._updateContent(event.payload);
case 'onFocus':
this.fire('onFocus');
this.content.show();
break;
case 'onBlur':
this.fire('onBlur');
this.content.hide();
break;
}
},

getSourceStartIndex: function () {
// KONtx_automation_log("function","KONtx.control.MetadataDisplay","getSourceStartIndex");
return this.source && this.source.getStartIndex();
},

getSourceFocusIndex: function () {
// KONtx_automation_log("function","KONtx.control.MetadataDisplay","getSourceFocusIndex");
return this.source && this.source.getFocusIndex();
},

getSourceDataItem: function (index) {
// KONtx_automation_log("function","KONtx.control.MetadataDisplay","getSourceDataItem");
return this.source && this.source.getDataItem(index);
},

_updateContent: function (state) {
// KONtx_automation_log("function","KONtx.control.MetadataDisplay","_updateContent");
var start = state && parseInt(state.startIndex) > -1 ? state.startIndex : this.source.getStartIndex(),
focused = state && parseInt(state.focusIndex) > -1 ? state.focusIndex : this.source.getFocusIndex(),
dataindex = parseInt(start) > -1 && parseInt(focused) > -1 ? start + focused : false,
dataitem = dataindex !== false && this.getSourceDataItem( dataindex );

if (dataitem) {
var updater = this.config.updateMethod || this._updateMethod;
updater.call && updater.call(this, dataitem);
}
},

_updateMethod: function (dataitem) {
// KONtx_automation_log("function","KONtx.control.MetadataDisplay","_updateMethod");
var text = "";
switch (typeof dataitem) {
case 'string':
text = dataitem;
break;
case 'object':
var map = this.config.metadataMap;
if (map) {
var key = map.label || map.text;
text = dataitem[key];
} else if ('label' in dataitem) {
text = dataitem.label;
} else if ('text' in dataitem) {
text = dataitem.text;
}
break;
}
this.setText(text);
},

setText: function (text) {
// KONtx_automation_log("function","KONtx.control.MetadataDisplay","setText");
this.content.data = text || "";
}
});



var TestGridView2 = new KONtx.Class({
ClassName: 'TestGridView2',

Extends: KONtx.system.SidebarView,

config: {
rows: 4,
columns: 3,
},

createView: function (){

var __baseID = (this.id||this.ClassName||this._ktxID+'.ImageGrid');

this.controls = {};

this.controls.backbutton = new KONtx.control.BackButton({
id: __baseID+'.BackButton',
label: 'Back Grid Test'
}).appendTo(this);

//
// if this seems goofy, it's because we need to create the page
// indicator and metadata container first so we can measure their
// height and fit the grid in last.
//
this.controls.pageindicator = new KONtx.control.PageIndicator({
id: __baseID+'.PageIndicator',
styles: {
vAlign: 'bottom',
vOffset: this.height
}
}).appendTo(this);

//working this.controls.metadata = new KONtx.control.MetadataDisplay({
this.controls.metadata = new CustomMetadataDisplay({
id: __baseID+'.Metadata',
styles: {
height: KONtx.utility.scale(40),
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.backbutton.height -
this.controls.pageindicator.height -
this.controls.metadata.height,
vOffset: this.controls.backbutton.height
},
cellCreator: this.imageCellCreator,
cellUpdater: this.imageCellUpdater
}).appendTo(this);

//
// and now that everyone's created, let's introduce them to each other.
//
this.controls.grid.attachAccessories( this.controls.pageindicator, this.controls.metadata );
},

updateView: function (){
var arr = [];
for(var i = 0; i < 20; i++) {
arr.push({
label: "Test "+i,
description: "some description "+i,
imageSrc: "http://l.yimg.com/eur.yimg.com/i/fr/hp/yahoo1.png",
});
}
this.controls.grid.changeDataset(arr, true);
},

//
// cell create/update methods get fired in context of grid
//
imageCellCreator: function () {
return new KONtx.control.PhotoGridCell({
styles: this.getCellDimensions(),
events: {
// this onSelect fires in context of cell
onSelect: function (event){
//TODO : some code here...
}
}
});

},

imageCellUpdater: function (cell, dataitem) {
//TODO: use setSources to set missingSrc and loadingSrc
cell.setSource(dataitem.imageSrc);
},


});


Any ideas ?

Thanks in advance
Regards
Jean-Noel

by
9 Replies
  • I apologize, but I don't know where the question is here. Can you clarify what you are asking?

    Thanks!

    -Jeremy
    0
  • Hi Jeremy. Sorry for the unclear explainations.

    I have a grid with a MetadataDisplay but I would like to provide more than the "standard" MetadataDisplay. So, I figured I could make my own version but I could not get it to work. I narrowed down the problem to the following :

    If I just cut & paste the code from KONtx.control.MetadataDisplay and make it my class and change the code of my Grid to use this new class instead of the standard version, the metadata display does not appear below the Grid. If I just change the class used back to the original (KONtx.control.MetadataDisplay) in the init code of the Grid, then it works ! ;-)

    So I am wondering if I am missing anything that would explain it does not work.

    Any ideas ?

    Best regards
    Jean-Noel
    0
  • Ideally speaking, you should extend the existing class instead of copying and renaming. If you would like a sample of doing that, please let me know.

    -Jeremy
    0
  • Hi Jeremy and thanks for the quick answer.

    Actually, I am trying to a control that displays metadata of the Grid item, but that has lots of fields (as opposed to just one in the MetadataDisplay that has just one text). I have already customized the MetadataDisplay in some other sidebars (thanks to the various customization points :-) ).

    I could make a subclass and overload the "_createContent" to create a "Container" with various "Text"s and then change the "_updateMethod" to modify all of them, but as they are "_" prefixed, I figured I would create a separate class to suit my needs.

    It could be interesting maybe to have a "BaseMetadataDisplay" that would propose those methods ready to be overloaded and have the "standard" MetadataDisplay inherit from it. This way, my custom "metadata display" would inherit from the "BaseMetadataDisplay". I guess that would be useful to a lot of people showing stuff in Grids.

    What do you think ?

    Regards
    Jean-Noel
    0
  • All good points. Let me discuss this internally and see how sure we are on the "privateness" of those methods. Sometimes we are a bit overzealous about making methods private when in fact they are really supported publicly.

    -Jeremy
    0
  • Thanks :-)

    Jean-Noel
    0
  • QUOTE (jngadreau @ Jun 4 2009, 05:40 AM) <{POST_SNAPBACK}>
    Thanks :-)

    Jean-Noel


    Ok, the _createContent and corresponding update content methods are fairly stable. Do realize they are _ (aka private) for a reason, but theoretically speaking they should be relatively safe to override.

    -Jeremy
    0
  • Thanks Jeremy. I am going to implement my custom MetadataDisplay . I also found my initial problem. I was missing the theme configuration. If I add it as defined below, it works fine. Now, I have several ways to code this ;-)... And I understand a bit better how themes work ;-)

    CODE
    Theme.storage.add('CustomMetadataDisplay', {

    renderSkin: function (state,w,h,args,theme) {
    var ff = new Frame();
    ff.width = w;
    ff.height = h;

    theme.applyLayer('BaseObjectGlow', ff);

    theme.applyLayer('BaseGlossHighlight', ff);

    return ff;
    },

    styles: {
    '1920x1080': {
    normal: {
    color: 'white',
    backgroundColor: 'transparent',
    width: Theme.keys.sidebar.width,
    // height: 51
    },
    focused: {
    backgroundColor: Theme.colors.bgColorFocused
    }
    },
    '960x540': {
    normal: {
    color: 'white',
    backgroundColor: 'transparent',
    width: Theme.keys.sidebar.width,
    // height: 26
    },
    focused: {
    backgroundColor: Theme.colors.bgColorFocused
    }
    }
    }[ Theme.keys.screen ]
    });
    Theme.storage.add('CustomMetadataDisplayText', {
    styles: {
    '1920x1080': {
    width: 588 - 20,
    fontSize: 28,
    paddingRight: 10,
    paddingLeft: 10,
    textAlign: 'center',
    vAlign: 'center',
    hAlign: 'center',
    truncation: 'end'
    },
    '960x540': {
    width: 294 - 10,
    fontSize: 14,
    paddingRight: 5,
    paddingLeft: 5,
    textAlign: 'center',
    vAlign: 'center',
    hAlign: 'center',
    truncation: 'end'
    }
    }[ Theme.keys.screen ]
    });


    Best regards
    Jean-Noel
    0
  • May I have a sample? I'm trying to make a custom theme for a paginator so that it will fit inside the entire screen for fullscreen.


    QUOTE(Jeremy Johnstone @ 3 Jun 2009 5:52 AM)
    Ideally speaking, you should extend the existing class instead of copying and renaming. If you would like a sample of doing that, please let me know.

    -Jeremy
    0

Recent Posts

in General - Yahoo! TV Widgets