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