[Lada-commits] [PATCH 2 of 2] Use treeModiefied timestamp to determine if working with 'old' objects

Wald Commits scm-commit at wald.intevation.org
Wed Mar 25 16:46:20 CET 2015


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1427298408 -3600
# Node ID e88381fb3bdb77dc8628b1b74476ce1b4c429a37
# Parent  c07419f07a0c55ab7a4d9c1b83538b4d06c5375d
Use treeModiefied timestamp to determine if working with 'old' objects.

diff -r c07419f07a0c -r e88381fb3bdb app/controller/grid/Messung.js
--- a/app/controller/grid/Messung.js	Wed Mar 25 16:45:29 2015 +0100
+++ b/app/controller/grid/Messung.js	Wed Mar 25 16:46:48 2015 +0100
@@ -31,7 +31,10 @@
     },
 
     editItem: function(grid, record) {
+        var probe = grid.up('window').record;
         var win = Ext.create('Lada.view.window.MessungEdit', {
+            parentWindow: grid.up('window'),
+            probe: probe,
             record: record,
             grid: grid
         });
diff -r c07419f07a0c -r e88381fb3bdb app/controller/grid/Ort.js
--- a/app/controller/grid/Ort.js	Wed Mar 25 16:45:29 2015 +0100
+++ b/app/controller/grid/Ort.js	Wed Mar 25 16:46:48 2015 +0100
@@ -29,7 +29,10 @@
     },
 
     open: function(grid, record) {
+        var probe = grid.up('window').record;
         var win = Ext.create('Lada.view.window.OrtEdit', {
+            parentWindow: grid.up('window'),
+            probe: probe,
             record: record,
             grid: grid
         });
diff -r c07419f07a0c -r e88381fb3bdb app/view/window/MessungEdit.js
--- a/app/view/window/MessungEdit.js	Wed Mar 25 16:45:29 2015 +0100
+++ b/app/view/window/MessungEdit.js	Wed Mar 25 16:46:48 2015 +0100
@@ -26,6 +26,9 @@
     autoscroll: true,
     layout: 'fit',
     constrain: true,
+
+    probe: null,
+    parentWindow: null,
     record: null,
     grid: null,
 
@@ -35,6 +38,11 @@
             this.callParent(arguments);
             return;
         }
+        if (this.probe === null) {
+            Ext.Msg.alert('Zu der Messung existiert keine Probe!');
+            this.callParent(arguments);
+            return;
+        }
         this.title = 'Messung ' + this.record.get('nebenprobenNr');
         this.buttons = [{
             text: 'Schließen',
@@ -88,14 +96,33 @@
 
     initData: function() {
         this.clearMessages();
-        this.down('messungform').setRecord(this.record);
         Ext.ClassManager.get('Lada.model.Messung').load(this.record.get('id'), {
             failure: function(record) {
                 // TODO
                 console.log(record);
             },
             success: function(record, response) {
+                var me = this;
+                if (this.probe.get('treeModified') < record.get('treeModified')) {
+                    Ext.Msg.show({
+                        title: 'Probe nicht aktuell!',
+                        msg: 'Die zugehörige Probe wurde verändert.\nMöchten Sie zu der Probe zurückkehren und neu laden?\nOhne das erneute Laden der Probe wird das Speichern der Messung nicht möglich sein.',
+                        buttons: Ext.Msg.OKCANCEL,
+                        icon: Ext.Msg.WARNING,
+                        closable: false,
+                        fn: function(button) {
+                            if (button === 'ok') {
+                                me.close();
+                                me.parentWindow.initData();
+                            }
+                            else {
+                                me.record.set('treeModified', me.probe.get('treeModified'));
+                            }
+                        }
+                    });
+                }
                 this.down('messungform').setRecord(record);
+                this.record = record;
                 var json = Ext.decode(response.response.responseText);
                 if (json) {
                     this.setMessages(json.errors, json.warnings);
@@ -103,23 +130,6 @@
             },
             scope: this
         });
-
-        if (this.record.get('readonly') == true){
-            this.down('messungform').setReadOnly(true);
-            this.disableChildren();
-        }
-     },
-
-    disableChildren: function(){
-            this.down('fset[name=messwerte]').down('messwertgrid').setReadOnly(true);
-            this.down('fset[name=messungstatus]').down('statusgrid').setReadOnly(true);
-            this.down('fset[name=messungskommentare]').down('mkommentargrid').setReadOnly(true);
-    },
-
-    enableChildren: function(){
-            this.down('fset[name=messwerte]').down('messwertgrid').setReadOnly(false);
-            this.down('fset[name=messungstatus]').down('statusgrid').setReadOnly(false);
-            this.down('fset[name=messungskommentare]').down('mkommentargrid').setReadOnly(false);
     },
 
     setMessages: function(errors, warnings) {
diff -r c07419f07a0c -r e88381fb3bdb app/view/window/OrtEdit.js
--- a/app/view/window/OrtEdit.js	Wed Mar 25 16:45:29 2015 +0100
+++ b/app/view/window/OrtEdit.js	Wed Mar 25 16:46:48 2015 +0100
@@ -25,6 +25,8 @@
     layout: 'border',
     constrain: true,
 
+    parentWindow: null,
+    probe: null,
     record: null,
     grid: null,
 
@@ -34,6 +36,11 @@
             this.callParent(arguments);
             return;
         }
+        if (this.probe === null) {
+            Ext.Msg.alert('Zu dem Ort existiert keine Probe!');
+            this.callParent(arguments);
+            return;
+        }
         this.title = 'Ort';
         this.buttons = [{
             text: 'Schließen',
@@ -83,7 +90,35 @@
     },
 
     initData: function() {
-        this.down('ortform').setRecord(this.record);
+        Ext.ClassManager.get('Lada.model.Ort').load(this.record.get('id'), {
+            failure: function(record, action) {
+                // TODO
+            },
+            success: function(record, response) {
+                var me = this;
+                if (this.probe.get('treeModified') < record.get('treeModified')) {
+                    Ext.Msg.show({
+                        title: 'Probe nicht aktuell!',
+                        msg: 'Die zugehörige Probe wurde verändert.\nMöchten Sie zu der Probe zurückkehren und neu laden?\nOhne das erneute Laden der Probe wird das Speichern des Ortes nicht möglich sein.',
+                        buttons: Ext.Msg.OKCANCEL,
+                        icon: Ext.Msg.WARNING,
+                        closable: false,
+                        fn: function(button) {
+                            if (button === 'ok') {
+                                me.close();
+                                me.parentWindow.initData();
+                            }
+                            else {
+                                me.record.set('treeModified', me.probe.get('treeModified'));
+                            }
+                        }
+                    });
+                }
+                this.down('ortform').setRecord(record);
+                this.record = record;
+            },
+            scope: this
+        });
         Ext.ClassManager.get('Lada.model.Location').load(this.record.get('ort'), {
             failure: function(record, action) {
                 // TODO
diff -r c07419f07a0c -r e88381fb3bdb app/view/window/ProbeEdit.js
--- a/app/view/window/ProbeEdit.js	Wed Mar 25 16:45:29 2015 +0100
+++ b/app/view/window/ProbeEdit.js	Wed Mar 25 16:46:48 2015 +0100
@@ -114,6 +114,7 @@
             },
             success: function(record, response) {
                 this.down('probeform').setRecord(record);
+                this.record = record;
                 var json = Ext.decode(response.response.responseText);
                 if (json) {
                     this.setMessages(json.errors, json.warnings);


More information about the Lada-commits mailing list