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