Exemplo n.º 1
0
 public function buildContent()
 {
     $ret = '';
     if (empty($this->attributes['required'])) {
         $ret = Tag::option(array('value' => ''))->setContent('')->build() . "\n";
     }
     if (!empty($this->options)) {
         if (is_array($this->options)) {
             foreach ($this->options as $value => $label) {
                 $option = Tag::option(array('value' => $value, 'content' => $label));
                 if ($value === 'NULL' && !isset($this->attributes['value'])) {
                     $option->setSelected(true);
                 } else {
                     if (isset($this->attributes['value']) && self::compareValues($this->attributes['value'], $value)) {
                         $option->setSelected(true);
                     }
                 }
                 $ret .= $option->build() . "\n";
             }
         } else {
             if (isset($this->attributes['value'])) {
                 $this->options = preg_replace('%(value=(?:\'|")' . preg_quote($this->attributes['value'], '%') . '(?:\'|"))%is', '$1 selected', $this->options);
             }
             $ret .= $this->options;
         }
     }
     return $ret;
 }
Exemplo n.º 2
0
<?php

/**
 * @var \PeskyCMF\Scaffold\Form\InputRendererConfig $rendererConfig
 * @var \PeskyCMF\Scaffold\Form\FormFieldConfig $fieldConfig
 * @var \PeskyCMF\Scaffold\Form\FormConfig $actionConfig
 * @var \PeskyCMF\Db\CmfDbModel $model
 */
$rendererConfig->addAttribute('name', $fieldConfig->getName(), false)->addAttribute('type', 'checkbox', true)->addAttribute('id', $fieldConfig->getDefaultId(), false)->addAttribute('value', 1, false)->addAttribute('class', 'styled', false);
$attributesForCreate = \Swayok\Html\Tag::buildAttributes($rendererConfig->getAttributesForCreate());
$attributesForEdit = \Swayok\Html\Tag::buildAttributes($rendererConfig->getAttributesForEdit());
?>
<div class="checkbox checkbox-primary">
    <input name="<?php 
echo $fieldConfig->getName();
?>
" id="_<?php 
echo $rendererConfig->getAttribute('id');
?>
" type="hidden" value="0">
    <input {{? !!it.<?php 
echo $fieldConfig->getName();
?>
 }}checked{{?}}
            {{? !!it.isCreation }}<?php 
echo $attributesForCreate;
?>
{{??}}<?php 
echo $attributesForEdit;
?>
{{?}}>
Exemplo n.º 3
0
 * @var \PeskyCMF\Db\CmfDbModel $model
 */
$id = $fieldConfig->getName() . '-input';
?>
<div class="form-group">
    <label for="<?php 
echo $id;
?>
"><?php 
echo $fieldConfig->getLabel();
?>
</label>
    <?php 
$attributes = array('name' => $fieldConfig->getName(), 'id' => $id, 'class' => 'form-control');
$attributesForCreate = \Swayok\Html\Tag::buildAttributes(array_merge($attributes, $rendererConfig->getAttributesForCreate()));
$attributesForEdit = \Swayok\Html\Tag::buildAttributes(array_merge($attributes, $rendererConfig->getAttributesForEdit()));
?>
    <select data-value="{{! it.<?php 
echo $fieldConfig->getName();
?>
 || ''}}"
        {{? !!it.isCreation }}<?php 
echo $attributesForCreate;
?>
{{??}}<?php 
echo $attributesForEdit;
?>
{{?}}
    >
    <?php 
if (!$fieldConfig->hasOptionsLoader()) {
Exemplo n.º 4
0
}
if ($formConfig->hasOptionsLoader()) {
    $formAttributes['data-load-options'] = '1';
}
if ($formConfig->hasJsInitiator()) {
    $formAttributes['data-initiator'] = addslashes($formConfig->getJsInitiator());
}
$editUrl = route('cmf_api_update_item', ['table_name' => $tableNameForRoutes, 'id' => ''], false) . '/' . $printPk;
$createUrl = route('cmf_api_create_item', ['table_name' => $tableNameForRoutes], false);
$formAction = $ifEdit . $editUrl . $else . $createUrl . $endIf;
?>
    <form role="form" method="post" action="<?php 
echo $formAction;
?>
" <?php 
echo \Swayok\Html\Tag::buildAttributes($formAttributes);
?>
    data-uuid="{{= it.formUUID }}">
        <?php 
echo $ifEdit;
?>
            <input type="hidden" name="_method" value="PUT">
            <input type="hidden" name="<?php 
echo $pkColName;
?>
" value="<?php 
echo $printPk;
?>
">
        <?php 
echo $endIf;
Exemplo n.º 5
0
<?php

/**
 * @var \PeskyCMF\Scaffold\Form\InputRendererConfig $rendererConfig
 * @var \PeskyCMF\Scaffold\Form\FormFieldConfig $fieldConfig
 * @var \PeskyCMF\Scaffold\Form\FormConfig $actionConfig
 * @var \PeskyCMF\Db\CmfDbModel $model
 */
$attributes = array('name' => $fieldConfig->getName(), 'id' => $fieldConfig->getDefaultId(), 'type' => 'text', 'class' => 'form-control');
$attributesForCreate = $rendererConfig->getAttributesForCreate();
$attributesForEdit = $rendererConfig->getAttributesForEdit();
$visibleOnCreate = !array_key_exists('visible', $attributesForCreate) || !empty($attributesForCreate['visible']);
$visibleOnEdit = !array_key_exists('visible', $attributesForEdit) || !empty($attributesForEdit['visible']);
unset($attributesForCreate['visible'], $attributesForEdit['visible']);
$attributesForCreate = \Swayok\Html\Tag::buildAttributes(array_merge($attributes, $attributesForCreate));
$attributesForEdit = \Swayok\Html\Tag::buildAttributes(array_merge($attributes, $attributesForEdit));
if (!$visibleOnCreate) {
    ?>
    {{? !it.isCreation }}
<?php 
} elseif (!$visibleOnEdit) {
    ?>
    {{? !!it.isCreation }}
<?php 
}
?>

<div class="form-group">
    <label for="<?php 
echo $attributes['id'];
?>
Exemplo n.º 6
0
 /**
  * @param array $options
  * @return string
  * @throws \Swayok\Html\HtmlTagException
  */
 private function buildFieldOptions(array $options)
 {
     $ret = '';
     foreach ($options as $value => $label) {
         if (!is_array($label)) {
             $ret .= Tag::option()->setContent($label)->setValue($value)->build();
         } else {
             $ret .= Tag::create()->setName('optgroup')->setAttribute('label', $value)->setContent($this->buildFieldOptions($label))->build();
         }
     }
     return $ret;
 }
Exemplo n.º 7
0
<?php

/**
 * @var \PeskyCMF\Scaffold\Form\InputRendererConfig $rendererConfig
 * @var \PeskyCMF\Scaffold\Form\FormFieldConfig $fieldConfig
 * @var \PeskyCMF\Scaffold\Form\FormConfig $actionConfig
 * @var \PeskyCMF\Db\CmfDbModel $model
 */
$id = $fieldConfig->getName() . '-input';
$attributes = array('name' => $fieldConfig->getName(), 'id' => $id);
$attributesForCreate = \Swayok\Html\Tag::buildAttributes(array_merge($attributes, $rendererConfig->getAttributesForCreate(), ['type' => 'hidden']));
$attributesForEdit = \Swayok\Html\Tag::buildAttributes(array_merge($attributes, $rendererConfig->getAttributesForEdit(), ['type' => 'hidden']));
?>
<input value="{{= it.<?php 
echo $fieldConfig->getName();
?>
 || '' }}"
    {{? !!it.isCreation }}<?php 
echo $attributesForCreate;
?>
{{??}}<?php 
echo $attributesForEdit;
?>
{{?}}>
Exemplo n.º 8
0
    $toolbar['create'] = \Swayok\Html\Tag::a()->setContent(\PeskyCMF\Config\CmfConfig::transBase('.datagrid.toolbar.create'))->setClass('btn btn-primary')->setHref(route('cmf_item_add_form', [$tableNameForRoutes], false))->build();
}
// row actions
$actionsTpl = '';
if ($dataGridConfig->isDetailsViewerAllowed()) {
    $url = $dblClickUrl = route('cmf_item_details', [$tableNameForRoutes, ":{$pkName}:"], false);
    $btn = \Swayok\Html\Tag::a()->setClass('row-action text-light-blue item-details')->setContent('<i class="glyphicon glyphicon-info-sign"></i>')->setTitle(\PeskyCMF\Config\CmfConfig::transBase('.datagrid.actions.view_item'))->setDataAttr('toggle', 'tooltip')->setDataAttr('container', '#section-content .content')->setHref($url)->build();
    $actionsTpl .= '{{? !!it.___details_allowed }}' . $btn . '{{?}}';
}
if ($dataGridConfig->isEditAllowed()) {
    $url = $dblClickUrl = route('cmf_item_edit_form', [$tableNameForRoutes, ":{$pkName}:"], false);
    $btn = \Swayok\Html\Tag::a()->setClass('row-action text-green item-edit')->setContent('<i class="glyphicon glyphicon-edit"></i>')->setTitle(\PeskyCMF\Config\CmfConfig::transBase('.datagrid.actions.edit_item'))->setDataAttr('toggle', 'tooltip')->setDataAttr('container', '#section-content .content')->setHref($url)->build();
    $actionsTpl .= '{{? !!it.___edit_allowed }}' . $btn . '{{?}}';
}
if ($dataGridConfig->isDeleteAllowed()) {
    $btn = \Swayok\Html\Tag::a()->setContent('<i class="glyphicon glyphicon-trash"></i>')->setClass('row-action text-red item-delete')->setTitle(\PeskyCMF\Config\CmfConfig::transBase('.datagrid.actions.delete_item'))->setDataAttr('toggle', 'tooltip')->setDataAttr('container', '#section-content .content')->setDataAttr('block-datagrid', '1')->setDataAttr('action', 'request')->setDataAttr('method', 'delete')->setDataAttr('url', route('cmf_api_delete_item', [$tableNameForRoutes, ":{$pkName}:"], false))->setDataAttr('confirm', \PeskyCMF\Config\CmfConfig::transBase('.action.delete.please_confirm'))->setHref('javascript: void(0)')->build();
    $actionsTpl .= '{{? !!it.___delete_allowed }}' . $btn . '{{?}}';
}
$customRowActions = $dataGridConfig->getRowActions();
if (!empty($customRowActions)) {
    foreach ($customRowActions as $rowAction) {
        $actionsTpl .= $rowAction;
    }
}
$actionsTpl = '<div class="row-actions text-nowrap">' . preg_replace('%:([a-zA-Z0-9_]+):%is', '{{= it.$1 }}', $actionsTpl) . '</div>';
?>

    <script type="application/javascript">
        (function() {
            <?php 
$dataTablesConfig = array_replace(\PeskyCMF\Config\CmfConfig::getInstance()->data_tables_config(), $dataGridConfig->getAdditionalDataTablesConfig(), ['processing' => true, 'serverSide' => true, 'ajax' => route('cmf_api_get_items', ['model' => $tableNameForRoutes], false), 'pageLength' => $dataGridConfig->getLimit(), 'toolbarItems' => array_values($toolbar), 'order' => []]);
Exemplo n.º 9
0
 public function buildLinkToExternalRecord(DbColumnConfig $columnConfig, array $record, $linkLabel = null)
 {
     if (empty($record[$columnConfig->getName()])) {
         return '-';
     }
     $relationConfig = null;
     $relationAlias = null;
     foreach ($columnConfig->getRelations() as $alias => $relation) {
         if (in_array($relation->getType(), [DbRelationConfig::BELONGS_TO, DbRelationConfig::HAS_ONE])) {
             $relationConfig = $relation;
             $relationAlias = $alias;
             break;
         }
     }
     if (empty($relation)) {
         throw new ScaffoldFieldException($this, "Column [{$columnConfig->getName()}] has no fitting relation");
     }
     if (empty($record[$relationAlias]) || empty($record[$relationAlias][$relationConfig->getDisplayField()])) {
         return CmfConfig::transBase('.item_details.field.no_relation');
     } else {
         return Tag::a(empty($linkLabel) ? $record[$relationAlias][$relationConfig->getDisplayField()] : $linkLabel)->setHref(route('cmf_item_details', [$relationConfig->getForeignTable(), $record[$columnConfig->getName()]]))->build();
     }
 }
Exemplo n.º 10
0
 /**
  * @return string
  */
 public function buildCloseTag()
 {
     return $this->buildSecurity() . parent::buildCloseTag();
 }
Exemplo n.º 11
0
 /**
  * @return string
  */
 public function buildCloseTag()
 {
     $error = $this->form->getError($this->name);
     if (!empty($error)) {
         $error = $this->div()->setClass('error-text')->setContent($error);
     }
     return parent::buildCloseTag() . $error;
 }