27c5d3a248fe9b2bb5124f3361632776bbd5dcbe
[Pman.Core] / Pman.Dialog.ImageUpload.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Pman.Dialog.ImageUpload = {
6
7     dialog : false,
8     callback:  false,
9
10     show : function(data, cb)
11     {
12         if (!this.dialog) {
13             this.create();
14         }
15
16         this.callback = cb;
17         this.data = data;
18         this.dialog.show(this.data._el);
19         if (this.form) {
20            this.form.reset();
21            this.form.setValues(data);
22            this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
23         }
24
25     },
26
27     create : function()
28     {
29         var _this = this;
30         this.dialog = Roo.factory({
31             xtype: 'LayoutDialog',
32             xns: Roo,
33             closable : false,
34             collapsible : false,
35             haveProgress : false,
36             height : 140,
37             modal : true,
38             resizable : true,
39             title : "Upload an Image or File",
40             uploadProgress : false,
41             width : 500,
42             shadow : true,
43             uploadProgres : function()
44             {
45                 var dlg = this;
46                if (!dlg.haveProgress) {
47                     Roo.MessageBox.progress("Uploading", "Uploading");
48                 }
49                 if (dlg.uploadComplete) {
50                     Roo.MessageBox.hide();
51                     return;
52                 }
53                 dlg.haveProgress = true;
54             
55                 var uid = _this.form.findField('UPLOAD_IDENTIFIER').getValue();
56                 Pman.request({
57                     url : baseURL + '/Core/UploadProgress.php',
58                     params: {
59                         id : uid
60                     },
61                     method: 'GET',
62                     success : function(data){
63                         //console.log(data);
64                         if (dlg.uploadComplete) {
65                             Roo.MessageBox.hide();
66                             return;
67                         }
68                             
69                         if (data){
70                             Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
71                                 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
72                             );
73                         }
74                         dlg.uploadProgress.defer(2000,dlg);
75                     },
76                     failure: function(data) {
77                       //  console.log('fail');
78                      //   console.log(data);
79                     }
80                 })
81                 
82             },
83             listeners : {
84                 show : function (_self)
85                 {
86                 
87                 }
88             },
89             items : [
90                 {
91                     xtype: 'ContentPanel',
92                     xns: Roo,
93                     fitToFrame : true,
94                     region : 'center',
95                     items : [
96                         {
97                             xtype: 'Form',
98                             xns: Roo.form,
99                             listeners : {
100                                 actioncomplete : function(_self,act)
101                                 {
102                                        _this.dialog.uploadComplete = true;
103                                         _this.dialog.el.unmask();
104                                          
105                                           if (act.type == 'setdata') { 
106                                          
107                                               this.findField('UPLOAD_IDENTIFIER').setValue(
108                                                 (new Date() * 1) + '' + Math.random());
109                                             return;
110                                          }
111                                          
112                                        
113                                         if (act.type == 'load') {
114                                           // should this happen?  
115                                             _this.data = act.result.data;
116                                            // _this.loaded();
117                                             return;
118                                         }
119                                         
120                                         
121                                         if (act.type == 'submit') { // only submitted here if we are 
122                                             _this.dialog.hide();
123                                             //console.log(act);
124                                             if (_this.callback) {
125                                                 _this.callback.call(this, act.result.data);
126                                             }
127                                             return; 
128                                         }
129                                 },
130                                 rendered : function (form)
131                                 {
132                                     _this.form= form;
133                                 },
134                                 actionfailed : function (_self, act)
135                                 {
136                                     _this.dialog.uploadComplete = true;
137                                     _this.dialog.el.unmask();
138                                     // error msg???
139                                     
140                                     if (act.type == 'submit') {
141                                         Ext.MessageBox.alert("Error", "Saving failed = fix errors and try again");
142                                         return;
143                                     }
144                                     
145                                     // what about load failing..
146                                     Ext.MessageBox.alert("Error", "Error loading details"); 
147                                 }
148                             },
149                             labelWidth : 140,
150                             method : 'POST',
151                             style : 'margin:10px;',
152                             url : baseURL + '/Roo/Images.php',
153                             items : [
154                                 {
155                                     xtype: 'Hidden',
156                                     xns: Roo.form,
157                                     name : 'UPLOAD_IDENTIFIER'
158                                 },
159                                 {
160                                     xtype: 'TextField',
161                                     xns: Roo.form,
162                                     fieldLabel : 'Upload Image or File',
163                                     inputType : 'file',
164                                     name : 'image',
165                                     width : 200
166                                 },
167                                 {
168                                     xtype: 'Hidden',
169                                     xns: Roo.form,
170                                     name : 'ontable'
171                                 },
172                                 {
173                                     xtype: 'Hidden',
174                                     xns: Roo.form,
175                                     name : 'onid'
176                                 },
177                                 {
178                                     xtype: 'Hidden',
179                                     xns: Roo.form,
180                                     name : 'imgtype'
181                                 },
182                                 {
183                                     xtype: 'Hidden',
184                                     xns: Roo.form,
185                                     name : 'post_max_size',
186                                     value : "32M"
187                                 },
188                                 {
189                                     xtype: 'Hidden',
190                                     xns: Roo.form,
191                                     name : 'upload_max_filesize',
192                                     value : "32M"
193                                 }
194                             ]
195                         }
196                     ]
197                 }
198             ],
199             center : {
200                 xtype: 'LayoutRegion',
201                 xns: Roo
202             },
203             buttons : [
204                 {
205                     xtype: 'Button',
206                     xns: Roo,
207                     listeners : {
208                         click : function (_self, e)
209                         {
210                             _this.dialog.hide();
211                         }
212                     },
213                     text : "Cancel"
214                 },
215                 {
216                     xtype: 'Button',
217                     xns: Roo,
218                     listeners : {
219                         click : function (_self, e)
220                         {
221                             // do some checks?
222                              
223                             _this.dialog.el.mask("Sending");
224                             _this.dialog.uploadComplete = false;
225                             _this.form.doAction('submit', {
226                                 url: baseURL + '/Roo/Images.html',
227                                 method: 'POST',
228                                 params: {
229                                  //   _id: 0 ,
230                                     ts : Math.random()
231                                 } 
232                             });
233                             _this.dialog.haveProgress = false,
234                             _this.dialog.uploadProgress.defer(1000, _this.dialog);
235                         
236                         }
237                     },
238                     text : "Post"
239                 }
240             ]
241         });
242     }
243 };