Initial dev repository
[kcls-web.git] / opac / extras / mobile / mobile / js / opac / search_result.js
diff --git a/opac/extras/mobile/mobile/js/opac/search_result.js b/opac/extras/mobile/mobile/js/opac/search_result.js
new file mode 100644 (file)
index 0000000..c92c20d
--- /dev/null
@@ -0,0 +1,12 @@
+var __hasProp=Object.prototype.hasOwnProperty;
+module("opac.search_result",imports("eg.fieldmapper","eg.eg_api","template","plugin"),function(y,q,g){var r,k,i,s,m;m=g.template('<div class="summary_info" id="title_id_<%= title_id %>">\n\t<div class="info_line">\n\t\t<a class="link title" title="View details and place a hold for this title" />\n\t\t<a 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</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(", "))};s=function(a,h){var c,f,d;c=[];for(f in a)if(__hasProp.call(a,f)){d=a[f];Number(d.depth)===h&&c.push(d)}c=c[0];$(".counts_avail",this).text(c.available);return $(".counts_total",this).text(c.count)};k=function(a,h){var c,f,d,j,b,e;if(a.length){b=a[0];d=a;c=0;for(f=d.length;c<f;c++){j=d[c];if(j.callnumber!==b.callnumber)return""}e=
+h[b.org_id].name;d=a;c=0;for(f=d.length;c<f;c++){j=d[c];if(h[j.org_id].name!==e)return this.text(""+b.copylocation+" / "+b.callnumber)}d=a;c=0;for(f=d.length;c<f;c++){j=d[c];if(j.copylocation!==b.copylocation)return this.text(""+b.callnumber)}return this.text(""+e+" / "+b.copylocation+" / "+b.callnumber)}};r=function(a){for(var h,c,f,d;a.length>0;){f=(a.attr("id")||"").split(" ");h=0;for(c=f.length;h<c;h++){d=f[h];if(d=d.match(/^title_id_(\d+)/))return Number(d[1])}a=a.parent()}return null};return $.fn.result_summary=
+function(){var a,h,c,f,d,j;d=h=f=c="";j=0;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){if(JSON.stringify(b)===JSON.stringify(a.data("request")))return null;a.data("request",b);a.html('<div class="summary_bar"></div>\n<div class="summary_list"></div>');return a.find("div.summary_bar").parallel("search results",{ou_tree:q.openils("actor.org_tree.retrieve"),
+result:q.openils("search",b)},function(e){var l,n,o,p,u,w;this.summary_bar({request:b,result:e.result});a.data("result",e.result);a.publish("search_results",[e.result]);l=a.find("div.summary_list");w=Number(b.org_unit);u=0;p=e.result.ids;n=0;for(o=p.length;n<o;n++)(function(){var z=p[n];if(j<++u)j=u;l.append(m({title_id:z}));return function(v,A){var t;t=$("#title_id_"+v);$(".title, .author",t).attr("tabindex",A);$(".info_line",t).openils("title info","search.biblio.record.mods_slim.retrieve",v,i);
+$(".status_line",t).openils("title availability","search.biblio.record.copy_count",{id:v,location:w},function(x){return s.call(this,x,b.depth)});return $(".callnumber",t).openils("call numbers","search.biblio.copy_location_counts.summary.retrieve",{id:v,org_id:w,depth:b.depth},function(x){return k.call(this,x,e.ou_tree)})}(z,u)})();$(".title:first",l).focus();return null})});this.delegate(".title, .author","keyup",function(b){switch(b.keyCode){case 13:$(this).click();break}return false});this.click(function(b){var e,
+l,n,o,p;e=$(b.target);n=r(e);l=$(b.currentTarget);o=l.data("request");if(e.hasClass("title")&&n&&o)thunk(imports("login_window","opac.edit_hold"),function(){$("#edit_hold").plugin()||$("#edit_hold").edit_hold();$("#login_window").plugin()||$("#login_window").login_window();return l.publish("hold_create",[n,o.org_unit,o.depth])});else if(e.hasClass("author")&&(p=e.text()))l.publish("search",[$.extend({},l.data("settings"),{default_class:"author",term:p,offset:0,type:"advanced"})]);return false});this.subscribe("ou",
+function(b){var e;$.pushState({library:JSON.stringify([b.id,b.name,b.depth,b.type])});c=b.id;f=b.name;h=b.depth;d=b.type;if(!this.is(":visible"))return false;if(e=a.data("request")){e=$.extend({},e,{org_unit:b.id,org_name:b.name,depth:b.depth,org_type:b.type});this.publish("search",[e])}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(y){var q;q=y.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 r,
+k,i,s,m,a;a=g.result.count;r=g.result.ids.length;i=Number(g.request.offset);k=Number(g.request.limit);s=1+Math.floor(i/k);m=Math.ceil(a/k);m>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}))});m>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-k});$(this).publish("search",[g]);return false}))});this.each(function(){return $(this).append(q({total:a,actual:r,pgnumber:s,pgtotal:m}))});m>1&&a-i>k&&this.each(function(){return $(this).append($('<span class="link next"  title="Go to next page">      >>  </span>').click(function(){g=$.extend({},g.request,{offset:i+k});$(this).publish("search",[g]);return false}))});return this}});