create / edit lineitem notes
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 16 Apr 2009 19:56:16 +0000 (19:56 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 16 Apr 2009 19:56:16 +0000 (19:56 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@12895 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/css/skin/default/acq.css
Open-ILS/web/js/ui/default/acq/common/li_table.js
Open-ILS/web/templates/default/acq/common/li_table.tt2

index c2d1967..bc02831 100644 (file)
 #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; }
index c8cc76d..4097f44 100644 (file)
@@ -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) {
index d3e5f34..18ba76a 100644 (file)
         </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>