Initial dev repository
[kcls-web.git] / opac / extras / mobile / mobile / js / account / holds.js
diff --git a/opac/extras/mobile/mobile/js/account/holds.js b/opac/extras/mobile/mobile/js/account/holds.js
new file mode 100644 (file)
index 0000000..f6c7bb7
--- /dev/null
@@ -0,0 +1,11 @@
+var __bind=function(f,n){return function(){return f.apply(n,arguments)}};module("account.account_holds",imports("eg.eg_api","plugin"),function(f){return $.fn.account_holds=function(){this.append($("<div>").holds());return this.refresh(function(){var n;if(typeof(n=f.auth.session==undefined?undefined:f.auth.session.user)!=="undefined"&&n!==null)this.publish("userid",[f.auth.session.user.id]);return false})}});
+module("account.holds",imports("eg.eg_api","eg.fieldmapper","template","plugin"),function(f,n,C){var o,y;y=C.template('<div class="my_hold <%= hold_activity %>" id="hold_id_<%= hold_id %>">\n\t<input type="checkbox" name="hold_id" value="<%= hold_id %>" />\n\t<span class="info_line">\n\t\t<span class="title" />\n\t\t<span class="author" />\n\t\t<span class="types" />\n\t</span>\n\t<div class="status_line">\n\t\t<span class="hold_status" /> at <%= hold_pickup %> until <%= hold_expire %>\n\t</div>\n</div>');
+o=function(g){g.title&&$(".title",this).text(g.title);g.author&&$(".author",this).text("/ "+g.author);if(g.types_of_resource)return $(".types",this).text("/ "+g.types_of_resource.join(", "))};return $.fn.holds=function(){var g,v,s,p,w,z,A;g=this;s=[];v=function(a){return f.openils("circ.hold.cancel",a,function(c){if(c!==1)return $().publish("prompt",["Hold was not cancelled",c])})};w=function(a){var c;c=a.id;return f.openils("circ.hold.update",a,function(b){if(b===c)return b;else{$().publish("prompt",
+["Hold was not updated",b]);return null}})};p=function(){return g.ajaxStop(function(){$(this).unbind("ajaxStop").refresh().publish("holds_summary");return false})};this.plugin("acct_holds").subscribe("userid",function(){this.is(":visible")&&this.refresh();return false}).subscribe("logout_event",function(){this.empty();return false}).refresh(function(){var a,c,b,d,i,e,q;this.empty().append(b=$('<form>\n\t<input type="submit" class="cancel" name="some" value="Cancel selected holds" />\n\t<input type="submit" class="cancel" name="all" value="Cancel all" />\n\t<input type="submit" class="suspend" name="some" value="Suspend selected holds" />\n\t<input type="submit" class="suspend" name="all" value="Suspend all" />\n\t<input type="submit" class="resume" name="some" value="Resume selected holds" />\n\t<input type="submit" class="resume" name="all" value="Resume all" />\n</form>'));
+c=$('.cancel[name="some"]',this).hide();a=$('.cancel[name="all"]',this).hide();q=$('.suspend[name="some"]',this).hide();e=$('.suspend[name="all"]',this).hide();i=$('.resume[name="some"]',this).hide();d=$('.resume[name="all"]',this).hide();b.parallel("holds details",{holds:f.openils("circ.holds.retrieve"),ouTree:f.openils("actor.org_tree.retrieve")},__bind(function(h){var j,t,x,B;s=h.holds;this.publish("holds",[h.holds]);j=[];x=h.holds;t=0;for(B=x.length;t<B;t++)(function(){var m=x[t];return j.push(function(){b.prepend(y({hold_id:m.id,
+hold_activity:m.frozen?"inactive":"active",hold_pickup:""+h.ouTree[m.pickup_lib].name,hold_expire:""+m.expire_time.slice(0,10)}));a.is(":visible")?c.show():a.show();if(m.frozen)d.is(":visible")?i.show():d.show();else e.is(":visible")?q.show():e.show();return function(l){var k,u;k=$("#hold_id_"+l.id);$(".hold_status",k).openils("hold status","circ.hold.status.retrieve",l.id,function(r){return this.text(r[1])});k=$(".info_line",k);if((u=l.hold_type)==="M")return k.openils("title_info","search.biblio.metarecord.mods_slim.retrieve",
+l.target,o);else if(u==="T")return k.openils("title info","search.biblio.record.mods_slim.retrieve",l.target,o);else if(u==="V")return k.openils("callnumber info","search.asset.call_number.retrieve",l.target,function(r){return this.openils("title info","search.biblio.record.mods_slim.retrieve",r.record,o)});else if(u==="C")return k.openils("copy info","search.asset.copy.retrieve",l.target,function(r){return this.openils("callnumber info","search.asset.call_number.retrieve",r.call_number,function(D){return this.openils("title info",
+"search.biblio.record.mods_slim.retrieve",D.record,o)})})}(m)}())})();return j},this)).error(function(h){return alert(JSON.stringify(h,null,"  "))});return false});this.delegate(".cancel[name=some]","click",function(){var a,c,b,d;d=$(this).parent().serializeArray();if(d.length){a=0;for(c=d.length;a<c;a++){b=d[a];v(b.value)}p()}else $(this).publish("notice",["Nothing was done because no holds were selected."]);return false});this.delegate(".cancel[name=all]","click",function(){var a;a=$(this).parent().find("input:checkbox");
+if(a.length){a.each(function(){return v($(this).val())});p()}else $(this).publish("notice",["Nothing was done because no holds were selected."]);return false});this.delegate(".suspend[name=some]","click",A=function(){var a,c,b,d,i,e,q,h,j;q=$(this).hasClass("suspend");j=$(this).parent().serializeArray();if(j.length){a=0;for(c=j.length;a<c;a++){h=j[a];d=s;b=0;for(i=d.length;b<i;b++){e=d[b];if(e.id===parseInt(h.value)){e.frozen=q;w(e);break}}}p()}else $(this).publish("notice",["Nothing was done because no holds were selected."]);
+return false});this.delegate(".suspend[name=all]","click",z=function(){var a,c;c=$(this).hasClass("suspend");a=$(this).parent();a=c?$(".my_hold.active",a).find("input:checkbox"):$(".my_hold.inactive",a).find("input:checkbox");if(a.length){a.each(function(){var b,d,i,e;d=s;b=0;for(i=d.length;b<i;b++){e=d[b];if(e.id===parseInt($(this).val())){e.frozen=c;w(e);break}}return[]});p()}else $(this).publish("notice",c?["Nothing was done because no active holds were found to suspend."]:["Nothing was done because no suspended holds were found to resume."]);
+return false});this.delegate(".resume[name=some]","click",A);return this.delegate(".resume[name=all]","click",z)}});