Fixed issue 16919. Now the number of notes in a record will be shown.
authorAntonio Moreno <antonio.moreno@openbravo.com>
Wed, 31 Aug 2011 17:58:02 +0200
changeset 13635 b9c2bbdb1ae6
parent 13634 16d51ad008c0
child 13636 0324c4da6bd2
Fixed issue 16919. Now the number of notes in a record will be shown.
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-notes.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java	Wed Aug 31 17:56:10 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java	Wed Aug 31 17:58:02 2011 +0200
@@ -49,6 +49,7 @@
 import org.openbravo.base.structure.ClientEnabled;
 import org.openbravo.base.structure.OrganizationEnabled;
 import org.openbravo.client.application.DynamicExpressionParser;
+import org.openbravo.client.application.Note;
 import org.openbravo.client.application.window.servlet.CalloutHttpServletResponse;
 import org.openbravo.client.application.window.servlet.CalloutServletConfig;
 import org.openbravo.client.kernel.BaseActionHandler;
@@ -247,14 +248,18 @@
       long t7 = System.currentTimeMillis();
       List<JSONObject> attachments = attachmentForRows(tab, rowId, multipleRowIds);
 
+      // Notes information
+      long t8 = System.currentTimeMillis();
+      int noteCount = computeNoteCount(tab, rowId);
+
       // Construction of the final JSONObject
-      long t8 = System.currentTimeMillis();
+      long t9 = System.currentTimeMillis();
       JSONObject finalObject = buildJSONObject(mode, tab, columnValues, row, changeEventCols,
-          calloutMessages, attachments, jsExcuteCode, hiddenInputs);
-      long t9 = System.currentTimeMillis();
+          calloutMessages, attachments, jsExcuteCode, hiddenInputs, noteCount);
+      long t10 = System.currentTimeMillis();
       log.debug("Elapsed time: " + (System.currentTimeMillis() - iniTime) + "(" + (t2 - t1) + ","
           + (t3 - t2) + "," + (t4 - t3) + "," + (t5 - t4) + "," + (t6 - t5) + "," + (t7 - t6) + ","
-          + (t8 - t7) + "," + (t9 - t8) + ")");
+          + (t8 - t7) + "," + (t9 - t8) + "," + (t10 - t9) + ")");
       log.debug("Attachment exists: " + finalObject.getBoolean("attachmentExists"));
       return finalObject;
     } catch (Throwable t) {
@@ -271,6 +276,13 @@
     return null;
   }
 
+  private int computeNoteCount(Tab tab, String rowId) {
+    OBCriteria<Note> criteria = OBDao.getFilteredCriteria(Note.class,
+        Restrictions.eq("table.id", (String) DalUtil.getId(tab.getTable())),
+        Restrictions.eq("record", rowId));
+    return criteria.count();
+  }
+
   private List<String> convertJSONArray(JSONArray jsonArray) {
     List<String> visibleProperties = new ArrayList<String>();
     for (int i = 0; i < jsonArray.length(); i++) {
@@ -312,7 +324,8 @@
 
   private JSONObject buildJSONObject(String mode, Tab tab, Map<String, JSONObject> columnValues,
       BaseOBObject row, List<String> changeEventCols, List<JSONObject> calloutMessages,
-      List<JSONObject> attachments, List<String> jsExcuteCode, Map<String, Object> hiddenInputs) {
+      List<JSONObject> attachments, List<String> jsExcuteCode, Map<String, Object> hiddenInputs,
+      int noteCount) {
     JSONObject finalObject = new JSONObject();
     try {
       if (mode.equals("NEW") || mode.equals("CHANGE")) {
@@ -407,6 +420,7 @@
             finalObject.put("_readOnly", true);
           }
         }
+        finalObject.put("noteCount", noteCount);
       }
       finalObject.put("attachments", new JSONArray(attachments));
       finalObject.put("attachmentExists", attachments.size() > 0);
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-notes.js	Wed Aug 31 17:56:10 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-notes.js	Wed Aug 31 17:58:02 2011 +0200
@@ -38,6 +38,8 @@
   canvasItem : null,
 
   visible : true,
+  
+  noteCount: 0,
  
   // this field group does not participate in personalization
   personalizable: false,
@@ -52,6 +54,15 @@
 
     this.Super('init', arguments);
   },
+  
+  setNoteCount: function(lNoteCount) {
+    this.noteCount = lNoteCount;
+    if(lNoteCount !== 0) {
+      this.setValue(OB.I18N.getLabel('OBUIAPP_NotesTitle') + ' (' + lNoteCount+')');
+    }else{
+      this.setValue(OB.I18N.getLabel('OBUIAPP_NotesTitle'));
+    }
+  },
 
   getNotePart : function() {
     if (!this.canvasItem) {
@@ -132,6 +143,8 @@
 
     // clean text area
     this.noteDynamicForm.getItem('noteOBTextAreaItem').clearValue();
+    
+    this.parentElement.noteSection.setNoteCount(this.parentElement.noteSection.noteCount + 1);
   },
 
   /**
@@ -139,11 +152,13 @@
    */
   deleteNote : function( /* note id to delete */id) {
     var noteDS = this.getNoteDataSource();
+    var noteSection = this.parentElement.noteSection;
     isc.confirm(OB.I18N.getLabel('OBUIAPP_ConfirmRemoveNote'), function(clickedOK){
       if(clickedOK){
         noteDS.removeData({
           'id' : id
         });
+        noteSection.setNoteCount(noteSection.noteCount - 1);
       }
     },{title: OB.I18N.getLabel('OBUIAPP_ConfirmRemoveTitle')});
   },
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js	Wed Aug 31 17:56:10 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js	Wed Aug 31 17:58:02 2011 +0200
@@ -633,6 +633,15 @@
     if(this.attachmentsSection) {
       this.attachmentsSection.fillAttachments(data.attachments);
     }
+    
+    // We will show the note count if it has been calculated and is different from 0
+    if(this.noteSection) {
+      if(data.noteCount) {
+        this.noteSection.setNoteCount(data.noteCount);
+      } else if(request.params.MODE === 'EDIT') {
+        this.noteSection.setNoteCount(0);
+      }
+    }
 
     // apparently sometimes an empty string is returned
     if (calloutMessages && calloutMessages.length > 0 && calloutMessages[0].text !== '') {