Code

Updated widgets to allow disabling items
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 20 Apr 2011 15:32:03 +0000 (15:32 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 20 Apr 2011 15:32:03 +0000 (15:32 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20760 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/TemplateWidget_textEditor.tpl [new file with mode: 0644]
gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateEngine.inc
gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateWidget.inc
gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateWidget_checkbox.inc
gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateWidget_combobox.inc
gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateWidget_file.inc
gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateWidget_fixedList.inc
gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateWidget_list.inc
gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateWidget_string.inc
gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateWidget_textEditor.inc
gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateWidget_textarea.inc

diff --git a/gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/TemplateWidget_textEditor.tpl b/gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/TemplateWidget_textEditor.tpl
new file mode 100644 (file)
index 0000000..02c5738
--- /dev/null
@@ -0,0 +1,12 @@
+{if $write_protect}
+  {t}The text is write protected due to its encoding. Editing may break it!{/t}
+  <br>
+  <button type='submit' name='editAnyway' {if !$enabled} disabled {/if}>{t}Edit anyway{/t}</button>
+{/if}
+<textarea {if !$enabled} disabled {/if} {if $write_protect} disabled {/if} {if !$write_protect} name="{$postName}" {/if}
+    style="width:100%;height:300px;" id="{$postName}"
+    rows="20" cols="120">{$value}</textarea>
+<div>
+  <input type="file" name="ImportFile" {if !$enabled} disabled {/if}>&nbsp;
+  <button type='submit' name='ImportUpload' {if !$enabled} disabled {/if}>{t}Import text{/t}</button>
+</div>
index fd9617c609bcec2b2b29c84e6f72caaaaf84c4be..e81fe3eb24005a005e18c2319a6023696035610c 100644 (file)
@@ -56,7 +56,21 @@ class TemplateEngine
     {
         return($this->itemType);
     }
+   
     
+    function editItem($type, $values)
+    {
+        $this->is_new = FALSE;
+        $this->setValues($type, $values);
+    }
+
+    function createItem($type, $values)
+    {
+        $this->is_new = TRUE;
+        $this->setValues($type, $values);
+    }
 
     /*! \brief  Sets the current item type we want to render
      *          E.g.  'KickstartTemplate' and the corresponding values.
@@ -104,6 +118,12 @@ class TemplateEngine
                         $item['type'],
                         $item['display'],
                         $providedValues);
+               
+                // Check if we've to disable this item.
+                if(isset($item['disable']) && $item['disable'] || 
+                        isset($item['initiallyEditableOnly']) && $item['initiallyEditableOnly']){
+                    $this->widgets[$name]->setEnabled(FALSE);
+                }
             }
         }
     }
index 45f4fae0317ee86d6984c9513e5a5f084bc069a9..190d9c7ee937ea8c27388a73808a49206e024be1 100644 (file)
@@ -14,6 +14,7 @@ class TemplateWidget
     protected $display = "";
     protected $syntax = "";
     protected $values = "";
+    protected $enabled = TRUE;
 
     /*! \brief  Constructs the template widget and sets the default values.
      *  @param  Config  The GOsa configuration object.
@@ -40,6 +41,14 @@ class TemplateWidget
     }
 
 
+    /*! \brief  Enabled or disabled the widget.
+     */    
+    function setEnabled($bool = TRUE)
+    {
+        $this->enabled = $bool;
+    }
+
+
     /*! \brief  Returns the display-name for the current widget.
      *  @return  String     The display-name for the widget, this 
      *                       name will usually be rendered infront of input fields.
index cd6cb1b0ff644538bd1ce24e2c59b1b7dbaec0b2..43318395e27a439bba95fc32e6cb79835f9ebcde 100644 (file)
@@ -5,7 +5,8 @@ class TemplateWidget_checkbox extends TemplateWidget
     function render()
     {
         $str = "";
-        $str .= "<input type='checkbox' value='1' name='{$this->postName}' ";
+        $disabled = (!$this->enabled)? "disabled" : "";
+        $str .= "<input type='checkbox' value='1' name='{$this->postName}' {$disabled}";
             if($this->value) $str .= " checked ";
         $str .= ">";
         return($str);
index d0a306926f938b62cb50fca7e46d9d2bda034d86..e1b4ecdb41e174beb1f5802eb5610e6a6376b97f 100644 (file)
@@ -7,7 +7,8 @@ class TemplateWidget_combobox extends TemplateWidget
         $str = "";
 
         // Build up list data
-        $str .= "<select size='1' name='{$this->postName}'>";
+        $disabled = (!$this->enabled)? "disabled" : "";
+        $str .= "<select size='1' name='{$this->postName}' {$disabled}>";
         foreach($this->values as $name => $value){
             if($name == $this->value){
                 $str .= "<option selected value=\"{$name}\">{$value}</option>\n";
index d73f64641e4c474e134b85fe9261c5527e4f121c..197d6453a4ab19c4895c55f30fab8a8aea22a51c 100644 (file)
@@ -29,20 +29,22 @@ class TemplateWidget_file extends TemplateWidget
 
     function render()
     {
-        $title = set_post($this->description);
+        $title = set_post($this->description);  
+        $disabled = (!$this->enabled) ? 'disalbed' : '';
         if(mb_strlen($this->value) == 0){   
             $ret = "<i>"._("No file uploaded yet")."</i>";
             $ret.= "<br> <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"2000000\">
                 <input id=\"{$this->postName}\" 
                 name=\"{$this->postName}\" 
+                {$disabled}
                 type=\"file\" 
                 size=\"20\" 
                 maxlength=\"255\" 
                 accept=\"*.*\">&nbsp;";
-            $ret.= "<button name='{$this->postName}_Upload'>"._("Upload")."</button>";
+            $ret.= "<button {$disabled} name='{$this->postName}_Upload'>"._("Upload")."</button>";
         }else{
             $ret = "<i>"._("File uploaded").": ".mb_strlen($this->value)." "._("Bytes");
-            $ret.= "&nbsp;<button name='{$this->postName}_Remove'>".msgPool::delButton()."</button>";
+            $ret.= "&nbsp;<button {$disabled} name='{$this->postName}_Remove'>".msgPool::delButton()."</button>";
         }
         return($ret);
     }
index 0f9809728beb0dcc3f32b310101a13c55ec9a1d4..8e227e218ae3dbec0440a0931a7301d84ca2bbc7 100644 (file)
@@ -33,6 +33,8 @@ class TemplateWidget_fixedList extends TemplateWidget
         $str = "";
 
         // Build up list data
+        $this->listWidget->setDeleteable($this->enabled);
+        $disabled = (!$this->enabled)? "disabled" : "";
         $data = $this->value;
         foreach($this->value as $key => $name){
             $lData[$key] = array('data' => array($this->values[$name]));
@@ -40,12 +42,12 @@ class TemplateWidget_fixedList extends TemplateWidget
         $this->listWidget->setListData($data, $lData);
         $this->listWidget->update();
         $str .= $this->listWidget->render();
-        $str .= "<select size='1' name='{$this->postName}_Input'>";
+        $str .= "<select size='1' name='{$this->postName}_Input' {$disabled}>";
         foreach($this->getAvailableOptions() as $name => $value){
             $str .= "<option value=\"{$name}\">{$value}</option>\n";
         }
         $str .= "</select>";
-        $str .= "<button name='{$this->postName}_Add'>".msgPool::addButton()."</button>";
+        $str .= "<button name='{$this->postName}_Add' {$disabled}>".msgPool::addButton()."</button>";
         return($str);
     }
 
index ccac0fee9c74059746170ff045552462aed71cd3..8bf17a07f32a2d96e5479e9abfd5a778214cd74b 100644 (file)
@@ -20,11 +20,14 @@ class TemplateWidget_list extends TemplateWidget
     function render()
     {
         $str = "";
+        $this->listWidget->setDeleteable($this->enabled);
         $this->listWidget->setListData($this->value);
         $this->listWidget->update();
         $str .= $this->listWidget->render();
-        $str .= "<input type='text' name='{$this->postName}_Input'>";
-        $str .= "<button name='{$this->postName}_Add'>".msgPool::addButton()."</button>";
+        $disabled = (!$this->enabled)? "disabled" : "";
+
+        $str .= "<input type='text' name='{$this->postName}_Input' {$disabled}>";
+        $str .= "<button name='{$this->postName}_Add' {$disabled}>".msgPool::addButton()."</button>";
         return($str);
     }
 
index 2bf3ccca030331d374800e93af72e4cf2b3957f3..99dc273b83f1350b7f4c1f2eb2cf020bcad6eb16 100644 (file)
@@ -6,12 +6,13 @@ class TemplateWidget_string extends TemplateWidget
     {
         $desc = set_post($this->description);
         $value = set_post($this->value);
-
+        
         $name = " name=\"{$this->postName}\" ";
         $value = " value=\"{$value}\" ";
         $title = (empty($this->description))?"": " title=\"{$desc}\"";
-
-        return("<input type='text' {$title} {$name} {$value }>");
+        
+        $disabled = (!$this->enabled)? "disabled" : "";
+        return("<input type='text' {$title} {$name} {$value} {$disabled}>");
     }
 }
 
index 7c824f4f14991d6852f291bb5a024d10d8c67686..ce85384bb1fd79a436c7daee3d5bb8e6e6d92593 100644 (file)
@@ -26,6 +26,7 @@ class TemplateWidget_textEditor extends TemplateWidget
         $smarty->assign("postName", set_post($this->postName));
         $smarty->assign("write_protect", set_post($this->write_protect));
         $smarty->assign("value", set_post($this->value));
+        $smarty->assign("enabled", set_post($this->enabled));
         return($smarty->fetch(get_template_path("TemplateWidget_textEditor.tpl", TRUE, dirname(__FILE__))));
     }
 
index 030dd1156e2331f3f7c5ae1585dc997923b5c644..8ca6ff8387d10d9f807fd2192aa65fd3fe0fae71 100644 (file)
@@ -5,8 +5,10 @@ class TemplateWidget_textarea extends TemplateWidget
     function render()
     {
         $title = set_post($this->description);
+        $disabled = (!$this->enabled)? "disabled" : "";
         return("<textarea   title=\"{$title}\"
-                            style='width:100%' 
+                            style='width:100%'
+                            {$disabled} 
                             rows=4 type='text' 
                             name=\"{$this->postName}\">".set_post($this->value)."</textarea>");
     }