[open-ils-commits] r9596 - branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq

svn at svn.open-ils.org svn at svn.open-ils.org
Tue May 13 22:46:07 EDT 2008


Author: djfiander
Date: 2008-05-13 22:46:05 -0400 (Tue, 13 May 2008)
New Revision: 9596

Modified:
   branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/Picklist.js
Log:
Turn openils.acq.Picklist into a real dojo object to make rest of
code simpler


Modified: branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/Picklist.js
===================================================================
--- branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/Picklist.js	2008-05-14 02:37:52 UTC (rev 9595)
+++ branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/Picklist.js	2008-05-14 02:46:05 UTC (rev 9596)
@@ -18,54 +18,83 @@
 dojo._hasResource['openils.acq.Picklist'] = true;
 dojo.provide('openils.acq.Picklist');
 
+dojo.require('dojo.data.ItemFileWriteStore');
+dojo.require('dojox.grid.Grid');
+dojo.require('dojox.grid._data.model');
 dojo.require('fieldmapper.Fieldmapper');
+dojo.require('fieldmapper.dojoData');
 
 /** Declare the Picklist class with dojo */
 dojo.declare('openils.acq.Picklist', null, {
-    /* add instance methods here if necessary */
-});
+    constructor: function (pl_id, onComplete) {
+	var pl_this = this;		// 'this' doesn't exist inside callbacks
+	var mkStore = function (r) {
+	    var storeData;
+	    var msg;
+	    var items = [];
 
-openils.acq.Picklist.cache = {};
+	    while (msg = r.recv()) {
+		var data = msg.content();
+		pl_this._data[data.id()] = data;
+		items.push(data);
+	    }
 
-openils.acq.Picklist.createStore = function(pl_id, onComplete) {
-    // Fetches the list of titles in a picklist and builds a grid
+	    storeData = jub.toStoreData(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,
+							query:{id:'*'}});
+	    onComplete(pl_this._model);
+	};
 
-    function mkStore(r) {
-	var msg;
-	var items = [];
-	while (msg = r.recv()) {
-	    var data = msg.content();
-	    openils.acq.Picklist.cache[data.id()] = data;
+	this._id = pl_id;
+	this._data = {};
+	this._plist = null;
+	// Fetch the picklist information
+	fieldmapper.standardRequest(
+	    ['open-ils.acq', 'open-ils.acq.picklist.retrieve'],
+	    { async: false,
+	      params: [openils.User.authtoken, pl_id, {flesh_lineitem_count:1}],
+	      oncomplete: function(r) {
+		  var msg = r.recv();
+		  pl_this._plist = msg.content();
+	      }
+	    });
 
-	    items.push(data);
+	// Fetch the title list for the picklist, asynchronously
+	fieldmapper.standardRequest(
+	    ['open-ils.acq', 'open-ils.acq.lineitem.picklist.retrieve'],
+	    { async: true,
+	      params: [openils.User.authtoken, pl_id, {flesh_attrs:1}],
+	      oncomplete: mkStore
+	    });
+    },
+    id: function () {
+	return this._id;
+    },
+    name: function() {
+	return this._plist.name();
+    },
+    owner: function() {
+	return this._plist.owner();
+    },
+    create_time: function() {
+	return this._plist.create_time();
+    },
+    edit_time: function() {
+	return this._plist.edit_time();
+    },
+    find_attr: function(id, at_name, at_type) {
+	attr_list = this._data[id].attributes();
+	for (var i in attr_list) {
+	    var attr = attr_list[i];
+	    if (attr.attr_type() == at_type && attr.attr_name() == at_name) {
+		return attr.attr_value();
+	    }
 	}
-	onComplete(jub.toStoreData(items));
-    }
+	return '';
+    },
+});
 
-    fieldmapper.standardRequest(
-	['open-ils.acq', 'open-ils.acq.lineitem.picklist.retrieve'],
-	{ async: true,
-	  params: [openils.User.authtoken, pl_id, {flesh_attrs:1}],
-	  oncomplete: mkStore
-	});
-};
-
-openils.acq.Picklist.find_attr = function(id, at_name, at_type) {
-    var li = openils.acq.Picklist.cache[id];
-    for (var i in li.attributes()) {
-	var attr = li.attributes()[i];
-	if (attr.attr_type() == at_type && attr.attr_name() == at_name) {
-	    return attr.attr_value();
-	}
-    }
-    return '';
-};
-
-openils.acq.Picklist.onRowClick = function(evt) {
-    var gridRefs = openils.acq.Picklist._gridRefs;
-    var row = gridRefs.grid.model.getRow(evt.rowIndex);
-
-    openils.acq.Lineitems.loadGrid('oils-acq-picklist-details-grid', row.id);
-};
 }
 



More information about the open-ils-commits mailing list