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