Commit f96a0ad4 authored by Tino Goratsch's avatar Tino Goratsch

refactored the admin create and edit templates of the files module

parent 5416c978
......@@ -84,12 +84,12 @@ abstract class AbstractFormAction extends AbstractAdminAction
/**
* @param array $formData
* @param array $settings
*
* @return int
*/
protected function useComments(array $formData, array $settings)
protected function useComments(array $formData)
{
$settings = $this->config->getSettings(Files\Installer\Schema::MODULE_NAME);
return $settings['comments'] == 1 && isset($formData['comments']) ? 1 : 0;
}
......@@ -125,12 +125,13 @@ abstract class AbstractFormAction extends AbstractAdminAction
}
/**
* @param array $settings
* @param array $file
* @return array
*/
protected function getOptions(array $settings, array $file)
protected function getOptions(array $file)
{
$settings = $this->config->getSettings(Files\Installer\Schema::MODULE_NAME);
$options = [];
if ($settings['comments'] == 1 && $this->modules->isActive('comments') === true) {
$comments = [
......
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers. See the LICENCE file at the top-level module directory for licencing details.
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Modules\ACP3\Files\Controller\Admin\Index;
......@@ -54,8 +55,8 @@ class Create extends AbstractFormAction
Core\Helpers\FormToken $formTokenHelper,
Files\Model\FilesModel $filesModel,
Files\Validation\AdminFormValidation $adminFormValidation,
Categories\Helpers $categoriesHelpers)
{
Categories\Helpers $categoriesHelpers
) {
parent::__construct($context, $formsHelper, $categoriesHelpers);
$this->date = $date;
......@@ -69,10 +70,8 @@ class Create extends AbstractFormAction
*/
public function execute()
{
$settings = $this->config->getSettings(Files\Installer\Schema::MODULE_NAME);
if ($this->request->getPost()->count() !== 0) {
return $this->executePost($this->request->getPost()->all(), $settings);
return $this->executePost($this->request->getPost()->all());
}
$defaults = [
......@@ -85,11 +84,15 @@ class Create extends AbstractFormAction
'end' => ''
];
$external = [
1 => $this->translator->t('files', 'external_resource')
];
return [
'options' => $this->getOptions($settings, ['comments' => '0']),
'options' => $this->getOptions(['comments' => '0']),
'units' => $this->formsHelper->choicesGenerator('units', $this->getUnits(), ''),
'categories' => $this->categoriesHelpers->categoriesList(Files\Installer\Schema::MODULE_NAME, '', true),
'checked_external' => $this->request->getPost()->has('external') ? ' checked="checked"' : '',
'external' => $this->formsHelper->checkboxGenerator('external', $external),
'SEO_FORM_FIELDS' => $this->metaFormFieldsHelper ? $this->metaFormFieldsHelper->formFields() : [],
'form' => array_merge($defaults, $this->request->getPost()->all()),
'form_token' => $this->formTokenHelper->renderFormToken()
......@@ -98,13 +101,11 @@ class Create extends AbstractFormAction
/**
* @param array $formData
* @param array $settings
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
protected function executePost(array $formData, array $settings)
protected function executePost(array $formData)
{
return $this->actionHelper->handleCreatePostAction(function () use ($formData, $settings) {
return $this->actionHelper->handleCreatePostAction(function () use ($formData) {
if (isset($formData['external'])) {
$file = $formData['file_external'];
} else {
......@@ -126,7 +127,7 @@ class Create extends AbstractFormAction
}
$formData['cat'] = $this->fetchCategoryId($formData);
$formData['comments'] = $this->useComments($formData, $settings);
$formData['comments'] = $this->useComments($formData);
$lastId = $this->filesModel->saveFile($formData, $this->user->getUserId());
......
......@@ -78,18 +78,21 @@ class Edit extends AbstractFormAction
$file = $this->filesModel->getOneById($id);
if (empty($file) === false) {
$settings = $this->config->getSettings(Files\Installer\Schema::MODULE_NAME);
$this->title->setPageTitlePostfix($file['title']);
if ($this->request->getPost()->count() !== 0) {
return $this->executePost($this->request->getPost()->all(), $settings, $file, $id);
return $this->executePost($this->request->getPost()->all(), $file, $id);
}
$file['filesize'] = substr($file['size'], 0, strpos($file['size'], ' '));
$file['file_external'] = '';
$external = [
1 => $this->translator->t('files', 'external_resource')
];
return [
'options' => $this->getOptions($settings, $file),
'options' => $this->getOptions($file),
'units' => $this->formsHelper->choicesGenerator('units', $this->getUnits(),
trim(strrchr($file['size'], ' '))),
'categories' => $this->categoriesHelpers->categoriesList(
......@@ -97,7 +100,7 @@ class Edit extends AbstractFormAction
$file['category_id'],
true
),
'checked_external' => $this->request->getPost()->has('external') ? ' checked="checked"' : '',
'external' => $this->formsHelper->checkboxGenerator('external', $external),
'current_file' => $file['file'],
'SEO_FORM_FIELDS' => $this->metaFormFieldsHelper
? $this->metaFormFieldsHelper->formFields(sprintf(Files\Helpers::URL_KEY_PATTERN, $id))
......@@ -112,15 +115,13 @@ class Edit extends AbstractFormAction
/**
* @param array $formData
* @param array $settings
* @param array $dl
* @param int $fileId
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
protected function executePost(array $formData, array $settings, array $dl, $fileId)
protected function executePost(array $formData, array $dl, $fileId)
{
return $this->actionHelper->handleEditPostAction(function () use ($formData, $settings, $dl, $fileId) {
return $this->actionHelper->handleEditPostAction(function () use ($formData, $dl, $fileId) {
$file = null;
if (isset($formData['external'])) {
$file = $formData['file_external'];
......@@ -134,7 +135,7 @@ class Edit extends AbstractFormAction
->validate($formData);
$formData['cat'] = $this->fetchCategoryId($formData);
$formData['comments'] = $this->useComments($formData, $settings);
$formData['comments'] = $this->useComments($formData);
if (!empty($file)) {
$newFileSql = $this->updateAssociatedFile($file, $formData, $dl['file']);
......
$(document).ready(function () {
if ($('#external').is(':checked')) {
$('#file-external').show();
$('#external-filesize').show();
$('#file-internal').hide();
} else {
$('#file-external').hide();
$('#external-filesize').hide();
$('#file-internal').show();
}
$('#external').click(function () {
$('#file-external').toggle();
$('#external-filesize').toggle();
$('#file-internal').toggle();
});
});
\ No newline at end of file
jQuery(document).ready(function ($) {
$(':checkbox[name="external"]')
.on('click change', function () {
$('#file-external-toggle').toggle($(this).is(':checked'));
$('#file-internal-toggle').toggle(!$(this).is(':checked'));
})
.triggerHandler('click');
});
......@@ -15,41 +15,34 @@
</div>
<div id="tab-2" class="tab-pane fade">
{include file="asset:System/Partials/form_group.input_text.tpl" name="title" value=$form.title required=true maxlength=120 data_attributes=['seo-slug-base' => 'true'] label={lang t="files|title"}}
{block FILES_FILE_UPLOAD}
<div id="file-internal-toggle">
{block FILES_FILE_UPLOAD}
{include file="asset:System/Partials/form_group.input_file.tpl" name="file_internal" labelRequired=true label={lang t="files|file"}}
{/block}
</div>
<div id="file-external-toggle">
{include file="asset:System/Partials/form_group.input_url.tpl" name="file_external" value=$form.file_external labelRequired=true maxlength=120 label={lang t="files|uri"}}
<div class="form-group">
<label for="file-internal" class="col-sm-2 control-label required">{lang t="files|file"}</label>
<div class="col-sm-10">
<div class="checkbox">
<label for="external">
<input type="checkbox" name="external" id="external" value="1"{$checked_external}>
{lang t="files|external_resource"}
</label>
</div>
<input type="file" name="file_internal" id="file-internal">
<input class="form-control" type="url" name="file_external" id="file-external" value="{$form.file_external}" maxlength="120">
</div>
</div>
{/block}
<div id="external-filesize" class="form-group">
<label for="filesize" class="col-sm-2 control-label required">{lang t="files|filesize"}</label>
<label for="filesize" class="col-sm-2 control-label required">{lang t="files|filesize"}</label>
<div class="col-sm-4">
<div class="row">
<div class="col-sm-8">
<input class="form-control" type="text" name="filesize" id="filesize" value="{$form.filesize}" maxlength="15">
</div>
<div class="col-sm-4">
<label for="unit" class="sr-only">{lang t="files|unit"}</label>
<select class="form-control" name="unit" id="unit">
{foreach $units as $row}
<option value="{$row.value}"{$row.selected}>{$row.value}</option>
{/foreach}
</select>
<div class="col-sm-4">
<div class="row">
<div class="col-sm-8">
<input class="form-control" type="text" name="filesize" id="filesize" value="{$form.filesize}" maxlength="15">
</div>
<div class="col-sm-4">
<label for="unit" class="sr-only">{lang t="files|unit"}</label>
<select class="form-control" name="unit" id="unit">
{foreach $units as $row}
<option value="{$row.value}"{$row.selected}>{$row.value}</option>
{/foreach}
</select>
</div>
</div>
</div>
</div>
</div>
{include file="asset:System/Partials/form_group.checkbox.tpl" options=$external}
{include file="asset:System/Partials/form_group.wysiwyg.tpl" name="text" value=$form.text required=true toolbar="simple" label={lang t="system|description"}}
<div class="form-group">
<label for="cat" class="col-sm-2 control-label required">{lang t="categories|category"}</label>
......@@ -69,6 +62,6 @@
</div>
{include file="asset:System/Partials/form_group.submit.tpl" form_token=$form_token back_url={uri args="acp/files"}}
{javascripts}
{include_js module="files" file="admin/acp"}
{include_js module="files" file="admin/index.create"}
{/javascripts}
{/block}
{extends file="asset:Files/Admin/index.create.tpl"}
{block FILES_FILE_UPLOAD}
<div class="form-group">
<label class="col-sm-2 control-label">{lang t="files|current_file"}</label>
<div class="col-sm-10">
<div class="form-control-static">{$current_file}</div>
</div>
</div>
<div class="form-group">
<label for="file-internal" class="col-sm-2 control-label">{lang t="files|new_file"}</label>
<div class="col-sm-10">
<div class="checkbox">
<label for="external">
<input type="checkbox" name="external" id="external" value="1"{$checked_external}>
{lang t="files|external_resource"}
</label>
</div>
<input type="file" name="file_internal" id="file-internal">
<input class="form-control" type="url" name="file_external" id="file-external" value="" maxlength="120">
</div>
</div>
{include file="asset:System/Partials/form_group.static.tpl" value=$current_file label={lang t="files|current_file"}}
{include file="asset:System/Partials/form_group.input_file.tpl" name="file_internal" labelRequired=true label={lang t="files|new_file"}}
{/block}
......@@ -31,5 +31,6 @@
<item key="type_in_title">Der Titel darf nicht leer sein.</item>
<item key="unit">Einheit</item>
<item key="unknown_filesize">Dateigröße unbekannt</item>
<item key="uri">URI</item>
</keys>
</language>
......@@ -31,5 +31,6 @@
<item key="type_in_title">The title should not be empty.</item>
<item key="unit">Unit</item>
<item key="unknown_filesize">Unknown filesize</item>
<item key="uri">URI</item>
</keys>
</language>
......@@ -5,7 +5,7 @@
{$label=(!empty($label)) ? $label : {lang t="system|publication_period"}}
{/if}
{block FORM_GROUP_LABEL_ID}{$datepicker.id_start}-input{/block}
{block FORM_GROUP_LABEL_ID}for="{$datepicker.id_start}-input"{/block}
{block FORM_GROUP_FORM_FIELD}
<div class="row" data-datepicker-range='{$datepicker.range_json}'>
<div class="col-sm-6">
......
......@@ -4,7 +4,7 @@
{$label=(!empty($label)) ? $label : {lang t="system|date"}}
{/if}
{block FORM_GROUP_LABEL_ID}{$datepicker.id}-input{/block}
{block FORM_GROUP_LABEL_ID}for="{$datepicker.id}-input"{/block}
{block FORM_GROUP_FORM_FIELD}
<div class="input-group date"
id="{$datepicker.id}"
......
<div class="form-group">
{if !empty($label)}
<label for="{block FORM_GROUP_LABEL_ID}{$options.0.id}{/block}"
class="col-sm-2 control-label{if (isset($required) && $required === true) || (isset($labelRequired) && $labelRequired === true)} required{/if}">
<label class="col-sm-2 control-label{if (isset($required) && $required === true) || (isset($labelRequired) && $labelRequired === true)} required{/if}"
{block FORM_GROUP_LABEL_ID}for="{$options.0.id}"{/block}>
{$label}
</label>
{/if}
......
{extends file="asset:System/Partials/form_group.base.tpl"}
{block FORM_GROUP_LABEL_ID}{$name|replace:'_':'-'}{/block}
{block FORM_GROUP_LABEL_ID}for="{$name|replace:'_':'-'}"{/block}
{block FORM_GROUP_FORM_FIELD}
<input {if isset($use_form_control) && $use_form_control === false}{else}class="form-control"{/if}
type="{block FORM_GROUP_INPUT_TYPE}text{/block}"
name="{$name}"
id="{$name|replace:'_':'-'}"
value="{if !empty($value)}{$value}{/if}"
{if !empty($value)}value="{$value}"{/if}
{if !empty($maxlength)}maxlength="{$maxlength}"{/if}
{if !empty($data_attributes) && is_array($data_attributes)}
{foreach $data_attributes as $attrName => $attrValue}
......
{extends file="asset:System/Partials/form_group.base.tpl"}
{block FORM_GROUP_LABEL_ID}{/block}
{block FORM_GROUP_FORM_FIELD}
<div class="form-control-static">
{if !empty($value)}
{$value}
{/if}
</div>
{/block}
{extends file="asset:System/Partials/form_group.base.tpl"}
{block FORM_GROUP_LABEL_ID}{$name|replace:'_':'-'}{/block}
{block FORM_GROUP_LABEL_ID}for="{$name|replace:'_':'-'}"{/block}
{block FORM_GROUP_FORM_FIELD}
{if !empty($before_textarea)}
{$before_textarea}
......
{extends file="asset:System/Partials/form_group.base.tpl"}
{block FORM_GROUP_LABEL_ID}{$name|replace:'_':'-'}{/block}
{block FORM_GROUP_LABEL_ID}for="{$name|replace:'_':'-'}"{/block}
{block FORM_GROUP_FORM_FIELD}
{$toolbar=(!empty($toolbar)) ? $toolbar : ''}
{$advanced=(isset($advanced)) ? $advanced : false}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment