Pman.I18n.js
[Pman.Core] / Pman.I18n.js
1 //<script type="text/javascript">
2
3
4 /**
5 * A few usefull tools to convert language info...
6
7 * Our login details contain the available translation data..
8
9
10 * Languages are included in the main application
11 * using <script src="baseURL/Core/I18N/Data.js"></script>
12 * which set's up. Pman.I18n.data 
13
14
15
16 * includes standard pulldowns.
17 */
18
19 Pman.I18n = {
20     
21     /**
22      * turn zh_HK,en  => into Chinese(HK) , English
23      * @arg type type (c = country, l = lang)
24      * @arg codes list of languages
25      */
26     listToNames: function (type, codes)
27     {
28         var ret = [];
29         var _this = this;
30         var cl = codes.split(',');
31         Roo.each(cl , function(c) {
32             ret.push(_this.toName(type, c));
33         });
34         return ret.join(', ');
35     },
36     /**
37      * 
38      * turns zh_HK into a Chinese(HK)
39      * @arg type type (c = country, l = lang)
40      * @arg langcode language code (eg. zh_HK, UK etc.)
41      * 
42      */
43     toName: function(type, code) 
44     {
45         var ret = code;
46         Roo.each(Pman.Login.authUser.i18n[type], function(d) {
47             if (d.code == code) {
48                 ret = d.title;
49                 return false;
50             }
51         });
52         return ret;
53     },
54     /**
55      * List to Objects
56      * zh_HK,en to [ { code=zh_HK, title=Chinese }, .... ]
57      * @arg type type (c = country, l = lang)
58      * @arg codes list of languages
59      */
60     listToObjects: function (type, codes)
61     {
62         var ret = [];
63         var _this = this;
64         if (!codes.length) {
65             return ret;
66         };
67         var cl = codes.split(',');
68         Roo.each(cl , function(c) {
69             ret.push({
70                 code : c,
71                 title : _this.toName(type,c)
72             })
73         });
74         return ret;
75     },
76     
77     
78     
79     reader :   { // std. reader for i18n items.
80         root : 'data',
81         totalProperty : 'total',
82         id : 'code',
83         xtype : 'JsonReader',
84         fields : [
85             'code',
86             'title'
87         ]
88         },
89     
90     countryStore : function() { return {
91         
92         // load using HTTP
93         xtype: 'Store',
94         proxy: {
95             xtype: 'HttpProxy',
96             url: baseURL + '/I18N/Country.html',
97             method: 'GET'
98         },
99         
100         reader: Pman.I18n.reader,
101         listeners : {
102              
103             loadexception : Pman.loadException
104
105         },
106         remoteSort: false,
107         sortInfo: {
108             field: 'title', direction: 'ASC'
109         }
110               
111     }},
112     languageStore: function() {return{
113         // load using HTTP
114         xtype: 'Store',
115         proxy: {
116             xtype: 'HttpProxy',
117             url: baseURL + '/I18N/Lang.html',
118             method: 'GET'
119         },
120         
121         reader: Pman.I18n.reader,
122         listeners : {
123              
124             loadexception : Pman.loadException
125     
126         },
127         remoteSort: false,
128         sortInfo: {
129             field: 'title', direction: 'ASC'
130         }
131     }},
132     currencyStore: function() {return{
133         // load using HTTP
134         xtype: 'Store',
135         proxy: {
136             xtype: 'HttpProxy',
137             url: baseURL + '/I18N/Currency.html',
138             method: 'GET'
139         },
140         
141         reader: Pman.I18n.reader,
142         listeners : {
143              
144             loadexception : Pman.loadException
145     
146         },
147         remoteSort: false,
148         sortInfo: {
149             field: 'title', direction: 'ASC'
150         }
151     }},
152     
153     country: function(cfg) {
154         var _this = this;
155         cfg = cfg || {};
156         return Roo.apply({
157                 // things that might need chnaging
158                 name : 'country_title',
159                 hiddenName : 'country',
160                 width : 290,
161                 listWidth : 300,
162                 fieldLabel : "Country",
163                 allowBlank : false,
164                 
165                 // less likely
166                 qtip : "Select Country",
167                 
168                 value : '',
169                 // very unlinkly
170                 xtype : 'ComboBox',   
171                 store: this.countryStore(),
172                 displayField:'title',
173                 valueField : 'code',
174                 typeAhead: false,
175                 editable: false,
176                 //mode: 'local',
177                 triggerAction: 'all',
178                 //emptyText:'Select a state...',
179                 selectOnFocus:true 
180                  
181             }, cfg);
182     },
183     language: function(cfg) {
184                var _this = this;
185         cfg = cfg || {};
186         return Roo.apply({
187                 // things that might need chnaging
188                 
189                 name : 'language_title',
190                 hiddenName : 'language',
191                 width : 290,
192                 listWidth : 300,
193                 fieldLabel : "Language",
194                 allowBlank : false,
195                 
196                 // less likely
197                 qtip : "Select Language",
198                 
199                 value : '',
200                 // very unlinkly
201                 xtype : 'ComboBox',   
202                 store: this.languageStore(),
203                 displayField:'title',
204                 valueField : 'code',
205                 
206                 typeAhead: false,
207                 editable: false,
208                 //mode: 'local',
209                 triggerAction: 'all',
210                 //emptyText:'Select a state...',
211                 selectOnFocus:true 
212                 
213             }, cfg);
214     },
215        
216     currency: function(cfg) {
217         var _this = this;
218         cfg = cfg || {};
219         return Roo.apply({
220                 // things that might need chnaging
221                 name : 'currency_title',
222                 hiddenName : 'currency',
223                 width : 290,
224                 listWidth : 300,
225                 fieldLabel : "Currency",
226                 allowBlank : false,
227                 
228                 // less likely
229                 qtip : "Select Currency",
230                 
231                 value : '',
232                 // very unlinkly
233                 xtype : 'ComboBox',   
234                 store: this.currencyStore(),
235                 displayField:'code',
236                 valueField : 'code',
237                 typeAhead: false,
238                 editable: false,
239                 //mode: 'local',
240                 triggerAction: 'all',
241                 //emptyText:'Select a state...',
242                 selectOnFocus:true,
243                    tpl: new Ext.Template(
244                     '<div class="x-grid-cell-text x-btn button">',
245                         '{title} ({code})</b>',
246                     '</div>'
247                 ) 
248                  
249             }, cfg);
250     },
251     
252     languageList : function(cfg) {
253         cfg = cfg || {};
254          
255         return Roo.apply({
256                 
257                 name : 'language',
258                 //hiddenListName
259                 fieldLabel : "Language(s)",
260                 idField : 'code',
261                 nameField: 'title',
262                 renderer : function(d) {
263                     return String.format('{0}',  d.title );
264                 },
265                 
266                 
267                 xtype: 'ComboBoxLister',
268                 displayField:'title',
269                 value : '',
270                
271                 qtip : "Select a language to add.",
272                 selectOnFocus:true,
273                 allowBlank : true,
274                 width: 150,
275                 boxWidth: 300,
276                  
277                 store:  this.languageStore(),
278                
279                 editable: false,
280                 //typeAhead: true,
281                 forceSelection: true,
282                 //mode: 'local',
283                 triggerAction: 'all',
284                 tpl: new Ext.Template(
285                     '<div class="x-grid-cell-text x-btn button">',
286                         '{title}</b>',
287                     '</div>'
288                 ),
289                 queryParam: 'query[name]',
290                 loadingText: "Searching...",
291                 listWidth: 400,
292                
293                 minChars: 2,
294                // pageSize:20,
295                 setList : function(ar) {
296                     var _this = this;
297                     Roo.each(ar, function(a) {
298                         _this.addItem(a);
299                     });
300                 },
301                 toList : function() {
302                     var ret = [];
303                     this.items.each(function(a) {
304                         ret.push(a.data);
305                     });
306                     return ret;
307                 }
308                 
309                  
310             }, cfg);
311     },
312     countryList : function(cfg) {
313         cfg = cfg || {};
314          
315          
316         return Roo.apply({
317                 
318                 name : 'countries',
319                 fieldLabel : "Country(s)",
320                 idField : 'code',
321                 nameField: 'title',
322                 renderer : function(d) {
323                     return String.format('{0}',  d.title );
324                 },
325                 
326                 
327                 xtype: 'ComboBoxLister',
328                 displayField:'title',
329                 value : '',
330                
331                 qtip : "Select a country to add.",
332                 selectOnFocus:true,
333                 allowBlank : true,
334                 width: 150,
335                 boxWidth: 300,
336                  
337                 store:  this.countryStore(), 
338                
339                 editable: false,
340                 //typeAhead: true,
341                 forceSelection: true,
342                 //mode: 'local',
343                 triggerAction: 'all',
344                 tpl: new Ext.Template(
345                     '<div class="x-grid-cell-text x-btn button">',
346                         '{title}</b>',
347                     '</div>'
348                 ),
349                 queryParam: 'query[name]',
350                 loadingText: "Searching...",
351                 listWidth: 400,
352                
353                 minChars: 2,
354                // pageSize:20,
355                 setList : function(ar) {
356                     var _this = this;
357                     Roo.each(ar, function(a) {
358                         _this.addItem(a);
359                     });
360                 },
361                 toList : function() {
362                     var ret = [];
363                     this.items.each(function(a) {
364                         ret.push(a.data);
365                     });
366                     return ret;
367                 }
368                 
369                  
370             }, cfg);
371     }
372      
373      
374     
375 };
376
377