Pman.Tab.FtpFiles.js
[Pman.Ftp] / Pman.Tab.FtpFiles.js
1 //<script type="text/javascript">
2 // tab on left...  
3
4 Pman.on('beforeload', function()
5 {
6     // this is always shown if Clipping module is enabled!!
7     //if (!Pman.hasPerm('Admin.Campaigns', 'E')) {
8     //    return;
9     //}
10     Pman.register({
11         modKey : '016-pman-tab-ftpfiles',
12         module : Pman.Tab.FtpFiles,
13         region : 'center',
14         parent : Pman.Tab.FtpTab,
15         name : "Ftp Files"
16     });
17 });
18  
19    
20
21 Pman.Tab.FtpFiles = {
22     grid : false,
23     panel : false,
24     
25      
26     add : function(parentLayout, region) {
27         
28          
29         if (this.panel) {
30             parentLayout.getRegion(region).showPanel(this.panel);
31             return;
32         }
33         
34      
35         
36         this.layout = new Ext.BorderLayout(
37             parentLayout.getEl().createChild({tag:'div'}),
38             {
39                
40                 center: {
41                     autoScroll:true,
42                     hideTabs: true,
43                     fitToFrame : true
44                 }, 
45                 south : {
46                     split:true,
47                     titleBar:  false,
48                     
49                     autoScroll:true,
50                     hideTabs: true,
51                    // hideTabs: false,
52                     collapsible: false,
53                    // collapsed : true,
54                     height: 250
55                 }
56             }
57         );
58
59         var _this = this;
60
61         this.tab = parentLayout.add(region,  new Ext.NestedLayoutPanel(
62             this.layout, {title: "Files", background: true}));
63             
64         this.tab.on('activate', function() {
65             _this.delayedCreate();
66             _this.reload();
67         });
68     },
69     delayedCreate :  function() 
70     {
71         if (this.grid) {
72             return;
73         }
74         var _this = this;
75         this.layout.beginUpdate();
76          
77
78         var frm = this.layout.getEl().createChild({tag:'div'});
79         //this.grid = new Ext.grid.EditorGrid(frm,  {
80         this.grid = new Ext.grid.Grid(frm,  {
81                 id: 'grid-supplog',
82                 ds:   new Ext.data.Store({
83                     // load using HTTP
84                     proxy: new Ext.data.HttpProxy({
85                         url: baseURL + '/Ftp/List.php',
86                         method: 'GET'
87                     }),
88                     remoteSort: true,
89                     reader:   {
90                         root : 'data',
91                         totalProperty : 'total',
92                         id : 'id',
93                         xtype : 'JsonReader',
94                         fields : [
95                             'id',
96                             'name',
97                             'mtime',
98                             'size'
99                         ]
100                     },
101                     listeners : {
102                         
103                         beforeload: function(t, o) {
104                             var sn = Pman.Tab.FtpTree.tree.getSelectionModel().getSelectedNode();
105                             if (!sn) {
106                                 // clear!?!?
107                                 return false;
108                             }
109                             o.params.name = sn.attributes.id;
110                             o.params.type = 'files';
111                             //console.log(o.params);
112                             // teams!?!
113                             // need to show month here..
114                             //o.params = o.params ? o.params : {};
115                           //  o.params['query[project_search]'] = _this.searchBox.getValue();
116                           //  o.params['query[project_filter]'] = _this.filter;
117                             
118                                 
119                         },
120                         load : function()
121                         {
122                              
123                         },
124                         loadexception : Pman.loadException
125                     
126                     },
127                     sortInfo: {
128                         field: 'name', direction: 'DESC'
129                     }
130                 }),
131                 cm: new Ext.grid.ColumnModel(
132                     [
133                     {
134                         id : 'ftpfiles-name',
135                         header : "Filename",
136                         dataIndex : 'name',
137                         sortable : false,
138                         width : 170
139                         
140                     },
141                     
142                     {
143                         header : "Size",
144                         dataIndex : 'size',
145                         sortable : false,
146                         width : 130
147                     }, 
148                     {
149                         header : "Modified",
150                         dataIndex : 'mtime',
151                         sortable : false,
152                         width : 130
153                     } ]
154                 ),
155                 autoExpandColumn: 'ftpfiles-name' , // fixme!!!!
156                 clicksToEdit : 1,
157                 
158                 loadMask: true,
159
160                 listeners: {
161                     // sel. changed-> show detail breakdown @ bottom.
162                     
163                     //rowclick : function(g, ri, e) {
164                         
165                       //  var x = g.getDataSource().getAt(ri);
166                        // x.data.languagelist = x.json.languagelist;
167                        // x.data.countrylist= x.json.countrylist;
168                        // _dialog.show(x.data, refreshPager); 
169                     //}
170                     
171                     
172                 },
173                 selModel : {
174                     xtype : 'RowSelectionModel',
175                     singleSelect: true,
176                     listeners : {
177                         afterselectionchange : function(sm) {
178                             var s = sm.getSelections();
179                             if (!s || s.length != 1) {
180                                 return;
181                             }
182                             // if it's not a text file.. download it..
183                             
184                             _this.viewLayout.load(baseURL+ '/Ftp/View' + s[0].data.id + '?html=1');
185                         }
186                     }
187                 }
188         });
189         this.grid.getSelectionModel().singleSelect = true;
190         this.grid.getSelectionModel().on('selectionchange' , function (s) {
191             //
192         });
193         
194         
195         
196          this.panel  = this.layout.add('center',  new Ext.GridPanel(this.grid ,
197             { fitToframe: true,fitContainer: true })
198         );
199         this.grid.render();
200         /*var gridFoot = this.grid.getView().getFooterPanel(true);
201         this.paging = new Ext.PagingToolbar(gridFoot, this.grid.getDataSource(), {
202             pageSize: 25,
203             displayInfo: true,
204             displayMsg: "",
205             emptyMsg: ""
206         });
207         */
208         var pagerFirst = function()
209         {
210             _this.reload();
211         }
212         
213         var grid = this.grid;
214  
215         var gridHead = this.grid.getView().getHeaderPanel(true);
216         var tb = new Ext.Toolbar(gridHead);
217         var daterange = [];
218         var td = Date.parseDate((new Date()).format('Y-m-01'), 'Y-m-d');
219          
220         
221         tb.add(
222       
223             
224             "DELETE",
225             "RENAME"
226               
227         );
228         
229             
230         //this.toolbar = tb;
231         // add stuff to toolbar?
232         
233         
234          // _this.paging.onClick('refresh');
235         
236         var frame = this.layout.getRegion('south').el.createChild({tag:'div', style: 'margin:0px;'});
237         this.viewLayout = this.layout.add('south',
238             new Ext.ContentPanel(frame, {
239             //autoCreate : true,
240             //toolbar: this.tb,
241             background : true,
242             fitToFrame:true,
243             fitContainer: true, 
244             title : "Details"
245         }));
246         //return;
247         this.layout.endUpdate();
248         //this.viewLayout.resizeEl= this.viewLayout.getEl();
249         //this.viewLayout.el.setStyle('overflow', 'auto');
250         
251     },
252      
253     reload : function()
254     {
255         this.grid.getDataSource().load({
256             params: {
257                 start:0, 
258                 limit:999
259             }
260         });
261     }
262      
263     
264     
265     
266 };   
267