PHP8
[Pman.BAdmin] / Pman.Dialog.Image.js
index a9f9c7b..873f075 100644 (file)
@@ -7,7 +7,12 @@ Roo.namespace('Pman.Dialog');
 Pman.Dialog.Image= function() {}
 Roo.apply(Pman.Dialog.Image.prototype, {
 
-
+ _strings : {
+  'ef797d5638c2e1c6b6225b2247541ea5' :"Upload Image or File:",
+  '2859a4ae58ae4e25abdfc530f814e42f' :"Upload an Image or File",
+  'ea4788705e6873b424c65e91c2846b19' :"Cancel",
+  '91412465ea9169dfd901dd5e7c96dd99' :"Upload"
+ },
 
  dialog : false,
  callback:  false,
@@ -34,40 +39,251 @@ Roo.apply(Pman.Dialog.Image.prototype, {
   var _this = this;
   this.dialog = Roo.factory({
     xtype : 'Modal',
+    haveProgress : false,
+    title : _this._strings['2859a4ae58ae4e25abdfc530f814e42f'] /* Upload an Image or File */,
+    uploadComplete : false,
+    uploadProgress : function()
+    {
+        var dlg = this;
+        if (!dlg.haveProgress) {
+            Roo.MessageBox.progress("Uploading", "Uploading");
+        }
+        
+        if (dlg.haveProgress == 2) {
+            // it's been closed elsewhere..
+            return;
+        }
+        if (dlg.uploadComplete) {
+            Roo.MessageBox.hide();
+            return;
+        }
+        
+        dlg.haveProgress = 1;
+    
+        var uid = _this.form.findField('UPLOAD_IDENTIFIER').getValue();
+        new Pman.Request({
+            url : baseURL + '/Core/UploadProgress.php',
+            params: {
+                id : uid
+            },
+            method: 'GET',
+            success : function(res){
+                var data = res.data;
+                if (dlg.haveProgress == 2) {
+                    return;
+                }
+                
+                if (dlg.uploadComplete) {
+                    Roo.MessageBox.hide();
+                    return;
+                }
+                    
+                if (data){
+                    Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
+                        Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
+                    );
+                } else {
+                    Roo.MessageBox.updateProgress(1,
+                        "Upload Complete - processing"
+                    );
+                    return;
+                }
+                dlg.uploadProgress.defer(2000,dlg);
+            },
+            failure: function(data) {
+            }
+        })
+        
+    },
     xns : Roo.bootstrap,
     '|xns' : 'Roo.bootstrap',
+    buttons : [
+     {
+      xtype : 'Button',
+      html : _this._strings['ea4788705e6873b424c65e91c2846b19'] /* Cancel */,
+      weight : 'default',
+      listeners : {
+       click : function (_self, e)
+        {
+            _this.dialog.hide();
+        }
+      },
+      xns : Roo.bootstrap,
+      '|xns' : 'Roo.bootstrap'
+     },
+     {
+      xtype : 'Button',
+      html : _this._strings['91412465ea9169dfd901dd5e7c96dd99'] /* Upload */,
+      weight : 'primary',
+      listeners : {
+       click : function (_self, e)
+        {
+            // do some checks?
+             
+            //_this.dialog.el.mask("Sending");
+            
+            _this.dialog.uploadComplete = false;
+            _this.form.doAction('submit', {
+                params: {
+                    ts : Math.random()
+                }
+            });
+            
+            _this.dialog.haveProgress = 0; // set to show..
+            _this.dialog.uploadProgress.defer(1000, _this.dialog);
+        }
+      },
+      xns : Roo.bootstrap,
+      '|xns' : 'Roo.bootstrap'
+     }
+    ],
     items  : [
      {
       xtype : 'Container',
+      style : 'width: 100%',
       xns : Roo.bootstrap,
       '|xns' : 'Roo.bootstrap',
       items  : [
        {
         xtype : 'Form',
+        fileUpload : true,
+        method : 'POST',
+        timeout : 300,
+        url : baseURL + '/Roo/Images.php',
+        listeners : {
+         actioncomplete : function(_self,action)
+          {
+              _this.dialog.uploadComplete = true;
+              
+              _this.dialog.haveProgress = 2;
+              
+              Roo.MessageBox.hide();
+               
+              if (action.type == 'setdata') { 
+                  
+                  /*
+                  _this.form.findField('imgtype').hide();
+                  
+                  if(_this.data._show_image_type){
+                      _this.form.findField('imgtype').show();
+                  }
+                  */
+                  
+                  this.url = _this.data._url ? _this.data._url : baseURL + '/Roo/Images.php';
+                  this.el.dom.action = this.url;
+                  if (typeof(_this.data.timeout) != 'undefined') {
+                      this.timeout = _this.data.timeout;
+                  }
+                  
+                  this.findField('UPLOAD_IDENTIFIER').setValue(
+                      (new Date() * 1) + '' + Math.random());
+                      
+                  return;
+              }
+               
+             
+              if (action.type == 'load') {
+                  
+                  _this.data = action.result.data;
+                  
+                  return;
+              }
+              
+              
+              if (action.type == 'submit') { // only submitted here if we are 
+                  _this.dialog.hide();
+                  Roo.log("Upload success");
+                  Roo.log(action);
+                  if (_this.callback) {
+                      _this.callback.call(this, action.result.data, action.result.extra);
+                  }
+                  return; 
+              }
+           
+          
+              
+          },
+         actionfailed : function (_self, action)
+          {
+              _this.dialog.uploadComplete = true;
+              
+               _this.dialog.haveProgress = 2;
+               
+              if (action.type == 'submit') {
+                  Roo.log("Upload error");
+                  Roo.log(action);
+                  
+                  try {
+                      
+                      Roo.MessageBox.alert("Error", action.result.errorMsg.split(/\n/).join('<BR/>'));
+                      
+                  } catch(e) {
+                      
+                      Roo.MessageBox.alert("Error", "Saving failed = fix errors and try again");
+                  }
+                  return;
+              }
+              
+              Roo.MessageBox.alert("Error", "Error loading details"); 
+          },
+         render : function (_self)
+          {
+              _this.form = this;
+          }
+        },
         xns : Roo.bootstrap,
         '|xns' : 'Roo.bootstrap',
         items  : [
          {
-          xtype : 'Row',
+          xtype : 'Input',
+          fieldLabel : _this._strings['ef797d5638c2e1c6b6225b2247541ea5'] /* Upload Image or File: */,
+          inputType : 'file',
+          labelWidth : 4,
+          name : 'imageUpload',
+          xns : Roo.bootstrap,
+          '|xns' : 'Roo.bootstrap'
+         },
+         {
+          xtype : 'Input',
+          inputType : 'hidden',
+          name : 'UPLOAD_IDENTIFIER',
+          xns : Roo.bootstrap,
+          '|xns' : 'Roo.bootstrap'
+         },
+         {
+          xtype : 'Input',
+          inputType : 'hidden',
+          name : 'post_max_size',
+          xns : Roo.bootstrap,
+          '|xns' : 'Roo.bootstrap'
+         },
+         {
+          xtype : 'Input',
+          inputType : 'hidden',
+          name : 'upload_max_filesize',
+          xns : Roo.bootstrap,
+          '|xns' : 'Roo.bootstrap'
+         },
+         {
+          xtype : 'Input',
+          inputType : 'hidden',
+          name : 'ontable',
+          xns : Roo.bootstrap,
+          '|xns' : 'Roo.bootstrap'
+         },
+         {
+          xtype : 'Input',
+          inputType : 'hidden',
+          name : 'onid',
+          xns : Roo.bootstrap,
+          '|xns' : 'Roo.bootstrap'
+         },
+         {
+          xtype : 'Input',
+          inputType : 'hidden',
+          name : 'id',
           xns : Roo.bootstrap,
-          '|xns' : 'Roo.bootstrap',
-          items  : [
-           {
-            xtype : 'Column',
-            xns : Roo.bootstrap,
-            '|xns' : 'Roo.bootstrap'
-           },
-           {
-            xtype : 'Column',
-            xns : Roo.bootstrap,
-            '|xns' : 'Roo.bootstrap'
-           },
-           {
-            xtype : 'Column',
-            xns : Roo.bootstrap,
-            '|xns' : 'Roo.bootstrap'
-           }
-          ]
+          '|xns' : 'Roo.bootstrap'
          }
         ]
        }