[open-ils-commits] r12895 - in trunk/Open-ILS/web: css/skin/default js/ui/default/acq/common templates/default/acq/common (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Apr 16 15:56:20 EDT 2009


Author: erickson
Date: 2009-04-16 15:56:16 -0400 (Thu, 16 Apr 2009)
New Revision: 12895

Modified:
   trunk/Open-ILS/web/css/skin/default/acq.css
   trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js
   trunk/Open-ILS/web/templates/default/acq/common/li_table.tt2
Log:
create / edit lineitem notes

Modified: trunk/Open-ILS/web/css/skin/default/acq.css
===================================================================
--- trunk/Open-ILS/web/css/skin/default/acq.css	2009-04-16 19:54:19 UTC (rev 12894)
+++ trunk/Open-ILS/web/css/skin/default/acq.css	2009-04-16 19:56:16 UTC (rev 12895)
@@ -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; }

Modified: trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js
===================================================================
--- trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js	2009-04-16 19:54:19 UTC (rev 12894)
+++ trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js	2009-04-16 19:56:16 UTC (rev 12895)
@@ -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 @@
     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 @@
         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 @@
         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 @@
             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 @@
 
     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,8 +181,112 @@
     };
 
     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) {
 
         var price = input.value;

Modified: trunk/Open-ILS/web/templates/default/acq/common/li_table.tt2
===================================================================
--- trunk/Open-ILS/web/templates/default/acq/common/li_table.tt2	2009-04-16 19:54:19 UTC (rev 12894)
+++ trunk/Open-ILS/web/templates/default/acq/common/li_table.tt2	2009-04-16 19:56:16 UTC (rev 12895)
@@ -114,6 +114,53 @@
         </div>
     </div>
 
+    <!-- Lineitem notes table -->
+    <div id='acq-lit-notes-div' class='hidden'>
+
+        <div class='acq-lit-li-menu-bar'>
+            <table style='width:100%'>
+                <tr>
+                    <td style='text-align:left;'>
+                        <div dojoType='dijit.form.Button' id='acq-lit-notes-back-button'>&#x2196; Return</div>
+                    </td>
+                    <td style='text-align:right;'>
+                        <div dojoType='dijit.form.Button' id='acq-lit-notes-new-button'>New Note</div>
+                        <div dojoType='dijit.form.Button' id='acq-lit-notes-save-button'>Save Changes</div>
+                    </td>
+                </tr>
+            </table>
+        </div>
+
+        <table class='oils-generic-table'>
+            <thead><tr>
+                <th>Creator</th>
+                <th>Create Time</th>
+                <th>Editor</th>
+                <th>Edit Time</th>
+                <th>Value</th>
+                <th/>
+            </tr></thead>
+            <tbody id='acq-lit-notes-tbody'>
+                <tr id='acq-lit-notes-row'>
+                    <td><div name='creator'/></td>
+                    <td><div name='create_time'/></td>
+                    <td><div name='editor'/></td>
+                    <td><div name='edit_time'/></td>
+                    <td class='acq-lit-note-textarea'><div name='value'/></td>
+                    <td><div name='delete' dojoType='dijit.form.Button' style='color:red;'>X</div></td>
+                </tr>
+            </tbody>
+        </table>
+    </div>
+
+    <div class='hidden'>
+        <div dojoType='dijit.Dialog' jsId='acqLitCreateLiNoteDialog'>
+            <div dojoType='dijit.form.Textarea' style='height:6em; width:40em;' name='note'></div>
+            <br/>
+            <div dojoType='dijit.form.Button' type='submit' jsId='acqLitCreateLiNoteSubmit'>Create</div>
+        </div>
+    </div>
+ 
     <!-- Copies table -->
     <div id='acq-lit-li-details' class='hidden'>
         <h2>Copies</h2>



More information about the open-ils-commits mailing list