Visitar URL original
Remove `gridEditingConfig` JS global · phpmyadmin/phpmyadmin@c482cd4 · GitHub
Skip to content

Commit c482cd4

Browse files
committed
Remove gridEditingConfig JS global
- Uses data attribute instead. - Uses Bootstrap's tooltip instead of the jQuery plugin. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent a0337bf commit c482cd4

7 files changed

Lines changed: 39 additions & 45 deletions

File tree

‎js/src/makegrid.js‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* global firstDayOfCalendar */ // templates/javascript/variables.twig
2-
/* global gridEditingConfig */ // templates/javascript/variables.twig
32

43
/**
54
* Create advanced table (resize, reorder, and show/hide columns; and also grid editing).
@@ -2151,10 +2150,9 @@ var makeGrid = function (t, enableResize, enableReorder, enableVisib, enableGrid
21512150
$(g.gDiv).append(g.cEditTextarea);
21522151

21532152
// add hint for grid editing feature when hovering "Edit" link in each table row
2154-
if (gridEditingConfig === 'double-click') {
2155-
Functions.tooltip($(g.t).find('.edit_row_anchor a'), 'a', Messages.strGridEditFeatureHintDoubleClick);
2156-
} else if (gridEditingConfig === 'click') {
2157-
Functions.tooltip($(g.t).find('.edit_row_anchor a'), 'a', Messages.strGridEditFeatureHintClick);
2153+
const editRowAnchor = $(g.t).find('.edit_row_anchor');
2154+
if (editRowAnchor.attr('data-grid-edit-config') !== 'disabled') {
2155+
editRowAnchor.find('a').tooltip();
21582156
}
21592157
}
21602158
};

‎libraries/classes/Controllers/JavaScriptMessagesController.php‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -582,12 +582,6 @@ private function setMessages(): array
582582
'dropImportDropFiles' => __('Drop files here'),
583583
'dropImportSelectDB' => __('Select database first'),
584584

585-
// this approach does not work when the parameter is changed via user prefs
586-
'strGridEditFeatureHintDoubleClick' => __(
587-
'You can also edit most values<br>by double-clicking directly on them.'
588-
),
589-
'strGridEditFeatureHintClick' => __('You can also edit most values<br>by clicking directly on them.'),
590-
591585
'strGoToLink' => __('Go to link:'),
592586

593587
/* password generation */

‎libraries/classes/Display/Results.php‎

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,25 +2119,12 @@ private function getTableBody(
21192119
$displayParams['row_delete'] = [];
21202120
$this->properties['display_params'] = $displayParams;
21212121

2122-
// name of the class added to all grid editable elements;
2123-
// if we don't have all the columns of a unique key in the result set,
2124-
// do not permit grid editing
2125-
if ($isLimitedDisplay || ! $this->properties['editable']) {
2126-
$gridEditClass = '';
2127-
} else {
2128-
switch ($GLOBALS['cfg']['GridEditing']) {
2129-
case 'double-click':
2130-
// trying to reduce generated HTML by using shorter
2131-
// classes like click1 and click2
2132-
$gridEditClass = 'grid_edit click2';
2133-
break;
2134-
case 'click':
2135-
$gridEditClass = 'grid_edit click1';
2136-
break;
2137-
default: // 'disabled'
2138-
$gridEditClass = '';
2139-
break;
2140-
}
2122+
$gridEditConfig = 'double-click';
2123+
// If we don't have all the columns of a unique key in the result set, do not permit grid editing.
2124+
if ($isLimitedDisplay || ! $this->properties['editable'] || $GLOBALS['cfg']['GridEditing'] === 'disabled') {
2125+
$gridEditConfig = 'disabled';
2126+
} elseif ($GLOBALS['cfg']['GridEditing'] === 'click') {
2127+
$gridEditConfig = 'click';
21412128
}
21422129

21432130
// prepare to get the column order, if available
@@ -2272,6 +2259,7 @@ private function getTableBody(
22722259
'condition' => json_encode($conditionArray),
22732260
'is_ajax' => ResponseRenderer::getInstance()->isAjax(),
22742261
'js_conf' => $jsConf ?? '',
2262+
'grid_edit_config' => $gridEditConfig,
22752263
]);
22762264
} elseif ($GLOBALS['cfg']['RowActionLinks'] === self::POSITION_NONE) {
22772265
$tableBodyHtml .= $this->template->render('display/results/checkbox_and_links', [
@@ -2294,6 +2282,7 @@ private function getTableBody(
22942282
'condition' => json_encode($conditionArray),
22952283
'is_ajax' => ResponseRenderer::getInstance()->isAjax(),
22962284
'js_conf' => $jsConf ?? '',
2285+
'grid_edit_config' => $gridEditConfig,
22972286
]);
22982287
}
22992288
}
@@ -2308,7 +2297,7 @@ private function getTableBody(
23082297
$rowNumber,
23092298
$colOrder,
23102299
$map,
2311-
$gridEditClass,
2300+
$gridEditConfig,
23122301
$colVisib,
23132302
$urlSqlQuery,
23142303
$analyzedSqlResults
@@ -2341,6 +2330,7 @@ private function getTableBody(
23412330
'condition' => json_encode($conditionArray ?? []),
23422331
'is_ajax' => ResponseRenderer::getInstance()->isAjax(),
23432332
'js_conf' => $jsConf ?? '',
2333+
'grid_edit_config' => $gridEditConfig,
23442334
]);
23452335
}
23462336

@@ -2427,13 +2417,12 @@ private function setMimeMap(): void
24272417
* a property not found false
24282418
* when a property not found
24292419
* @param array<string, string[]> $map the list of relations
2430-
* @param string $gridEditClass the class for all editable
2431-
* columns
24322420
* @param bool|array|string $colVisib column is visible(false);
24332421
* column isn't visible(string
24342422
* array)
24352423
* @param string $urlSqlQuery the analyzed sql query
24362424
* @param array $analyzedSqlResults analyzed sql results
2425+
* @psalm-param 'double-click'|'click'|'disabled' $gridEditConfig
24372426
*
24382427
* @return string html content
24392428
*/
@@ -2442,7 +2431,7 @@ private function getRowValues(
24422431
$rowNumber,
24432432
$colOrder,
24442433
array $map,
2445-
$gridEditClass,
2434+
string $gridEditConfig,
24462435
$colVisib,
24472436
$urlSqlQuery,
24482437
array $analyzedSqlResults
@@ -2478,7 +2467,11 @@ private function getRowValues(
24782467
$hideClass = is_array($colVisib) && isset($colVisib[$currentColumn]) && ! $colVisib[$currentColumn]
24792468
? 'hide'
24802469
: '';
2481-
$gridEdit = $meta->orgtable != '' ? $gridEditClass : '';
2470+
2471+
$gridEdit = '';
2472+
if ($meta->orgtable != '' && $gridEditConfig !== 'disabled') {
2473+
$gridEdit = $gridEditConfig === 'click' ? 'grid_edit click1' : 'grid_edit click2';
2474+
}
24822475

24832476
// handle datetime-related class, for grid editing
24842477
$fieldTypeClass = $this->getClassForDateTimeRelatedFields($meta);

‎libraries/classes/Header.php‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,14 +667,10 @@ private function getVariablesForJavaScript(): string
667667

668668
$maxInputVars = ini_get('max_input_vars');
669669
$maxInputVarsValue = $maxInputVars === false || $maxInputVars === '' ? 'false' : (int) $maxInputVars;
670-
$gridEditing = $cfg['GridEditing'] === 'click' || $cfg['GridEditing'] === 'disabled'
671-
? $cfg['GridEditing']
672-
: 'double-click';
673670

674671
return $this->template->render('javascript/variables', [
675672
'first_day_of_calendar' => $cfg['FirstDayOfCalendar'] ?? 0,
676673
'max_input_vars' => $maxInputVarsValue,
677-
'grid_editing' => $gridEditing,
678674
]);
679675
}
680676
}

‎templates/display/results/checkbox_and_links.twig‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@
88
{% endif %}
99

1010
{% if edit.url is not empty %}
11-
<td class="text-center d-print-none edit_row_anchor{{ not edit.clause_is_unique ? ' nonunique' }}">
11+
<td class="text-center d-print-none edit_row_anchor{{ not edit.clause_is_unique ? ' nonunique' }}" data-grid-edit-config="{{ grid_edit_config }}">
1212
<span class="text-nowrap">
13-
{{ link_or_button(edit.url, edit.params, edit.string) }}
13+
{% if grid_edit_config == 'disabled' %}
14+
{% set grid_edit_tooltip = {} %}
15+
{% elseif grid_edit_config == 'click' %}
16+
{% set grid_edit_tooltip = {'data-bs-toggle': 'tooltip', 'data-bs-placement': 'right', 'title': 'You can also edit most values by clicking directly on them.'|trans} %}
17+
{% else %}
18+
{% set grid_edit_tooltip = {'data-bs-toggle': 'tooltip', 'data-bs-placement': 'right', 'title': 'You can also edit most values by double-clicking directly on them.'|trans} %}
19+
{% endif %}
20+
{{ link_or_button(edit.url, edit.params, edit.string, grid_edit_tooltip) }}
1421
{% if where_clause is not empty %}
1522
<input type="hidden" class="where_clause" value="{{ where_clause }}">
1623
{% endif %}
@@ -63,9 +70,16 @@
6370
{% endif %}
6471

6572
{% if edit.url is not empty %}
66-
<td class="text-center d-print-none edit_row_anchor{{ not edit.clause_is_unique ? ' nonunique' }}">
73+
<td class="text-center d-print-none edit_row_anchor{{ not edit.clause_is_unique ? ' nonunique' }}" data-grid-edit-config="{{ grid_edit_config }}">
6774
<span class="text-nowrap">
68-
{{ link_or_button(edit.url, edit.params, edit.string) }}
75+
{% if grid_edit_config == 'disabled' %}
76+
{% set grid_edit_tooltip = {} %}
77+
{% elseif grid_edit_config == 'click' %}
78+
{% set grid_edit_tooltip = {'data-bs-toggle': 'tooltip', 'data-bs-placement': 'left', 'title': 'You can also edit most values by clicking directly on them.'|trans} %}
79+
{% else %}
80+
{% set grid_edit_tooltip = {'data-bs-toggle': 'tooltip', 'data-bs-placement': 'left', 'title': 'You can also edit most values by double-clicking directly on them.'|trans} %}
81+
{% endif %}
82+
{{ link_or_button(edit.url, edit.params, edit.string, grid_edit_tooltip) }}
6983
{% if where_clause is not empty %}
7084
<input type="hidden" class="where_clause" value="{{ where_clause }}">
7185
{% endif %}

‎templates/javascript/variables.twig‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ var firstDayOfCalendar = '{{ first_day_of_calendar }}';
33
var themeImagePath = '{{ image() }}';
44
var mysqlDocTemplate = '{{ get_mysql_docu_url('%s') }}';
55
var maxInputVars = {{ max_input_vars }};
6-
var gridEditingConfig = '{{ grid_editing }}';
76

87
{% set show_month_after_year -%}
98
{% trans %}calendar-month-year{% notes %}Month-year order for calendar, use either "calendar-month-year" or "calendar-year-month".{% endtrans %}

‎test/classes/Display/ResultsTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ public function testOutputTransformations(): void
958958
0,
959959
false,
960960
[],
961-
'',
961+
'disabled',
962962
false,
963963
$query,
964964
Query::getAll($query),

0 commit comments

Comments
 (0)