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 Roo.namespace('Pman.Tab');
6
7 Pman.Tab.AdminTranslations = new Roo.XComponent({
8
9  _strings : {
10   '0a52da7a03a6de3beefe54f8c03ad80d' :"Original",
11   'ae739a236065a45c64ad51aacb19498c' :"Active?",
12   '801ab24683a4a8c433c6eb40c48bcd9d' :"Download",
13   'e2ade2e0b88406a390f59b5232abb328' :"Translated (Click to Edit)",
14   '6dd08874f83507e9c7b23f1a46b7fa7c' :"Translation",
15   '83dad8107f9459efe2b4fabcf5b63108' :"Select Language",
16   'a1d1ae170f841c328acdc6052511ed8c' :"Text in interface",
17   '78463a384a5aa4fad5fa73e2f506ecfc' :"English",
18   '4e7c16d320ae129cc81b296e05748b3a' :"Translate App",
19   '526d688f37a86d3c3f27d0c5016eb71d' :"Reset",
20   'b51c3fa7e0ae26a1d88bf1279f265bb4' :"Select Module",
21   '49ee3087348e8d44e1feda1917443987' :"Name",
22   '552bcc4e00cd663f09cc4efbaca1cd45' :"Select Translation of",
23   'ca0dbad92a874b2f69b549293387925e' :"Code",
24   '0a9e8bd9e8b301dfb2c21c355e0b377d' :"Languages and Countries"
25  },
26
27   part     :  ["Admin", "Translations" ],
28   order    : '950-Pman.Tab.AdminTranslations',
29   region   : 'center',
30   parent   : 'Pman.Tab.Admin',
31   name     : "Admin - Translations",
32   disabled : false, 
33   permname : 'Admin.Translations', 
34   _tree : function()
35   {
36    var _this = this;
37    var MODULE = this;
38    return {
39    layout : {
40     center : {
41      '|xns' : 'Roo',
42      alwaysShowTabs : true,
43      tabPosition : 'top',
44      xns : Roo,
45      xtype : 'LayoutRegion'
46     },
47     '|xns' : 'Roo',
48     xns : Roo,
49     xtype : 'BorderLayout',
50     items : [
51      {
52       grid : {
53        dataSource : {
54         proxy : {
55          '|xns' : 'Roo.data',
56          method : 'GET',
57          url : baseURL + '/Admin/Translations.php',
58          xns : Roo.data,
59          xtype : 'HttpProxy'
60         },
61         reader : {
62          '|xns' : 'Roo.data',
63          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'                  ],
64          id : 'id',
65          root : 'data',
66          totalProperty : 'total',
67          xns : Roo.data,
68          xtype : 'JsonReader'
69         },
70         '|xns' : 'Roo.data',
71         reader : Pman.Readers.Category,
72         xns : Roo.data,
73         xtype : 'Store',
74         listeners : {
75          beforeload : function (_self, opts)
76           {
77           
78                                   if (!_this.langCombo || !_this.langCombo.getValue().length) {
79                                       return false;
80                                   }
81                                   if (!_this.modCombo || !_this.modCombo.getValue().length) {
82                                       return false;
83                                   }
84                                   opts.params = {
85                                       lang :  _this.langCombo.getValue(),
86                                       module :  _this.modCombo.getValue()
87                                   };
88           },
89          loadexception : function (self, ret, load, jsonData)
90           {
91               Roo.MessageBox.alert("Error", jsonData);
92           }
93         },
94         items : [
95
96         ]
97
98        },
99        toolbar : {
100         '|xns' : 'Roo',
101         xns : Roo,
102         xtype : 'Toolbar',
103         items : [
104          {
105           store : {
106            '|xns' : 'Roo.data',
107            data : (function() {             
108                    var modlist = [];             
109                    AppModules = typeof(AppModules) == 'undefined' ? '' : AppModules;
110                    Roo.each( AppModules.split(','), function(mod) {            
111                             modlist.push( [ mod ] );            
112                  });             
113                  return modlist;
114               })(),
115            fields : ['module'],
116            xns : Roo.data,
117            xtype : 'SimpleStore'
118           },
119           '|xns' : 'Roo.form',
120           displayField : 'module',
121           editable : false,
122           emptyText : _this._strings['b51c3fa7e0ae26a1d88bf1279f265bb4'],
123           mode : 'local',
124           selectOnFocus : true,
125           triggerAction : 'all',
126           typeAhead : false,
127           valueField : 'module',
128           width : 200,
129           xns : Roo.form,
130           xtype : 'ComboBox',
131           listeners : {
132            render : function (_self)
133             {
134               _this.modCombo = _self;
135             },
136            select : function (combo, record, index)
137             {
138               _this.grid.getDataSource().reload(); 
139             }
140           },
141           items : [
142
143           ]
144
145          },
146          {
147           store : {
148            '|xns' : 'Roo.data',
149            data : [                                                [ 'zh_HK' , '\u7E41\u4E2D - Trad. Chin. (HK)' ],                         [ 'zh_CN', '\u7C21\u4E2D - Simp. Chin.' ]                     ],
150            fields : ['lang', 'ldisp'],
151            xns : Roo.data,
152            xtype : 'SimpleStore'
153           },
154           '|xns' : 'Roo.form',
155           displayField : 'ldisp',
156           editable : false,
157           emptyText : _this._strings['83dad8107f9459efe2b4fabcf5b63108'],
158           mode : 'local',
159           selectOnFocus : true,
160           triggerAction : 'all',
161           typeAhead : false,
162           valueField : 'lang',
163           width : 200,
164           xns : Roo.form,
165           xtype : 'ComboBox',
166           listeners : {
167            render : function (_self)
168             {
169               _this.langCombo=_self;
170             },
171            select : function (combo, record, index)
172             {
173               _this.grid.getDataSource().reload(); 
174             }
175           },
176           items : [
177
178           ]
179
180          },
181          {
182           '|xns' : 'Roo.Toolbar',
183           xns : Roo.Toolbar,
184           xtype : 'Fill'
185          },
186          {
187           '|xns' : 'Roo.Toolbar',
188           text : _this._strings['801ab24683a4a8c433c6eb40c48bcd9d'],
189           xns : Roo.Toolbar,
190           xtype : 'Button',
191           listeners : {
192            click : function (_self, e)
193             {
194                 new Pman.Download({
195                     grid: _this.grid
196                 
197                 });
198             }
199           }
200          }
201         ]
202
203        },
204        '|xns' : 'Roo.grid',
205        autoExpandColumn : 'txt',
206        clicksToEdit : 1,
207        loadMask : true,
208        xns : Roo.grid,
209        xtype : 'EditorGrid',
210        colModel : [
211          {
212           '|xns' : 'Roo.grid',
213           dataIndex : 'colname',
214           header : _this._strings['49ee3087348e8d44e1feda1917443987'],
215           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>';                                              },
216           width : 150,
217           xns : Roo.grid,
218           xtype : 'ColumnModel'
219          },
220 {
221           '|xns' : 'Roo.grid',
222           dataIndex : 'origtxt',
223           header : _this._strings['0a52da7a03a6de3beefe54f8c03ad80d'],
224           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>';                                              },
225           width : 300,
226           xns : Roo.grid,
227           xtype : 'ColumnModel'
228          },
229 {
230           '|xns' : 'Roo.grid',
231           dataIndex : 'reset_tx',
232           header : _this._strings['526d688f37a86d3c3f27d0c5016eb71d'],
233           renderer : function(v,x,r) {    
234               return  '<img src="' + rootURL + '/Pman/templates/images/edit-clear.gif' + '" width="16" height="16">';
235           },
236           width : 50,
237           xns : Roo.grid,
238           xtype : 'ColumnModel'
239          },
240 {
241           editor : {
242            field : {
243             '|xns' : 'Roo.form',
244             xns : Roo.form,
245             xtype : 'TextField'
246            },
247            '|xns' : 'Roo.grid',
248            xns : Roo.grid,
249            xtype : 'GridEditor',
250            items : [
251
252            ]
253
254           },
255           '|xns' : 'Roo.grid',
256           dataIndex : 'txt',
257           header : _this._strings['e2ade2e0b88406a390f59b5232abb328'],
258           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>';                     },
259           width : 150,
260           xns : Roo.grid,
261           xtype : 'ColumnModel',
262           items : [
263
264           ]
265
266          }
267        ],
268        listeners : {
269         afteredit : function (e)
270          {
271              var saveRec  = function(rec)
272              {
273                  var g = _this.grid;
274          
275                  //g.getView().el.mask('Saving');
276                  new Pman.Request({
277                      url : baseURL + '/Admin/Translations.php',
278                      method: 'POST',
279                      params : {
280                          id : rec.get('id'),
281                          txt : rec.get('txt'),
282                          lang :  _this.langCombo.getValue(),
283                          module :  _this.modCombo.getValue()
284                      },
285                      success : function()
286                      {
287                          //g.getView().el.unmask();
288                          //g.getDataSource().reload();
289                      },
290                      failure : function()
291                      {
292                          Roo.MessageBox.alert("Error", "There was a problem saving the data - try reloading");
293                         // g.getView().el.unmask();
294                      }
295                      
296              });
297                  };
298              
299              saveRec.defer(1000, _this, [ e.record ]);
300          },
301         beforeedit : function(e) {
302              console.log('beforeedit');
303              //if (e.record.get('origtxt').indexOf('<') > -1) {
304                                 // console.log("HTML EDITOR!!");
305                               
306                              //    return false;
307                              //}
308                              if (e.record.get('txt').replace(/\s+/, '').length) {
309                                  return true;
310                              }
311                              if (e.record.get('suggest').length) {
312                                  e.record.set('txt', e.record.get('suggest'));
313                              //    _this.saveRec(e.record);
314                                  return;
315                              }
316                              
317                              
318                              
319                             
320                              var tl = e.record.get('id').split('/')[0];
321                            
322                              tl = (tl == 'zh_HK') ? 'zh-TW' : tl; 
323                              tl = tl.replace('_', '-');
324                              var rec = e.record;
325                              
326                              
327                              
328                              Pman.gtranslate(e.record.get('origtxt'), 'en', tl, function(result) { 
329                                  if (typeof(result) == 'object') { //error
330                                      return; 
331                                     }
332                                  
333                                  if (_this.grid.activeEditor) {
334                                      _this.grid.activeEditor.setValue(result);
335                                  } else {
336                                      rec.set('txt',result);
337                                      //_this.saveRec(rec);
338                                  }
339          
340                                  //
341                                  
342                                  
343                                  //console.log(result.translation);
344                              });
345                              
346                             
347                              
348                              return true;
349                          },
350         celldblclick : function (_self, rowIndex, columnIndex, e)
351          {
352              var di  = this.colModel.config[columnIndex].dataIndex;
353              if (di != 'reset_tx') {
354                  return;
355              }
356              rec = this.ds.getAt(rowIndex);
357              
358                var g = _this.grid;
359           
360              new Pman.Request({
361                  url : baseURL + '/Admin/Translations.php',
362                  method: 'POST',
363                  params : {
364                      id : rec.get('id'),
365                      txt : '',
366                      lang :  _this.langCombo.getValue(),
367                      module :  _this.modCombo.getValue()
368                  },
369                  success : function()
370                  {
371                      //g.getView().el.unmask();
372                      //g.getDataSource().reload();
373                      rec.set('txt', '');
374                  },
375                  failure : function()
376                  {
377                      Roo.MessageBox.alert("Error", "There was a problem saving the data - try reloading");
378                     // g.getView().el.unmask();
379                  }
380                  
381              });
382                 
383              
384          },
385         render : function() { 
386              _this.grid = this; 
387              //_this.dialog = Pman.Dialog.FILL_IN
388              if (_this.panel.active) {
389                _this.grid.getDataSource().reload(); 
390              }
391          }
392        },
393        items : [
394
395        ]
396
397       },
398       '|xns' : 'Roo',
399       background : true,
400       fitContainer : true,
401       fitToframe : true,
402       region : 'center',
403       title : _this._strings['a1d1ae170f841c328acdc6052511ed8c'],
404       xns : Roo,
405       xtype : 'GridPanel',
406       listeners : {
407        activate : function() {
408             _this.panel = this;
409             if (_this.grid) {
410                _this.grid.getDataSource().reload(); 
411             }
412         }
413       },
414       items : [
415
416       ]
417
418      },
419      {
420       grid : {
421        dataSource : {
422         proxy : {
423          '|xns' : 'Roo.data',
424          method : 'GET',
425          url : baseURL + '/Roo/i18n.php',
426          xns : Roo.data,
427          xtype : 'HttpProxy'
428         },
429         reader : {
430          '|xns' : 'Roo.data',
431          fields : [
432              {
433                  'name': 'id',
434                  'type': 'int'
435              },
436              {
437                  'name': 'ltype',
438                  'type': 'string'
439              },
440              {
441                  'name': 'lkey',
442                  'type': 'string'
443              },
444              {
445                  'name': 'inlang',
446                  'type': 'string'
447              },
448              {
449                  'name': 'lval',
450                  'type': 'string'
451              }
452          ],
453          id : 'id',
454          root : 'data',
455          totalProperty : 'total',
456          xns : Roo.data,
457          xtype : 'JsonReader'
458         },
459         '|xns' : 'Roo.data',
460         remoteSort : true,
461         sortInfo : { field : 'lkey', direction: 'ASC' },
462         xns : Roo.data,
463         xtype : 'Store',
464         listeners : {
465          beforeload : function (_self, options)
466           {
467              options  =options ||  {};
468              options.params =options.params|| {};
469              options.params.ltype = _this.langtypeCombo.getValue();
470              options.params.inlang = _this.langgridCombo.getValue();
471              options.params['query[_with_en]'] = 1;
472              if (!options.params.ltype.length || !options.params.inlang.length) {
473                  return false;
474              }
475              
476              options.params.limit = 9999;
477              
478           }
479         },
480         items : [
481
482         ]
483
484        },
485        toolbar : {
486         '|xns' : 'Roo',
487         xns : Roo,
488         xtype : 'Toolbar',
489         items : [
490          {
491           store : {
492            '|xns' : 'Roo.data',
493            data : [
494               [ 'l', 'Language Names' ],
495               [ 'c', 'Country Names' ],
496                [ 'm', 'Currency Names' ]
497            ],
498            fields : ['lkey','lval'],
499            xns : Roo.data,
500            xtype : 'SimpleStore'
501           },
502           '|xns' : 'Roo.form',
503           displayField : 'lval',
504           editable : false,
505           emptyText : _this._strings['552bcc4e00cd663f09cc4efbaca1cd45'],
506           mode : 'local',
507           selectOnFocus : true,
508           triggerAction : 'all',
509           typeAhead : false,
510           valueField : 'lkey',
511           width : 200,
512           xns : Roo.form,
513           xtype : 'ComboBox',
514           listeners : {
515            render : function (_self)
516             {
517               _this.langtypeCombo = _self;
518             },
519            select : function (combo, record, index)
520             {
521               _this.langgrid.getDataSource().reload(); 
522             }
523           },
524           items : [
525
526           ]
527
528          },
529          {
530           store : {
531            '|xns' : 'Roo.data',
532            data : [                                                [ 'zh_HK' , '\u7E41\u4E2D - Trad. Chin. (HK)' ],                         [ 'zh_CN', '\u7C21\u4E2D - Simp. Chin.' ]                     ],
533            fields : ['lang', 'ldisp'],
534            xns : Roo.data,
535            xtype : 'SimpleStore'
536           },
537           '|xns' : 'Roo.form',
538           displayField : 'ldisp',
539           editable : false,
540           emptyText : _this._strings['83dad8107f9459efe2b4fabcf5b63108'],
541           mode : 'local',
542           selectOnFocus : true,
543           triggerAction : 'all',
544           typeAhead : false,
545           valueField : 'lang',
546           width : 200,
547           xns : Roo.form,
548           xtype : 'ComboBox',
549           listeners : {
550            render : function (_self)
551             {
552               _this.langgridCombo=_self;
553             },
554            select : function (combo, record, index)
555             {
556               _this.langgrid.getDataSource().reload(); 
557             }
558           },
559           items : [
560
561           ]
562
563          }
564         ]
565
566        },
567        '|xns' : 'Roo.grid',
568        autoExpandColumn : 'lval',
569        clicksToEdit : 1,
570        loadMask : true,
571        xns : Roo.grid,
572        xtype : 'EditorGrid',
573        colModel : [
574          {
575           '|xns' : 'Roo.grid',
576           dataIndex : 'lkey',
577           header : _this._strings['ca0dbad92a874b2f69b549293387925e'],
578           renderer : function(v) { return String.format('{0}', v); },
579           width : 50,
580           xns : Roo.grid,
581           xtype : 'ColumnModel'
582          },
583 {
584           '|xns' : 'Roo.grid',
585           dataIndex : 'lval_en',
586           header : _this._strings['78463a384a5aa4fad5fa73e2f506ecfc'],
587           renderer : function(v) { return String.format('{0}', v); },
588           width : 150,
589           xns : Roo.grid,
590           xtype : 'ColumnModel'
591          },
592 {
593           editor : {
594            field : {
595             '|xns' : 'Roo.form',
596             xns : Roo.form,
597             xtype : 'TextField'
598            },
599            '|xns' : 'Roo.grid',
600            xns : Roo.grid,
601            xtype : 'GridEditor',
602            items : [
603
604            ]
605
606           },
607           '|xns' : 'Roo.grid',
608           dataIndex : 'lval',
609           header : _this._strings['6dd08874f83507e9c7b23f1a46b7fa7c'],
610           renderer : function(v) { return String.format('{0}', v); },
611           width : 200,
612           xns : Roo.grid,
613           xtype : 'ColumnModel',
614           items : [
615
616           ]
617
618          },
619 {
620           '|xns' : 'Roo.grid',
621           dataIndex : 'is_active',
622           header : _this._strings['ae739a236065a45c64ad51aacb19498c'],
623           renderer : function(v,x,r) { 
624           
625               return '<img class="x-grid-check-icon' + (v*1 ? '-checked' : '')  + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
626                                                   
627               
628           },
629           width : 150,
630           xns : Roo.grid,
631           xtype : 'ColumnModel'
632          }
633        ],
634        listeners : {
635         afteredit : function (e)
636          {
637              var saveRec  = function(rec)
638              {
639                  var g = _this.grid;
640          
641                  //g.getView().el.mask('Saving');
642                  Ext.Ajax.request({
643                      url : baseURL + '/Roo/I18n.php',
644                      method: 'POST',
645                      params : {
646                          id : rec.get('id'),
647                          lval : rec.get('lval')
648                      },
649                      success : function()
650                      {
651                          //g.getView().el.unmask();
652                          //g.getDataSource().reload();
653                      },
654                      failure : function()
655                      {
656                          Ext.Msg.alert("Error", "There was a problem saving the data - try reloading");
657                         // g.getView().el.unmask();
658                      }
659                      
660              });
661                  };
662              
663              saveRec.defer(1000, _this, [ e.record ]);
664          },
665         beforeedit : function(e) {
666              console.log('beforeedit');
667              //if (e.record.get('origtxt').indexOf('<') > -1) {
668                                 // console.log("HTML EDITOR!!");
669                       
670                      //    return false;
671                      //}
672                      if (e.record.get('lval').replace(/\s+/, '').length) {
673                          return true;
674                      }
675                      
676                      
677                      var tl = _this.langgridCombo.getValue();
678                    
679                      tl = (tl == 'zh_HK') ? 'zh-TW' : tl; 
680                      tl = tl.replace('_', '-');
681                      var rec = e.record;
682                      
683                      
684                      
685                      Pman.gtranslate(e.record.get('lval_en'), 'en', tl, function(result) { 
686                          if (typeof(result) == 'object') { //error
687                              return; 
688                             }
689                          
690                          if (_this.grid.activeEditor) {
691                              _this.grid.activeEditor.setValue(result);
692                          } else {
693                              rec.set('lval',result);
694                              //_this.saveRec(rec);
695                          }
696          
697                          //
698                          
699                          
700                          //console.log(result.translation);
701                      });
702                      
703                     
704                      
705                      return true;
706                  },
707         cellclick : function (_self, rowIndex, columnIndex, e)
708          {
709              if(_this.langgrid.colModel.getDataIndex(columnIndex) !== 'is_active'){
710                  return;
711              }
712              
713              var s = _this.langgrid.ds.getAt(rowIndex);
714              
715              if(!s || s.data.id * 1 < 0){
716                  return;
717              }
718              
719              s.set('is_active', s.data.is_active ? 0 : 1);
720              
721              new Pman.Request({
722                  url : baseURL+'/Roo/I18n',
723                  method : 'POST',
724                  params : {
725                      id : s.data.id,
726                      is_active : s.data.is_active
727                  }
728              }); 
729              
730          },
731         render : function() 
732          {
733              _this.langgrid = this; 
734              //_this.dialog = Pman.Dialog.FILL_IN
735              if (_this.langpanel.active) {
736                 this.ds.load({});
737              }
738          }
739        },
740        items : [
741
742        ]
743
744       },
745       '|xns' : 'Roo',
746       background : true,
747       fitContainer : true,
748       fitToframe : true,
749       region : 'center',
750       tableName : 'i18n',
751       title : _this._strings['0a9e8bd9e8b301dfb2c21c355e0b377d'],
752       xns : Roo,
753       xtype : 'GridPanel',
754       listeners : {
755        activate : function() {
756             _this.langpanel = this;
757             if (_this.langgrid) {
758                 _this.langgrid.ds.load({});
759             }
760         }
761       },
762       items : [
763
764       ]
765
766      }
767     ]
768
769    },
770    '|xns' : 'Roo',
771    region : 'center',
772    title : _this._strings['4e7c16d320ae129cc81b296e05748b3a'],
773    xns : Roo,
774    xtype : 'NestedLayoutPanel',
775    items : [
776
777    ]
778
779   };  }
780 });