Opens Search Result Records in New Tab
authorAndrew Coomes <acoomes@catalystitservices.com>
Tue, 22 Jan 2013 22:02:07 +0000 (14:02 -0800)
committerJustin Douma <jdouma@catalystitservices.com>
Fri, 25 Jan 2013 01:59:27 +0000 (17:59 -0800)
A new setting, new_tab_without_ctrl, was created to set if a ctrl-click
is required to open a search result item in a new tab.  By default,
ctrl-click is required for a new tab.
Signed-off-by: Andrew Coomes <acoomes@catalystitservices.com>
Signed-off-by: Kyle Tomita <ktomita@catalystitservices.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.add-option-for-new-tab-without-ctrl.sql [new file with mode: 0644]
Open-ILS/src/templates/opac/parts/js.tt2
Open-ILS/src/templates/opac/parts/result/table.tt2
docs/RELEASE_NOTES_NEXT/search_results_new_tab.txt [new file with mode: 0644]

index dea0145..bc5b7d7 100644 (file)
@@ -309,6 +309,9 @@ sub load_rresults {
     # find the last record in the set, then redirect
     my $find_last = $cgi->param('find_last');
 
+    # Set check_ctrl_click as is_not_ctrl_click value in ctx
+    $ctx->{is_not_ctrl_click} = check_ctrl_click( $self );
+
     $self->timelog("Loading results");
     # load bookbag metadata, if requested.
     if (my $bbag_err = $self->load_rresults_bookbag) {
@@ -490,6 +493,21 @@ sub load_rresults {
     return Apache2::Const::OK;
 }
 
+# Checks the ctrl-click option status ( on - left click opens new tab, or off - ctrl-click opens new tab )
+sub check_ctrl_click {
+    my $self = shift || 0;
+    my $ctx = $self->ctx;
+    my $ou = 0;
+    my $sname = 'opac.new_tab_without_ctrl';
+    if ( $ctx->{is_staff} ) {
+        $ou = $ctx->{user}->ws_ou;
+    } else {
+        $ou = $self->_get_search_lib();
+    }
+    my $setting_status = $ctx->{get_org_setting}->( $ou, $sname ) ? 1 : 0;
+    return $setting_status;
+}
+
 # If the calling search results in 1 record and the client
 # is configured to do so, redirect the search results to 
 # the record details page.
index 25fa292..3e15462 100644 (file)
@@ -87,7 +87,7 @@ CREATE TRIGGER no_overlapping_deps
     BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
     FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates');
 
-INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0751', :eg_version); -- berick/senator
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('XXXX', :eg_version); -- catalyst/search_results_new_tab
 
 CREATE TABLE config.bib_source (
        id              SERIAL  PRIMARY KEY,
index 8805181..1bc5a99 100644 (file)
@@ -4711,7 +4711,18 @@ INSERT into config.org_unit_setting_type
     ),
     'string', null)
 
-;
+   ,( 'opac.new_tab_without_ctrl', 'opac',
+       oils_i18n_gettext(
+           'opac.new_tab_without_ctrl',
+           'Enable opening a new tab when clicking on records from the search results page without holding ctrl.',
+           'coust',
+           'label'),
+       oils_i18n_gettext(
+           'opac.new_tab_without_ctrl',
+           'By enabling this option, a new tab will open when clicking on records from the search results page without ctrl.  It will override the default of ctrl + left click for new tab.  The new tab feature is only for the search results page and is disabled on the Patron holds tab.',
+           'coust',
+           'description'),
+       'bool', null);
 
 UPDATE config.org_unit_setting_type
     SET view_perm = (SELECT id FROM permission.perm_list
@@ -4740,8 +4751,10 @@ INSERT INTO actor.org_unit_setting (org_unit, name, value) VALUES (
     ,(1, 'cat.label.font.size', 10)
     ,(1, 'cat.label.font.weight', '"normal"')
     ,(1, 'circ.grace.extend', 'true')
-;
 
+   --Optionalized new tab for search results
+       ,(1, 'opac.new_tab_without_ctrl', 'false')
+;
 
 -- Staged Search (for default matchpoints)
 INSERT INTO search.relevance_adjustment (field, bump_type, multiplier) VALUES(1, 'first_word', 1.5);
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.add-option-for-new-tab-without-ctrl.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.add-option-for-new-tab-without-ctrl.sql
new file mode 100644 (file)
index 0000000..d02b405
--- /dev/null
@@ -0,0 +1,22 @@
+BEGIN;
+
+   INSERT INTO config.org_unit_setting_type ( name, grp, label, description, datatype ) VALUES (
+       'opac.new_tab_without_ctrl', 'opac',
+           oils_i18n_gettext(
+               'opac.new_tab_without_ctrl',
+               'Enable opening a new tab when clicking on records from the search results page without holding ctrl.',
+               'coust',
+               'label'),
+           oils_i18n_gettext(
+               'opac.new_tab_without_ctrl',
+               'By enabling this option, a new tab will open when clicking on records from the search results page without ctrl.  It will override the default of ctrl + left click for new tab.  The new tab feature is only for the search results page and is disabled on the Patron holds tab.',
+               'coust',
+               'description'),
+           'bool'
+   );
+
+   INSERT INTO actor.org_unit_setting (org_unit, name, value) VALUES (
+           1, 'opac.new_tab_without_ctrl', 'false'
+   );
+
+COMMIT;
index d6cacbe..f443e90 100644 (file)
 <script type="text/javascript" src="[% ctx.media_prefix %]/js/dojo/dojo/dojo.js?[% ctx.eg_cache_hash %]"></script>
 <script type="text/javascript" src="[% ctx.media_prefix %]/js/dojo/dojo/openils_dojo.js?[% ctx.eg_cache_hash %]"></script>
 
+[% IF ctx.is_staff %]
+    <script type="text/javascript">
+
+       var setting_value = [% ctx.is_not_ctrl_click %];
+       var element_tag = dojo.query( "#result_table_div a.result_title" );
+
+        if ( setting_value === 0 ) {
+            // If the ou setting value is false, call new_tab when a result title link is ctrl-clicked.
+            element_tag.connect( "onclick", function ( e ) {
+                if( e.ctrlKey ) {
+                    if ( !new_tab( this ) ) {
+                        set_url_as_href( this );
+                   }
+                } else {
+                    set_url_as_href( this );
+                }
+            }
+           );
+        } else if ( setting_value === 1 ) {
+            // If the ou setting is true, call new_tab when a result title link is left clicked.
+            element_tag.connect( "onclick", function ( e ) {
+                if ( !new_tab( this ) ) {
+                    set_url_as_href( this );
+               }
+            }
+            );
+        }
+
+        // New tab function; opens a fresh tab with given URL and tab name.
+        function new_tab( element ) {
+            var tabName = element.getAttribute( 'tabname' );
+            var url = element.getAttribute( 'url' );
+            var content_params = {
+                'override_tab_lock': true,
+                'no_xulG': false,
+                'show_print_button': false,
+                'show_nav_buttons': false,
+                'opac_url': "oils://remote" + url
+            };
+           var result = true;
+           try {
+               result = xulG.new_tab( xulG.urls.XUL_OPAC_WRAPPER, {}, content_params );
+           } catch ( err ) {
+               result = false;
+           }
+           return result;
+        }
+
+        // Set url as href function; sets the url value as the href value
+        function set_url_as_href( element ) {
+            element.setAttribute( "href", element.getAttribute( 'url' ) )
+        }
+
+    </script>
+[% END %]
+
 [%- # So the following works in Mozilla and Chrome, but not in IE8.
     # Seems like it /should/ work anywhere, though, and obviate the
     # next three script tags: %]
index e0f3f2a..6d0b574 100644 (file)
                                             </td>
                                             <td class='result_table_title_cell' name='result_table_title_cell'>
                                                 <div class="bold">
-                                                    <a name='record_[% rec.id %]' name='item_title'
-                                                        href="[% mkurl(ctx.opac_root _ '/record/' _ rec.id) %]"
-                                                        [% HTML.attributes(title => l('Display record details for "[_1]"', attrs.title)) %]
-                                                        class='search_link'>[% attrs.title | html %]</a>
+                                                    [% IF ctx.is_staff %]
+                                                        <a name = 'record_[% rec.id %]'
+                                                            style="text-decoration: underline; cursor: pointer"
+                                                            url = "[% mkurl(ctx.opac_root _ '/record/' _ rec.id) %]"
+                                                            tabname = "Bib Record: [% rec.id %]"
+                                                            recId = "[% rec.id %]"
+                                                            [% HTML.attributes(title => l( 'Display record details for "[_1]"', attrs.title ) ) %]
+                                                            class = 'search_link result_title'>[% attrs.title | html %]
+                                                        </a>
+                                                    [% END %]
+                                                    [% IF !ctx.is_staff %]
+                                                        <a name='record_[% rec.id %]' name='item_title'
+                                                            href="[% mkurl(ctx.opac_root _ '/record/' _ rec.id) %]"
+                                                            [% HTML.attributes(title => l('Display record details for "[_1]"', attrs.title)) %]
+                                                            class='search_link'>[% attrs.title | html %]
+                                                        </a>
+                                                    [% END %]
                                                 </div>
 [%-
 FOR entry IN attrs.graphic_titles;
diff --git a/docs/RELEASE_NOTES_NEXT/search_results_new_tab.txt b/docs/RELEASE_NOTES_NEXT/search_results_new_tab.txt
new file mode 100644 (file)
index 0000000..28ed3ae
--- /dev/null
@@ -0,0 +1,11 @@
+New feature: Search result new tab option
+================================
+When browsing search results, a user may want to open the title link in a new tab or in an existing tab.
+This feature gives the option to be set to require ctrl-click to open a new tab or simply just a click.  The
+option is set in the Library Settings Editor.
+
+Group: OPAC
+Setting: "Enable opening a new tab when clicking on records from the search results page without holding ctrl"
+Value: True/False
+
+Having the option set to False give it similar functionality to most web browsers.