From cd7df4a7846e21980ecd161dbf9f5c84d59983fb Mon Sep 17 00:00:00 2001
From: Markus Escher <m.escher@adito.de>
Date: Tue, 27 Nov 2018 08:19:48 +0100
Subject: [PATCH] add documentation apply code guidelines change previewField
 to readonly

---
 entity/Document_entity/Document_entity.aod    |  1 +
 entity/Document_entity/contentProcess.js      | 13 +++----
 .../_____PREFERENCES_PROJECT.aod              |  2 +-
 process/Document_lib/process.js               | 36 ++++++++++++-------
 4 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/entity/Document_entity/Document_entity.aod b/entity/Document_entity/Document_entity.aod
index 51187c3cef3..f943b39d25d 100644
--- a/entity/Document_entity/Document_entity.aod
+++ b/entity/Document_entity/Document_entity.aod
@@ -48,6 +48,7 @@
       <title>Vorschau</title>
       <fieldName>PREVIEW</fieldName>
       <contentType>IMAGE</contentType>
+      <state>READONLY</state>
     </entityField>
     <entityIncomingField>
       <name>OrgDocument_dfi</name>
diff --git a/entity/Document_entity/contentProcess.js b/entity/Document_entity/contentProcess.js
index eba3027b5c0..1b32f4aed32 100644
--- a/entity/Document_entity/contentProcess.js
+++ b/entity/Document_entity/contentProcess.js
@@ -2,25 +2,26 @@ import("system.vars");
 import("system.result");
 import("system.db");
 
+// Check if assignment parameters are present
 if(vars.exists("$param.AssignmentTable_param") &&
     vars.exists("$param.AssignmentName_param") &&
-    vars.exists("$param.AssignmentRowId_param"))
-{
+    vars.exists("$param.AssignmentRowId_param")) {
     var assignmentTable = vars.get("$param.AssignmentTable_param");
     var assignmentName = vars.get("$param.AssignmentName_param");
     var assignmentRowId = vars.get("$param.AssignmentRowId_param");
     var alias = db.getCurrentAlias();
     var documents = [];
     
-    // Check for Selection
+    // Check if multiple Documents are selected
     if(vars.exists("$local.idvalues") && vars.get("$local.idvalues") != '')
         metadata = db.getBinaryMetadataForIds(vars.get("$local.idvalues"), true, alias)
     else
         metadata = db.getBinaryMetadata(assignmentTable, assignmentName, assignmentRowId, false, alias);    
 
-    for( var i = 0; i < metadata.length; i++)
-    {
-        documents.push( [metadata[i].id, metadata[i].filename, metadata[i].size, metadata[i].edit, metadata[i].preview, metadata[i].mimetype]);
+    // Iterate through found binaray data and populate result array    
+    for( var i = 0; i < metadata.length; i++) {
+        documents.push( [metadata[i].id, metadata[i].filename, metadata[i].size, 
+            metadata[i].edit, metadata[i].preview, metadata[i].mimetype]);
     }
 
     result.object(documents);
diff --git a/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod b/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod
index 1ea4864f5a7..473ef689d83 100644
--- a/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod
+++ b/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod
@@ -2,7 +2,7 @@
 <preferences xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="3.0.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/preferences/3.0.1">
   <name>_____PREFERENCES_PROJECT</name>
   <majorModelMode>DISTRIBUTED</majorModelMode>
-  <projectName>xRM-Basic-5-1</projectName>
+  <projectName>xRM-Basic5</projectName>
   <jditoMaxContentSize v="57671680" />
   <calendarCategoriesEvent>
     <entry>
diff --git a/process/Document_lib/process.js b/process/Document_lib/process.js
index 0e53a27da48..4b811e6a60a 100644
--- a/process/Document_lib/process.js
+++ b/process/Document_lib/process.js
@@ -3,29 +3,39 @@ import("system.db");
 import("system.vars");
 import("system.neon");
 
+/**
+ * Provides static methods for managing documents.
+ * Do not create an instance of this
+ * 
+ * @static
+ * @class
+ */
 function DocumentUtil(){    
 }
 
-DocumentUtil.downloadSelectedDocuments = function(){
+/**
+ * Utility function to download all selected or open documents.
+ * Selected documents will be checked with $local.uids.
+ * Open documents will be checked with $field.id.
+ * Documents will be downloaded with neon.doanload
+ */
+DocumentUtil.downloadSelectedDocuments = function() {
     var alias = db.getCurrentAlias();
     
-    // Multiple Files (=not oppened)
-    if(vars.exists("$local.uids"))
-    {
+    // Download selected files (=not oppened)
+    if(vars.exists("$local.uids")) {
         var rows = JSON.parse(vars.get("$local.rows"));
         var uids = JSON.parse(vars.get("$local.uids"));   
         var binaryContents = db.getBinaryContents(uids, alias);     
 
-        for(var i = 0; i < binaryContents.length; i++)
-        {   
+        for(var i = 0; i < binaryContents.length; i++) {   
             var base64data = binaryContents[i];
             var filename = rows[i]["NAME"];
             neon.download(base64data, filename);        
         }
     }
-    // Single File (=already opened)
-    else if(vars.exists("$field.ID"))
-    {
+    // Download open file
+    else if(vars.exists("$field.ID")) {
         var id = vars.get("$field.ID");
         var name = vars.get("$field.NAME");
         var binaryContent = db.getBinaryContent(id, alias); 
@@ -33,9 +43,11 @@ DocumentUtil.downloadSelectedDocuments = function(){
     }
 }
 
-DocumentUtil.deleteCurrentDocument = function(){
-    if(vars.exists("$local.uid"))
-    {
+/**
+ * Utility function to delete the current/opened Document.
+ */
+DocumentUtil.deleteCurrentDocument = function() {
+    if(vars.exists("$local.uid")) {
         var uid = vars.get("$local.uid");   
         var alias = db.getCurrentAlias();
         db.deleteBinary(uid, alias);
-- 
GitLab