* Fork - LGPL
* <script type="text/javascript">
*/
-
+
+// as we use this in bootstrap.
+Roo.namespace('Roo.form');
/**
* @class Roo.form.Action
* Internal Class used to handle form actions
* @param {Roo.form.BasicForm} el The form element or its id
* @param {Object} config Configuration options
*/
+
// define the action interface
* Server Validation Failed
* @const
*/
- Roo.form.Action.SERVER_INVALID = 'server';
+Roo.form.Action.SERVER_INVALID = 'server';
/**
* Connect to Server Failed
* @const
// default connection failure
failure : function(response){
+
this.response = response;
this.failureType = Roo.form.Action.CONNECT_FAILURE;
this.form.afterAction(this, false);
haveProgress : false,
uploadComplete : false,
- // uploadPrograss indicator.
+ // uploadProgress indicator.
uploadProgress : function()
{
+ if (!this.form.progressUrl) {
+ return;
+ }
if (!this.haveProgress) {
Roo.MessageBox.progress("Uploading", "Uploading");
id : uid
},
method: 'GET',
- success : function(data){
+ success : function(req){
//console.log(data);
+ var rdata = false;
+ var edata;
+ try {
+ rdata = Roo.decode(req.responseText)
+ } catch (e) {
+ Roo.log("Invalid data from server..");
+ Roo.log(edata);
+ return;
+ }
+ if (!rdata || !rdata.success) {
+ Roo.log(rdata);
+ Roo.MessageBox.alert(Roo.encode(rdata));
+ return;
+ }
+ var data = rdata.data;
+
if (this.uploadComplete) {
Roo.MessageBox.hide();
return;
}
this.uploadProgress.defer(2000,this);
},
- scope : this,
- failure: function(data) {
+
+ failure: function(data) {
Roo.log('progress url failed ');
Roo.log(data);
- }
+ },
+ scope : this
});
},
var method = this.getMethod();
var isPost = method == 'POST';
if(o.clientValidation === false || this.form.isValid()){
- if (this.form.progressUrl && this.form.findField( 'UPLOAD_IDENTIFIER')) {
- // use upload progress bar..
- this.findField('UPLOAD_IDENTIFIER').setValue(
+
+ if (this.form.progressUrl) {
+ this.form.findField('UPLOAD_IDENTIFIER').setValue(
(new Date() * 1) + '' + Math.random());
-
- }
-
+ }
Roo.Ajax.request(Roo.apply(this.createCallback(), {
url:this.getUrl(!isPost),
method: method,
params:isPost ? this.getParams() : null,
- isUpload: this.form.fileUpload
+ isUpload: this.form.fileUpload,
+ formData : this.form.formData
}));
+
+ this.uploadProgress();
}else if (o.clientValidation !== false){ // client validation failed
this.failureType = Roo.form.Action.CLIENT_INVALID;
Roo.MessageBox.hide();
}
+
var result = this.processResponse(response);
if(result === true || result.success){
this.form.afterAction(this, true);
}
var ret = false;
try {
- ret = Roo.decode(response.responseText);
+ var rt = response.responseText;
+ if (rt.match(/^\<!--\[CDATA\[/)) {
+ rt = rt.replace(/^\<!--\[CDATA\[/,'');
+ rt = rt.replace(/\]\]--\>$/,'');
+ }
+
+ ret = Roo.decode(rt);
} catch (e) {
ret = {
success: false,
type : 'load',
run : function(){
+
Roo.Ajax.request(Roo.apply(
this.createCallback(), {
method:this.getMethod(),
},
success : function(response){
+
var result = this.processResponse(response);
if(result === true || !result.success || !result.data){
this.failureType = Roo.form.Action.LOAD_FAILURE;