bb90bb0cffe56b31c07413e8c72ebc73dad01459
[working/Evergreen.git] / Open-ILS / web / js / ui / default / opac / ebook_api / ebook.js
1 // define our classes
2 function Vendor(name) {
3     this.name = name;
4     this.ebooks = [];
5 }
6
7 function Ebook(vendor, id) {
8     this.vendor = vendor;
9     this.id = id; // external ID for this title
10     this.rec_id;  // bre.id for this title's MARC record
11     this.title;   // title of ebook
12     this.author;  // author of ebook
13     this.avail;   // availability info for this title
14     this.holdings = {}; // holdings info
15     this.conns = {}; // references to Dojo event connection for performing actions with this ebook
16
17 }
18
19 Ebook.prototype.getDetails = function(callback) {
20     var ses = dojo.cookie(this.vendor);
21     var ebook = this;
22     new OpenSRF.ClientSession('open-ils.ebook_api').request({
23         method: 'open-ils.ebook_api.title.details',
24         params: [ ses, ebook.id ],
25         async: true,
26         oncomplete: function(r) {
27             var resp = r.recv();
28             if (resp) {
29                 console.log('title details response: ' + resp.content());
30                 ebook.title = resp.content().title;
31                 ebook.author = resp.content().author;
32                 return callback(ebook);
33             }
34         }
35     }).send();
36 }
37
38 Ebook.prototype.getAvailability = function(callback) {
39     var ses = dojo.cookie(this.vendor);
40     new OpenSRF.ClientSession('open-ils.ebook_api').request({
41         method: 'open-ils.ebook_api.title.availability',
42         params: [ ses, this.id ],
43         async: true,
44         oncomplete: function(r) {
45             var resp = r.recv();
46             if (resp) {
47                 console.log('availability response: ' + resp.content());
48                 this.avail = resp.content();
49                 return callback(resp.content());
50             }
51         }
52     }).send();
53 }
54
55 Ebook.prototype.getHoldings = function(callback) {
56     var ses = dojo.cookie(this.vendor);
57     new OpenSRF.ClientSession('open-ils.ebook_api').request({
58         method: 'open-ils.ebook_api.title.holdings',
59         params: [ ses, this.id ],
60         async: true,
61         oncomplete: function(r) {
62             var resp = r.recv();
63             if (resp) {
64                 console.log('holdings response: ' + resp.content());
65                 this.holdings = resp.content();
66                 return callback(resp.content());
67             }
68         }
69     }).send();
70 }
71
72 Ebook.prototype.checkout = function(authtoken, patron_id, callback) {
73     var ses = dojo.cookie(this.vendor);
74     var ebook = this;
75     new OpenSRF.ClientSession('open-ils.ebook_api').request({
76         method: 'open-ils.ebook_api.checkout',
77         params: [ authtoken, ses, ebook.id, patron_id ],
78         async: true,
79         oncomplete: function(r) {
80             var resp = r.recv();
81             if (resp) {
82                 console.log('checkout response: ' + resp.content());
83                 return callback(resp.content());
84             }
85         }
86     }).send();
87 }
88
89 Ebook.prototype.placeHold = function(authtoken, patron_id, callback) {
90     var ses = dojo.cookie(this.vendor);
91     var ebook = this;
92     new OpenSRF.ClientSession('open-ils.ebook_api').request({
93         method: 'open-ils.ebook_api.place_hold',
94         params: [ authtoken, ses, ebook.id, patron_id ],
95         async: true,
96         oncomplete: function(r) {
97             var resp = r.recv();
98             if (resp) {
99                 console.log('place hold response: ' + resp.content());
100                 return callback(resp.content());
101             }
102         }
103     }).send();
104 }
105