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