Page-related settings, rfe#1559

Signed-off-by: Nisarg Jhaveri <nisargjhaveri@gmail.com>
This commit is contained in:
Nisarg Jhaveri 2015-05-18 20:38:07 +05:30
parent 74a9200c60
commit e115adb533
25 changed files with 327 additions and 27 deletions

View File

@ -34,6 +34,7 @@ phpMyAdmin - ChangeLog
+ rfe #1668 Procedures window shift-click should select multiple rows
+ rfe #1669 Designer: "Sticky" menu option
+ rfe #1671 Directly show table comments in structure view
+ rfe #1559 Page-related settings
4.4.8.0 (not yet released)
- bug Allow accessing visual query builder when pmadb is not configured
@ -197,7 +198,7 @@ phpMyAdmin - ChangeLog
+ rfe Change tracking activation status from db level tracking page
+ rfe #1207 Export users associated with a specific schema/database
+ rfe #1575 "Disable database expansion" : unclear directive name and
explanation
explanation
+ rfe #1607 Tool tip for lock icon when making changes to a page
+ rfe #1327 Hide 'Add user' link if user does not have privileges
+ rfe #501 Support for SSL GRANT option
@ -285,7 +286,7 @@ explanation
- bug #4717 Database navigation menu broken when resolution/screen is changing
- bug #4727 Collation column missing in database list when DisableIS is true
- bug Undefined index central_columnswork
- bug Undefined index favorite_tables
- bug Undefined index favorite_tables
4.3.7.0 (2015-01-15)
- bug #4694 js error on marking table as favorite in Safari (in private mode)

View File

@ -10,6 +10,9 @@
* Gets some core libraries
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/config/page_settings.class.php';
PMA_PageSettings::showGroup('Export');
$response = PMA_Response::getInstance();
$header = $response->getHeader();

View File

@ -7,6 +7,9 @@
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/config/page_settings.class.php';
PMA_PageSettings::showGroup('Import');
$response = PMA_Response::getInstance();
$header = $response->getHeader();

View File

@ -10,6 +10,9 @@
*
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/config/page_settings.class.php';
PMA_PageSettings::showGroup('Sql_queries');
/**
* Runs common work

View File

@ -10,6 +10,9 @@
*
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/config/page_settings.class.php';
PMA_PageSettings::showGroup('DbStructure');
/**
* Function implementations for this script

View File

@ -341,6 +341,7 @@ var AJAX = {
.not('#floating_menubar')
.not('#goto_pagetop')
.not('#lock_page_icon')
.not('#page_settings_icon')
.not('#page_content')
.not('#selflink')
.not('#session_debug')

View File

@ -299,7 +299,7 @@ function validateField(id, type, onKeyUp, params)
function getFieldValidators(field_id, onKeyUpOnly)
{
// look for field bound validator
var name = field_id.match(/[^-]+$/)[0];
var name = field_id && field_id.match(/[^-]+$/)[0];
if (typeof validators._field[name] != 'undefined') {
return [[validators._field[name], null]];
}
@ -478,6 +478,9 @@ function setRestoreDefaultBtn(field, display)
}
AJAX.registerOnload('config.js', function () {
if (typeof configInlineParams === 'function') {
configInlineParams();
}
// register validators and mark custom values
var $elements = $('input[id], select[id], textarea[id]');
$('input[id], select[id], textarea[id]').each(function () {

View File

@ -266,6 +266,10 @@ $js_messages['strFormatting'] = __('Formatting SQL...');
$js_messages['strGo'] = __('Go');
$js_messages['strCancel'] = __('Cancel');
/* For page-related settings */
$js_messages['strPageSettings'] = _('Page-related settings');
$js_messages['strApply'] = _('Apply');
/* For Ajax Notifications */
$js_messages['strLoading'] = __('Loading…');
$js_messages['strAbortedRequest'] = __('Request Aborted!!');

42
js/page_settings.js Normal file
View File

@ -0,0 +1,42 @@
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* @fileoverview function used for page-related settings
* @name Page-related settings
*
* @requires jQuery
* @requires jQueryUI
* @required js/functions.js
*/
function show_settings() {
var buttons = {};
buttons[PMA_messages.strApply] = function() {
$('.config-form').submit();
};
buttons[PMA_messages.strCancel] = function () {
$(this).dialog('close');
};
$('.page_settings_modal')
.dialog({
title: PMA_messages.strPageSettings,
width: 700,
minHeight: 250,
modal: true,
open: function() {
$(this).dialog('option', 'maxHeight', $(window).height() - $(this).offset().top);
},
buttons: buttons
});
}
AJAX.registerTeardown('page_settings.js', function () {
$('#page_settings_icon').css('display', 'none');
$('#page_settings_icon').unbind('click');
});
AJAX.registerOnload('page_settings.js', function () {
$('#page_settings_icon').css('display', 'inline');
$('#page_settings_icon').bind('click', show_settings);
});

View File

@ -444,6 +444,12 @@ class PMA_Header
if ($this->_menuEnabled && $GLOBALS['server'] > 0) {
$retval .= $this->_menu->getDisplay();
$retval .= '<span id="lock_page_icon"></span>';
$retval .= '<span id="page_settings_icon">'
. PMA_Util::getImage(
's_cog.png',
__('Page-related settings')
)
. '</span>';
$retval .= sprintf(
'<a id="goto_pagetop" href="#">%s</a>',
PMA_Util::getImage(

View File

@ -212,11 +212,12 @@ class FormDisplay
* @param array &$js_default stores JavaScript code
* to be displayed
* @param array &$js will be updated with javascript code
* @param bool $show_buttons whether show submit and reset button
*
* @return string $htmlOutput
*/
private function _displayForms(
$show_restore_default, array &$js_default, array &$js
$show_restore_default, array &$js_default, array &$js, $show_buttons
) {
$htmlOutput = '';
$validators = PMA_Validator::getValidators($this->_configFile);
@ -259,7 +260,7 @@ class FormDisplay
PMA_addJsValidate($translated_path, $validators[$path], $js);
}
}
$htmlOutput .= PMA_displayFieldsetBottom();
$htmlOutput .= PMA_displayFieldsetBottom($show_buttons);
}
return $htmlOutput;
}
@ -267,23 +268,30 @@ class FormDisplay
/**
* Outputs HTML for forms
*
* @param bool $tabbed_form if true, use a form with tabs
* @param bool $show_restore_default whether show "restore default" button
* besides the input field
* @param bool $tabbed_form if true, use a form with tabs
* @param bool $show_restore_default whether show "restore default" button
* besides the input field
* @param bool $show_buttons whether show submit and reset button
* @param string $form_action action attribute for the form
* @param array $hidden_fields array of form hidden fields (key: field name)
*
* @return string HTML for forms
*/
public function getDisplay($tabbed_form = false, $show_restore_default = false)
{
public function getDisplay(
$tabbed_form = false,
$show_restore_default = false,
$show_buttons = true,
$form_action = null,
$hidden_fields = null
) {
static $js_lang_sent = false;
$htmlOutput = '';
$js = array();
$js_default = array();
$tabbed_form = $tabbed_form && (count($this->_forms) > 1);
$htmlOutput .= PMA_displayFormTop();
$htmlOutput .= PMA_displayFormTop($form_action, 'post', $hidden_fields);
if ($tabbed_form) {
$tabs = array();
@ -311,7 +319,7 @@ class FormDisplay
// display forms
$htmlOutput .= $this->_displayForms(
$show_restore_default, $js_default, $js
$show_restore_default, $js_default, $js, $show_buttons
);
if ($tabbed_form) {

View File

@ -384,22 +384,27 @@ function PMA_displayGroupFooter()
/**
* Displays bottom part of a fieldset
*
* @param bool $show_buttons whether show submit and reset button
*
* @return string
*/
function PMA_displayFieldsetBottom()
function PMA_displayFieldsetBottom($show_buttons = true)
{
$colspan = 2;
if (defined('PMA_SETUP')) {
$colspan++;
}
$htmlOutput = '<tr>';
$htmlOutput .= '<td colspan="' . $colspan . '" class="lastrow">';
$htmlOutput .= '<input type="submit" name="submit_save" value="'
. __('Apply') . '" class="green" />';
$htmlOutput .= '<input type="button" name="submit_reset" value="'
. __('Reset') . '" />';
$htmlOutput .= '</td>';
$htmlOutput .= '</tr>';
$htmlOutput = '';
if ($show_buttons) {
$htmlOutput .= '<tr>';
$htmlOutput .= '<td colspan="' . $colspan . '" class="lastrow">';
$htmlOutput .= '<input type="submit" name="submit_save" value="'
. __('Apply') . '" class="green" />';
$htmlOutput .= '<input type="button" name="submit_reset" value="'
. __('Reset') . '" />';
$htmlOutput .= '</td>';
$htmlOutput .= '</tr>';
}
$htmlOutput .= '</table>';
$htmlOutput .= '</fieldset>';
return $htmlOutput;
@ -475,9 +480,11 @@ function PMA_displayJavascript($js_array)
if (empty($js_array)) {
return;
}
$htmlOutput = '<script type="text/javascript">' . "\n";
$htmlOutput .= implode(";\n", $js_array) . ";\n";
$htmlOutput .= '</script>' . "\n";
$htmlOutput = '<script type="text/javascript">' . "\n"
. 'function configInlineParams() {' . "\n"
. implode(";\n", $js_array) . ";\n"
. '};' . "\n"
. '</script>' . "\n";
return $htmlOutput;
}

View File

@ -0,0 +1,148 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Page-related settings
*
* @package PhpMyAdmin
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/user_preferences.lib.php';
require_once 'libraries/config/config_functions.lib.php';
require_once 'libraries/config/messages.inc.php';
require_once 'libraries/config/ConfigFile.class.php';
require_once 'libraries/config/Form.class.php';
require_once 'libraries/config/FormDisplay.class.php';
require 'libraries/config/user_preferences.forms.php';
require 'libraries/config/page_settings.forms.php';
/**
* Page-related settings
*
* @package PhpMyAdmin
*/
class PMA_PageSettings
{
/**
* Is class initiated
*
* @access private
* @static
* @var bool
*/
private static $_initiated = false;
/**
* Constructor
*
* @param string $formGroupName The name of config form group to display
*/
public function __construct($formGroupName)
{
global $forms;
if (self::$_initiated) {
return;
}
if (empty($forms[$formGroupName])) {
return;
}
self::$_initiated = true;
$cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings);
PMA_userprefsPageInit($cf);
$form_display = new FormDisplay($cf);
foreach ($forms[$formGroupName] as $form_name => $form) {
// skip Developer form if no setting is available
if ($form_name == 'Developer' && !$GLOBALS['cfg']['UserprefsDeveloperTab']) {
continue;
}
$form_display->registerForm($form_name, $form, 1);
}
// Process form
$error = null;
$this->_processPageSettings($form_display, $cf, $error);
// Display forms
$this->_displayPageSettings($form_display, $error);
}
/**
* Process response to form
*
* @return void
*/
private function _processPageSettings(&$form_display, &$cf, &$error)
{
if ($form_display->process(false) && !$form_display->hasErrors()) {
// save settings
$result = PMA_saveUserprefs($cf->getConfigArray());
if ($result === true) {
// reload config
$GLOBALS['PMA_Config']->loadUserPreferences();
$hash = ltrim(filter_input(INPUT_POST, 'tab_hash'), '#');
header('Location: ' . $_SERVER['REQUEST_URI']);
exit();
} else {
$error = $result;
}
}
}
/**
* Display page-related settings
*
* @return void
*/
private function _displayPageSettings(&$form_display, &$error)
{
$response = PMA_Response::getInstance();
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('config.js');
$scripts->addFile('page_settings.js');
if ($error) {
$response->addHTML($error->getDisplay());
}
if ($form_display->hasErrors()) {
// form has errors
$response->addHTML(
'<div class="error config-form">'
. '<b>' . __('Cannot save settings, submitted configuration form contains errors!') . '</b>'
. $form_display->displayErrors()
. '</div>'
);
}
$response->addHTML('<div class="page_settings_modal">');
$response->addHTML(
$form_display->getDisplay(
true,
true,
false,
$response->getFooter()->getSelfUrl('unencoded'),
array(
'submit_save' => 'Submit'
)
)
);
$response->addHTML('</div>');
}
/**
* Group to show for Page-related settings
* @param string $formGroupName The name of config form group to display
* @return PMA_PageSettings|false
*/
public static function showGroup($formGroupName)
{
if (!self::$_initiated) {
return new PMA_PageSettings($formGroupName);
}
return false;
}
}

View File

@ -0,0 +1,28 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Used for page-related settings
*
* Extends groups defined in user_preferences.forms.php
* specific to page-related settings
*
* See more info in user_preferences.forms.php
*
* @package PhpMyAdmin
*/
if (!is_array($forms)) {
$forms = array();
}
$forms['Browse'] = array();
$forms['Browse']['Browse'] = $forms['Main_panel']['Browse'];
$forms['DbStructure'] = array();
$forms['DbStructure']['DbStructure'] = $forms['Main_panel']['DbStructure'];
$forms['Edit'] = array();
$forms['Edit']['Edit'] = $forms['Main_panel']['Edit'];
$forms['TableStructure'] = array();
$forms['TableStructure']['TableStructure'] = $forms['Main_panel']['TableStructure'];

View File

@ -12,6 +12,9 @@
require_once 'libraries/common.inc.php';
require_once 'libraries/server_common.inc.php';
require_once 'libraries/display_export.lib.php';
require_once 'libraries/config/page_settings.class.php';
PMA_PageSettings::showGroup('Export');
$response = PMA_Response::getInstance();
$header = $response->getHeader();

View File

@ -10,6 +10,9 @@
*
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/config/page_settings.class.php';
PMA_PageSettings::showGroup('Import');
$response = PMA_Response::getInstance();
$header = $response->getHeader();

View File

@ -10,6 +10,9 @@
*
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/config/page_settings.class.php';
PMA_PageSettings::showGroup('Sql_queries');
/**
* Does the common work

View File

@ -18,6 +18,10 @@ require_once 'libraries/check_user_privileges.lib.php';
require_once 'libraries/bookmark.lib.php';
require_once 'libraries/sql.lib.php';
require_once 'libraries/sqlparser.lib.php';
require_once 'libraries/config/page_settings.class.php';
PMA_PageSettings::showGroup('Browse');
$response = PMA_Response::getInstance();
$header = $response->getHeader();

View File

@ -12,6 +12,9 @@
* Gets the variables sent or posted to this script and displays the header
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/config/page_settings.class.php';
PMA_PageSettings::showGroup('Edit');
/**
* Ensures db and table are valid, else moves to the "parent" script

View File

@ -10,6 +10,9 @@
*
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/config/page_settings.class.php';
PMA_PageSettings::showGroup('Export');
$response = PMA_Response::getInstance();
$header = $response->getHeader();

View File

@ -10,6 +10,9 @@
*
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/config/page_settings.class.php';
PMA_PageSettings::showGroup('Import');
$response = PMA_Response::getInstance();
$header = $response->getHeader();

View File

@ -10,6 +10,9 @@
*
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/config/page_settings.class.php';
PMA_PageSettings::showGroup('Sql_queries');
/**
* Runs common work

View File

@ -12,6 +12,9 @@
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/mysql_charsets.inc.php';
require_once 'libraries/config/page_settings.class.php';
PMA_PageSettings::showGroup('TableStructure');
/**
* Function implementations for this script

View File

@ -557,8 +557,10 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
$this->assertEquals(
"<script type=\"text/javascript\">\n" .
"function configInlineParams() {\n" .
"var i = 1;\n" .
"i++;\n" .
"};\n" .
"</script>\n",
$result
);

View File

@ -1146,7 +1146,7 @@ div#tablestatistics table {
color: #fff;
}
#goto_pagetop, #lock_page_icon {
#goto_pagetop, #lock_page_icon, #page_settings_icon {
position: fixed;
padding: .25em .25em .2em;
top: 0;
@ -1158,8 +1158,18 @@ div#tablestatistics table {
<?php echo $right; ?>: 0;
}
#lock_page_icon {
#page_settings_icon {
<?php echo $right; ?>: 2em;
cursor: pointer;
display: none;
}
#lock_page_icon {
<?php echo $right; ?>: 4em;
}
.page_settings_modal {
display: none;
}
#span_table_comment {