Preview-Functinality
authorJoachim Breitner <mail@joachim-breitner.de>
Fri, 26 Jun 2009 11:12:57 +0000 (13:12 +0200)
committerJoachim Breitner <mail@joachim-breitner.de>
Fri, 26 Jun 2009 11:12:57 +0000 (13:12 +0200)
The passing of the plant.ID to the new tab is done quite hackish.

web/js/communication.js
web/php/Communication.php
web/php/PlantImages.php [new file with mode: 0644]
web/php/Response.php
web/php/page/myplants.pg
web/php/page/nav.pg
web/php/page/previewplant.pg [new file with mode: 0644]
web/php/page/testplant.pg [deleted file]

index 2b29ff7..1540954 100644 (file)
@@ -67,7 +67,7 @@ Lseed.Communication = function() {
                                case 'Content':
                                        this.stopWaitingForPage();
                                        
-                                       this.showContent(obj.content, obj.contentname);
+                                       this.showContent(obj);
                                        break;
                        }
                } catch (e) {
@@ -97,15 +97,20 @@ Lseed.Communication = function() {
 
        // ----- Application -----
        
-       this.showContent = function (content, contentname) {
-               switch(contentname) {
+       this.showContent = function (contentmsg) {
+               switch(contentmsg.contentname) {
                        case "nav":
                        case "adminnav":
-                               this.loadNavigation(content);
+                               this.loadNavigation(contentmsg.content);
                                break;
                        default:
-                               this.loadTab(content, contentname);
-                               if (contentname == "editplant") {
+                               content = contentmsg.content;
+                               if (contentmsg.contentname == "previewplant") {
+
+                                       content.html = '<img src="php/PlantImages.php?plantid='+contentmsg.plantid+'"/>';
+                               }
+                               this.loadTab(content, contentmsg.contentname);
+                               if (contentmsg.contentname == "editplant") {
                                        editor.EditCallback();
                                }
                                break;
@@ -552,6 +557,12 @@ Lseed.Editor = function() {
                }
        };
        
+       this.Preview = function(plant) {
+               communication.sendMessage(Lseed.MessageCommands.ContentRequest, {content: 'previewplant', plantid: plant.data.ID} );
+       };
+       this.PreviewCallback = function() {
+       };
+       
        this.Edit = function(plant) {
                communication.sendMessage(Lseed.MessageCommands.ContentRequest, {content: 'editplant'});
                this.LastEditPlant = plant;
index 39c1976..c23ef46 100644 (file)
@@ -34,7 +34,7 @@
 
                        case "ContentRequest":
                                if ($controller->IsLoggedIn() != "false") {
-                                       $response = new ContentMessage($_POST["content"]);
+                                       $response = new ContentMessage($_POST["content"], $_POST["plantid"]);
                                } else {
                                        $func = "function() { this.showLoginDialog(); this.showMessage('Sie sind nicht eingeloggt bitte einloggen', 'error'); }";
                                        $response = new RemoteProcedureCall($func);
diff --git a/web/php/PlantImages.php b/web/php/PlantImages.php
new file mode 100644 (file)
index 0000000..0705106
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+       session_start();
+       if (get_magic_quotes_gpc()) { $_POST = array_map( 'stripslashes', $_POST ); }
+       
+       $_GLOBALS['WINDOWS'] = false;
+       
+       include("Plant.php");
+       include("User.php");
+       include("Season.php");
+       include("SeasonScore.php");
+       include("Controller.php");
+       include("Database.php");
+
+       function main()
+       {
+               $controller = new Controller();
+
+               $user = $controller->GetUser();
+               if ($user == null) {
+                       header("HTTP/1.0 404 Not Found");
+                       header("Content-type: text/plain; charset=utf-8");
+                       echo "User not found";
+                       return;
+               }
+
+               $plantid = $_GET[plantid];
+               if ($plantid == null) {
+                       header("HTTP/1.0 404 Not Found");
+                       header("Content-type: text/plain; charset=utf-8");
+                       echo "No Plant id given";
+                       return;
+               }
+
+               $plant = $user->GetPlantById($plantid);
+               if ($plant == null) {
+                       header("HTTP/1.0 404 Not Found");
+                       header("Content-type: text/plain; charset=utf-8");
+                       echo "No Plant found";
+                       return;
+               }
+
+               $descriptorspec = array(
+                  0 => array("pipe", "r"),
+                  1 => array("pipe","w"),
+                  2 => array("pipe","w"),
+               );
+
+               $cwd = realpath(".");
+
+               $process = proc_open("../cgi/renderAsPNG ".escapeshellarg($plant->Name), $descriptorspec, $pipes, $cwd, array());
+
+               if (is_resource($process)) {
+                       // $pipes sieht nun so aus:
+                       // 0 => Schreibhandle, das auf das Child STDIN verbunden ist
+                       // 1 => Lesehandle, das auf das Child STDOUT verbunden ist
+                       // Jedwede Fehlerausgaben werden an /tmp/error-output.txt angefĆ¼gt
+                       header("Content-type: image/png");
+
+                       fwrite($pipes[0], $plant->Code);
+                       fclose($pipes[0]);
+
+                       echo stream_get_contents($pipes[1]);
+                        fclose($pipes[1]);
+                        fclose($pipes[2]);
+
+                       $return_value = proc_close($process);
+               }
+       }
+
+       main();
+?>
index 18809c8..049c7e7 100644 (file)
                public $m_Type;
                public $m_ContentName;
                
-               public function __construct($name) {
+               public function __construct($name, $plantid) {
                        parent::__construct("Content");
                        $this->m_ContentName = $name;
+                       $this->m_PlantID = $plantid;
                }
                
                public function send() {
                        echo "{ cmd: '".$this->m_Command."', contentname: '".$this->m_ContentName."', content: ";
                        readfile( "page/".$this->m_ContentName.".pg" );
+                       if ($this->m_PlantID != null) {
+                               echo ", plantid: ".$this->m_PlantID;
+                       };
                        echo "}";
                }
        }
index 77d6f6c..a28e706 100644 (file)
                                    editor.Activate(selected[0]);
                                }
                        }
+               },{
+                       id: 'plantlistPreviewPlant'
+                       ,text: 'Preview'
+                       ,icon: 'img/icons/edit.png'
+                       ,cls: 'x-btn-text-icon'
+                       ,disabled: true
+                       ,handler: function(){
+                               var grid = Ext.getCmp("plantlistgrid");
+                               var selected = grid.getSelectionModel().getSelections();
+                               if(selected.length > 0) {
+                                   editor.Preview(selected[0]);
+                               }
+                       }
                },{
                        id: 'plantlistEditPlant'
                        ,text: 'Edit'
                                        Ext.getCmp("plantlistDeletePlant").enable();
                                        Ext.getCmp("plantlistActivatePlant").enable();
                                        Ext.getCmp("plantlistEditPlant").enable();
+                                       Ext.getCmp("plantlistPreviewPlant").enable();
                                }
                                ,rowdeselect: function() {
                                        Ext.getCmp("plantlistDeletePlant").disable();
                                        Ext.getCmp("plantlistActivatePlant").disable();
+                                       Ext.getCmp("plantlistPreviewPlant").disable();
                                        Ext.getCmp("plantlistEditPlant").disable();
                                }
                        }
index 408b176..cee6af6 100644 (file)
                id: 'myplants'
                ,text: "Meine Pflanzen"
                ,leaf: true
-       },{
-               id: 'testplant'
-               ,text: "Pflanze testen"
-               ,leaf: true
        },{
                id: 'season'
                ,text: "Aktuelle Saison"
diff --git a/web/php/page/previewplant.pg b/web/php/page/previewplant.pg
new file mode 100644 (file)
index 0000000..e9504d7
--- /dev/null
@@ -0,0 +1,6 @@
+{
+       id: 'ContentPanel_previewplant'
+       ,closable: true
+       ,style: 'padding: 5px;'
+       ,title: 'Pflanze anschauen'
+}
diff --git a/web/php/page/testplant.pg b/web/php/page/testplant.pg
deleted file mode 100644 (file)
index 09a0506..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-{
-       id: 'ContentPanel_testplant'
-       ,closable: true
-       ,style: 'padding: 5px;'
-       ,title: 'Pflanze testen'
-       ,html: 'TODO'
-}
\ No newline at end of file