3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 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.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
15 Ext.define('FV.controller.Articles', {
16 extend: 'Ext.app.Controller',
22 views: ['article.Grid', 'article.Preview'],
31 ref: 'articlePreview',
32 selector: 'articlepreview'
35 xtype: 'articlepreview',
38 selector: 'articlepreview'
44 selectionchange: this.previewArticle
46 'articlegrid > tableview': {
47 itemdblclick: this.loadArticle,
48 refresh: this.selectArticle
50 'articlegrid button[action=openall]': {
51 click: this.openAllArticles
53 'articlepreview button[action=viewintab]': {
54 click: this.viewArticle
56 'articlepreview button[action=gotopost]': {
57 click: this.openArticle
62 selectArticle: function(view) {
63 var first = this.getArticlesStore().getAt(0);
65 view.getSelectionModel().select(first);
70 * Loads the given article into the preview panel
71 * @param {FV.model.Article} article The article to load
73 previewArticle: function(grid, articles) {
74 var article = articles[0],
75 articlePreview = this.getArticlePreview();
78 articlePreview.article = article;
79 articlePreview.update(article.data);
83 openArticle: function(btn) {
84 window.open(btn.up('articlepreview').article.get('link'));
87 openAllArticles: function() {
89 viewer = this.getViewer();
91 this.getArticlesStore().each(function(article) {
92 articles.push(this.loadArticle(null, article, true));
96 viewer.setActiveTab(articles[articles.length-1]);
99 viewArticle: function(btn) {
100 this.loadArticle(null, btn.up('articlepreview').article);
104 * Loads the given article into a new tab
105 * @param {FV.model.Article} article The article to load into a new tab
107 loadArticle: function(view, article, preventAdd) {
108 var viewer = this.getViewer(),
109 title = article.get('title'),
110 articleId = article.id;
112 tab = viewer.down('[articleId=' + articleId + ']');
114 tab = this.getArticleTab();
115 tab.down('button[action=viewintab]').destroy();
119 tab.article = article;
120 tab.articleId = articleId;
121 tab.update(article.data);
123 if (preventAdd !== true) {
125 viewer.setActiveTab(tab);