moved jubgrid JS to external file
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 22 May 2008 15:54:05 +0000 (15:54 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 22 May 2008 15:54:05 +0000 (15:54 +0000)
added isbn and pubdate columns
when jubgrid is used, you have to provide a list of lineitems directly
so it knows how to find the lineitem-attr fields
put jubgrid JS into an object (currently called JUBGrid) to contain
the helper functions and grid references (less global namespace collision opportunities);
updated picklist/view and li_search to use this updated grid
Picklist now stores an array of lineitems refs in addition to the _data object

git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@9665 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/acq/Picklist.js
Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/default/acq/po/li_search.js
Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/picklist/view.html
Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/po/li_search.html
Open-ILS/web/oilsweb/oilsweb/templates/oils/default/common/jubgrid.html

index 57cee2e..b33fa63 100644 (file)
@@ -31,15 +31,15 @@ dojo.declare('openils.acq.Picklist', null, {
        var mkStore = function (r) {
            var storeData;
            var msg;
-           var items = [];
+           pl_this._items = [];
 
            while (msg = r.recv()) {
                var data = msg.content();
                pl_this._data[data.id()] = data;
-               items.push(data);
+               pl_this._items.push(data);
            }
 
-           storeData = jub.toStoreData(items);
+           storeData = jub.toStoreData(pl_this._items);
            pl_this._store = new dojo.data.ItemFileWriteStore({data:storeData});
            pl_this._model = new dojox.grid.data.DojoData(null, pl_this._store,
                                                       {rowsPerPage:20, clientSort:true,
@@ -65,7 +65,7 @@ dojo.declare('openils.acq.Picklist', null, {
        fieldmapper.standardRequest(
            ['open-ils.acq', 'open-ils.acq.lineitem.picklist.retrieve'],
            { async: true,
-             params: [openils.User.authtoken, pl_id, {flesh_attrs:1}],
+             params: [openils.User.authtoken, pl_id, {flesh_attrs:1, clear_marc:1}],
              oncomplete: mkStore
            });
     },
index 22ee466..efb710e 100644 (file)
@@ -68,52 +68,7 @@ function viewList() {
     var store = new dojo.data.ItemFileReadStore({data:jub.toStoreData(lineitems)});
     var model = new dojox.grid.data.DojoData(
         null, store, {rowsPerPage: 20, clientSort: true, query:{id:'*'}});
-    liGrid.setModel(model);
-    liGrid.update();
-}
-
-
-function getProvider(rowIndex) {
-    data = liGrid.model.getRow(rowIndex);
-    if(!data) return;
-    if(!data.provider) return '';
-    return openils.acq.Provider.retrieve(data.provider).code();
-}
-
-function getLi(id) {
-    for(var i in lineitems) {
-        var li = lineitems[i];
-        if(li.id() == id) 
-            return li;
-    }
-}
-
-function getJUBTitle(rowIndex) {
-    var data = liGrid.model.getRow(rowIndex);
-    if(!data) return '';
-    return new openils.acq.Lineitems(
-        {lineitem:getLi(data.id)}).findAttr('title', 'lineitem_marc_attr_definition')
-}
-
-function getJUBIsbn(rowIndex) {
-    var data = liGrid.model.getRow(rowIndex);
-    if(!data) return '';
-    return new openils.acq.Lineitems(
-        {lineitem:getLi(data.id)}).findAttr('isbn', 'lineitem_marc_attr_definition')
-}
-
-function getJUBPubdate(rowIndex) {
-    var data = liGrid.model.getRow(rowIndex);
-    if(!data) return '';
-    return new openils.acq.Lineitems(
-        {lineitem:getLi(data.id)}).findAttr('pubdate', 'lineitem_marc_attr_definition')
-}
-
-function getJUBPrice(rowIndex) {
-    var data = liGrid.model.getRow(rowIndex);
-    if(!data) return;
-    return new openils.acq.Lineitems(
-        {lineitem:getLi(data.id)}).findAttr('price', 'lineitem_marc_attr_definition')
+    JUBGrid.populate(liGrid, model, lineitems)
 }
 
 function createPOFromLineitems() {
index b121a33..48e4b77 100644 (file)
@@ -9,6 +9,7 @@
     <script type='text/javascript'>
        dojo.require('dijit.layout.LayoutContainer');
        dojo.require('dijit.layout.ContentPane');
+    dojo.require('openils.acq.Picklist');
     </script>
 </%def>
 <%def name="page_title()">${_('Picklist')}</%def>
@@ -36,8 +37,7 @@
                                    dojo.byId("oils-acq-picklist-attr-cdate").innerHTML = plist.create_time();
                                    dojo.byId("oils-acq-picklist-attr-edate").innerHTML = plist.edit_time();
                                    dojo.byId("oils-acq-picklist-attr-owner").innerHTML = plist.owner();
-           
-                                   populateJUBGrid(pickListGrid, model);
+                    JUBGrid.populate(pickListGrid, model, plist._items);
                                });
             }
            dojo.addOnLoad(loadPL);
index 920100b..0e429b8 100644 (file)
@@ -1,6 +1,8 @@
 # -*- coding: utf-8 -*-
 <%inherit file='base.html'/>
 <%def name="page_title()">${_('Lineitem Search')}</%def>
+<%namespace file='/oils/default/common/jubgrid.html' name='jubgrid'/>
+
 
 <%def name="block_content()">
     <script src='${c.oils.core.media_prefix.value}/ui_js/oils/default/acq/po/li_search.js'> </script>
             </table>
         </div>
     </div> 
-
-
-    <script>
-        var liGridStructure = [{
-            cells: [[
-                {name: '${_("ID")}', field: 'id'},
-                {name: '${_("Title")}', width: 'auto', get:getJUBTitle},
-                {name: '${_("ISBN")}', get:getJUBIsbn},
-                {name: '${_("Pubdate")}', get:getJUBPubdate},
-                {name: '${_("Price")}', get:getJUBPrice},
-                {name: '${_("Vendor")}', get:getProvider},
-                {name: '${_("# of Copies")}', field: 'item_count'},
-                {name: '${_("State")}', field: 'state'}
-            ]]
-        }];
-    </script>
-    <div jsId='liGrid' dojoType="dojox.Grid" structure='liGridStructure'> </div>
+    ${jubgrid.jubgrid('oils-acq-lineitem', 'liGrid')}
 </%def>
 
 
index a18485f..79af846 100644 (file)
@@ -36,102 +36,47 @@ instantiate the template, and model is a javascript variable
 pointing to the JUB model (and store) that you have created.
 
 </%doc>
-<div dojoType="dijit.layout.SplitContainer"
+
+<div dojoType="dijit.layout.SplitContainer" style='height:100%'
      orientation="vertical" sizerWidth="5"
      activeSizing="1" layoutAlign="client">
-    <script type="text/javascript">
-       dojo.require('dojo.data.ItemFileReadStore');
-       dojo.require('dijit.layout.SplitContainer');
-       dojo.require('dojox.grid.Grid');
-       dojo.require('openils.editors');
-       dojo.require('openils.acq.Picklist');
-       dojo.require("openils.acq.Fund");
-       dojo.require('openils.acq.Provider');
-       dojo.require("openils.acq.Lineitems");
-       dojo.require("openils.widget.FundSelector");
-       dojo.require("fieldmapper.OrgUtils");
-
-       var globalUser = new openils.User();
-       function getJUBTitle(rowIndex) {
-           var data = ${grid_jsid}.model.getRow(rowIndex);
-           if (!data) return '';
-           return plist.find_attr(data.id, "title", "lineitem_marc_attr_definition")
-       }
-       function getJUBPrice(rowIndex) {
-           var data = ${grid_jsid}.model.getRow(rowIndex);
-           if (!data) return;
-           return plist.find_attr(data.id, "price", "lineitem_marc_attr_definition")
-       }
-       function getJUBProvider(rowIndex) {
-           var data = ${grid_jsid}.model.getRow(rowIndex);
-           if (!data || !data.provider) return;
-           return openils.acq.Provider.retrieve(data.provider).name();
-       }
-       function getLIDFundName(rowIndex) {
-           var data = lineItemGrid.model.getRow(rowIndex);
-           if (!data || !data.fund) return;
-           try {
-               return openils.acq.Fund.retrieve(data.fund).name();
-           } catch (evt) {
-               return data.fund;
-           }
-       }
-       function getLIDLibName(rowIndex) {
-           var data = lineItemGrid.model.getRow(rowIndex);
-           if (!data || !data.owning_lib) return;
-           try {
-               return fieldmapper.aou.findOrgUnit(data.owning_lib, true).name();
-           } catch (evt) {
-               return data.owning_lib;
-           }
-       }
+
+    <script src='${c.oils.core.media_prefix.value}/ui_js/oils/default/common/jubgrid.js'> </script>
+    <script>
+    JUBGrid.jubGridLayout = [{
+        cells: [[
+            {name: "ID", field: 'id'},
+            {name: "Title", width: "auto", get:JUBGrid.getJUBTitle},
+            {name: "ISBN", get:JUBGrid.getJUBIsbn},
+            {name: '${_("Pubdate")}', get:JUBGrid.getJUBPubdate},
+            {name: "Price", get:JUBGrid.getJUBPrice},
+            {name: "Vendor", get:JUBGrid.getProvider},
+            {name: "# of Copies", field: 'item_count'},
+            {name: "State", field: 'state'}
+        ]]
+    }];
+
+    JUBGrid.jubDetailGridLayout = [{
+        cells: [[
+            {name:"ID", field:"id"},
+            {name:"Fund", field:"fund",
+             get:JUBGrid.getLIDFundName,
+             editor: openils.widget.FundSelector,
+            },
+            {name:"Location", field:"location", get:JUBGrid.getLIDLibName}
+        ]]
+    }];
     </script>
-    <div id=${domprefix + '-container'}
+
+    <div id="${domprefix + '-container'}"
         dojoType="dijit.layout.ContentPane" sizeMin="20" sizeShare="50">
-       <div jsid=${grid_jsid} dojoType='dojox.Grid'
-            id=${domprefix + '-JUB-grid'}> </div>
-       <script type="text/javascript">
-           var picklistLayout = [{
-               cells: [[
-                   {name: "ID", field: 'id'},
-                   {name: "Title", width: "50%", get:getJUBTitle},
-                   {name: "Price", get:getJUBPrice},
-                   {name: "Vendor", field: 'provider',
-                    get:getJUBProvider},
-                   {name: "# of Copies", field: 'item_count'}
-               ]]
-           }];
-
-           var lineitemLayout = [{
-               cells: [[
-                   {name:"ID", field:"id"},
-                   {name:"Fund", field:"fund",
-                    get:getLIDFundName,
-                    editor: openils.widget.FundSelector,
-                   },
-                   {name:"Location", field:"location",
-                    get:getLIDLibName}
-               ]]
-           }];
-           function populateJUBGrid(gridDom, model) {
-               ${grid_js_id}.setStructure(picklistLayout);
-               ${grid_js_id}.setModel(model);
-                                   
-               dojo.connect(gridDom, "onRowClick", 
-                            function(evt) {
-                                openils.acq.Lineitems.loadGrid(
-                                    lineItemGrid, model.getRow(evt.rowIndex).id, lineitemLayout);
-                            });
-               ${grid_js_id}.update();
-           }
-       </script>
+           <div structure='JUBGrid.jubGridLayout' jsid='${grid_jsid}' 
+            dojoType='dojox.Grid' id="${domprefix + '-JUB-grid'}"> </div>
     </div>
-    <div dojoType="dijit.layout.ContentPane" sizeMin="20"
-        sizeShare="50">
-       <div jsid="lineItemGrid" dojoType="dojox.Grid"
-            id=${domprefix + "-details-grid"}>
-           <!-- Copy order details go here -->
-       </div>
+    <div dojoType="dijit.layout.ContentPane" sizeMin="20" sizeShare="50">
+        <div structure='JUBGrid.jubDetailGridLayout' jsid="JUBGrid.jubDetailGrid" dojoType="dojox.Grid"
+            id='${domprefix + "-details-grid"}'>
+        </div>
     </div>
 </div>
 </%def>