]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/booking/common.js
Stab at matching up reservation.js with the pluralized, JSON-compliant Dojo NLS file
[working/Evergreen.git] / Open-ILS / web / js / ui / default / booking / common.js
1 /* Quick and dirty way to localize some strings; not recommended for reuse.
2  * I'm sure dojo provides a better mechanism for this, but at the moment
3  * this is faster to implement anew than figuring out the Right way to do
4  * the same thing w/ dojo.
5  */
6 function init_auto_l10n(el) {
7     function do_it(myel, cls) {
8         if (cls) {
9             var clss = cls.split(" ");
10             for (var k in clss) {
11                 var parts = clss[k].match(/^AUTO_ATTR_([A-Z]+)_.+$/);
12                 if (parts && localeStrings[clss[k]]) {
13                     myel.setAttribute(
14                         parts[1].toLowerCase(), localeStrings[clss[k]]
15                     );
16                 } else if (clss[k].match(/^AUTO_/) && localeStrings[clss[k]]) {
17                     myel.innerHTML = localeStrings[clss[k]];
18                 }
19             }
20         }
21     }
22
23     for (var i in el.attributes) {
24         if (el.attributes[i].nodeName == "class") {
25             do_it(el, el.attributes[i].value);
26             break;
27         }
28     }
29     for (var i in el.childNodes) {
30         if (el.childNodes[i].nodeType == 1) { // element node?
31             init_auto_l10n(el.childNodes[i]); // recurse!
32         }
33     }
34 }
35
36 function get_keys(L) { var K = []; for (var k in L) K.push(k); return K; }
37 function hide_dom_element(e) { e.style.display = "none"; };
38 function reveal_dom_element(e) { e.style.display = ""; };
39 function formal_name(u) {
40     var name = u.family_name() + ", " + u.first_given_name();
41     if (u.second_given_name())
42         name += (" " + u.second_given_name());
43     return name;
44 }
45 function humanize_timestamp_string(ts) {
46     /* For now, this discards time zones. */
47     var parts = ts.split("T");
48     var timeparts = parts[1].split("-")[0].split(":");
49     return parts[0] + " " + timeparts[0] + ":" + timeparts[1];
50 }
51 function is_ils_event(e) { return (e.ilsevent != undefined); }
52 function is_ils_actor_card_error(e) {
53     return (e.textcode == "ACTOR_CARD_NOT_FOUND");
54 }
55 function my_ils_error(leader, e) {
56     var s = leader + "\n";
57     var keys = [
58         "ilsevent", "desc", "textcode", "servertime", "pid", "stacktrace"
59     ];
60     for (var i in keys) {
61         if (e[keys[i]]) s += ("\t" + keys[i] + ": " + e[keys[i]] + "\n");
62     }
63     return s;
64 }
65 function set_datagrid_empty_store(grid, flattener) {
66     grid.setStore(
67         new dojo.data.ItemFileReadStore(
68             {"data": flattener([])}
69         )
70     );
71 }