From 2c9dcd878bb9a400a208e70f0000fce2d944895b Mon Sep 17 00:00:00 2001 From: djfiander Date: Wed, 14 May 2008 02:46:05 +0000 Subject: [PATCH] Turn openils.acq.Picklist into a real dojo object to make rest of code simpler git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@9596 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/js/dojo/openils/acq/Picklist.js | 107 +++++++++++++++++---------- 1 file changed, 68 insertions(+), 39 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/acq/Picklist.js b/Open-ILS/web/js/dojo/openils/acq/Picklist.js index de6710aa61..2346e7c2f2 100644 --- a/Open-ILS/web/js/dojo/openils/acq/Picklist.js +++ b/Open-ILS/web/js/dojo/openils/acq/Picklist.js @@ -18,54 +18,83 @@ if(!dojo._hasResource['openils.acq.Picklist']) { 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 */ -}); - -openils.acq.Picklist.cache = {}; - -openils.acq.Picklist.createStore = function(pl_id, onComplete) { - // Fetches the list of titles in a picklist and builds a grid + 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 = []; - function mkStore(r) { - var msg; - var items = []; - while (msg = r.recv()) { - var data = msg.content(); - openils.acq.Picklist.cache[data.id()] = data; + while (msg = r.recv()) { + var data = msg.content(); + pl_this._data[data.id()] = data; + items.push(data); + } - items.push(data); - } - onComplete(jub.toStoreData(items)); - } + 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); + }; - fieldmapper.standardRequest( - ['open-ils.acq', 'open-ils.acq.lineitem.picklist.retrieve'], - { async: true, - params: [openils.User.authtoken, pl_id, {flesh_attrs:1}], - oncomplete: mkStore - }); -}; + 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(); + } + }); -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(); + // 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(); + } } - } - return ''; -}; - -openils.acq.Picklist.onRowClick = function(evt) { - var gridRefs = openils.acq.Picklist._gridRefs; - var row = gridRefs.grid.model.getRow(evt.rowIndex); + return ''; + }, +}); - openils.acq.Lineitems.loadGrid('oils-acq-picklist-details-grid', row.id); -}; } -- 2.11.0