changeset 1347:2fc8e2b3c456

fix ortszuordnung 'revert' if record is new ortszuordnung
author Maximilian Krambach <mkrambach@intevation.de>
date Mon, 06 Feb 2017 12:33:00 +0100
parents 8742d020c685
children 26e0aec2eb31
files app/controller/form/Ortszuordnung.js app/view/form/Ortszuordnung.js
diffstat 2 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/app/controller/form/Ortszuordnung.js	Mon Feb 06 12:02:37 2017 +0100
+++ b/app/controller/form/Ortszuordnung.js	Mon Feb 06 12:33:00 2017 +0100
@@ -113,14 +113,17 @@
         var osg = button.up('window').down('ortstammdatengrid');
         var recordData = form.getForm().getRecord().data;
         var currentOrt = recordData.ortId;
-        var record = osg.store.getById(currentOrt);
         var selmod = osg.getView().getSelectionModel();
         form.getForm().reset();
-        form.setOrt(null, record);
+        if (!currentOrt) {
+            selmod.deselectAll();
+        } else {
+            var record = osg.store.getById(currentOrt);
+            form.setOrt(null, record);
+            selmod.select(record);
+        }
         button.setDisabled(true);
         button.up('toolbar').down('button[action=save]').setDisabled(true);
-        var selmod = osg.getView().getSelectionModel();
-        selmod.select(record);
     },
 
     /**
@@ -190,12 +193,14 @@
      * is present in the toolbar of the form.
      */
     validityChange: function(form, valid) {
-        // the form itself seems to be always dirty because of the ortinfo
-        // values put into the form at later moments. Check whether a real
-        // commit field is dirty
+        // the simple form.isDirty() check seems to fail for a lot of cases
+        var ortIdIsDirty = true;
+        if (form.getRecord().data.ortId == form.findField('ortId').getValue()) {
+            ortIdIsDirty = false;
+        }
         if (form.findField('ortszusatztext').isDirty()
             || form.findField('ortszuordnungTyp').isDirty()
-            || form.findField('ortId').isDirty()) {
+            || ortIdIsDirty) {
             form.owner.down('button[action=revert]').setDisabled(false);
             if (valid && form.getValues().ortId !== '') {
                 form.owner.down('button[action=save]').setDisabled(false);
--- a/app/view/form/Ortszuordnung.js	Mon Feb 06 12:02:37 2017 +0100
+++ b/app/view/form/Ortszuordnung.js	Mon Feb 06 12:33:00 2017 +0100
@@ -73,6 +73,7 @@
                         qtip: 'Ă„nderungen verwerfen',
                         icon: 'resources/img/dialog-cancel.png',
                         action: 'revert',
+                        disabled: true
                     }]
                 }],
                 items: [{
@@ -141,7 +142,9 @@
      * it will set the ortId of this record
      */
     setOrt: function(row, selRecord, index, opts) {
-        var newOrtId = selRecord.get('id');
+        if (selRecord) {
+            var newOrtId = selRecord.get('id');
+        }
         if (newOrtId) {
             this.getForm().setValues({ortId: newOrtId});
             this.setOrtInfo(selRecord);

http://lada.wald.intevation.org