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(){
30 var mybibnum = $(this).attr("title");
31 var mynewtag = "newtag" + mybibnum;
32 var mytagid = "#" + mynewtag;
33 var mydata = {CGISESSID: readCookie('CGISESSID')}; // Someday this should be OPACSESSID
34 mydata[mynewtag] = $(mytagid).val(); // need [bracket] for variable property id
35 var response; // AJAX from server will assign value to response.
37 "/cgi-bin/koha/opac-tags.pl",
40 // alert("AJAX Response: " + data);
42 // alert("counts: " + response["added"] + response["deleted"] + response["errors"]);
43 KOHA.Tags.set_tag_status(
45 KOHA.Tags.common_status(response["added"], response["deleted"], response["errors"])
47 if (response.alerts) {
48 alert(response.alerts.join("\n\n"));
55 common_status : function(addcount, delcount, errcount) {
57 if (addcount && addcount > 0) {cstat += MSG_TAGS_ADDED + addcount + ". " ;}
58 if (delcount && delcount > 0) {cstat += MSG_TAGS_DELETED + delcount + ". " ;}
59 if (errcount && errcount > 0) {cstat += MSG_TAGS_ERRORS + errcount + ". " ;}
62 set_tag_status : function(tagid, newstatus) {
63 $(tagid).html(newstatus);
64 $(tagid).css({display:"inline"});
66 append_tag_status : function(tagid, newstatus) {
67 $(tagid).append(newstatus);
68 $(tagid).css({display:"inline"});
72 tagsdisabled : function(arg) {return (MSG_TAGS_DISABLED);},
73 scrubbed_all_bad : function(arg) {return (MSG_TAG_ALL_BAD);},
74 badparam : function(arg) {return (MSG_ILLEGAL_PARAMETER+" "+arg);},
75 scrubbed : function(arg) {return (MSG_TAG_SCRUBBED+" "+arg);},
76 failed_add_tag : function(arg) {return (MSG_ADD_TAG_FAILED+ " "+arg+" "+MSG_ADD_TAG_FAILED_NOTE);},
77 failed_delete : function(arg) {return (MSG_DELETE_TAG_FAILED+ " "+arg+" "+MSG_DELETE_TAG_FAILED_NOTE);},
78 login : function(arg) {return (MSG_LOGIN_REQUIRED);}
81 // Used to tag multiple items at once. The main difference
82 // is that status is displayed on a per item basis.
83 add_multitags_button : function(bibarray, tag){
84 var mydata = {CGISESSID: readCookie('CGISESSID')}; // Someday this should be OPACSESSID
85 for (var i = 0; i < bibarray.length; i++) {
86 var mynewtag = "newtag" + bibarray[i];
87 mydata[mynewtag] = tag;
89 var response; // AJAX from server will assign value to response.
91 "/cgi-bin/koha/opac-tags.pl",
95 $(".tagstatus").empty();
96 var bibErrors = false;
98 // Display the status for each tagged bib
99 for (var i = 0; i < bibarray.length; i++) {
100 var bib = bibarray[i];
101 var mytagid = "#newtag" + bib;
104 // Number of tags added.
106 var added = response[bib]["added"];
108 status = MSG_TAGS_ADDED + added + ". ";
109 KOHA.Tags.set_tag_status(mytagid + "_status", status);
112 // Show a link that opens an error dialog, if necessary.
113 var errors = response[bib]["errors"];
114 if (errors.length > 0) {
116 var errid = "tagerr_" + bib;
117 var errstat = "<a id=\"" + errid + "\" class=\"tagerror\" href=\"#\">";
118 errstat += MSG_TAGS_ERRORS + errors.length + ". ";
120 KOHA.Tags.append_tag_status(mytagid + "_status", errstat);
122 for (var e = 0; e < errors.length; e++){
128 $("#" + errid).click(function(){
135 if (bibErrors || response["global_errors"]) {
138 msg = MSG_MULTI_ADD_TAG_FAILED;
141 // Show global errors in a dialog.
142 if (response["global_errors"]) {
143 var global_errors = response["global_errors"];
145 for (var e = 0; e < global_errors.length; e++) {
147 msg += response.alerts[global_errors[e]];