Related with issue 36838: multiple requests to load product image are performed
authorInigo Sanchez <inigo.sanchez@openbravo.com>
Sat, 28 Oct 2017 13:27:49 +0200
changeset 32887 82a3e88a20e8
parent 32886 8071a84ccfe2
child 32901 be7ca3e335fd
Related with issue 36838: multiple requests to load product image are performed

The problem was that multiple ShowImage requests were performed when it shouldn't.

Now, the problem is fixed by take into account when the image has been loaded previously. In this case,
the setValue of the ob-formitem-image avoids to performed an unnecessary request to the server.
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-image.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-image.js	Fri Oct 20 11:58:31 2017 +0530
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-image.js	Sat Oct 28 13:27:49 2017 +0200
@@ -241,8 +241,10 @@
     if (!newValue || newValue === '') {
       this.canvas.setImage('');
     } else {
-      this.canvas.setImage("../utility/ShowImage?id=" + newValue + '&nocache=' + Math.random());
-      if (this.getValue() !== newValue) {
+      if (this.isLoadedCurrentImage(newValue)) {
+        this.canvas.setImage(this.canvas.image.src);
+      } else {
+        this.canvas.setImage("../utility/ShowImage?id=" + newValue + '&nocache=' + Math.random());
         var d = {
           inpimageId: newValue,
           command: 'GETSIZE'
@@ -276,6 +278,9 @@
     this.canvas.selectorButton.updateState((this.form && !this.form.readOnly) && !this.disabled);
     return this.Super('setValue', arguments);
   },
+  isLoadedCurrentImage: function (imageId) {
+    return this.canvas.image && this.canvas.image.src && this.canvas.image.src.contains('ShowImage?id=' + imageId);
+  },
   refreshImage: function (imageId) {
     //If creating/replacing an image, the form is marked as modified
     //and the image id is set as the value of the item