[open-ils-commits] r9290 - in
branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb:
controllers/acq public/oils/media/js/openils/acq
templates/oils/default templates/oils/default/acq/picklist
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Apr 9 22:56:10 EDT 2008
Author: djfiander
Date: 2008-04-09 22:18:49 -0400 (Wed, 09 Apr 2008)
New Revision: 9290
Added:
branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Picklist.js
Modified:
branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/acq/picklist.py
branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/picklist/view.html
branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/base.html
branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/navigate.html
Log:
Dojo-ize Picklist display. There are still problems with the grid being displayed.
Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/acq/picklist.py
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/acq/picklist.py 2008-04-10 02:18:34 UTC (rev 9289)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/acq/picklist.py 2008-04-10 02:18:49 UTC (rev 9290)
@@ -4,6 +4,9 @@
import oilsweb.lib.bib, oilsweb.lib.acq.search
import oils.const, oils.utils.utils
import osrf.net_obj
+
+import simplejson
+
from osrf.ses import ClientSession
from oils.event import Event
from oils.org import OrgUtil
@@ -14,21 +17,20 @@
from oilsweb.lib.acq import provider_mgr
class PicklistController(BaseController):
-
+
def view(self, **kwargs):
r = RequestMgr()
pl_manager = oilsweb.lib.acq.picklist.PicklistMgr(r, picklist_id=kwargs['id'])
pl_manager.retrieve()
- # sort by author suppresses lineitems that don't have an author
pl_manager.retrieve_lineitems(flesh_provider=True,
- #sort_attr="author",
- #sort_dir="asc",
+ sort_attr="author",
+ sort_dir="asc",
offset=r.ctx.acq.offset.value,
limit=r.ctx.acq.limit.value)
r.ctx.acq.picklist.value = pl_manager.picklist
r.ctx.acq.picklist_list.value = pl_manager.retrieve_list()
return r.render('acq/picklist/view.html')
-
+
def create(self, **kwargs):
r = RequestMgr()
if r.ctx.acq.picklist_name.value:
@@ -41,7 +43,7 @@
Event.parse_and_raise(picklist_id)
return redirect_to(controller='acq/picklist', action='view', id=picklist_id)
return r.render('acq/picklist/create.html')
-
+
def view_lineitem(self, **kwargs):
r = RequestMgr()
pl_manager = oilsweb.lib.acq.picklist.PicklistMgr(r)
@@ -55,28 +57,58 @@
r.ctx.acq.picklist.value = pl_manager.picklist
r.ctx.acq.lineitem.value = lineitem
r.ctx.acq.lineitem_marc_html.value = oilsweb.lib.bib.marc_to_html(lineitem.marc())
-
+
r.ctx.acq.provider_list.value = provider_mgr.list(r)
r.ctx.acq.fund_list.value = fmgr.retrieve_org_funds()
-
+
return r.render('acq/picklist/view_lineitem.html')
-
+
+
+ def json(self, **kwargs):
+ r = RequestMgr()
+ pl_manager = oilsweb.lib.acq.picklist.PicklistMgr(r, picklist_id=kwargs['id'])
+ pl_manager.retrieve()
+ pl_manager.retrieve_lineitems(flesh_provider=True,
+ sort_attr="author",
+ sort_dir="asc")
+
+ items = []
+ for title in pl_manager.picklist.entries():
+ label = ''.join(PicklistMgr.find_lineitem_attr(title, x) for x in ("title", "publisher", "pubdate", "pagination", "isbn", "price"))
+ item = {
+ 'id': title.id(),
+ 'copies': title.item_count(),
+ 'title': PicklistMgr.find_lineitem_attr(title, "title"),
+ 'isbn': PicklistMgr.find_lineitem_attr(title, "isbn"),
+ 'price': PicklistMgr.find_lineitem_attr(title, "price"),
+ 'provider': PicklistMgr.find_lineitem_attr(title, "provider"),
+ 'label': label
+ }
+ items.append(item)
+
+ pylons.response.headers["Content-type"] = "text/x-json"
+ return simplejson.dumps({'identifier': 'id',
+ 'label': 'label',
+ 'items': items
+ })
+
+
def list(self):
r = RequestMgr()
pl_manager = oilsweb.lib.acq.picklist.PicklistMgr(r)
r.ctx.acq.picklist_list.value = pl_manager.retrieve_list()
return r.render('acq/picklist/view_list.html')
-
+
def listall(self):
r = RequestMgr()
pl_manager = oilsweb.lib.acq.picklist.PicklistMgr(r)
r.ctx.acq.picklist_list.value = pl_manager.retrieve_list(all=True)
return r.render('acq/picklist/view_listall.html')
-
+
def search(self):
r = RequestMgr()
r.ctx.acq.z39_sources.value = oilsweb.lib.acq.search.fetch_z39_sources(r.ctx)
-
+
sc = {}
for data in r.ctx.acq.z39_sources.value.values():
for key, val in data['attrs'].iteritems():
@@ -85,22 +117,22 @@
keys = sc.keys()
keys.sort()
r.ctx.acq.search_classes_sorted.value = keys
-
+
return r.render('acq/picklist/search.html')
-
+
def do_search(self):
r = RequestMgr()
picklist_id = oilsweb.lib.acq.search.multi_search(
r, oilsweb.lib.acq.search.compile_multi_search(r))
return redirect_to(controller='acq/picklist', action='view', id=picklist_id)
-
+
def delete(self, **kwargs):
r = RequestMgr()
pl_manager = oilsweb.lib.acq.picklist.PicklistMgr(r, picklist_id=kwargs['id'])
pl_manager.delete()
return redirect_to(controller='acq/picklist', action='list')
-
-
+
+
def delete_lineitem(self, **kwargs):
r = RequestMgr()
pl_manager = oilsweb.lib.acq.picklist.PicklistMgr(r)
@@ -108,39 +140,39 @@
lineitem = pl_manager.retrieve_lineitem(lineitem_id)
pl_manager.delete_lineitem(lineitem_id)
return redirect_to(controller='acq/picklist', action='view', id=lineitem.picklist())
-
+
def update(self):
r = RequestMgr()
ses = ClientSession(oils.const.OILS_APP_ACQ)
ses.connect()
page = None
-
+
if r.ctx.acq.lineitem_id:
page = self._update_lineitem_count(r, ses)
elif r.ctx.acq.picklist_action.value == 'move_selected':
page = self._move_selected(r, ses)
-
+
if not page:
page = redirect_to(controller='acq/picklist', action='list')
-
+
ses.disconnect()
return page
-
+
def update_lineitem(self):
r = RequestMgr()
ses = ClientSession(oils.const.OILS_APP_ACQ)
ses.connect()
-
+
if r.ctx.acq.lineitem_detail_id.value:
# update fund assignment, etc
detail = ses.request('open-ils.acq.lineitem_detail.retrieve',
r.ctx.core.authtoken.value,
r.ctx.acq.lineitem_detail_id.value).recv().content()
detail = Event.parse_and_raise(detail)
-
+
# Update all the fields that are editable via the form
detail.fund(r.ctx.acq.fund_id.value)
-
+
detail = ses.request('open-ils.acq.lineitem_detail.update',
r.ctx.core.authtoken.value,
detail).recv().content()
@@ -150,54 +182,54 @@
r.ctx.core.authtoken.value,
r.ctx.acq.lineitem_id.value).recv().content()
lineitem = Event.parse_and_raise(lineitem)
-
+
lineitem.provider(r.ctx.acq.provider_id.value)
lineitem = ses.request('open-ils.acq.lineitem.update',
r.ctx.core.authtoken.value,
lineitem).recv().content()
Event.parse_and_raise(lineitem)
-
+
return redirect_to(controller='acq/picklist', action='view_lineitem',
id=r.ctx.acq.lineitem_id.value)
-
+
def approve_lineitem(self):
r = RequestMgr()
ses = ClientSession(oils.const.OILS_APP_ACQ)
ses.connect
-
+
li = ses.request('open-ils.acq.lineitem.retrieve',
r.ctx.core.authtoken.value,
r.ctx.acq.lineitem_id.value).Recv().content()
li = Event.parse_and_raise(li)
-
+
li.state("approved")
-
+
li = ses.request('open-ils.acq.lineitem.update',
r.ctx.core.authtoken.value,
li).recv().content()
li = Event.parse_and_raise(li)
-
+
return redirect_to(controller='acq/picklist', action='view',
id=r.ctx.acq.picklist_id.value)
-
+
def _update_lineitem_count(self, r, ses):
''' Updates # of copies to order for single lineitem '''
-
+
picklist_id = r.ctx.acq.picklist_source_id.value
lineitem_id = r.ctx.acq.lineitem_id.value
new_count = int(r.ctx.acq.lineitem_item_count.value)
-
+
lineitem = ses.request('open-ils.acq.lineitem.retrieve',
r.ctx.core.authtoken.value,
lineitem_id, {'flesh_li_details':1}).recv().content()
lineitem = Event.parse_and_raise(lineitem)
-
+
# Make sure the lineitem count is correct.
lineitem.item_count(len(lineitem.lineitem_details()))
-
+
# Can't remove detail records yet
assert (lineitem.item_count() <= new_count), "Can't delete detail records"
-
+
for i in range(new_count - lineitem.item_count()):
detail = osrf.net_obj.NetworkObject.acqlid()
detail.lineitem(lineitem.id())
@@ -205,35 +237,35 @@
r.ctx.core.authtoken.value,
detail, dict())
Event.parse_and_raise(detail)
-
+
if (lineitem.item_count() != new_count):
# Update the number of detail records
lineitem.item_count(new_count)
-
+
lineitem = ses.request('open-ils.acq.lineitem.update',
r.ctx.core.authtoken.value, lineitem)
Event.parse_and_raise(lineitem)
-
+
# fail()
return redirect_to(controller='acq/picklist', action='view',
id=picklist_id)
-
+
def _move_selected(self, r, ses):
''' Moves the selected picklist lineitem's to the destination picklist '''
for lineitem_id in r.ctx.acq.lineitem_id_list.value:
-
+
lineitem = ses.request(
'open-ils.acq.lineitem.retrieve',
r.ctx.core.authtoken.value, lineitem_id).recv().content()
lineitem = Event.parse_and_raise(lineitem)
-
+
lineitem.picklist(r.ctx.acq.picklist_dest_id.value)
-
+
status = ses.request(
'open-ils.acq.lineitem.update',
r.ctx.core.authtoken.value, lineitem).recv().content()
Event.parse_and_raise(status)
-
+
return redirect_to(controller='acq/picklist', action='view',
id=r.ctx.acq.picklist_dest_id.value)
Added: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Picklist.js
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Picklist.js (rev 0)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Picklist.js 2008-04-10 02:18:49 UTC (rev 9290)
@@ -0,0 +1,51 @@
+if(!dojo._hasResource['openils.acq.Picklist']) {
+dojo._hasResource['openils.acq.Picklist'] = true;
+dojo.provide('openils.acq.Picklist');
+dojo.require('util.Dojo');
+
+/** Declare the Picklist class with dojo */
+dojo.declare('openils.acq.Picklist', null, {
+ /* add instance methods here if necessary */
+});
+
+ openils.acq.Picklist.find_attr = function(li, at_name, at_type) {
+ 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.loadGrid = function(domId, columns, pl_id) {
+ /** Fetches the list of picklists and builds a grid from them */
+
+ var gridRefs = util.Dojo.buildSimpleGrid(domId, columns, [], 'id', true);
+ var ses = new OpenSRF.ClientSession('open-ils.acq');
+ var req = ses.request('open-ils.acq.lineitem.picklist.retrieve',
+ oilsAuthtoken, pl_id, {flesh_attrs:1});
+
+ req.oncomplete = function(r) {
+ var msg
+ gridRefs.grid.setModel(gridRefs.model);
+ while(msg = r.recv()) {
+ var jub = msg.content();
+ alert(js2JSON(jub));
+ gridRefs.store.newItem({
+ id:jub.id(),
+ title:openils.acq.Picklist.find_attr(jub, "title", "lineitem_marc_attr_definition"),
+ price:openils.acq.Picklist.find_attr(jub, "price", "lineitem_marc_attr_definition"),
+ provider:jub.provider(),
+ copies:jub.item_count()
+ });
+ }
+ gridRefs.grid.update();
+ };
+
+ req.send();
+ return gridRefs.grid;
+};
+}
+
Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/picklist/view.html
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/picklist/view.html 2008-04-10 02:18:34 UTC (rev 9289)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/picklist/view.html 2008-04-10 02:18:49 UTC (rev 9290)
@@ -5,83 +5,27 @@
<%inherit file='../base.html'/>
<%namespace file='../../common/widgets.html' name='widget' />
<%namespace file='picklist_summary.html' name='picklist' />
+
<%def name="page_title()">${_('Picklist')}</%def>
+
<%def name="block_content()">
-<%
- import oilsweb.lib.bib
- from oilsweb.lib.acq.picklist import PicklistMgr
-%>
-
${picklist.summary(c.oils.acq.picklist.value)}
-<div id='oils-acq-picklist-header-block'>
- <div class='spacer'> </div>
- <div id="oils-acq-picklist-paging-block">
- ${widget.paging(c.oils.acq.offset.value, c.oils.acq.limit.value,
- c.oils.acq.picklist.value.entry_count())}
- </div>
- <div id="oils-acq-picklist-actions-block">
- <select name='${c.oils.acq.picklist_action.cgi_name}'>
- <option value='move_selected'>${_('Move Selected to Picklist...')}</option>
- </select>
- <select name='${c.oils.acq.picklist_dest_id.cgi_name}'>
- <option selected='selected' value=''>${_('-- Select A Picklist --')}</option>
- % for list in c.oils.acq.picklist_list.value:
- <option value='${list.id()}'>${list.name()}</option>
- % endfor
- </select> <button type='submit' dojoType="dijit.form.Button">${_("Submit")}</button>
- </div>
- <div class='spacer'> </div>
-</div>
-<div id='fred'>
-<table id="oils-acq-picklist-table">
- <thead>
- <tr>
- <td colspan="2">Item Description</td>
- <td class="oils-acq-picklist-records-copies"># of Copies</td>
- </tr>
- </thead>
- <tbody>
- % for lineitem in c.oils.acq.picklist.value.entries():
- <tr class='oils-acq-picklist-records-title'>
- <td class='oils-acq-picklist-records-jacket-td'>
- <img class='oils-acq-picklist-records-jacket'
- src='${c.oils.core.ac_prefix.value}/jacket/small/${oilsweb.lib.bib.scrub_isbn(PicklistMgr.find_lineitem_attr(lineitem, "isbn"))}'/>
- </td>
- <td><a href='../view_lineitem/${lineitem.id()}'>${h.util.html_escape(PicklistMgr.find_lineitem_attr(lineitem, "title"))}</a>
- ${PicklistMgr.find_lineitem_attr(lineitem, "publisher")}
- ${PicklistMgr.find_lineitem_attr(lineitem, "pubdate")}
- ${PicklistMgr.find_lineitem_attr(lineitem, "pagination")}
- ${PicklistMgr.find_lineitem_attr(lineitem, "isbn")}
- ${PicklistMgr.find_lineitem_attr(lineitem, "price")}
- </td>
- <td class="oils-acq-picklist-records-copies">
- % if lineitem.state() == 'approved':
- ${lineitem.item_count()} Approved
- % else:
- <form dojoType="dijit.form.Form" method="POST"
- action="${c.oils.acq.prefix.value}/picklist/update">
- <input name="${c.oils.acq.picklist_source_id.cgi_name}"
- type="hidden"
- value="${c.oils.acq.picklist.value.id()}" />
- <input name="${c.oils.acq.lineitem_id.cgi_name}"
- type="hidden"
- value="${lineitem.id()}" />
- <input name="${c.oils.acq.lineitem_item_count.cgi_name}"
- type="text" size="3"
- value="${lineitem.item_count()}"
- smallDelta="1"
- dojoType="dijit.form.NumberSpinner"
- constraints="{min:0,places:0}" />
- <button type='submit'
- dojoType="dijit.form.Button">${_("Update")}</button>
- </form>
- % endif
- </td>
- </tr>
- % endfor
- </tbody>
-</table>
-</div>
+<div id="oils-acq-picklist-grid"> </div>
+<script type="text/javascript" src="${c.oils.core.media_prefix.value}/js/util/Dojo.js"></script>
+<script type="text/javascript" src="${c.oils.core.media_prefix.value}/js/openils/acq/Picklist.js"></script>
+<script type="text/javascript">
+ dojo.require('openils.acq.Picklist');
+
+ var cols = [
+ {name: "${_('ID')}", field: 'id'},
+ {name: "${_('Title')}", field: 'title'},
+ {name: "${_('Price')}", field: 'price'},
+ {name: "${_('Vendor')}", field: 'provider'},
+ {name: "${_('# of Copies')}", field: 'copies'}
+ ];
+
+ dojo.addOnLoad(function(){openils.acq.Picklist.loadGrid('oils-acq-picklist-grid', cols, ${c.oils.acq.picklist.value.id()})});
+</script>
</%def>
Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/base.html
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/base.html 2008-04-10 02:18:34 UTC (rev 9289)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/base.html 2008-04-10 02:18:49 UTC (rev 9290)
@@ -2,6 +2,15 @@
<%inherit file='../base.html'/>
<%def name="body_css()">tundra</%def>
+<%def name="block_js()">
+ ${parent.block_js()}
+
+ <script type="text/javascript">
+ dojo.require("dijit.layout.LayoutContainer")
+ dojo.require("dijit.layout.ContentPane")
+ </script>
+</%def>
+
<%def name='block_body_content()'>
<div id="oils-base-body-block" class="tundra"
dojoType="dijit.layout.LayoutContainer">
Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/navigate.html
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/navigate.html 2008-04-10 02:18:34 UTC (rev 9289)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/navigate.html 2008-04-10 02:18:49 UTC (rev 9290)
@@ -1,6 +1,8 @@
<script>
/* Create a simple data store to organize the menu options */
dojo.require("dijit.Tree");
+ dojo.require("dojo.data.ItemFileReadStore");
+
var menuData = {
data : {
label: 'label',
More information about the open-ils-commits
mailing list