X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/6a7e4474cba9d8be4b2ec445e10f1691f7277c50..refs/heads/master:/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..7d3f884b --- /dev/null +++ b/examples/key-feed-viewer/viewer/FeedPost.js @@ -0,0 +1,119 @@ +/* + +This file is part of Ext JS 4 + +Copyright (c) 2011 Sencha Inc + +Contact: http://www.sencha.com/contact + +GNU General Public License Usage +This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. + +If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact. + +*/ +/** + * @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); + } + +}); +