details:   https://code.openbravo.com/erp/devel/pi/rev/eea6e57d2404
changeset: 16537:eea6e57d2404
user:      Guillermo Álvarez de Eulate <guillermo.alvarez <at> openbravo.com>
date:      Tue May 15 09:10:03 2012 +0200
summary:   Fixed issue 20277: Two files cannot be uploaded simultaneously

A new general callback has been added to manage the uploads and to avoid 
undesired cancelation of uploads which are in progress.

diffstat:

 
modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml
                                |   11 +
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-attachments.js
 |  231 +++++----
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities.js
        |    8 +
 src/org/openbravo/erpCommon/businessUtility/TabAttachments.java                
                                   |    3 +-
 4 files changed, 158 insertions(+), 95 deletions(-)

diffs (300 lines):

diff -r 8f563fb9a3b6 -r eea6e57d2404 
modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml
--- 
a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml
        Mon May 14 22:26:04 2012 +0200
+++ 
b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml
        Tue May 15 09:10:03 2012 +0200
@@ -1,5 +1,16 @@
 <?xml version='1.0' encoding='UTF-8'?>
 <data>
+<!--00D28B11D6224C649FDC51E822522686--><AD_MESSAGE>
+<!--00D28B11D6224C649FDC51E822522686-->  
<AD_MESSAGE_ID><![CDATA[00D28B11D6224C649FDC51E822522686]]></AD_MESSAGE_ID>
+<!--00D28B11D6224C649FDC51E822522686-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--00D28B11D6224C649FDC51E822522686-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--00D28B11D6224C649FDC51E822522686-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--00D28B11D6224C649FDC51E822522686-->  
<VALUE><![CDATA[OBUIAPP_OtherUploadInProgress]]></VALUE>
+<!--00D28B11D6224C649FDC51E822522686-->  <MSGTEXT><![CDATA[It seems that 
another file is being uploaded. If a new file is uploaded, the previous one 
will be canceled. Are you sure you want to upload a new file?]]></MSGTEXT>
+<!--00D28B11D6224C649FDC51E822522686-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--00D28B11D6224C649FDC51E822522686-->  
<AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--00D28B11D6224C649FDC51E822522686--></AD_MESSAGE>
+
 <!--02727C95034C407789ED4C1A86AAC58C--><AD_MESSAGE>
 <!--02727C95034C407789ED4C1A86AAC58C-->  
<AD_MESSAGE_ID><![CDATA[02727C95034C407789ED4C1A86AAC58C]]></AD_MESSAGE_ID>
 <!--02727C95034C407789ED4C1A86AAC58C-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff -r 8f563fb9a3b6 -r eea6e57d2404 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-attachments.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-attachments.js
 Mon May 14 22:26:04 2012 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-attachments.js
 Tue May 15 09:10:03 2012 +0200
@@ -194,7 +194,32 @@
     button.resetBaseStyle();
     this.fillAttachments(attachmentsobj.attachments);
   },
-
+  resetToolbar: function () {
+    var canvas = null;
+    var currentElement = null;
+    var positionOfLastMember = 0;
+    var button = 
this.getForm().view.toolBar.getLeftMember(isc.OBToolbar.TYPE_ATTACHMENTS);
+    if (!button) {
+      button = this.getForm().view.toolBar.getLeftMember("attachExists");
+    }
+    button.customState = '';
+    button.resetBaseStyle();
+    //Deleting the upload message of the cancelled upload
+    if (OB.Utilities.currentUploader) {
+      canvas = window[OB.Utilities.currentUploader];
+      if (canvas) {
+        //The last member is the cancelled upload.
+        positionOfLastMember = canvas.getMembers().size() - 1;
+        //The first member is the Hlayout where the buttons are.
+        if (positionOfLastMember > 0) {
+          currentElement = canvas.getMembers()[positionOfLastMember];
+          if (currentElement) {
+            canvas.removeMember(currentElement);
+          }
+        }
+      }
+    }
+  },
   fileExists: function (fileName, attachments) {
     var i, length;
 
@@ -228,100 +253,118 @@
       title: '[ ' + OB.I18N.getLabel('OBUIAPP_AttachmentAdd') + ' ]',
       width: '30px',
       canvas: me,
-      action: function () {
-        var attachmentFile = OB.I18N.getLabel('OBUIAPP_AttachmentFile');
-        var form = isc.DynamicForm.create({
-          fields: [{
-            name: 'inpname',
-            title: attachmentFile,
-            type: 'upload',
-            multiple: false,
-            canFocus: false,
-            align: 'right'
+      action: function (forceUpload) {
+        if (OB.Utilities.currentUploader === null || forceUpload) {
+          var attachmentFile = OB.I18N.getLabel('OBUIAPP_AttachmentFile');
+          var form = isc.DynamicForm.create({
+            fields: [{
+              name: 'inpname',
+              title: attachmentFile,
+              type: 'upload',
+              multiple: false,
+              canFocus: false,
+              align: 'right'
+            }, {
+              name: 'Command',
+              type: 'hidden',
+              value: 'SAVE_NEW_OB3'
+            }, {
+              name: 'buttonId',
+              type: 'hidden',
+              value: this.canvas.ID
+            }, {
+              name: 'inpKey',
+              type: 'hidden',
+              value: this.canvas.recordId
+            }, {
+              name: 'inpTabId',
+              type: 'hidden',
+              value: this.canvas.tabId
+            }, {
+              name: 'inpwindowId',
+              type: 'hidden',
+              value: this.canvas.windowId
+            }],
+            encoding: 'multipart',
+            action: './businessUtility/TabAttachments_FS.html',
+            target: "background_target",
+            numCols: 4,
+            align: 'center',
+            height: '30px',
+            redraw: function () {},
+            theCanvas: this.canvas
+          });
+          var submitbutton = isc.OBFormButton.create({
+            title: OB.I18N.getLabel('OBUIAPP_AttachmentSubmit'),
+            theForm: form,
+            canvas: me,
+            click: function () {
+              var fileName, form = this.theForm,
+                  addFunction;
+              addFunction = function (clickedOK) {
+                if (clickedOK) {
+                  var hTempLayout = isc.HLayout.create();
+                  form.theCanvas.addMember(hTempLayout, 
form.theCanvas.getMembers().size());
+                  var uploadingFile = isc.Label.create({
+                    contents: fileName
+                  });
+                  var uploading = isc.Label.create({
+                    className: 'OBLinkButtonItemFocused',
+                    contents: '    ' + 
OB.I18N.getLabel('OBUIAPP_AttachmentUploading')
+                  });
+                  hTempLayout.addMember(uploadingFile);
+                  hTempLayout.addMember(uploading);
+                  var button = 
form.theCanvas.getForm().view.toolBar.getLeftMember(isc.OBToolbar.TYPE_ATTACHMENTS);
+                  if (!button) {
+                    button = 
form.theCanvas.getForm().view.toolBar.getLeftMember("attachExists");
+                  }
+                  button.customState = 'Progress';
+                  button.resetBaseStyle();
+                  if (OB.Utilities.currentUploader !== null) {
+                    var origButton = window[OB.Utilities.currentUploader];
+                    if (origButton && origButton.resetToolbar) {
+                      origButton.resetToolbar();
+                    }
+                  }
+                  OB.Utilities.currentUploader = form.theCanvas.ID;
+                  form.submitForm();
+                  form.popup.hide();
+                }
+              };
+              var value = this.theForm.getItem('inpname').getElement().value;
+              if (!value) {
+                isc.say(OB.I18N.getLabel('OBUIAPP_AttachmentsSpecifyFile'));
+                return;
+              }
+              value = value ? value : '';
+
+              var lastChar = value.lastIndexOf("\\") + 1;
+
+              fileName = lastChar === -1 ? value : value.substring(lastChar);
+
+              if (this.theForm.theCanvas.fileExists(fileName, 
this.canvas.savedAttachments)) {
+                
isc.confirm(OB.I18N.getLabel('OBUIAPP_ConfirmUploadOverwrite'), addFunction);
+              } else {
+                addFunction(true);
+              }
+            }
+          });
+          var popup = isc.OBAttachmentsSubmitPopup.create({
+            submitButton: submitbutton,
+            addForm: form
+          });
+          form.popup = popup;
+          popup.show();
+        } else {
+          isc.ask(OB.I18N.getLabel('OBUIAPP_OtherUploadInProgress'), function 
(clickOK) {
+            if (clickOK) {
+              var forceUpload = true;
+              this.button.action(forceUpload);
+            }
           }, {
-            name: 'Command',
-            type: 'hidden',
-            value: 'SAVE_NEW_OB3'
-          }, {
-            name: 'buttonId',
-            type: 'hidden',
-            value: this.canvas.ID
-          }, {
-            name: 'inpKey',
-            type: 'hidden',
-            value: this.canvas.recordId
-          }, {
-            name: 'inpTabId',
-            type: 'hidden',
-            value: this.canvas.tabId
-          }, {
-            name: 'inpwindowId',
-            type: 'hidden',
-            value: this.canvas.windowId
-          }],
-          encoding: 'multipart',
-          action: './businessUtility/TabAttachments_FS.html',
-          target: "background_target",
-          numCols: 4,
-          align: 'center',
-          height: '30px',
-          redraw: function () {},
-          theCanvas: this.canvas
-        });
-        var submitbutton = isc.OBFormButton.create({
-          title: OB.I18N.getLabel('OBUIAPP_AttachmentSubmit'),
-          theForm: form,
-          canvas: me,
-          click: function () {
-            var fileName, form = this.theForm,
-                addFunction;
-            addFunction = function (clickedOK) {
-              if (clickedOK) {
-                var hTempLayout = isc.HLayout.create();
-                form.theCanvas.addMember(hTempLayout, 
form.theCanvas.getMembers().size());
-                var uploadingFile = isc.Label.create({
-                  contents: fileName
-                });
-                var uploading = isc.Label.create({
-                  className: 'OBLinkButtonItemFocused',
-                  contents: '    ' + 
OB.I18N.getLabel('OBUIAPP_AttachmentUploading')
-                });
-                hTempLayout.addMember(uploadingFile);
-                hTempLayout.addMember(uploading);
-                var button = 
form.theCanvas.getForm().view.toolBar.getLeftMember(isc.OBToolbar.TYPE_ATTACHMENTS);
-                if (!button) {
-                  button = 
form.theCanvas.getForm().view.toolBar.getLeftMember("attachExists");
-                }
-                button.customState = 'Progress';
-                button.resetBaseStyle();
-                form.submitForm();
-                form.popup.hide();
-              }
-            };
-            var value = this.theForm.getItem('inpname').getElement().value;
-            if (!value) {
-              isc.say(OB.I18N.getLabel('OBUIAPP_AttachmentsSpecifyFile'));
-              return;
-            }
-            value = value ? value : '';
-
-            var lastChar = value.lastIndexOf("\\") + 1;
-
-            fileName = lastChar === -1 ? value : value.substring(lastChar);
-
-            if (this.theForm.theCanvas.fileExists(fileName, 
this.canvas.savedAttachments)) {
-              isc.confirm(OB.I18N.getLabel('OBUIAPP_ConfirmUploadOverwrite'), 
addFunction);
-            } else {
-              addFunction(true);
-            }
-          }
-        });
-        var popup = isc.OBAttachmentsSubmitPopup.create({
-          submitButton: submitbutton,
-          addForm: form
-        });
-        form.popup = popup;
-        popup.show();
+            button: this
+          });
+        }
       }
     });
     hLayout.addMember(addButton);
diff -r 8f563fb9a3b6 -r eea6e57d2404 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities.js
        Mon May 14 22:26:04 2012 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities.js
        Tue May 15 09:10:03 2012 +0200
@@ -155,6 +155,14 @@
   return dialog;
 };
 
+OB.Utilities.uploadFinished = function (target, data) {
+  var origButton = window[target];
+  OB.Utilities.currentUploader = null;
+  if (origButton && origButton.callback) {
+    origButton.callback(data);
+  }
+};
+OB.Utilities.currentUploader = null;
 // ** {{{OB.Utilities.createLoadingLayout}}} **
 // Creates a layout with the loading image.
 OB.Utilities.createLoadingLayout = function () {
diff -r 8f563fb9a3b6 -r eea6e57d2404 
src/org/openbravo/erpCommon/businessUtility/TabAttachments.java
--- a/src/org/openbravo/erpCommon/businessUtility/TabAttachments.java   Mon May 
14 22:26:04 2012 +0200
+++ b/src/org/openbravo/erpCommon/businessUtility/TabAttachments.java   Tue May 
15 09:10:03 2012 +0200
@@ -112,7 +112,8 @@
             response.setContentType("text/html; charset=UTF-8");
             Writer writer = response.getWriter();
             writer.write("<HTML><BODY><script type=\"text/javascript\">");
-            writer.write("top." + buttonId + ".callback(" + obj.toString() + 
");");
+            writer.write("top.OB.Utilities.uploadFinished(\"" + buttonId + 
"\"," + obj.toString()
+                + ");");
             writer.write("</SCRIPT></BODY></HTML>");
           } finally {
             OBContext.restorePreviousMode();

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to