diff --git a/CodeCorner3.md b/CodeCorner3.md index 372b825..dc69d7c 100644 --- a/CodeCorner3.md +++ b/CodeCorner3.md @@ -1,4 +1,382 @@ > [Wiki](Home) ▸ [Developer Docs](Developer Docs) ▸ [Code Corner](Code Corner) ▸ **day three** ▸ [a day in between](CodeCorner3a) *** -some stuff \ No newline at end of file +on day three we went out of base camp eGroupware and stepped into the high fields of ((eTemplate))s.
+  +

motivation

+ + +  + +

how to Setup our application the eGroupware way

+There is a [http://egroupware.org/egroupware/etemplate/doc/etemplate.html HowTo] for ((eTemplate))s as well and a [http://egroupware.org/egroupware/etemplate/doc/reference.html reference] too.
+The [http://egroupware.org/egroupware/etemplate/doc/etemplate.html HowTo] was helpful to get my first moves with ((eTemplate)) going, but we agreed to rewrite that part at least partially.
+
+Lets consider we want to rebuild our old flagship test. Remember the folderstructure?! + +
  +
+test                                    that has to be identical to our app-name
+        + setup                         files necessary for the setup Programm, give the webserver write-permission to that dir (on a development box only!)
+        + inc                           class-files
+        + templates                     templates, still needed to store the images and get around a lot of complains from the api
+                + default
+                        + images        here goes our images / icons
+
+ +

+The optional file setup.inc.php in folder $app/setup?
+$app/setup/setup.inc.php should contain the information to setup your application. + +
  +
+<?php
+        $setup_info['test']['name']      = 'test';
+        $setup_info['test']['title']     = 'Test';
+        $setup_info['test']['version']   = '0.9.001';  //anything you like, as long as it is fitting the schema of a version number
+        $setup_info['test']['app_order'] = 100;        // at the end
+        // $setup_info['test']['tables']    = array('egw_test'); // if there are any
+        $setup_info['test']['enable']    = 1;
+
+        /* Dependencies for this app to work */
+        // if you define dependencies, you MUST meet them to get that baby on the road
+        $setup_info['test']['depends'][] = array(
+                 'appname' => 'phpgwapi',
+                 'versions' => Array('1.8','1.9'),
+         );
+        $setup_info['test']['depends'][] = array(   // this is only necessary as long the etemplate-class is not in the api
+                 'appname' => 'etemplate',
+                 'versions' => Array('1.6','1.8','1.9'),
+        );
+
+
+ +

+Since we had our original application registered manually, we should unregister our baby, to avoid version-number conflicts that may occur, since the manually registered application had no ((VersionNumbers|version number)) at all.
+So + +It is still there nothing changed so far exept the way we handle the setup.
+With the setup.inc.php we tell eGroupware how to handle our application, apply VersionNumbers and all the other fancy stuff we might need later on.
+  +

creating an eTemplate for the dialog

+Now we need a nice edit dialog and use the eTemplate editor to set it up.
+Assume that we wanted to name our first eTemplate index.
+  +
+
+
+
Step 1
+
start the etemplate app and type 'test.index' in the name field. Click on save in order to create the template as a new (almost empty) one.
+
+
+
+  + +
+
+
+
Step 2
+
an (almost empty) empty template is displayed. An eTemplate can be thought off as a “grid”. The first cell may be a bit tricky to find, but will be highlighted when moving the mouse over it. On my computer this cell appears in pink as illustrated below. If you do not see anything, try selecting everything via Strg-A. You should see a small rectangle right below the horizontal rule below the button CSS-Style:
+
+ +
+
[vfs:/home/Manual/etemplate0.png]
+
+
+
+  + +
+
+
+
Step 3
+
doubleclick the small rectangle right below the horizontal rule below the button CSS-Style. You should see something similar to this:
+
+ +
+
[vfs:/home/Manual/etemplate1.png]
+
+
+
+  + +
+
+
+
Step 4
+
as type choose Text, as label name, as name name, add a blurText of your choice and maybe a help. You may set the dimensions of the textfield by setting the options to 20,40 (approximately 20 character visible, 40 character in available width):
+
+ +
+
[vfs:/home/Manual/etemplate2.png]
+
Save your work.
+
+
+
+  + +
+
+
+
Step 5
+
now we need a button to send our data that we collect to us. To accomplish this, we have to add a column to our grid.
+
+ +
+
+
    +
  • Doubleclick on the label of our newly created name-text-field.
  • +
  • in the upper area of the properties window is a bar with three select boxes. Within the third one select insert a column behind.
  • +
  • Doubleclick on the label of our name-text-field.
  • +
  • in the third line of the properties window, klick on the tiny right-arrow behind the word grid.
  • +
  • choose Submitbutton, as label submit, as name submit
  • +
  • Save
  • +
+
+
+
+
+ +
+
+
+
Step 6
+
Create a widget before the grid
+
+ +
+
+
    +
  • Doubleclick on the label of our name-text-field.
  • +
  • Click on the word grid
  • +
  • in the upper area of the properties window is a bar with two select boxes. Within the second one select insert a widget before.
  • +
  • select grid as type
  • +
  • Save
  • +
  • doubleclick the small rectangle right below the horizontal rule below the button CSS-Style (that is the newly created grid, first cell).
  • +
  • select text as type, Hello as label and who as name.
  • +
  • disable the cell within the grid-row attributes, by typing !@who in the disabled property
  • +
  • check the checkbox readonly to make it an read-only textfield. This has two effects: +
      +
    • for one thing the value of @who is not editable
    • +
    • the borders around the text-field vanish.
    • +
    +
  • +
  • Save
  • +
+
+
+
+
+ +
+
+
+
Step 7
+
Now our first eTemplate is designed.
+
+ +
+
+
    +
  • we have a input-field to enter text
  • +
  • we have a submit button to send our form somewhere (by default back to our very page).
  • +
  • we have a container to hold our response
  • +
+
+
+
+
+
+ETemplate handles the complete form stuff for you. Data validation, parsing of the $_POST[...]
+security issues, callbacks (e.g. for required field values, etc. +
+
+
+
[vfs:/home/Manual/etemplate3.png]
+
+
+
+Doing all that, all you have to do, is handling the data.
+The data are transported within the $content[...] array. Each name you assign within a eTemplate will respond to named entrys in the $content[...] array. Our name will be accessible via $content['name'] and "who" the field which was intended to hold and display the value of the submitted name via $content['who'].
+While you control the content of the $content[...] array, you control the behavior of your eTemplate.
+  +
+
+
+
Step 8
+
In order to get your newly created eTemplate test.index going, you must call it from within your application. I realized that, from within a function.
+
+
+
+This function is added to the class.test_ui.inc.php file. + +
  +
+function index($content=null)
+{
+    $debug=false;
+    if (is_array($content)){
+        $debug=true;
+        // after submit
+        $content['message']=print_r($content,true);
+        $content['datetime']=time();
+        $content['who']=$content['name'];
+        $content['name']='';
+        $content['ergebnis']=$content['wert1']*$content['wert2'];
+    } else {
+        // first call
+        /*
+        $content=array(
+            'who'=>', please type a name ...',
+        );
+        */
+    }
+    $tpl=new etemplate('test.index');
+    $tpl->set_cell_attribute('debuginfos','disabled',!$debug); 
+    $tpl->exec('test.test_ui.index',$content);
+    // the debug info will be displayed at the very end of the page
+    //_debug_array($content);
+}
+
+ +
  +
+
+
+
Step 9
+
Since you want to be able to call that function from the eGroupware as function call or link or redirekt-link, you have to add the function name to the public_functions array.
+
+
+
+ +
  +
+var $public_functions = array(
+    'testinterface' => True,
+    'index'    => True,
+    );
+
+ +
  +
+
+
+
Step 10
+
You have to add a constructor to your test_ui class:
+
+
+
+ +
  +
+ // construktor
+ function test_ui()
+    {
+      $GLOBALS['egw_info']['flags']['app_header']='test-Application';
+      
+      $this->tmpl =& CreateObject('etemplate.etemplate', 'test.index');
+      $this->bo   =& CreateObject('test.botest');
+      $this->html =& $GLOBALS['egw']->html;
+                
+      if(!@is_object($GLOBALS['egw']->js))
+      {
+           $GLOBALS['egw']->js =& CreateObject('phpgwapi.javascript');
+      }
+
+    }
+
+ +
  +
+
+
+
Step 11
+
If we add echo "<a href='".$GLOBALS['egw']->link('/index.php',array('menuaction' => 'test.test_ui.index'))."'> Call the eTemplate version </a> <br>"; to our old function testinterface just before the creation of the footer, we have a link to start up our new eTemplate.
+
+ +
+
Sure thing, you can call your eTemplate - which is wrapped in a function from your test/index.php:
+
header('Location: ../index.php?menuaction=test.test_ui.index');
+
+
+
+  + +
+
+
+
Step 12
+
If you wanted to have some fancy title for your Application, different from your application name. Set the app_header (as I did) within the constructor:
+
+ +
+
$GLOBALS['egw_info']['flags']['app_header']='My fancy application title';
+
+
+
+
+Now we have our application converted to the eTemplate way of eGroupware. As you can see in the code of the function, I added a few fields to the eTemplate. You can see that I handle data of the $content[...] array and assign them to fields that I have not talked about.
+
+The index function is called from our index.php file, from a link out of our old application or as callback for this form / dialog. In that case $content is an array with the content the user put into the fields of the dialog.
+  +

Let first have a look what happend if we called the first time (or what we do to show the dialog again with the changed data)

+  + + +  + +

Now let's have a look what happens if the user submits the form and our callback is called.

+  + + +  + +

What do we have

+Using the eTemplate we have now splitted the display of the userinterface from its processing code.
+The structured developing techniques of the CodingRules - the 3-tier-approach (UI > BO > SO !!!) - enables us to split the layers of our application, and handle certain stuff at the right level (e.g. time -> user/system) and just there.