]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/services/strings.js
LP#1736269: Mark Missing Pieces is non-functional
[working/Evergreen.git] / Open-ILS / web / js / ui / default / staff / services / strings.js
1 /**
2  * egStrings : service for tracking page-specific string translations.
3  *
4  * Convience functions embedded herein are prefixed with "$" to avoid
5  * collisions with string keys, which are linked directly to the 
6  * service.
7  *
8  * egStrings.A_STRING = 'hello, world {{foo}';
9  *
10  * egStrings.$replace(egStrings.A_STRING, {foo : 'bar'})
11  *
12  */
13
14 angular.module('egCoreMod').factory('egStrings', 
15 ['$interpolate', '$rootScope', function($interpolate, $rootScope) { 
16     var service = {
17
18         '$replace' : function(str, args) {
19             if (!str) return '';
20             return $interpolate(str)(args);
21         },
22
23         /**
24          * Sets the page <title> value.  
25          *
26          * The title is composed of a dynamic and static component.
27          * The dynamic component may optionally be compiled via
28          * $interpolate'ion.  
29          *
30          * The dynamic component is subject to truncation if it exceeds 
31          * titleTruncLevel length and a context value is also applied.
32          *
33          * Only components that have values applied are used.  When
34          * both have a value, they are combined into a single string
35          * separated by a - (by default).
36          */
37         titleTruncLevel : 12,
38         setPageTitle : function(dynamic, context, dynargs) {
39
40             if (!dynamic) {
41                 $rootScope.pageTitle = context || service.PAGE_TITLE_DEFAULT;
42                 return;
43             }
44
45             if (dynargs) dynamic = service.$replace(dynamic, dynargs);
46
47             if (!context) {
48                 $rootScope.pageTitle = dynamic;
49                 return;
50             }
51
52             // only truncate when it's competing with a context value
53             dynamic = dynamic.substring(0, service.titleTruncLevel);
54
55             $rootScope.pageTitle = service.$replace(
56                 service.PAGE_TITLE_DYNAMIC_AND_CONTEXT, {
57                     dynamic : dynamic,
58                     context : context
59                 }
60             );
61         }
62     };
63
64     return service;
65 }]);