1 if (typeof KOHA == "undefined" || !KOHA) {
6 * A namespace for Tags related functions.
9 url: "/cgi-bin/koha/opac-tags.pl",
15 add_tag_button: function(bibnum, tag){
16 var mynewtag = "newtag" + bibnum;
17 var mytagid = "#" + mynewtag;
19 mydata[mynewtag] = tag;
20 var response; // AJAX from server will assign value to response.
22 "/cgi-bin/koha/opac-tags.pl",
25 // alert("AJAX Response: " + data);
27 // alert("counts: " + response["added"] + response["deleted"] + response["errors"]);
28 KOHA.Tags.set_tag_status(
30 KOHA.Tags.common_status(response["added"], response["deleted"], response["errors"])
32 if (response.alerts) {
33 alert(response.alerts.join("\n\n"));
40 common_status : function(addcount, delcount, errcount) {
42 if (addcount && addcount > 0) {cstat += MSG_TAGS_ADDED + addcount + ". " ;}
43 if (delcount && delcount > 0) {cstat += MSG_TAGS_DELETED + delcount + ". " ;}
44 if (errcount && errcount > 0) {cstat += MSG_TAGS_ERRORS + errcount + ". " ;}
47 set_tag_status : function(tagid, newstatus) {
48 $(tagid).html(newstatus);
51 append_tag_status : function(tagid, newstatus) {
52 $(tagid).append(newstatus);
55 clear_all_tag_status : function() {
56 $(".tagstatus").empty().hide();
60 tagsdisabled : function(arg) {return (MSG_TAGS_DISABLED);},
61 scrubbed_all_bad : function(arg) {return (MSG_TAG_ALL_BAD);},
62 badparam : function(arg) {return (MSG_ILLEGAL_PARAMETER+" "+arg);},
63 scrubbed : function(arg) {return (MSG_TAG_SCRUBBED+" "+arg);},
64 failed_add_tag : function(arg) {return (MSG_ADD_TAG_FAILED+ " '"+arg+"'. \n"+MSG_ADD_TAG_FAILED_NOTE);},
65 failed_delete : function(arg) {return (MSG_DELETE_TAG_FAILED+ " '"+arg+"'. \n"+MSG_DELETE_TAG_FAILED_NOTE);},
66 login : function(arg) {return (MSG_LOGIN_REQUIRED);}
69 // Used to tag multiple items at once. The main difference
70 // is that status is displayed on a per item basis.
71 add_multitags_button : function(bibarray, tag){
73 for (var i = 0; i < bibarray.length; i++) {
74 var mynewtag = "newtag" + bibarray[i];
75 mydata[mynewtag] = tag;
77 var response; // AJAX from server will assign value to response.
79 "/cgi-bin/koha/opac-tags.pl",
83 KOHA.Tags.clear_all_tag_status();
84 var bibErrors = false;
86 // Display the status for each tagged bib
87 for (var i = 0; i < bibarray.length; i++) {
88 var bib = bibarray[i];
89 var mytagid = "#newtag" + bib;
92 // Number of tags added.
94 var added = response[bib]["added"];
96 status = MSG_TAGS_ADDED + added + ". ";
97 KOHA.Tags.set_tag_status(mytagid + "_status", status);
100 // Show a link that opens an error dialog, if necessary.
101 var errors = response[bib]["errors"];
102 if (errors.length > 0) {
104 var errid = "tagerr_" + bib;
105 var errstat = "<a id=\"" + errid + "\" class=\"tagerror\" href=\"#\">";
106 errstat += MSG_TAGS_ERRORS + errors.length + ". ";
108 KOHA.Tags.append_tag_status(mytagid + "_status", errstat);
110 for (var e = 0; e < errors.length; e++){
116 $("#" + errid).click(function(){
123 if (bibErrors || response["global_errors"]) {
126 msg = MSG_MULTI_ADD_TAG_FAILED;
129 // Show global errors in a dialog.
130 if (response["global_errors"]) {
131 var global_errors = response["global_errors"];
133 for (var e = 0; e < global_errors.length; e++) {
135 msg += response.alerts[global_errors[e]];