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