diff app/view/window/AuditTrail.js @ 1407:2195fd3946e4

Reduce code duplication.
author Tom Gottfried <tom@intevation.de>
date Wed, 22 Mar 2017 16:12:11 +0100
parents d1f6aa80758f
children 86c6b6c01246
line wrap: on
line diff
--- a/app/view/window/AuditTrail.js	Wed Mar 22 15:01:35 2017 +0100
+++ b/app/view/window/AuditTrail.js	Wed Mar 22 16:12:11 2017 +0100
@@ -118,25 +118,7 @@
                         audit[i].identifier.identifier;
 
                 }
-                if (audit[i].action === 'I') {
-                    html += '<br>angelegt<br><div style="margin-left:2em;">'
-                }
-                else {
-                    html += '<br>geändert in<br><div style="margin-left:2em;">'
-                }
-                for (var key in audit[i].changedFields) {
-                    var value = '';
-                    if (Ext.Array.contains(this.dateItems, key)) {
-                        value = Ext.Date.format(new Date(audit[i].changedFields[key]), 'd.m.Y H:i');
-                    }
-                    else {
-                        value = audit[i].changedFields[key];
-                    }
-                    html += '' + i18n.getMsg(key) + ': ' +
-                        value + '<br>';
-                }
-                html += '</div>';
-                html += '</p>';
+                html += this.createHtmlChangedFields(audit[i]);
             }
         }
         return html;
@@ -157,27 +139,31 @@
                     html += '<br>' + i18n.getMsg(audit[i].type) + ': ';
                     html += audit[i].identifier;
                 }
-                if (audit[i].action === 'I') {
-                    html += '<br>angelegt<br><div style="margin-left:2em;">'
-                }
-                else {
-                    html += '<br>geändert in<br><div style="margin-left:2em;">'
-                }
-                for (var key in audit[i].changedFields) {
-                    var value = '';
-                    if (Ext.Array.contains(this.dateItems, key)) {
-                        value = Ext.Date.format(new Date(audit[i].changedFields[key]), 'd.m.Y H:i');
-                    }
-                    else {
-                        value = audit[i].changedFields[key];
-                    }
-                    html += '' + i18n.getMsg(key) + ': ' +
-                        value + '<br>';
-                }
-                html += '</div>';
-                html += '</p>';
+                html += this.createHtmlChangedFields(audit[i]);
             }
         }
         return html;
+    },
+
+    createHtmlChangedFields: function(audit) {
+        var i18n = Lada.getApplication().bundle;
+        html = '<br>' + i18n.getMsg(audit.action)
+            + '<br><div style="margin-left:2em;">';
+
+        for (var key in audit.changedFields) {
+            var value = '';
+            if (Ext.Array.contains(this.dateItems, key)) {
+                value = Ext.Date.format(new Date(audit.changedFields[key]),
+                                        'd.m.Y H:i');
+            }
+            else {
+                value = audit.changedFields[key];
+            }
+            html += '' + i18n.getMsg(key) + ': ' +
+                value + '<br>';
+        }
+        html += '</div>';
+        html += '</p>';
+        return html;
     }
 });

http://lada.wald.intevation.org