diff options
author | Scott Ullrich <sullrich@pfsense.org> | 2004-12-22 19:33:27 +0000 |
---|---|---|
committer | Scott Ullrich <sullrich@pfsense.org> | 2004-12-22 19:33:27 +0000 |
commit | eec70f2143b8726f905d44d3eef564a977fb1149 (patch) | |
tree | 54a1f800a120fda565c38d3ce263d5bbe7373424 | |
parent | 2a520a0a1bc2bd9df601d828f84b9dc17da28147 (diff) | |
download | pfsense-eec70f2143b8726f905d44d3eef564a977fb1149.zip pfsense-eec70f2143b8726f905d44d3eef564a977fb1149.tar.gz |
Add rowhelper type which will place add and delete row items on a form. This can be used to group like items together on the web gui. First package employing this neat feature is pfStat
-rwxr-xr-x | usr/local/www/pkg_edit.php | 126 | ||||
-rwxr-xr-x | usr/local/www/row_helper.js | 5 | ||||
-rwxr-xr-x | usr/local/www/row_helper_dynamic.js | 66 |
3 files changed, 187 insertions, 10 deletions
diff --git a/usr/local/www/pkg_edit.php b/usr/local/www/pkg_edit.php index e3cfed9..4797133 100755 --- a/usr/local/www/pkg_edit.php +++ b/usr/local/www/pkg_edit.php @@ -96,30 +96,52 @@ include("fbegin.inc"); } } + // donotsave is enabled. lets simply exit. if($pkg['donotsave'] <> "") exit; // store values in xml configration file. if (!$input_errors) { $pkgarr = array(); - + foreach ($pkg['fields']['field'] as $fields) { - $fieldname = $fields['fieldname']; - $fieldvalue = $_POST[$fieldname]; - $toeval = "\$pkgarr['" . $fieldname . "'] = \"" . $fieldvalue . "\";"; - eval($toeval); + if($fields['type'] == "rowhelper") { + // save rowhelper items. + $rowhelperarray = array(); + foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) { + array_push($rowhelperarray, $rowhelperfield['fieldname']); + } + for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form. + foreach($rowhelperarrray as $rha) { + $comd = "\$value = \$_POST['" . $rha . $x . "'];"; + eval($comd); + if($value <> "") { + $comd = "pkgarr['rowhelper']['" . $rha . "'] = \"" . $value . "\";"; + eval($comd); + } + } + } + } else { + // simply loop through all field names looking for posted + // values matching the fieldnames. if found, save to package + // configuration area. + $fieldname = $fields['fieldname']; + $fieldvalue = $_POST[$fieldname]; + $toeval = "\$pkgarr['" . $fieldname . "'] = \"" . $fieldvalue . "\";"; + eval($toeval); + } } - + if (isset($id) && $a_pkg[$id]) $a_pkg[$id] = $pkgarr; else $a_pkg[] = $pkgarr; - + write_config(); - + if($pkg['custom_add_php_command_late'] <> "") { eval($pkg['custom_add_php_command_late']); } - + header("Location: pkg.php?xml=" . $xml); } } @@ -134,6 +156,10 @@ include("fbegin.inc"); </head> <body link="#0000CC" vlink="#0000CC" alink="#0000CC"> + +<script type="text/javascript" language="javascript" src="row_helper_dynamic.js"> +</script> + <?php $config_tmp = $config; $config = $pfSense_config; @@ -190,6 +216,88 @@ $config = $config_tmp; echo "<br>" . $pkga['description'] . "\n"; } else if($pkga['type'] == "radio") { echo "<input type='radio' name='" . $pkga['fieldname'] . "' value='" . $value . "'>"; + } else if($pkga['type'] == "rowhelper") { + ?> + <script type="text/javascript" language='javascript'> + <!-- + + <?php + $rowcounter = 0; + $fieldcounter = 0; + foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) { + echo "rowname[" . $fieldcounter . "] = \"" . $rowhelper['fieldname'] . "\";\n"; + echo "rowtype[" . $fieldcounter . "] = \"" . $rowhelper['type'] . "\";\n"; + $fieldcounter++; + } + ?> + + --> + </script> + + <table name="maintable" id="maintable"> + <tbody> + + <?php + echo "<tr>"; + // XXX: traverse saved fields, add back needed rows. + echo "</tr>"; + + if($rowcounter == 0) { + // nothing saved. manually add the first row. + echo "<tr>\n"; + $rowcounter = 0; + $trc = 0; + foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) { + $temp = ""; + $text = ""; + echo "<td>\n"; + if($rowhelper['type'] == "input") { + echo "<input name='" . $rowhelper['fieldname'] . $trc . "' value=''>\n"; + } else if($rowhelper['type'] == "password") { + echo "<input type='password' name='" . $rowhelper['fieldname'] . $trc . "' value=''>\n"; + } else if($rowhelper['type'] == "textarea") { + echo "<textarea name='" . $rowhelper['fieldname'] . $trc . "'></textarea>\n"; + } else if($rowhelper['type'] == "select") { + echo "<select name='" . $rowhelper['fieldname'] . $trc . "'>\n"; + foreach($rowhelper['options']['option'] as $rowopt) { + $text .= "<option value='" . $rowopt['name'] . "'>" . $rowopt['value'] . "</option>"; + echo "<option value='" . $rowopt['value'] . "'>" . $rowopt['name'] . "</option>\n"; + } + echo "</select>\n"; + } + echo "</td>\n"; + echo "<script language=\"JavaScript\">\n"; + echo "<!--\n"; + echo "newrow[" . $trc . "] = \"" . $text . "\";\n"; + echo "-->\n"; + echo "</script>\n"; + $trc++; + } + $rowcounter++; + echo "<td>"; + echo "<input type=\"button\" onclick=\"removeRow(this); typesel_change();\" value=\"Delete\">"; + echo "</td>\n"; + echo "</tr>\n"; + } + ?> + + </tbody> + </table> + + <br><input type="button" onclick="addRowTo('maintable'); typesel_change();" value="Add"> + + <script language="JavaScript"> + <!-- + field_counter_js = <?= $fieldcounter ?>; + rows = <?= $rowcounter ?>; + totalrows = <?php echo $rowcounter; ?>; + loaded = <?php echo $rowcounter; ?>; + typesel_change(); + + //--> + </script> + + <?php } if($pkga['typehint']) echo " " . $pkga['typehint']; diff --git a/usr/local/www/row_helper.js b/usr/local/www/row_helper.js index 2379f96..1be80e5 100755 --- a/usr/local/www/row_helper.js +++ b/usr/local/www/row_helper.js @@ -1,9 +1,12 @@ // Global Variables var rowname = new Array(99); var rowtype = new Array(99); +var newrow = new Array(99); + for (i = 0; i < 99; i++) { rowname[i] = ''; rowtype[i] = ''; + newrow[i] = ''; } var field_counter_js = 0; @@ -21,7 +24,7 @@ var addRowTo = (function() { for (i = 0; i < field_counter_js; i++) { td = d.createElement("td"); if(rowtype[i] == 'textbox') { - td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><input name='" + rowname[i] + + totalrows + "'></input> "; + td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><input name='" + rowname[i] + totalrows + "'></input> "; } else if(rowtype[i] == 'select') { td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><select name='" + rowname[i] + totalrows + "'><option value=\"32\" selected>32</option><option value=\"31\" >31</option><option value=\"30\" >30</option><option value=\"29\" >29</option><option value=\"28\" >28</option><option value=\"27\" >27</option><option value=\"26\" >26</option><option value=\"25\" >25</option><option value=\"24\" >24</option><option value=\"23\" >23</option><option value=\"22\" >22</option><option value=\"21\" >21</option><option value=\"20\" >20</option><option value=\"19\" >19</option><option value=\"18\" >18</option><option value=\"17\" >17</option><option value=\"16\" >16</option><option value=\"15\" >15</option><option value=\"14\" >14</option><option value=\"13\" >13</option><option value=\"12\" >12</option><option value=\"11\" >11</option><option value=\"10\" >10</option><option value=\"9\" >9</option><option value=\"8\" >8</option><option value=\"7\" >7</option><option value=\"6\" >6</option><option value=\"5\" >5</option><option value=\"4\" >4</option><option value=\"3\" >3</option><option value=\"2\" >2</option><option value=\"1\" >1</option></select> "; } else { diff --git a/usr/local/www/row_helper_dynamic.js b/usr/local/www/row_helper_dynamic.js new file mode 100755 index 0000000..10caca4 --- /dev/null +++ b/usr/local/www/row_helper_dynamic.js @@ -0,0 +1,66 @@ +// Global Variables +var rowname = new Array(99); +var rowtype = new Array(99); +var newrow = new Array(99); + +for (i = 0; i < 99; i++) { + rowname[i] = ''; + rowtype[i] = ''; + newrow[i] = ''; +} + +var field_counter_js = 0; +var loaded = 0; +var is_streaming_progress_bar = 0; +var temp_streaming_text = ""; + +var addRowTo = (function() { + return (function (tableId) { + var d, tbody, tr, td, bgc, i, ii, j; + d = document; + tbody = d.getElementById(tableId).getElementsByTagName("tbody").item(0); + tr = d.createElement("tr"); + totalrows++; + for (i = 0; i < field_counter_js; i++) { + td = d.createElement("td"); + if(rowtype[i] == 'textbox') { + td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><input name='" + rowname[i] + totalrows + "'></input> "; + } else if(rowtype[i] == 'select') { + td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><select name='" + rowname[i] + totalrows + "'>" + newrow[i] + "</select> "; + } else if(rowtype[i] == 'checkbox') { + td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><input type='checkbox' name='" + rowname[i] + totalrows + "'></input> "; + } + tr.appendChild(td); + } + td = d.createElement("td"); + td.rowSpan = "1"; + td.innerHTML = '<input type="button" value="Delete" onclick="removeRow(this)">'; + tr.appendChild(td); + tbody.appendChild(tr); + }); +})(); + +function removeRow(el) { + var cel; + while (el && el.nodeName.toLowerCase() != "tr") + el = el.parentNode; + + if (el && el.parentNode) { + cel = el.getElementsByTagName("td").item(0); + el.parentNode.removeChild(el); + } +} + +function find_unique_field_name(field_name) { + // loop through field_name and strip off -NUMBER + var last_found_dash = 0; + for (var i = 0; i < field_name.length; i++) { + // is this a dash, if so, update + // last_found_dash + if (field_name.substr(i,1) == "-" ) + last_found_dash = i; + } + if (last_found_dash < 1) + return field_name; + return(field_name.substr(0,last_found_dash)); +} |