From 0d050c0d1c3070453ebe6e6f4879c91c76273491 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 12 Oct 2017 11:27:27 -0400 Subject: [PATCH] LP#1656036 Webstaff dynamic page titles Support page/tab titles applied by page controllers. Each title is composed of 2 optional components, a dynamic component and a context component. The dynamic component may be interpolated with real-time data (e.g. a patron's name) and the context is generally a page or tab-level value (e.g. Checkout). For example: "Smith, Jane - Checkout" Apply a title within a controller like so: egCore.strings.setPageTitle( egCore.strings.MY_DYNAMIC_TEMPLATE, egCore.strings.MY_CONTEXT_STRING, {foo : 'foo', bar : 'bar'} ); If no values are set, the default template-level title is applied. Signed-off-by: Bill Erickson Signed-off-by: Jason Boyer Signed-off-by: Kathy Lussier Conflicts: Open-ILS/src/templates/staff/base_js.tt2 Open-ILS/web/js/ui/default/staff/circ/patron/app.js --- Open-ILS/src/templates/staff/base.tt2 | 4 +- Open-ILS/src/templates/staff/base_js.tt2 | 2 + Open-ILS/src/templates/staff/cat/catalog/index.tt2 | 2 + Open-ILS/src/templates/staff/circ/patron/index.tt2 | 10 +++++ .../web/js/ui/default/staff/cat/catalog/app.js | 20 +++++++++ .../web/js/ui/default/staff/circ/patron/app.js | 15 +++++++ .../web/js/ui/default/staff/services/strings.js | 49 ++++++++++++++++++++-- 7 files changed, 98 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/templates/staff/base.tt2 b/Open-ILS/src/templates/staff/base.tt2 index f279759969..7ce42ae73f 100644 --- a/Open-ILS/src/templates/staff/base.tt2 +++ b/Open-ILS/src/templates/staff/base.tt2 @@ -10,7 +10,9 @@ display: none !important; } - [% l('Evergreen Staff [_1]', ctx.page_title) %] + + {{pageTitle || "[% ctx.page_title %]"}} diff --git a/Open-ILS/src/templates/staff/base_js.tt2 b/Open-ILS/src/templates/staff/base_js.tt2 index 324e452932..79735000d4 100644 --- a/Open-ILS/src/templates/staff/base_js.tt2 +++ b/Open-ILS/src/templates/staff/base_js.tt2 @@ -187,6 +187,8 @@ UpUp.start({ s.CONFIRM_CLEAR_PENDING_BODY = "[% l('Are you certain you want to clear these pending offline transactions? This action is irreversible. Transactions cannot be recovered after clearing!') %]"; s.LOCATION_NAME_OU_QUALIFIED = "[% l('{{location_name}} ({{owning_lib_shortname}})') %]"; s.CONFIRM_IN_HOUSE_NUM_USES_COUNT_TITLE = "[% l('Are you sure you want to record {{num_uses}} uses for this?') %]"; + s.PAGE_TITLE_DEFAULT = "[% l('Evergreen Staff Client') %]"; + s.PAGE_TITLE_DYNAMIC_AND_CONTEXT = "[% l('[_1] - [_2]', '{{dynamic}}', '{{context}}') %]"; }]); diff --git a/Open-ILS/src/templates/staff/cat/catalog/index.tt2 b/Open-ILS/src/templates/staff/cat/catalog/index.tt2 index a50822e778..bb7d232f29 100644 --- a/Open-ILS/src/templates/staff/cat/catalog/index.tt2 +++ b/Open-ILS/src/templates/staff/cat/catalog/index.tt2 @@ -60,6 +60,8 @@ s.SERIALS_ISSUANCE_FAIL_SAVE = "[% l('Failed to save issuance') %]"; s.SERIALS_ISSUANCE_SUCCESS_SAVE = "[% l('Issuance saved') %]"; + s.PAGE_TITLE_CATALOG_CONTEXT = "[% l('Catalog') %]"; + s.PAGE_TITLE_BIB_DETAIL = "[% l('Bib [_1]', '{{record_id}}') %]"; }]) diff --git a/Open-ILS/src/templates/staff/circ/patron/index.tt2 b/Open-ILS/src/templates/staff/circ/patron/index.tt2 index 5cb8a29e1f..94849f203e 100644 --- a/Open-ILS/src/templates/staff/circ/patron/index.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/index.tt2 @@ -66,6 +66,16 @@ angular.module('egCoreMod').run(['egStrings', function(s) { s.OPT_IN_DIALOG = "[% l('Does patron [_1], [_2] from [_3] ([_4]) consent to having their personal information shared with your library?', '{{family_name}}', '{{first_given_name}}', '{{org_name}}', '{{org_shortname}}') %]"; s.BUCKET_ADD_SUCCESS = "[% l('Successfully added [_1] users to bucket [_2].', '{{count}}', '{{name}}') %]"; s.BUCKET_ADD_FAIL = "[% l('Failed to add [_1] users to bucket [_2].', '{{count}}', '{{name}}') %]"; + s.PAGE_TITLE_PATRON_SEARCH = "[% l('Patron Search') %]"; + s.PAGE_TITLE_PATRON_NAME = "[% l('[_1], [_2] [_3]', '{{lname}}','{{fname}}','{{mname}}') %]"; + s.PAGE_TITLE_PATRON_CHECKOUT = "[% l('Checkout') %]"; + s.PAGE_TITLE_PATRON_MESSAGES = "[% l('Messages') %]"; + /* TODO: The "Other" page title could be smarter.. */ + s.PAGE_TITLE_PATRON_OTHER = "[% l('Other') %]"; + s.PAGE_TITLE_PATRON_BILLS = "[% l('Bills') %]"; + s.PAGE_TITLE_PATRON_HOLDS = "[% l('Holds') %]"; + s.PAGE_TITLE_PATRON_ITEMS_OUT = "[% l('Items Out') %]"; + s.PAGE_TITLE_PATRON_EDIT = "[% l('Edit') %]"; }]); diff --git a/Open-ILS/web/js/ui/default/staff/cat/catalog/app.js b/Open-ILS/web/js/ui/default/staff/cat/catalog/app.js index 95c1dd34ca..90d7fd1b94 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/catalog/app.js +++ b/Open-ILS/web/js/ui/default/staff/cat/catalog/app.js @@ -259,6 +259,19 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e $scope.record_id = $routeParams.record_id; $scope.summary_pane_record; + if ($scope.record_id) { + // TODO: Apply tab-specific title contexts + egCore.strings.setPageTitle( + egCore.strings.PAGE_TITLE_BIB_DETAIL, + egCore.strings.PAGE_TITLE_CATALOG_CONTEXT, + {record_id : $scope.record_id} + ); + } else { + // Default to title = Catalog + egCore.strings.setPageTitle( + egCore.strings.PAGE_TITLE_CATALOG_CONTEXT); + } + if ($routeParams.record_id) $scope.from_route = true; else $scope.from_route = false; @@ -535,6 +548,13 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e egHolds.fetch_holds(hold_ids).then($scope.hold_grid_data_provider.refresh); init_parts_url(); $location.update_path('/cat/catalog/record/' + $scope.record_id); + // update_path() bypasses the controller for path + // /cat/catalog/record/:record_id. Manually set title here too. + egCore.strings.setPageTitle( + egCore.strings.PAGE_TITLE_BIB_DETAIL, + egCore.strings.PAGE_TITLE_CATALOG_CONTEXT, + {record_id : $scope.record_id} + ); } else { delete $scope.record_id; $scope.from_route = false; diff --git a/Open-ILS/web/js/ui/default/staff/circ/patron/app.js b/Open-ILS/web/js/ui/default/staff/circ/patron/app.js index 4d4c728857..748cbfcf7d 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/patron/app.js +++ b/Open-ILS/web/js/ui/default/staff/circ/patron/app.js @@ -291,12 +291,27 @@ function($scope, $q , $location , $filter , egCore , egNet , egUser , egAlertDi if (patron_id) { $scope.patron_id = patron_id; return patronSvc.setPrimary($scope.patron_id) + .then(function() { + // the page title context label comes from the tab. + egCore.strings.setPageTitle( + egCore.strings.PAGE_TITLE_PATRON_NAME, + egCore.strings['PAGE_TITLE_PATRON_' + tab.toUpperCase()], + { lname : patronSvc.current.family_name(), + fname : patronSvc.current.first_given_name(), + mname : patronSvc.current.second_given_name() + } + ); + }) .then(function() {return patronSvc.checkAlerts()}) .then(redirectToAlertPanel) .then(function(){ $scope.ident_type_name = $scope.patron().ident_type().name() $scope.hasIdentTypeName = $scope.ident_type_name.length > 0; }); + } else { + // No patron, use the tab name as the page title. + egCore.strings.setPageTitle( + egCore.strings['PAGE_TITLE_PATRON_' + tab.toUpperCase()]); } return $q.when(); } diff --git a/Open-ILS/web/js/ui/default/staff/services/strings.js b/Open-ILS/web/js/ui/default/staff/services/strings.js index d9a801bc43..92d2aeb2f5 100644 --- a/Open-ILS/web/js/ui/default/staff/services/strings.js +++ b/Open-ILS/web/js/ui/default/staff/services/strings.js @@ -12,11 +12,54 @@ */ angular.module('egCoreMod').factory('egStrings', -['$interpolate', function($interpolate) { - return { +['$interpolate', '$rootScope', function($interpolate, $rootScope) { + var service = { + '$replace' : function(str, args) { if (!str) return ''; return $interpolate(str)(args); + }, + + /** + * Sets the page value. + * + * The title is composed of a dynamic and static component. + * The dynamic component may optionally be compiled via + * $interpolate'ion. + * + * The dynamic component is subject to truncation if it exceeds + * titleTruncLevel length and a context value is also applied. + * + * Only components that have values applied are used. When + * both have a value, they are combined into a single string + * separated by a - (by default). + */ + titleTruncLevel : 12, + setPageTitle : function(dynamic, context, dynargs) { + + if (!dynamic) { + $rootScope.pageTitle = context || service.PAGE_TITLE_DEFAULT; + return; + } + + if (dynargs) dynamic = service.$replace(dynamic, dynargs); + + if (!context) { + $rootScope.pageTitle = dynamic; + return; + } + + // only truncate when it's competing with a context value + dynamic = dynamic.substring(0, service.titleTruncLevel); + + $rootScope.pageTitle = service.$replace( + service.PAGE_TITLE_DYNAMIC_AND_CONTEXT, { + dynamic : dynamic, + context : context + } + ); } - } + }; + + return service; }]); -- 2.11.0