Mercurial > lada > lada-client
changeset 111:6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
author | Torsten Irländer <torsten.irlaender@intevation.de> |
---|---|
date | Wed, 19 Jun 2013 14:11:35 +0200 |
parents | c4f97a5a9939 |
children | 882566d0b8f3 |
files | app/controller/Kommentare.js app/view/kommentare/Create.js app/view/kommentare/CreateForm.js app/view/kommentare/Edit.js |
diffstat | 4 files changed, 99 insertions(+), 83 deletions(-) [+] |
line wrap: on
line diff
--- a/app/controller/Kommentare.js Wed Jun 19 14:10:54 2013 +0200 +++ b/app/controller/Kommentare.js Wed Jun 19 14:11:35 2013 +0200 @@ -2,7 +2,6 @@ extend: 'Ext.app.Controller', views: [ 'kommentare.List', - 'kommentare.Edit', 'kommentare.Create' ], stores: [ @@ -17,7 +16,6 @@ // CSS like selector to select element in the viewport. See // ComponentQuery documentation for more details. 'kommentarelist': { - // Map Doubleclick on rows of the probenlist. itemdblclick: this.editKommentar }, 'kommentarelist toolbar button[action=add]': { @@ -26,20 +24,24 @@ 'kommentarelist toolbar button[action=delete]': { click: this.deleteKommentar }, - 'kommentaredit button[action=save]': { - click: this.saveKommentar + 'kommentarecreate form': { + savesuccess: this.createSuccess, + savefailure: this.createFailure + }, + 'kommentareedit form': { + savesuccess: this.editSuccess, + savefailure: this.editFailure } }); }, addKommentar: function(button) { console.log('Adding new Kommentar'); - var view = Ext.create('Lada.view.kommentare.Create'); - var form = view.down('form'); - // Set probeId - var probenform = button.up('form'); - var probe = probenform.getRecord(); - var probeId = probe.get('probeId'); - form.model.set('probeId', probeId); + var view = Ext.widget('kommentarecreate'); + }, + editKommentar: function(grid, record) { + console.log('Editing Kommentar'); + var view = Ext.widget('kommentarecreate', {model: record}); + console.log("Loaded Kommentar with ID " + record.getId()); //outputs ID }, deleteKommentar: function(button) { // Get selected item in grid @@ -56,22 +58,34 @@ } }); }, - editKommentar: function(grid, record) { - // Create new window to edit the seletced record. - var view = Ext.widget('kommentaredit'); - var form = view.down('form'); - form.loadRecord(record); + createSuccess: function(form, record, operation) { + // Reload store + var store = this.getKommentareStore(); + store.reload(); + var win = form.up('window'); + win.close(); }, - saveKommentar: function(button) { - var win = button.up('window'); - var form = win.down('form'); - var record = form.getRecord(); - var values = form.getValues(); + createFailure: function(form, record, operation) { + Ext.MessageBox.show({ + title: 'Fehler beim Speichern', + msg: form.message, + icon: Ext.MessageBox.ERROR, + buttons: Ext.Msg.OK + }); + }, + editSuccess: function(form, record, operation) { + // Reload store var store = this.getKommentareStore(); - record.set(values); - store.add(record); - store.sync(); - console.log('Saving Kommentar'); + store.reload(); + var win = form.up('window'); win.close(); + }, + editFailure: function(form, record, operation) { + Ext.MessageBox.show({ + title: 'Fehler beim Speichern', + msg: form.message, + icon: Ext.MessageBox.ERROR, + buttons: Ext.Msg.OK + }); } });
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/view/kommentare/Create.js Wed Jun 19 14:11:35 2013 +0200 @@ -0,0 +1,29 @@ +Ext.define('Lada.view.kommentare.Create', { + extend: 'Ext.window.Window', + alias: 'widget.kommentarecreate', + + title: 'Maske für Kommentare', + // Make size of the dialog dependend of the available space. + // TODO: Handle resizing the browser window. + width: Ext.getBody().getViewSize().width - 30, + height: Ext.getBody().getViewSize().height - 30, + autoShow: true, + autoScroll: true, + modal: true, + + requires: [ + 'Lada.view.kommentare.CreateForm' + ], + initComponent: function() { + var form = Ext.create('Lada.view.kommentare.CreateForm'); + this.items = [form]; + this.buttons = [ + { + text: 'Speichern', + handler: form.commit, + scope: form + } + ]; + this.callParent(); + } +});
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/view/kommentare/CreateForm.js Wed Jun 19 14:11:35 2013 +0200 @@ -0,0 +1,31 @@ +Ext.define('Lada.view.kommentare.CreateForm', { + extend: 'Lada.view.widgets.LadaForm', + model: 'Lada.model.Kommentar', + initComponent: function() { + this.items = [ + { + xtype: 'textfield', + name: 'erzeuger', + fieldLabel: 'Erzeuger' + }, + { + xtype: 'datefield', + name: 'kdatum', + fieldLabel: 'Datum' + }, + { + xtype: 'textareafield', + name: 'ktext', + fieldLabel: 'Text' + } + ]; + //this.buttons = [ + // { + // text: 'Speichern', + // handler: this.commit, + // scope: this + // } + //]; + this.callParent(); + } +});
--- a/app/view/kommentare/Edit.js Wed Jun 19 14:10:54 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -Ext.define('Lada.view.kommentare.Edit', { - extend: 'Ext.window.Window', - alias: 'widget.kommentaredit', - - title: 'Maske für Kommentare', - // Make size of the dialog dependend of the available space. - // TODO: Handle resizing the browser window. - width: Ext.getBody().getViewSize().width - 30, - maxHeight: Ext.getBody().getViewSize().height - 30, - autoShow: true, - autoScroll: true, - modal: true, - - requires: [ - ], - - initComponent: function() { - this.items = [ - { - //Define the form - xtype: 'form', - bodyPadding: '10 10', - border: 0, - layout: 'fit', - items: [ - { - xtype: 'textfield', - name: 'erzeuger', - fieldLabel: 'Erzeuger' - }, - { - xtype: 'datefield', - name: 'kdatum', - fieldLabel: 'Datum' - }, - { - xtype: 'textareafield', - name: 'ktext', - fieldLabel: 'Text' - } - ] - } - ]; - this.buttons = [ - { - text: 'Speichern', - action: 'save' - }, - { - text: 'Verwerfen', - scope: this, - handler: this.close - } - ]; - this.callParent(arguments); - } -}); -