069871612f12f4f7a3ed01cdab8a339d21f1c4f4
[Pman.Core] / Pman.Dialog.Image.js
1 //<script type="text/javascript">
2
3 /*
4 Pman.Dialog.Image = {
5     dialog : false,
6     form : false,
7     create: function()
8     {
9         if (this.dialog) {
10             return;
11         }
12         var _this = this;
13         
14         this.dialog = new Ext.LayoutDialog(Ext.get(document.body).createChild({tag:'div'}),  { 
15             autoCreated: true,
16             title: "Upload Image or  File",
17             modal: true,
18             width:  500,
19             height: 140,
20             shadow:true,
21             minWidth:200,
22             minHeight:180,
23             //proxyDrag: true,
24             closable: false,
25             draggable: false,
26             center: {
27                 autoScroll:false,
28                 titlebar: false,
29                // tabPosition: 'top',
30                 hideTabs: true,
31                 closeOnTab: true,
32                 alwaysShowTabs: false
33             }
34         });
35         this.dialog.addKeyListener(27, this.dialog.hide, this.dialog);
36         this.dialog.addButton("Cancel", this.dialog.hide, this.dialog);
37        
38         this.dialog.addButton("Save", this.save, this);
39         this.layout = this.dialog.getLayout();
40         this.layout.beginUpdate();
41         
42          
43         this.form = new Ext.form.Form({
44             labelWidth: 150 ,
45             fileUpload : true,
46             listeners : {
47                 actionfailed : function(f, act) {
48                     _this.uploadComplete = true;
49                     _this.dialog.el.unmask();
50                     // error msg???
51                     
52                     if (act.type == 'submit') {
53                         Ext.MessageBox.alert("Error", "Saving failed = fix errors and try again");
54                         return;
55                     }
56                     
57                     // what about load failing..
58                     Ext.MessageBox.alert("Error", "Error loading details"); 
59                               
60                 },
61                 actioncomplete: function(f, act) {
62                     _this.uploadComplete = true;
63                     _this.dialog.el.unmask();
64                      
65                    
66                     if (act.type == 'load') {
67                         
68                         _this.data = act.result.data;
69                        // _this.loaded();
70                         return;
71                     }
72                     
73                     
74                     if (act.type == 'submit') { // only submitted here if we are 
75                         _this.dialog.hide();
76                         //console.log(act);
77                         if (_this.callback) {
78                             _this.callback.call(this, act.result.data);
79                         }
80                         return; 
81                     }
82                     // unmask?? 
83                 }
84             }
85         
86             
87             
88              
89         });
90         //?? will this work...
91         this.form.addxtype.apply(this.form,
92             [
93                 // type filed??
94                 { name: 'UPLOAD_IDENTIFIER' , xtype: 'Hidden' },
95                 { 
96                         xtype :  'TextField',
97                         name : 'imageUpload',
98                         fieldLabel : "Upload Image or File",
99                         inputType : 'file'
100                 },
101                 { name: 'ontable', xtype: 'Hidden' },
102                 { name: 'onid', xtype: 'Hidden' },
103                 { name: 'imgtype', xtype: 'Hidden' }, // special value for sorting!!
104                 { name: 'post_max_size', xtype: 'Hidden' , value :'32M'} ,
105                 { name: 'upload_max_filesize', xtype: 'Hidden' , value :'32M'} 
106                     
107                    
108                  
109         ]
110
111         );
112         var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
113         ef.dom.style.margin = 10;
114          
115         this.form.render(ef.dom);
116
117         var vp = this.dialog.getLayout().add('center', new Ext.ContentPanel(ef, {
118             autoCreate : true,
119             //title: 'Org Details',
120             //toolbar: this.tb,
121             width: 250,
122             maxWidth: 250,
123             fitToFrame:true
124         }));
125           
126
127         
128         
129         this.layout.endUpdate();
130     },
131     _id : 0,
132     
133     show: function (data, callback)
134     {
135         
136         this.callback = callback;
137          this.create();
138         this.form.reset();
139         
140         this.form.setValues(data);
141         this.form.findField('UPLOAD_IDENTIFIER').setValue((new Date() * 1) + '' + Math.random());
142         this.dialog.show();
143         
144
145     },
146      
147     save : function()
148     {
149         this.dialog.el.mask("Sending");
150         this.uploadComplete = false;
151         this.form.doAction('submit', {
152             url: baseURL + '/Roo/Images.html',
153             method: 'POST',
154             params: {
155              //   _id: 0 ,
156                 ts : Math.random()
157             } 
158         });
159         this.haveProgress = false,
160         this.uploadProgress.defer(1000, this);
161         
162     },
163     uploadComplete : false,
164     haveProgress: false,
165     uploadProgress : function()
166     {
167         if (!this.haveProgress) {
168             Roo.MessageBox.progress("Uploading", "Uploading");
169         }
170         if (this.uploadComplete) {
171             Roo.MessageBox.hide();
172             return;
173         }
174         this.haveProgress = true;
175         var _this = this;
176         var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
177         Pman.request({
178             url : baseURL + '/Core/UploadProgress.php',
179             params: {
180                 id : uid
181             },
182             method: 'GET',
183             success : function(data){
184                 //console.log(data);
185                 if (_this.uploadComplete) {
186                     Roo.MessageBox.hide();
187                     return;
188                 }
189                     
190                 if (data){
191                     Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
192                         Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
193                     );
194                 }
195                 _this.uploadProgress.defer(2000, _this);
196             },
197             failure: function(data) {
198               //  console.log('fail');
199              //   console.log(data);
200             }
201         })
202         
203         
204         
205     }
206     
207     
208     
209     
210          
211 };
212 */