Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / examples / app / nested-loading / app / view / review / List.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
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.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * A view which displays a list of reviews for a specified book.
17  * @extends Ext.view.View
18  */
19 Ext.define('Books.view.review.List', {
20     alias: 'widget.reviewlist',
21     extend: 'Ext.panel.Panel',
22
23     requires: ['Ext.layout.container.Card'],
24
25     initComponent: function() {
26         this.dataview = Ext.create('Ext.view.View', {
27             id: 'reviews',
28             border: false,
29             cls: 'review-list',
30
31             autoScroll: true,
32
33             store: 'Books.store.Review',
34             itemSelector: '.review',
35             tpl: new Ext.XTemplate(
36                 '<tpl for=".">',
37                     '<div class="review {[xindex === 1 ? "first-review" : ""]}">',
38                         '<div class="title">{title} {[this.stars(values)]}</div>',
39                         '<div class="author">By <span>{author}</span> - {date}</div>',
40                         '<div class="comment">{comment}</div>',
41                     '</div>',
42                 '</tpl>',
43                 {
44                     stars: function(values) {
45                         var res = "";
46
47                         //print out the stars for each of the ratings
48                         for (var i = 0; i < values.rating; i++) {
49                             res += '<img src="./resources/images/star.' + ((Ext.isIE6) ? 'gif' : 'png') + '" />';
50                         }
51
52                         //print out transparent stars for the rest (up to 5)
53                         while (i < 5) {
54                             res += '<img src="./resources/images/star_no.' + ((Ext.isIE6) ? 'gif' : 'png') + '" />';
55                             i++;
56                         }
57
58                         return res;
59                     }
60                 }
61             )
62         });
63
64         Ext.apply(this, {
65             border: false,
66             flex: 1,
67             id: 'test',
68
69             layout: 'card',
70
71             dockedItems: [
72                 Ext.create('Books.view.Header', {
73                     html: 'Reviews'
74                 })
75             ],
76
77             items: [
78                 this.dataview,
79                 Ext.create('widget.panel', {
80                     id: 'test2',
81                     html: 'asdasdsa'
82                 })
83             ]
84         });
85
86         this.callParent(arguments);
87     },
88
89     /**
90      * Used to bind a store to this dataview.
91      * Delegates to bindStore and also shows this view
92      * @param {Ext.data.Model} record The record to bind
93      * @param {Ext.data.Store} store The reviews store used by the application
94      */
95     bind: function(record, store) {
96         //put the reviews into the store and bind the store to thie dataview
97         store.loadData(record.data.reviews || []);
98         this.dataview.bindStore(store);
99     }
100 });
101