BDG Scenario 3

Activity.js

window.onload = window_onLoad;

function window_onLoad() {
   var xmldoc=xmldso_dd.XMLDocument;
   xmldoc.async=false;
   xmldoc.load('../Scripts/viewData.asp?tableName=location&fieldList=LocationId,Name&sortBy=Name');
   copyToSel(xmldoc.documentElement,document.frmActivity.LocationId);
   xmldoc.load('../Scripts/viewData.asp?tableName=gradeScale&fieldList=gradeScaleId,Name&sortBy=Name');
   copyToSel(xmldoc.documentElement,document.frmActivity.GradeScaleId);
   xmldoc.load('../Scripts/viewData.asp?tableName=activityType&fieldList=activityTypeId,Name&sortBy=Name');
   copyToSel(xmldoc.documentElement,document.frmActivity.ActivityTypeId);
   xmldoc.load('../Scripts/viewData.asp?tableName=group&fieldList=groupId,Name&sortBy=Name');
   copyToSel(xmldoc.documentElement,document.frmActivity.GroupId);
   var win = parent.frames("LEFTPANE").window;
   if (win && win.document.readyState == "complete")
      win.selectFirst();
}

function load(id) {
   if (isDirty) location.reload(); // force page reload
   else {
      var xml = '../Scripts/viewData.asp?tableName=activity&whereID=' + id;
      xmldso.XMLDocument.ondataavailable = loaded;
      xmldso.XMLDocument.load(xml);
   }
}

// called when XML data has been fully loaded
function loaded() {
   var col;
   if (col = document.all.tags('BUTTON')) {
      for (var i=0; i < col.length; i++) {
         col[i].disabled = false;
      }
   }
   clearDirty();
}

// called when Submit button is pressed
function update() {
   var theForm = document.frmActivity;
   if (validateForm(theForm)) {
      if (theForm.ActivityId.value.length == 0) {
         theForm.procName.value = "lw_addActivity";
         theForm.actionBtn.value = "ADD";
      }
      clearDirty();
      return true;
   }
   else
      return false;
}

function remove() {
   var theForm = document.frmActivity;
   if (theForm.ActivityId.value.length != 0) {
      if (confirm(L_ConfirmDelete)) {
         theForm.procName.value = "lw_deleteActivity";
         theForm.actionBtn.value = "DELETE";
         theForm.submit();
      }
      theForm.reset();
   }
}

function refresh() {
   var col;
   if (col = document.all.tags('BUTTON')) {
      for (var i=0; i < col.length; i++) {
         if (col[i] != frmActivity.cmdSubmit)
            col[i].disabled = true;
      }
   }
   clearDirty();
}

// Copy values from XML nodes into SELECT tag
// (NOTE: This routine is used by multiple recordsets.)
function copyToSel(xmldoc,sel) {
   var record,node,id,name,opt;
   if (xmldoc) {
      record = xmldoc.firstChild;
      while (record != null) {
         node = record.firstChild;
         while (node != null) {
            // copy values from node into variables
            switch (node.nodeName) {
               case 'LocationId':
               case 'gradeScaleId':
               case 'groupId':
               case 'activityTypeId':
                              id = node.text; break;
               case 'Name':   name = node.text; break;
            }
            node = node.nextSibling;
         }
         opt = document.createElement("OPTION");
         opt.value = id;
         opt.text = name;
         sel.options.add(opt);
         record = record.nextSibling;
      }
   }
}

function viewActivityTypes() {
   top.location.href = 'gate.htm?fileName=activityType';
}

// called from IFRAME script returned by DB action
function updateView(actn,id) {
   switch (actn) {
   case 'ADD': 
      // set new ID in form
      document.frmActivity.elements("ID").value = id;
      document.frmActivity.ActivityId.value = id;
      // return form to "CHANGE" mode
      document.frmActivity.actionBtn.value = "CHANGE";
      document.frmActivity.procName.value = "lw_changeActivity";
      parent.frames("LEFTPANE").reloadList(id);
      loaded();
      break;
   case 'DELETE': 
      document.frmActivity.reset();
      parent.frames("LEFTPANE").reloadList(null);
      break;
   case 'CHANGE': 
      parent.frames("LEFTPANE").reloadList(id);
      break;
   }
}