Remove tristate form element
This commit is contained in:
parent
6166d1eaf9
commit
f98f988aff
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
||||
|
||||
/**
|
||||
* Helper to generate a "datetime" element
|
||||
*/
|
||||
class Zend_View_Helper_FormTriStateCheckbox extends Zend_View_Helper_FormElement
|
||||
{
|
||||
/**
|
||||
* Generate a tri-state checkbox
|
||||
*
|
||||
* @param string $name The element name
|
||||
* @param int $value The checkbox value
|
||||
* @param array $attribs Attributes for the element tag
|
||||
*
|
||||
* @return string The element XHTML
|
||||
*/
|
||||
public function formTriStateCheckbox($name, $value = null, $attribs = null)
|
||||
{
|
||||
$class = "";
|
||||
$xhtml = '<div class="tristate">'
|
||||
. '<div>' . ($value == 1 ? ' ' : ($value === 'unchanged' ? ' ' : ' ' )) . '</div>'
|
||||
|
||||
. '<input class="' . $class . '" type="radio" value=1 name="'
|
||||
. $name . '" ' . ($value == 1 ? 'checked' : '') . ' ">On</input> '
|
||||
|
||||
. '<input class="' . $class . '" type="radio" value=0 name="'
|
||||
. $name . '" ' . ($value == 0 ? 'checked' : '') . ' ">Off</input> ';
|
||||
|
||||
if ($value === 'unchanged') {
|
||||
$xhtml = $xhtml . '<input class="' . $class . '" type="radio" value="unchanged" name="'
|
||||
. $name . '" ' . 'checked "> Undefined </input>';
|
||||
};
|
||||
return $xhtml . '</div>';
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Web\Form\Element;
|
||||
|
||||
use Icinga\Web\Form\Validator\TriStateValidator;
|
||||
use Zend_Form_Element_Xhtml;
|
||||
|
||||
/**
|
||||
* A checkbox that can display three different states:
|
||||
* true, false and mixed. When there is no JavaScript
|
||||
* available to display the checkbox properly, a radio
|
||||
* button-group with all three possible states will be
|
||||
* displayed.
|
||||
*/
|
||||
class TriStateCheckbox extends Zend_Form_Element_Xhtml
|
||||
{
|
||||
/**
|
||||
* Name of the view helper
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $helper = 'formTriStateCheckbox';
|
||||
|
||||
public function __construct($name, $options = null)
|
||||
{
|
||||
parent::__construct($name, $options);
|
||||
|
||||
$this->triStateValidator = new TriStateValidator($this->patterns);
|
||||
$this->addValidator($this->triStateValidator);
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Web\Form\Validator;
|
||||
|
||||
use Zend_Validate_Abstract;
|
||||
|
||||
class TriStateValidator extends Zend_Validate_Abstract
|
||||
{
|
||||
/**
|
||||
* @var null
|
||||
*/
|
||||
private $validPattern = null;
|
||||
|
||||
/**
|
||||
* Validate the input value and set the value of @see validPattern if the input machtes
|
||||
* a state description like '0', '1' or 'unchanged'
|
||||
*
|
||||
* @param string $value The value to validate
|
||||
* @param null $context The form context (ignored)
|
||||
*
|
||||
* @return bool True when the input is valid, otherwise false
|
||||
*
|
||||
* @see Zend_Validate_Abstract::isValid()
|
||||
*/
|
||||
public function isValid($value, $context = null)
|
||||
{
|
||||
if (!is_string($value) && !is_int($value)) {
|
||||
$this->error('INVALID_TYPE');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
$value = intval($value);
|
||||
if ($value === 'unchanged') {
|
||||
$this->validPattern = null;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_int($value)) {
|
||||
if ($value === 1 || $value === 0) {
|
||||
$this->validPattern = $value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getValidPattern()
|
||||
{
|
||||
return $this->validPattern;
|
||||
}
|
||||
}
|
|
@ -28,7 +28,6 @@ class JavaScript
|
|||
'js/icinga/behavior/collapsible.js',
|
||||
'js/icinga/behavior/detach.js',
|
||||
'js/icinga/behavior/sparkline.js',
|
||||
'js/icinga/behavior/tristate.js',
|
||||
'js/icinga/behavior/dropdown.js',
|
||||
'js/icinga/behavior/navigation.js',
|
||||
'js/icinga/behavior/form.js',
|
||||
|
|
|
@ -47,7 +47,6 @@
|
|||
<!-- application/views -->
|
||||
<file>../../application/views/helpers/FormNumber.php</file>
|
||||
<file>../../application/views/helpers/FormDateTime.php</file>
|
||||
<file>../../application/views/helpers/FormTriStateCheckbox.php</file>
|
||||
<!-- library/Icinga/Logger -->
|
||||
<file>../../library/Icinga/Logger/Writer/SyslogWriter.php</file>
|
||||
<!-- library/Icinga/User -->
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
/*! Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
|
||||
|
||||
(function(Icinga, $) {
|
||||
|
||||
"use strict";
|
||||
|
||||
Icinga.Behaviors = Icinga.Behaviors || {};
|
||||
|
||||
var Tristate = function (icinga) {
|
||||
Icinga.EventListener.call(this, icinga);
|
||||
this.on('click', 'div.tristate .tristate-dummy', this.clickTriState, this);
|
||||
};
|
||||
Tristate.prototype = new Icinga.EventListener();
|
||||
|
||||
Tristate.prototype.clickTriState = function (event) {
|
||||
var _this = event.data.self;
|
||||
var $tristate = $(this);
|
||||
var triState = parseInt($tristate.data('icinga-tristate'), 10);
|
||||
|
||||
// load current values
|
||||
var old = $tristate.data('icinga-old').toString();
|
||||
var value = $tristate.parent().find('input:radio:checked').first().prop('checked', false).val();
|
||||
|
||||
// calculate the new value
|
||||
if (triState) {
|
||||
// 1 => 0
|
||||
// 0 => unchanged
|
||||
// unchanged => 1
|
||||
value = value === '1' ? '0' : (value === '0' ? 'unchanged' : '1');
|
||||
} else {
|
||||
// 1 => 0
|
||||
// 0 => 1
|
||||
value = value === '1' ? '0' : '1';
|
||||
}
|
||||
|
||||
// update form value
|
||||
$tristate.parent().find('input:radio[value="' + value + '"]').prop('checked', true);
|
||||
// update dummy
|
||||
|
||||
if (value !== old) {
|
||||
$tristate.parent().find('b.tristate-changed').css('visibility', 'visible');
|
||||
} else {
|
||||
$tristate.parent().find('b.tristate-changed').css('visibility', 'hidden');
|
||||
}
|
||||
_this.icinga.ui.setTriState(value.toString(), $tristate);
|
||||
};
|
||||
|
||||
Icinga.Behaviors.Tristate = Tristate;
|
||||
|
||||
}) (Icinga, jQuery);
|
|
@ -566,8 +566,6 @@
|
|||
|
||||
req.$target.data('icingaUrl', req.url);
|
||||
|
||||
this.icinga.ui.initializeTriStates($resp);
|
||||
|
||||
if (rendered) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -495,60 +495,6 @@
|
|||
return $calc.width() / 1000;
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize all TriStateCheckboxes in the given html
|
||||
*/
|
||||
initializeTriStates: function ($html) {
|
||||
$('div.tristate', $html).each(function(index, item) {
|
||||
var $target = $(item);
|
||||
|
||||
// hide input boxess and remove text nodes
|
||||
$target.find("input").hide();
|
||||
$target.contents().filter(function() { return this.nodeType === 3; }).remove();
|
||||
|
||||
// has three states?
|
||||
var triState = $target.find('input[value="unchanged"]').length > 0 ? 1 : 0;
|
||||
|
||||
// fetch current value from radiobuttons
|
||||
var value = $target.find('input:checked').first().val();
|
||||
|
||||
$target.append(
|
||||
'<input class="tristate-dummy" ' +
|
||||
' data-icinga-old="' + value + '" data-icinga-tristate="' + triState + '" type="checkbox" ' +
|
||||
(value === '1' ? 'checked ' : ( value === 'unchanged' ? 'indeterminate="true" ' : ' ' )) +
|
||||
'/> <b style="visibility: hidden;" class="tristate-changed"> (changed) </b>'
|
||||
);
|
||||
if (triState) {
|
||||
// TODO: find a better way to activate indeterminate checkboxes after load.
|
||||
$target.append(
|
||||
'<script type="text/javascript"> ' +
|
||||
' $(\'input.tristate-dummy[indeterminate="true"]\').each(function(i, el){ el.indeterminate = true; }); ' +
|
||||
'</script>'
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Set the value of the given TriStateCheckbox
|
||||
*
|
||||
* @param value {String} The value to set, can be '1', '0' and 'unchanged'
|
||||
* @param $checkbox {jQuery} The checkbox
|
||||
*/
|
||||
setTriState: function(value, $checkbox) {
|
||||
switch (value) {
|
||||
case ('1'):
|
||||
$checkbox.prop('checked', true).prop('indeterminate', false);
|
||||
break;
|
||||
case ('0'):
|
||||
$checkbox.prop('checked', false).prop('indeterminate', false);
|
||||
break;
|
||||
case ('unchanged'):
|
||||
$checkbox.prop('checked', false).prop('indeterminate', true);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle mobile menu
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue