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                                         new Roo.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                                                 Roo.MessageBox.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                                 celldblclick : function (_self, rowIndex, columnIndex, e)
135                                 {
136                                     var di  = this.colModel.config[columnIndex].dataIndex;
137                                     if (di != 'reset_tx') {
138                                         return;
139                                     }
140                                     rec = this.ds.getAt(rowIndex);
141                                     
142                                       var g = _this.grid;
143                                 
144                                         //g.getView().el.mask('Saving');
145                                         new Roo.Request({
146                                             url : baseURL + '/Admin/Translations.php',
147                                             method: 'POST',
148                                             params : {
149                                                 id : rec.get('id'),
150                                                 txt : '',
151                                                 lang :  _this.langCombo.getValue(),
152                                                 module :  _this.modCombo.getValue()
153                                             },
154                                             success : function()
155                                             {
156                                                 //g.getView().el.unmask();
157                                                 //g.getDataSource().reload();
158                                             },
159                                             failure : function()
160                                             {
161                                                 Roo.MessageBox.alert("Error", "There was a problem saving the data - try reloading");
162                                                // g.getView().el.unmask();
163                                             }
164                                             
165                                     });
166                                        
167                                     
168                                 }
169                             },
170                             autoExpandColumn : 'txt',
171                             clicksToEdit : 1,
172                             loadMask : true,
173                             dataSource : {
174                                 xtype: 'Store',
175                                 xns: Roo.data,
176                                 listeners : {
177                                     beforeload : function (_self, opts)
178                                     {
179                                     
180                                                             if (!_this.langCombo || !_this.langCombo.getValue().length) {
181                                                                 return false;
182                                                             }
183                                                             if (!_this.modCombo || !_this.modCombo.getValue().length) {
184                                                                 return false;
185                                                             }
186                                                             opts.params = {
187                                                                 lang :  _this.langCombo.getValue(),
188                                                                 module :  _this.modCombo.getValue()
189                                                             };
190                                     },
191                                     loadexception : function (self, ret, load, jsonData)
192                                     {
193                                         Roo.MessageBox.alert("Error", jsonData);
194                                     }
195                                 },
196                                 reader : Pman.Readers.Category,
197                                 proxy : {
198                                     xtype: 'HttpProxy',
199                                     xns: Roo.data,
200                                     method : 'GET',
201                                     url : baseURL + '/Admin/Translations.php'
202                                 },
203                                 reader : {
204                                     xtype: 'JsonReader',
205                                     xns: Roo.data,
206                                     root : 'data',
207                                     totalProperty : 'total',
208                                     id : 'id',
209                                     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'                  ]
210                                 }
211                             },
212                             toolbar : {
213                                 xtype: 'Toolbar',
214                                 xns: Roo,
215                                 items : [
216                                     {
217                                         xtype: 'ComboBox',
218                                         xns: Roo.form,
219                                         listeners : {
220                                             render : function (_self)
221                                             {
222                                               _this.modCombo = _self;
223                                             },
224                                             select : function (combo, record, index)
225                                             {
226                                               _this.grid.getDataSource().reload(); 
227                                             }
228                                         },
229                                         valueField : 'module',
230                                         displayField : 'module',
231                                         width : 200,
232                                         typeAhead : false,
233                                         editable : false,
234                                         mode : 'local',
235                                         triggerAction : 'all',
236                                         emptyText : "Select Module",
237                                         selectOnFocus : true,
238                                         store : {
239                                             xtype: 'SimpleStore',
240                                             xns: Roo.data,
241                                             data : (function() {             
242                                                     var modlist = [];             
243                                                     AppModules = typeof(AppModules) == 'undefined' ? '' : AppModules;
244                                                     Roo.each( AppModules.split(','), function(mod) {            
245                                                              modlist.push( [ mod ] );            
246                                                   });             
247                                                   return modlist;
248                                                })(),
249                                             fields : ['module']
250                                         }
251                                     },
252                                     {
253                                         xtype: 'ComboBox',
254                                         xns: Roo.form,
255                                         listeners : {
256                                             select : function (combo, record, index)
257                                             {
258                                               _this.grid.getDataSource().reload(); 
259                                             },
260                                             render : function (_self)
261                                             {
262                                               _this.langCombo=_self;
263                                             }
264                                         },
265                                         valueField : 'lang',
266                                         displayField : 'ldisp',
267                                         width : 200,
268                                         typeAhead : false,
269                                         editable : false,
270                                         mode : 'local',
271                                         triggerAction : 'all',
272                                         emptyText : "Select Language",
273                                         selectOnFocus : true,
274                                         store : {
275                                             xtype: 'SimpleStore',
276                                             xns: Roo.data,
277                                             fields : ['lang', 'ldisp'],
278                                             data : [                                                [ 'zh_HK' , '\u7E41\u4E2D - Trad. Chin. (HK)' ],                         [ 'zh_CN', '\u7C21\u4E2D - Simp. Chin.' ]                     ]
279                                         }
280                                     },
281                                     {
282                                         xtype: 'Spacer',
283                                         xns: Roo.Toolbar
284                                     },
285                                     {
286                                         xtype: 'Button',
287                                         xns: Roo.Toolbar
288                                     }
289                                 ]
290                             },
291                             colModel : [
292                                 {
293                                     xtype: 'ColumnModel',
294                                     xns: Roo.grid,
295                                     header : 'Name',
296                                     width : 150,
297                                     dataIndex : 'colname',
298                                     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>';                                              }
299                                 },
300                                 {
301                                     xtype: 'ColumnModel',
302                                     xns: Roo.grid,
303                                     header : 'Original',
304                                     width : 300,
305                                     dataIndex : 'origtxt',
306                                     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>';                                              }
307                                 },
308                                 {
309                                     xtype: 'ColumnModel',
310                                     xns: Roo.grid,
311                                     dataIndex : 'reset_tx',
312                                     header : 'Reset',
313                                     width : 50,
314                                     renderer : function(v,x,r) {    
315                                         return  '<img src="' + rootURL + '/Pman/templates/images/edit-clear.gif' + '" width="16" height="16">';
316                                     }
317                                 },
318                                 {
319                                     xtype: 'ColumnModel',
320                                     xns: Roo.grid,
321                                     dataIndex : 'txt',
322                                     header : 'Translated (Click to Edit)',
323                                     width : 150,
324                                     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>';                     },
325                                     editor : {
326                                         xtype: 'GridEditor',
327                                         xns: Roo.grid,
328                                         field : {
329                                             xtype: 'TextField',
330                                             xns: Roo.form
331                                         }
332                                     }
333                                 }
334                             ]
335                         }
336                     },
337                     {
338                         xtype: 'GridPanel',
339                         xns: Roo,
340                         listeners : {
341                             activate : function() {
342                                 _this.langpanel = this;
343                                 if (_this.langgrid) {
344                                     _this.langgrid.ds.load({});
345                                 }
346                             }
347                         },
348                         background : true,
349                         fitContainer : true,
350                         fitToframe : true,
351                         region : 'center',
352                         tableName : 'i18n',
353                         title : "Languages and Countries",
354                         grid : {
355                             xtype: 'EditorGrid',
356                             xns: Roo.grid,
357                             listeners : {
358                                 render : function() 
359                                 {
360                                     _this.langgrid = this; 
361                                     //_this.dialog = Pman.Dialog.FILL_IN
362                                     if (_this.langpanel.active) {
363                                        this.ds.load({});
364                                     }
365                                 },
366                                 afteredit : function (e)
367                                 {
368                                     var saveRec  = function(rec)
369                                     {
370                                         var g = _this.grid;
371                                 
372                                         //g.getView().el.mask('Saving');
373                                         Ext.Ajax.request({
374                                             url : baseURL + '/Roo/I18n.php',
375                                             method: 'POST',
376                                             params : {
377                                                 id : rec.get('id'),
378                                                 lval : rec.get('lval')
379                                             },
380                                             success : function()
381                                             {
382                                                 //g.getView().el.unmask();
383                                                 //g.getDataSource().reload();
384                                             },
385                                             failure : function()
386                                             {
387                                                 Ext.Msg.alert("Error", "There was a problem saving the data - try reloading");
388                                                // g.getView().el.unmask();
389                                             }
390                                             
391                                     });
392                                         };
393                                     
394                                     saveRec.defer(1000, _this, [ e.record ]);
395                                 },
396                                 beforeedit : function(e) {
397                                     console.log('beforeedit');
398                                     //if (e.record.get('origtxt').indexOf('<') > -1) {
399                                                        // console.log("HTML EDITOR!!");
400                                              
401                                             //    return false;
402                                             //}
403                                             if (e.record.get('lval').replace(/\s+/, '').length) {
404                                                 return true;
405                                             }
406                                             
407                                             
408                                             var tl = _this.langgridCombo.getValue();
409                                           
410                                             tl = (tl == 'zh_HK') ? 'zh-TW' : tl; 
411                                             tl = tl.replace('_', '-');
412                                             var rec = e.record;
413                                             
414                                             
415                                             
416                                             Pman.gtranslate(e.record.get('lval_en'), 'en', tl, function(result) { 
417                                                 if (typeof(result) == 'object') { //error
418                                                     return; 
419                                                    }
420                                                 
421                                                 if (_this.grid.activeEditor) {
422                                                     _this.grid.activeEditor.setValue(result);
423                                                 } else {
424                                                     rec.set('lval',result);
425                                                     //_this.saveRec(rec);
426                                                 }
427                                 
428                                                 //
429                                                 
430                                                 
431                                                 //console.log(result.translation);
432                                             });
433                                             
434                                            
435                                             
436                                             return true;
437                                         }
438                             },
439                             autoExpandColumn : 'lval',
440                             clicksToEdit : 1,
441                             loadMask : true,
442                             dataSource : {
443                                 xtype: 'Store',
444                                 xns: Roo.data,
445                                 listeners : {
446                                     beforeload : function (_self, options)
447                                     {
448                                        options  =options ||  {};
449                                        options.params =options.params|| {};
450                                        options.params.ltype = _this.langtypeCombo.getValue();
451                                        options.params.inlang = _this.langgridCombo.getValue();
452                                        options.params['query[_with_en]'] = 1;
453                                        if (!options.params.ltype.length || !options.params.inlang.length) {
454                                            return false;
455                                        }
456                                        
457                                        options.params.limit = 9999;
458                                        
459                                     }
460                                 },
461                                 remoteSort : true,
462                                 sortInfo : { field : 'lkey', direction: 'ASC' },
463                                 proxy : {
464                                     xtype: 'HttpProxy',
465                                     xns: Roo.data,
466                                     method : 'GET',
467                                     url : baseURL + '/Roo/i18n.php'
468                                 },
469                                 reader : {
470                                     xtype: 'JsonReader',
471                                     xns: Roo.data,
472                                     totalProperty : 'total',
473                                     root : 'data',
474                                     id : 'id',
475                                     fields : [
476                                         {
477                                             'name': 'id',
478                                             'type': 'int'
479                                         },
480                                         {
481                                             'name': 'ltype',
482                                             'type': 'string'
483                                         },
484                                         {
485                                             'name': 'lkey',
486                                             'type': 'string'
487                                         },
488                                         {
489                                             'name': 'inlang',
490                                             'type': 'string'
491                                         },
492                                         {
493                                             'name': 'lval',
494                                             'type': 'string'
495                                         }
496                                     ]
497                                 }
498                             },
499                             toolbar : {
500                                 xtype: 'Toolbar',
501                                 xns: Roo,
502                                 items : [
503                                     {
504                                         xtype: 'ComboBox',
505                                         xns: Roo.form,
506                                         listeners : {
507                                             render : function (_self)
508                                             {
509                                               _this.langtypeCombo = _self;
510                                             },
511                                             select : function (combo, record, index)
512                                             {
513                                               _this.langgrid.getDataSource().reload(); 
514                                             }
515                                         },
516                                         displayField : 'lval',
517                                         editable : false,
518                                         emptyText : "Select Translation of",
519                                         mode : 'local',
520                                         selectOnFocus : true,
521                                         triggerAction : 'all',
522                                         typeAhead : false,
523                                         valueField : 'lkey',
524                                         width : 200,
525                                         store : {
526                                             xtype: 'SimpleStore',
527                                             xns: Roo.data,
528                                             data : [
529                                                [ 'l', 'Language Names' ],
530                                                [ 'c', 'Country Names' ],
531                                                 [ 'm', 'Currency Names' ]
532                                             ],
533                                             fields : ['lkey','lval']
534                                         }
535                                     },
536                                     {
537                                         xtype: 'ComboBox',
538                                         xns: Roo.form,
539                                         listeners : {
540                                             select : function (combo, record, index)
541                                             {
542                                               _this.langgrid.getDataSource().reload(); 
543                                             },
544                                             render : function (_self)
545                                             {
546                                               _this.langgridCombo=_self;
547                                             }
548                                         },
549                                         displayField : 'ldisp',
550                                         editable : false,
551                                         emptyText : "Select Language",
552                                         mode : 'local',
553                                         selectOnFocus : true,
554                                         triggerAction : 'all',
555                                         typeAhead : false,
556                                         valueField : 'lang',
557                                         width : 200,
558                                         store : {
559                                             xtype: 'SimpleStore',
560                                             xns: Roo.data,
561                                             fields : ['lang', 'ldisp'],
562                                             data : [                                                [ 'zh_HK' , '\u7E41\u4E2D - Trad. Chin. (HK)' ],                         [ 'zh_CN', '\u7C21\u4E2D - Simp. Chin.' ]                     ]
563                                         }
564                                     }
565                                 ]
566                             },
567                             colModel : [
568                                 {
569                                     xtype: 'ColumnModel',
570                                     xns: Roo.grid,
571                                     dataIndex : 'lkey',
572                                     header : 'Code',
573                                     width : 50,
574                                     renderer : function(v) { return String.format('{0}', v); }
575                                 },
576                                 {
577                                     xtype: 'ColumnModel',
578                                     xns: Roo.grid,
579                                     dataIndex : 'lval_en',
580                                     header : 'English',
581                                     width : 150,
582                                     renderer : function(v) { return String.format('{0}', v); }
583                                 },
584                                 {
585                                     xtype: 'ColumnModel',
586                                     xns: Roo.grid,
587                                     dataIndex : 'lval',
588                                     header : 'Translation',
589                                     width : 200,
590                                     renderer : function(v) { return String.format('{0}', v); },
591                                     editor : {
592                                         xtype: 'GridEditor',
593                                         xns: Roo.grid,
594                                         field : {
595                                             xtype: 'TextField',
596                                             xns: Roo.form
597                                         }
598                                     }
599                                 }
600                             ]
601                         }
602                     }
603                 ],
604                 center : {
605                     xtype: 'LayoutRegion',
606                     xns: Roo,
607                     alwaysShowTabs : true,
608                     tabPosition : 'top'
609                 }
610             }
611         };
612     }
613 });