Pman.Tab.CmsProduct.js
[Pman.Cms] / Pman.Tab.CmsProductCategory.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.CmsProductCategory',
12         module : Pman.Tab.CmsProductCategory,
13         region : 'center',
14         parent : Pman.Tab.CmsProductMgr,
15         name : "Pman.Tab.CmsProductCategory",
16         disabled : false, 
17         permname: '' 
18     });
19 });
20
21 Pman.Tab.CmsProductCategory = 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: 'TreePanel',
35             xns: Roo,
36             listeners : {
37                 activate : function (_self)
38                 {
39                     
40                     _this.panel = _self;
41                 }
42             },
43             autoScroll : true,
44             fitToFrame : true,
45             region : 'west',
46             title : "Category Tree",
47             toolbar : {
48                 xtype: 'Toolbar',
49                 xns: Roo,
50                 items : [
51                     {
52                         xtype: 'Button',
53                         xns: Roo.Toolbar,
54                         text : "Manage Categories",
55                         menu : {
56                             xtype: 'Menu',
57                             xns: Roo.menu,
58                             items : [
59                                 {
60                                     xtype: 'Item',
61                                     xns: Roo.menu,
62                                     listeners : {
63                                         click : function (_self, e)
64                                         {
65                                         
66                                             var sel = _this.panel.tree.getSelectionModel().getSelectedNode();
67                                             var id =  (!sel || isNaN(parseInt(sel.attributes.id))) ? 0 : sel.attributes.id;
68                                         
69                                             if (!id) {
70                                                 var sel = _this.panel.tree.root;
71                                             }
72                                             
73                                             
74                                             Pman.Dialog.CmsCategory.show( { id : 0 , parent_id : id, parent_id_title:  sel.text }, function(r)
75                                             {
76                                                if (r && r.title) {
77                                                     if(sel.reload) {
78                                                         sel.reload();
79                                                         return;
80                                                     }
81                                                     // otherwise it's a treenode, and needs replacing...
82                                                     var attr = sel.attributes;
83                                                     attr.leaf = false;
84                                                     var repnode = new Roo.tree.AsyncTreeNode(attr);
85                                                     sel.parentNode.replaceChild(repnode, sel);
86                                                     repnode.expand();
87                                                }
88                                             });
89                                         }
90                                     },
91                                     text : "Add",
92                                     icon : Roo.rootURL + 'images/default/tree/drop-add.gif'
93                                 },
94                                 {
95                                     xtype: 'Item',
96                                     xns: Roo.menu,
97                                     listeners : {
98                                         click : function (_self, e)
99                                         {
100                                         
101                                             var sel = _this.panel.tree.getSelectionModel().getSelectedNode();
102                                             if (!sel || isNaN(parseInt(sel.id))) {
103                                                 Roo.MessageBox.alert("Error", "select a category to edit");
104                                                 return;
105                                             }
106                                              var ats = sel.attributes;
107                                         
108                                              Pman.Dialog.CmsCategory.show( ats  , function(r)
109                                             {
110                                                if (r && r.title) {
111                                                     sel.setText(r.display_order + '. ' + r.title);
112                                                }
113                                                sel.attributes = r;
114                                             });
115                                         }
116                                     },
117                                     text : "Edit",
118                                     icon : Roo.rootURL + 'images/default/tree/leaf.gif'
119                                 },
120                                 {
121                                     xtype: 'Separator',
122                                     xns: Roo.menu
123                                 },
124                                 {
125                                     xtype: 'Item',
126                                     xns: Roo.menu,
127                                     listeners : {
128                                         click : function (_self, e)
129                                         {
130                                             var sel = _this.panel.tree.getSelectionModel().getSelectedNode();
131                                             if (!sel || isNaN(parseInt(sel.id))) {
132                                                 Roo.MessageBox.alert("Error", "you can not delete that category");
133                                                 return;
134                                             }
135                                             var par = sel.parentNode;
136                                             Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that?", function(b)
137                                             {
138                                                // console.log(b);
139                                                 if (b!='yes') {
140                                                     return;
141                                                 }
142                                                   Roo.Ajax.request({
143                                                     method : 'GET',
144                                                     params : {
145                                                         _delete : sel.id
146                                                     },
147                                                     url : baseURL + '/Roo/Category.php',
148                                                     success : function(r, o) { 
149                                                         par.removeChild(sel);
150                                                         // do nothing..
151                                                     },
152                                                     failure : function () {
153                                                         Roo.messageBox.alert('Error', 'Error updating categories');
154                                                         _this.root.reload();
155                                                     }
156                                                 });
157                                                 
158                                             });
159                                                 
160                                             
161                                             
162                                             
163                                         }
164                                     },
165                                     text : "Delete"
166                                 },
167                                 {
168                                     xtype: 'Separator',
169                                     xns: Roo.menu
170                                 },
171                                 {
172                                     xtype: 'Item',
173                                     xns: Roo.menu,
174                                     listeners : {
175                                         click : function (_self, e)
176                                         {
177                                            _this.panel.tree.root.reload();
178                                         }
179                                     },
180                                     text : "Reload"
181                                 }
182                             ]
183                         }
184                     }
185                 ]
186             },
187             tree : {
188                 xtype: 'TreePanel',
189                 xns: Roo.tree,
190                 listeners : {
191                     click : function (node, e)
192                     {
193                          (function() {
194                             Pman.Tab.CmsProduct.grid.footer.onClick('first');
195                         }).defer(200);
196                     },
197                     nodedragover : function (dragOverEvent)
198                     {
199                          //console.log('nodedragover');
200                          // console.log(dragOverEvent.point);     
201                          
202                          if (dragOverEvent.data.grid) {
203                             // comming from grid..
204                              if (!dragOverEvent.data.selections.length) {
205                                  return false;
206                              }
207                            
208                              if (isNaN(parseInt(dragOverEvent.target.id))) {
209                                 return false;
210                              }
211                     
212                              if (dragOverEvent.point !='append') {
213                                 return false; 
214                              }
215                              return true;
216                         }
217                         // only allow append..
218                          if (dragOverEvent.point !='append') {
219                             return false; 
220                          }
221                         
222                         
223                     },
224                     beforenodedrop : function (dropEvent)
225                     {
226                         console.log('beforenodedrop');
227                         console.log(dropEvent);
228                         if (dropEvent.data.grid) {
229                             // comming from grid..
230                              if (!dropEvent.data.selections.length) {
231                                  return false;
232                              }
233                            
234                              if (isNaN(parseInt(dropEvent.target.id))) {
235                                 return false;
236                              }
237                     
238                              if (dropEvent.point !='append') {
239                                 return false; 
240                              }
241                              var ids = [];
242                              Roo.each(dropEvent.data.selections, function(d) {
243                                 ids.push(d.data.id)
244                              });
245                              Roo.Ajax.request({
246                                 method : 'POST',
247                                 params : {
248                                     _ids : ids.join(','),
249                                     category_id : dropEvent.target.id
250                                 },
251                                 url : baseURL + '/Roo/Product.php',
252                                 success : function(r, o) { 
253                                     dropEvent.data.grid.footer.onClick('refresh');
254                                 },
255                                 failure : function () {
256                                     Roo.messageBox.alert('Error', 'Error updating categories');
257                                 }
258                             });
259                              
260                              
261                              
262                              return true;
263                         }
264                         
265                      
266                         
267                         
268                         
269                         
270                         return true;
271                     },
272                     nodedrop : function (dropEvent)
273                     {
274                        // now handle node drop..
275                         // if it fails, we just reload the tree..  a bit messy, but acceptable..
276                         var _t = this;
277                         
278                         Roo.Ajax.request({
279                             method : 'POST',
280                             params : {
281                                 id : dropEvent.dropNode.id,
282                                 parent_id : dropEvent.target.id
283                             },
284                             url : baseURL + '/Roo/Category.php',
285                             success : function(r, o) { 
286                                 
287                                 // do nothing..
288                             },
289                             failure : function () {
290                                 Roo.messageBox.alert('Error', 'Error updating categories');
291                                 _this.root.reload()
292                             }
293                         });
294                          
295                     },
296                     contextmenu : function (node, e)
297                     {
298                       this.selModel.select(node);
299                       _this.panel.menu = Roo.factory(_this.panel.menu, Roo.menu);
300                       Roo.log(node);
301                       _this.panel.menu.show(node.ui.textNode);
302                     }
303                 },
304                 ddGroup : 'products',
305                 enableDrag : true,
306                 enableDrop : true,
307                 root : {
308                     xtype: 'AsyncTreeNode',
309                     xns: Roo.tree,
310                     text : "TOP LEVEL"
311                 },
312                 loader : {
313                     xtype: 'TreeLoader',
314                     xns: Roo.tree,
315                     listeners : {
316                         create : function (This, attr)
317                         {
318                             //Roo.log(attr);
319                             attr.text =  attr.display_order + '. ' + attr.title;
320                          
321                             attr.allowChildren = true;
322                         }
323                     },
324                     queryParam : 'parent_id',
325                     requestMethod : 'GET',
326                     root : 'data',
327                     baseParams : { _tree: 1, 'sort': 'display_order,title', 'dir': 'ASC' },
328                     dataUrl : baseURL + '/Roo/Category.php'
329                 }
330             },
331             menu : {
332                 xtype: 'Menu',
333                 xns: Roo.menu,
334                 items : [
335                     {
336                         xtype: 'Item',
337                         xns: Roo.menu,
338                         listeners : {
339                             click : function (_self, e)
340                             {
341                             
342                                 var sel = _this.panel.tree.getSelectionModel().getSelectedNode();
343                                 if (!sel || isNaN(parseInt(sel.id))) {
344                                     Roo.MessageBox.alert("Error", "select a category to edit");
345                                     return;
346                                 }
347                                  var ats = sel.attributes;
348                             
349                                  Pman.Dialog.CmsCategory.show( ats  , function(r)
350                                 {
351                                    Roo.log(r);
352                                    if (r && r.title) {
353                                         sel.setText(r.display_order + '. ' + r.title);
354                                    }
355                                    sel.attributes = r;
356                                 });
357                             }
358                         },
359                         text : "Edit",
360                         icon : Roo.rootURL + 'images/default/tree/leaf.gif'
361                     }
362                 ]
363             }
364         });
365         this.layout = this.panel.layout;
366
367     }
368 });