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