multi-lang.js
5.98 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
Ext.Loader.setConfig({enabled: true});
Ext.Loader.setPath('Ext.ux', '../ux/');
Ext.require([
'Ext.data.*',
'Ext.tip.QuickTipManager',
'Ext.form.*',
'Ext.ux.data.PagingMemoryProxy',
'Ext.grid.Panel'
]);
Ext.onReady(function(){
MultiLangDemo = (function() {
// get the selected language code parameter from url (if exists)
var params = Ext.urlDecode(window.location.search.substring(1));
//Ext.form.Field.prototype.msgTarget = 'side';
return {
init: function() {
Ext.tip.QuickTipManager.init();
/* Language chooser combobox */
var store = Ext.create('Ext.data.ArrayStore', {
fields: ['code', 'language', 'charset'],
data : Ext.exampledata.languages // from languages.js
});
var combo = Ext.create('Ext.form.field.ComboBox', {
renderTo: 'languages',
store: store,
displayField:'language',
queryMode: 'local',
emptyText: 'Select a language...',
hideLabel: true,
listeners: {
select: {
fn: function(cb, records) {
var record = records[0];
window.location.search = Ext.urlEncode({"lang":record.get("code"),"charset":record.get("charset")});
},
scope: this
}
}
});
if (params.lang) {
// check if there's really a language with that language code
var record = store.findRecord('code', params.lang, null, null, null, true);
// if language was found in store assign it as current value in combobox
if (record) {
combo.setValue(record.data.language);
}
}
if (params.lang) {
var record = store.findRecord('code', params.lang, null, null, null, true),
url = Ext.util.Format.format("../../locale/ext-lang-{0}.js", params.lang);
Ext.Loader.injectScriptElement(
url,
this.onSuccess,
this.onFailure,
this,
params.charset);
} else {
this.setupDemo();
}
},
onSuccess: function() {
this.setupDemo();
},
onFailure: function() {
Ext.Msg.alert('Failure', 'Failed to load locale file.');
this.setupDemo();
},
setupDemo: function() {
// Grid needs to be this wide to handle the largest language case for the toolbar.
// In this case, it's Russian.
var width = 500;
/* Email field */
Ext.create('Ext.FormPanel', {
renderTo: 'emailfield',
labelWidth: 100, // label settings here cascade unless overridden
frame: true,
title: 'Email Field',
bodyStyle: 'padding:5px 5px 0',
width: width,
defaults: {
msgTarget: 'side',
width: width - 40
},
defaultType: 'textfield',
items: [{
fieldLabel: 'Email',
name: 'email',
vtype: 'email'
}]
});
/* Datepicker */
Ext.create('Ext.FormPanel', {
renderTo: 'datefield',
labelWidth: 100, // label settings here cascade unless overridden
frame: true,
title: 'Datepicker',
bodyStyle: 'padding:5px 5px 0',
width: width,
defaults: {
msgTarget: 'side',
width: width - 40
},
defaultType: 'datefield',
items: [{
fieldLabel: 'Date',
name: 'date'
}]
});
// shorthand alias
var monthArray = Ext.Array.map(Ext.Date.monthNames, function (e) { return [e]; });
var ds = Ext.create('Ext.data.Store', {
fields: ['month'],
remoteSort: true,
pageSize: 6,
proxy: {
type: 'pagingmemory',
data: monthArray,
reader: {
type: 'array'
}
}
});
Ext.create('Ext.grid.Panel', {
renderTo: 'grid',
width: width,
height: 203,
title:'Month Browser',
columns:[{
text: 'Month of the year',
dataIndex: 'month',
width: 240
}],
store: ds,
bbar: Ext.create('Ext.toolbar.Paging', {
pageSize: 6,
store: ds,
displayInfo: true
})
});
// trigger the data store load
ds.load();
}
};
})();
MultiLangDemo.init();
});