]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | Ext.define('TouchTomatoes.view.MoviesListView', {\r |
2 | extend: 'Ext.Container',\r | |
3 | xtype: 'movieslistview',\r | |
4 | requires: [\r | |
5 | 'Ext.dataview.DataView',\r | |
6 | 'Ext.dataview.List',\r | |
7 | 'TouchTomatoes.proxy.RottenTomatoes', 'TouchTomatoes.model.Movie'],\r | |
8 | config: {\r | |
9 | layout: "vbox",\r | |
10 | title: null,\r | |
11 | header: {\r | |
12 | iconCls: "fa fa-bars",\r | |
13 | ui: "plain",\r | |
14 | docked: "left"\r | |
15 | },\r | |
16 | menu: null,\r | |
17 | enablePaging: false,\r | |
18 | autoLoad: false,\r | |
19 | proxy: {}\r | |
20 | },\r | |
21 | _headerBar: null,\r | |
22 | _list: null,\r | |
23 | _store: null,\r | |
24 | _itemTemplate: null,\r | |
25 | \r | |
26 | initialize: function() {\r | |
27 | this.create();\r | |
28 | },\r | |
29 | \r | |
30 | create: function() {\r | |
31 | this.removeAll(false);\r | |
32 | this.add(this.getHeaderBar());\r | |
33 | this.add(this.getList());\r | |
34 | \r | |
35 | this.down("list").getStore().load();\r | |
36 | },\r | |
37 | \r | |
38 | \r | |
39 | getHeaderBar: function() {\r | |
40 | if (!this._headerBar) {\r | |
41 | this._headerBar = Ext.create("Ext.Toolbar", {\r | |
42 | xtype: "toolbar",\r | |
43 | layout: {\r | |
44 | type: 'hbox',\r | |
45 | pack: 'center'\r | |
46 | },\r | |
47 | title: this.getTitle(),\r | |
48 | items: this.getHeader()\r | |
49 | });\r | |
50 | }\r | |
51 | return this._headerBar;\r | |
52 | },\r | |
53 | \r | |
54 | getList: function() {\r | |
55 | if (!this._list) {\r | |
56 | this._list = Ext.create("Ext.dataview.List", {\r | |
57 | flex: 1,\r | |
58 | emptyText: 'No movies found.',\r | |
59 | loadingText: "Loading Movies",\r | |
60 | cls: 'grid',\r | |
61 | plugins: this.getEnablePaging() ? {\r | |
62 | xclass: 'Ext.plugin.ListPaging',\r | |
63 | autoPaging: true\r | |
64 | } : null,\r | |
65 | mode: "simple",\r | |
66 | store: this.getStore(),\r | |
67 | itemTpl: this.getItemTemplate()\r | |
68 | });\r | |
69 | }\r | |
70 | return this._list;\r | |
71 | },\r | |
72 | \r | |
73 | getStore: function() {\r | |
74 | if (!this._store) {\r | |
75 | this._store = Ext.create("Ext.data.Store", {\r | |
76 | model: "TouchTomatoes.model.Movie",\r | |
77 | autoLoad: this.getAutoLoad() === true,\r | |
78 | remoteFilter: true,\r | |
79 | pageSize: 20,\r | |
80 | proxy: this.getProxy()\r | |
81 | });\r | |
82 | }\r | |
83 | return this._store;\r | |
84 | },\r | |
85 | \r | |
86 | getItemTemplate: function() {\r | |
87 | if (!this._itemTemplate) {\r | |
88 | this._itemTemplate = new Ext.XTemplate(\r | |
89 | '<div class="movie">',\r | |
90 | '<div class="title">{title}</div>',\r | |
91 | '<div class="img" style="background-image: url(\'{posters.detailed}\')"></div>',\r | |
92 | '<div class="ratings">',\r | |
93 | '<div class="user fa fa-user<tpl if=\"ratings.audience_score > 60\"> success</tpl><tpl if=\"ratings.audience_score < 0\"> unknown</tpl>"><tpl if=\"ratings.audience_score >= 0\">{ratings.audience_score}<tpl else> </tpl></div>',\r | |
94 | '<div class="spacer"></div>',\r | |
95 | '<div class="critics fa fa-pencil<tpl if=\"ratings.critics_score > 60\"> success</tpl><tpl if=\"ratings.critics_score < 0\"> unknown</tpl>"><tpl if=\"ratings.critics_score >= 0\">{ratings.critics_score}<tpl else> </tpl></div>',\r | |
96 | '</div>',\r | |
97 | '</div>'\r | |
98 | )\r | |
99 | }\r | |
100 | return this._itemTemplate;\r | |
101 | },\r | |
102 | \r | |
103 | applyProxy: function(config) {\r | |
104 | if (Ext.isSimpleObject(config)) {\r | |
105 | return Ext.factory(config, 'TouchTomatoes.proxy.RottenTomatoes')\r | |
106 | }\r | |
107 | return config;\r | |
108 | },\r | |
109 | \r | |
110 | updateProxy: function(value) {\r | |
111 | if (this._store) {\r | |
112 | this._store.setProxy(value);\r | |
113 | this._store.load();\r | |
114 | }\r | |
115 | },\r | |
116 | \r | |
117 | updateEnablePaging: function(currentValue, oldValue) {\r | |
118 | if (currentValue != oldValue && (currentValue != false && oldValue != undefined)) {\r | |
119 | this.create();\r | |
120 | this._store.load();\r | |
121 | }\r | |
122 | return currentValue;\r | |
123 | }\r | |
124 | });\r |