Skip to content

Commit

Permalink
support for boolselect fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Praesidiarius committed Mar 17, 2020
1 parent 323d5cf commit 9db8bd5
Show file tree
Hide file tree
Showing 10 changed files with 255 additions and 29 deletions.
11 changes: 8 additions & 3 deletions module/Application/src/Controller/CoreEntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,6 @@ public function generateEditView($sKey,$sSingleForm = '') {
$iSkeletonID = $oRequest->getPost('Item_ID');
$oSkeleton = $this->oTableGateway->getSingle($iSkeletonID);

# Update Skeleton with Form Data
$oSkeleton = $this->attachFormData($_REQUEST,$oSkeleton);

# file upload
$aFields = $this->getFormFields($this->sSingleForm);
foreach($aFields as $oField) {
Expand All @@ -493,9 +490,17 @@ public function generateEditView($sKey,$sSingleForm = '') {
$oSkeleton->setTextField($oField->fieldkey,$_FILES[$sFileKey]['name']);
}
}
# attach empty checkboxes
} elseif($oField->type == 'boolselect') {
if(!isset($_REQUEST[$this->sSingleForm.'_'.$oField->fieldkey])) {
$_REQUEST[$this->sSingleForm.'_'.$oField->fieldkey] = 0;
}
}
}

# Update Skeleton with Form Data
$oSkeleton = $this->attachFormData($_REQUEST,$oSkeleton);

# Save Skeleton
$iSkeletonID = $this->oTableGateway->saveSingle($oSkeleton);

Expand Down
1 change: 1 addition & 0 deletions module/Application/src/Model/CoreEntityModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ protected function attachDynamicFields() {
case 'currency':
case 'hidden':
case 'number':
case 'boolselect':
$this->$sFieldName = 0;
break;
case 'date':
Expand Down
1 change: 1 addition & 0 deletions module/Application/src/Model/CoreEntityTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ protected function attachDynamicFields(array $aData,$oObject) {
case 'text':
case 'textarea':
case 'email':
case 'boolselect':
case 'upload':
case 'tel':
case 'url':
Expand Down
222 changes: 205 additions & 17 deletions module/Application/view/partial/basicform.phtml
Original file line number Diff line number Diff line change
@@ -1,18 +1,206 @@
<form action="" method="POST" enctype="multipart/form-data" class="plc-core-basic-form">
<?php if(isset($this->oItem)) { ?>
<input type="hidden" name="Item_ID" value="<?=$this->oItem->getID()?>" />
<?php } ?>
<?php if(isset($this->iRefIDFS)) { ?>
<input type="hidden" name="ref_idfs" value="<?=$this->iRefIDFS?>" />
<?php } ?>
<div class="row">
<?= $this->partial('partial/basictabs', ['sFormName'=>$this->sFormName]); ?>
<?php
$aPartialData = ['sFormName'=>$this->sFormName,'oItem'=>$this->oItem];
if(isset($this->aPartialExtraData)) {
$aPartialData['aPartialExtraData'] = $this->aPartialExtraData;
}
?>
<?= $this->partial('partial/basictabcontents',$aPartialData); ?>
<div class="row">
<div class="col-md-3">
<div class="card">
<div class="card-body text-center">
<?php if($oItem->hasFeaturedImage()) { ?>
<div style="max-width:250px; margin:auto;">
<!-- our filepond input -->
<input type="file" name="filepond" id="filepond">
</div>
<?php } ?>
<h2><?=$oItem->getLabel()?></h2>
<hr/>
<?php
echo $this->partial('partial/viewleftwidgets', [
'oItem' => $this->oItem,
'sFormName' => $this->sFormName,
'aFormFieldsByTab' => $this->layout()->aFormFieldsByTab
]);
?>
<?php
$sCreatedDate = $oItem->getTextField('created_date');
if($sCreatedDate != '0000-00-00 00:00:00' && !empty($sCreatedDate)) { ?>
<div style="text-align: left;">
<small><?=$this->translate('Created')?>: <?=date('d.m.Y H:i',strtotime($sCreatedDate))?></small><br/>
<small><?=$this->translate('Last Edited')?>: <?=date('d.m.Y H:i',strtotime($oItem->getTextField('modified_date')))?></small>
</div>
<?php } ?>
</div>
</div>
</div>
<div class="col-md-9">
<div class="card px-0">
<div class="card-body px-0 py-2 px-3">
<form action="" method="POST" enctype="multipart/form-data" class="plc-core-basic-form">
<?php if(isset($this->oItem)) { ?>
<input type="hidden" name="Item_ID" value="<?=$this->oItem->getID()?>" />
<?php } ?>
<?php if(isset($this->iRefIDFS)) { ?>
<input type="hidden" name="ref_idfs" value="<?=$this->iRefIDFS?>" />
<?php } ?>
<div class="row">
<?= $this->partial('partial/basictabs', ['sFormName'=>$this->sFormName]); ?>
<?php
$aPartialData = ['sFormName'=>$this->sFormName,'oItem'=>$this->oItem];
if(isset($this->aPartialExtraData)) {
$aPartialData['aPartialExtraData'] = $this->aPartialExtraData;
}
?>
<?= $this->partial('partial/basictabcontents',$aPartialData); ?>
</div>
</form>
</div>
</div>
</div>
</form>
</div>

<?php if($oItem->hasFeaturedImage()) { ?>
<script>
const fieldsetElement = document.getElementById('filepond');

FilePond.registerPlugin(
FilePondPluginFileValidateType,
FilePondPluginImageExifOrientation,
FilePondPluginImagePreview,
FilePondPluginImageTransform
);
FilePond.create(
fieldsetElement,
{
labelIdle: `Drag & Drop your picture or <span class="filepond--label-action">Browse</span>`,
imagePreviewHeight: 170,
stylePanelLayout: 'compact circle',
styleLoadIndicatorPosition: 'center bottom',
styleProgressIndicatorPosition: 'right bottom',
styleButtonRemoveItemPosition: 'left bottom',
styleButtonProcessItemPosition: 'right bottom',
}
);

FilePond.setOptions({
server: {
process: {
url: '/filepond',
method: 'POST',
withCredentials: false,
headers: {},
timeout: 7000,
onload: (response) => {
console.log(response);
},
onerror: (e) => {
$('#plc-featured-image').printMessage('Fehler',e.detail.error.main,'error');
},
ondata: (formData) => {
formData.append('type', '<?=explode('-',$this->sFormName)[0]?>');
formData.append('entity_id', '<?=$oItem->getID()?>');
return formData;
}
},
load: '/'
},
<?php if($oItem->getTextField('featured_image')) { ?>
files: [
{
// the server file reference
source: '/data/<?=explode('-',$this->sFormName)[0]?>/<?=$oItem->getID()?>/<?=$oItem->getTextField('featured_image')?>',

// set type to limbo to tell FilePond this is a temp file
options: {
type: 'local'
}
}
]
<?php } ?>
});

fieldsetElement.addEventListener('FilePond:error', e => {
$('#plc-featured-image').printMessage('Fehler',e.detail.error.main,'error');
});
</script>
<?php } ?>
<script>
$('#<?=$this->sFormName?>Form').sortable({
axis:'x',
containment:'parent',
update: function( event, ui ) {
var sortedIDs = $( '#<?=$this->sFormName?>Form' ).sortable( "toArray" );
console.log(sortedIDs);
$.post('/application/updatetabsort',{form:"<?=$this->sFormName?>",tabs:sortedIDs},function () {

});
}
});

const tour = new Shepherd.Tour({
defaultStepOptions: {
classes: 'shadow-md bg-purple-dark',
scrollTo: false
},
useModalOverlay: true
});

tour.addStep({
id: 'edit-button',
text: '<?=$this->translate('Click here to edit '.$this->sFormName)?>',
attachTo: {
element: '.plc-button-panel a',
on: 'right'
},
classes: 'example-step-extra-class',
buttons: [
{
text: 'Weiter',
action: tour.next
}
]
});

tour.addStep({
id: 'breadcrumb-info',
text: '<?=$this->translate('See where youre currently at')?>',
attachTo: {
element: 'ol.breadcrumb',
on: 'left'
},
classes: 'example-step-extra-class',
buttons: [
{
text: 'Weiter',
action: tour.next
}
]
});

tour.addStep({
id: 'changesort-fields',
text: '<?=$this->translate('Click here to change field order')?>',
attachTo: {
element: 'a.plc-change-form-field-sort',
on: 'left'
},
classes: 'example-step-extra-class',
buttons: [
{
text: 'Weiter',
action: tour.next
}
]
});

tour.addStep({
id: 'formfield-Tabs',
text: '<?=$this->translate('Form fields are grouped in tabs')?>',
attachTo: {
element: '#article-singleForm li',
on: 'left'
},
classes: 'example-step-extra-class',
buttons: [
{
text: 'Fertig',
action: tour.complete
}
]
});
</script>
15 changes: 15 additions & 0 deletions module/Application/view/partial/basicformfield.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,21 @@ switch($oField->type) {
<input type="time" class="form-control" name="<?=$this->sFormName?>_<?=$oField->fieldkey?>" />
<?php
break;
case 'boolselect': ?>
<div class="form-control" style="margin-top:22px;">
<?php
$sChecked = '';
if(isset($this->oItem)) {
if($this->oItem->getTextField($oField->fieldkey) == 1) {
$sChecked = ' checked';
}
}
?>
<input type="checkbox" name="<?=$this->sFormName?>_<?=$oField->fieldkey?>" style="width:20%; float:left;" value="1"<?=$sChecked?> />
<label for="<?=$this->sFormName?>_<?=$oField->fieldkey?>" style="float:left; width:70%;"> <?=$this->translate($oField->label)?></label>
</div>
<?php
break;
/**
* Select field
*/
Expand Down
2 changes: 1 addition & 1 deletion module/Application/view/partial/basicformfields.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if(array_key_exists($this->sTab,$this->aFieldsByTab)) {
?>
<!-- Field <?=$oField->fieldkey?> START -->
<div class="form-group <?=$oField->class?>">
<?php if($oField->type != 'partial' && $oField->type != 'gallery') { ?>
<?php if($oField->type != 'partial' && $oField->type != 'gallery' && $oField->type != 'boolselect') { ?>
<label class="plcViewFormLabel" for="<?=$this->sFormName?>_<?=$oField->fieldkey?>">
<?=$this->translate($oField->label)?>
</label><br/>
Expand Down
3 changes: 1 addition & 2 deletions module/Application/view/partial/formheader.phtml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<?php
?>
<h2><i><?=$this->translate($this->sTitle)?></i></h2>
?>
7 changes: 4 additions & 3 deletions module/Application/view/partial/viewform.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@
fieldsetElement.addEventListener('FilePond:error', e => {
$('#plc-featured-image').printMessage('Fehler',e.detail.error.main,'error');
});

</script>
<?php } ?>
<script>
$('#<?=$this->sFormName?>Form').sortable({
axis:'x',
containment:'parent',
Expand Down Expand Up @@ -192,5 +194,4 @@
}
]
});
</script>
<?php } ?>
</script>
11 changes: 11 additions & 0 deletions module/Application/view/partial/viewformfield.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ switch($oField->type) {
echo '-';
}
break;
case 'boolselect':
$sChecked = '';
if(isset($this->oItem)) {
if($this->oItem->getTextField($oField->fieldkey) == 1) {
echo '<i class="fas fa-check"></i> ';
} else {
echo '<i class="fas fa-times"></i> ';
}
}
echo $this->translate($oField->label);
break;
case 'datetime':
if($this->oItem->getTextField($oField->fieldkey) != '0000-00-00 00:00:00') {
echo date('d.m.Y H:i',strtotime($this->oItem->getTextField($oField->fieldkey)));
Expand Down
11 changes: 8 additions & 3 deletions module/Application/view/partial/viewformfields.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ $bHideLabels = (isset($this->bHideLabels)) ? $this->bHideLabels : false;
$bOnlyLabels = (isset($this->bOnlyLabels)) ? $this->bOnlyLabels : false;
if(array_key_exists($this->sTab,$this->aFormFieldsByTab)) {
foreach($this->aFormFieldsByTab[$this->sTab] as $oField) {
$iMargin = 0;

# skip hidden fields entirely
if($oField->type == 'hidden') {
continue;
} ?>
}
if($oField->type == 'boolselect') {
$iMargin = '21px';
}?>
<!-- Field <?=$oField->fieldkey?> START -->
<div class="form-group <?=$oField->class?>">
<?php if($oField->type != 'partial' && $oField->type != 'gallery' && $oField->type != 'featuredimage' && !$bHideLabels) { ?>
<?php if($oField->type != 'partial' && $oField->type != 'gallery' && $oField->type != 'featuredimage' && !$bHideLabels && $oField->type != 'boolselect') { ?>
<label class="plcViewFormLabel" for="<?=$this->sFormName?>_<?=$oField->fieldkey?>" style="top:6px; height:25px; overflow:hidden;">
<?=$this->translate($oField->label)?>
</label><br/>
Expand All @@ -25,7 +30,7 @@ if(array_key_exists($this->sTab,$this->aFormFieldsByTab)) {
$aPartialData['aPartialExtraData'] = $this->aPartialExtraData;
}
?>
<div class="form-control" style="display: inline-block; height:auto !important; padding-left:6px; min-height:34px; ">
<div class="form-control" style="display: inline-block; margin-top:<?=$iMargin?>; height:auto !important; padding-left:6px; min-height:34px; ">
<?= $this->partial('partial/viewformfield', $aPartialData); ?>
</div>
<?php } ?>
Expand Down

0 comments on commit 9db8bd5

Please sign in to comment.