Skip to content

Instantly share code, notes, and snippets.

@pedrofaria
Created September 2, 2011 00:03
Show Gist options
  • Save pedrofaria/1187625 to your computer and use it in GitHub Desktop.
Save pedrofaria/1187625 to your computer and use it in GitHub Desktop.
awplus.plugin.News = Ext.extend(Ext.Panel, {
title: 'news',
id: 'p_news',
iconCls: 'bookmarks',
layout: 'card',
fullscreen: true,
animation: 'slide',
initComponent: function() {
Ext.regModel('News', {
fields: ['type', 'time', 'message']
});
var store = new Ext.data.Store({
autoLoad: true,
model: 'News',
sorters: 'time',
data: {data: {news: {}}},
proxy: {type: 'memory', reader: {type: 'json', root: 'data.news'}
}
});
var list = new Ext.List({
id: 'news-list',
itemTpl: [
'<tpl for=".">',
'<div class="awnews {type} <tpl if="isnew">new-new</tpl>">',
'<div class="new-date">{time}</div>',
'<div class="new-content">',
'<p>{message}</p>',
'</div>',
'</div>',
'</tpl>'
],
grouped: false,
indexBar: false,
store: store,
});
var toolbar = new Ext.Toolbar({
id: 'news-toolbar',
dock: 'top',
title: 'News',
});
this.dockedItems = [toolbar];
this.items = [list];
this.on('activate', function(card) {
if (card._news_already_done) return;
awplus.API('news', 'GET', null, function(data) {
var store = Ext.getCmp('news-list').getStore();
store.clearData();
var news = 0;
for (var i =0; i<data.data.news.length;i++) {
if (data.data.news[i].isnew == true) {
news++;
}
store.add(data.data.news[i]);
}
store.sync();
if (news > 0) {
awplus.controllers.viewport.tabBar.items.items[0].setBadge(''+news);
}
card._news_already_done = true;
});
});
awplus.plugin.News.superclass.initComponent.call(this);
},
_news_already_done: false,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment