View.php
[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: false,
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                             'mimetype'
100                         ]
101                     },
102                     listeners : {
103                         
104                         beforeload: function(t, o) {
105                             var sn = Pman.Tab.FtpTree.tree.getSelectionModel().getSelectedNode();
106                             if (!sn) {
107                                 // clear!?!?
108                                 return false;
109                             }
110                             o.params.name = sn.attributes.id;
111                             o.params.type = 'files';
112                             //console.log(o.params);
113                             // teams!?!
114                             // need to show month here..
115                             //o.params = o.params ? o.params : {};
116                           //  o.params['query[project_search]'] = _this.searchBox.getValue();
117                           //  o.params['query[project_filter]'] = _this.filter;
118                             return true;
119                                 
120                         },
121                         load : function()
122                         {
123                              
124                         },
125                         loadexception : Pman.loadException
126                     
127                     },
128                     sortInfo: {
129                         field: 'name', direction: 'DESC'
130                     }
131                 }),
132                 cm: new Ext.grid.ColumnModel(
133                     [
134                     {
135                         id : 'ftpfiles-name',
136                         header : "Filename",
137                         dataIndex : 'name',
138                         sortable : true,
139                         width : 170
140                         
141                     },
142                     
143                     {
144                         header : "Size",
145                         dataIndex : 'size',
146                         sortable : true,
147                         width : 130
148                     }, 
149                     {
150                         header : "Modified",
151                         dataIndex : 'mtime',
152                         sortable : true,
153                         width : 130 
154                          
155                     } ]
156                 ),
157                 autoExpandColumn: 'ftpfiles-name' , // fixme!!!!
158                 clicksToEdit : 1,
159                 
160                 loadMask: true,
161
162                 listeners: {
163                     // sel. changed-> show detail breakdown @ bottom.
164                     
165                     //rowclick : function(g, ri, e) {
166                         
167                       //  var x = g.getDataSource().getAt(ri);
168                        // x.data.languagelist = x.json.languagelist;
169                        // x.data.countrylist= x.json.countrylist;
170                        // _dialog.show(x.data, refreshPager); 
171                     //}
172                     
173                     
174                 },
175                 selModel : {
176                     xtype : 'RowSelectionModel',
177                     singleSelect: true,
178                     listeners : {
179                         afterselectionchange : function(sm) {
180                             var s = sm.getSelections();
181                             if (!s || s.length != 1) {
182                                 return;
183                             }
184                             // if it's not a text file.. download it..
185                             
186                             var mt = s[0].data.mimetype;
187                             Roo.log(mt);
188                             if (mt.match(/^text\//)) {
189                                 _this.viewLayout.load(baseURL+ '/Ftp/View/' + s[0].data.id + '?html=1');
190                                 return;
191                             }
192                             if (mt.match(/\/xml$/)) {
193                                 _this.viewLayout.load(baseURL+ '/Ftp/View/' + s[0].data.id + '?html=1');
194                                 return;
195                             }
196                             // download
197                             new Pman.Download({
198                                 url: baseURL+ '/Ftp/View/' + s[0].data.id
199                             });
200                             
201                             
202                         }
203                     }
204                 }
205         });
206         this.grid.getSelectionModel().singleSelect = true;
207         this.grid.getSelectionModel().on('selectionchange' , function (s) {
208             //
209         });
210         
211         
212         
213          this.panel  = this.layout.add('center',  new Ext.GridPanel(this.grid ,
214             { fitToframe: true,fitContainer: true })
215         );
216         this.grid.render();
217         /*var gridFoot = this.grid.getView().getFooterPanel(true);
218         this.paging = new Ext.PagingToolbar(gridFoot, this.grid.getDataSource(), {
219             pageSize: 25,
220             displayInfo: true,
221             displayMsg: "",
222             emptyMsg: ""
223         });
224         */
225         var pagerFirst = function()
226         {
227             _this.reload();
228         }
229         
230         var grid = this.grid;
231  
232         var gridHead = this.grid.getView().getHeaderPanel(true);
233         var tb = new Ext.Toolbar(gridHead);
234         var daterange = [];
235         var td = Date.parseDate((new Date()).format('Y-m-01'), 'Y-m-d');
236          
237         
238         tb.add(
239       
240             
241             "DELETE",
242             "RENAME"
243               
244         );
245         
246             
247         //this.toolbar = tb;
248         // add stuff to toolbar?
249         
250         
251          // _this.paging.onClick('refresh');
252         
253         var frame = this.layout.getRegion('south').el.createChild({tag:'div', style: 'margin:0px;'});
254         this.viewLayout = this.layout.add('south',
255             new Ext.ContentPanel(frame, {
256             //autoCreate : true,
257             //toolbar: this.tb,
258             background : true,
259             fitToFrame:true,
260             fitContainer: true, 
261             title : "Details"
262         }));
263         //return;
264         this.layout.endUpdate();
265         //this.viewLayout.resizeEl= this.viewLayout.getEl();
266         //this.viewLayout.el.setStyle('overflow', 'auto');
267         
268     },
269      
270     reload : function()
271     {
272         this.grid.getDataSource().load({
273             params: {
274                 start:0, 
275                 limit:999
276             }
277         });
278     }
279      
280     
281     
282     
283 };   
284