1 if (typeof KOHA == "undefined" || !KOHA) {
6 * A namespace for Tags related functions.
7 * readCookie is expected to already be declared. That's why the assignment below is unscoped.
8 * readCookie should be from basket.js or undefined.
11 url: "/cgi-bin/koha/opac-tags.pl",
16 if (typeof(readCookie) == "undefined") {
17 readCookie = function (name) { // from http://www.quirksmode.org/js/cookies.html
18 var nameEQ = name + "=";
19 var ca = document.cookie.split(';');
20 for (var i=0;i < ca.length;i++) {
22 while (c.charAt(0)==' '){ c = c.substring(1,c.length); }
23 if (c.indexOf(nameEQ) == 0){ return c.substring(nameEQ.length,c.length); }
29 add_tag_button: function(bibnum, tag){
30 var mynewtag = "newtag" + bibnum;
31 var mytagid = "#" + mynewtag;
32 var mydata = {CGISESSID: readCookie('CGISESSID')}; // Someday this should be OPACSESSID
33 mydata[mynewtag] = tag; // need [bracket] for variable property id
34 var response; // AJAX from server will assign value to response.
36 "/cgi-bin/koha/opac-tags.pl",
39 // alert("AJAX Response: " + data);
41 // alert("counts: " + response["added"] + response["deleted"] + response["errors"]);
42 KOHA.Tags.set_tag_status(
44 KOHA.Tags.common_status(response["added"], response["deleted"], response["errors"])
46 if (response.alerts) {
47 alert(response.alerts.join("\n\n"));
54 common_status : function(addcount, delcount, errcount) {
56 if (addcount && addcount > 0) {cstat += MSG_TAGS_ADDED + addcount + ". " ;}
57 if (delcount && delcount > 0) {cstat += MSG_TAGS_DELETED + delcount + ". " ;}
58 if (errcount && errcount > 0) {cstat += MSG_TAGS_ERRORS + errcount + ". " ;}
61 set_tag_status : function(tagid, newstatus) {
62 $(tagid).html(newstatus);
65 append_tag_status : function(tagid, newstatus) {
66 $(tagid).append(newstatus);
69 clear_all_tag_status : function() {
70 $(".tagstatus").empty().hide();
74 tagsdisabled : function(arg) {return (MSG_TAGS_DISABLED);},
75 scrubbed_all_bad : function(arg) {return (MSG_TAG_ALL_BAD);},
76 badparam : function(arg) {return (MSG_ILLEGAL_PARAMETER+" "+arg);},
77 scrubbed : function(arg) {return (MSG_TAG_SCRUBBED+" "+arg);},
78 failed_add_tag : function(arg) {return (MSG_ADD_TAG_FAILED+ " '"+arg+"'. \n"+MSG_ADD_TAG_FAILED_NOTE);},
79 failed_delete : function(arg) {return (MSG_DELETE_TAG_FAILED+ " '"+arg+"'. \n"+MSG_DELETE_TAG_FAILED_NOTE);},
80 login : function(arg) {return (MSG_LOGIN_REQUIRED);}
83 // Used to tag multiple items at once. The main difference
84 // is that status is displayed on a per item basis.
85 add_multitags_button : function(bibarray, tag){
86 var mydata = {CGISESSID: readCookie('CGISESSID')}; // Someday this should be OPACSESSID
87 for (var i = 0; i < bibarray.length; i++) {
88 var mynewtag = "newtag" + bibarray[i];
89 mydata[mynewtag] = tag;
91 var response; // AJAX from server will assign value to response.
93 "/cgi-bin/koha/opac-tags.pl",
97 KOHA.Tags.clear_all_tag_status();
98 var bibErrors = false;
100 // Display the status for each tagged bib
101 for (var i = 0; i < bibarray.length; i++) {
102 var bib = bibarray[i];
103 var mytagid = "#newtag" + bib;
106 // Number of tags added.
108 var added = response[bib]["added"];
110 status = MSG_TAGS_ADDED + added + ". ";
111 KOHA.Tags.set_tag_status(mytagid + "_status", status);
114 // Show a link that opens an error dialog, if necessary.
115 var errors = response[bib]["errors"];
116 if (errors.length > 0) {
118 var errid = "tagerr_" + bib;
119 var errstat = "<a id=\"" + errid + "\" class=\"tagerror\" href=\"#\">";
120 errstat += MSG_TAGS_ERRORS + errors.length + ". ";
122 KOHA.Tags.append_tag_status(mytagid + "_status", errstat);
124 for (var e = 0; e < errors.length; e++){
130 $("#" + errid).click(function(){
137 if (bibErrors || response["global_errors"]) {
140 msg = MSG_MULTI_ADD_TAG_FAILED;
143 // Show global errors in a dialog.
144 if (response["global_errors"]) {
145 var global_errors = response["global_errors"];
147 for (var e = 0; e < global_errors.length; e++) {
149 msg += response.alerts[global_errors[e]];