BDG Scenario 3

PersonGroup.js

window.onload = window_onLoad;

function window_onLoad() {
   var id = getParam('pid');
   if (id) {
      document.frmPerson.PersonId.value = id;
      var xml='../Scripts/viewData.asp?tableName=person&fieldList=LastName,FirstName&whereID=' + id;
      xmldso_info.XMLDocument.ondataavailable = setUserName;
      xmldso_info.XMLDocument.load(xml);
      xml = '../Scripts/viewData.asp?procName=lw_getSchedule&personID=' + id;
      xmldso.XMLDocument.ondataavailable = loaded;
      xmldso.XMLDocument.load(xml);
   }
}

function addClass(id,name) {
   //enable the submit changes button
   frmPerson.cmdSubmit.disabled = false;
   
   var found = false;
   var sel = document.frmPerson.groupId;
   // search for existing entry
   for (var i=0; i<sel.options.length; i++) {
      var opt = sel.options[i];
      if (opt.value == id) {
         // if found, flash to indicate already added...
         opt.selected = !opt.selected;
         found = true;
         break;
      }
   }
   if (!found) {
      var opt = document.createElement("OPTION");
      opt.value = id;
      opt.text = name;
      sel.options.add(opt);
      setDirty();
   }
}

function removeClass() {
   var sel = document.frmPerson.groupId;
   if (sel.selectedIndex >= 0) {
      sel.options.remove(sel.selectedIndex);
      setDirty();
   }
}

// copies data from xmldso_info to "PersonInfo" SPAN tag
function setUserName() {
   var HTML = '<B>unknown</B>';
   var doc = xmldso_info.XMLDocument.documentElement;
   if (doc) {
      var record = doc.firstChild;
      var fname = record.selectSingleNode("./FirstName");
      var lname = record.selectSingleNode("./LastName");
      var HTML = '<B>' + fname.text + ' ' + lname.text + '</B>';
   }
   document.all("PersonInfo").innerHTML = HTML;
}

// called when XML data has been fully loaded
function loaded() {
   copyToSel();
}

function copyToSel() {
   // copy values from xmldso to REMOVE list
   var doc = xmldso.XMLDocument.documentElement;
   if (doc) {
      var sel = document.frmPerson.personGroupId;
      var child = doc.firstChild;
      while (child) {
         var id = child.selectSingleNode("./personGroupId");
         var name = child.selectSingleNode("./Name");
         var type = child.selectSingleNode("./personType");
         var opt = document.createElement("OPTION");
         opt.value = id.text;
         opt.text = name.text + " (" + type.text + ")";
         sel.options.add(opt);
         child = child.nextSibling;
      }
   }
}

function update() {
   var submitOk = false;
   
   // call 'lw_deletePersonGroup' only if items from personGroupId are selected
   var sel = document.frmPerson.personGroupId;
   for (var i=0; i<sel.options.length; i++) {
      if (sel.options[i].selected) {
         var elem = document.createElement("INPUT");
         elem.name = 'procName';
         elem.value = 'lw_deletePersonGroup';
         elem.type = 'hidden';
         document.frmPerson.appendChild(elem);
         submitOk = true;
         break;
      }
   }
   
   // call 'lw_addPersonGroup' if items exist in groupId
   sel = document.frmPerson.groupId;
   if (sel.options.length>0) {
      elem = document.createElement("INPUT");
      elem.name = 'procName';
      elem.value = 'lw_addPersonGroup';
      elem.type = 'hidden';
      document.frmPerson.appendChild(elem);
      submitOk = true;
      // form will only send values if selected from drop-down
      for (i=0; i<sel.options.length; i++) {
         sel.options[i].selected = true;
      }
   }
   
   // prepare for data submission
   if (submitOk) clearDirty();
   
   // allow submission only if there's something to do
   return submitOk;      
}

function updateView(actn,id) {
   // just reload the document
   window.location.reload();
}