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