Code

Updated item config management
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 30 Sep 2010 08:19:22 +0000 (08:19 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 30 Sep 2010 08:19:22 +0000 (08:19 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19862 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/goto/admin/systems/goto/Config/AddItemDialog.tpl [new file with mode: 0644]
gosa-plugins/goto/admin/systems/goto/Config/DeviceConfig-list.xml
gosa-plugins/goto/admin/systems/goto/Config/class_AddItemDialog.inc [new file with mode: 0644]
gosa-plugins/goto/admin/systems/goto/Config/class_DeviceConfig.inc

diff --git a/gosa-plugins/goto/admin/systems/goto/Config/AddItemDialog.tpl b/gosa-plugins/goto/admin/systems/goto/Config/AddItemDialog.tpl
new file mode 100644 (file)
index 0000000..2d9823c
--- /dev/null
@@ -0,0 +1,21 @@
+
+<h3>{t}Add item{/t}</h3>
+
+{t}Please specify a name for the item to add, this name has to be uniq within the item configuration.{/t}
+<br>
+
+<hr>
+
+<p>
+ <b>{$itemCfg.name}</b>&nbsp;-&nbsp; {$itemCfg.description}
+</p>
+
+{t}Name{/t}:&nbsp;<input type='text' name='itemName' value="{$itemName}">
+
+<hr>
+
+<div class='plugin-actions'>
+    <button name='saveItemAdd'>{msgPool type=okButton}</button>
+    <button name='cancelItemAdd'>{msgPool type=cancelButton}</button>
+</div>
+
index e5783ccae784378e0c503b7bec0f6a910261d80c..27e6ec474e00458a1be5c6390de3f2013f2af694 100644 (file)
@@ -21,7 +21,7 @@
   </definition>
 
   <table>
-    <layout>|20px;c||80px|170px;r|</layout>
+    <layout>|20px;c|||170px;r|</layout>
 
     <column>
       <value>%{filter:objectType(dn,objectClass)}</value>
 
   <actionmenu>
 
-    <action>
-     <type>sub</type>
-     <image>images/lists/element.png[new]</image>
-     <label>Create</label>
-    <action>
-      <name>remove</name>
-      <type>entry</type>
-      <image>images/lists/trash.png</image>
-      <label>Blaa</label>
-    </action>
-    </action>
+    %ITEMS%
 
     <action>
       <name>remove</name>
diff --git a/gosa-plugins/goto/admin/systems/goto/Config/class_AddItemDialog.inc b/gosa-plugins/goto/admin/systems/goto/Config/class_AddItemDialog.inc
new file mode 100644 (file)
index 0000000..461508f
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+
+class AddItemDialog
+{
+    private $itemCfg = NULL;
+    private $config = NULL;
+
+    private $itemName = "";
+    private $itemType = NULL;
+
+    function __construct(&$config, $itemType, $itemCfg)
+    {
+        $this->config = $config;
+        $this->itemCfg = $itemCfg;
+        $this->itemType = $itemType;
+    }
+
+    function execute()
+    {
+        $smarty = get_smarty();
+        $smarty->assign('itemCfg', set_post($this->itemCfg));
+        $smarty->assign('itemName', set_post($this->itemName));
+        return($smarty->fetch(get_template_path('goto/Config/AddItemDialog.tpl', TRUE)));
+    }
+
+    function getItemCfg()
+    {
+        return($this->itemCfg);
+    }
+
+    function getName()
+    {
+        return($this->itemName);
+    }
+
+    function getItemType()
+    {
+        return($this->itemType);
+    }
+
+    function save_object()
+    {
+        if(isset($_POST['itemName'])){
+            $this->itemName = get_post('itemName');
+        }
+    }
+
+    function check()
+    {
+        $message = array();
+        if(empty($this->itemName)){
+            $message[] = msgPool::required(_("Name"));
+        }else
+        if(!tests::is_uid($this->itemName)){
+            $message[] = msgPool::invalid(_("Name"));
+        }
+        return($message);
+    }
+}
+
+?>
index 87d317a895d73eaf062edb9c5adcc73266866edb..ad89ebb6739dc8d73eb49abd7513c87f4d52ceb8 100644 (file)
@@ -23,6 +23,8 @@ class DeviceConfig extends management
 
     private $baseToDN = array();
 
+    private $addableContainerItems = array();
+
     /*! \brief  Constructs the device configuration plugin 
      *  @param  Config  The GOsa configuration object.
      */
@@ -109,13 +111,6 @@ class DeviceConfig extends management
     }
 
 
-    function cancelItemEdit()
-    {
-        $this->closeDialogs();
-        $this->dialog = FALSE;
-    }
-    
-    
     function saveItemChanges()
     {
         // Save eventually changed values
@@ -125,7 +120,6 @@ class DeviceConfig extends management
             }
         }
         $this->closeDialogs();
-        $this->dialog = FALSE;
     }
 
 
@@ -203,6 +197,33 @@ class DeviceConfig extends management
 
         // Load service xml file and fill in placeholders
         $contents =file_get_contents(get_template_path("goto/Config/DeviceConfig-list.xml", true));
+
+
+        $items = "";
+        foreach($this->addableContainerItems as $item){
+            $desc = $this->itemConfig[$item]['description'];
+            $items .=
+                "<action>".
+                "    <name>add_{$item}</name>".
+                "    <type>entry</type>".
+                "    <image>images/lists/edit.png</image>".
+                "    <label>{$desc}</label>".
+                "</action>";
+        }
+
+        if(!empty($item)){
+            $items = 
+
+                "<action>".
+                " <type>sub</type>".
+                " <image>images/lists/element.png[new]</image>".
+                " <label>Create</label>".
+                " {$items}".
+                "</action>";
+        }
+
+        $contents = preg_replace("/%ITEMS%/", $items, $contents);
+
         $headpage = new listing($contents,TRUE);
         $headpage->setBase($this->base);
         $headpage->setFilter($filter);
@@ -215,7 +236,56 @@ class DeviceConfig extends management
         $this->registerAction("editEntry",  "editEntry");
 
         $this->registerAction("saveItemChanges", "saveItemChanges");
-        $this->registerAction("cancelItemEdit", "cancelItemEdit");
+        $this->registerAction("cancelItemEdit", "closeDialogs");
+        $this->registerAction("cancelItemAdd", "closeDialogs");
+        $this->registerAction("saveItemAdd", "saveItemAdd");
+        foreach($this->itemConfig as $name => $item){
+            $this->registerAction("add_{$name}", "newEntry");
+        }
+    }
+
+
+    /*! \brief  This method intiates the object creation.
+     *
+     *  @param  String  'action'  The name of the action which was the used as trigger.
+     *  @param  Array   'target'  A list of object dns, which should be affected by this method.
+     *  @param  Array   'all'     A combination of both 'action' and 'target'.
+     */
+    function newEntry($action="",$target=array(),$all=array(), 
+            $altTabClass ="", $altTabType = "", $altAclCategory="")
+    {
+        $toAdd = preg_replace("/^add_/", "",$action);
+        $itemToAdd = $this->itemConfig[$toAdd];
+
+        $this->dialogObject = new AddItemDialog($this->config,$toAdd,$itemToAdd);
+        $this->dialog = true;
+    }
+
+    
+    function saveItemAdd()
+    {
+        if(!$this->dialogObject instanceOf AddItemDialog) return;
+
+        $msgs = $this->dialogObject->save_object();
+        $msgs = $this->dialogObject->check();
+        if(count($msgs)){
+            msg_dialog::displayChecks($msgs);
+        }else{
+            $itemName = $this->dialogObject->getName();
+            $itemCfg = $this->dialogObject->getItemCfg();
+            $itemType = $this->dialogObject->getItemType();
+
+            $this->setCurrentItem($this->baseToDN[$this->base]);
+    
+            $this->addItem($itemType, $itemName);
+            $this->closeDialogs();
+
+#           $this->setCurrentItem($itemName);
+#           $this->dialogObject = $this->TemplateEngine;
+#           $this->skipFooter = TRUE;
+#           $this->dialog = TRUE;
+
+        }
     }
 
 
@@ -226,7 +296,7 @@ class DeviceConfig extends management
      *  @param  Array   values  The initial values for this object.
      *  @return 
      */
-    function addItem($type,$name, $values)
+    function addItem($type,$name, $values = array())
     {
         if(!isset($this->itemConfig[$type])){
             echo "Invalid type {$type}, skipping item!";
@@ -234,10 +304,9 @@ class DeviceConfig extends management
         }
 
         $allValuesSet = TRUE;
-        foreach($this->itemConfig[$type]['options'] as $oName => $option){
+        foreach($this->itemConfig[$type]['options'] as $oName => $oValue){
             if(!isset($values[$oName])){
-                echo "Missing value for option {$oName}! Skipping addItem({$type},{$name},array())!<br>";
-                return;
+                $values[$oName] = $oValue;
             }
         }
 
@@ -343,6 +412,7 @@ class DeviceConfig extends management
     {
         $this->base = $base;
         $item = $this->currentItemValues[$this->baseToDN[$base]];
+        $this->addableContainerItems = $this->itemConfig[$item['type']]['container'];
     }
 
 
@@ -376,7 +446,9 @@ class DeviceConfig extends management
     {
         $action = management::detectPostActions();
         if(isset($_POST['saveItemEdit'])) $action['action'] = "saveItemChanges";
+        if(isset($_POST['saveItemAdd'])) $action['action'] = "saveItemAdd";
         if(isset($_POST['cancelItemEdit'])) $action['action'] = "cancelItemEdit";
+        if(isset($_POST['cancelItemAdd'])) $action['action'] = "cancelItemAdd";
 
         if($action['action'] == 'remove'){
              echo "Löschen geht nicht!";
@@ -384,6 +456,13 @@ class DeviceConfig extends management
         }
         return($action);
     }
+
+    
+    function closeDialogs()
+    {
+        parent::closeDialogs();
+        $this->dialog = false;
+    }
    
  
     function check()