(file) Return to provider.js CVS log (file) (dir) Up to [Pegasus] / pegasus / www / js

  1 lawrence.luo 1.1.2.1 
  2                      //base url which is identical for all requests
  3                      baseURL = "http://"+window.location.hostname+":"+window.location.port+"/cimrs/";
  4                      host = "http://"+window.location.hostname+":"+window.location.port+"/";
  5                      configURL = "root%2FPG_InterOp/enum?class=PG_ProviderModule";
  6                      currentElement = null;
  7                      
  8                      function insertProviderRow(name, location, vendor, version, interfacetype, state, ref) {
  9                          var t_rows = document.getElementById('providerTable').rows;
 10                      	
 11                      
 12                          var x=1;
 13                      
 14                          for (x=1; x < t_rows.length; x++) {
 15                              var celValue = t_rows[x].cells[0].textContent;
 16                              if (name < celValue) {
 17                                  break;
 18                              }
 19                          }
 20                      
 21                      	
 22 lawrence.luo 1.1.2.1     var t_row = document.getElementById('providerTable').insertRow(x);
 23                          t_row.id = "row_" + ref;
 24                          var t_name =t_row.insertCell(0);
 25                          var t_location = t_row.insertCell(1);
 26                          var t_vendor =t_row.insertCell(2);
 27                          var t_version =t_row.insertCell(3);
 28                          var t_interfacetype =t_row.insertCell(4);
 29                          var t_state = t_row.insertCell(5);
 30                      	
 31                      	
 32                      	
 33                          refArray[name] = ref;
 34                      
 35                          t_name.innerHTML=name;
 36                          t_location.innerHTML=location;
 37                          t_vendor.innerHTML=vendor;
 38                          t_version.innerHTML = version;
 39                          t_interfacetype.innerHTML = interfacetype; 
 40                          t_state.innerHTML = state;
 41                      }
 42                      
 43 lawrence.luo 1.1.2.1 
 44                      /**
 45                       * Writes received content on page.
 46                       */
 47                      function writeContent(data) {
 48                          //define a global variable to store property names and corresponding $ref values 
 49                          refArray = new Array();
 50                      	
 51                          var responseArray = JSON.parse(data);
 52                          var providerList=responseArray.instances;
 53                          var i=0;
 54                          for (i=0; i < providerList.length; i++) {
 55                              insertProviderRow(providerList[i].properties.Name,
 56                                                providerList[i].properties.Location,
 57                                                providerList[i].properties.Vendor,
 58                                                providerList[i].properties.Version,
 59                                                providerList[i].properties.InterfaceType,
 60                                                providerList[i].properties.OperationalStatus);
 61                          }
 62                          //change background color for every second row to improve readability
 63                          var t_rows = document.getElementById('providerTable').rows;
 64 lawrence.luo 1.1.2.1     var x;
 65                          for (x=0; x < t_rows.length; x+=2) {
 66                              document.getElementById('providerTable').rows[x].style.background = "#EEEEEE";
 67                              document.getElementById('providerTable').rows[x+1].style.background = "#E0E0E0";		
 68                          }
 69                      	
 70                      	
 71                      }
 72                      
 73                      /**function to delete all rows of a table except the head row
 74                       * afterwards a new request is send to get the lastet data and the table can be rebuilt
 75                       */
 76                      function reloadTable(table)
 77                      {
 78                          var rows = table.rows;
 79                          var rowCount = rows.length;
 80                          for (var i = rowCount-1; i > 0; i--)
 81                              {
 82                                  table.deleteRow(i);
 83                              }
 84                         //default case, change it to redraw another table
 85 lawrence.luo 1.1.2.1    genericRequest('root%2FPG_InterOp/enum?class=PG_ProviderModule', writeContent, true);         
 86                          
 87                      }
 88                      
 89                      function genericRequest(urlAdd, funcToCall, synchronous){
 90                          /*
 91                      	 * based on api example from: 
 92                      	 * https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Example.3a_Asynchronous_request
 93                      	 */
 94                              
 95                              
 96                          if (funcToCall == "writeContent")
 97                              funcToCall = writeContent;
 98                          
 99                          try {
100                              var req = new XMLHttpRequest();
101                          } catch(e) {
102                              alert('No support for XMLHTTPRequests');
103                              return;
104                          }
105                          var url = baseURL + urlAdd;
106 lawrence.luo 1.1.2.1     
107                          var async = synchronous;
108                          req.open('GET', url, async);
109                      
110                          // add progress listener (differs from version to version...)
111                          req.onreadystatechange = function () {
112                              // state complete is of interest, only
113                              if (req.readyState == 4) {
114                                  if (req.status == 200) {
115                                      //call of the passed function (as parameter)
116                                      funcToCall(req.responseText);
117                                  //dump(req.responseText);
118                                  } else {
119                                      //if return code is another than 200 process error
120                                      processRequestError(req.responseText);
121                                      
122                                  }
123                              }
124                          };
125                      
126                          // send request
127 lawrence.luo 1.1.2.1     req.send();
128                              
129                      }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2