var SV_FETCH_ALL = 'open-ils.circ:open-ils.circ.survey.retrieve.all';
var FETCH_ID_TYPES = 'open-ils.actor:open-ils.actor.user.ident_types.retrieve';
var FETCH_GROUPS = 'open-ils.actor:open-ils.actor.groups.tree.retrieve';
-var identTypes = null;
+var identTypes = {};
var groupTree = null;
+var cachedSurveys = {};
var ERRORS = ""; /* global set of errors */
var myPerms = [ 'CREATE_USER', 'UPDATE_USER', 'CREATE_PATRON_STAT_CAT_ENTRY_MAP' ];
);
}
+/* UI code ---------------------------------------------------- */
+
function uEditNext() {
var i = _findActive();
if( i < (pages.length - 1)) uEditShowPage(pages[i+1]);
if( i > 0 ) uEditShowPage(pages[i-1]);
}
+function uEditFetchError(id) { if($(id)) return $(id).innerHTML + "\n"; return "";}
function uEditShowPage(id) {
if( id == null ) return;
}
-
-function uEditDrawUser(patron) {
- if(!patron) return 0;
-}
-
+/* ------------------------------------------------------------------------------ */
+/* Fetch code
+/* ------------------------------------------------------------------------------ */
function uEditFetchIDTypes() {
var req = new Request(FETCH_ID_TYPES);
req.callback(uEditDrawIDTypes);
req.send();
}
+function uEditFetchStatCats() {
+ var req = new Request(SC_FETCH_ALL, SESSION);
+ req.callback(uEditDrawStatCats);
+ req.send();
+}
+
+function uEditFetchSurveys() {
+ var req = new Request(SV_FETCH_ALL, SESSION);
+ req.callback(uEditDrawSurveys);
+ req.send();
+}
+
+
+/* ------------------------------------------------------------------------------ */
+/* Save the user
+/* ------------------------------------------------------------------------------ */
+var uEditExistingStatEnties;
+var uEditExistingSurveyResponses;
+
+function uEditSaveUser() {
+ uEditCollectData();
+ if(ERRORS) { alert(ERRORS); ERRORS = ""; }
+ else alert(js2JSON(patron));
+}
+
+function uEditCollectData() {
+
+ var card = null;
+
+ if(patron == null) {
+ patron = new au();
+ patron.isnew(1);
+ patron.id(-1);
+ card = new ac();
+ patron.card(-1); /* attach to the virtual id of the card */
+ patron.cards([card]);
+
+ } else {
+
+ patron.ischanged(1);
+ patron.isnew(0);
+ uEditExistingStatEnties = patron.stat_cat_entries();
+ uEditExistingSurveyResponses = patron.survey_responses();
+ }
+
+ patron.stat_cat_entries([]);
+ patron.survey_responses([]);
+
+ uEditFleshCard(card);
+ uEditAddBasicPatronInfo(patron);
+ uEditAddPhones(patron);
+ uEditAddIdents(patron);
+ uEditAddAddresses(patron);
+ uEditAddGroupsAndPerms(patron);
+ uEditReapStatCats(patron);
+ uEditReapSurveys(patron);
+
+}
+
+
+
+/* ------------------------------------------------------------------------------ */
+/* Draw the user
+/* ------------------------------------------------------------------------------ */
+function uEditDrawUser(patron) {
+ if(!patron) return 0;
+}
+
+
+
+
+
+/* ------------------------------------------------------------------------------ */
+/* Draw the ID types
+/* ------------------------------------------------------------------------------ */
function uEditDrawIDTypes(r) {
var types = r.getResultObject();
var idx = 1;
for( var t in types ) {
var type = types[t];
+ identTypes[type.id()] = type;
setSelectorVal( pri_sel, idx, type.name(), type.id() );
setSelectorVal( sec_sel, idx++, type.name(), type.id() );
}
- identTypes = types;
}
-function uEditFetchStatCats() {
- var req = new Request(SC_FETCH_ALL, SESSION);
- req.callback(uEditDrawStatCats);
- req.send();
-}
+
+/* ------------------------------------------------------------------------------ */
+/* Stat Cat handling code
+/* ------------------------------------------------------------------------------ */
function uEditDrawStatCats(r) {
var cats = r.getResultObject();
var tbody = $('ue_stat_cat_tbody');
}
}
+/* fleshes the stat cat with entries in the dropdown */
function uEditInsertCat( tbody, row, cat, idx ) {
cat.entries().sort( /* sort the entries by value */
}
);
+ row.setAttribute('statcat', cat.id());
+ var newval = $n(row, 'ue_stat_cat_newval');
+ newval.onchange = function(){
+ findParentNodeByName(newval,'tr').setAttribute('changed', '1'); }
+
var selector = $n(row, 'ue_stat_cat_selector');
+ selector.onchange = function(){
+ findParentByNodeName(selector, 'tr').setAttribute('changed', '1');
+ newval.value = getSelectorName(selector);
+ newval.setAttribute('entry', getSelectorVal(selector));
+ }
+
if( idx == 0 ) selector.id = 'ue_stat_cat_selector_1';
+
$n(row, 'ue_stat_cat_name').appendChild(text(cat.name()));
- $n(row, 'ue_stat_cat_owner').appendChild(text(fetchOrgUnit(cat.owner()).shortname()));
+ $n(row, 'ue_stat_cat_owner').appendChild(
+ text(fetchOrgUnit(cat.owner()).shortname()));
var idx = 1;
for( var e in cat.entries() ) {
}
}
-function uEditFetchSurveys() {
- var req = new Request(SV_FETCH_ALL, SESSION);
- req.callback(uEditDrawSurveys);
- req.send();
+/* finds all the changed/new stat entries and updates the patron object*/
+function uEditReapStatCats(patron) {
+ var tbody = $('ue_stat_cat_tbody');
+ for( var r in tbody.childNodes ) {
+ var row = tbody.childNodes[r];
+ if( !row || row.nodeName != 'tr' ) continue;
+ if( row.getAttribute('changed') ) {
+ var val = $n( row, 'ue_stat_cat_newval' );
+ uEditCreateStatEntry( patron, row.getAttribute('statcat'),
+ val.value, val.getAttribute('entry') );
+ }
+ }
+}
+
+
+function uEditCreateStatEntry( patron, catid, newval, entryid ) {
+ var map = new actscecm();
+ map.isnew(1);
+
+ if( ! patron.isnew() ) {
+ if( grep( uEditExistingStatEntries,
+ function(a) { return a.id() == entryid } ) )
+ map.ischanged(1);
+ }
+
+ map.stat_cat_entry(newval);
+ map.stat_cat(catid);
+ map.target_usr(patron.id());
+ patron.stat_cat_entries().push(map);
}
+
+
+/* ------------------------------------------------------------------------------ */
+/* Survey handling code
+/* ------------------------------------------------------------------------------ */
function uEditDrawSurveys(r) {
var surveys = r.getResultObject();
var x = 0;
for( var s in surveys ) {
var survey = surveys[s];
+ cachedSurveys[survey.id()] = survey;
var clone = table.cloneNode(true);
uEditInsertSurvey( div, clone, survey, x++ );
div.appendChild(clone);
var polltbody = $n(row, 'ue_survey_answer_poll_tbody');
var pollrow = polltbody.removeChild($n(polltbody, 'ue_survey_answer_poll_row'));
+ table.setAttribute('survey', survey.id());
+ row.setAttribute('question', question.id());
+
+ selector.onchange = function() {
+ row.setAttribute('answer', getSelectorVal(selector));
+ row.setAttribute('changed', '1');
+ }
+
if( sidx == 0 ) selector.id = 'ue_survey_selector_1';
for( var a in question.answers() ) {
unHideMe(polldiv);
var prow = pollrow.cloneNode(true);
+
+ prow.onselect = function() {
+ row.setAttribute('answer', answer.id());
+ row.setAttribute('changed', '1');
+ }
+
$n(prow, 'ue_survey_answer_poll_answer').appendChild(text(answer.answer()));
$n(prow, 'ue_survey_answer_poll_radio').appendChild(
}
-function uEditFetchError(id) { if($(id)) return $(id).innerHTML + "\n"; return "";}
-
+function uEditReapSurveys(patron) {
-function uEditSaveUser() {
+ var div = $('uedit_surveys');
+ var tables = getElementsByTagNameFlat(div, 'table');
+
+ for( var t in tables ) {
+
+ var table = tables[t];
+ var survey = cachedSurveys[table.getAttribute('survey')];
+ var tbody = getElementsByTagNameFlat( table, 'tbody' )[0];
+ var rows = getElementsByTagNameFlat( tbody, 'tr' );
+
+ for( var r in rows ) {
+ var row = rows[r];
+ var resp = new asvr();
+ resp.isnew(1);
+ resp.survey(survey.id());
+ resp.usr(patron.id());
+ resp.question(row.getAttribute('question'));
+ resp.answer(row.getAttribute('answer'));
+ patron.survey_responses().push( resp );
+ }
+ }
+}
- var card = null;
- if(patron == null) {
- patron = new au();
- patron.isnew(1);
- card = new ac();
- patron.card(-1); /* attach to the virtual id of the card */
- patron.cards([card]);
- } else {
- patron.ischanged(1);
- patron.isnew(0);
- }
- uEditFleshCard(card);
- uEditAddBasicPatronInfo(patron);
- uEditAddPhones(patron);
- uEditAddIdents(patron);
- uEditAddAddresses(patron);
- uEditAddGroupsAndPerms(patron);
- if(ERRORS) { alert(ERRORS); ERRORS = ""; }
- else alert(js2JSON(patron));
-}
/* returns true if an error occurred */
function uEditSetVal( obj, func, val, regxtype, errtype ) {
function uEditAddAddresses(patron) {
var tbody = $('ue_address_tbody');
+ patron.addresses([]);
+ /* shove the addresses living in the page into the patron */
for( var r in tbody.childNodes ) {
var row = tbody.childNodes[r];
if(!(row && row.nodeName == 'tr')) continue;
- uEditSetAddress( tbody, row );
+ patron.addresses().push( uEditBuildAddress( patron, tbody, row ));
}
}
/* extracts a single address from the page */
-function uEditSetAddress( tbody, row ) {
+var uEditVirtualAddrId = -1;
+function uEditBuildAddress( patron, tbody, row ) {
+
+ var addr = new aua();
+ var id = row.getAttribute('exists');
+
+ if(id) {
+ addr.id(id)
+ addr.ischanged(1);
+ addr.isnew(0);
+ } else {
+ addr.id(uEditVirtualAddrId--);
+ addr.isnew(1);
+ }
- var label = $n(row, 'ue_addr_label');
- var street1 = $n(row, 'ue_addr_street1');
- var street2 = $n(row, 'ue_addr_street2');
- var city = $n(row, 'ue_addr_city');
- var county = $n(row, 'ue_addr_county');
- var state = $n(row, 'ue_addr_state');
- var zip = $n(row, 'ue_addr_zip');
- var country = $n(row, 'ue_addr_country');
+ if($n(row, 'ue_addr_mailing_yes')) patron.mailing_address(addr.id());
+ if($n(row, 'ue_addr_billing_yes')) patron.billing_address(addr.id());
+ uEditSetVal(addr, "address_type", $n(row, 'ue_addr_address_type'), null, 'ue_bad_addr_address_type' );
+ uEditSetVal(addr, "street1", $n(row, 'ue_addr_street1'), null, 'ue_bad_addr_street' );
+ uEditSetVal(addr, "street2", $n(row, 'ue_addr_street2'), null, 'ue_bad_addr_street' );
+ uEditSetVal(addr, "city", $n(row, 'ue_addr_city'), null, 'ue_bad_addr_city' );
+ uEditSetVal(addr, "county", $n(row, 'ue_addr_county'), null, 'ue_bad_addr_county' );
+ uEditSetVal(addr, "state", $n(row, 'ue_addr_state'), null, 'ue_bad_addr_state' );
+ uEditSetVal(addr, "post_code", $n(row, 'ue_addr_post_code'), null, 'ue_bad_addr_post_code' );
+ uEditSetVal(addr, "country", $n(row, 'ue_addr_country'), null, 'ue_bad_addr_country' );
+
+ return addr;
}
return;
}
}
+
+
+function uEditShowSummary() {
+ uEditCollectData();
+ var table = $('ue_summary_table');
+ uEditFleshSummaryTable(table);
+ var win = window.open("", $('ue_summary_window').innerHTML );
+ win.document.body.appendChild(table.cloneNode(true));
+}
+
+function uEditFleshSummaryTable(table) {
+ var identt1 = "";
+ var identt2 = "";
+ var homeorg = "";
+
+ if( patron.ident_type() != null)
+ identt1 = identTypes[patron.ident_type()].name();
+ if( patron.ident_type2() != null )
+ identt2 = identTypes[patron.ident_type()].name();
+ if( patron.home_ou() != null )
+ homeorg = findOrgUnit(patron.home_ou()).name();
+
+ $('ue_summary_username').appendChild(text(patron.usrname()));
+ $('ue_summary_firstname').appendChild(text(patron.first_given_name()));
+ $('ue_summary_middlename').appendChild(text(patron.second_given_name()));
+ $('ue_summary_lastname').appendChild(text(patron.family_name()));
+ $('ue_summary_suffix').appendChild(text(patron.suffix()));
+ $('ue_summary_dob').appendChild(text(patron.dob()));
+ $('ue_summary_primary_ident_type').appendChild(text(identt1));
+ $('ue_summary_primary_ident').appendChild(text(patron.ident_value()));
+ $('ue_summary_secondary_ident_type').appendChild(text(identt2));
+ $('ue_summary_secondary_ident').appendChild(text(patron.ident_value2()));
+ $('ue_summary_email').appendChild(text(patron.email()));
+ $('ue_summary_dayphone').appendChild(text(patron.day_phone()));
+ $('ue_summary_nightphone').appendChild(text(patron.evening_phone()));
+ $('ue_summary_otherphone').appendChild(text(patron.other_phone()));
+ $('ue_summary_home_lib').appendChild(text(homeorg));
+}
+
+
#uedit_nav_bar { border: 2px solid #E0F0E0; padding: 6px;}
.nav_link { padding-left: 90px; padding-right: 90px; }
.main_nav_link { -moz-border-radius: 7px; height: 13%;}
- .main_div { height: 480px; padding-left: 15px; text-align: center; vertical-align: middle; overflow: auto;}
+ .main_div { height: 480px; padding-left: 15px;
+ text-align: center; vertical-align: middle; overflow: auto;}
.nav_link_table { height: 480px;}
.label_active { background: #E0F0E0; }
.right { text-align: right; padding-right: 3px;}
<!-- Addresses Pane -->
<!-- ************************************************************** -->
<div id='uedit_addresses' class='main_div hide_me' >
- <table class='uedit_table' style='width: 95%; padding: 1px;'>
+ <table class='uedit_table' style='width: 98%; padding: 1px;'>
<thead>
<tr>
<td>Address</td>
<tr>
<td colspan='6'>
<div class='button_row'>
- <input type='submit' name='ue_addr_delete' value='Delete this Address'
+ <input type='submit' name='ue_addr_delete'
+ value='Delete this Address'
onclick='
- var mytab = this.parentNode.parentNode.parentNode.parentNode.parentNode;
- mytab.parentNode.parentNode.parentNode.removeChild(mytab.parentNode.parentNode);
+ if( confirm($("ue_delete_addr_warn").innerHTML) ) {
+ var td = this.parentNode.parentNode;
+ var mytab = td.parentNode.parentNode.parentNode;
+ var top = mytab.parentNode.parentNode.parentNode;
+ top.removeChild(mytab.parentNode.parentNode);
+ }
'/>
</div>
</td>
</table>
</center>
+ <div id='ue_summary_page' class='hide_me'>
+ <table id='ue_summary_table' class='summary_grid'>
+ <style type='text/css'>
+ .summary_grid { padding: 5px; }
+ .summary_grid thead tr { background: #E0F0E0; font-weight: bold;}
+ .summary_grid tbody tr td { border: 1px solid #E0F0E0; }
+ </style>
+ <thead><tr><td colspan='2'>User Summary Information</td></tr></thead>
+ <tbody id='ue_summary_page_tbody'>
+ <tr><td>Username</td><td id='ue_summary_username'/></tr>
+ <tr><td>First Name</td><td id='ue_summary_firstname'/></tr>
+ <tr><td>Middle Name</td><td id='ue_summary_middlename'/></tr>
+ <tr><td>Last Name</td><td id='ue_summary_lastname'/></tr>
+ <tr><td>Suffix</td><td id='ue_summary_suffix'/></tr>
+ <tr><td>Date of Birth</td><td id='ue_summary_dob'/></tr>
+ <tr><td>Primary Identification Type</td><td id='ue_summary_primary_ident_type'/></tr>
+ <tr><td>Primary Identification</td><td id='ue_summary_primary_ident'/></tr>
+ <tr><td>Secondary Identification Type</td><td id='ue_summary_secondary_ident_type'/></tr>
+ <tr><td>Secondary Identification</td><td id='ue_summary_secondary_ident'/></tr>
+ <tr><td>Email Address</td><td id='ue_summary_email'/></tr>
+ <tr><td>Day Phone</td><td id='ue_summary_dayphone'/></tr>
+ <tr><td>Evening Phone</td><td id='ue_summary_nightphone'/></tr>
+ <tr><td>Other Phone</td><td id='ue_summary_otherphone'/></tr>
+ <tr><td>Home Library</td><td id='ue_summary_home_lib'/></tr>
+ <tr>
+ <td colspan='2'>
+ <table>
+ <thead><tr><td colspan='2'>Addresses</td></tr></thead>
+ <tbody id='ue_summary_addr_tbody'>
+ <tr>
+ <td>
+ <table id='ue_summary_addr_table'>
+ <tbody>
+ <tr><td>Address Label</td><td name='label'/></tr>
+ <tr><td>Street1</td><td name='street1'/></tr>
+ <tr><td>Street2</td><td name='street2'/></tr>
+ <tr><td>City</td><td name='city'/></tr>
+ <tr><td>County</td><td name='county'/></tr>
+ <tr><td>State</td><td name='state'/></tr>
+ <tr><td>Zip Code</td><td name='zip'/></tr>
+ <tr><td>Country</td><td name='country'/></tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+ <tr><td>Profile</td><td id='ue_summary_profile'/></tr>
+ <tr><td>Expire Date</td><td id='ue_summary_expire'/></tr>
+ <tr><td>Family Lead Account</td><td id='ue_summary_family_lead'/></tr>
+ <tr><td>Claims Returned Count</td><td id='ue_summary_claims_returned'/></tr>
+ <tr><td>Alert Message</td><td id='ue_summary_alert_message'/></tr>
+ <tr>
+ <td>
+ <table>
+ <thead><tr><td colspan='2'>Statistical Category Updates</td></tr></thead>
+ <tbody id='ue_summary_stats_tbody'>
+ <tr id='ue_summary_stats_row'>
+ <td name='name'/><td name='value'/>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <table>
+ <thead><tr><td colspan='2'>Survey Responses</td></tr></thead>
+ <tbody id='ue_summary_survey_tbody'>
+ <tr id='ue_summary_survey_row'>
+ <td name='name'/><td name='value'/>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><input type='submit' value='Print Page'/></td>
+ <td><input type='submit' value='Close Window'/></td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+
<!-- ************************************************************** -->
<!-- This holds all of the strings we may have to alert to the user -->
<!-- ************************************************************** -->
<span id='ue_bad_claims_returned'>The claims returned count is invalid</span>
<span id='ue_no_profile'>A profile group must be selected</span>
<span id='ue_unknown_error'>An unknown formatting error occurred</span>
+ <span id='ue_bad_addr_lable'>Address label is invalid</span>
+ <span id='ue_bad_addr_street'>Address street is invalid</span>
+ <span id='ue_bad_addr_city'>Address city is invalid</span>
+ <span id='ue_bad_addr_county'>Address county is invalid</span>
+ <span id='ue_bad_addr_state'>Address state is invalid</span>
+ <span id='ue_bad_addr_country'>Address country is invalid</span>
+ <span id='ue_bad_addr_zip'>Address zip is invalid</span>
+ <span id='ue_delete_addr_warn'>
+ This will remove this address from the user.
+ Are you sure you wish to continue?
+ </span>
+ <span id='yes'>Yes</span>
+ <span id='no'>No</span>
+ <span id='ue_summary_window'>Patron Summary</span>
</div>
</body>