Fix #6494 - translations code for reports
[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   '0b8d92bc19b720bb1065649535463409' :"Translations",
12   '69fd71b6f79260924a32a45850a13ab7' :"Translations (rescan this to update strings)",
13   '9d1ead73e678fa2f51a70a933b0bf017' :"Not Found",
14   '801ab24683a4a8c433c6eb40c48bcd9d' :"Download",
15   '6dd08874f83507e9c7b23f1a46b7fa7c' :"Translation",
16   'e3d388b2c43e5ba0905702620ae2abc1' :"Search for",
17   'e2f9d206562d8f5ea421ad51100f7151' :"Displaying petition_entry{0} - {1} of {2}",
18   'cd6ae20e52d83f601c5fa12b66f0f6d0' :"Rescan",
19   '4d1c8263ba1036754f8db14a98f9f006' :"Reload",
20   'f2a6c498fb90ee345d997f888fce3b18' :"Delete",
21   '03c2e7e41ffc181a4e84080b4710e81e' :"New",
22   '193cfc9be3b995831c6af2fea6650e60' :"Page",
23   '1bc29b36f623ba82aaf6724fd3b16718' :"md5"
24  },
25
26   part     :  ["Admin", "Translations" ],
27   order    : '950-Pman.Tab.AdminTranslations',
28   region   : 'center',
29   parent   : 'Pman.Tab.Admin',
30   name     : "Admin - Translations",
31   disabled : false, 
32   permname : 'Admin.Translations', 
33   _tree : function(_data)
34   {
35    var _this = this;
36    var MODULE = this;
37    return {
38    xtype : 'NestedLayoutPanel',
39    region : 'center',
40    title : _this._strings['0b8d92bc19b720bb1065649535463409'] /* Translations */,
41    xns : Roo,
42    '|xns' : 'Roo',
43    layout : {
44     xtype : 'BorderLayout',
45     xns : Roo,
46     '|xns' : 'Roo',
47     center : {
48      xtype : 'LayoutRegion',
49      xns : Roo,
50      '|xns' : 'Roo'
51     },
52     west : {
53      xtype : 'LayoutRegion',
54      split : true,
55      width : 450,
56      xns : Roo,
57      '|xns' : 'Roo'
58     },
59     items  : [
60      {
61       xtype : 'TreePanel',
62       region : 'west',
63       listeners : {
64        render : function (_self)
65         {
66             _this.treepanel = _self;
67         }
68       },
69       xns : Roo,
70       '|xns' : 'Roo',
71       toolbar : {
72        xtype : 'Toolbar',
73        xns : Roo,
74        '|xns' : 'Roo',
75        items  : [
76         {
77          xtype : 'Button',
78          text : _this._strings['03c2e7e41ffc181a4e84080b4710e81e'] /* New */,
79          listeners : {
80           click : function (_self, e)
81            {
82                Pman.Dialog.AdminLanguagePick.show( {  }, function(lang) {
83                    
84                    new Pman.Request({
85                        url : baseURL + '/Roo/core_templatestr',
86                        method : 'POST',
87                        params : {
88                            _rescan : lang
89                        }, 
90                        success : function()
91                        {
92                            _this.treepanel.tree.getRootNode().reload();
93                        }
94                    });
95                
96                });
97                
98            }
99          },
100          xns : Roo.Toolbar,
101          '|xns' : 'Roo.Toolbar'
102         },
103         {
104          xtype : 'Separator',
105          xns : Roo.Toolbar,
106          '|xns' : 'Roo.Toolbar'
107         },
108         {
109          xtype : 'Button',
110          text : _this._strings['f2a6c498fb90ee345d997f888fce3b18'] /* Delete */,
111          listeners : {
112           click : function (_self, e)
113            {
114                var tree = _this.treepanel.tree;
115                var sn  = tree.getSelectionModel().getSelectedNode();
116            
117                if (!sn || typeof(sn.attributes.language) == 'undefined' || !sn.attributes.language) {
118                    Roo.MessageBox.alert("Error", "Select a language");
119                    return;
120                }
121            
122                 Roo.MessageBox.confirm("Confirm", "Are sure you want to delete the language", function (v){
123                        if (v != 'yes') {
124                            return;
125                        }
126                        Roo.MessageBox.alert("Not yet", "not done yet");
127                        return;
128                        
129                        
130                        
131                        
132                    });
133            }
134          },
135          xns : Roo.Toolbar,
136          '|xns' : 'Roo.Toolbar'
137         },
138         {
139          xtype : 'Separator',
140          xns : Roo.Toolbar,
141          '|xns' : 'Roo.Toolbar'
142         },
143         {
144          xtype : 'Button',
145          text : _this._strings['cd6ae20e52d83f601c5fa12b66f0f6d0'] /* Rescan */,
146          listeners : {
147           click : function (_self, e)
148            {
149                var tree = _this.treepanel.tree;
150                Roo.log(tree);
151                var sn  = tree.getSelectionModel().getSelectedNode();
152            
153                if (!sn) {
154                    Roo.MessageBox.alert("Error", "Select a node");
155                    return;
156                }
157                
158                var syncTemplate = function(){
159                    new Pman.Request({
160                        url : baseURL + '/Admin/UpdateBjsTemplates',
161                        method : 'GET',
162                        mask : 'Processing...',
163                        timeout : 9000000,
164                        success : function()
165                        {
166                            _this.treepanel.tree.getRootNode().reload();
167                        }
168                    });
169                
170                };
171                
172                
173                var syncLanguage = function(){
174                    new Pman.Request({
175                        url : baseURL + '/Roo/Core_templatestr',
176                        method : 'POST',
177                        mask : 'Processing...',
178                        params : {
179                            _rescan : sn.attributes.id.split(':')[1]
180                        }, 
181                        success : function()
182                        {
183                            _this.treepanel.tree.getRootNode().reload();
184                        }
185                    });
186                };
187                
188                if(typeof(sn.isRoot) != 'undefined' && sn.isRoot){
189                    syncTemplate();
190                    return;
191                }
192                
193                if(typeof(sn.attributes.language) != 'undefined' && sn.attributes.language){
194                    syncLanguage();
195                    return;
196                }
197                
198                
199                
200                
201                
202            }
203          },
204          xns : Roo.Toolbar,
205          '|xns' : 'Roo.Toolbar'
206         },
207         {
208          xtype : 'Fill',
209          xns : Roo.Toolbar,
210          '|xns' : 'Roo.Toolbar'
211         },
212         {
213          xtype : 'Button',
214          text : _this._strings['801ab24683a4a8c433c6eb40c48bcd9d'] /* Download */,
215          listeners : {
216           click : function (_self, e)
217            {
218                var tree = _this.treepanel.tree;
219            
220                var sn  = tree.getSelectionModel().getSelectedNode();
221                
222                p = {
223                    csvCols : 'src_id_mdsum,template_id_view_name,template_id_template,src_id_txt,lang,txt',
224                    csvTitles : 'Code,Module,Template,Original,Language,Translation',
225                    limit : 9999,
226                    sort: 'template_id_view_name,template_id_template,src_id_txt',
227                    dir: 'ASC'
228                };
229                if (!sn ||  sn.id == 'transtree') {
230                    Roo.MessageBox.alert("Error", "Select language, module or page");
231                    return;
232                }
233                if (typeof(sn.id) == 'number') {
234                    p.template_id = sn.id;
235            
236                }
237                if (sn.id.match(/^view:/)) {
238                    var sns = sn.id.split(':');
239                    p.lang = sns[1];
240                    p.template_id_view_name = sns[2];
241                }
242                if (sn.id.match(/^lang:/)) {
243                    var sns = sn.id.split(':');
244                    p.lang = sns[1];
245            
246               }
247                // transtree
248                // view: {lang} : {view_name}
249                // lang:
250                 
251                new Pman.Download({
252                    url : baseURL + '/Roo/Core_templatestr',
253                    params : p,
254                    method : 'GET' 
255                });
256                
257                
258                
259                
260                
261            }
262          },
263          xns : Roo.Toolbar,
264          '|xns' : 'Roo.Toolbar'
265         },
266         {
267          xtype : 'Separator',
268          xns : Roo.Toolbar,
269          '|xns' : 'Roo.Toolbar'
270         },
271         {
272          xtype : 'Button',
273          text : _this._strings['4d1c8263ba1036754f8db14a98f9f006'] /* Reload */,
274          listeners : {
275           click : function (_self, e)
276            {
277                _this.treepanel.tree.getRootNode().reload();
278                
279            }
280          },
281          xns : Roo.Toolbar,
282          '|xns' : 'Roo.Toolbar'
283         }
284        ]
285       },
286       tree : {
287        xtype : 'TreePanel',
288        containerScroll : false,
289        rootVisible : true,
290        xns : Roo.tree,
291        '|xns' : 'Roo.tree',
292        root : {
293         xtype : 'AsyncTreeNode',
294         id : 'transtree',
295         text : _this._strings['69fd71b6f79260924a32a45850a13ab7'] /* Translations (rescan this to update strings) */,
296         xns : Roo.tree,
297         '|xns' : 'Roo.tree'
298        },
299        selModel : {
300         xtype : 'DefaultSelectionModel',
301         listeners : {
302          selectionchange : function (_self, node)
303           {
304               Roo.log(node);
305               
306               //if (node.id.split('/').length < 2) {
307               //    return;
308              // }
309               (function() {
310                   _this.grid.footer.onClick('first');
311               }).defer(100);
312               
313           }
314         },
315         xns : Roo.tree,
316         '|xns' : 'Roo.tree'
317        },
318        loader : {
319         xtype : 'TreeLoader',
320         baseParams : { _tree : 1 },
321         dataUrl : baseURL + '/Roo/Core_templatestr',
322         requestMethod : 'GET',
323         listeners : {
324          beforeload : function (This, node, callback)
325           {
326               // set some params.
327               Roo.log(node);
328               this.baseParams._tree = 1;
329               
330               //this.baseParams.category = node.attributes.category;
331           },
332          loadexception : function (This, node, response)
333           {
334               Roo.MessageBox.alert("Error", "Problem loading tree");
335           }
336         },
337         xns : Roo.tree,
338         '|xns' : 'Roo.tree'
339        }
340       }
341      },
342      {
343       xtype : 'GridPanel',
344       background : false,
345       fitContainer : true,
346       fitToframe : true,
347       region : 'center',
348       tableName : 'Page',
349       title : _this._strings['193cfc9be3b995831c6af2fea6650e60'] /* Page */,
350       listeners : {
351        activate : function() {
352             _this.panel = this;
353             if (_this.grid) {
354                 _this.grid.footer.onClick('first');
355             }
356         }
357       },
358       xns : Roo,
359       '|xns' : 'Roo',
360       grid : {
361        xtype : 'EditorGrid',
362        autoExpandColumn : 'txt',
363        clicksToEdit : 1,
364        loadMask : true,
365        listeners : {
366         afteredit : function (e)
367          {
368              e.record.commit();
369          },
370         beforeedit : function (e)
371          {   
372              /*if (e.record.data.src_id_txt.indexOf('<') > -1) {
373                 // console.log("HTML EDITOR!!");
374                  Pman.Dialog.CmsTranslateEditor.show(e.record);
375                  return false;
376              }*/
377              
378              var str=e.record.data.src_id_txt;
379              var patt=/{(.*?)}/g;
380              
381              Roo.log(str.length);
382              
383              
384              if(patt.test(str)){
385                  e.cancel = true;
386                  Pman.Dialog.AdminTranslateTemplates.show(e.record.data, function(v){
387                      Roo.log(v);
388                      e.value = v.txt;
389                      e.record.set('txt', v.txt);
390                      e.record.commit();
391                  });
392                  /*
393                  Roo.MessageBox.prompt('WARNING', 'This text is with {TEMPLATE VARIABLE}, PLEASE BE CAREFUL EDITING. What\'s change? '+str, function(btn, text){
394                      if (btn == 'ok'){
395                          e.value = text;
396                          e.record.set('txt', text);
397                          e.record.commit();
398                      }
399                  });*/
400                  return;
401              }
402              
403              if(str.length > 150){
404                  e.cancel = true;
405                  Pman.Dialog.AdminTranslateTemplates.show(e.record.data, function(v){
406                      e.value = v.txt;
407                      e.record.set('txt', v.txt);
408                      e.record.commit();
409                  });
410                  /*
411                  Roo.MessageBox.prompt('WARNING', 'This text is with {TEMPLATE VARIABLE}, PLEASE BE CAREFUL EDITING. What\'s change? '+str, function(btn, text){
412                      if (btn == 'ok'){
413                          e.value = text;
414                          e.record.set('txt', text);
415                          e.record.commit();
416                      }
417                  });*/
418                  return;
419              }
420              
421          
422              if (e.record.data.txt.replace(/\s+/, '').length) {
423                  return true;
424              }
425              
426              var tl = _this.treepanel.tree.getSelectionModel().getSelectedNode().parentNode.attributes.id;
427              // mapping?
428              
429              tl = (tl == 'zh_HK') ? 'zh-TW' : tl;
430              
431              if (tl == 'en' && !e.value.length) {
432          
433                  e.value = e.record.data.src_id_txt;
434                  e.record.set('txt', e.record.data.src_id_txt);
435                  return true;
436              }
437              
438              Pman.GoogleTranslate(e.record.data.src_id_txt, "en", tl, function(result) {
439                 // Roo.log(result);
440                  _this.grid.activeEditor.setValue(result);
441                  //console.log(result.translation);
442              });
443              
444          
445              
446              return true;
447          },
448         render : function() 
449          {
450              _this.grid = this; 
451              //_this.dialog = Pman.Dialog.FILL_IN
452              if (_this.panel.active) {
453                  this.footer.onClick('first');
454                // this.ds.onc.onClick('first');
455              }
456          },
457         rowdblclick : function (_self, rowIndex, e)
458          {
459              if (!_this.dialog) {
460                  return;
461              }
462              _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
463                  _this.grid.footer.onClick('first');
464              }); 
465          }
466        },
467        xns : Roo.grid,
468        '|xns' : 'Roo.grid',
469        footer : {
470         xtype : 'PagingToolbar',
471         displayInfo : true,
472         displayMsg : _this._strings['e2f9d206562d8f5ea421ad51100f7151'] /* Displaying petition_entry{0} - {1} of {2} */,
473         emptyMsg : _this._strings['9d1ead73e678fa2f51a70a933b0bf017'] /* Not Found */,
474         pageSize : 100,
475         xns : Roo,
476         '|xns' : 'Roo'
477        },
478        toolbar : {
479         xtype : 'Toolbar',
480         xns : Roo,
481         '|xns' : 'Roo',
482         items  : [
483          {
484           xtype : 'TextField',
485           emptyText : _this._strings['e3d388b2c43e5ba0905702620ae2abc1'] /* Search for */,
486           listeners : {
487            render : function (_self)
488             {
489                 _this.searchBox = this;
490             },
491            specialkey : function (_self, e)
492             {
493             _this.grid.footer.onClick('first');
494             }
495           },
496           xns : Roo.form,
497           '|xns' : 'Roo.form'
498          },
499          {
500           xtype : 'Button',
501           cls : 'x-btn-icon',
502           icon : rootURL + '/Pman/templates/images/search.gif',
503           listeners : {
504            click : function (_self, e)
505             {
506             _this.grid.footer.onClick('first');
507             }
508           },
509           xns : Roo.Toolbar,
510           '|xns' : 'Roo.Toolbar'
511          },
512          {
513           xtype : 'Button',
514           cls : 'x-btn-icon',
515           icon : rootURL + '/Pman/templates/images/edit-clear.gif',
516           listeners : {
517            click : function (_self, e)
518             {
519                 _this.searchBox.setValue('');
520                 
521                 _this.grid.footer.onClick('first');
522             }
523           },
524           xns : Roo.Toolbar,
525           '|xns' : 'Roo.Toolbar'
526          }
527         ]
528        },
529        dataSource : {
530         xtype : 'Store',
531         remoteSort : true,
532         sortInfo : { field : 'src_id_txt', direction: 'ASC' },
533         listeners : {
534          beforeload : function (_self, o)
535           {
536              
537               var sn = _this.treepanel.tree.getSelectionModel().getSelectedNode();
538           
539               if (!sn || typeof(sn.attributes) == 'undefined' || typeof(sn.attributes.leaf) == 'undefined' || !sn.attributes.leaf) { 
540                   _this.grid.ds.removeAll();
541                   return false;
542               }
543           
544               o.params = o.params || {};
545               o.params.lang =  sn.parentNode.attributes.id.split(':')[1];
546               o.params.template_id = sn.attributes.id * 1;
547               o.params.active = 1;
548               o.params['!src_id'] = 0;
549               
550               if (_this.searchBox && _this.searchBox.getValue().length) { 
551                   o.params['_search_txt'] = _this.searchBox.getValue();
552               }
553               
554               
555               if(sn.attributes.on_table){
556                   o.params.on_table = sn.attributes.on_table;
557               }
558               
559           },
560          update : function (_self, rec, operation)
561           {
562               Roo.log(operation);
563               
564               if (operation != 'commit') {
565                   return;
566               }
567               
568           
569               _this.grid.getView().el.mask("Saving");
570               new Pman.Request({
571                   url : baseURL + '/Roo/Core_templatestr',
572                   method: 'POST',
573                   params : {
574                       id : rec.get('id'),
575                       txt : rec.get('txt')
576                   },
577                   success : function()
578                   {
579                       _this.grid.getView().el.unmask();
580                           //g.getDataSource().reload();
581                   },
582                   failure : function()
583                   {
584                       _this.grid.getView().el.unmask();
585                       Roo.MessageBox.alert("Error", "There was a problem saving the data - try reloading");
586                    }
587                       
588               });
589               
590           }
591         },
592         xns : Roo.data,
593         '|xns' : 'Roo.data',
594         proxy : {
595          xtype : 'HttpProxy',
596          method : 'GET',
597          url : baseURL + '/Roo/Core_templatestr.php',
598          xns : Roo.data,
599          '|xns' : 'Roo.data'
600         },
601         reader : {
602          xtype : 'JsonReader',
603          fields : [
604              {
605                  'name': 'id',
606                  'type': 'int'
607              },
608              {
609                  'name': 'shortname',
610                  'type': 'string'
611              }
612             
613          ],
614          id : 'id',
615          root : 'data',
616          totalProperty : 'total',
617          xns : Roo.data,
618          '|xns' : 'Roo.data'
619         }
620        },
621        cm : [
622         {
623          xtype : 'ColumnModel',
624          dataIndex : 'src_id_txt',
625          header : _this._strings['0a52da7a03a6de3beefe54f8c03ad80d'] /* Original */,
626          renderer : function(v,x,r) 
627          {
628              var c = '#666';
629              if (r.data.updated  < r.data.src_id_updated) {
630                  c = 'red';
631              }
632              
633              return String.format('<div style="color:'+c+'";>{0}</div>', v)
634          
635          },
636          width : 300,
637          xns : Roo.grid,
638          '|xns' : 'Roo.grid'
639         },
640         {
641          xtype : 'ColumnModel',
642          dataIndex : 'txt',
643          header : _this._strings['6dd08874f83507e9c7b23f1a46b7fa7c'] /* Translation */,
644          renderer : function(v,x,r) 
645          { 
646          
647              var c = '#666';
648              if (r.data.updated  < r.data.src_id_updated) {
649                  c = 'red';
650              }
651              
652              return String.format('<div style="color:'+c+'";>{0}</div>', v)
653          
654          },
655          width : 200,
656          xns : Roo.grid,
657          '|xns' : 'Roo.grid',
658          editor : {
659           xtype : 'GridEditor',
660           xns : Roo.grid,
661           '|xns' : 'Roo.grid',
662           field : {
663            xtype : 'TextField',
664            allowBlank : false,
665            xns : Roo.form,
666            '|xns' : 'Roo.form'
667           }
668          }
669         },
670         {
671          xtype : 'ColumnModel',
672          dataIndex : 'src_id_mdsum',
673          header : _this._strings['1bc29b36f623ba82aaf6724fd3b16718'] /* md5 */,
674          hidden : true,
675          renderer : function(v,x,r) 
676          {
677              return v ? v : '';
678          
679          },
680          width : 250,
681          xns : Roo.grid,
682          '|xns' : 'Roo.grid'
683         }
684        ]
685       }
686      }
687     ]
688    }
689   };  }
690 });