Răsfoiți Sursa

修复附件上传出错进度条没有删除的问题

unknown 5 ani în urmă
părinte
comite
4c4815b7bc

+ 32 - 6
o2web/source/o2_core/o2/widget/AttachmentController.js

@@ -742,11 +742,11 @@ o2.widget.AttachmentController = o2.widget.ATTER  = new Class({
     uploadAttachment: function(e, node){
         if (this.module) this.module.uploadAttachment(e, node);
     },
-    doUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size){
+    doUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery){
         if (FormData.expiredIE){
-            this.doInputUploadAttachment(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size);
+            this.doInputUploadAttachment(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery);
         }else{
-            this.doFormDataUploadAttachment(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size);
+            this.doFormDataUploadAttachment(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery);
         }
     },
     addUploadMessage: function(fileName){
@@ -788,7 +788,7 @@ o2.widget.AttachmentController = o2.widget.ATTER  = new Class({
         }
 
     },
-    doInputUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept){
+    doInputUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, failureEvery){
         var restActions = action;
         if (typeOf(action)=="string"){
             restActions = o2.Actions.get(action).action;
@@ -835,6 +835,7 @@ o2.widget.AttachmentController = o2.widget.ATTER  = new Class({
                     if(finish) finish();
                 }else{
                     //formNode.unmask();
+                    // if(failureEvery)failureEvery(json);
                     this.setMessageTitle(messageItem, o2.LP.desktop.action.sendError);
                     this.setMessageText(messageItem, o2.LP.desktop.action.sendError+": "+json.message);
                     o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
@@ -897,7 +898,7 @@ o2.widget.AttachmentController = o2.widget.ATTER  = new Class({
             }.bind(this));
         }.bind(this));
     },
-    doFormDataUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size){
+    doFormDataUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery){
         if (!this.uploadFileAreaNode){
             this.uploadFileAreaNode = new Element("div");
             var html = "<input name=\"file\" multiple type=\"file\" accept=\"*/*\"/>";
@@ -909,6 +910,7 @@ o2.widget.AttachmentController = o2.widget.ATTER  = new Class({
                 if (files.length){
                     var count = files.length;
                     var current = 0;
+                    var hasFailUpload = false;
 
                     var restActions = action;
                     if (typeOf(action)=="string"){
@@ -918,7 +920,7 @@ o2.widget.AttachmentController = o2.widget.ATTER  = new Class({
 
                     var callback = function(){
                         if (current == count){
-                            if(finish) finish();
+                            if(finish) finish( hasFailUpload );
                         }
                     };
 
@@ -992,6 +994,14 @@ o2.widget.AttachmentController = o2.widget.ATTER  = new Class({
                                                                     current++;
                                                                     if (every) every(json, current, count);
                                                                     callback();
+                                                                },
+                                                                "failure": function (xhr) {
+                                                                    var json = JSON.decode(xhr.responseText);
+                                                                    if( json && json.message )o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
+                                                                    current++;
+                                                                    hasFailUpload = true;
+                                                                    if (failureEvery) failureEvery(xhr, current, count);
+                                                                    callback();
                                                                 }
                                                             });
                                                         }else{
@@ -1005,6 +1015,14 @@ o2.widget.AttachmentController = o2.widget.ATTER  = new Class({
                                                                     current++;
                                                                     if (every) every(json, current, count);
                                                                     callback();
+                                                                },
+                                                                "failure": function (xhr) {
+                                                                    var json = JSON.decode(xhr.responseText);
+                                                                    if( json && json.message )o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
+                                                                    current++;
+                                                                    hasFailUpload = true;
+                                                                    if (failureEvery) failureEvery(xhr, current, count);
+                                                                    callback();
                                                                 }
                                                             });
                                                         }
@@ -1036,6 +1054,14 @@ o2.widget.AttachmentController = o2.widget.ATTER  = new Class({
                                             current++;
                                             if (every) every(json, current, count);
                                             callback();
+                                        },
+                                        "failure": function (xhr) {
+                                            var json = JSON.decode(xhr.responseText);
+                                            if( json && json.message )o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
+                                            current++;
+                                            hasFailUpload = true;
+                                            if (failureEvery) failureEvery(xhr, current, count);
+                                            callback();
                                         }
                                     });
                                 }

+ 6 - 0
o2web/source/o2_core/o2/xDesktop/Actions/RestActions.js

@@ -367,13 +367,19 @@ MWF.xDesktop.Actions.RestActions = new Class({
                         }, xhr.responseText]);
                         break;
                     case "error":
+                        var messageId = (messageItem && messageItem.moduleMessage) ? messageItem.moduleMessage.data.id : "";
+                        if( messageId && xhr )xhr.messageId = messageId;
                         MWF.runCallback(callback, "failure", [xhr]);
                         break;
                 }
             }else{
+                var messageId = (messageItem && messageItem.moduleMessage) ? messageItem.moduleMessage.data.id : "";
+                if( messageId && xhr )xhr.messageId = messageId;
                 MWF.runCallback(callback, "failure", [xhr]);
             }
         }else{
+            var messageId = (messageItem && messageItem.moduleMessage) ? messageItem.moduleMessage.data.id : "";
+            if( messageId && xhr )xhr.messageId = messageId;
             MWF.runCallback(callback, "failure", [xhr]);
         }
     },

+ 34 - 20
o2web/source/x_component_Forum/Attachment.js

@@ -81,28 +81,42 @@ MWF.xApplication.Forum.Attachment = new Class({
     },
 
     createUploadFileNode: function () {
-        this.attachmentController.doUploadAttachment({"site": this.options.documentId}, this.actions.action, "uploadAttachment", {"id": this.options.documentId, "documentid":this.options.documentId}, null, function(o){
-            j = o;
-            if ( j.data ) {
-                //j.userMessage
-                var aid = typeOf( j.data ) == "object" ? j.data.id : j.data[0].id;
-                this.actions.getAttachment(aid, this.options.documentId, function (json) {
-                    json = this.transportData(json);
-                    if (json.data) {
-                        this.attachmentController.addAttachment(json.data, o.messageId);
-                        //this.attachmentList.push(json.data);
-                    }
-                    this.attachmentController.checkActions();
+        this.attachmentController.doUploadAttachment(
+            {"site": this.options.documentId},
+            this.actions.action,
+            "uploadAttachment",
+            {"id": this.options.documentId, "documentid":this.options.documentId},
+            null,
+            function(o){
+                var j = o;
+                if ( j.data ) {
+                    //j.userMessage
+                    var aid = typeOf( j.data ) == "object" ? j.data.id : j.data[0].id;
+                    this.actions.getAttachment(aid, this.options.documentId, function (json) {
+                        json = this.transportData(json);
+                        if (json.data) {
+                            this.attachmentController.addAttachment(json.data, o.messageId);
+                            //this.attachmentList.push(json.data);
+                        }
+                        this.attachmentController.checkActions();
 
-                    this.fireEvent("upload", [json.data]);
-                    this.fireEvent("change");
-                }.bind(this))
+                        this.fireEvent("upload", [json.data]);
+                        this.fireEvent("change");
+                    }.bind(this))
+                }
+                this.attachmentController.checkActions();
+            }.bind(this),
+            function(files){
+                this.isQueryUploadSuccess = true;
+                this.fireEvent( "queryUploadAttachment" );
+                return this.isQueryUploadSuccess;
+            }.bind(this),
+            null, null, null,
+            function (o) { //错误的回调
+            if (o.messageId && this.attachmentController.messageItemList) {
+                var message = this.attachmentController.messageItemList[o.messageId];
+                if( message && message.node )message.node.destroy();
             }
-            this.attachmentController.checkActions();
-        }.bind(this), function(files){
-            this.isQueryUploadSuccess = true;
-            this.fireEvent( "queryUploadAttachment" );
-            return this.isQueryUploadSuccess;
         }.bind(this));
         // this.uploadFileAreaNode = new Element("div");
         // var html = "<input name=\"file\" type=\"file\" multiple/>";

+ 13 - 2
o2web/source/x_component_cms_Xform/Attachment.js

@@ -203,6 +203,7 @@ MWF.xApplication.cms.Xform.Attachment = MWF.CMSAttachment = new Class({
         }
         var size = 0;
         if (this.json.attachmentSize) size = this.json.attachmentSize.toFloat();
+        debugger;
         this.attachmentController.doUploadAttachment({ "site": this.json.id }, this.form.documentAction.action, "uploadAttachment", { "id": this.form.businessData.document.id }, null, function (o) {
             if (o.id) {
                 this.form.documentAction.getAttachment(o.id, this.form.businessData.document.id, function (json) {
@@ -227,7 +228,12 @@ MWF.xApplication.cms.Xform.Attachment = MWF.CMSAttachment = new Class({
                 }
             }
             return true;
-        }.bind(this), true, accept, size);
+        }.bind(this), true, accept, size, function (o) { //错误的回调
+            if (o.messageId && this.attachmentController.messageItemList) {
+                var message = this.attachmentController.messageItemList[o.messageId];
+                if( message && message.node )message.node.destroy();
+            }
+        }.bind(this));
 
         // this.uploadFileAreaNode = new Element("div");
         // var html = "<input name=\"file\" type=\"file\" multiple/>";
@@ -366,7 +372,12 @@ MWF.xApplication.cms.Xform.Attachment = MWF.CMSAttachment = new Class({
 
                     this.attachmentController.checkActions();
                 }.bind(this))
-            }.bind(this), null);
+            }.bind(this), null, true, accept, size, function (o) { //错误的回调
+                if (o.messageId && this.attachmentController.messageItemList) {
+                    var message = this.attachmentController.messageItemList[o.messageId];
+                    if( message && message.node )message.node.destroy();
+                }
+            }.bind(this));
 
         // this.replaceFileAreaNode = new Element("div");
         // var html = "<input name=\"file\" type=\"file\" multiple/>";

+ 12 - 2
o2web/source/x_component_process_Xform/Attachment.js

@@ -1210,7 +1210,12 @@ MWF.xApplication.process.Xform.Attachment = MWF.APPAttachment = new Class({
                 }
             }
             return true;
-        }.bind(this), true, accept, size);
+        }.bind(this), true, accept, size, function (o) { //错误的回调
+            if (o.messageId && this.attachmentController.messageItemList) {
+                var message = this.attachmentController.messageItemList[o.messageId];
+                if( message && message.node )message.node.destroy();
+            }
+        }.bind(this));
 
 
         // this.uploadFileAreaNode = new Element("div");
@@ -1405,7 +1410,12 @@ MWF.xApplication.process.Xform.Attachment = MWF.APPAttachment = new Class({
 
                     this.attachmentController.checkActions();
                 }.bind(this))
-            }.bind(this), null, true, accept, size);
+            }.bind(this), null, true, accept, size, function (o) { //错误的回调
+                if (o.messageId && this.attachmentController.messageItemList) {
+                    var message = this.attachmentController.messageItemList[o.messageId];
+                    if( message && message.node )message.node.destroy();
+                }
+            }.bind(this));
 
         // this.replaceFileAreaNode = new Element("div");
         // var html = "<input name=\"file\" type=\"file\" multiple/>";