Pman.Tab.AdminTranslations.bjs
[Pman.Admin] / Pman.Tab.AdminTranslations.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Pman.Tab.AdminTranslations = new Roo.XComponent({
6     part     :  ["Admin","Translations"],
7     order    : '950-Pman.Tab.AdminTranslations',
8     region   : 'center',
9     parent   : 'Pman.Tab.Admin',
10     name     : "Admin - Translations",
11     disabled : false, 
12     permname : 'Admin.Translations', 
13     _tree : function()
14     {
15         var _this = this;
16         var MODULE = this;
17         return {
18             xtype: 'NestedLayoutPanel',
19             xns: Roo,
20             region : 'center',
21             title : "Translate App",
22             layout : {
23                 xtype: 'BorderLayout',
24                 xns: Roo,
25                 items : [
26                     {
27                         xtype: 'GridPanel',
28                         xns: Roo,
29                         listeners : {
30                             activate : function() {
31                                 _this.panel = this;
32                                 if (_this.grid) {
33                                    _this.grid.getDataSource().reload(); 
34                                 }
35                             }
36                         },
37                         background : true,
38                         fitContainer : true,
39                         fitToframe : true,
40                         region : 'center',
41                         title : "Text in interface",
42                         grid : {
43                             xtype: 'EditorGrid',
44                             xns: Roo.grid,
45                             listeners : {
46                                 render : function() { 
47                                     _this.grid = this; 
48                                     //_this.dialog = Pman.Dialog.FILL_IN
49                                     if (_this.panel.active) {
50                                       _this.grid.getDataSource().reload(); 
51                                     }
52                                 },
53                                 beforeedit : function(e) {
54                                     console.log('beforeedit');
55                                     //if (e.record.get('origtxt').indexOf('<') > -1) {
56                                                        // console.log("HTML EDITOR!!");
57                                                      
58                                                     //    return false;
59                                                     //}
60                                                     if (e.record.get('txt').replace(/\s+/, '').length) {
61                                                         return true;
62                                                     }
63                                                     if (e.record.get('suggest').length) {
64                                                         e.record.set('txt', e.record.get('suggest'));
65                                                     //    _this.saveRec(e.record);
66                                                         return;
67                                                     }
68                                                     
69                                                     
70                                                     
71                                                    
72                                                     var tl = e.record.get('id').split('/')[0];
73                                                   
74                                                     tl = (tl == 'zh_HK') ? 'zh-TW' : tl; 
75                                                     tl = tl.replace('_', '-');
76                                                     var rec = e.record;
77                                                     
78                                                     
79                                                     
80                                                     Pman.gtranslate(e.record.get('origtxt'), 'en', tl, function(result) { 
81                                                         if (typeof(result) == 'object') { //error
82                                                             return; 
83                                                            }
84                                                         
85                                                         if (_this.grid.activeEditor) {
86                                                             _this.grid.activeEditor.setValue(result);
87                                                         } else {
88                                                             rec.set('txt',result);
89                                                             //_this.saveRec(rec);
90                                                         }
91                                 
92                                                         //
93                                                         
94                                                         
95                                                         //console.log(result.translation);
96                                                     });
97                                                     
98                                                    
99                                                     
100                                                     return true;
101                                                 },
102                                 afteredit : function (e)
103                                 {
104                                     var saveRec  = function(rec)
105                                     {
106                                         var g = _this.grid;
107                                 
108                                         //g.getView().el.mask('Saving');
109                                         Ext.Ajax.request({
110                                             url : baseURL + '/Admin/Translations.php',
111                                             method: 'POST',
112                                             params : {
113                                                 id : rec.get('id'),
114                                                 txt : rec.get('txt'),
115                                                 lang :  _this.langCombo.getValue(),
116                                                 module :  _this.modCombo.getValue()
117                                             },
118                                             success : function()
119                                             {
120                                                 //g.getView().el.unmask();
121                                                 //g.getDataSource().reload();
122                                             },
123                                             failure : function()
124                                             {
125                                                 Ext.Msg.alert("Error", "There was a problem saving the data - try reloading");
126                                                // g.getView().el.unmask();
127                                             }
128                                             
129                                     });
130                                         };
131                                     
132                                     saveRec.defer(1000, _this, [ e.record ]);
133                                 }
134                             },
135                             autoExpandColumn : 'txt',
136                             clicksToEdit : 1,
137                             loadMask : true,
138                             dataSource : {
139                                 xtype: 'Store',
140                                 xns: Roo.data,
141                                 listeners : {
142                                     beforeload : function (_self, opts)
143                                     {
144                                     
145                                                             if (!_this.langCombo || !_this.langCombo.getValue().length) {
146                                                                 return false;
147                                                             }
148                                                             if (!_this.modCombo || !_this.modCombo.getValue().length) {
149                                                                 return false;
150                                                             }
151                                                             opts.params = {
152                                                                 lang :  _this.langCombo.getValue(),
153                                                                 module :  _this.modCombo.getValue()
154                                                             };
155                                     },
156                                     loadexception : function (self, ret, load, jsonData)
157                                     {
158                                         Roo.MessageBox.alert("Error", jsonData);
159                                     }
160                                 },
161                                 reader : Pman.Readers.Category,
162                                 proxy : {
163                                     xtype: 'HttpProxy',
164                                     xns: Roo.data,
165                                     method : 'GET',
166                                     url : baseURL + '/Admin/Translations.php'
167                                 },
168                                 reader : {
169                                     xtype: 'JsonReader',
170                                     xns: Roo.data,
171                                     root : 'data',
172                                     totalProperty : 'total',
173                                     id : 'id',
174                                     fields : [                    'id',             'tablename',             'tableid',             'colname',             'txt',             'lang',             { name:'updated', type:'date', dateFormat: 'Y-m-d H:i:s' },             { name:'origupdated', type:'date', dateFormat: 'Y-m-d H:i:s' },             'origtxt',             'msum',             'suggest'                  ]
175                                 }
176                             },
177                             toolbar : {
178                                 xtype: 'Toolbar',
179                                 xns: Roo,
180                                 items : [
181                                     {
182                                         xtype: 'ComboBox',
183                                         xns: Roo.form,
184                                         listeners : {
185                                             render : function (_self)
186                                             {
187                                               _this.modCombo = _self;
188                                             },
189                                             select : function (combo, record, index)
190                                             {
191                                               _this.grid.getDataSource().reload(); 
192                                             }
193                                         },
194                                         valueField : 'module',
195                                         displayField : 'module',
196                                         width : 200,
197                                         typeAhead : false,
198                                         editable : false,
199                                         mode : 'local',
200                                         triggerAction : 'all',
201                                         emptyText : "Select Module",
202                                         selectOnFocus : true,
203                                         store : {
204                                             xtype: 'SimpleStore',
205                                             xns: Roo.data,
206                                             data : (function() {             
207                                                     var modlist = [];             
208                                                     AppModules = typeof(AppModules) == 'undefined' ? '' : AppModules;
209                                                     Roo.each( AppModules.split(','), function(mod) {            
210                                                              modlist.push( [ mod ] );            
211                                                   });             
212                                                   return modlist;
213                                                })(),
214                                             fields : ['module']
215                                         }
216                                     },
217                                     {
218                                         xtype: 'ComboBox',
219                                         xns: Roo.form,
220                                         listeners : {
221                                             select : function (combo, record, index)
222                                             {
223                                               _this.grid.getDataSource().reload(); 
224                                             },
225                                             render : function (_self)
226                                             {
227                                               _this.langCombo=_self;
228                                             }
229                                         },
230                                         valueField : 'lang',
231                                         displayField : 'ldisp',
232                                         width : 200,
233                                         typeAhead : false,
234                                         editable : false,
235                                         mode : 'local',
236                                         triggerAction : 'all',
237                                         emptyText : "Select Language",
238                                         selectOnFocus : true,
239                                         store : {
240                                             xtype: 'SimpleStore',
241                                             xns: Roo.data,
242                                             fields : ['lang', 'ldisp'],
243                                             data : [                                                [ 'zh_HK' , '\u7E41\u4E2D - Trad. Chin. (HK)' ],                         [ 'zh_CN', '\u7C21\u4E2D - Simp. Chin.' ]                     ]
244                                         }
245                                     }
246                                 ]
247                             },
248                             colModel : [
249                                 {
250                                     xtype: 'ColumnModel',
251                                     xns: Roo.grid,
252                                     header : 'Name',
253                                     width : 150,
254                                     dataIndex : 'colname',
255                                     renderer : function(v,x,r) {                         var c = '#666';                         if (r.get('updated') < r.get('origupdated')) {                             c = 'red';                         }                                                  return '<div style="color:'+c+'";>' +r.get('tableid')+ ':' + v + '</div>';                                              }
256                                 },
257                                 {
258                                     xtype: 'ColumnModel',
259                                     xns: Roo.grid,
260                                     header : 'Original',
261                                     width : 300,
262                                     dataIndex : 'origtxt',
263                                     renderer : function(v,x,r) {                         var c = '#666';                         if (r.get('updated') < r.get('origupdated')) {                             c = 'red';                         }                         return '<div style="color:' + c+ '">' +                                  Ext.util.Format.htmlEncode(v) + '</div>';                                              }
264                                 },
265                                 {
266                                     xtype: 'ColumnModel',
267                                     xns: Roo.grid,
268                                     dataIndex : 'reset_tx',
269                                     header : 'Reset',
270                                     width : 50,
271                                     renderer : function(v,x,r) {    
272                                         return '[x]';
273                                     }
274                                 },
275                                 {
276                                     xtype: 'ColumnModel',
277                                     xns: Roo.grid,
278                                     dataIndex : 'txt',
279                                     header : 'Translated (Click to Edit)',
280                                     width : 150,
281                                     renderer : function(v,x,r) {                                                   var c = '#666';                         if (r.get('updated') < r.get('origupdated')) {                             c = 'red';                         }                                                  return '<div style="color:' + c+ '">' + Ext.util.Format.htmlEncode(v) + '</div>';                     },
282                                     editor : {
283                                         xtype: 'GridEditor',
284                                         xns: Roo.grid,
285                                         field : {
286                                             xtype: 'TextField',
287                                             xns: Roo.form
288                                         }
289                                     }
290                                 }
291                             ]
292                         }
293                     },
294                     {
295                         xtype: 'GridPanel',
296                         xns: Roo,
297                         listeners : {
298                             activate : function() {
299                                 _this.langpanel = this;
300                                 if (_this.langgrid) {
301                                     _this.langgrid.ds.load({});
302                                 }
303                             }
304                         },
305                         background : true,
306                         fitContainer : true,
307                         fitToframe : true,
308                         region : 'center',
309                         tableName : 'i18n',
310                         title : "Languages and Countries",
311                         grid : {
312                             xtype: 'EditorGrid',
313                             xns: Roo.grid,
314                             listeners : {
315                                 render : function() 
316                                 {
317                                     _this.langgrid = this; 
318                                     //_this.dialog = Pman.Dialog.FILL_IN
319                                     if (_this.langpanel.active) {
320                                        this.ds.load({});
321                                     }
322                                 },
323                                 afteredit : function (e)
324                                 {
325                                     var saveRec  = function(rec)
326                                     {
327                                         var g = _this.grid;
328                                 
329                                         //g.getView().el.mask('Saving');
330                                         Ext.Ajax.request({
331                                             url : baseURL + '/Roo/I18n.php',
332                                             method: 'POST',
333                                             params : {
334                                                 id : rec.get('id'),
335                                                 lval : rec.get('lval')
336                                             },
337                                             success : function()
338                                             {
339                                                 //g.getView().el.unmask();
340                                                 //g.getDataSource().reload();
341                                             },
342                                             failure : function()
343                                             {
344                                                 Ext.Msg.alert("Error", "There was a problem saving the data - try reloading");
345                                                // g.getView().el.unmask();
346                                             }
347                                             
348                                     });
349                                         };
350                                     
351                                     saveRec.defer(1000, _this, [ e.record ]);
352                                 },
353                                 beforeedit : function(e) {
354                                     console.log('beforeedit');
355                                     //if (e.record.get('origtxt').indexOf('<') > -1) {
356                                                        // console.log("HTML EDITOR!!");
357                                              
358                                             //    return false;
359                                             //}
360                                             if (e.record.get('lval').replace(/\s+/, '').length) {
361                                                 return true;
362                                             }
363                                             
364                                             
365                                             var tl = _this.langgridCombo.getValue();
366                                           
367                                             tl = (tl == 'zh_HK') ? 'zh-TW' : tl; 
368                                             tl = tl.replace('_', '-');
369                                             var rec = e.record;
370                                             
371                                             
372                                             
373                                             Pman.gtranslate(e.record.get('lval_en'), 'en', tl, function(result) { 
374                                                 if (typeof(result) == 'object') { //error
375                                                     return; 
376                                                    }
377                                                 
378                                                 if (_this.grid.activeEditor) {
379                                                     _this.grid.activeEditor.setValue(result);
380                                                 } else {
381                                                     rec.set('lval',result);
382                                                     //_this.saveRec(rec);
383                                                 }
384                                 
385                                                 //
386                                                 
387                                                 
388                                                 //console.log(result.translation);
389                                             });
390                                             
391                                            
392                                             
393                                             return true;
394                                         }
395                             },
396                             autoExpandColumn : 'lval',
397                             clicksToEdit : 1,
398                             loadMask : true,
399                             dataSource : {
400                                 xtype: 'Store',
401                                 xns: Roo.data,
402                                 listeners : {
403                                     beforeload : function (_self, options)
404                                     {
405                                        options  =options ||  {};
406                                        options.params =options.params|| {};
407                                        options.params.ltype = _this.langtypeCombo.getValue();
408                                        options.params.inlang = _this.langgridCombo.getValue();
409                                        options.params['query[_with_en]'] = 1;
410                                        if (!options.params.ltype.length || !options.params.inlang.length) {
411                                            return false;
412                                        }
413                                        
414                                        options.params.limit = 9999;
415                                        
416                                     }
417                                 },
418                                 remoteSort : true,
419                                 sortInfo : { field : 'lkey', direction: 'ASC' },
420                                 proxy : {
421                                     xtype: 'HttpProxy',
422                                     xns: Roo.data,
423                                     method : 'GET',
424                                     url : baseURL + '/Roo/i18n.php'
425                                 },
426                                 reader : {
427                                     xtype: 'JsonReader',
428                                     xns: Roo.data,
429                                     totalProperty : 'total',
430                                     root : 'data',
431                                     id : 'id',
432                                     fields : [
433                                         {
434                                             'name': 'id',
435                                             'type': 'int'
436                                         },
437                                         {
438                                             'name': 'ltype',
439                                             'type': 'string'
440                                         },
441                                         {
442                                             'name': 'lkey',
443                                             'type': 'string'
444                                         },
445                                         {
446                                             'name': 'inlang',
447                                             'type': 'string'
448                                         },
449                                         {
450                                             'name': 'lval',
451                                             'type': 'string'
452                                         }
453                                     ]
454                                 }
455                             },
456                             toolbar : {
457                                 xtype: 'Toolbar',
458                                 xns: Roo,
459                                 items : [
460                                     {
461                                         xtype: 'ComboBox',
462                                         xns: Roo.form,
463                                         listeners : {
464                                             render : function (_self)
465                                             {
466                                               _this.langtypeCombo = _self;
467                                             },
468                                             select : function (combo, record, index)
469                                             {
470                                               _this.langgrid.getDataSource().reload(); 
471                                             }
472                                         },
473                                         displayField : 'lval',
474                                         editable : false,
475                                         emptyText : "Select Translation of",
476                                         mode : 'local',
477                                         selectOnFocus : true,
478                                         triggerAction : 'all',
479                                         typeAhead : false,
480                                         valueField : 'lkey',
481                                         width : 200,
482                                         store : {
483                                             xtype: 'SimpleStore',
484                                             xns: Roo.data,
485                                             data : [
486                                                [ 'l', 'Language Names' ],
487                                                [ 'c', 'Country Names' ],
488                                                 [ 'm', 'Currency Names' ]
489                                             ],
490                                             fields : ['lkey','lval']
491                                         }
492                                     },
493                                     {
494                                         xtype: 'ComboBox',
495                                         xns: Roo.form,
496                                         listeners : {
497                                             select : function (combo, record, index)
498                                             {
499                                               _this.langgrid.getDataSource().reload(); 
500                                             },
501                                             render : function (_self)
502                                             {
503                                               _this.langgridCombo=_self;
504                                             }
505                                         },
506                                         displayField : 'ldisp',
507                                         editable : false,
508                                         emptyText : "Select Language",
509                                         mode : 'local',
510                                         selectOnFocus : true,
511                                         triggerAction : 'all',
512                                         typeAhead : false,
513                                         valueField : 'lang',
514                                         width : 200,
515                                         store : {
516                                             xtype: 'SimpleStore',
517                                             xns: Roo.data,
518                                             fields : ['lang', 'ldisp'],
519                                             data : [                                                [ 'zh_HK' , '\u7E41\u4E2D - Trad. Chin. (HK)' ],                         [ 'zh_CN', '\u7C21\u4E2D - Simp. Chin.' ]                     ]
520                                         }
521                                     }
522                                 ]
523                             },
524                             colModel : [
525                                 {
526                                     xtype: 'ColumnModel',
527                                     xns: Roo.grid,
528                                     dataIndex : 'lkey',
529                                     header : 'Code',
530                                     width : 50,
531                                     renderer : function(v) { return String.format('{0}', v); }
532                                 },
533                                 {
534                                     xtype: 'ColumnModel',
535                                     xns: Roo.grid,
536                                     dataIndex : 'lval_en',
537                                     header : 'English',
538                                     width : 150,
539                                     renderer : function(v) { return String.format('{0}', v); }
540                                 },
541                                 {
542                                     xtype: 'ColumnModel',
543                                     xns: Roo.grid,
544                                     dataIndex : 'lval',
545                                     header : 'Translation',
546                                     width : 200,
547                                     renderer : function(v) { return String.format('{0}', v); },
548                                     editor : {
549                                         xtype: 'GridEditor',
550                                         xns: Roo.grid,
551                                         field : {
552                                             xtype: 'TextField',
553                                             xns: Roo.form
554                                         }
555                                     }
556                                 }
557                             ]
558                         }
559                     }
560                 ],
561                 center : {
562                     xtype: 'LayoutRegion',
563                     xns: Roo,
564                     alwaysShowTabs : true,
565                     tabPosition : 'top'
566                 }
567             }
568         };
569     }
570 });