]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/conify/global/config/hold_matrix_matchpoint.js
6175e7cf44560238c1a19002151e0dd8f3dde1aa
[working/Evergreen.git] / Open-ILS / web / js / ui / default / conify / global / config / hold_matrix_matchpoint.js
1 dojo.require('dojox.grid.DataGrid');
2 dojo.require('dojox.grid.cells.dijit');
3 dojo.require('dojo.data.ItemFileWriteStore');
4 dojo.require('dijit.form.CheckBox');
5 dojo.require('dijit.form.FilteringSelect');
6 dojo.require('fieldmapper.OrgUtils');
7 //dojo.require('openils.widget.OrgUnitFilteringSelect');
8 dojo.require('openils.PermGrp');
9 dojo.require('openils.PermaCrud');
10
11 var marcType = {};
12 var marcForm = {};
13 var vrForm = {};
14 var pcrud = new openils.PermaCrud();
15 var hmCache = [];
16
17 function getOrgInfo(rowIndex, item) {
18     if(!item) return '';
19     var orgId = this.grid.store.getValue(item, this.field);
20     if(orgId != null) {
21         return fieldmapper.aou.findOrgUnit(orgId).shortname();
22     }
23     return '';
24 }
25 function getGroupName (rowIndex, item) {
26     if(!item) return '';
27     var grpId = this.grid.store.getValue(item, this.field);
28     if (grpId != null) {
29         grpName = openils.PermGrp.groupIdMap[grpId].name();
30         return grpName;
31     }
32     return '';
33 }
34 function getMarcType(rowIndex, item) {
35     if(!item) return '';
36     var mt = this.grid.store.getValue(item, this.field);
37     if(mt != null){
38         mtObject = marcType[mt];
39         return mtObject.value();
40     }
41     return'';
42 }
43 function getMarcForm(rowIndex, item){
44     if(!item) return '';
45     var mf = this.grid.store.getValue(item, this.field);
46     if(mf != null){
47         mfObject = marcForm[mf];
48         return mfObject.value();
49     }
50     return'';
51 }
52 function getVrForm(rowIndex, item){
53     if(!item) return '';
54     var vr = this.grid.store.getValue(item, this.field);
55     console.log(vr);
56     if(vr != null){
57         vrObject = vrForm[vr];
58         return vrObject.value();
59     }
60     return'';
61 }
62 function formatReference(inDatum) {
63     switch (inDatum) {
64         case 't':
65             return "<span style='color:green;'>&#x2713;</span>";
66         case 'f':
67             return "<span style='color:red;'>&#x2717;</span>";
68     default:
69         return '';
70     }
71 }
72
73 function init() {
74     var pending = 4
75
76     pcrud.retrieveAll(
77         'citm',
78         { async : true,
79           oncomplete: function (r) {
80              var list = openils.Util.readResponse(r);
81               marcType = openils.Util.mapList(list, 'code', true);
82               if(--pending == 0) {
83                   buildHMGrid();
84               }
85           }
86         }
87     );
88     pcrud.retrieveAll(
89         'cifm',
90         { async : true,
91           oncomplete: function (r) {
92               var list = openils.Util.readResponse(r);
93               marcForm = openils.Util.mapList(list, 'code', true);
94               if(--pending == 0) {
95                   buildHMGrid();
96               }
97           }
98         }
99     );
100     pcrud.retrieveAll(
101         'cvrfm',
102         { async : true,
103           oncomplete: function (r) {
104               var list = openils.Util.readResponse(r);
105               vrForm = openils.Util.mapList(list, 'code', true);
106               if(--pending == 0) {
107                   buildHMGrid();
108               }
109           }
110         }
111     );
112     openils.PermGrp.fetchGroupTree(
113         function() {
114             openils.PermGrp.flatten();
115             if(--pending == 0) {
116                   buildHMGrid();
117               }
118         }
119     );
120 }
121 function buildHMGrid() {
122     var store = new dojo.data.ItemFileWriteStore({data:chmm.initStoreData('id', {identifier:'id'})});
123     hmGrid.setStore(store);
124     hmGrid.render();
125
126     fieldmapper.standardRequest(
127         ['open-ils.pcrud', 'open-ils.pcrud.search.chmm'],
128         {   async: true,
129             params: [openils.User.authtoken, {id:{'!=':null}}],
130             onresponse: function (r) {
131                 if(obj = openils.Util.readResponse(r)) {
132                     store.newItem(chmm.toStoreItem(obj));
133                     // cmCache[obj.code()] = obj;
134                 }
135            }
136         }
137     );
138 }
139 function deleteFromGrid() {
140     _deleteFromGrid(hmGrid.selection.getSelected(), 0);
141 }   
142
143 function _deleteFromGrid(list, idx) {
144     if(idx >= list.length) // we've made it through the list
145         return;
146
147     var item = list[idx];
148     var id = hmGrid.store.getValue(item, 'id');
149
150     fieldmapper.standardRequest(
151         ['open-ils.permacrud', 'open-ils.permacrud.delete.chmm'],
152         {   async: true,
153             params: [openils.User.authtoken, id],
154             oncomplete: function(r) {
155                 if(stat = openils.Util.readResponse(r)) {
156                     // delete succeeded, remove it from the grid and the local cache
157                     hmGrid.store.deleteItem(item); 
158                     delete hmCache[item.code];
159                 }
160                 _deleteFromGrid(list, ++idx);
161             }
162         }
163     );
164 }
165
166 openils.Util.addOnLoad(init);