1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64:
<?php
namespace SpojeNet\System\ui;
class VATSwitch extends TWBSwitch
{
public function __construct($name = 'typCenyDphK', $checked = null,
$properties = null)
{
if (empty($checked)) {
$checked = 'typCeny.sDph';
}
if (!isset($properties['onText'])) {
$properties['onText'] = _('with VAT');
}
if (!isset($properties['offText'])) {
$properties['offText'] = _('without VAT');
}
$properties['value'] = $checked;
parent::__construct($name, $checked == 'typCeny.sDph', $checked,
$properties);
}
public function finalize()
{
parent::finalize();
$this->addJavaScript('
$(\'input[name="'.$this->getTagName().'"]\').on(\'switchChange.bootstrapSwitch\', function(event, state) {
console.log(this); // DOM element
console.log(event); // jQuery event
console.log(state); // true | false
if(state){
$(\'input[name="'.$this->getTagName().'"]\').val("typCeny.sDph");
} else {
$(\'input[name="'.$this->getTagName().'"]\').val("typCeny.bezDph");
}
});
');
}
}