zoneminder/web/api/app/Controller/Component/ConfigParserComponent.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2.6 KiB
PHP
Raw Normal View History

<?php
App::uses('Component', 'Controller');
class ConfigParserComponent extends Component {
public function parseHints($hint) {
$string = "";
$hints = explode('|', $hint);
foreach ($hints as $hint) {
$string .= "<option value=\"$hint\">$hint</option>";
}
return $string;
}
2014-09-25 01:24:53 +08:00
public function getLabel($name) {
$width = 'col-md-4';
$string = '<div class="form-group">';
$string .= '<label for="%s" class="control-label %s">%s</label>';
$label = sprintf($string, $name, $width, $name);
$label .= '<div class="col-md-6">';
return $label;
}
public function getInput($name, $type, $id) {
if ($type == 'checkbox') {
2015-06-11 10:58:58 +08:00
$string = '<input id="%s" type="checkbox" ng-change="updateConfig(\'%s\', \'%s\')" ng-model="myModel.configData[\'%s\']" ng-true-value="\'1\'" ng-false-value="\'0\'"><span class="form-control-feedback"></span></div>';
2014-09-25 01:24:53 +08:00
} elseif ($type == 'text') {
$string = '<input id="%s" type="text" ng-change="updateConfig(\'%s\', \'%s\')" ng-model="myModel.configData[\'%s\']" class="form-control"><span class="form-control-feedback"></span></div>';
} elseif ($type == 'textarea') {
$string = '<textarea id="%s" ng-change="updateConfig(\'%s\', \'%s\')" class="form-control" rows="3" ng-model="myModel.configData[\'%s\']"></textarea><span class="form-control-feedback"></span></div>';
} elseif ($type == 'select') {
$string = '<select id="%s" ng-change="updateConfig(\'%s\', \'%s\')" class="form-control" ng-model="myModel.configData[\'%s\']">';
}
$input = sprintf($string, $name, $id, $name, $name);
return $input;
}
public function parseOptions($configs) {
$category = $configs[0]['Config']['Category'];
$string = "";
foreach ($configs as $option) {
$type = $option['Config']['Type'];
$name = $option['Config']['Name'];
$value = $option['Config']['Value'];
$hint = $option['Config']['Hint'];
$id = $option['Config']['Id'];
2014-09-25 01:24:53 +08:00
$string .= $this->getLabel($name);
switch ($type) {
case "boolean":
2014-09-25 01:24:53 +08:00
$string .= $this->getInput($name, 'checkbox', $id);
break;
case "text":
2014-09-25 01:24:53 +08:00
$string .= $this->getInput($name, 'textarea', $id);
break;
case "string":
if (strpos($hint, '|') === FALSE) {
2014-09-25 01:24:53 +08:00
$string .= $this->getInput($name, 'text', $id);
} else {
2014-09-25 01:24:53 +08:00
$string .= $this->getInput($name, 'select', $id);
$string .= $this->parseHints($hint);
2014-09-25 01:24:53 +08:00
$string .= '</select> <span class="form-control-feedback"></span> </div>';
}
break;
default:
2014-09-25 01:24:53 +08:00
$string .= $this->getInput($name, 'text', $id);
}
2014-09-25 01:24:53 +08:00
$string .= "</div><!-- End .form-group -->\n";
}
return $string;
}
}
?>