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