changeset 447:12231f31c112

Apply new workflow in orte dialog.
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 05 Dec 2013 09:57:57 +0100
parents b3e806045a5a
children bd2b26c249e2
files app/controller/Orte.js app/view/orte/CreateForm.js
diffstat 2 files changed, 58 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/app/controller/Orte.js	Thu Dec 05 09:56:50 2013 +0100
+++ b/app/controller/Orte.js	Thu Dec 05 09:57:57 2013 +0100
@@ -5,7 +5,8 @@
     extend: 'Lada.controller.Base',
     views: [
         'orte.List',
-        'orte.Create'
+        'orte.Create',
+        'orte.CreateOrt'
     ],
     stores: [
         'Orte',
@@ -34,6 +35,12 @@
             'ortecreate button[action=save]': {
                 click: this.saveItem
             },
+            'ortecreate form button[action=newort]': {
+                click: this.createOrt
+            },
+            'createortdetail button[action=save]': {
+                click: this.saveNewOrt
+            },
             'ortecreate form': {
                 savesuccess: this.createSuccess,
                 savefailure: this.createFailure
@@ -44,6 +51,41 @@
             }
         });
     },
+    createOrt: function(button) {
+        console.log('button clicked');
+        var win = Ext.create('Lada.view.orte.CreateOrt',{});
+        win.show();
+    },
+    saveNewOrt: function(button) {
+        console.log('button clicked');
+
+        var form = button.up('window').down('form').getForm();
+        var ortdetailstore = Ext.getStore('Ortedetails');
+        var ortdetail = Ext.create('Lada.model.Ortdetail');
+        var fields = ['beschreibung', 'hoeheLand',
+                      'latitude', 'longitude', 'staatId', 'gemId'];
+        for (var i = fields.length - 1; i >= 0; i--){
+            var ffield = form.findField("ort_"+fields[i]);
+            ortdetail.set(fields[i], ffield.getValue());
+        }
+        ortdetailstore.add(ortdetail);
+        ortdetailstore.sync({
+            success: function(batch, options) {
+                console.log(batch);
+                var od = Ext.ComponentQuery.query('ortdetail');
+                console.log(od);
+                batch.operations[0].resultSet.records[0].data;
+                var response = batch.operations[0].resultSet.records[0].data;
+                od[0].setValue(response.ortId);
+                console.log('id:' + response.ortId);
+                button.up('window').close();
+            },
+            failure: function() {
+                console.log('Error on saving Ortdetails');
+                ortdetailstore.remove(ortdetail);
+            }
+        });
+    },
     saveItem: function(button) {
         console.log('Saving Ort');
         var form = button.up('window').down('form');
@@ -100,7 +142,7 @@
         console.log("Loaded Ort with ID " + record.getId()); //outputs ID
     },
     initEditWindow: function(record, readonly, owner) {
-        var view = Ext.widget('ortecreate', {model: record});
+        var view = Ext.widget('ortecreate', {model: record, edit: true});
         var ignore = Array();
         if (readonly) {
             var form = view.down('form');
--- a/app/view/orte/CreateForm.js	Thu Dec 05 09:56:50 2013 +0100
+++ b/app/view/orte/CreateForm.js	Thu Dec 05 09:57:57 2013 +0100
@@ -7,8 +7,10 @@
     requires: [
         'Lada.view.widgets.Ortdetail',
         'Lada.view.widgets.Staat',
-        'Lada.view.widgets.Verwaltungseinheit'
+        'Lada.view.widgets.Verwaltungseinheit',
+        'Lada.view.orte.CreateOrt'
     ],
+    edit: false,
     initComponent: function() {
         this.items = [
             {
@@ -18,6 +20,9 @@
                 listeners: {
                     scope: this,
                     'change': function (field, newv, oldv, opts) {
+                        if (field.up('window')) {
+                            field.up('window').down('fieldset').show();
+                        }
                         var orte = Ext.getStore('Ortedetails');
                         var ort = orte.getById(newv);
                         var fields = ['beschreibung', 'bezeichnung', 'hoeheLand',
@@ -57,8 +62,16 @@
                 fieldLabel: 'Ortszusatz'
             },
             {
+                xtype: 'button',
+                name: 'newort',
+                text: 'Neuen Ort Anlegen',
+                hidden: this.edit,
+                action: 'newort'
+            },
+            {
                 xtype: 'fieldset',
                 title: 'Ortsangaben',
+                hidden: !this.edit,
                 defaults: {
                         labelWidth: 150
                 },

http://lada.wald.intevation.org