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 Pman.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                                     new Pman.Request({
145                                         url : baseURL + '/Admin/Translations.php',
146                                         method: 'POST',
147                                         params : {
148                                             id : rec.get('id'),
149                                             txt : '',
150                                             lang :  _this.langCombo.getValue(),
151                                             module :  _this.modCombo.getValue()
152                                         },
153                                         success : function()
154                                         {
155                                             //g.getView().el.unmask();
156                                             //g.getDataSource().reload();
157                                             rec.set('txt', '');
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: 'Fill',
283                                         xns: Roo.Toolbar
284                                     },
285                                     {
286                                         xtype: 'Button',
287                                         xns: Roo.Toolbar,
288                                         listeners : {
289                                             click : function (_self, e)
290                                             {
291                                                 new Pman.Download({
292                                                     grid: _this.grid
293                                                 
294                                                 });
295                                             }
296                                         },
297                                         text : "Download"
298                                     }
299                                 ]
300                             },
301                             colModel : [
302                                 {
303                                     xtype: 'ColumnModel',
304                                     xns: Roo.grid,
305                                     header : 'Name',
306                                     width : 150,
307                                     dataIndex : 'colname',
308                                     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>';                                              }
309                                 },
310                                 {
311                                     xtype: 'ColumnModel',
312                                     xns: Roo.grid,
313                                     header : 'Original',
314                                     width : 300,
315                                     dataIndex : 'origtxt',
316                                     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>';                                              }
317                                 },
318                                 {
319                                     xtype: 'ColumnModel',
320                                     xns: Roo.grid,
321                                     dataIndex : 'reset_tx',
322                                     header : 'Reset',
323                                     width : 50,
324                                     renderer : function(v,x,r) {    
325                                         return  '<img src="' + rootURL + '/Pman/templates/images/edit-clear.gif' + '" width="16" height="16">';
326                                     }
327                                 },
328                                 {
329                                     xtype: 'ColumnModel',
330                                     xns: Roo.grid,
331                                     dataIndex : 'txt',
332                                     header : 'Translated (Click to Edit)',
333                                     width : 150,
334                                     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>';                     },
335                                     editor : {
336                                         xtype: 'GridEditor',
337                                         xns: Roo.grid,
338                                         field : {
339                                             xtype: 'TextField',
340                                             xns: Roo.form
341                                         }
342                                     }
343                                 }
344                             ]
345                         }
346                     },
347                     {
348                         xtype: 'GridPanel',
349                         xns: Roo,
350                         listeners : {
351                             activate : function() {
352                                 _this.langpanel = this;
353                                 if (_this.langgrid) {
354                                     _this.langgrid.ds.load({});
355                                 }
356                             }
357                         },
358                         background : true,
359                         fitContainer : true,
360                         fitToframe : true,
361                         region : 'center',
362                         tableName : 'i18n',
363                         title : "Languages and Countries",
364                         grid : {
365                             xtype: 'EditorGrid',
366                             xns: Roo.grid,
367                             listeners : {
368                                 render : function() 
369                                 {
370                                     _this.langgrid = this; 
371                                     //_this.dialog = Pman.Dialog.FILL_IN
372                                     if (_this.langpanel.active) {
373                                        this.ds.load({});
374                                     }
375                                 },
376                                 afteredit : function (e)
377                                 {
378                                     var saveRec  = function(rec)
379                                     {
380                                         var g = _this.grid;
381                                 
382                                         //g.getView().el.mask('Saving');
383                                         Ext.Ajax.request({
384                                             url : baseURL + '/Roo/I18n.php',
385                                             method: 'POST',
386                                             params : {
387                                                 id : rec.get('id'),
388                                                 lval : rec.get('lval')
389                                             },
390                                             success : function()
391                                             {
392                                                 //g.getView().el.unmask();
393                                                 //g.getDataSource().reload();
394                                             },
395                                             failure : function()
396                                             {
397                                                 Ext.Msg.alert("Error", "There was a problem saving the data - try reloading");
398                                                // g.getView().el.unmask();
399                                             }
400                                             
401                                     });
402                                         };
403                                     
404                                     saveRec.defer(1000, _this, [ e.record ]);
405                                 },
406                                 beforeedit : function(e) {
407                                     console.log('beforeedit');
408                                     //if (e.record.get('origtxt').indexOf('<') > -1) {
409                                                        // console.log("HTML EDITOR!!");
410                                              
411                                             //    return false;
412                                             //}
413                                             if (e.record.get('lval').replace(/\s+/, '').length) {
414                                                 return true;
415                                             }
416                                             
417                                             
418                                             var tl = _this.langgridCombo.getValue();
419                                           
420                                             tl = (tl == 'zh_HK') ? 'zh-TW' : tl; 
421                                             tl = tl.replace('_', '-');
422                                             var rec = e.record;
423                                             
424                                             
425                                             
426                                             Pman.gtranslate(e.record.get('lval_en'), 'en', tl, function(result) { 
427                                                 if (typeof(result) == 'object') { //error
428                                                     return; 
429                                                    }
430                                                 
431                                                 if (_this.grid.activeEditor) {
432                                                     _this.grid.activeEditor.setValue(result);
433                                                 } else {
434                                                     rec.set('lval',result);
435                                                     //_this.saveRec(rec);
436                                                 }
437                                 
438                                                 //
439                                                 
440                                                 
441                                                 //console.log(result.translation);
442                                             });
443                                             
444                                            
445                                             
446                                             return true;
447                                         }
448                             },
449                             autoExpandColumn : 'lval',
450                             clicksToEdit : 1,
451                             loadMask : true,
452                             dataSource : {
453                                 xtype: 'Store',
454                                 xns: Roo.data,
455                                 listeners : {
456                                     beforeload : function (_self, options)
457                                     {
458                                        options  =options ||  {};
459                                        options.params =options.params|| {};
460                                        options.params.ltype = _this.langtypeCombo.getValue();
461                                        options.params.inlang = _this.langgridCombo.getValue();
462                                        options.params['query[_with_en]'] = 1;
463                                        if (!options.params.ltype.length || !options.params.inlang.length) {
464                                            return false;
465                                        }
466                                        
467                                        options.params.limit = 9999;
468                                        
469                                     }
470                                 },
471                                 remoteSort : true,
472                                 sortInfo : { field : 'lkey', direction: 'ASC' },
473                                 proxy : {
474                                     xtype: 'HttpProxy',
475                                     xns: Roo.data,
476                                     method : 'GET',
477                                     url : baseURL + '/Roo/i18n.php'
478                                 },
479                                 reader : {
480                                     xtype: 'JsonReader',
481                                     xns: Roo.data,
482                                     totalProperty : 'total',
483                                     root : 'data',
484                                     id : 'id',
485                                     fields : [
486                                         {
487                                             'name': 'id',
488                                             'type': 'int'
489                                         },
490                                         {
491                                             'name': 'ltype',
492                                             'type': 'string'
493                                         },
494                                         {
495                                             'name': 'lkey',
496                                             'type': 'string'
497                                         },
498                                         {
499                                             'name': 'inlang',
500                                             'type': 'string'
501                                         },
502                                         {
503                                             'name': 'lval',
504                                             'type': 'string'
505                                         }
506                                     ]
507                                 }
508                             },
509                             toolbar : {
510                                 xtype: 'Toolbar',
511                                 xns: Roo,
512                                 items : [
513                                     {
514                                         xtype: 'ComboBox',
515                                         xns: Roo.form,
516                                         listeners : {
517                                             render : function (_self)
518                                             {
519                                               _this.langtypeCombo = _self;
520                                             },
521                                             select : function (combo, record, index)
522                                             {
523                                               _this.langgrid.getDataSource().reload(); 
524                                             }
525                                         },
526                                         displayField : 'lval',
527                                         editable : false,
528                                         emptyText : "Select Translation of",
529                                         mode : 'local',
530                                         selectOnFocus : true,
531                                         triggerAction : 'all',
532                                         typeAhead : false,
533                                         valueField : 'lkey',
534                                         width : 200,
535                                         store : {
536                                             xtype: 'SimpleStore',
537                                             xns: Roo.data,
538                                             data : [
539                                                [ 'l', 'Language Names' ],
540                                                [ 'c', 'Country Names' ],
541                                                 [ 'm', 'Currency Names' ]
542                                             ],
543                                             fields : ['lkey','lval']
544                                         }
545                                     },
546                                     {
547                                         xtype: 'ComboBox',
548                                         xns: Roo.form,
549                                         listeners : {
550                                             select : function (combo, record, index)
551                                             {
552                                               _this.langgrid.getDataSource().reload(); 
553                                             },
554                                             render : function (_self)
555                                             {
556                                               _this.langgridCombo=_self;
557                                             }
558                                         },
559                                         displayField : 'ldisp',
560                                         editable : false,
561                                         emptyText : "Select Language",
562                                         mode : 'local',
563                                         selectOnFocus : true,
564                                         triggerAction : 'all',
565                                         typeAhead : false,
566                                         valueField : 'lang',
567                                         width : 200,
568                                         store : {
569                                             xtype: 'SimpleStore',
570                                             xns: Roo.data,
571                                             fields : ['lang', 'ldisp'],
572                                             data : [                                                [ 'zh_HK' , '\u7E41\u4E2D - Trad. Chin. (HK)' ],                         [ 'zh_CN', '\u7C21\u4E2D - Simp. Chin.' ]                     ]
573                                         }
574                                     }
575                                 ]
576                             },
577                             colModel : [
578                                 {
579                                     xtype: 'ColumnModel',
580                                     xns: Roo.grid,
581                                     dataIndex : 'lkey',
582                                     header : 'Code',
583                                     width : 50,
584                                     renderer : function(v) { return String.format('{0}', v); }
585                                 },
586                                 {
587                                     xtype: 'ColumnModel',
588                                     xns: Roo.grid,
589                                     dataIndex : 'lval_en',
590                                     header : 'English',
591                                     width : 150,
592                                     renderer : function(v) { return String.format('{0}', v); }
593                                 },
594                                 {
595                                     xtype: 'ColumnModel',
596                                     xns: Roo.grid,
597                                     dataIndex : 'lval',
598                                     header : 'Translation',
599                                     width : 200,
600                                     renderer : function(v) { return String.format('{0}', v); },
601                                     editor : {
602                                         xtype: 'GridEditor',
603                                         xns: Roo.grid,
604                                         field : {
605                                             xtype: 'TextField',
606                                             xns: Roo.form
607                                         }
608                                     }
609                                 },
610                                 {
611                                     xtype: 'ColumnModel',
612                                     xns: Roo.grid,
613                                     dataIndex : 'lval_en',
614                                     header : 'English',
615                                     width : 150,
616                                     renderer : function(v) { return String.format('{0}', v); }
617                                 }
618                             ]
619                         }
620                     }
621                 ],
622                 center : {
623                     xtype: 'LayoutRegion',
624                     xns: Roo,
625                     alwaysShowTabs : true,
626                     tabPosition : 'top'
627                 }
628             }
629         };
630     }
631 });