adding some copy loc handling code
[Evergreen.git] / Open-ILS / web / js / dojo / openils / CopyLocation.js
1 /* ---------------------------------------------------------------------------
2  * Copyright (C) 2008  Georgia Public Library Service
3  * Author: Bill Erickson <erickson@esilibrary.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * ---------------------------------------------------------------------------
15  */
16
17 if(!dojo._hasResource["openils.CopyLocation"]) {
18
19     dojo._hasResource["openils.CopyLocation"] = true;
20     dojo.provide("openils.CopyLocation");
21     dojo.declare('openils.CopyLocation', null, {
22     });
23
24     openils.CopyLocation.cache = {};
25     openils.CopyLocation.storeCache = {};
26
27     openils.CopyLocation.createStore = function(focusOrg, onload, nocache) {
28         if(!nocache && openils.CopyLocation.storeCache[focusOrg])
29             return onload(openils.CopyLocation.storeCache[focusOrg]);
30         function mkStore(r) {
31             var locs = r.recv().content();
32             for(var i = 0; i < locs.length; i++) 
33                 openils.CopyLocation.cache[locs[i].id()] = locs[i];
34             openils.CopyLocation.storeCache[focusOrg] = acpl.toStoreData(locs);
35             onload(openils.CopyLocation.storeCache[focusOrg]);
36         }
37         fieldmapper.standardRequest(
38             ['open-ils.circ', 'open-ils.circ.copy_location.retrieve.all'],
39             {   async: true,
40                 params: [focusOrg],
41                 oncomplete: mkStore
42             }
43         );
44     }
45
46     openils.CopyLocation.retrieve = function(id) {
47         if(openils.CopyLocation.cache[id])
48             return openils.CopyLocation.cache[id];
49         return openils.CopyLocation.cache[id] = 
50             fieldmapper.standardRequest(
51                 ['open-ils.circ', 'open-ils.circ.copy_location.retrieve'], [id]);
52     }
53 }
54