mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 12:19:28 +00:00
JSON-Forms
This commit is contained in:
@@ -87,6 +87,7 @@ class Templates extends FHC_Controller
|
||||
$data['bezeichnung'] = $this->input->post('bezeichnung', TRUE);
|
||||
$data['anmerkung'] = $this->input->post('anmerkung', TRUE);
|
||||
$data['mimetype'] = $this->input->post('mimetype', TRUE);
|
||||
$data['attribute'] = $this->input->post('attribute', TRUE);
|
||||
$vorlage = $this->vorlagelib->saveVorlage($vorlage_kurzbz, $data);
|
||||
if ($vorlage->error)
|
||||
show_error($vorlage->retval);
|
||||
@@ -139,13 +140,11 @@ class Templates extends FHC_Controller
|
||||
|
||||
public function preview($vorlagestudiengang_id)
|
||||
{
|
||||
$formdata = $this->input->post('formdata', FALSE);
|
||||
$daten = json_decode($formdata, TRUE);
|
||||
$vorlagetext = $this->vorlagelib->getVorlagetextById($vorlagestudiengang_id);
|
||||
if ($vorlagetext->error)
|
||||
show_error($vorlagetext->retval);
|
||||
$daten = array
|
||||
(
|
||||
'vorname' => 'Christian'
|
||||
);
|
||||
$data = array
|
||||
(
|
||||
'text' => $this->vorlagelib->parseVorlagetext($vorlagetext->retval[0]->text, $daten)
|
||||
|
||||
@@ -1,18 +1,32 @@
|
||||
<?php
|
||||
$this->load->view('templates/header', array('title' => 'TemplateEdit'));
|
||||
$this->load->view('templates/header', array('title' => 'TemplateEdit', 'jsoneditor' => true));
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="span4">
|
||||
<h2>Vorlage: <?php echo $vorlage->vorlage_kurzbz; ?></h2>
|
||||
<form method="post" action="../save">
|
||||
Bezeichnung: <input type="text" name="bezeichnung" value="<?php echo $vorlage->bezeichnung; ?>" />
|
||||
Anmerkung: <input type="text" name="anmerkung" value="<?php echo $vorlage->anmerkung; ?>" />
|
||||
Anmerkung: <input type="text" name="anmerkung" value="<?php echo $vorlage->anmerkung; ?>" /><br/>
|
||||
|
||||
MimeType:<?php echo $this->templatelib->widget("mimetype_widget", array('mimetype' => $vorlage->mimetype)); ?>
|
||||
|
||||
Attribute: <?php echo $this->templatelib->widget("jsoneditor_widget", array('json' => $vorlage->attribute)); ?>
|
||||
|
||||
<input type="hidden" name="attribute" id="attribute" value="<?=$vorlage->attribute?>" />
|
||||
<input type="hidden" name="vorlage_kurzbz" value="<?php echo $vorlage->vorlage_kurzbz; ?>" />
|
||||
<button type="submit">Save</button>
|
||||
<button type="submit" onclick="getJSON(this.form);">Save</button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" >
|
||||
// get json
|
||||
function getJSON(form)
|
||||
{
|
||||
form.elements["attribute"].value = JSON.stringify(jsoneditor.get(), null, 2);
|
||||
//alert(form.elements["attribute"].value);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
$this->load->view('templates/header', array('title' => 'TemplateEdit', 'tinymce' => true));
|
||||
$this->load->view('templates/header', array('title' => 'TemplateEdit', 'tinymce' => true, 'jsonforms' => true));
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
@@ -18,13 +18,24 @@ StudiengangKZ: <?=$studiengang_kz?>
|
||||
?>
|
||||
<button type="submit">Save</button>
|
||||
</form>
|
||||
|
||||
<hr/><h2>Preview-Data</h2>
|
||||
<form method="post" action="../preview/<?=$vorlagestudiengang_id?>" target="TemplatePreview">
|
||||
<button type="submit">Preview</button>
|
||||
<?php echo $this->templatelib->widget("jsonforms_widget", array('id' => 'dataform')); ?>
|
||||
<input type="hidden" name="formdata" id="formdata" value="" />
|
||||
<button type="submit" onclick="getFormdata(this.form);">Preview</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" >
|
||||
// get json
|
||||
function getFormdata(form)
|
||||
{
|
||||
form.elements["formdata"].value = JSON.stringify(bf.getData(), null, 2);
|
||||
//alert(form.elements["formdata"].value);
|
||||
}
|
||||
</script>
|
||||
|
||||
<iframe name="TemplatePreview" width="100%" src="../preview/<?=$vorlagestudiengang_id?>"/>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -8,6 +8,8 @@ isset($title) ? $title = 'VileSci - '.$title : $title = 'VileSci';
|
||||
!isset($widgets) ? $widgets = 'zebra' : $widgets = $widgets;
|
||||
!isset($headers) ? $headers = '' : $headers = $headers;
|
||||
!isset($tinymce) ? $tinymce = false : $tinymce = $tinymce;
|
||||
!isset($jsoneditor) ? $jsoneditor = false : $jsoneditor = $jsoneditor;
|
||||
!isset($jsonforms) ? $jsonforms = false : $jsonforms = $jsonforms;
|
||||
|
||||
if ($tablesort)
|
||||
$jquery = true;
|
||||
@@ -46,6 +48,15 @@ if ($tablesort)
|
||||
<script type="text/javascript" src="<?php echo base_url('vendor/tinymce/tinymce/tinymce.min.js');?>"></script>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if($jsoneditor) : ?>
|
||||
<link href="<?php echo base_url('vendor/jsoneditor/dist/jsoneditor.css');?>" rel="stylesheet" type="text/css">
|
||||
<script src="<?php echo base_url('vendor/jsoneditor/dist/jsoneditor.js');?>"></script>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if($jsonforms) : ?>
|
||||
<link rel="stylesheet" href="<?php echo base_url('vendor/json-forms/dist/css/brutusin-json-forms.min.css'); ?>"/>
|
||||
<script src="<?php echo base_url('vendor/json-forms/dist/js/brutusin-json-forms.min.js'); ?>"></script>
|
||||
<?php endif ?>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<div id="<?=$id?>" style="<?=$style?>"></div>
|
||||
<script>
|
||||
var container = document.getElementById('<?=$id?>');
|
||||
|
||||
var options = {
|
||||
mode: '<?=$mode?>',
|
||||
modes: [<?=$modes?>],
|
||||
onError: function (err) {
|
||||
alert(err.toString());
|
||||
},
|
||||
onModeChange: function (newMode, oldMode) {
|
||||
console.log('Mode switched from', oldMode, 'to', newMode);
|
||||
}
|
||||
};
|
||||
|
||||
var json = <?=$json?>;
|
||||
|
||||
var <?=$vareditor?> = new JSONEditor(container, options, json);
|
||||
</script>
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<div id="<?=$id?>" style="<?=$style?>"></div>
|
||||
<script language="Javascript" type="text/javascript">
|
||||
var container = document.getElementById('<?=$id?>');
|
||||
var schema = <?=$schema?>;
|
||||
var BrutusinForms = brutusin["json-forms"];
|
||||
var <?=$objectname?> = BrutusinForms.create(schema);
|
||||
<?=$objectname?>.render(container);
|
||||
</script>
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<div id="<?=$id?>" style="<?=$style?>"></div>
|
||||
<script>
|
||||
var container = document.getElementById('<?=$id?>');
|
||||
|
||||
var options = {
|
||||
mode: '<?=$mode?>',
|
||||
modes: [<?=$modes?>],
|
||||
onError: function (err) {
|
||||
alert(err.toString());
|
||||
},
|
||||
onModeChange: function (newMode, oldMode) {
|
||||
console.log('Mode switched from', oldMode, 'to', newMode);
|
||||
}
|
||||
};
|
||||
|
||||
var json = <?=$json?>;
|
||||
|
||||
var <?=$vareditor?> = new JSONEditor(container, options, json);
|
||||
</script>
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* JSONEditor widget
|
||||
*/
|
||||
class jsoneditor_widget extends Widget
|
||||
{
|
||||
public function display($data)
|
||||
{
|
||||
// set default values if needed
|
||||
if (! isset($data['vareditor']))
|
||||
$data['vareditor'] = 'jsoneditor';
|
||||
if (! isset($data['style']))
|
||||
$data['style'] = 'width: 500px; height: 400px;';
|
||||
if (! isset($data['id']))
|
||||
$data['id'] = 'jsoneditor';
|
||||
if (! isset($data['mode']))
|
||||
$data['mode'] = 'code';
|
||||
if (! isset($data['modes']))
|
||||
$data['modes'] = "'code', 'tree', 'form'";// allowed modes
|
||||
if (! isset($data['json']))
|
||||
$data['json'] = '{
|
||||
"array": [1, 2, 3],
|
||||
"boolean": true,
|
||||
"null": null,
|
||||
"number": 123,
|
||||
"object": {"a": "b", "c": "d"},
|
||||
"string": "Hello FH-Complete"
|
||||
}';
|
||||
$this->view('widgets/jsoneditor', $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* JSON-Forms widget
|
||||
*/
|
||||
class jsonforms_widget extends Widget
|
||||
{
|
||||
public function display($data)
|
||||
{
|
||||
// set default values if needed
|
||||
if (! isset($data['objectname']))
|
||||
$data['objectname'] = 'bf';
|
||||
if (! isset($data['id']))
|
||||
$data['id'] = 'jsonforms';
|
||||
if (! isset($data['style']))
|
||||
$data['style'] = 'width: 500px; height: 200px;';
|
||||
if (! isset($data['schema']))
|
||||
$data['schema'] = '{
|
||||
"$schema": "http://json-schema.org/draft-03/schema#",
|
||||
"title": "Person",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"anrede": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"Herr",
|
||||
"Frau"
|
||||
],
|
||||
"default": "Herr"
|
||||
},
|
||||
"vorname": {
|
||||
"type": "string",
|
||||
"description": "Firstname",
|
||||
"minLength": 2,
|
||||
"default": "Vorname"
|
||||
},
|
||||
"nachname": {
|
||||
"type": "string",
|
||||
"description": "Firstname",
|
||||
"minLength": 2,
|
||||
"default": "Nachname"
|
||||
},
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "Accesscode",
|
||||
"minLength": 6,
|
||||
"default": "1q2w3e4r5t6z7u8i9o0"
|
||||
},
|
||||
"link": {
|
||||
"type": "string",
|
||||
"description": "LoginURL",
|
||||
"minLength": 6,
|
||||
"default": "https://cis.fhcomplete.org"
|
||||
}
|
||||
}
|
||||
}';
|
||||
$this->view('widgets/jsonforms', $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* JSONEditor widget
|
||||
*/
|
||||
class jsoneditor_widget extends Widget
|
||||
{
|
||||
public function display($data)
|
||||
{
|
||||
// set default values if needed
|
||||
if (! isset($data['vareditor']))
|
||||
$data['vareditor'] = 'jsoneditor';
|
||||
if (! isset($data['style']))
|
||||
$data['style'] = 'width: 500px; height: 400px;';
|
||||
if (! isset($data['id']))
|
||||
$data['id'] = 'jsoneditor';
|
||||
if (! isset($data['mode']))
|
||||
$data['mode'] = 'code';
|
||||
if (! isset($data['modes']))
|
||||
$data['modes'] = "'code', 'tree', 'form'";// allowed modes
|
||||
if (! isset($data['json']))
|
||||
$data['json'] = '{
|
||||
"array": [1, 2, 3],
|
||||
"boolean": true,
|
||||
"null": null,
|
||||
"number": 123,
|
||||
"object": {"a": "b", "c": "d"},
|
||||
"string": "Hello FH-Complete"
|
||||
}';
|
||||
$this->view('widgets/jsoneditor', $data);
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,32 @@
|
||||
"type": "zip"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "package",
|
||||
"package":
|
||||
{
|
||||
"name": "jsoneditor",
|
||||
"version": "5.5.6",
|
||||
"dist":
|
||||
{
|
||||
"url": "https://github.com/josdejong/jsoneditor/archive/v5.5.6.zip",
|
||||
"type": "zip"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "package",
|
||||
"package":
|
||||
{
|
||||
"name": "json-forms",
|
||||
"version": "1.4.0",
|
||||
"dist":
|
||||
{
|
||||
"url": "https://github.com/brutusin/json-forms/archive/v1.4.0.zip",
|
||||
"type": "zip"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"require":
|
||||
@@ -42,6 +68,8 @@
|
||||
"php": ">=5.4.0",
|
||||
"codeigniter/framework":"3.*",
|
||||
"codeigniter-restserver": "2.6",
|
||||
"jsoneditor": "5.5.6",
|
||||
"kingsquare/json-schema-form": "*",
|
||||
"easyrdf/easyrdf": "0.9.*",
|
||||
"ml/json-ld": "1.*",
|
||||
"rougin/combustor": "1.1.*",
|
||||
@@ -55,6 +83,7 @@
|
||||
"zetacomponents/document": "1.*",
|
||||
"zetacomponents/workflow-database-tiein": "1.*",
|
||||
"zetacomponents/workflow-event-log-tiein": "1.*",
|
||||
"json-forms": "1.4.0",
|
||||
"wikimedia/composer-merge-plugin": "^1.3"
|
||||
},
|
||||
"require-dev":
|
||||
|
||||
Reference in New Issue
Block a user