DataObjects/Core_watch.php
[Pman.Core] / Pman.Dialog.Image.js
index 6865d74..80cb4c9 100644 (file)
 //<script type="text/javascript">
 
+// Auto generated file - created by app.Builder.js- do not edit directly (at present!)
+
 Pman.Dialog.Image = {
+
     dialog : false,
-    form : false,
-    create: function()
+    callback:  false,
+
+    show : function(data, cb)
     {
-        if (this.dialog) {
-            return;
+        if (!this.dialog) {
+            this.create();
+        }
+
+        this.callback = cb;
+        this.data = data;
+        this.dialog.show(this.data._el);
+        if (this.form) {
+           this.form.reset();
+           this.form.setValues(data);
+           this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
         }
+
+    },
+
+    create : function()
+    {
         var _this = this;
-        
-        this.dialog = new Ext.LayoutDialog(Ext.get(document.body).createChild({tag:'div'}),  { 
-            autoCreated: true,
-            title: "Upload Image or  File",
-            modal: true,
-            width:  500,
-            height: 140,
-            shadow:true,
-            minWidth:200,
-            minHeight:180,
-            //proxyDrag: true,
-            closable: false,
-            draggable: false,
-            center: {
-                autoScroll:false,
-                titlebar: false,
-               // tabPosition: 'top',
-                hideTabs: true,
-                closeOnTab: true,
-                alwaysShowTabs: false
-            }
-        });
-        this.dialog.addKeyListener(27, this.dialog.hide, this.dialog);
-        this.dialog.addButton("Cancel", this.dialog.hide, this.dialog);
-       
-        this.dialog.addButton("Save", this.save, this);
-        this.layout = this.dialog.getLayout();
-        this.layout.beginUpdate();
-        
-         
-        this.form = new Ext.form.Form({
-            labelWidth: 150 ,
-            fileUpload : true,
+        this.dialog = Roo.factory({
+            xtype: 'LayoutDialog',
+            xns: Roo,
             listeners : {
-                actionfailed : function(f, act) {
-                    _this.uploadComplete = true;
-                    _this.dialog.el.unmask();
-                    // error msg???
+                show : function (_self)
+                {
+                
+                    // this does not really work - escape on the borders works..
+                    // resize to fit.. if we have styled stuff...
                     
-                    if (act.type == 'submit') {
-                        Ext.MessageBox.alert("Error", "Saving failed = fix errors and try again");
-                        return;
-                    }
                     
-                    // what about load failing..
-                    Ext.MessageBox.alert("Error", "Error loading details"); 
-                              
-                },
-                actioncomplete: function(f, act) {
-                    _this.uploadComplete = true;
-                    _this.dialog.el.unmask();
-                     
-                   
-                    if (act.type == 'load') {
-                        
-                        _this.data = act.result.data;
-                       // _this.loaded();
-                        return;
-                    }
                     
                     
-                    if (act.type == 'submit') { // only submitted here if we are 
-                        _this.dialog.hide();
-                        //console.log(act);
-                        if (_this.callback) {
-                            _this.callback.call(this, act.result.data);
-                        }
-                        return; 
+                    var d = this;
+                    
+                    var pad =     d.el.getSize().height - (d.header.getSize().height +
+                        d.footer.getSize().height +        
+                        d.layout.getRegion('center').getPanel(0).el.getSize().height
+                        );
+                    
+                    var height = (
+                        pad + 
+                        d.header.getSize().height +
+                        d.footer.getSize().height +        
+                        d.layout.getRegion('center').getPanel(0).el.child('div').getSize().height
+                    );
+                    this.resizeTo(d.el.getSize().width, height);
+                    
+                    if (this.keylistener) {
+                        return;
                     }
-                    // unmask?? 
-                }
-            }
-        
-            
-            
-             
-        });
-        //?? will this work...
-        this.form.addxtype.apply(this.form,
-            [
-                // type filed??
-                { name: 'UPLOAD_IDENTIFIER' , xtype: 'Hidden' },
-                { 
-                        xtype :  'TextField',
-                        name : 'imageUpload',
-                        fieldLabel : "Upload Image or File",
-                        inputType : 'file'
-                },
-                { name: 'ontable', xtype: 'Hidden' },
-                { name: 'onid', xtype: 'Hidden' },
-                { name: 'imgtype', xtype: 'Hidden' }, // special value for sorting!!
-                { name: 'post_max_size', xtype: 'Hidden' , value :'32M'} ,
-                { name: 'upload_max_filesize', xtype: 'Hidden' , value :'32M'} 
+                    this.keylistener = this.addKeyListener(27, this.hide, this);
                     
-                   
-                 
-        ]
-
-        );
-        var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
-        ef.dom.style.margin = 10;
-         
-        this.form.render(ef.dom);
-
-        var vp = this.dialog.getLayout().add('center', new Ext.ContentPanel(ef, {
-            autoCreate : true,
-            //title: 'Org Details',
-            //toolbar: this.tb,
-            width: 250,
-            maxWidth: 250,
-            fitToFrame:true
-        }));
-          
-
-        
-        
-        this.layout.endUpdate();
-    },
-    _id : 0,
-    
-    show: function (data, callback)
-    {
-        
-        this.callback = callback;
-         this.create();
-        this.form.reset();
-        
-        this.form.setValues(data);
-        this.form.findField('UPLOAD_IDENTIFIER').setValue((new Date() * 1) + '' + Math.random());
-        this.dialog.show();
-        
-
-    },
-     
-    save : function()
-    {
-        this.dialog.el.mask("Sending");
-        this.uploadComplete = false;
-        this.form.doAction('submit', {
-            url: baseURL + '/Roo/Images.html',
-            method: 'POST',
-            params: {
-             //   _id: 0 ,
-                ts : Math.random()
-            } 
-        });
-        this.haveProgress = false,
-        this.uploadProgress.defer(1000, this);
-        
-    },
-    uploadComplete : false,
-    haveProgress: false,
-    uploadProgress : function()
-    {
-        if (!this.haveProgress) {
-            Roo.MessageBox.progress("Uploading", "Uploading");
-        }
-        if (this.uploadComplete) {
-            Roo.MessageBox.hide();
-            return;
-        }
-        this.haveProgress = true;
-        var _this = this;
-        var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
-        Pman.request({
-            url : baseURL + '/Core/UploadProgress.php',
-            params: {
-                id : uid
+                }
             },
-            method: 'GET',
-            success : function(data){
-                //console.log(data);
-                if (_this.uploadComplete) {
+            closable : false,
+            collapsible : false,
+            haveProgress : false,
+            height : 140,
+            modal : true,
+            resizable : false,
+            title : "Upload an Image or File",
+            uploadComplete : false,
+            width : 500,
+            shadow : true,
+            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;
                 }
-                    
-                if (data){
-                    Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
-                        Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
-                    );
+                
+                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){
+                        //console.log(data);
+                        var data = res.data;
+                        if (dlg.haveProgress == 2) {
+                            // it's been closed elsewhere..
+                            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) {
+                      //  console.log('fail');
+                     //   console.log(data);
+                    }
+                })
+                
+            },
+            items : [
+                {
+                    xtype: 'ContentPanel',
+                    xns: Roo,
+                    fitToFrame : true,
+                    region : 'center',
+                    items : [
+                        {
+                            xtype: 'Form',
+                            xns: Roo.form,
+                            listeners : {
+                                actioncomplete : function(_self,act)
+                                {
+                                    _this.dialog.uploadComplete = true;
+                                    _this.dialog.haveProgress = 2; 
+                                    Roo.MessageBox.hide(); // force hiding
+                                    //_this.dialog.el.unmask();
+                                     
+                                    if (act.type == 'setdata') { 
+                                        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 (act.type == 'load') {
+                                      // should this happen?  
+                                        _this.data = act.result.data;
+                                       // _this.loaded();
+                                        return;
+                                    }
+                                    
+                                    
+                                    if (act.type == 'submit') { // only submitted here if we are 
+                                        _this.dialog.hide();
+                                        Roo.log("Upload success");
+                                        Roo.log(act);
+                                        //console.log(act);
+                                        if (_this.callback) {
+                                            _this.callback.call(this, act.result.data, act.result.extra);
+                                        }
+                                        return; 
+                                    }
+                                    
+                                
+                                    
+                                },
+                                rendered : function (form)
+                                {
+                                    _this.form= form;
+                                },
+                                actionfailed : function (_self, act)
+                                {
+                                   
+                                   
+                                    _this.dialog.uploadComplete = true;
+                                   // _this.dialog.el.unmask();
+                                    // error msg???
+                                     _this.dialog.haveProgress = 2; 
+                                    if (act.type == 'submit') {
+                                        Roo.log("Upload error");
+                                        Roo.log(act);
+                                        
+                                        try {
+                                            Roo.MessageBox.alert("Error", act.result.errorMsg.split(/\n/).join('<BR/>'));
+                                        } catch(e) {
+                                          //  Roo.log(e);
+                                            Roo.MessageBox.alert("Error", "Saving failed = fix errors and try again");        
+                                        }
+                                        return;
+                                    }
+                                    
+                                    // what about load failing..
+                                    Roo.MessageBox.alert("Error", "Error loading details"); 
+                                }
+                            },
+                            fileUpload : true,
+                            labelWidth : 140,
+                            method : 'POST',
+                            style : 'margin:10px;',
+                            timeout : 300,
+                            url : baseURL + '/Roo/Images.php',
+                            items : [
+                                {
+                                    xtype: 'Hidden',
+                                    xns: Roo.form,
+                                    name : 'UPLOAD_IDENTIFIER'
+                                },
+                                {
+                                    xtype: 'Hidden',
+                                    xns: Roo.form,
+                                    name : 'post_max_size',
+                                    value : "32M"
+                                },
+                                {
+                                    xtype: 'Hidden',
+                                    xns: Roo.form,
+                                    name : 'upload_max_filesize',
+                                    value : "32M"
+                                },
+                                {
+                                    xtype: 'TextField',
+                                    xns: Roo.form,
+                                    fieldLabel : 'Upload Image or File',
+                                    inputType : 'file',
+                                    name : 'imageUpload',
+                                    width : 200
+                                },
+                                {
+                                    xtype: 'Hidden',
+                                    xns: Roo.form,
+                                    name : 'ontable'
+                                },
+                                {
+                                    xtype: 'Hidden',
+                                    xns: Roo.form,
+                                    name : 'onid'
+                                },
+                                {
+                                    xtype: 'Hidden',
+                                    xns: Roo.form,
+                                    name : 'id'
+                                },
+                                {
+                                    xtype: 'Hidden',
+                                    xns: Roo.form,
+                                    name : 'imgtype'
+                                }
+                            ]
+                        }
+                    ]
                 }
-                _this.uploadProgress.defer(2000, _this);
+            ],
+            center : {
+                xtype: 'LayoutRegion',
+                xns: Roo
             },
-            failure: function(data) {
-              //  console.log('fail');
-             //   console.log(data);
-            }
-        })
-        
-        
-        
+            buttons : [
+                {
+                    xtype: 'Button',
+                    xns: Roo,
+                    listeners : {
+                        click : function (_self, e)
+                        {
+                            _this.dialog.hide();
+                        }
+                    },
+                    text : "Cancel"
+                },
+                {
+                    xtype: 'Button',
+                    xns: Roo,
+                    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);
+                        
+                        }
+                    },
+                    text : "Upload"
+                }
+            ]
+        });
     }
-    
-    
-    
-    
-         
 };