From 13477e80a8c422492ebb81ba265307de3637bd6c Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 16 Apr 2009 19:56:16 +0000 Subject: [PATCH] create / edit lineitem notes git-svn-id: svn://svn.open-ils.org/ILS/trunk@12895 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/css/skin/default/acq.css | 1 + Open-ILS/web/js/ui/default/acq/common/li_table.js | 134 ++++++++++++++++++++- .../web/templates/default/acq/common/li_table.tt2 | 47 ++++++++ 3 files changed, 180 insertions(+), 2 deletions(-) diff --git a/Open-ILS/web/css/skin/default/acq.css b/Open-ILS/web/css/skin/default/acq.css index c2d19670ed..bc028318dc 100644 --- a/Open-ILS/web/css/skin/default/acq.css +++ b/Open-ILS/web/css/skin/default/acq.css @@ -102,6 +102,7 @@ #acq-lit-li-details-table th {padding:0px 3px 1px 3px; font-weight:bold;} #acq-lit-li-details-table .dijit {width:130px;} #acq-lit-li-details-table td input {width:100px;} +.acq-lit-note-textarea div { padding: 2px 5px 2px 5px; } .acq-lit-li-menu-bar {width:99%; text-align:left; border:1px solid #aaa; margin:5px 0px 10px 0px;} .acq-lit-table-spacer { height:20px; } diff --git a/Open-ILS/web/js/ui/default/acq/common/li_table.js b/Open-ILS/web/js/ui/default/acq/common/li_table.js index c8cc76d281..4097f440bf 100644 --- a/Open-ILS/web/js/ui/default/acq/common/li_table.js +++ b/Open-ILS/web/js/ui/default/acq/common/li_table.js @@ -1,6 +1,9 @@ +dojo.require('dojo.date.locale'); +dojo.require('dojo.date.stamp'); dojo.require('dijit.form.Button'); dojo.require('dijit.form.TextBox'); dojo.require('dijit.form.FilteringSelect'); +dojo.require('dijit.form.Textarea'); dojo.require('dijit.ProgressBar'); dojo.require('openils.User'); dojo.require('openils.Util'); @@ -26,6 +29,8 @@ function AcqLiTable() { this.copyRow = this.copyTbody.removeChild(dojo.byId('acq-lit-li-details-row')); this.copyBatchRow = dojo.byId('acq-lit-li-details-batch-row'); this.copyBatchWidgets = {}; + this.liNotesTbody = dojo.byId('acq-lit-notes-tbody'); + this.liNotesRow = this.liNotesTbody.removeChild(dojo.byId('acq-lit-notes-row')); dojo.connect(acqLitLiActionsSelector, 'onChange', function() { @@ -43,9 +48,12 @@ function AcqLiTable() { self._savePl(acqLitSavePlDialog.getValues()); } + dojo.byId('acq-lit-notes-new-button').onclick = function(){acqLitCreateLiNoteDialog.show();} + dojo.byId('acq-lit-select-toggle').onclick = function(){self.toggleSelect()}; dojo.byId('acq-lit-info-back-button').onclick = function(){self.show('list')}; dojo.byId('acq-lit-copies-back-button').onclick = function(){self.show('list')}; + dojo.byId('acq-lit-notes-back-button').onclick = function(){self.show('list')}; this.reset = function() { while(self.tbody.childNodes[0]) @@ -77,7 +85,8 @@ function AcqLiTable() { openils.Util.hide('acq-lit-table-div'); openils.Util.hide('acq-lit-info-div'); openils.Util.hide('acq-lit-li-details'); - switch(div){ + openils.Util.hide('acq-lit-notes-div'); + switch(div) { case 'list': openils.Util.show('acq-lit-table-div'); break; @@ -87,6 +96,9 @@ function AcqLiTable() { case 'copies': openils.Util.show('acq-lit-li-details'); break; + case 'notes': + openils.Util.show('acq-lit-notes-div'); + break; default: if(div) openils.Util.show(div); @@ -125,7 +137,21 @@ function AcqLiTable() { this.addLineitem = function(li) { this.liCache[li.id()] = li; - if(!li.lineitem_notes()) li.lineitem_notes([]); + + // sort the lineitem notes on create_time + if(li.lineitem_notes()) { + li.lineitem_notes( + li.lineitem_notes().sort( + function(a, b) { + if(a.create_time() < b.create_time()) return 1; + return -1; + } + ) + ); + } else { + li.lineitem_notes([]); + } + var liWrapper = new openils.acq.Lineitem({lineitem:li}); var row = self.rowTemplate.cloneNode(true); row.setAttribute('li', li.id()); @@ -155,6 +181,110 @@ function AcqLiTable() { }; this.drawLiNotes = function(li) { + var self = this; + + while(this.liNotesTbody.childNodes[0]) + this.liNotesTbody.removeChild(this.liNotesTbody.childNodes[0]); + this.show('notes'); + + acqLitCreateLiNoteSubmit.onClick = function() { + acqLitCreateLiNoteDialog.hide(); + var value = acqLitCreateLiNoteDialog.getValues().note; + if(!value) return; + var note = new fieldmapper.acqlin(); + note.isnew(true); + note.value(value); + li.lineitem_notes().push(note); + note.lineitem(li.id()); + self.addLiNote(li, note); + } + + dojo.byId('acq-lit-notes-save-button').onclick = function() { + self.updateLiNotes(li); + } + + dojo.forEach(li.lineitem_notes(), function(note) { self.addLiNote(li, note) }); + } + + this.addLiNote = function(li, note) { + var self = this; + var row = self.liNotesRow.cloneNode(true); + dojo.query('[name=creator]', row)[0].innerHTML = note.creator() || ''; /* XXX */ + dojo.query('[name=editor]', row)[0].innerHTML = note.editor() || ''; /* XXX */ + + if(note.create_time()) { + dojo.query('[name=create_time]', row)[0].innerHTML = + dojo.date.locale.format( + dojo.date.stamp.fromISOString(note.create_time()), + {formatLength:'short'}); + } + + if(note.edit_time()) { + dojo.query('[name=edit_time]', row)[0].innerHTML = + dojo.date.locale.format( + dojo.date.stamp.fromISOString(note.edit_time()), + {formatLength:'short'}); + } + + new openils.widget.AutoFieldWidget({ + fmField : 'value', + fmObject : note, + parentNode : dojo.query('[name=value]', row)[0], + widgetClass : 'dijit.form.Textarea', + }).build( + function(w) { + dojo.connect(w, 'onChange', + function() { + note.value(this.attr('value')); + note.ischanged(true); + } + ); + } + ); + + dojo.query('[name=delete]', row)[0].onclick = function() { + note.isdeleted(true); + self.liNotesTbody.removeChild(row); + }; + + self.liNotesTbody.appendChild(row); + } + + this.updateLiNotes = function(li) { + progressDialog.show(); + + var notes = li.lineitem_notes().filter( + function(note) { + if(note.ischanged() || note.isnew() || note.isdeleted()) + return note; + } + ); + + fieldmapper.standardRequest( + ['open-ils.acq', 'open-ils.acq.lineitem_note.cud.batch'], + { async : true, + params : [this.authtoken, notes], + onresponse : function(r) { + var resp = openils.Util.readResponse(r); + + if(resp.complete) { + progressDialog.hide(); + self.drawLiNotes(li); + return; + } + + progressDialog.update(resp); + + var newnote = resp.note; + var oldnote = li.lineitem_notes().filter(function(n) { return (n.value() == newnote.value()) })[0]; + var notes = li.lineitem_notes().filter(function(n) { return (n.value() != newnote.value()) }); + + if(!openils.Util.isTrue(oldnote.isdeleted())) + notes.push(newnote); + li.lineitem_notes(notes); + }, + } + ); } this.updateLiPrice = function(input, li) { diff --git a/Open-ILS/web/templates/default/acq/common/li_table.tt2 b/Open-ILS/web/templates/default/acq/common/li_table.tt2 index d3e5f34c60..18ba76abca 100644 --- a/Open-ILS/web/templates/default/acq/common/li_table.tt2 +++ b/Open-ILS/web/templates/default/acq/common/li_table.tt2 @@ -114,6 +114,53 @@ + + + + +