X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/2e847cf21b8ab9d15fa167b315ca5b2fa92638fc..3789b528d8dd8aad4558e38e22d775bcab1cbd36:/examples/key-feed-viewer/viewer/FeedPost.js diff --git a/examples/key-feed-viewer/viewer/FeedPost.js b/examples/key-feed-viewer/viewer/FeedPost.js new file mode 100644 index 00000000..ce80bc5a --- /dev/null +++ b/examples/key-feed-viewer/viewer/FeedPost.js @@ -0,0 +1,104 @@ +/** + * @class FeedViewer.FeedPost + * @extends Ext.panel.Panel + * + * Shows the detail of a feed post + * + * @constructor + * Create a new Feed Post + * @param {Object} config The config object + */ +Ext.define('FeedViewer.FeedPost', { + + extend: 'Ext.panel.Panel', + alias: 'widget.feedpost', + cls: 'preview', + autoScroll: true, + border: true, + + initComponent: function(){ + Ext.apply(this, { + dockedItems: [this.createToolbar()], + tpl: Ext.create('Ext.XTemplate', + '
', + '{pubDate:this.formatDate}', + '

{title}

', + '

by {author:this.defaultValue}

', + '
', + '
{content:this.getBody}
', + { + getBody: function(value, all){ + return Ext.util.Format.stripScripts(value); + }, + + defaultValue: function(v){ + return v ? v : 'Unknown'; + }, + + formatDate: function(value){ + if (!value) { + return ''; + } + return Ext.Date.format(value, 'M j, Y, g:i a'); + } + } + ) + }); + this.callParent(arguments); + }, + + /** + * Set the active post + * @param {Ext.data.Model} rec The record + */ + setActive: function(rec) { + this.active = rec; + this.update(rec.data); + }, + + /** + * Create the top toolbar + * @private + * @return {Ext.toolbar.Toolbar} toolbar + */ + createToolbar: function(){ + var items = [], + config = {}; + if (!this.inTab) { + items.push({ + scope: this, + handler: this.openTab, + text: 'View in new tab', + iconCls: 'tab-new' + }, '-'); + } + else { + config.cls = 'x-docked-noborder-top'; + } + items.push({ + scope: this, + handler: this.goToPost, + text: 'Go to post', + iconCls: 'post-go' + }); + config.items = items; + return Ext.create('widget.toolbar', config); + }, + + /** + * Navigate to the active post in a new window + * @private + */ + goToPost: function(){ + window.open(this.active.get('link')); + }, + + /** + * Open the post in a new tab + * @private + */ + openTab: function(){ + this.fireEvent('opentab', this, this.active); + } + +});