Pman.Tab.BuilderTop.bjs
[Pman.Builder] / Pman.Tab.BuilderTop.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5
6
7 // register the module first
8 Pman.on('beforeload', function()
9 {
10     Pman.register({
11         part :  ["Builder","Top"],
12         modKey : '001-Pman.Tab.BuilderTop',
13         module : Pman.Tab.BuilderTop,
14         region : 'center',
15         parent : Pman.Tab.BuilderTab,
16         name : "Pman.Tab.BuilderTop",
17         disabled : false, 
18         permname: '' 
19     });
20 });
21
22 Pman.Tab.BuilderTop = new Roo.util.Observable({
23
24     panel : false,
25     disabled : false,
26     parentLayout:  false,
27
28     add : function(parentLayout, region)
29     {
30
31         var _this = this;
32         this.parentLayout = parentLayout;
33
34         this.panel = parentLayout.addxtype({
35             xtype: 'ContentPanel',
36             xns: Roo,
37             background : true,
38             fitToFrame : true,
39             region : 'north',
40             toolbar : {
41                 xtype: 'Toolbar',
42                 xns: Roo,
43                 items : [
44                     {
45                         xtype: 'Button',
46                         xns: Roo.Toolbar,
47                         text : "Manage Modules",
48                         menu : {
49                             xtype: 'Menu',
50                             xns: Roo.menu,
51                             items : [
52                                 {
53                                     xtype: 'Item',
54                                     xns: Roo.menu,
55                                     listeners : {
56                                         click : function (_self, e)
57                                         {
58                                             Pman.Dialog.BuilderModule.show({
59                                                  id : 0
60                                             },function(data) {
61                                                 if (data) {
62                                                    _this.modsel.setFromData(data);
63                                                 }
64                                             });
65                                         
66                                         }
67                                     },
68                                     text : "Create",
69                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
70                                 },
71                                 {
72                                     xtype: 'Item',
73                                     xns: Roo.menu,
74                                     listeners : {
75                                         click : function (_self, e)
76                                         {
77                                          
78                                             if (!_this.modsel.getValue()) {
79                                                 Roo.MessageBox.alert("Error", "Select Module");
80                                                 return false;
81                                             }
82                                             Pman.Dialog.BuilderModule.show( { id : _this.modsel.getValue() } ,function(data) {
83                                                 if (data) {
84                                                     _this.modsel.setFromData(data);
85                                                 }
86                                             });
87                                         
88                                         }
89                                     },
90                                     text : "Edit"
91                                 },
92                                 {
93                                     xtype: 'Item',
94                                     xns: Roo.menu,
95                                     listeners : {
96                                         click : function (_self, e)
97                                         {
98                                            
99                                         
100                                         }
101                                     },
102                                     text : "Delete"
103                                 },
104                                 {
105                                     xtype: 'Separator',
106                                     xns: Roo.menu
107                                 },
108                                 {
109                                     xtype: 'Item',
110                                     xns: Roo.menu,
111                                     listeners : {
112                                         click : function (_self, e)
113                                         {
114                                             new Pman.Request({
115                                                 method : 'GET',
116                                                 url : baseURL + '/Roo/Builder_modules.php',
117                                                 params : 'query[_sync]',
118                                                 success : function() {
119                                                     Roo.MessageBox.alert("Re-syned modules");
120                                                 }
121                                             });
122                                         }
123                                     },
124                                     text : "Sync"
125                                 }
126                             ]
127                         }
128                     },
129                     {
130                         xtype: 'ComboBox',
131                         xns: Roo.form,
132                         listeners : {
133                             select : function (combo, record, index)
134                             {
135                                 _this.filesel.reset();
136                                 _this.filesel.fireEvent('select', false);
137                             
138                             },
139                             render : function (_self)
140                             {
141                                 _this.modsel = this;
142                             }
143                         },
144                         allowBlank : true,
145                         alwaysQuery : true,
146                         displayField : 'name',
147                         editable : false,
148                         forceSelection : true,
149                         listWidth : 300,
150                         loadingText : "Searching...",
151                         minChars : 2,
152                         pageSize : 40,
153                         queryParam : 'query[name]',
154                         selectOnFocus : true,
155                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b></div>',
156                         triggerAction : 'all',
157                         typeAhead : true,
158                         valueField : 'id',
159                         width : 100,
160                         store : {
161                             xtype: 'Store',
162                             xns: Roo.data,
163                             remoteSort : true,
164                             sortInfo : { field : 'name' , direction : 'ASC' },
165                             proxy : {
166                                 xtype: 'HttpProxy',
167                                 xns: Roo.data,
168                                 method : 'GET',
169                                 url : baseURL + '/Roo/Builder_modules.php'
170                             },
171                             reader : {
172                                 xtype: 'JsonReader',
173                                 xns: Roo.data,
174                                 id : 'id',
175                                 root : 'data',
176                                 totalProperty : 'total',
177                                 fields : [
178                                  
179                                     {
180                                         'name': 'name',
181                                         'type': 'string'
182                                     }
183                                     
184                                 ]
185                             }
186                         }
187                     },
188                     {
189                         xtype: 'Button',
190                         xns: Roo.Toolbar,
191                         text : "Manage Parts ",
192                         menu : {
193                             xtype: 'Menu',
194                             xns: Roo.menu,
195                             items : [
196                                 {
197                                     xtype: 'Item',
198                                     xns: Roo.menu,
199                                     listeners : {
200                                         click : function (_self, e)
201                                         {
202                                             if (!_this.modsel.getValue()) {
203                                                 Roo.MessageBox.alert("Error", "Select Module");
204                                                 return false;
205                                             }
206                                             
207                                             Pman.Dialog.BuilderPart.show( {
208                                                      id : 0, 
209                                                      module_id: _this.modsel.getValue() 
210                                                  } ,
211                                                  function(data) {
212                                                     _this.filesel.reset();
213                                                     if (!data.id) {
214                                                         return;
215                                                     }
216                                                     _this.filesel.setfromdata(data);
217                                                     Pman.Tab.BuilderTree.clearAll();
218                                                     Pman.Tab.BuilderTree.setCurrentNode(Pman.Tab.BuilderTree.tree.root,true);
219                                                     
220                                                     var bp = Pman.Tab.BuilderPanel;
221                                                     bp.redraw.defer(100,bp,[true]);
222                                             });
223                                         
224                                         }
225                                     },
226                                     text : "New Part",
227                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
228                                 },
229                                 {
230                                     xtype: 'Item',
231                                     xns: Roo.menu,
232                                     text : "Delete"
233                                 }
234                             ]
235                         }
236                     },
237                     {
238                         xtype: 'ComboBox',
239                         xns: Roo.form,
240                         listeners : {
241                             select : function (combo, rec, index)
242                             {
243                                //cb.lastData = rec.data;
244                                 
245                                 
246                                 
247                                 
248                                 var bt = Pman.Tab.BuilderTree.tree;
249                                 
250                                 
251                                 if (!rec) {
252                                     bt.clearAll();
253                                     bt.setCurrentNode(bt.root,true);
254                                    // var bv = Pman.Tab.BuilderView;
255                                    Pman.Tab.BuilderView.panel.clearAll();
256                                    // bv.panel.el.mask("select Module / Part");
257                                     return;
258                                 }
259                                 //bv.panel.el.unmask();
260                                 
261                                 bt.loadBJS(_this.modsel.getValue(), rec.data.id)
262                             
263                             
264                             },
265                             render : function (_self)
266                             {
267                                 _this.filesel = this;
268                             }
269                         },
270                         allowBlank : true,
271                         alwaysQuery : true,
272                         displayField : 'name',
273                         editable : false,
274                         forceSelection : true,
275                         listWidth : 400,
276                         loadingText : "Searching...",
277                         minChars : 2,
278                         pageSize : 40,
279                         queryParam : 'query[name]',
280                         selectOnFocus : true,
281                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b></div>',
282                         triggerAction : 'all',
283                         typeAhead : true,
284                         valueField : 'id',
285                         width : 200,
286                         store : {
287                             xtype: 'Store',
288                             xns: Roo.data,
289                             listeners : {
290                                 beforeload : function (_self, o)
291                                 {
292                                      o.params = o.params || {}; 
293                                    // o.params.btype = 'FORM';
294                                     if (!_this.modsel.getValue()) {
295                                         Roo.MessageBox.alert("Error", "Select Module");
296                                         return false;
297                                     }
298                                     o.params.module_id = _this.modsel.getValue();
299                                     o.params._columns = 'id,name';
300                                 }
301                             },
302                             remoteSort : true,
303                             sortInfo : { field : 'name' , direction : 'ASC' },
304                             proxy : {
305                                 xtype: 'HttpProxy',
306                                 xns: Roo.data,
307                                 method : 'GET',
308                                 url : baseURL + '/Roo/Builder_part.php'
309                             },
310                             reader : {
311                                 xtype: 'JsonReader',
312                                 xns: Roo.data,
313                                 id : 'id',
314                                 root : 'data',
315                                 totalProperty : 'total',
316                                 fields : [
317                                    
318                                     {
319                                         'name': 'name',
320                                         'type': 'string'
321                                     } 
322                                 ]
323                             }
324                         }
325                     },
326                     {
327                         xtype: 'Button',
328                         xns: Roo.Toolbar,
329                         listeners : {
330                             click : function (_self, e)
331                             {
332                                 this.save();
333                             },
334                             render : function (_self)
335                             {
336                                _this.saveBtn = this;
337                             }
338                         },
339                         cls : 'x-btn-text-icon',
340                         text : "Save",
341                         save : function() {
342                                // first see if first element has a name.. - we can not save otherwise..
343                                 var t = Pman.Tab.BuilderTree.tree;
344                                 if (!t.root.elConfig.name.length) {
345                                     Roo.MessageBox.alert("Error", "No name set for form");
346                                     return;
347                                 }
348                              
349                                 sid = (typeof(sid) == 'undefined') ?  (this.filesel.lastData ? this.filesel.lastData.id : 0) : sid;
350                                 
351                                 var js = Pman.Tab.BuilderTree.toJS();
352                                 var json = Roo.encode(js);
353                                // console.log(js);
354                                // console.log(json);
355                                 
356                                 // check the select box to see if that has been set... - save it with that id..
357                                 
358                                 var _this = this;
359                                 
360                                 Pman.request({
361                                     url: baseURL + '/Roo/Builder.php',
362                                     method : 'POST',
363                                     params : {
364                                         json : json,
365                                         name : t.root.elConfig.name,
366                                         module : t.root.elConfig['|module'],
367                                         app : t.root.elConfig.app,
368                                         btype : 'FORM',
369                                         id : sid
370                                     }, 
371                                     success : function(data) {
372                                         // set the fileSel!!
373                                         console.log(data);
374                                         if (data) {
375                                             _this.filesel.setFromData(data);
376                                             if (cb) {
377                                                 cb.call(_this,data);
378                                             }
379                                             _this.postCode(data);
380                                         }
381                                     }
382                                 });
383                         },
384                         icon : rootURL + '/Pman/templates/images/save.gif',
385                         menu : {
386                             xtype: 'Menu',
387                             xns: Roo.menu,
388                             items : [
389                                 {
390                                     xtype: 'Item',
391                                     xns: Roo.menu,
392                                     listeners : {
393                                         click : function (_self, e)
394                                         {
395                                           _this.saveBtn.save(false,0);
396                                         }
397                                     },
398                                     icon : rootURL + '/Pman/templates/images/save.gif',
399                                     text : "Save a copy as"
400                                 },
401                                 {
402                                     xtype: 'Item',
403                                     xns: Roo.menu,
404                                     listeners : {
405                                         click : function (_self, e)
406                                         {
407                                            _this.saveBtn.save(
408                                              function() {
409                                                  Pman.Dialog.BuilderViewCode.show({ id : _this.filesel.getValue() } ); 
410                                                     
411                                         
412                                           } );
413                                         }
414                                     },
415                                     text : "Show JSON"
416                                 }
417                             ]
418                         }
419                     },
420                     {
421                         xtype: 'Separator',
422                         xns: Roo.Toolbar
423                     },
424                     {
425                         xtype: 'SplitButton',
426                         xns: Roo.Toolbar,
427                         listeners : {
428                             click : function (_self, e)
429                             {
430                                Pman.Tab.BuilderView.panel.redraw();
431                             }
432                         },
433                         text : "Redraw",
434                         menu : {
435                             xtype: 'Menu',
436                             xns: Roo.menu,
437                             items : [
438                                 {
439                                     xtype: 'Item',
440                                     xns: Roo.menu,
441                                     listeners : {
442                                         click : function (_self, e)
443                                         {
444                                          _this.redrawBtn.setText("Redraw (AUTO OFF)");
445                                             _this.redrawBtn.auto = 0;
446                                         
447                                         }
448                                     },
449                                     text : "Auto redraw - OFF"
450                                 },
451                                 {
452                                     xtype: 'Item',
453                                     xns: Roo.menu,
454                                     listeners : {
455                                         click : function (_self, e)
456                                         {
457                                          
458                                             _this.redrawBtn.setText("Redraw");
459                                              _this.redrawBtn.auto = 1;
460                                             var bp = Pman.Tab.BuilderPanel;
461                                             bp.redraw.defer(100,bp,[true]);
462                                             
463                                         
464                                         }
465                                     },
466                                     text : "Auto redraw - On"
467                                 }
468                             ]
469                         }
470                     }
471                 ]
472             }
473         });
474         this.layout = this.panel.layout;
475
476     }
477 });