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