Pman.Dialog.ImageUpload.js
[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             items : [
84                 {
85                     xtype: 'ContentPanel',
86                     xns: Roo,
87                     fitToFrame : true,
88                     region : 'center',
89                     items : [
90                         {
91                             xtype: 'Form',
92                             xns: Roo.form,
93                             listeners : {
94                                 actioncomplete : function(_self,act)
95                                 {
96                                        _this.dialog.uploadComplete = true;
97                                         _this.dialog.el.unmask();
98                                          
99                                           if (act.type == 'setdata') { 
100                                          
101                                               this.findField('UPLOAD_IDENTIFIER').setValue(
102                                                 (new Date() * 1) + '' + Math.random());
103                                             return;
104                                          }
105                                          
106                                        
107                                         if (act.type == 'load') {
108                                           // should this happen?  
109                                             _this.data = act.result.data;
110                                            // _this.loaded();
111                                             return;
112                                         }
113                                         
114                                         
115                                         if (act.type == 'submit') { // only submitted here if we are 
116                                             _this.dialog.hide();
117                                             //console.log(act);
118                                             if (_this.callback) {
119                                                 _this.callback.call(this, act.result.data);
120                                             }
121                                             return; 
122                                         }
123                                 },
124                                 rendered : function (form)
125                                 {
126                                     _this.form= form;
127                                 },
128                                 actionfailed : function (_self, act)
129                                 {
130                                     _this.dialog.uploadComplete = true;
131                                     _this.dialog.el.unmask();
132                                     // error msg???
133                                     
134                                     if (act.type == 'submit') {
135                                         Ext.MessageBox.alert("Error", "Saving failed = fix errors and try again");
136                                         return;
137                                     }
138                                     
139                                     // what about load failing..
140                                     Ext.MessageBox.alert("Error", "Error loading details"); 
141                                 }
142                             },
143                             labelWidth : 140,
144                             method : 'POST',
145                             style : 'margin:10px;',
146                             url : baseURL + '/Roo/Images.php',
147                             items : [
148                                 {
149                                     xtype: 'Hidden',
150                                     xns: Roo.form,
151                                     name : 'UPLOAD_IDENTIFIER'
152                                 },
153                                 {
154                                     xtype: 'TextField',
155                                     xns: Roo.form,
156                                     fieldLabel : 'Upload Image or File',
157                                     inputType : 'file',
158                                     name : 'image',
159                                     width : 200
160                                 },
161                                 {
162                                     xtype: 'Hidden',
163                                     xns: Roo.form,
164                                     name : 'ontable'
165                                 },
166                                 {
167                                     xtype: 'Hidden',
168                                     xns: Roo.form,
169                                     name : 'onid'
170                                 },
171                                 {
172                                     xtype: 'Hidden',
173                                     xns: Roo.form,
174                                     name : 'imgtype'
175                                 },
176                                 {
177                                     xtype: 'Hidden',
178                                     xns: Roo.form,
179                                     name : 'post_max_size',
180                                     value : "32M"
181                                 },
182                                 {
183                                     xtype: 'Hidden',
184                                     xns: Roo.form,
185                                     name : 'upload_max_filesize',
186                                     value : "32M"
187                                 }
188                             ]
189                         }
190                     ]
191                 }
192             ],
193             center : {
194                 xtype: 'LayoutRegion',
195                 xns: Roo
196             },
197             buttons : [
198                 {
199                     xtype: 'Button',
200                     xns: Roo,
201                     listeners : {
202                         click : function (_self, e)
203                         {
204                             _this.dialog.hide();
205                         }
206                     },
207                     text : "Cancel"
208                 },
209                 {
210                     xtype: 'Button',
211                     xns: Roo,
212                     listeners : {
213                         click : function (_self, e)
214                         {
215                             // do some checks?
216                              
217                             _this.dialog.el.mask("Sending");
218                             _this.dialog.uploadComplete = false;
219                             _this.form.doAction('submit', {
220                                 url: baseURL + '/Roo/Images.html',
221                                 method: 'POST',
222                                 params: {
223                                  //   _id: 0 ,
224                                     ts : Math.random()
225                                 } 
226                             });
227                             _this.dialog.haveProgress = false,
228                             _this.dialog.uploadProgress.defer(1000, _this.dialog);
229                         
230                         }
231                     },
232                     text : "Post"
233                 }
234             ]
235         });
236     }
237 };