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