added activate plant functionality, improved datamapping, removed test button
[L-seed.git] / web / js / communication.js
index a6923b7..784289f 100644 (file)
@@ -22,6 +22,8 @@ Lseed.MessageCommands = {
 };
 
 Lseed.Communication = function() {
+       
+       this.Username = '';
 
        // ----- Framework -----
        
@@ -192,6 +194,8 @@ Lseed.Communication = function() {
                        var pw = cmpPw.getValue();
                        pw = MD5(pw);
                        Ext.MessageBox.wait("Authentifiziere.", "Wird geladen...");
+                               
+                       this.Username = user;
                        
                        this.sendMessage(Lseed.MessageCommands.RPC, { func: 'Auth', user: user, pw: pw });
                        this.hideLoginDialog();
@@ -299,6 +303,8 @@ Lseed.Communication = function() {
                        if (pw == pwRepeat) {
                                pw = MD5(pw);
                                Ext.MessageBox.wait("Registriere.", "Wird geladen...");
+                               
+                               this.Username = user;
 
                                this.sendMessage(Lseed.MessageCommands.RPC, { func: 'Register', user: user, pw: pw });
                                this.hideRegisterDialog();
@@ -463,6 +469,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("ActivatePlant", editor.ActivateCallback.createDelegate(editor));
                
                this.sendMessage(Lseed.MessageCommands.RPC, {func: 'IsLoggedIn'});
        };
@@ -492,6 +499,24 @@ Lseed.Editor = function() {
                }
        };
        
+       this.Activate = function(plant) {
+               console.log(arguments);
+               communication.sendMessage(Lseed.MessageCommands.RPC, { 
+                       func: 'ActivatePlant'
+                       ,plant: plant.data.Name
+                       ,user: communication.Username
+               });
+       };
+       
+       this.ActivateCallback = function(data) {
+               if (data.success) {
+                       communication.showMessage("Erfolgreich aktiviert.", "info");
+                       communication.GetPlantList();
+               } else {
+                       communication.showMessage(data.msg, "error");
+               }
+       };
+       
        this.Test = function(plant, callback) {
                communication.showMessage("Diese Funktion ist leider momentan nicht verf├╝gbar", "error");
        };
@@ -501,25 +526,39 @@ Lseed.Editor = function() {
        
        this.CheckSyntaxCallback = null;
        this.CheckSyntax = function(plant, callback) {
-               this.CheckSyntaxCallback = callback;
+               if (typeof callback != 'undefined' && callback != null) {
+                       this.CheckSyntaxCallback = callback;
+               }
                
                communication.sendMessage(Lseed.MessageCommands.RPC, { 
                        func: 'ValidatePlant'
+                       ,plant: plant.data.Name
                        ,code: plant.data.Code
                });
        };
        
-       this.CheckSyntaxCallback = function(data) {
-               if (!data.valid) {
-                       if (this.CheckSyntaxCallback != null) {
-                               this.CheckSyntaxCallback(data);
-                       } else {
-                               console.error("Lseed.Editor.CheckSyntaxCallback: no Callback given.");
-                       }
+       this.HandleSyntaxCheckAnswerForEditor = function(data) {
+               var pdEditor = Ext.getCmp("plantdefinitioneditor");
+               if (pdEditor) {
+                       communication.stopWaitingForPage();
+                       Ext.MessageBox.show({
+                               title:'Fehler'
+                               ,msg: data.msg
+                               ,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
+                       });
                } else {
-                       console.info("Syntax is Valid.");
+                       console.error("Lseed.Editor.CheckSyntaxCallback_Callback: 'plantdefinitioneditor' Could not be found.");
                }
-       };
+       }
+       
+       this.CheckSyntaxCallback = function() {};
        
        this.Delete = function(plant) {
                communication.sendMessage(Lseed.MessageCommands.RPC, { 
@@ -561,5 +600,8 @@ Lseed.Plant = Ext.data.Record.create([{
 }, {
        name: 'Code'
        ,type: 'string'
+}, {
+       name: 'IsActive'
+       ,type: 'boolean'
 }]);