From bffe78904f6a0b406c2e97a3bd21bece430aa634 Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Sat, 22 Jun 2013 11:59:46 -0400 Subject: [PATCH] Display the correct input type for the config option. I am keying the input type off of the 'Hint' and 'Type' columns in the Config table. It would be easier if I just added an 'inputtype' column to the Config table, and I might do that later, but I don't want to mess with the database right now. --- web/app/View/Config/index.ctp | 55 +++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/web/app/View/Config/index.ctp b/web/app/View/Config/index.ctp index be5fad2d2..2ed7b8ae1 100644 --- a/web/app/View/Config/index.ctp +++ b/web/app/View/Config/index.ctp @@ -18,9 +18,46 @@ foreach ($options as $option => $value) { echo "
"; foreach ($value as $val) { $id = $val['Config']['Id']; - $inputname = 'Config.' . $id . '.' . $val['Config']['Name']; + $name = $val['Config']['Name']; + $inputname = 'Config.' . $id . '.' . $name; + $type = $val['Config']['Type']; + $hint = $val['Config']['Hint']; + $hints = explode('|', $hint); + $selectoptions = array(); - switch ($val['Config']['Type']) { + // Because I don't want to modify the database, I need + // to work with what is already there to determine + // which types of inputs to use. I can do this based + // off of hthe 'hint' fileld. + // + // If 'hint' contains '|', it is either a radio + // or select box, though I'm making all radios selects. + // If the 'hint' contains '|' && '=', it was supposed to be a + // select. + // + // This would be much easier if each Config row had an 'inputtype' column... + + // If the type is supposed to be a radio... + // I'm making it a select anyway! + if (preg_match("/\|/", $hint) && ($type != 'boolean') ) { + $type = 'select'; + foreach ($hints as $hint) { + $foo = explode('|', $hint); + $selectoptions[$foo[0]] = $foo[0]; // I don't want my selects indexed - I want them associated. + } + } + + // If the type is supposed to be a select box... + if ( preg_match("/\=/", $hint) && ($type == 'select') ) { + $selectoptions = array(); + foreach ($hints as $hint) { + $foo = explode('=', $hint); + $selectoptions[$foo[1]] = $foo[0]; + } + } + + // For all of the other types, set them appropriately. + switch ($type) { case 'boolean': $type = 'checkbox'; break; @@ -30,14 +67,22 @@ foreach ($options as $option => $value) { case 'string': $type = 'text'; break; + case 'text': + $type = 'textarea'; + break; } + + // Create the actual inputs. 'options' and 'legend' + // are ignored when they're not needed, such as in + // the case of a text or checkbox input type. echo $this->Form->input($inputname, array( 'default' => $val['Config']['Value'], - 'label' => $val['Config']['Name'], + 'label' => $name, 'title' => $val['Config']['Prompt'], - 'type' => $type + 'type' => $type, + 'options' => $selectoptions, // Only used by cakephp when 'type' is 'select' + 'legend' => false )); - echo "\n"; } echo "
"; // End each category div }