added editing, fix validation
authorSven Hecht <sven@sven-laptop.(none)>
Thu, 25 Jun 2009 20:14:33 +0000 (22:14 +0200)
committerSven Hecht <sven@sven-laptop.(none)>
Thu, 25 Jun 2009 20:14:33 +0000 (22:14 +0200)
web/img/icons/edit.png [new file with mode: 0644]
web/js/communication.js
web/php/page/editplant.pg [new file with mode: 0755]
web/php/page/myplants.pg

diff --git a/web/img/icons/edit.png b/web/img/icons/edit.png
new file mode 100644 (file)
index 0000000..fb2efb8
Binary files /dev/null and b/web/img/icons/edit.png differ
index 062fc11..79451ff 100644 (file)
@@ -105,6 +105,9 @@ Lseed.Communication = function() {
                                break;
                        default:
                                this.loadTab(content, contentname);
+                               if (contentname == "editplant") {
+                                       editor.EditCallback();
+                               }
                                break;
                }
        };
@@ -487,7 +490,7 @@ Lseed.Communication = function() {
                
                this.AddCallback("SavePlant", editor.SaveCallback.createDelegate(editor));
                this.AddCallback("DeletePlant", editor.DeleteCallback.createDelegate(editor));
-               this.AddCallback("ValidatePlant", editor.CheckSyntaxCallback.createDelegate(editor));
+               this.AddCallback("ValidatePlant", editor.HandleSyntaxCheckAnswerForEditor.createDelegate(editor));
                this.AddCallback("ActivatePlant", editor.ActivateCallback.createDelegate(editor));
                
                this.sendMessage(Lseed.MessageCommands.RPC, {func: 'IsLoggedIn'});
@@ -536,6 +539,21 @@ Lseed.Editor = function() {
                }
        };
        
+       this.Edit = function(plant) {
+               communication.sendMessage(Lseed.MessageCommands.ContentRequest, {content: 'editplant'});
+               this.LastEditPlant = plant;
+       };
+       this.EditCallback = function() {
+               var cmp = Ext.getCmp("editplantdefinitionnamefield");
+               if (cmp) {
+                       cmp.setValue(this.LastEditPlant.data.Name);
+               }
+               var cmp = Ext.getCmp("editplantdefinitioneditor");
+               if (cmp) {
+                       cmp.setValue(this.LastEditPlant.data.Code);
+               }
+       };
+       
        this.Test = function(plant, callback) {
                communication.showMessage("Diese Funktion ist leider momentan nicht verfügbar", "error");
        };
@@ -543,7 +561,6 @@ Lseed.Editor = function() {
        this.TestCallback = function() {
        };
        
-       this.CheckSyntaxCallback = null;
        this.CheckSyntax = function(plant, callback) {
                if (typeof callback != 'undefined' && callback != null) {
                        this.CheckSyntaxCallback = callback;
@@ -557,27 +574,37 @@ Lseed.Editor = function() {
        };
        
        this.HandleSyntaxCheckAnswerForEditor = function(data) {
-               var pdEditor = Ext.getCmp("plantdefinitioneditor");
-               if (pdEditor) {
-                       communication.stopWaitingForPage();
+               if (data.success || data.valid) {
                        Ext.MessageBox.show({
-                               title:'Fehler'
-                               ,msg: data.msg
+                               title:'Valide'
+                               ,msg: "Alles Super."
                                ,buttons: Ext.Msg.OK
-                               ,fn: function() {
-                                       var index = editor.GetStartFromField(pdEditor, data.line-1, data.column);
-                                       if (index != -1) {
-                                               pdEditor.selectText(index-1, index);
-                                       }
-                               }
-                               ,icon: Ext.MessageBox.ERROR
+                               ,icon: Ext.MessageBox.Info
                        });
                } else {
-                       console.error("Lseed.Editor.CheckSyntaxCallback_Callback: 'plantdefinitioneditor' Could not be found.");
+                       var pdEditor = Ext.getCmp("plantdefinitioneditor");
+                       if (pdEditor) {
+                               communication.stopWaitingForPage();
+                               Ext.MessageBox.show({
+                                       title:'Fehler'
+                                       ,msg: data.msg
+                                       ,buttons: Ext.Msg.OK
+                                       ,fn: function() {
+                                               if (typeof data.line != "undefined") {
+                                                       var index = editor.GetStartFromField(pdEditor, data.line-1, data.column);
+                                                       if (index != -1) {
+                                                               pdEditor.selectText(index-1, index);
+                                                       }
+                                               }
+                                       }
+                                       ,icon: Ext.MessageBox.ERROR
+                               });
+                       } else {
+                               console.error("Lseed.Editor.CheckSyntaxCallback_Callback: 'plantdefinitioneditor' Could not be found.");
+                               alert("Es trat ein Fehler auf...sowas.");
+                       }
                }
-       }
-       
-       this.CheckSyntaxCallback = function() {};
+       };
        
        this.Delete = function(plant) {
                communication.sendMessage(Lseed.MessageCommands.RPC, { 
diff --git a/web/php/page/editplant.pg b/web/php/page/editplant.pg
new file mode 100755 (executable)
index 0000000..f207407
--- /dev/null
@@ -0,0 +1,70 @@
+{
+       id: 'ContentPanel_createplant'
+       ,closable: true
+       ,style: 'padding: 5px;'
+       ,title: 'Pflanze editieren'
+       ,layout: 'form'
+       ,labelWidth: 100
+       ,baseCls: 'x-plain'
+       ,bodyStyle:'padding:5px;'
+       ,defaults: {
+               bodyStyle:'padding:5px;'
+       }
+       ,tbar: [{
+               text: "Save"
+               ,icon: 'img/icons/disk.png'
+               ,cls: 'x-btn-text-icon'
+               ,handler: function() {
+                       var namefield = Ext.getCmp("editplantdefinitionnamefield");
+                       var planteditor = Ext.getCmp("editplantdefinitioneditor");
+                       if (namefield.isValid()) {
+                       
+                               var plant = new Lseed.Plant({
+                                       Name: namefield.getValue() 
+                                       ,Code: planteditor.getValue()
+                               });
+                               editor.Save(plant);
+                       } else {
+                               communication.showMessage("Ihre Pflanze benötigt einen Namen.", "error");
+                       }
+               }
+       },{
+               text: "CheckSyntax"
+               ,icon: 'img/icons/accept.png'
+               ,cls: 'x-btn-text-icon'
+               ,handler: function() { 
+                       communication.waitForPage();
+                       var pdEditor = Ext.getCmp("editplantdefinitioneditor");
+                       var pnEditor = Ext.getCmp("editplantdefinitionnamefield");
+                       if (pdEditor && pnEditor) {
+                               var name = pnEditor.getValue();
+                               var code = pdEditor.getValue();
+                               editor.CheckSyntax({data:{Code:code, Name:name}}, editor.HandleSyntaxCheckAnswerForEditor); 
+                       } else {
+                               console.error("Lseed.Editor.CheckSyntaxCallback_Callback: 'plantdefinitioneditor' Could not be found.");
+                       }
+               }.createDelegate(editor)
+       }]
+       ,items: [{
+               id: "editplantdefinitionnamefield"
+               ,xtype: 'textfield'
+               ,name: 'name'
+               ,allowBlank: false
+               ,fieldLabel: 'Name der Pflanze'
+               ,anchor:'100%'
+               ,disabled: true
+               ,enableKeyEvents: true
+               ,listeners: {
+               }
+       },{
+               id: "editplantdefinitioneditor"
+               ,xtype: 'textarea'
+               ,name: 'code'
+               ,fieldLabel: 'Pflanzendefinition'
+               ,anchor:'100% -50'
+               ,enableKeyEvents: true
+               ,listeners: {
+               }
+               ,value: ''
+       }]
+}
index f74743b..44e654a 100644 (file)
                                    editor.Activate(selected[0]);
                                }
                        }
+               },{
+                       id: 'plantlistEditPlant'
+                       ,text: 'Edit'
+                       ,icon: 'img/icons/edit.png'
+                       ,cls: 'x-btn-text-icon'
+                       ,disabled: true
+                       ,handler: function(){
+                               Ext.getCmp("plantlistgridEditor").stopEditing();
+                               var grid = Ext.getCmp("plantlistgrid");
+                               var selected = grid.getSelectionModel().getSelections();
+                               if(selected.length > 0) {
+                                   editor.Edit(selected[0]);
+                               }
+                       }
                },{
                        id: 'plantlistRefresh'
                        ,text: 'Refresh'
                                        Ext.getCmp("plantlistDeletePlant").enable();
                                        Ext.getCmp("plantlistCheckPlantSyntax").enable();
                                        Ext.getCmp("plantlistActivatePlant").enable();
+                                       Ext.getCmp("plantlistEditPlant").enable();
                                }
                                ,rowdeselect: function() {
                                        Ext.getCmp("plantlistDeletePlant").disable();
                                        Ext.getCmp("plantlistCheckPlantSyntax").disable();
                                        Ext.getCmp("plantlistActivatePlant").disable();
-                                       Ext.getCmp("plantlistActivatePlant").disable();
+                                       Ext.getCmp("plantlistEditPlant").disable();
                                }
                        }
                })