]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * This class is created to manage a template against a `ViewModel`. A binding of this\r | |
3 | * type uses `{@link Ext.app.bind.Template}` to process the template text so see that\r | |
4 | * class for details on template syntax.\r | |
5 | *\r | |
6 | * The bindings to provide the data needed by the template are managed here.\r | |
7 | */\r | |
8 | Ext.define('Ext.app.bind.TemplateBinding', {\r | |
9 | extend: 'Ext.app.bind.BaseBinding',\r | |
10 | \r | |
11 | requires: [\r | |
12 | 'Ext.app.bind.Multi',\r | |
13 | 'Ext.app.bind.Template'\r | |
14 | ],\r | |
15 | \r | |
16 | isTemplateBinding: true,\r | |
17 | \r | |
18 | lastValue: undefined,\r | |
19 | \r | |
20 | value: undefined,\r | |
21 | \r | |
22 | constructor: function (template, owner, callback, scope, options) {\r | |
23 | var me = this,\r | |
24 | tpl = new Ext.app.bind.Template(template),\r | |
25 | tokens = tpl.getTokens();\r | |
26 | \r | |
27 | me.callParent([ owner, callback, scope, options ]);\r | |
28 | \r | |
29 | me.tpl = tpl;\r | |
30 | me.tokens = tokens;\r | |
31 | tokens.$literal = true;\r | |
32 | \r | |
33 | // If we don't have any tokens, then we've just got a static string.\r | |
34 | if (tokens.length) {\r | |
35 | me.multiBinding = new Ext.app.bind.Multi(tokens, owner, me.onBindData, me);\r | |
36 | } else {\r | |
37 | me.isStatic = true;\r | |
38 | me.onData(tpl.text);\r | |
39 | }\r | |
40 | },\r | |
41 | \r | |
42 | destroy: function() {\r | |
43 | var me = this;\r | |
44 | Ext.destroy(me.multiBinding);\r | |
45 | me.tpl = me.multiBinding = null;\r | |
46 | me.callParent();\r | |
47 | },\r | |
48 | \r | |
49 | getFullName: function () {\r | |
50 | var multi = this.multiBinding;\r | |
51 | return this.fullName || (this.fullName = '$' + (multi ? multi.getFullName() : this.callParent()));\r | |
52 | },\r | |
53 | \r | |
54 | getRawValue: function () {\r | |
55 | return this.value;\r | |
56 | },\r | |
57 | \r | |
58 | getTemplateScope: function () {\r | |
59 | return null;\r | |
60 | },\r | |
61 | \r | |
62 | isDescendantOf: function () {\r | |
63 | return false;\r | |
64 | },\r | |
65 | \r | |
66 | isLoading: function () {\r | |
67 | var multi = this.multiBinding;\r | |
68 | return multi ? multi.isLoading() : false;\r | |
69 | },\r | |
70 | \r | |
71 | onBindData: function(data) {\r | |
72 | this.onData(this.tpl.apply(data, this.getTemplateScope()));\r | |
73 | },\r | |
74 | \r | |
75 | onData: function (value) {\r | |
76 | var me = this,\r | |
77 | lastValue = me.value;\r | |
78 | \r | |
79 | if (lastValue !== (me.value = value)) {\r | |
80 | me.lastValue = lastValue;\r | |
81 | me.schedule();\r | |
82 | }\r | |
83 | },\r | |
84 | \r | |
85 | react: function () {\r | |
86 | this.notify(this.value);\r | |
87 | },\r | |
88 | \r | |
89 | refresh: function () {\r | |
90 | var multi = this.multiBinding;\r | |
91 | if (multi) {\r | |
92 | multi.refresh();\r | |
93 | }\r | |
94 | },\r | |
95 | \r | |
96 | privates: {\r | |
97 | sort: function () {\r | |
98 | var multi = this.multiBinding;\r | |
99 | if (multi) {\r | |
100 | this.scheduler.sortItem(multi);\r | |
101 | }\r | |
102 | \r | |
103 | // Schedulable#sort === emptyFn\r | |
104 | //me.callParent();\r | |
105 | }\r | |
106 | }\r | |
107 | });\r |