sync
[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               var syncSingleTemplate = function(id){
209                    new Pman.Request({
210                        url : baseURL + '/Roo/Core_template',
211                        method : 'POST',
212                        mask : 'Processing...',
213                        params : {
214                            id : id,
215                            _rescan : 1
216                        }, 
217                        success : function()
218                        {
219                           (function() {
220                                _this.grid.footer.onClick('first');
221                            }).defer(100);
222                        }
223                    });
224                };
225                
226                
227                if(typeof(sn.isRoot) != 'undefined' && sn.isRoot){
228                    Roo.MessageBox.progress("Syncing templates", "Starting");
229                    syncTemplate();
230                    return;
231                }
232                
233                if(typeof(sn.attributes.language) != 'undefined' && sn.attributes.language){
234                    syncLanguage();
235                    return;
236                }
237                
238                 if(typeof(sn.attributes.id) != 'undefined' && sn.attributes.id * 1> 0){
239                    syncSingleTemplate(sn.attributes.id);
240                    return;
241                }
242                
243                
244                
245                
246            }
247          },
248          xns : Roo.Toolbar,
249          '|xns' : 'Roo.Toolbar'
250         },
251         {
252          xtype : 'Fill',
253          xns : Roo.Toolbar,
254          '|xns' : 'Roo.Toolbar'
255         },
256         {
257          xtype : 'Button',
258          text : _this._strings['91412465ea9169dfd901dd5e7c96dd99'] /* Upload */,
259          listeners : {
260           click : function (_self, e)
261            {
262                
263                
264                Pman.Dialog.Image.show({
265                   _url : baseURL + '/Admin/Import/Core_templatestr' 
266                 
267                }, function() {
268                     _this.treepanel.tree.getRootNode().reload();
269                });
270                
271                
272                
273            }
274          },
275          xns : Roo.Toolbar,
276          '|xns' : 'Roo.Toolbar'
277         },
278         {
279          xtype : 'Fill',
280          xns : Roo.Toolbar,
281          '|xns' : 'Roo.Toolbar'
282         },
283         {
284          xtype : 'Button',
285          text : _this._strings['801ab24683a4a8c433c6eb40c48bcd9d'] /* Download */,
286          listeners : {
287           click : function (_self, e)
288            {
289                var tree = _this.treepanel.tree;
290            
291                var sn  = tree.getSelectionModel().getSelectedNode();
292                
293                p = {
294                    csvCols : 'src_id_mdsum,template_id_view_name,template_id_template,src_id_txt,lang,txt',
295                    csvTitles : 'Code,Module,Template,Original,Language,Translation',
296                    limit : 9999,
297                    sort: 'template_id_view_name,template_id_template,src_id_txt',
298                    dir: 'ASC',
299                    active : 1
300                };
301                if (!sn ||  sn.id == 'transtree') {
302                    Roo.MessageBox.alert("Error", "Select language, module or page");
303                    return;
304                }
305                if (typeof(sn.id) == 'number') {
306                    p.template_id = sn.id;
307            
308                }
309                
310                
311                if (typeof(sn.id) == 'string' && sn.id.match(/^table:/)) {
312                    var sns = sn.id.split(':');
313                    p.lang = sns[1];
314                    p.on_table = sns[2];
315                    p.csvCols = 'src_id_mdsum,on_table,on_id,on_col,src_id_txt,lang,txt';
316                    p.csvTitles = 'Code,Table,Table id,Column,Language,Translation';
317                }
318                
319                if (typeof(sn.id) == 'string' && sn.id.match(/^view:/)) {
320                    var sns = sn.id.split(':');
321                    p.lang = sns[1];
322                    p.template_id_view_name = sns[2];
323                    
324                }
325                if (typeof(sn.id) == 'string' &&  sn.id.match(/^lang:/)) {
326                    var sns = sn.id.split(':');
327                    p.lang = sns[1];
328            
329               }
330                // transtree
331                // view: {lang} : {view_name}
332                // lang:
333                 
334                new Pman.Download({
335                    url : baseURL + '/Roo/Core_templatestr',
336                    params : p,
337                    method : 'GET' 
338                });
339                
340                
341                
342                
343                
344            }
345          },
346          xns : Roo.Toolbar,
347          '|xns' : 'Roo.Toolbar'
348         },
349         {
350          xtype : 'Separator',
351          xns : Roo.Toolbar,
352          '|xns' : 'Roo.Toolbar'
353         },
354         {
355          xtype : 'Button',
356          text : _this._strings['4d1c8263ba1036754f8db14a98f9f006'] /* Reload */,
357          listeners : {
358           click : function (_self, e)
359            {
360                _this.treepanel.tree.getRootNode().reload();
361                
362            }
363          },
364          xns : Roo.Toolbar,
365          '|xns' : 'Roo.Toolbar'
366         }
367        ]
368       },
369       tree : {
370        xtype : 'TreePanel',
371        containerScroll : false,
372        rootVisible : true,
373        xns : Roo.tree,
374        '|xns' : 'Roo.tree',
375        root : {
376         xtype : 'AsyncTreeNode',
377         id : 'transtree',
378         text : _this._strings['69fd71b6f79260924a32a45850a13ab7'] /* Translations (rescan this to update strings) */,
379         xns : Roo.tree,
380         '|xns' : 'Roo.tree'
381        },
382        selModel : {
383         xtype : 'DefaultSelectionModel',
384         listeners : {
385          selectionchange : function (_self, node)
386           {
387               Roo.log(node);
388               
389               //if (node.id.split('/').length < 2) {
390               //    return;
391              // }
392               (function() {
393                   _this.grid.footer.onClick('first');
394               }).defer(100);
395               
396           }
397         },
398         xns : Roo.tree,
399         '|xns' : 'Roo.tree'
400        },
401        loader : {
402         xtype : 'TreeLoader',
403         baseParams : { _tree : 1 },
404         dataUrl : baseURL + '/Roo/Core_templatestr',
405         requestMethod : 'GET',
406         listeners : {
407          beforeload : function (This, node, callback)
408           {
409               // set some params.
410               Roo.log(node);
411               this.baseParams._tree = 1;
412               
413               //this.baseParams.category = node.attributes.category;
414           },
415          loadexception : function (This, node, response)
416           {
417               Roo.MessageBox.alert("Error", "Problem loading tree");
418           }
419         },
420         xns : Roo.tree,
421         '|xns' : 'Roo.tree'
422        }
423       }
424      },
425      {
426       xtype : 'GridPanel',
427       background : false,
428       fitContainer : true,
429       fitToframe : true,
430       region : 'center',
431       tableName : 'Page',
432       title : _this._strings['193cfc9be3b995831c6af2fea6650e60'] /* Page */,
433       listeners : {
434        activate : function() {
435             _this.panel = this;
436             if (_this.grid) {
437                 _this.grid.footer.onClick('first');
438             }
439         }
440       },
441       xns : Roo,
442       '|xns' : 'Roo',
443       grid : {
444        xtype : 'EditorGrid',
445        autoExpandColumn : 'txt',
446        clicksToEdit : 1,
447        loadMask : true,
448        listeners : {
449         afteredit : function (e)
450          {
451              e.record.commit();
452          },
453         beforeedit : function (e)
454          {   
455              /*if (e.record.data.src_id_txt.indexOf('<') > -1) {
456                 // console.log("HTML EDITOR!!");
457                  Pman.Dialog.CmsTranslateEditor.show(e.record);
458                  return false;
459              }*/
460              
461              var str=e.record.data.src_id_txt;
462              var patt=/{(.*?)}/g;
463              
464              Roo.log(str.length);
465              
466              
467              if(patt.test(str)){
468                  e.cancel = true;
469                  Pman.Dialog.AdminTranslateTemplates.show(e.record.data, function(v){
470                      Roo.log(v);
471                      e.value = v.txt;
472                      e.record.set('txt', v.txt);
473                      e.record.commit();
474                  });
475                  /*
476                  Roo.MessageBox.prompt('WARNING', 'This text is with {TEMPLATE VARIABLE}, PLEASE BE CAREFUL EDITING. What\'s change? '+str, function(btn, text){
477                      if (btn == 'ok'){
478                          e.value = text;
479                          e.record.set('txt', text);
480                          e.record.commit();
481                      }
482                  });*/
483                  return;
484              }
485              
486              if(str.length > 150){
487                  e.cancel = true;
488                  Pman.Dialog.AdminTranslateTemplates.show(e.record.data, function(v){
489                      e.value = v.txt;
490                      e.record.set('txt', v.txt);
491                      e.record.commit();
492                  });
493                  /*
494                  Roo.MessageBox.prompt('WARNING', 'This text is with {TEMPLATE VARIABLE}, PLEASE BE CAREFUL EDITING. What\'s change? '+str, function(btn, text){
495                      if (btn == 'ok'){
496                          e.value = text;
497                          e.record.set('txt', text);
498                          e.record.commit();
499                      }
500                  });*/
501                  return;
502              }
503              
504          
505              if (e.record.data.txt.replace(/\s+/, '').length) {
506                  return true;
507              }
508              
509              var tl = _this.treepanel.tree.getSelectionModel().getSelectedNode().parentNode.attributes.id;
510              // mapping?
511              
512              tl = (tl == 'zh_HK') ? 'zh-TW' : tl;
513              
514              if (tl == 'en' && !e.value.length) {
515          
516                  e.value = e.record.data.src_id_txt;
517                  e.record.set('txt', e.record.data.src_id_txt);
518                  return true;
519              }
520              
521              Pman.GoogleTranslate(e.record.data.src_id_txt, "en", tl, function(result) {
522                 // Roo.log(result);
523                  _this.grid.activeEditor.setValue(result);
524                  //console.log(result.translation);
525              });
526              
527          
528              
529              return true;
530          },
531         render : function() 
532          {
533              _this.grid = this; 
534              //_this.dialog = Pman.Dialog.FILL_IN
535              if (_this.panel.active) {
536                  this.footer.onClick('first');
537                // this.ds.onc.onClick('first');
538              }
539          },
540         rowdblclick : function (_self, rowIndex, e)
541          {
542              if (!_this.dialog) {
543                  return;
544              }
545              _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
546                  _this.grid.footer.onClick('first');
547              }); 
548          }
549        },
550        xns : Roo.grid,
551        '|xns' : 'Roo.grid',
552        footer : {
553         xtype : 'PagingToolbar',
554         displayInfo : true,
555         displayMsg : _this._strings['e2f9d206562d8f5ea421ad51100f7151'] /* Displaying petition_entry{0} - {1} of {2} */,
556         emptyMsg : _this._strings['9d1ead73e678fa2f51a70a933b0bf017'] /* Not Found */,
557         pageSize : 100,
558         xns : Roo,
559         '|xns' : 'Roo'
560        },
561        toolbar : {
562         xtype : 'Toolbar',
563         xns : Roo,
564         '|xns' : 'Roo',
565         items  : [
566          {
567           xtype : 'TextField',
568           emptyText : _this._strings['e3d388b2c43e5ba0905702620ae2abc1'] /* Search for */,
569           listeners : {
570            render : function (_self)
571             {
572                 _this.searchBox = this;
573             },
574            specialkey : function (_self, e)
575             {
576             _this.grid.footer.onClick('first');
577             }
578           },
579           xns : Roo.form,
580           '|xns' : 'Roo.form'
581          },
582          {
583           xtype : 'Button',
584           cls : 'x-btn-icon',
585           icon : rootURL + '/Pman/templates/images/search.gif',
586           listeners : {
587            click : function (_self, e)
588             {
589             _this.grid.footer.onClick('first');
590             }
591           },
592           xns : Roo.Toolbar,
593           '|xns' : 'Roo.Toolbar'
594          },
595          {
596           xtype : 'Button',
597           cls : 'x-btn-icon',
598           icon : rootURL + '/Pman/templates/images/edit-clear.gif',
599           listeners : {
600            click : function (_self, e)
601             {
602                 _this.searchBox.setValue('');
603                 
604                 _this.grid.footer.onClick('first');
605             }
606           },
607           xns : Roo.Toolbar,
608           '|xns' : 'Roo.Toolbar'
609          }
610         ]
611        },
612        dataSource : {
613         xtype : 'Store',
614         remoteSort : true,
615         sortInfo : { field : 'src_id_txt', direction: 'ASC' },
616         listeners : {
617          beforeload : function (_self, o)
618           {
619              
620               var sn = _this.treepanel.tree.getSelectionModel().getSelectedNode();
621           
622               if (!sn || typeof(sn.attributes) == 'undefined' || typeof(sn.attributes.leaf) == 'undefined' || !sn.attributes.leaf) { 
623                   _this.grid.ds.removeAll();
624                   return false;
625               }
626           
627               o.params = o.params || {};
628               o.params.lang =  sn.parentNode.attributes.id.split(':')[1];
629              
630               o.params.active = 1;
631               o.params['!src_id'] = 0;
632               
633               if (_this.searchBox && _this.searchBox.getValue().length) { 
634                   o.params['_search_txt'] = _this.searchBox.getValue();
635               }
636               
637               
638               if(sn.attributes.on_table){
639                   o.params.on_table = sn.attributes.on_table;
640               } else {
641                    o.params.template_id = sn.attributes.id * 1;
642                }
643               
644           },
645          update : function (_self, rec, operation)
646           {
647               Roo.log(operation);
648               
649               if (operation != 'commit') {
650                   return;
651               }
652               
653           
654               _this.grid.getView().el.mask("Saving");
655               new Pman.Request({
656                   url : baseURL + '/Roo/Core_templatestr',
657                   method: 'POST',
658                   params : {
659                       id : rec.get('id'),
660                       txt : rec.get('txt')
661                   },
662                   success : function()
663                   {
664                       _this.grid.getView().el.unmask();
665                           //g.getDataSource().reload();
666                   },
667                   failure : function()
668                   {
669                       _this.grid.getView().el.unmask();
670                       Roo.MessageBox.alert("Error", "There was a problem saving the data - try reloading");
671                    }
672                       
673               });
674               
675           }
676         },
677         xns : Roo.data,
678         '|xns' : 'Roo.data',
679         proxy : {
680          xtype : 'HttpProxy',
681          method : 'GET',
682          url : baseURL + '/Roo/Core_templatestr.php',
683          xns : Roo.data,
684          '|xns' : 'Roo.data'
685         },
686         reader : {
687          xtype : 'JsonReader',
688          fields : [
689              {
690                  'name': 'id',
691                  'type': 'int'
692              },
693              {
694                  'name': 'shortname',
695                  'type': 'string'
696              }
697             
698          ],
699          id : 'id',
700          root : 'data',
701          totalProperty : 'total',
702          xns : Roo.data,
703          '|xns' : 'Roo.data'
704         }
705        },
706        cm : [
707         {
708          xtype : 'ColumnModel',
709          dataIndex : 'src_id_txt',
710          header : _this._strings['0a52da7a03a6de3beefe54f8c03ad80d'] /* Original */,
711          renderer : function(v,x,r) 
712          {
713              var c = '#666';
714              if (r.data.updated  < r.data.src_id_updated) {
715                  c = 'red';
716              }
717              
718              return String.format('<div style="color:'+c+'";>{0}</div>', v)
719          
720          },
721          width : 300,
722          xns : Roo.grid,
723          '|xns' : 'Roo.grid'
724         },
725         {
726          xtype : 'ColumnModel',
727          dataIndex : 'txt',
728          header : _this._strings['6dd08874f83507e9c7b23f1a46b7fa7c'] /* Translation */,
729          renderer : function(v,x,r) 
730          { 
731          
732              var c = '#666';
733              if (r.data.updated  < r.data.src_id_updated) {
734                  c = 'red';
735              }
736              
737              return String.format('<div style="color:'+c+'";>{0}</div>', v)
738          
739          },
740          width : 200,
741          xns : Roo.grid,
742          '|xns' : 'Roo.grid',
743          editor : {
744           xtype : 'GridEditor',
745           xns : Roo.grid,
746           '|xns' : 'Roo.grid',
747           field : {
748            xtype : 'TextField',
749            allowBlank : false,
750            xns : Roo.form,
751            '|xns' : 'Roo.form'
752           }
753          }
754         },
755         {
756          xtype : 'ColumnModel',
757          dataIndex : 'src_id_mdsum',
758          header : _this._strings['1bc29b36f623ba82aaf6724fd3b16718'] /* md5 */,
759          hidden : true,
760          renderer : function(v,x,r) 
761          {
762              return v ? v : '';
763          
764          },
765          width : 250,
766          xns : Roo.grid,
767          '|xns' : 'Roo.grid'
768         }
769        ]
770       }
771      }
772     ]
773    }
774   };  }
775 });