From d72f4222bfef585ef6f4de4727dadf2af79b45be Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Thu, 1 Aug 2019 17:28:53 +0000 Subject: [PATCH] Bug 23388: [WIP] Make system preferences links This alternate solution adds a link which when clicked will copy a URL linking directly to the corresponding system preference. To test, apply the patch and view system preferences. Hovering the mouse over any row in the system preferences table should trigger the display of an anchor link at the end of the row. Hovering over the link should display a tooltip, "Copy link to this preference." Clicking the link should copy it to your clipboard. Test that the link is copied correctly and that it works to link you to the preference in question. Known issues: Because of the way the page is drawn, the browser's calculation of where to scroll isn't accurate, meaning the target preference will sometimes be hidden by the floating toolbar. Question: "Hover" isn't a mobile/touch-friendly interaction. Show the link all the time? Show it at narrower browser widths? --- koha-tmpl/intranet-tmpl/prog/css/preferences.css | 17 +++++++++++++++++ .../prog/en/modules/admin/preferences.tt | 15 ++++++++++++--- .../intranet-tmpl/prog/js/pages/preferences.js | 21 +++++++++++++++++++-- koha-tmpl/intranet-tmpl/prog/js/staff-global.js | 13 +++++++++++++ 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/css/preferences.css b/koha-tmpl/intranet-tmpl/prog/css/preferences.css index 7ecce1be4d9..521db6d0aac 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/preferences.css +++ b/koha-tmpl/intranet-tmpl/prog/css/preferences.css @@ -134,4 +134,21 @@ span.overridden { border: 1px solid #EEE; margin: 1em 1em 1em 0; resize: vertical; +} + +.name-cell:target { + background-color: #FFC; +} + +.permalink { + bottom: 0; + display: inline-block; + padding: 5px; + position: absolute; + right: 0; +} + +.pref-cell > div { + padding-right: 1em; + position: relative; } \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt index 764f1645d95..a9f27568a89 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt @@ -52,9 +52,11 @@ [% ELSE %] [% IF ( loop.first ) %][% END %] - - + [% IF ( is_pref ) %] + + [% END %] + + [% IF ( loop.last ) %]
PreferenceValue
+
+
+
[% FOREACH CHUNK IN LINE.CHUNKS %] [% IF ( CHUNK.type_text ) %] [% CHUNK.contents | $raw %] @@ -143,7 +146,11 @@ [% END %] [% END %] -
[% END %] [% END %] @@ -212,6 +219,8 @@ var MSG_ALL_VALUE_WARN = _("Note: _ALL_ value will override all other values"); var MSG_UPD_LOC_FORMAT_WARN = _("The following values are not formatted correctly:"); var MSG_INVALID = _( "Error: presence of invalid data prevent saving. Please make the corrections and try again." ); + var MSG_COPY_TO_CLIPBOARD = _( "Copy link to this preference" ); + var MSG_COPIED_TO_CLIPBOARD = _( "Link copied to the clipboard" ); [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %] [% Asset.js("js/ajax.js") | $raw %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js index d5db030e7b9..7c99c2e4b06 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js +++ b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js @@ -1,4 +1,4 @@ -/* global KOHA MSG_MADE_CHANGES CodeMirror MSG_CLICK_TO_EXPAND MSG_CLICK_TO_COLLAPSE to_highlight search_jumped humanMsg MSG_NOTHING_TO_SAVE MSG_MODIFIED MSG_SAVING MSG_SAVED_PREFERENCE dataTablesDefaults */ +/* global KOHA MSG_MADE_CHANGES CodeMirror MSG_CLICK_TO_EXPAND MSG_CLICK_TO_COLLAPSE to_highlight search_jumped humanMsg MSG_NOTHING_TO_SAVE MSG_MODIFIED MSG_SAVING MSG_SAVED_PREFERENCE dataTablesDefaults copyToClipboard MSG_COPIED_TO_CLIPBOARD MSG_COPY_TO_CLIPBOARD */ // We can assume 'KOHA' exists, as we depend on KOHA.AJAX KOHA.Preferences = { @@ -68,6 +68,10 @@ $( document ).ready( function () { KOHA.Preferences.Modified = true; } + $(".pref-cell").on("hover", function(){ + $(this).find(".permalink").toggle(); + }); + $( '.prefs-tab' ) .find( 'input.preference, textarea.preference' ).on('input', function () { if ( this.defaultValue === undefined || this.value != this.defaultValue ) mark_modified.call( this ); @@ -205,4 +209,17 @@ $( document ).ready( function () { email: true }); }); -} ); + + $(".permalink").on("click", function(e){ + e.preventDefault(); + copyToClipboard( $(this).attr("href") ); + $(this).attr("data-original-title", MSG_COPIED_TO_CLIPBOARD ) + .tooltip("show"); + }); + + $(".permalink").tooltip({ + delay: { "show": 100, "hide": 500 } + }).on("hidden.bs.tooltip", function(){ + $(this).attr("data-original-title", MSG_COPY_TO_CLIPBOARD ); + }); +}); \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js index 4c6f96c92bd..eef38da5eb9 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js +++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js @@ -232,3 +232,16 @@ function keep_text(clicked_index) { searchboxes[i].value = persist; } } + +// https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f +function copyToClipboard( text ){ + var el = document.createElement("textarea"); // Create a