BDG Scenario 3

ActivityType.js

window.onload = window_onLoad;

function window_onLoad() {
   var xmldoc=xmldso_gs.XMLDocument;
   xmldoc.async=false;
   xmldoc.load('../Scripts/viewData.asp?tableName=gradeScale&fieldList=gradeScaleId,Name&sortBy=Name');
   copyToSel(xmldoc.documentElement,document.frmActivityType.GradeScaleId);
   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=activityType&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.frmActivityType;
   if(validateForm(theForm)){
      if (theForm.ActivityTypeId.value.length == 0) {
         theForm.procName.value = "lw_addActivityType";
         theForm.actionBtn.value = "ADD";
      }
      clearDirty();
      return true;
   }
   else
      return false;
}

function remove() {
   var theForm = document.frmActivityType;
   if (theForm.ActivityTypeId.value.length != 0) {
      if (confirm(L_ConfirmDelete)) {
         theForm.procName.value = "lw_deleteActivityType";
         theForm.actionBtn.value = "DELETE";
         theForm.submit();
      }
   }
}

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

// Copy values from XML nodes into SELECT tag
// (NOTE: This routine may be 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 'gradeScaleId':
                              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;
      }
   }
}

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