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