function display($arrParam = array()) { print '<div id="' . $this->name . '">'; if (isset($arrParam['value']) && $arrParam['value']) { for ($i = 0; $i < count($arrParam['value']); $i++) { $range = new RangeInputTpl('subnetpool_' . $i); $range->display(array("value" => $arrParam['value'][$i])); } } else { $range = new RangeInputTpl('subnetpool_0'); $range->display(); $i = 0; } $nbRanges = $i; $url = urlStrRedirect('network/network/ajaxRange'); print '</div>'; print <<<EOF <script> var nbRanges = {$nbRanges}; addRange = function() { var ranges = jQuery(jQuery.find('#{$this->name}')); jQuery.get("{$url}", { name: 'subnetpool_' + (nbRanges + 1) }). success(function(result) { ranges.append(result); nbRanges++; }); } delRange = function(elem) { jQuery(elem).parent().remove(); } updateRange = function(elem) { var range = jQuery(elem).parent().parent(); var rangeValue = jQuery(range.find('> input')[0]); rangeValue.val(""); range.find('span > input').each(function() { var str = rangeValue.val() + " " + jQuery(this).val(); rangeValue.val(str.trim()); }); } </script> EOF; print '<button type="button" class="btn btn-small" onclick="addRange(); return false;">' . _('Add') . '</button>'; }
<?php /** * (c) 2014 Mandriva, http://www.mandriva.com/ * * This file is part of Management Console. * * MMC is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * MMC is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MMC; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ include_once 'modules/network/includes/network2.inc.php'; $name = isset($_GET['name']) ? $_GET['name'] : ""; $range = new RangeInputTpl($name); $range->display();