From 9279147ad26f3c2d32b7e37da010f2346e77a6e7 Mon Sep 17 00:00:00 2001 From: Stephen Beaver Date: Mon, 9 Nov 2015 12:19:46 -0500 Subject: Allow fa icons to be embedded in Form_Button class buttons --- src/usr/local/www/classes/Form/Button.class.php | 12 ++++++++++- src/usr/local/www/classes/Form/Element.class.php | 19 +++++++++++++++-- src/usr/local/www/diag_logs.php | 26 ++++++++++++++++++------ 3 files changed, 48 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/usr/local/www/classes/Form/Button.class.php b/src/usr/local/www/classes/Form/Button.class.php index 32876a7..0b2a9de 100644 --- a/src/usr/local/www/classes/Form/Button.class.php +++ b/src/usr/local/www/classes/Form/Button.class.php @@ -36,7 +36,7 @@ class Form_Button extends Form_Input 'type' => 'submit', ); - public function __construct($name, $title, $link = null) + public function __construct($name, $title, $link = null, $icon = null) { // If we have a link; we're actually an if (isset($link)) @@ -45,6 +45,16 @@ class Form_Button extends Form_Input $this->_tagName = 'a'; $this->addClass('btn-default'); unset($this->_attributes['type']); + if(isset($icon)) { + $this->_attributes['icon'] = $icon; + } + } + else if(isset($icon)) + { + $this->_tagSelfClosing = false; + $this->_tagName = 'button'; + $this->_attributes['value'] = $title; + $this->_attributes['icon'] = $icon; } else { diff --git a/src/usr/local/www/classes/Form/Element.class.php b/src/usr/local/www/classes/Form/Element.class.php index d3ad142..163c14b 100644 --- a/src/usr/local/www/classes/Form/Element.class.php +++ b/src/usr/local/www/classes/Form/Element.class.php @@ -61,7 +61,7 @@ class Form_Element $this->_attributes[ $key ] = $value; return $this; } - + public function __toString() { $attributes = ''; @@ -79,12 +79,27 @@ class Form_Element if ($value === null) continue; + if ($key == "icon") + continue; + $attributes .= ' '. $key; if ($value !== true) $attributes .= '="' . htmlspecialchars($value) . '"'; } - return '<'. $this->_tagName . $attributes . ($this->_tagSelfClosing ? '/' : '') .'>'; + if (isset($this->_attributes['icon'])) { + $rv = '<'. $this->_tagName . $attributes .'>' . + '' . ' ' . + htmlspecialchars($this->_attributes['value']); + + if ($this->_tagName != 'a') { + $rv .= '_tagName . '>'; + } + + return $rv; + } else { + return '<'. $this->_tagName . $attributes . ($this->_tagSelfClosing ? '/' : '') .'>'; + } } protected function _setParent(Form_Element $parent) diff --git a/src/usr/local/www/diag_logs.php b/src/usr/local/www/diag_logs.php index 372e138..d4fc974 100755 --- a/src/usr/local/www/diag_logs.php +++ b/src/usr/local/www/diag_logs.php @@ -139,15 +139,28 @@ $section->addInput(new Form_Input( ['placeholder' => 'Filter text'] )); -$form->addGlobal(new Form_Button( +$btnsubmit = new Form_Button( 'filtersubmit', - 'Filter' -))->removeClass('btn-primary')->addClass('btn-default')->addClass('btn-sm'); + 'Filter', + null, + 'fa-filter' +); + +$btnsubmit->removeClass('btn-primary')->addClass('btn-success')->addClass('btn-sm'); -$form->addGlobal(new Form_Button( +$btnclear = new Form_Button( 'clear', - 'Clear log' -))->removeClass('btn-primary')->addClass('btn-danger')->addClass('btn-sm'); + 'Clear log', + null, + 'fa-trash' +); + +$btnclear->removeClass('btn-primary')->addClass('btn-danger')->addClass('btn-sm'); + +$section->addInput(new Form_StaticText( + '', + $btnsubmit . $btnclear +)); $form->add($section); print $form; @@ -156,6 +169,7 @@ if ($logfile == 'dhcpd') print_info_box('Warning: Clearing the log file will restart the DHCP daemon.'); ?> +

-- 
cgit v1.1