maqetta/maqetta — Issue #1803: RoundRecDataList needs way to map feeds to ListItem labels
Author: billreed63
Created: 2012-02-22 21:06:31+00:00
State: open
Labels: Feature, Mobile, Priority Med, Widget Libraries

RoundRecDataList and EdgeToEdgeDataList can take a data store, through the use of dojo/io/script we can set up a data store to use a cross domain feed

For example if we used a feed like http://search.twitter.com/search.json?q=%40twitterapi this feed returns json that has the format:

````
{
"completed_in": 0.126,
"max_id": 172326837547040770,
"max_id_str": "172326837547040768",
"next_page": "?page=2&max_id=172326837547040768&q=%40twitterapi",
"page": 1,
"query": "%40twitterapi",
"refresh_url": "?since_id=172326837547040768&q=%40twitterapi",
"results": [
{
"created_at": "Wed, 22 Feb 2012 14:28:14 +0000",
"from_user": "iqbaloud",
"from_user_id": 181482740,
"from_user_id_str": "181482740",
"from_user_name": "M Iqbal Firdaus",
"geo": null,
"id": 172326837547040770,
"id_str": "172326837547040768",
"iso_language_code": "en",
"metadata": {
"result_type": "recent"
},
"profile_image_url": "http://a0.twimg.com/profile_images/1756407635/395629_2580162221520_1178354427_2272885_368746385_n_normal.jpg",
"profile_image_url_https": "https://si0.twimg.com/profile_images/1756407635/395629_2580162221520_1178354427_2272885_368746385_n_normal.jpg",
"source": "<a href="http://twitter.com/tweetbutton" rel="nofollow">Tweet Button</a>",
"text": "The BRIT Awards 2012 http://t.co/gHdllsPN via @twitterapi",
"to_user": null,
"to_user_id": null,
"to_user_id_str": null,
"to_user_name": null
}

],
"results_per_page": 15,
"since_id": 0,
"since_id_str": "0"
}
````

RoundRecDataList expects the json to have the format:

````
{
"items" : [
{ "label" : "Wi-Fi", "icon" : "sample_data/images/i-icon-1.png", "moveTo": "wifi" },
{ "label" : "Brightness & Wallpaper", "icon" : "sample_data/images/i-icon-2.png", "moveTo": "bright" },
{ "label" : "Picture Frame", "icon" : "sample_data/images/i-icon-3.png", "moveTo": "picture" },
{ "label" : "General", "icon" : "sample_data/images/i-icon-4.png", "moveTo": "general", "selected": "true" },
{ "label" : "Mail, Contacts, Calendars", "icon" : "sample_data/images/i-icon-5.png", "moveTo": "wifi" },
{ "label" : "Safari", "icon" : "sample_data/images/i-icon-6.png", "moveTo": "bright" },
{ "label" : "iPod", "icon" : "sample_data/images/i-icon-7.png", "moveTo": "picture" },
{ "label" : "Video", "icon" : "sample_data/images/i-icon-8.png", "moveTo": "general" },
{ "label" : "Photos", "icon" : "sample_data/images/i-icon-9.png", "moveTo": "wifi" },
{ "label" : "Store", "icon" : "sample_data/images/i-icon-10.png", "moveTo": "bright" }
]
}

````

If RoundRecDataList had a "mapping" attribute/feature where the developer could supply RoundRecDataList with a Mapping object that could be used when generating the list of items from the DataStore existing feeds could be used to populate the List

For example:

````

````
In the above example when the ListItem is created for addition to the RoundRecList the text attribute is used instead of the Label.

_DataListMixin.js
````
createListItem: function(/*Object*/item){
// summary:
//	Creates a list item widget.

var attr = {};
var arr = this.store.getLabelAttributes(item);
var labelAttr = arr ? arr[0] : null;
array.forEach(this.store.getAttributes(item), function(name){
if(name === labelAttr){
attr["label"] = this.store.getLabel(item);
}else{
var t = name;
if (this.itemMap[name]) {
t = this.itemMap[name];
}
attr[t /*name*/] = this.store.getValue(item, name);
}
}, this);
var w = new ListItem(attr);
item._widgetId = w.id;
return w;
},
````