Merge pull request #13458 from udan11/view_create_tpl

Refactored view_create to use Twig templates.
This commit is contained in:
Michal Čihař 2017-07-10 12:12:56 +03:00 committed by GitHub
commit 7f7af4c646
5 changed files with 136 additions and 123 deletions

View File

@ -24,6 +24,7 @@ phpMyAdmin - ChangeLog
- issue #13095 Fixed alignmnet of foreign keys editing
- issue #12944 Improved inline editor for JSON
- issue #13145 Improved layout of operations pages
- issue #13448 Add "format" query button in edit view form
4.7.3 (not yet released)
- issue #13447 Large multi-line query removes Export operation and blanks query box options

View File

@ -4721,21 +4721,21 @@ AJAX.registerOnload('functions.js', function () {
}); // end $(document).on()
}
syntaxHighlighter = PMA_getSQLEditor($('textarea[name="view[as]"]'));
codemirror_editor = PMA_getSQLEditor($('textarea[name="view[as]"]'));
});
function PMA_createViewDialog($this)
{
var $msg = PMA_ajaxShowMessage();
var syntaxHighlighter = null;
var codemirror_editor = null;
$.get($this.attr('href') + '&ajax_request=1&ajax_dialog=1', function (data) {
if (typeof data !== 'undefined' && data.success === true) {
PMA_ajaxRemoveMessage($msg);
var buttonOptions = {};
buttonOptions[PMA_messages.strGo] = function () {
if (typeof CodeMirror !== 'undefined') {
syntaxHighlighter.save();
codemirror_editor.save();
}
$msg = PMA_ajaxShowMessage();
$.post('view_create.php', $('#createViewDialog').find('form').serialize(), function (data) {
@ -4763,7 +4763,7 @@ function PMA_createViewDialog($this)
}
});
// Attach syntax highlighted editor
syntaxHighlighter = PMA_getSQLEditor($dialog.find('textarea'));
codemirror_editor = PMA_getSQLEditor($dialog.find('textarea'));
$('input:visible[type=text]', $dialog).first().focus();
} else {
PMA_ajaxShowMessage(data.error);

123
templates/view_create.twig Normal file
View File

@ -0,0 +1,123 @@
<!-- CREATE VIEW options -->
<div id="div_view_options">
<form method="post" action="view_create.php">
{{ URL_getHiddenInputs(url_params) }}
<fieldset>
<legend>
{% if ajax_dialog %}
{% trans 'Details' %}
{% else %}
{% if view['operation'] == 'create' %}
{% trans 'Create view' %}
{% else %}
{% trans 'Edit view' %}
{% endif %}
{% endif %}
</legend>
<table class="rte_table">
{% if view['operation'] == 'create' %}
<tr>
<td class="nowrap"><label for="or_replace">OR REPLACE</label></td>
<td>
<input type="checkbox" name="view[or_replace]" id="or_replace"
{% if (view['or_replace']) %} checked="checked" {% endif %}
value="1" />
</td>
</tr>
{% endif %}
<tr>
<td class="nowrap"><label for="algorithm">ALGORITHM</label></td>
<td>
<select name="view[algorithm]" id="algorithm">
{% for option in view_algorithm_options %}
<option value="{{ option }}"
{% if view['algorithm'] == option %}
selected="selected"
{% endif %}
>{{ option }}</option>
{% endfor %}
</select>
</td>
</tr>
<tr>
<td class="nowrap">{% trans 'Definer' %}</td>
<td><input type="text" maxlength="100" size="50" name="view[definer]" value="{{ view['definer'] }}" /></td>
</tr>
<tr>
<td class="nowrap">SQL SECURITY</td>
<td>
<select name="view[sql_security]">
<option value=""></option>
{% for option in view_security_options %}
<option value="{{ option }}"
{% if option == view['sql_security'] %} selected="selected" {% endif %}
>{{ option }}</option>
{% endfor %}
</select>
</td>
</tr>
{% if view['operation'] == 'create' %}
<tr>
<td class="nowrap">{% trans 'VIEW name' %}</td>
<td>
<input type="text" size="20" name="view[name]" onfocus="this.select()" maxlength="64" value="{{ view['name'] }}" />
</td>
</tr>
{% else %}
<tr>
<td>
<input type="hidden" name="view[name]" value="{{ view['name'] }}" />
</td>
</tr>
{% endif %}
<tr>
<td class="nowrap">{% trans 'Column names' %}</td>
<td>
<input type="text" maxlength="100" size="50" name="view[column_names]" onfocus="this.select()" value="{{ view['column_names'] }}" />
</td>
</tr>
<tr>
<td class="nowrap">AS</td>
<td>
<textarea name="view[as]" rows="15" cols="40" dir="{{ text_dir }}" onclick="selectContent(this, sql_box_locked, true)">{{ view['as'] }}</textarea><br/>
<input type="button" value="Format" id="format" class="button sqlbutton">
<span id="querymessage"></span>
</td>
</tr>
<tr>
<td class="nowrap">WITH CHECK OPTION</td>
<td>
<select name="view[with]">
<option value=""></option>
{% for option in view_with_options %}
<option value="{{ option }}"
{% if option == view['with'] %} selected="selected" {% endif %}
>{{ option }}</option>
{% endfor %}
</select>
</td>
</tr>
</table>
</fieldset>
{% if ajax_dialog %}
<fieldset class="tblFooters">
<input type="hidden" name="{{ (view['operation'] == 'create') ? 'createview' : 'alterview' }}" value="1" />
<input type="submit" name="" value="{% trans 'Go' %}" />
</fieldset>
{% else %}
<input type="hidden" name="{{ (view['operation'] == 'create') ? 'createview' : 'alterview' }}" value="1" />
<input type="hidden" name="ajax_dialog" value="1" />
<input type="hidden" name="ajax_request" value="1" />
{% endif %}
</form>
</div>

View File

@ -38,6 +38,7 @@ if (! defined('PMA_MINIMUM_COMMON') && ! defined('TESTSUITE')) {
-webkit-box-sizing: border-box;
}
.rte_table input[type=button],
.rte_table input[type=checkbox],
.rte_table input[type=radio] {
width: auto;

View File

@ -11,6 +11,7 @@
use PhpMyAdmin\Core;
use PhpMyAdmin\Url;
use PhpMyAdmin\Response;
use PhpMyAdmin\Template;
require_once './libraries/common.inc.php';
@ -194,122 +195,9 @@ if (Core::isValid($_REQUEST['view'], 'array')) {
$url_params['db'] = $GLOBALS['db'];
$url_params['reload'] = 1;
/**
* Displays the page
*/
$htmlString = '<!-- CREATE VIEW options -->'
. '<div id="div_view_options">'
. '<form method="post" action="view_create.php">'
. Url::getHiddenInputs($url_params)
. '<fieldset>'
. '<legend>'
. (isset($_REQUEST['ajax_dialog']) ?
__('Details') :
($view['operation'] == 'create' ? __('Create view') : __('Edit view'))
)
. '</legend>'
. '<table class="rte_table">';
if ($view['operation'] == 'create') {
$htmlString .= '<tr>'
. '<td class="nowrap"><label for="or_replace">OR REPLACE</label></td>'
. '<td><input type="checkbox" name="view[or_replace]" id="or_replace"';
if ($view['or_replace']) {
$htmlString .= ' checked="checked"';
}
$htmlString .= ' value="1" /></td></tr>';
}
$htmlString .= '<tr>'
. '<td class="nowrap"><label for="algorithm">ALGORITHM</label></td>'
. '<td><select name="view[algorithm]" id="algorithm">';
foreach ($view_algorithm_options as $option) {
$htmlString .= '<option value="' . htmlspecialchars($option) . '"';
if ($view['algorithm'] === $option) {
$htmlString .= ' selected="selected"';
}
$htmlString .= '>' . htmlspecialchars($option) . '</option>';
}
$htmlString .= '</select>'
. '</td></tr>';
$htmlString .= '<tr><td class="nowrap">' . __('Definer') . '</td>'
. '<td><input type="text" maxlength="100" size="50" name="view[definer]"'
. ' value="' . htmlspecialchars($view['definer']) . '" />'
. '</td></tr>';
$htmlString .= '<tr><td class="nowrap">SQL SECURITY</td>'
. '<td><select name="view[sql_security]">'
. '<option value=""></option>';
foreach ($view_security_options as $option) {
$htmlString .= '<option value="' . htmlspecialchars($option) . '"';
if ($option == $view['sql_security']) {
$htmlString .= ' selected="selected"';
}
$htmlString .= '>' . htmlspecialchars($option) . '</option>';
}
$htmlString .= '<select>'
. '</td></tr>';
if ($view['operation'] == 'create') {
$htmlString .= '<tr><td class="nowrap">' . __('VIEW name') . '</td>'
. '<td><input type="text" size="20" name="view[name]"'
. ' onfocus="this.select()" maxlength="64"'
. ' value="' . htmlspecialchars($view['name']) . '" />'
. '</td></tr>';
} else {
$htmlString .= '<tr><td><input type="hidden" name="view[name]"'
. ' value="' . htmlspecialchars($view['name']) . '" />'
. '</td></tr>';
}
$htmlString .= '<tr><td class="nowrap">' . __('Column names') . '</td>'
. '<td><input type="text" maxlength="100" size="50" name="view[column_names]"'
. ' onfocus="this.select()"'
. ' value="' . htmlspecialchars($view['column_names']) . '" />'
. '</td></tr>';
$htmlString .= '<tr><td class="nowrap">AS</td>'
. '<td>'
. '<textarea name="view[as]" rows="15" cols="40" dir="' . $text_dir . '"';
if ($GLOBALS['cfg']['TextareaAutoSelect'] || true) {
$htmlString .= ' onclick="selectContent(this, sql_box_locked, true)"';
}
$htmlString .= '>' . htmlspecialchars($view['as']) . '</textarea>'
. '</td></tr>';
$htmlString .= '<tr><td class="nowrap">WITH CHECK OPTION</td>'
. '<td><select name="view[with]">'
. '<option value=""></option>';
foreach ($view_with_options as $option) {
$htmlString .= '<option value="' . htmlspecialchars($option) . '"';
if ($option == $view['with']) {
$htmlString .= ' selected="selected"';
}
$htmlString .= '>' . htmlspecialchars($option) . '</option>';
}
$htmlString .= '<select>'
. '</td></tr>';
$htmlString .= '</table>'
. '</fieldset>';
if (! isset($_REQUEST['ajax_dialog'])) {
$htmlString .= '<fieldset class="tblFooters">'
. '<input type="hidden" name="'
. ($view['operation'] == 'create' ? 'createview' : 'alterview' )
. '" value="1" />'
. '<input type="submit" name="" value="' . __('Go') . '" />'
. '</fieldset>';
} else {
$htmlString .= '<input type="hidden" name="'
. ($view['operation'] == 'create' ? 'createview' : 'alterview' )
. '" value="1" />'
. '<input type="hidden" name="ajax_dialog" value="1" />'
. '<input type="hidden" name="ajax_request" value="1" />';
}
$htmlString .= '</form>'
. '</div>';
echo $htmlString;
echo Template::get('view_create')->render([
'ajax_dialog' => isset($_REQUEST['ajax_dialog']),
'text_dir' => $text_dir,
'url_params' => $url_params,
'view' => $view,
]);