PHP8
[Pman.BAdmin] / Pman.Dialog.BAdminImage.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Roo.namespace('Pman.Dialog');
6
7 Pman.Dialog.BAdminImage= function() {}
8 Roo.apply(Pman.Dialog.BAdminImage.prototype, {
9
10  _strings : {
11   'ef797d5638c2e1c6b6225b2247541ea5' :"Upload Image or File:",
12   '2859a4ae58ae4e25abdfc530f814e42f' :"Upload an Image or File",
13   'ea4788705e6873b424c65e91c2846b19' :"Cancel",
14   '91412465ea9169dfd901dd5e7c96dd99' :"Upload"
15  },
16  _named_strings : {
17   'imageUpload_fieldLabel' : 'ef797d5638c2e1c6b6225b2247541ea5' /* Upload Image or File: */ 
18  },
19
20  dialog : false,
21  callback:  false,
22
23  show : function(data, cb)
24  {
25   if (!this.dialog) {
26    this.create();
27   }
28
29   this.callback = cb;
30   this.data = data;
31   this.dialog.show(this.data._el);
32   if (this.form) {
33    this.form.reset();
34    this.form.setValues(data);
35    this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
36   }
37
38  },
39
40  create : function()
41  {
42   var _this = this;
43   this.dialog = Roo.factory({
44     xtype : 'Modal',
45     haveProgress : false,
46     title : _this._strings['2859a4ae58ae4e25abdfc530f814e42f'] /* Upload an Image or File */,
47     uploadComplete : false,
48     uploadProgress : function()
49     {
50         var dlg = this;
51         if (!dlg.haveProgress) {
52             Roo.MessageBox.progress("Uploading", "Uploading");
53         }
54         
55         if (dlg.haveProgress == 2) {
56             // it's been closed elsewhere..
57             return;
58         }
59         if (dlg.uploadComplete) {
60             Roo.MessageBox.hide();
61             return;
62         }
63         
64         dlg.haveProgress = 1;
65     
66         var uid = _this.form.findField('UPLOAD_IDENTIFIER').getValue();
67         new Pman.Request({
68             url : baseURL + '/Core/UploadProgress.php',
69             params: {
70                 id : uid
71             },
72             method: 'GET',
73             success : function(res){
74                 var data = res.data;
75                 if (dlg.haveProgress == 2) {
76                     return;
77                 }
78                 
79                 if (dlg.uploadComplete) {
80                     Roo.MessageBox.hide();
81                     return;
82                 }
83                     
84                 if (data){
85                     Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
86                         Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
87                     );
88                 } else {
89                     Roo.MessageBox.updateProgress(1,
90                         "Upload Complete - processing"
91                     );
92                     return;
93                 }
94                 dlg.uploadProgress.defer(2000,dlg);
95             },
96             failure: function(data) {
97             }
98         })
99         
100     },
101     xns : Roo.bootstrap,
102     '|xns' : 'Roo.bootstrap',
103     buttons : [
104      {
105       xtype : 'Button',
106       html : _this._strings['ea4788705e6873b424c65e91c2846b19'] /* Cancel */,
107       weight : 'default',
108       listeners : {
109        click : function (_self, e)
110         {
111             _this.dialog.hide();
112         }
113       },
114       xns : Roo.bootstrap,
115       '|xns' : 'Roo.bootstrap'
116      },
117      {
118       xtype : 'Button',
119       html : _this._strings['91412465ea9169dfd901dd5e7c96dd99'] /* Upload */,
120       weight : 'primary',
121       listeners : {
122        click : function (_self, e)
123         {
124             // do some checks?
125              
126             //_this.dialog.el.mask("Sending");
127             
128             _this.dialog.uploadComplete = false;
129             _this.form.doAction('submit', {
130                 params: {
131                     ts : Math.random()
132                 }
133             });
134             
135             _this.dialog.haveProgress = 0; // set to show..
136             _this.dialog.uploadProgress.defer(1000, _this.dialog);
137         }
138       },
139       xns : Roo.bootstrap,
140       '|xns' : 'Roo.bootstrap'
141      }
142     ],
143     items  : [
144      {
145       xtype : 'Container',
146       style : 'width: 100%',
147       xns : Roo.bootstrap,
148       '|xns' : 'Roo.bootstrap',
149       items  : [
150        {
151         xtype : 'Form',
152         fileUpload : true,
153         method : 'POST',
154         timeout : 300,
155         url : baseURL + '/Roo/Images.php',
156         listeners : {
157          actioncomplete : function(_self,action)
158           {
159               _this.dialog.uploadComplete = true;
160               
161               _this.dialog.haveProgress = 2;
162               
163               Roo.MessageBox.hide();
164                
165               if (action.type == 'setdata') { 
166                   
167                   /*
168                   _this.form.findField('imgtype').hide();
169                   
170                   if(_this.data._show_image_type){
171                       _this.form.findField('imgtype').show();
172                   }
173                   */
174                   
175                   this.url = _this.data._url ? baseURL + _this.data._url : baseURL + '/Roo/Images.php';
176                   this.el.dom.action = this.url;
177                   if (typeof(_this.data.timeout) != 'undefined') {
178                       this.timeout = _this.data.timeout;
179                   }
180                   
181                   this.findField('UPLOAD_IDENTIFIER').setValue(
182                       (new Date() * 1) + '' + Math.random());
183                       
184                   return;
185               }
186                
187              
188               if (action.type == 'load') {
189                   
190                   _this.data = action.result.data;
191                   
192                   return;
193               }
194               
195               
196               if (action.type == 'submit') { // only submitted here if we are 
197                   _this.dialog.hide();
198                   Roo.log("Upload success");
199                   Roo.log(action);
200                   if (_this.callback) {
201                       _this.callback.call(this, action.result.data, action.result.extra);
202                   }
203                   return; 
204               }
205            
206           
207               
208           },
209          actionfailed : function (_self, action)
210           {
211               _this.dialog.uploadComplete = true;
212               
213                _this.dialog.haveProgress = 2;
214                
215               if (action.type == 'submit') {
216                   Roo.log("Upload error");
217                   Roo.log(action);
218                   
219                   try {
220                       
221                       Roo.MessageBox.alert("Error", action.result.errorMsg.split(/\n/).join('<BR/>'));
222                       
223                   } catch(e) {
224                       
225                       Roo.MessageBox.alert("Error", "Saving failed = fix errors and try again");
226                   }
227                   return;
228               }
229               
230               Roo.MessageBox.alert("Error", "Error loading details"); 
231           },
232          render : function (_self)
233           {
234               _this.form = this;
235           }
236         },
237         xns : Roo.bootstrap,
238         '|xns' : 'Roo.bootstrap',
239         items  : [
240          {
241           xtype : 'Input',
242           fieldLabel : _this._strings['ef797d5638c2e1c6b6225b2247541ea5'] /* Upload Image or File: */,
243           inputType : 'file',
244           labelWidth : 4,
245           name : 'imageUpload',
246           xns : Roo.bootstrap,
247           '|xns' : 'Roo.bootstrap'
248          },
249          {
250           xtype : 'Input',
251           inputType : 'hidden',
252           name : 'UPLOAD_IDENTIFIER',
253           xns : Roo.bootstrap,
254           '|xns' : 'Roo.bootstrap'
255          },
256          {
257           xtype : 'Input',
258           inputType : 'hidden',
259           name : 'post_max_size',
260           xns : Roo.bootstrap,
261           '|xns' : 'Roo.bootstrap'
262          },
263          {
264           xtype : 'Input',
265           inputType : 'hidden',
266           name : 'upload_max_filesize',
267           xns : Roo.bootstrap,
268           '|xns' : 'Roo.bootstrap'
269          },
270          {
271           xtype : 'Input',
272           inputType : 'hidden',
273           name : 'ontable',
274           xns : Roo.bootstrap,
275           '|xns' : 'Roo.bootstrap'
276          },
277          {
278           xtype : 'Input',
279           inputType : 'hidden',
280           name : 'onid',
281           xns : Roo.bootstrap,
282           '|xns' : 'Roo.bootstrap'
283          },
284          {
285           xtype : 'Input',
286           inputType : 'hidden',
287           name : 'id',
288           xns : Roo.bootstrap,
289           '|xns' : 'Roo.bootstrap'
290          }
291         ]
292        }
293       ]
294      }
295     ]
296    }  );
297  }
298 });
299 Roo.apply(Pman.Dialog.BAdminImage, Pman.Dialog.BAdminImage.prototype);