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