adding jubgrid management JS
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 22 May 2008 15:54:55 +0000 (15:54 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 22 May 2008 15:54:55 +0000 (15:54 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@9666 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/default/common/jubgrid.js [new file with mode: 0644]

diff --git a/Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/default/common/jubgrid.js b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/default/common/jubgrid.js
new file mode 100644 (file)
index 0000000..52b3877
--- /dev/null
@@ -0,0 +1,73 @@
+dojo.require('dojo.data.ItemFileReadStore');
+dojo.require('dijit.layout.SplitContainer');
+dojo.require('dojox.grid.Grid');
+dojo.require("openils.acq.Fund");
+dojo.require("openils.acq.Lineitems");
+dojo.require("openils.widget.FundSelector");
+dojo.require("fieldmapper.OrgUtils");
+dojo.require('openils.editors');
+dojo.require('openils.acq.Provider');
+
+/* put all the accessors, etc. into a local object for namespacing */
+var JUBGrid = {
+    jubGrid : null,
+    lineitems : [], // full list of lineitem objects to display 
+    getLi : function(id) { 
+        // given an ID, returns the lineitem object from the list
+        for(var i in JUBGrid.lineitems) {
+            var li = JUBGrid.lineitems[i];
+            if(li.id() == id)
+                return li;
+        }
+    },
+
+    _getMARCAttr : function(rowIndex, attr) {
+        var data = JUBGrid.jubGrid.model.getRow(rowIndex);
+        if (!data) return '';
+        return new openils.acq.Lineitems(
+            {lineitem:JUBGrid.getLi(data.id)}).findAttr(attr, 'lineitem_marc_attr_definition')
+    },
+    getJUBTitle : function(rowIndex) {
+        return JUBGrid._getMARCAttr(rowIndex, 'title');
+    },
+    getJUBIsbn : function(rowIndex) {
+        return JUBGrid._getMARCAttr(rowIndex, 'isbn');
+    },
+    getJUBPrice : function(rowIndex) {
+        return JUBGrid._getMARCAttr(rowIndex, 'price');
+    },
+    getJUBPubdate : function(rowIndex) {
+        return JUBGrid._getMARCAttr(rowIndex, 'pubdate');
+    },
+    getProvider : function(rowIndex) {
+        data = liGrid.model.getRow(rowIndex);
+        if(!data || !data.provider) return;
+        return openils.acq.Provider.retrieve(data.provider).code();
+    },
+    getLIDFundName : function(rowIndex) {
+        var data = JUBGrid.jubDetailGrid.model.getRow(rowIndex);
+        if (!data || !data.fund) return;
+        try {
+        return openils.acq.Fund.retrieve(data.fund).name();
+        } catch (evt) {
+        return data.fund;
+        }
+    },
+    getLIDLibName : function(rowIndex) {
+        var data = JUBGrid.jubDetailGrid.model.getRow(rowIndex);
+        if (!data || !data.owning_lib) return;
+        return fieldmapper.aou.findOrgUnit(data.owning_lib).shortname();
+    },
+    populate : function(gridWidget, model, lineitems) {
+        JUBGrid.lineitems = lineitems;
+        JUBGrid.jubGrid = gridWidget;
+        JUBGrid.jubGrid.setModel(model);
+        dojo.connect(gridWidget, "onRowClick", 
+            function(evt) {
+             openils.acq.Lineitems.loadGrid(
+                 JUBGrid.jubDetailGrid, 
+                    model.getRow(evt.rowIndex).id, JUBGrid.jubDetailGridLayout);
+            });
+        gridWidget.update();
+    }
+};