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
/**
 * A view which displays a list of reviews for a specified book.
 * @extends Ext.view.View
 */
Ext.define('Books.view.review.List', {
    alias: 'widget.reviewlist',
    extend: 'Ext.panel.Panel',
 
    requires: ['Ext.layout.container.Card'],
 
    initComponent: function() {
        this.dataview = Ext.create('Ext.view.View', {
            id: 'reviews',
            border: false,
            cls: 'review-list',
 
            autoScroll: true,
 
            itemSelector: '.review',
            tpl: new Ext.XTemplate(
                '<tpl for=".">',
                    '<div class="review {[xindex === 1 ? "first-review" : ""]}">',
                        '<div class="title">{title} {[this.stars(values)]}</div>',
                        '<div class="author">By <span>{author}</span> - {date}</div>',
                        '<div class="comment">{comment}</div>',
                    '</div>',
                '</tpl>',
                {
                    stars: function(values) {
                        var res = [],
                            extension = Ext.isIE6 ? 'gif' : 'png',
                            i = 0;
 
                        //print out the stars for each of the ratings
                        for (; i < values.rating; i++) {
                            res.push('<img src="./resources/images/star.', extension, '" />');
                        }
 
                        //print out transparent stars for the rest (up to 5)
                        while (i < 5) {
                            res.push('<img src="./resources/images/star_no.', extension, '" />');
                            i++;
                        }
 
                        return res.join('');
                    }
                }
            )
        });
 
        Ext.apply(this, {
            border: false,
            flex: 1,
            id: 'test',
 
            layout: 'card',
 
            dockedItems: [
                Ext.create('Books.view.Header', {
                    html: 'Reviews'
                })
            ],
 
            items: this.dataview
        });
 
        this.callParent(arguments);
    },
 
    /**
     * Used to bind a store to this dataview.
     * Delegates to bindStore and also shows this view
     * @param {Ext.data.Model} record The record to bind
     * @param {Ext.data.Store} store The reviews store used by the application
     */
    bind: function(record, store) {
        //put the reviews into the store and bind the store to thie dataview
        this.dataview.bindStore(record.reviews());
    }
});