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