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