changeset 603:9d0113bc2f70

Added ort form and controller.
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 12 Mar 2015 15:51:24 +0100
parents e1ab24758392
children 2f17dd53e69f
files app/controller/form/Ort.js app/view/form/Ort.js
diffstat 2 files changed, 192 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/controller/form/Ort.js	Thu Mar 12 15:51:24 2015 +0100
@@ -0,0 +1,96 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+
+Ext.define('Lada.controller.form.Ort', {
+    extend: 'Ext.app.Controller',
+
+    init: function() {
+        this.control({
+            'ortform button[action=save]': {
+                click: this.save
+            },
+            'ortform button[action=discard]': {
+                click: this.discard
+            },
+            'ortform': {
+                dirtychange: this.dirtyForm
+            },
+            'ortform combobox[name=ort]': {
+                select: this.updateDetails
+            }
+        });
+    },
+
+    save: function(button) {
+        var formPanel = button.up('form');
+        var data = formPanel.getForm().getFieldValues(true);
+        for (var key in data) {
+            formPanel.getForm().getRecord().set(key, data[key]);
+        }
+        formPanel.getForm().getRecord().save({
+            success: function(record, response) {
+                var json = Ext.decode(response.response.responseText);
+                if (response.action !== 'create' &&
+                    json &&
+                    json.success) {
+                    button.setDisabled(true);
+                    button.up('toolbar').down('button[action=discard]')
+                        .setDisabled(true);
+                    formPanel.clearMessages();
+                    formPanel.setRecord(record);
+                    formPanel.setMessages(json.errors, json.warnings);
+                }
+            },
+            failure: function(record, response) {
+                button.setDisabled(true);
+                button.up('toolbar').down('button[action=discard]')
+                    .setDisabled(true);
+                formPanel.getForm().loadRecord(formPanel.getForm().getRecord());
+                var json = response.request.scope.reader.jsonData;
+                if (json) {
+                    formPanel.setMessages(json.errors, json.warnings);
+                }
+            }
+        });
+        console.log('save');
+    },
+
+    discard: function(button) {
+        var formPanel = button.up('form');
+        formPanel.getForm().loadRecord(formPanel.getForm().getRecord());
+    },
+
+    dirtyForm: function(form, dirty) {
+        if (dirty) {
+            form.owner.down('button[action=save]').setDisabled(false);
+            form.owner.down('button[action=discard]').setDisabled(false);
+        }
+        else {
+            form.owner.down('button[action=save]').setDisabled(true);
+            form.owner.down('button[action=discard]').setDisabled(true);
+        }
+    },
+
+    updateDetails: function(combobox, record) {
+        console.log(record);
+        var win = combobox.up('window');
+        var details = win.down('locationform');
+        var id = record[0].get('id');
+        if (details) {
+            Ext.ClassManager.get('Lada.model.Location').load(id, {
+                failure: function(record, action) {
+                    // TODO
+                },
+                success: function(record, response) {
+                    win.down('locationform').setRecord(record);
+                },
+                scope: this
+            });
+        }
+    }
+});
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/view/form/Ort.js	Thu Mar 12 15:51:24 2015 +0100
@@ -0,0 +1,96 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+
+/*
+ * Formular to edit a Probe
+ */
+Ext.define('Lada.view.form.Ort', {
+    extend: 'Ext.form.Panel',
+    alias: 'widget.ortform',
+
+    requires: [
+        'Lada.view.widget.Location'
+    ],
+
+    model: 'Lada.model.Ort',
+    minWidth: 300,
+    margin: 5,
+    border: 0,
+
+    recordId: null,
+
+    trackResetOnLoad: true,
+
+    initComponent: function() {
+        this.items = [{
+            xtype: 'fieldset',
+            title: 'Ort',
+            items: [{
+                border: 0,
+                margin: '0, 0, 10, 0',
+                dockedItems: [{
+                    xtype: 'toolbar',
+                    dock: 'bottom',
+                    border: '0, 1, 1, 1',
+                    style: {
+                        borderBottom: '1px solid #b5b8c8 !important',
+                        borderLeft: '1px solid #b5b8c8 !important',
+                        borderRight: '1px solid #b5b8c8 !important'
+                    },
+                    items: ['->', {
+                        text: 'Speichern',
+                        qtip: 'Daten speichern',
+                        icon: 'resources/img/dialog-ok-apply.png',
+                        action: 'save',
+                        disabled: true
+                    }, {
+                        text: 'Verwerfen',
+                        qtip: 'Ă„nderungen verwerfen',
+                        icon: 'resources/img/dialog-cancel.png',
+                        action: 'discard',
+                        disabled: true
+                    }]
+                }],
+                items: [{
+                    xtype: 'location',
+                    name: 'ort',
+                    fieldLabel: 'Ort',
+                    labelWidth: 80,
+                    width: 280
+                }, {
+                    xtype: 'tfield',
+                    name: 'ortsTyp',
+                    fieldLabel: 'Typ',
+                    labelWidth: 80,
+                    width: 280,
+                    maxLength: 1
+                }, {
+                    xtype: 'textarea',
+                    name: 'ortszusatztext',
+                    fieldLabel: 'Ortszusatz',
+                    width: 280,
+                    labelWidth: 80
+                }]
+            }]
+        }];
+        this.callParent(arguments);
+    },
+
+    setRecord: function(record) {
+        this.getForm().loadRecord(record);
+    },
+
+    setMessages: function(errors, warnings) {
+    },
+
+    clearMessages: function() {
+    },
+
+    setReadOnly: function(value) {
+    }
+});

http://lada.wald.intevation.org