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