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