Port templates to Twig

- Port export templates to Twig
- Port javascript/display template to Twig
- Port list templates to Twig

Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
This commit is contained in:
Maurício Meneghini Fauth 2017-06-28 23:03:45 -03:00
parent 3048161603
commit 4c92fd5827
10 changed files with 95 additions and 139 deletions

View File

@ -1,54 +0,0 @@
<table>
<thead>
<tr>
<th colspan="4"><?= __('Define new aliases') ?></th>
</tr>
</thead>
<tr>
<td>
<label><?= __('Select database:') ?></label>
</td>
<td>
<select id="db_alias_select"><option value=""></option></select>
</td>
<td>
<input id="db_alias_name" placeholder="<?= __('New database name') ?>" disabled="1" />
</td>
<td>
<button id="db_alias_button" class="ui-button ui-corner-all ui-widget" disabled="1"><?= __('Add') ?></button>
</td>
</tr>
<tr>
<td>
<label><?= __('Select table:') ?></label>
</td>
<td>
<select id="table_alias_select"><option value=""></option></select>
</td>
<td>
<input id="table_alias_name" placeholder="<?= __('New table name') ?>" disabled="1" />
</td>
<td>
<button id="table_alias_button" class="ui-button ui-corner-all ui-widget" disabled="1"><?= __('Add') ?></button>
</td>
</tr>
<tr>
<td>
<label><?= __('Select column:') ?></label>
</td>
<td>
<select id="column_alias_select"><option value=""></option></select>
</td>
<td>
<input id="column_alias_name" placeholder="<?= __('New column name') ?>" disabled="1" />
</td>
<td>
<button id="column_alias_button" class="ui-button ui-corner-all ui-widget" disabled="1"><?= __('Add') ?></button>
</td>
</tr>
</table>

View File

@ -0,0 +1,49 @@
<table>
<thead>
<tr>
<th colspan="4">{% trans 'Define new aliases' %}</th>
</tr>
</thead>
<tr>
<td>
<label>{% trans 'Select database:' %}</label>
</td>
<td>
<select id="db_alias_select"><option value=""></option></select>
</td>
<td>
<input id="db_alias_name" placeholder="{% trans 'New database name' %}" disabled="1" />
</td>
<td>
<button id="db_alias_button" class="ui-button ui-corner-all ui-widget" disabled="1">{% trans 'Add' %}</button>
</td>
</tr>
<tr>
<td>
<label>{% trans 'Select table:' %}</label>
</td>
<td>
<select id="table_alias_select"><option value=""></option></select>
</td>
<td>
<input id="table_alias_name" placeholder="{% trans 'New table name' %}" disabled="1" />
</td>
<td>
<button id="table_alias_button" class="ui-button ui-corner-all ui-widget" disabled="1">{% trans 'Add' %}</button>
</td>
</tr>
<tr>
<td>
<label>{% trans 'Select column:' %}</label>
</td>
<td>
<select id="column_alias_select"><option value=""></option></select>
</td>
<td>
<input id="column_alias_name" placeholder="{% trans 'New column name' %}" disabled="1" />
</td>
<td>
<button id="column_alias_button" class="ui-button ui-corner-all ui-widget" disabled="1">{% trans 'Add' %}</button>
</td>
</tr>
</table>

View File

@ -1,10 +0,0 @@
<tr>
<th><?= htmlspecialchars($type) ?></th>
<td><?= htmlspecialchars($name) ?></td>
<td>
<input name="<?= htmlspecialchars($field) ?>" value="<?= htmlspecialchars($value) ?>" type="text" />
</td>
<td>
<button class="alias_remove ui-button ui-corner-all ui-widget"><?= __('Remove') ?></button>
</td>
</tr>

View File

@ -0,0 +1,10 @@
<tr>
<th>{{ type }}</th>
<td>{{ name }}</td>
<td>
<input name="{{ field }}" value="{{ value }}" type="text" />
</td>
<td>
<button class="alias_remove ui-button ui-corner-all ui-widget">{% trans 'Remove' %}</button>
</td>
</tr>

View File

@ -1,7 +1,7 @@
<script type="text/javascript">
if (typeof configInlineParams === "undefined" || !Array.isArray(configInlineParams)) configInlineParams = [];
configInlineParams.push(function() {
<?= implode(";\n", $js_array); ?>;
{{ js_array|join(';\n')|raw }};
});
if (typeof configScriptLoaded !== "undefined" && configInlineParams) loadInlineConfig();
</script>
</script>

View File

@ -1,45 +0,0 @@
<?php
/**
* Display item of a list.
*
* $content - mandatory string - Content to display
* $id - optional string - Contains the id of li tag
* $class - optional string - Contains the class name(s) of li tag
* $mysql_help_page - optional string - Related help page
* $url - optional array: - href - optional string - Destination page or anchor
* - target - optional string - Target of link
* - class - optional string - Class of link
* - title - optional string - Title of link
*/
?>
<li <?= !empty($id) ? ' id="' . $id . '"' : null ?>
<?= !empty($class) ? ' class="' . $class . '"' : null ?>>
<?php if (isset($url) && is_array($url) && array_filter($url)) : ?>
<a<?= !empty($url['href']) ? ' href="' . $url['href'] . '"' : null ?>
<?= !empty($url['target'])
? ' target="' . $url['target'] . '"'
: null;
?>
<?= !empty($url['target']) && $url['target'] == '_blank'
? ' rel="noopener noreferrer"'
: null;
?>
<?= !empty($url['id']) ? ' id="' . $url['id'] . '"' : null; ?>
<?= !empty($url['class'])
? ' class="' . $url['class'] . '"'
: null;
?>
<?= !empty($url['title'])
? ' title="' . $url['title'] . '"'
: null;
?>>
<?php endif; ?>
<?= $content ?>
<?php if (isset($url) && is_array($url) && array_filter($url)) : ?>
</a>
<?php endif; ?>
<?php if (!empty($mysql_help_page)): ?>
<?= PMA\libraries\Util::showMySQLDocu($mysql_help_page) ?>
<?php endif; ?>
</li>

19
templates/list/item.twig Normal file
View File

@ -0,0 +1,19 @@
<li{% if id is not empty %} id="{{ id }}"{% endif -%}
{%- if class is not empty %} class="{{ class }}"{% endif %}>
{% if url is defined and url is iterable %}
<a{% if url['href'] is not empty %} href="{{ url['href'] }}"{% endif -%}
{%- if url['target'] is not empty %} target="{{ url['target'] }}"{% endif -%}
{%- if url['target'] is not empty and url['target'] == '_blank' %} rel="noopener noreferrer"{% endif -%}
{%- if url['id'] is not empty %} id="{{ url['id'] }}"{% endif -%}
{%- if url['class'] is not empty %} class="{{ url['class'] }}"{% endif -%}
{%- if url['title'] is not empty %} title="{{ url['title'] }}"{% endif %}>
{% endif %}
{{ content|raw }}
{% if url is defined and url is iterable %}
</a>
{% endif %}
{% if mysql_help_page is not empty %}
{{ Util_showMySQLDocu(mysql_help_page) }}
{% endif %}
</li>

View File

@ -1,27 +0,0 @@
<?php
/**
* Display unordered list.
*
* $class - optional string - Contains the class name(s) of ul tag
* $id - optional string - Contains the id of ul tag
* $item - mandatory string|array - If string, this is the content
* - Else, see templates/list/item.phtml
* $content - mandatory string - Content to display if $item is empty
*/
?>
<ul<?= !empty($class) ? ' class="' . $class . '"' : null ?>
<?= !empty($id) ? ' id="' . $id . '"' : null ?>>
<?php if (!empty($items)): ?>
<?php foreach ($items as $item): ?>
<?php if (!is_array($item)): ?>
<?php $item = array('content' => $item) ?>
<?php endif; ?>
<?= PMA\libraries\Template::get('list/item')
->render($item)
?>
<?php endforeach; ?>
<?php elseif (!empty($content)): ?>
<?= $content ?>
<?php endif; ?>
</ul>

View File

@ -0,0 +1,14 @@
<ul{% if id is not empty %} id="{{ id }}"{% endif -%}
{%- if class is not empty %} class="{{ class }}"{% endif %}>
{% if items is not empty %}
{% for item in items %}
{% if item is not iterable %}
{% set item = {'content': item} %}
{% endif %}
{% include 'list/item.twig' with item only %}
{% endfor %}
{% elseif content is not empty %}
{{ content|raw }}
{% endif %}
</ul>

View File

@ -550,7 +550,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
. '});' . "\n"
. 'if (typeof configScriptLoaded !== "undefined"'
. ' && configInlineParams) loadInlineConfig();'
. "\n" . '</script>',
. "\n" . '</script>'. "\n",
$result
);
}