Initial dev repository
[kcls-web.git] / opac / extras / mobile / js / opac / search_result.js
diff --git a/opac/extras/mobile/js/opac/search_result.js b/opac/extras/mobile/js/opac/search_result.js
new file mode 100644 (file)
index 0000000..8479520
--- /dev/null
@@ -0,0 +1,24 @@
+var __hasProp=Object.prototype.hasOwnProperty;
+module("opac.search_result",imports("eg.fieldmapper","eg.eg_api","template","plugin"),function(w,p,g){var q,j,i,r,l;l=g.template(
+   '<div class="summary_info" id="title_id_<%= title_id %>">\n\t<div class="info_line">\n\t\t'
+   + '<span class="link title" title="View details and place a hold for this title" />\n\t\t'
+   + '<span class="link author" title="Search other titles by this author" />\n\t\t'
+   + '<span class="pub_date" />\n\t\t'
+   + '<span class="resource_types" />\n\t</div>\n\t<div class="status_line">\n\t\t'
+   + '<span class="counts_avail" /> of <span class="counts_total" /> available.\n\t\t'
+   + '<span class="callnumber" title="Location and call number of this title" />\n\t</div>\n<hr/></div>');i=
+function(a){$(".title",this).text(a.title);$(".author",this).text(a.author);$(".pub_date",this).text(a.pubdate);return $(".resource_types",this).text(a.types_of_resource.join(", "))};r=function(a,h){var d,e,f;d=[];for(e in a)if(__hasProp.call(a,e)){f=a[e];Number(f.depth)===h&&d.push(f)}d=d[0];$(".counts_avail",this).text(d.available);return $(".counts_total",this).text(d.count)};j=function(a,h){var d,e,f,b,c;if(a.length){c=a[0];d=0;for(e=a.length;d<e;d++){b=a[d];if(b.callnumber!==c.callnumber)return""}d=
+h[c.org_id].name;e=0;for(f=a.length;e<f;e++){b=a[e];if(h[b.org_id].name!==d)return this.text(""+c.copylocation+" / "+c.callnumber)}e=0;for(f=a.length;e<f;e++){b=a[e];if(b.copylocation!==c.copylocation)return this.text(""+c.callnumber)}return this.text(""+d+" / "+c.copylocation+" / "+c.callnumber)}};q=function(a){for(var h,d,e,f;a.length>0;){d=(a.attr("id")||"").split(" ");h=0;for(e=d.length;h<e;h++){f=d[h];if(f=f.match(/^title_id_(\d+)/))return Number(f[1])}a=a.parent()}return null};return $.fn.result_summary=
+function(){var a,h,d,e,f;f=h=e=d="";a=this.plugin("search_settings").data("settings",{default_class:"keyword",term:"",item_type:"",limit:10,visibility_limit:1E3,offset:0,sort:"",sort_dir:"asc",depth:0,org_unit:1});this.subscribe("search",function(b){b=$.extend({},$(".search_settings").data("settings"),b);if(!b)return null;if(!b.term)return null;if(JSON.stringify(b)===JSON.stringify(a.data("request")))return null;$(".search_settings").data("settings",b);a.data("request",b);a.html('<hr/><div class="summary_bar"></div>\n<div class="summary_list"></div>');
+return a.find("div.summary_bar").parallel("search results",{ou_tree:p.openils("actor.org_tree.retrieve"),result:p.openils("search",b)},function(c){var m,n,k,o,x,u;this.summary_bar({request:b,result:c.result});a.data("result",c.result);a.publish("search_results",[c.result]);m=a.find("div.summary_list");u=Number(b.org_unit);n=[];o=c.result.ids;k=0;for(x=o.length;k<x;k++)(function(){var y=o[k];return n.push(function(){m.append(l({title_id:y}));return function(s){var t;t=$("#title_id_"+s);$(".info_line",
+t).openils("title info","search.biblio.record.mods_slim.retrieve",s,i);$(".status_line",t).openils("title availability","search.biblio.record.copy_count",{id:s,location:u},function(v){return r.call(this,v,b.depth)});return $(".callnumber",t).openils("call numbers","search.biblio.copy_location_counts.summary.retrieve",{id:s,org_id:u,depth:b.depth},function(v){return j.call(this,v,c.ou_tree)})}(y)}())})();return n})});this.click(function(b){var c,m,n,k,o;c=$(b.target);n=q(c);m=$(b.currentTarget);k=
+m.data("request");if(c.hasClass("title")&&n&&k)thunk(imports("login_window","opac.edit_hold"),function(){$("#edit_hold").plugin()||$("#edit_hold").edit_hold();$("#login_window").plugin()||$("#login_window").login_window();return m.publish("hold_create",[n,k.org_unit,k.depth])});else if(c.hasClass("author")&&(o=c.text()))m.publish("search",[$.extend({},m.data("settings"),{default_class:"author",term:o,offset:0,type:"advanced"})]);return false});this.subscribe("ou",function(b){var c;$.pushState({library:JSON.stringify([b.id,
+b.name,b.depth,b.type])});d=b.id;e=b.name;h=b.depth;f=b.type;if(!this.is(":visible"))return false;if(c=a.data("request")){c=$.extend({},c,{org_unit:b.id,org_name:b.name,depth:b.depth,org_type:b.type});this.publish("search",[c])}return false});this.subscribe("clear_data",function(){a.removeData("request");return false});return this.refresh(function(){return false})}});
+module("opac.summary_bar",imports("template"),function(w){var p;p=w.template(
+   "<% if (total <= 0) { %>\n\t<span>No titles were found.</span>\n<% } else if (pgtotal === 1 && actual === 1) { %>"
+   + "\n\t<span><%= actual %> title was found.</span>\n<% } else if (pgtotal === 1) { %>\n\t<span><%= actual %> titles were found.</span>\n"
+   + "<% } else if (actual <= 0) { %>\n\t<span>End of your search.</span>\n<% } else { %>"
+   + "\n\t<span>Page <%= pgnumber %> of <%= pgtotal %></span>\n<% } %>");return $.fn.summary_bar=function(g){var q,
+j,i,r,l,a;a=g.result.count;q=g.result.ids.length;i=Number(g.request.offset);j=Number(g.request.limit);r=1+Math.floor(i/j);l=Math.ceil(a/j);l>1&&i!==0&&this.each(function(){return $(this).append($('<span class="link start" title="Go to first page">    |<<  </span>').click(function(){g=$.extend({},g.request,{offset:0});$(this).publish("search",[g]);return false}))});l>1&&i!==0&&this.each(function(){return $(this).append($(
+   '<span class="link prev"  title="Go to previous page">  <<  </span>').click(function(){g=
+$.extend({},g.request,{offset:i-j});$(this).publish("search",[g]);return false}))});this.each(function(){return $(this).append(p({total:a,actual:q,pgnumber:r,pgtotal:l}))});l>1&&a-i>j&&this.each(function(){return $(this).append($('<span class="link next"  title="Go to next page">      >>  </span>').click(function(){g=$.extend({},g.request,{offset:i+j});$(this).publish("search",[g]);return false}))});return this}});