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