13693261870
2022-09-16 354b3dbfbffb3df45212a2a44dbbf48b4acc2594
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Ext.define('FV.controller.Articles', {
    extend: 'Ext.app.Controller',
 
    stores: ['Articles'],
 
    models: ['Article'],
 
    views: ['article.Grid', 'article.Preview'],
 
    refs: [{
        ref: 'feedShow',
        selector: 'feedshow'
    }, {
        ref: 'viewer',
        selector: 'viewer'
    }, {
        ref: 'articlePreview',
        selector: 'articlepreview'
    }, {
        ref: 'articleTab',
        xtype: 'articlepreview',
        closable: true,
        forceCreate: true,
        selector: 'articlepreview'
    }],
 
    init: function() {
        this.control({
            'articlegrid': {
                selectionchange: this.previewArticle
            },
            'articlegrid > tableview': {
                itemdblclick: this.loadArticle,
                refresh: this.selectArticle
            },
            'articlegrid button[action=openall]': {
                click: this.openAllArticles
            },
            'articlepreview button[action=viewintab]': {
                click: this.viewArticle
            },
            'articlepreview button[action=gotopost]': {
                click: this.openArticle
            }
        });
    },
 
    selectArticle: function(view) {
        var first = this.getArticlesStore().getAt(0);
        if (first) {
            view.getSelectionModel().select(first);
        }
    },
 
    /**
     * Loads the given article into the preview panel
     * @param {FV.model.Article} article The article to load
     */
    previewArticle: function(grid, articles) {
        var article = articles[0],
            articlePreview = this.getArticlePreview();
 
        if (article) {
            articlePreview.article = article;
            articlePreview.update(article.data);
        }
    },
 
    openArticle: function(btn) {
        window.open(btn.up('articlepreview').article.get('link'));
    },
    
    openAllArticles: function() {
        this.loadArticles(this.getArticlesStore().getRange());
    },
 
    viewArticle: function(btn) {
        this.loadArticle(null, btn.up('articlepreview').article);
    },
    
    loadArticles: function(articles){
        var viewer = this.getViewer(),
            toAdd = [],
            id;
            
        Ext.Array.forEach(articles, function(article){
            id = article.id;
            if (!viewer.down('[articleId=' + id + ']')) {
                tab = this.getArticleTab();
                tab.down('button[action=viewintab]').destroy();
                tab.setTitle(article.get('title'));
                tab.article = article;
                tab.articleId = id;
                tab.update(article.data);
                toAdd.push(tab);
            }
        }, this);
        viewer.add(toAdd);
    },
 
    /**
     * Loads the given article into a new tab
     * @param {FV.model.Article} article The article to load into a new tab
     */
    loadArticle: function(view, article) {
        var viewer = this.getViewer(),
            title = article.get('title'),
            articleId = article.id;
            
        tab = viewer.down('[articleId=' + articleId + ']');
        if (!tab) {
            tab = this.getArticleTab();
            tab.down('button[action=viewintab]').destroy();
        }
 
        tab.setTitle(title);
        tab.article = article;
        tab.articleId = articleId;
        tab.update(article.data);
 
        viewer.add(tab);
        viewer.setActiveTab(tab);            
        
        return tab;
    }
});