mark record dirty if cf's changes
[tine20] / tine20 / Tinebase / js / data / Record.js
index 00decb1..84c0a8b 100644 (file)
@@ -123,10 +123,22 @@ Ext.extend(Tine.Tinebase.data.Record, Ext.data.Record, {
         if (this.modified[name] === undefined) {
             this.modified[name] = current;
         }
-        
+        if (encode(value) == encode(this.modified[name])) {
+            delete this.modified[name];
+        }
+        if (Object.keys(this.modified).length === 0) {
+            this.dirty = false;
+        }
         if (cfName = String(name).match(this.cfExp)) {
-            this.data.customfields = this.data.customfields || {};
-            this.data.customfields[cfName[1]] = value;
+            var oldValueJSON = JSON.stringify(this.get('customfields') || {}),
+                valueObject = JSON.parse(oldValueJSON);
+
+            Tine.Tinebase.common.assertComparable(valueObject);
+            valueObject[cfName[1]] = value;
+
+            if (JSON.stringify(valueObject) != oldValueJSON) {
+                this.set('customfields', valueObject);
+            }
         } else {
             this.data[name] = value;
         }