initial plugin of staff-cats
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 17 Feb 2009 02:30:46 +0000 (02:30 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 17 Feb 2009 02:30:46 +0000 (02:30 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@12194 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/ui/default/actor/user/register.js
Open-ILS/web/templates/default/actor/user/register.tt2

index 3eaf1bf..cb033f8 100644 (file)
@@ -1,6 +1,7 @@
 dojo.require('dojo.data.ItemFileReadStore');
 dojo.require('dijit.form.Textarea');
 dojo.require('dijit.form.FilteringSelect');
+dojo.require('dijit.form.ComboBox');
 dojo.require('fieldmapper.IDL');
 dojo.require('openils.PermaCrud');
 dojo.require('openils.widget.AutoGrid');
@@ -10,81 +11,101 @@ dojo.require('dijit.form.CheckBox');
 var pcrud;
 var fmClasses = ['au', 'ac', 'aua', 'actsc', 'asv', 'asvq', 'asva'];
 var fieldDoc = {};
+var statCats;
+var surveys;
+var staff;
 
 
 function load() {
+    staff = new openils.User().user;
     pcrud = new openils.PermaCrud();
-    pcrud.search('fdoc', 
-        {fm_class:fmClasses},
-        {
-            oncomplete : function(r) {
-                var list = openils.Util.readResponse(r, null, true);
-                for(var i in list) {
-                    var doc = list[i];
-                    if(!fieldDoc[doc.fm_class()])
-                        fieldDoc[doc.fm_class()] = {};
-                    fieldDoc[doc.fm_class()][doc.field()] = doc;
-                }
-                loadTable();
-            }
-        }
+
+    var list = pcrud.search('fdoc', {fm_class:fmClasses});
+    for(var i in list) {
+        var doc = list[i];
+        if(!fieldDoc[doc.fm_class()])
+            fieldDoc[doc.fm_class()] = {};
+        fieldDoc[doc.fm_class()][doc.field()] = doc;
+    }
+
+    statCats = fieldmapper.standardRequest(
+        ['open-ils.circ', 'open-ils.circ.stat_cat.actor.retrieve.all'],
+        {params : [openils.User.authtoken, staff.ws_ou()]}
+    );
+
+    surveys = fieldmapper.standardRequest(
+        ['open-ils.circ', 'open-ils.circ.survey.retrieve.all'],
+        {params : [openils.User.authtoken]}
     );
+
+    loadTable();
 }
 
 function loadTable() {
     var tbody = dojo.byId('uedit-tbody');
-
     for(var idx = 0; tbody.childNodes[idx]; idx++) {
-
         var row = tbody.childNodes[idx];
         if(row.nodeType != row.ELEMENT_NODE) continue;
         var fmcls = row.getAttribute('fmclass');
         if(!fmcls) continue;
+        fleshFMRow(row, fmcls);
+    }
 
-        var fmfield = row.getAttribute('fmfield');
-        var wclass = row.getAttribute('wclass');
-        var wstyle = row.getAttribute('wstyle');
-        var fieldIdl = fieldmapper.IDL.fmclasses[fmcls].field_map[fmfield];
-
-        if(!fieldIdl)
-            console.log("failed loading " + fmcls + ' : ' + fmfield);
-
-        var existing = dojo.query('td', row);
-        var htd = existing[0] || row.appendChild(document.createElement('td'));
-        var ltd = existing[1] || row.appendChild(document.createElement('td'));
-        var wtd = existing[2] || row.appendChild(document.createElement('td'));
-
-        openils.Util.addCSSClass(htd, 'uedit-help');
-        if(fieldDoc[fmcls] && fieldDoc[fmcls][fmfield]) {
-            var link = dojo.byId('uedit-help-template').cloneNode(true);
-            link.id = '';
-            link.setAttribute('href', 'javascript:ueLoadContextHelp("'+fmcls+'","'+fmfield+'")');
-            openils.Util.removeCSSClass(link, 'hidden');
-            htd.appendChild(link);
-            console.log(link.href);
-        }
-
-        if(!ltd.textContent) {
-            var span = document.createElement('span');
-            ltd.appendChild(document.createTextNode(fieldIdl.label));
-        }
-
-        span = document.createElement('span');
-        wtd.appendChild(span);
-
-        var widget = new openils.widget.AutoFieldWidget({
-            idlField : fieldIdl,
-            fmObject : null, // XXX
-            fmClass : fmcls,
-            parentNode : span,
-            widgetClass : wclass,
-            dijitArgs : {style: wstyle},
-            orgLimitPerms : ['UPDATE_USER'],
-        });
-        widget.build();
+    for(var idx in statCats) {
+        var stat = statCats[idx];
+        var row = dojo.byId('stat-cat-row-' + idx);
+        if(!row) row = dojo.byId('stat-cat-row-0').cloneNode(true);
+        row.id = 'stat-cat-row-' + idx;
+        dojo.query('[name=name]', row)[0].innerHTML = stat.name();
+        var valtd = dojo.query('[name=widget]', row)[0];
+        var span = valtd.appendChild(document.createElement('span'));
+        new dijit.form.ComboBox({}, span);
+        tbody.insertBefore(row, dojo.byId('survey-cat-divider'));
     }
 }
 
+
+function fleshFMRow(row, fmcls) {
+    var fmfield = row.getAttribute('fmfield');
+    var wclass = row.getAttribute('wclass');
+    var wstyle = row.getAttribute('wstyle');
+    var fieldIdl = fieldmapper.IDL.fmclasses[fmcls].field_map[fmfield];
+
+    var existing = dojo.query('td', row);
+    var htd = existing[0] || row.appendChild(document.createElement('td'));
+    var ltd = existing[1] || row.appendChild(document.createElement('td'));
+    var wtd = existing[2] || row.appendChild(document.createElement('td'));
+
+    openils.Util.addCSSClass(htd, 'uedit-help');
+    if(fieldDoc[fmcls] && fieldDoc[fmcls][fmfield]) {
+        var link = dojo.byId('uedit-help-template').cloneNode(true);
+        link.id = '';
+        link.setAttribute('href', 'javascript:ueLoadContextHelp("'+fmcls+'","'+fmfield+'")');
+        openils.Util.removeCSSClass(link, 'hidden');
+        htd.appendChild(link);
+    }
+
+    if(!ltd.textContent) {
+        var span = document.createElement('span');
+        ltd.appendChild(document.createTextNode(fieldIdl.label));
+    }
+
+    span = document.createElement('span');
+    wtd.appendChild(span);
+
+    var widget = new openils.widget.AutoFieldWidget({
+        idlField : fieldIdl,
+        fmObject : null, // XXX
+        fmClass : fmcls,
+        parentNode : span,
+        widgetClass : wclass,
+        dijitArgs : {style: wstyle},
+        orgLimitPerms : ['UPDATE_USER'],
+    });
+    widget.build();
+}
+
+
 function ueLoadContextHelp(fmcls, fmfield) {
     openils.Util.removeCSSClass(dojo.byId('uedit-help-div'), 'hidden');
     dojo.byId('uedit-help-field').innerHTML = fieldmapper.IDL.fmclasses[fmcls].field_map[fmfield].label;
index c412eb8..f4bdb86 100644 (file)
         <tr><td class='uedit-help'><td>Mailing Address</td>
             <td><div dojoType='dijit.form.CheckBox' name='billing-addr-widget'></div></td>
         </tr>
-        <tr class='divider'><td colspan='10'>Statistical Categories</td></tr>
-        <tr class='divider'><td colspan='10'>Surveys</td></tr>
+        <tr class='divider' id='stat-cat-divider'><td colspan='10'>Statistical Categories</td></tr>
+        <tr id='stat-cat-row-0'><td class='uedit-help'/><td name='name'/><td name='widget'/></tr>
+        <tr class='divider' id='survey-cat-divider'><td colspan='10'>Surveys</td></tr>
     </tbody>
 </table>
 [% END %]
+