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