Pman.Tab.BuilderDatabase.bjs
[Pman.Builder] / Pman.Tab.BuilderDatabase.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","Database"],
12         modKey : '999-Pman.Tab.BuilderDatabase',
13         module : Pman.Tab.BuilderDatabase,
14         region : 'center',
15         parent : Pman.Tab.Builder,
16         name : "Pman.Tab.BuilderDatabase",
17         disabled : false, 
18         permname: '' 
19     });
20 });
21
22 Pman.Tab.BuilderDatabase = 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: 'NestedLayoutPanel',
36             xns: Roo,
37             listeners : {
38                 activate : function (_self)
39                 {
40                  _this.treepanel.tree.root.reload();
41                 }
42             },
43             background : true,
44             region : 'center',
45             title : "Manage Database",
46             layout : {
47                 xtype: 'BorderLayout',
48                 xns: Roo,
49                 items : [
50                     {
51                         xtype: 'TreePanel',
52                         xns: Roo,
53                         listeners : {
54                             render : function (_self)
55                             {
56                                _this.treepanel = _self;
57                             }
58                         },
59                         region : 'west',
60                         toolbar : {
61                             xtype: 'Toolbar',
62                             xns: Roo,
63                             items : [
64                                 {
65                                     xtype: 'SplitButton',
66                                     xns: Roo.Toolbar,
67                                     listeners : {
68                                         click : function (_self, e)
69                                         {
70                                          _this.treepanel.tree.root.reload();
71                                         }
72                                     },
73                                     text : "Refresh/Manage Tables",
74                                     menu : {
75                                         xtype: 'Menu',
76                                         xns: Roo.menu,
77                                         items : [
78                                             {
79                                                 xtype: 'Item',
80                                                 xns: Roo.menu,
81                                                 text : "Add Table/Container"
82                                             },
83                                             {
84                                                 xtype: 'Separator',
85                                                 xns: Roo.menu
86                                             },
87                                             {
88                                                 xtype: 'Item',
89                                                 xns: Roo.menu,
90                                                 listeners : {
91                                                     click : function (_self, e)
92                                                     {
93                                                         new Pman.Request({
94                                                             method: 'GET',
95                                                             url: baseURL + '/Roo/Builder_tables.php',
96                                                             params : {
97                                                                  _sync : 1
98                                                             }
99                                                         });
100                                                             
101                                                     }
102                                                 },
103                                                 text : "Sync Tables"
104                                             }
105                                         ]
106                                     }
107                                 }
108                             ]
109                         },
110                         tree : {
111                             xtype: 'TreePanel',
112                             xns: Roo.tree,
113                             listeners : {
114                                 beforeload : function (node)
115                                 {
116                                     if (!_this.panel.active) {
117                                         return false;
118                                     }
119                                 },
120                                 contextmenu : function (node, e)
121                                 {
122                                     if (!node.expanded || node.leaf) {
123                                         return;
124                                     }
125                                 
126                                    _this.treepanel.menu = Roo.factory(_this.treepanel.menu);
127                                    _this.treepanel.menu.show(node.ui.anchor,'tr');
128                                    _this.cxnode = node;
129                                 }
130                             },
131                             containerScroll : true,
132                             ddGroup : 'dbtree',
133                             enableDD : true,
134                             rootVisible : false,
135                             loader : {
136                                 xtype: 'TreeLoader',
137                                 xns: Roo.tree,
138                                 listeners : {
139                                     create : function (_self, attr)
140                                     {
141                                         Roo.log("CREATE");
142                                         try {
143                                             attr.text = attr.name.length ? attr.name : attr.descrip;
144                                             
145                                             attr.leaf = attr.name.length ? true : false;
146                                             attr.html = String.format('<B>{0}</B><i>{1}</i>',
147                                                 attr.name,
148                                                 attr.descrip
149                                             );
150                                         } catch(e) {
151                                             Roo.log(e);
152                                         }
153                                         Roo.log(attr);
154                                     
155                                     }
156                                 },
157                                 queryParam : 'parent_id',
158                                 requestMethod : 'GET',
159                                 root : 'data',
160                                 baseParams : { _tree: 1, 'sort': 'name', dir: 'ASC', limit : 9999 },
161                                 dataUrl : baseURL + '/Roo/Builder_tables.php'
162                             },
163                             root : {
164                                 xtype: 'AsyncTreeNode',
165                                 xns: Roo.tree,
166                                 text : "TOP LEVEL"
167                             },
168                             sm : {
169                                 xtype: 'DefaultSelectionModel',
170                                 xns: Roo.tree
171                             },
172                             editor : {
173                                 xtype: 'TreeEditor',
174                                 xns: Roo.tree,
175                                 listeners : {
176                                     beforenodeedit : function (_self,node)
177                                     {
178                                         Roo.log('before start edit');
179                                         Roo.log(this.editNode);
180                                         if (node.attributes.name.length) {
181                                             return false;
182                                         }
183                                         return true;
184                                         
185                                     },
186                                     complete : function (_self, value, startValue)
187                                     {
188                                         Roo.log(this.editNode);
189                                     
190                                         var attr = this.editNode.attributes;
191                                         
192                                         var pa = this.editNode.parentNode.attributes;
193                                         Roo.log(pa);
194                                         var pr =  {
195                                      
196                                             parent_id : pa.id,
197                                             descrip : this.editNode.text,
198                                             name : ''
199                                         };
200                                             
201                                         if (attr.id > 0) {
202                                             pr.id = attr.id;
203                                         }
204                                         
205                                         new Pman.Request({
206                                             url : baseURL + '/Roo/Builder_tables',
207                                             method : 'POST',
208                                             params : pr
209                                         });
210                                         
211                                         
212                                         
213                                     }
214                                 }
215                             }
216                         },
217                         menu : {
218                             xtype: 'Menu',
219                             xns: Roo.menu,
220                             items : [
221                                 {
222                                     xtype: 'Item',
223                                     xns: Roo.menu,
224                                     listeners : {
225                                         click : function (_self, e)
226                                         {
227                                             _this.nIndex =     _this.nIndex || 0;
228                                             
229                                             var m = _this.cxnode.firstChild ? 'insertBefore' : 'appendChild';
230                                             var tree =  _this.treepanel.tree;
231                                             
232                                             var n = tree.loader.createNode({
233                                                 id : -1,
234                                                 descrip :'New Group ' + (++_this.nIndex), 
235                                                 name : ''
236                                             }); 
237                                             
238                                             var node = _this.cxnode[m]( n , _this.cxnode.firstChild);
239                                             setTimeout(function(){
240                                                     tree.editor.editNode = node;
241                                                     tree.editor.startEdit(node.ui.textNode);
242                                                 }, 10);
243                                         }
244                                     },
245                                     text : "Add Group"
246                                 }
247                             ]
248                         }
249                     },
250                     {
251                         xtype: 'GridPanel',
252                         xns: Roo,
253                         listeners : {
254                             activate : function() {
255                                 _this.panel = this;
256                                 if (_this.grid) {
257                                     _this.grid.footer.onClick('first');
258                                 }
259                             }
260                         },
261                         background : true,
262                         fitContainer : true,
263                         fitToframe : true,
264                         region : 'center',
265                         tableName : 'Tables',
266                         title : "Tables",
267                         grid : {
268                             xtype: 'Grid',
269                             xns: Roo.grid,
270                             listeners : {
271                                 render : function() 
272                                 {
273                                     _this.grid = this; 
274                                     //_this.dialog = Pman.Dialog.FILL_IN
275                                     if (_this.panel.active) {
276                                        this.footer.onClick('first');
277                                     }
278                                 },
279                                 rowdblclick : function (_self, rowIndex, e)
280                                 {
281                                     if (!_this.dialog) return;
282                                     _this.dialog.show( this.getDataSource().getAt(rowIndex), function() {
283                                         _this.grid.footer.onClick('first');
284                                     }); 
285                                 }
286                             },
287                             autoExpandColumn : 'table',
288                             loadMask : true,
289                             dataSource : {
290                                 xtype: 'Store',
291                                 xns: Roo.data,
292                                 remoteSort : true,
293                                 sortInfo : { field : 'filename', direction: 'ASC' },
294                                 proxy : {
295                                     xtype: 'HttpProxy',
296                                     xns: Roo.data,
297                                     method : 'GET',
298                                     url : baseURL + '/Builder/ERM.php'
299                                 },
300                                 reader : {
301                                     xtype: 'JsonReader',
302                                     xns: Roo.data,
303                                     totalProperty : 'total',
304                                     root : 'data',
305                                     id : 'id',
306                                     fields : [
307                                         {
308                                             'name': 'id',
309                                             'type': 'int'
310                                         },
311                                         {
312                                             'name': 'filename',
313                                             'type': 'string'
314                                         },
315                                         {
316                                             'name': 'ontable',
317                                             'type': 'string'
318                                         },
319                                         {
320                                             'name': 'onid',
321                                             'type': 'int'
322                                         },
323                                         {
324                                             'name': 'mimetype',
325                                             'type': 'string'
326                                         },
327                                         {
328                                             'name': 'width',
329                                             'type': 'int'
330                                         },
331                                         {
332                                             'name': 'height',
333                                             'type': 'int'
334                                         },
335                                         {
336                                             'name': 'filesize',
337                                             'type': 'int'
338                                         },
339                                         {
340                                             'name': 'displayorder',
341                                             'type': 'int'
342                                         },
343                                         {
344                                             'name': 'language',
345                                             'type': 'string'
346                                         },
347                                         {
348                                             'name': 'parent_image_id',
349                                             'type': 'int'
350                                         },
351                                         {
352                                             'name': 'created',
353                                             'type': 'date',
354                                             'dateFormat': 'Y-m-d'
355                                         },
356                                         {
357                                             'name': 'imgtype',
358                                             'type': 'string'
359                                         },
360                                         {
361                                             'name': 'linkurl',
362                                             'type': 'string'
363                                         },
364                                         {
365                                             'name': 'descript',
366                                             'type': 'string'
367                                         },
368                                         {
369                                             'name': 'title',
370                                             'type': 'string'
371                                         },
372                                         {
373                                             'name': 'credit',
374                                             'type': 'string'
375                                         },
376                                         {
377                                             'name': 'source',
378                                             'type': 'string'
379                                         },
380                                         {
381                                             'name': 'parent_image_id_id',
382                                             'type': 'int'
383                                         },
384                                         {
385                                             'name': 'parent_image_id_filename',
386                                             'type': 'string'
387                                         },
388                                         {
389                                             'name': 'parent_image_id_ontable',
390                                             'type': 'string'
391                                         },
392                                         {
393                                             'name': 'parent_image_id_onid',
394                                             'type': 'int'
395                                         },
396                                         {
397                                             'name': 'parent_image_id_mimetype',
398                                             'type': 'string'
399                                         },
400                                         {
401                                             'name': 'parent_image_id_width',
402                                             'type': 'int'
403                                         },
404                                         {
405                                             'name': 'parent_image_id_height',
406                                             'type': 'int'
407                                         },
408                                         {
409                                             'name': 'parent_image_id_filesize',
410                                             'type': 'int'
411                                         },
412                                         {
413                                             'name': 'parent_image_id_displayorder',
414                                             'type': 'int'
415                                         },
416                                         {
417                                             'name': 'parent_image_id_language',
418                                             'type': 'string'
419                                         },
420                                         {
421                                             'name': 'parent_image_id_parent_image_id',
422                                             'type': 'int'
423                                         },
424                                         {
425                                             'name': 'parent_image_id_created',
426                                             'type': 'date'
427                                         },
428                                         {
429                                             'name': 'parent_image_id_imgtype',
430                                             'type': 'string'
431                                         },
432                                         {
433                                             'name': 'parent_image_id_linkurl',
434                                             'type': 'string'
435                                         },
436                                         {
437                                             'name': 'parent_image_id_descript',
438                                             'type': 'string'
439                                         },
440                                         {
441                                             'name': 'parent_image_id_title',
442                                             'type': 'string'
443                                         },
444                                         {
445                                             'name': 'parent_image_id_credit',
446                                             'type': 'string'
447                                         },
448                                         {
449                                             'name': 'parent_image_id_source',
450                                             'type': 'string'
451                                         }
452                                     ]
453                                 }
454                             },
455                             footer : {
456                                 xtype: 'PagingToolbar',
457                                 xns: Roo,
458                                 pageSize : 25,
459                                 displayInfo : true,
460                                 displayMsg : "Displaying Images{0} - {1} of {2}",
461                                 emptyMsg : "No Images found"
462                             },
463                             toolbar : {
464                                 xtype: 'Toolbar',
465                                 xns: Roo,
466                                 items : [
467                                     {
468                                         xtype: 'Button',
469                                         xns: Roo.Toolbar,
470                                         listeners : {
471                                             click : function()
472                                             {
473                                                 Roo.MessageBox.alert("Updating", "Updating the cache");
474                                                 new Pman.Request({
475                                                     url : baseURL + '/Core/RefreshDatabaseCache',
476                                                     method : 'GET',
477                                                     success : function() {
478                                                         Roo.MessageBox.hide();
479                                                     }
480                                                 });
481                                             }
482                                         },
483                                         cls : 'x-btn-text-icon',
484                                         text : "Refresh Schema",
485                                         icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
486                                     }
487                                 ]
488                             },
489                             colModel : [
490                                 {
491                                     xtype: 'ColumnModel',
492                                     xns: Roo.grid,
493                                     dataIndex : 'table',
494                                     header : 'Table',
495                                     width : 200,
496                                     renderer : function(v) { return String.format('{0}', v); }
497                                 }
498                             ]
499                         }
500                     }
501                 ],
502                 west : {
503                     xtype: 'LayoutRegion',
504                     xns: Roo,
505                     split : true,
506                     width : 150
507                 },
508                 center : {
509                     xtype: 'LayoutRegion',
510                     xns: Roo
511                 }
512             }
513         });
514         this.layout = this.panel.layout;
515
516     }
517 });