Templating getWithSelected() and getCheckbox(), Issue #12004
This commit is contained in:
Atul Pratap Singh 2016-02-25 04:21:24 +05:30
commit 0370f382c2
14 changed files with 323 additions and 225 deletions

View File

@ -1746,16 +1746,26 @@ class DisplayResults
}
$options_html .= '<div class="formelement">'
. Util::getCheckbox(
'display_binary', __('Show binary contents'),
! empty($_SESSION['tmpval']['display_binary']), false,
'display_binary_' . $this->__get('unique_id')
. Template::get('checkbox')
->render(
array(
'html_field_name' => 'display_binary',
'label' => __('Show binary contents'),
'checked' => ! empty($_SESSION['tmpval']['display_binary']),
'onclick' => false,
'html_field_id' => 'display_binary_' . $this->__get('unique_id'),
)
)
. '<br />'
. Util::getCheckbox(
'display_blob', __('Show BLOB contents'),
! empty($_SESSION['tmpval']['display_blob']), false,
'display_blob_' . $this->__get('unique_id')
. Template::get('checkbox')
->render(
array(
'html_field_name' => 'display_blob',
'label' => __('Show BLOB contents'),
'checked' => ! empty($_SESSION['tmpval']['display_blob']),
'onclick' => false,
'html_field_id' => 'display_blob_' . $this->__get('unique_id'),
)
)
. '</div>';
@ -1764,10 +1774,15 @@ class DisplayResults
// per SQL query, and at the same time have a default that displays
// the transformations.
$options_html .= '<div class="formelement">'
. Util::getCheckbox(
'hide_transformation', __('Hide browser transformation'),
! empty($_SESSION['tmpval']['hide_transformation']), false,
'hide_transformation_' . $this->__get('unique_id')
. Template::get('checkbox')
->render(
array(
'html_field_name' => 'hide_transformation',
'label' => __('Hide browser transformation'),
'checked' => ! empty($_SESSION['tmpval']['hide_transformation']),
'onclick' => false,
'html_field_id' => 'hide_transformation_' . $this->__get('unique_id'),
)
)
. '</div>';

View File

@ -16,6 +16,7 @@ use stdClass;
use SqlParser\Utils\Error as ParserError;
use PMA\libraries\URL;
use PMA\libraries\Sanitize;
use PMA\libraries\Template;
if (! defined('PHPMYADMIN')) {
exit;
@ -1318,12 +1319,16 @@ class Util
// be checked, which would reexecute an INSERT, for example
if (! empty($refresh_link) && self::profilingSupported()) {
$retval .= '<input type="hidden" name="profiling_form" value="1" />';
$retval .= self::getCheckbox(
'profiling',
__('Profiling'),
isset($_SESSION['profiling']),
true
);
$retval .= Template::get('checkbox')
->render(
array(
'html_field_name' => 'profiling',
'label' => __('Profiling'),
'checked' => isset($_SESSION['profiling']),
'onclick' => true,
'html_field_id' => '',
)
);
}
$retval .= '</form>';
@ -2730,28 +2735,6 @@ class Util
return $ext_but_html;
}
/**
* Returns a HTML checkbox
*
* @param string $html_field_name the checkbox HTML field
* @param string $label label for checkbox
* @param boolean $checked is it initially checked?
* @param boolean $onclick should it submit the form on click?
* @param string $html_field_id id for the checkbox
*
* @return string HTML for the checkbox
*/
public static function getCheckbox(
$html_field_name, $label, $checked, $onclick, $html_field_id = ''
) {
return '<input type="checkbox" name="' . $html_field_name . '"'
. ($html_field_id ? ' id="' . $html_field_id . '"' : '')
. ($checked ? ' checked="checked"' : '')
. ($onclick ? ' class="autosubmit"' : '') . ' />'
. '<label' . ($html_field_id ? ' for="' . $html_field_id . '"' : '')
. '>' . $label . '</label>';
}
/**
* Generates a set of radio HTML fields
*
@ -4590,31 +4573,6 @@ class Util
return array($primary, $pk_array, $indexes_info, $indexes_data);
}
/**
* Returns the HTML for check all check box and with selected text
* for multi submits
*
* @param string $pmaThemeImage path to theme's image folder
* @param string $text_dir text direction
* @param string $formName name of the enclosing form
*
* @return string HTML
*/
public static function getWithSelected($pmaThemeImage, $text_dir, $formName)
{
$html = '<img class="selectallarrow" '
. 'src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png" '
. 'width="38" height="22" alt="' . __('With selected:') . '" />';
$html .= '<input type="checkbox" id="' . $formName . '_checkall" '
. 'class="checkall_box" title="' . __('Check all') . '" />'
. '<label for="' . $formName . '_checkall">' . __('Check all')
. '</label>';
$html .= '<i style="margin-left: 2em">'
. __('With selected:') . '</i>';
return $html;
}
/**
* Function to get html for the start row and number of rows panel
*

View File

@ -1184,9 +1184,14 @@ function PMA_getCentralColumnsListRaw($db, $table)
*/
function PMA_getCentralColumnsTableFooter($pmaThemeImage, $text_dir)
{
$html_output = Util::getWithSelected(
$pmaThemeImage, $text_dir, "tableslistcontainer"
);
$html_output = PMA\libraries\Template::get('select_all')
->render(
array(
'pmaThemeImage' => $pmaThemeImage,
'text_dir' => $text_dir,
'formName' => 'tableslistcontainer',
)
);
$html_output .= Util::getButtonOrImage(
'edit_central_columns', 'mult_submit change_central_columns',
__('Edit'), 'b_edit.png', 'edit central columns'

View File

@ -378,9 +378,15 @@ class ServerDatabasesController extends Controller
return '';
}
$html = Util::getWithSelected(
$GLOBALS['pmaThemeImage'], $GLOBALS['text_dir'], "dbStatsForm"
);
$html = Template::get('select_all')
->render(
array(
'pmaThemeImage' => $GLOBALS['pmaThemeImage'],
'text_dir' => $GLOBALS['text_dir'],
'formName' => 'dbStatsForm',
)
);
$html .= Util::getButtonOrImage(
'',
'mult_submit' . ' ajax',

View File

@ -7,6 +7,7 @@
*/
use SqlParser\Statements\CreateStatement;
use PMA\libraries\URL;
use PMA\libraries\Template;
if (! defined('PHPMYADMIN')) {
@ -143,9 +144,14 @@ function PMA_RTE_getList($type, $items)
if (count($items)) {
$retval .= '<div class="withSelected">';
$retval .= PMA\libraries\Util::getWithSelected(
$GLOBALS['pmaThemeImage'], $GLOBALS['text_dir'], 'rteListForm'
);
$retval .= Template::get('select_all')
->render(
array(
'pmaThemeImage' => $GLOBALS['pmaThemeImage'],
'text_dir' => $GLOBALS['text_dir'],
'formName' => 'rteListForm',
)
);
$retval .= PMA\libraries\Util::getButtonOrImage(
'submit_mult', 'mult_submit',
__('Export'), 'b_export.png', 'export'

View File

@ -2306,30 +2306,40 @@ function PMA_getHtmlForAddUser($dbname)
$html_output .= '<fieldset id="fieldset_add_user_database">' . "\n"
. '<legend>' . __('Database for user account') . '</legend>' . "\n";
$html_output .= Util::getCheckbox(
'createdb-1',
__('Create database with same name and grant all privileges.'),
false, false, 'createdb-1'
);
$html_output .= Template::get('checkbox')
->render(
array(
'html_field_name' => 'createdb-1',
'label' => __('Create database with same name and grant all privileges.'),
'checked' => false,
'onclick' => false,
'html_field_id' => 'createdb-1',
)
);
$html_output .= '<br />' . "\n";
$html_output .= Util::getCheckbox(
'createdb-2',
__('Grant all privileges on wildcard name (username\\_%).'),
false, false, 'createdb-2'
);
$html_output .= Template::get('checkbox')
->render(
array(
'html_field_name' => 'createdb-2',
'label' => __('Grant all privileges on wildcard name (username\\_%).'),
'checked' => false,
'onclick' => false,
'html_field_id' => 'createdb-2',
)
);
$html_output .= '<br />' . "\n";
if (! empty($dbname) ) {
$html_output .= Util::getCheckbox(
'createdb-3',
sprintf(
__('Grant all privileges on database "%s".'),
htmlspecialchars($dbname)
),
true,
false,
'createdb-3'
);
$html_output .= Template::get('checkbox')
->render(
array(
'html_field_name' => 'createdb-3',
'label' => sprintf(__('Grant all privileges on database %s.'), htmlspecialchars($dbname)),
'checked' => true,
'onclick' => false,
'html_field_id' => 'createdb-3',
)
);
$html_output .= '<input type="hidden" name="dbname" value="'
. htmlspecialchars($dbname) . '" />' . "\n";
$html_output .= '<br />' . "\n";
@ -2506,9 +2516,14 @@ function PMA_getHtmlForSpecificDbPrivileges($db)
$html_output .= '</table>';
$html_output .= '<div class="floatleft">';
$html_output .= Util::getWithSelected(
$GLOBALS['pmaThemeImage'], $GLOBALS['text_dir'], "usersForm"
);
$html_output .= Template::get('select_all')
->render(
array(
'pmaThemeImage' => $GLOBALS['pmaThemeImage'],
'text_dir' => $GLOBALS['text_dir'],
'formName' => "usersForm",
)
);
$html_output .= Util::getButtonOrImage(
'submit_mult', 'mult_submit',
__('Export'), 'b_tblexport.png', 'export'
@ -2585,9 +2600,14 @@ function PMA_getHtmlForSpecificTablePrivileges($db, $table)
$html_output .= '</table>';
$html_output .= '<div class="floatleft">';
$html_output .= Util::getWithSelected(
$GLOBALS['pmaThemeImage'], $GLOBALS['text_dir'], "usersForm"
);
$html_output .= Template::get('select_all')
->render(
array(
'pmaThemeImage' => $GLOBALS['pmaThemeImage'],
'text_dir' => $GLOBALS['text_dir'],
'formName' => "usersForm",
)
);
$html_output .= Util::getButtonOrImage(
'submit_mult', 'mult_submit',
__('Export'), 'b_tblexport.png', 'export'
@ -3602,8 +3622,14 @@ function PMA_getUsersOverview($result, $db_rights, $pmaThemeImage, $text_dir)
. '</table>' . "\n";
$html_output .= '<div class="floatleft">'
. Util::getWithSelected($pmaThemeImage, $text_dir, "usersForm") . "\n";
. Template::get('select_all')
->render(
array(
'pmaThemeImage' => $pmaThemeImage,
'text_dir' => $text_dir,
'formName' => 'usersForm',
)
) . "\n";
$html_output .= Util::getButtonOrImage(
'submit_mult', 'mult_submit',
__('Export'), 'b_tblexport.png', 'export'

View File

@ -355,11 +355,14 @@ function PMA_getHtmlForTableVersionDetails(
$html .= '</tbody>';
$html .= '</table>';
$html .= PMA\libraries\Util::getWithSelected(
$pmaThemeImage,
$text_dir,
"versionsForm"
);
$html .= PMA\libraries\Template::get('select_all')
->render(
array(
'pmaThemeImage' => $pmaThemeImage,
'text_dir' => $text_dir,
'formName' => 'versionsForm',
)
);
$html .= PMA\libraries\Util::getButtonOrImage(
'submit_mult', 'mult_submit',
__('Delete version'), 'b_drop.png', 'delete_version'
@ -1488,11 +1491,14 @@ function PMA_displayUntrackedTables(
</tbody>
</table>
<?php
echo PMA\libraries\Util::getWithSelected(
$pmaThemeImage,
$text_dir,
"untrackedForm"
);
echo PMA\libraries\Template::get('select_all')
->render(
array(
'pmaThemeImage' => $pmaThemeImage,
'text_dir' => $text_dir,
'formName' => 'untrackedForm',
)
);
echo PMA\libraries\Util::getButtonOrImage(
'submit_mult', 'mult_submit',
__('Track table'), 'eye.png', 'track'
@ -1708,11 +1714,14 @@ function PMA_displayTrackedTables(
</tbody>
</table>
<?php
echo PMA\libraries\Util::getWithSelected(
$pmaThemeImage,
$text_dir,
"trackedForm"
);
echo PMA\libraries\Template::get('select_all')
->render(
array(
'pmaThemeImage' => $pmaThemeImage,
'text_dir' => $text_dir,
'formName' => 'trackedForm',
)
);
echo PMA\libraries\Util::getButtonOrImage(
'submit_mult', 'mult_submit',
__('Delete tracking'), 'b_drop.png', 'delete_tracking'

13
templates/checkbox.phtml Normal file
View File

@ -0,0 +1,13 @@
<input type="checkbox" name="<?= $html_field_name ; ?>"
<?php if (isset($html_field_id)): ?>
id="<?= $html_field_id ; ?>"
<?php endif ;
if (isset($checked) && $checked): ?>
checked="checked"
<?php endif ;
if (isset($onclick) && $onclick): ?>
class="autosubmit"
<?php endif ; ?> />
<label <?php if (isset($html_field_id)): ?>
for="<?= $html_field_id ; endif ; ?>">
<?= $label ; ?> </label>

View File

@ -0,0 +1,7 @@
<img class="selectallarrow" src="<?= $pmaThemeImage . 'arrow_' . $text_dir . '.png' ; ?>"
width="38" height="22" alt="<?= __('With selected:') ; ?>" />
<input type="checkbox" id="<?= $formName . '_checkall' ; ?>" class="checkall_box"
title="<?= __('Check all') ; ?>" />
<label for="<?= $formName . '_checkall' . __('Check all') ;?>" </label>
<i style="margin-left: 2em">
<?= __('With selected:') ; ?> </i>

View File

@ -17,10 +17,13 @@
</select>
<br>
<?= PMA\libraries\Util::getCheckbox(
'useRegex',
__('Use regular expression'),
false,
false,
'useRegex'
); ?>
<?= PMA\libraries\Template::get('checkbox')
->render(
array(
'html_field_name' => 'useRegex',
'label' => __('Use regular expression'),
'checked' => false,
'onclick' => false,
'html_field_id' => 'useRegex',
)
); ?>

View File

@ -1,5 +1,12 @@
<div class="print_ignore" >
<?= PMA\libraries\Util::getWithSelected($pmaThemeImage, $text_dir, "fieldsForm") ?>
<?= PMA\libraries\Template::get('select_all')
->render(
array(
'pmaThemeImage' => $pmaThemeImage,
'text_dir' => $text_dir,
'formName' => "fieldsForm",
)
); ?>
<?= PMA\libraries\Util::getButtonOrImage(
'submit_mult', 'mult_submit',
__('Browse'), 'b_browse.png', 'browse'
@ -53,4 +60,4 @@
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
</div>
</div>

View File

@ -1206,11 +1206,16 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase
$html
);
$item = PMA\libraries\Util::getCheckbox(
'createdb-2',
__('Grant all privileges on wildcard name (username\\_%).'),
false, false, 'createdb-2'
);
$item = PMA\libraries\Template::get('checkbox')
->render(
array(
'html_field_name' => 'createdb-2',
'label' => __('Grant all privileges on wildcard name (username\\_%).'),
'checked' => false,
'onclick' => false,
'html_field_id' => 'createdb-2',
)
);
$this->assertContains(
$item,
$html

View File

@ -0,0 +1,132 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for checkbox.phtml
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
** Test for checkbox.phtml
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_GetCheckboxTest extends PHPUnit_Framework_TestCase
{
/**
* Test for checkbox.phtml
*
* @return void
*/
function testGetCheckbox()
{
$name = "test_display_html_checkbox";
$label = "text_label_for_checkbox";
// assertXmlStringEqualsXmlString require both inputs to be a valid xml string
// dummy <root> tag will make input a valid xml string
$this->assertXmlStringEqualsXmlString(
'<root> ' . PMA\libraries\Template::get('checkbox')
->render(
array(
'html_field_name' => $name,
'label' => $label,
'checked' => false,
'onclick' => false,
'html_field_id' => $name,
)
) . ' </root>',
'<root> <input type="checkbox" name="' . $name . '" id="' . $name
. '" /><label for="' . $name . '">' . $label
. '</label> </root>'
);
}
/**
* Test for checkbox.phtml
*
* @return void
*/
function testGetCheckboxChecked()
{
$name = "test_display_html_checkbox";
$label = "text_label_for_checkbox";
$this->assertXmlStringEqualsXmlString(
'<root>' . PMA\libraries\Template::get('checkbox')
->render(
array(
'html_field_name' => $name,
'label' => $label,
'checked' => true,
'onclick' => false,
'html_field_id' => $name,
)
) . '</root>',
'<root> <input type="checkbox" name="' . $name . '" id="' . $name
. '" checked="checked" /><label for="' . $name . '">' . $label
. '</label> </root>'
);
}
/**
* Test for checkbox.phtml
*
* @return void
*/
function testGetCheckboxOnclick()
{
$name = "test_display_html_checkbox";
$label = "text_label_for_checkbox";
$this->assertXmlStringEqualsXmlString(
'<root>' . PMA\libraries\Template::get('checkbox')
->render(
array(
'html_field_name' => $name,
'label' => $label,
'checked' => false,
'onclick' => true,
'html_field_id' => $name,
)
) . '</root>',
'<root> <input type="checkbox" name="' . $name . '" id="' . $name
. '" class="autosubmit" /><label for="' . $name . '">' . $label
. '</label> </root>'
);
}
/**
* Test for checkbox.phtml
*
* @return void
*/
function testGetCheckboxCheckedOnclick()
{
$name = "test_display_html_checkbox";
$label = "text_label_for_checkbox";
$this->assertXmlStringEqualsXmlString(
'<root>' . PMA\libraries\Template::get('checkbox')
->render(
array(
'html_field_name' => $name,
'label' => $label,
'checked' => true,
'onclick' => true,
'html_field_id' => $name,
)
) . '</root>',
'<root> <input type="checkbox" name="' . $name . '" id="' . $name
. '" checked="checked" class="autosubmit" /><label for="' . $name
. '">' . $label . '</label> </root>'
);
}
}

View File

@ -1,94 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::getCheckbox from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
** Test for PMA\libraries\Util::getCheckbox from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_GetCheckboxTest extends PHPUnit_Framework_TestCase
{
/**
* Test for getCheckbox
*
* @return void
*/
function testGetCheckbox()
{
$name = "test_display_html_checkbox";
$label = "text_label_for_checkbox";
$this->assertEquals(
PMA\libraries\Util::getCheckbox($name, $label, false, false, $name),
'<input type="checkbox" name="' . $name . '" id="' . $name
. '" /><label for="' . $name . '">' . $label
. '</label>'
);
}
/**
* Test for getCheckbox
*
* @return void
*/
function testGetCheckboxChecked()
{
$name = "test_display_html_checkbox";
$label = "text_label_for_checkbox";
$this->assertEquals(
PMA\libraries\Util::getCheckbox($name, $label, true, false, $name),
'<input type="checkbox" name="' . $name . '" id="' . $name
. '" checked="checked" /><label for="' . $name . '">' . $label
. '</label>'
);
}
/**
* Test for getCheckbox
*
* @return void
*/
function testGetCheckboxOnclick()
{
$name = "test_display_html_checkbox";
$label = "text_label_for_checkbox";
$this->assertEquals(
PMA\libraries\Util::getCheckbox($name, $label, false, true, $name),
'<input type="checkbox" name="' . $name . '" id="' . $name
. '" class="autosubmit" /><label for="' . $name . '">' . $label
. '</label>'
);
}
/**
* Test for getCheckbox
*
* @return void
*/
function testGetCheckboxCheckedOnclick()
{
$name = "test_display_html_checkbox";
$label = "text_label_for_checkbox";
$this->assertEquals(
PMA\libraries\Util::getCheckbox($name, $label, true, true, $name),
'<input type="checkbox" name="' . $name . '" id="' . $name
. '" checked="checked" class="autosubmit" /><label for="' . $name
. '">' . $label . '</label>'
);
}
}