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

  1 lawrence.luo 1.2 /*!LICENSE
  2                   *
  3                   * Licensed to The Open Group (TOG) under one or more contributor license
  4                   * agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5                   * this work for additional information regarding copyright ownership.
  6                   * Each contributor licenses this file to you under the OpenPegasus Open
  7                   * Source License; you may not use this file except in compliance with the
  8                   * License.
  9                   *
 10                   * Permission is hereby granted, free of charge, to any person obtaining a
 11                   * copy of this software and associated documentation files (the "Software"),
 12                   * to deal in the Software without restriction, including without limitation
 13                   * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14                   * and/or sell copies of the Software, and to permit persons to whom the
 15                   * Software is furnished to do so, subject to the following conditions:
 16                   *
 17                   * The above copyright notice and this permission notice shall be included
 18                   * in all copies or substantial portions of the Software.
 19                   *
 20                   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21                   * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 lawrence.luo 1.2  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23                   * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24                   * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25                   * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26                   * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27                   *
 28                   */
 29                  
 30                  getConfigURL = "root%2FPG_Internal/enum?class=PG_ConfigSetting";
 31                  updateConfigURL="root%2FPG_Internal/PG_ConfigSetting/";
 32                  currentElement = null;
 33                  
 34                  function insertConfigRow(name, current, defaultvalue, planned, dynamic, ref) {
 35                      var t_rows = document.getElementById('configTable').rows;
 36                  	
 37                  
 38                      var x=1;
 39                  
 40                      for (x=1; x < t_rows.length; x++) {
 41                          var celValue = t_rows[x].cells[0].textContent;
 42                          if (name < celValue) {
 43 lawrence.luo 1.2             break;
 44                          }
 45                      }
 46                  
 47                  	
 48                      var t_row = document.getElementById('configTable').insertRow(x);
 49                      t_row.id = "row_" + ref;
 50                      var t_name =t_row.insertCell(0);
 51                      var t_current = t_row.insertCell(1);
 52                      var t_dynamic =t_row.insertCell(2);
 53                      var t_planned =t_row.insertCell(3);
 54                      var t_defaultvalue =t_row.insertCell(4);
 55                      var t_actions = t_row.insertCell(5);
 56                  	
 57                  	
 58                  	
 59                      t_name.innerHTML=name;
 60                      t_current.innerHTML=current;
 61                      t_defaultvalue.innerHTML=defaultvalue;
 62                      t_planned.innerHTML = planned;
 63                      //store ref value
 64 lawrence.luo 1.2     refArray[name] = ref;
 65                      //set dynamic property icons
 66                      if (dynamic == true)
 67                      {
 68                          t_dynamic.innerHTML = "<img src='images/green_circle.gif' alt='true' />"; 
 69                      }
 70                      else
 71                      {
 72                          t_dynamic.innerHTML = "<img src='images/red_circle.gif' alt='false' />";
 73                      }
 74                      //set the property value name as ID, starting with "edit_"
 75                      t_actions.innerHTML = "<table style='text-align: left; width: 100%;' border='0' cellpadding='2' cellspacing='2'>" +
 76                      "<tbody><tr><td style='vertical-align: top;'><a href='#' id='reset_"+name+"' onclick='showResetOverlay(this)'><img style='width: 12px; height: 12px;' alt='reset' src='images/reset.png'"+
 77                      "title='reset default value'></a></td>"+
 78                      "<td style='vertical-align: top;'><a href='#' id='edit_"+name+"' onclick='showEditOverlay(this)'><img style='width: 12px; "+
 79                      "height: 12px;' alt='edit' src='images/edit.png' title='edit config setting'></a>"+
 80                      "</td></tr></tbody></table>";
 81                  	
 82                  }
 83                  
 84                  
 85 lawrence.luo 1.2 /**
 86                   * Writes received content on page.
 87                   */
 88                  function writeContent(data) {
 89                      //define a global variable to store property names and corresponding $ref values 
 90                      refArray = new Array();
 91                  	
 92                      var processList = JSON.parse(data);
 93                      var instanceList=processList.instances;
 94                      var i=0;
 95                      for (i=0; i < instanceList.length; i++) {
 96                          insertConfigRow(decodeURIComponent(instanceList[i].properties.PropertyName),
 97                          		        decodeURIComponent(instanceList[i].properties.CurrentValue),
 98                          		        decodeURIComponent(instanceList[i].properties.DefaultValue),
 99                          		        decodeURIComponent(instanceList[i].properties.PlannedValue),
100                          		        instanceList[i].properties.DynamicProperty,
101                          		        decodeURIComponent(instanceList[i].properties.PropertyName));
102                      }
103                      //change background color for every second row to improve readability
104                      var t_rows = document.getElementById('configTable').rows;
105                      var x;
106 lawrence.luo 1.2     for (x=1; x < t_rows.length; x+=2) {
107                          document.getElementById('configTable').rows[x].style.background = "#CACDCE";		
108                      }
109                  	
110                  	
111                  }
112                  
113                  /**function to delete all rows of a table except the head row
114                   * afterwards a new request is send to get the lastet data and the table can be rebuilt
115                   */
116                  function reloadTable(table)
117                  {
118                      var rows = table.rows;
119                      var rowCount = rows.length;
120                      for (var i = rowCount-1; i > 0; i--)
121                          {
122                              table.deleteRow(i);
123                          }
124                      enableApplyButton();
125                      //default case, change it to redraw another table
126                      genericRequestGet('root%2FPG_Internal/enum?class=PG_ConfigSetting', writeContent, true);         
127 lawrence.luo 1.2     
128                  }
129                  
130                  /**
131                   *this functions replaces the content of the central div, to show some other page here.
132                   *this is just an approach to to use static headers and footers as the cim server does not support server side scripting.
133                   *if there is a better solution for that issue, feel free to change that.
134                   *
135                   *deprecated
136                   */
137                  function replContDiv(urlAdd)
138                  {
139                      try {
140                          var req = new XMLHttpRequest();
141                      } catch(e) {
142                          alert('No support for XMLHTTPRequests');
143                          return;
144                      }
145                      
146                      var url = host + urlAdd;
147                  	var async = false;
148 lawrence.luo 1.2     req.open('GET', url, async);
149                  
150                      // add progress listener (differs from version to version...)
151                      req.onreadystatechange = function () {
152                          // state complete is of interest, only
153                          if (req.readyState == 4) {
154                              if (req.status == 200) {
155                                  document.getElementById("content").innerHTML = req.responseText;
156                  				if (urlAdd == "config.html")
157                  				{
158                  					genericRequestGet(geyConfigURL, writeContent, false);
159                  				}
160                              //dump(req.responseText);
161                              } else {
162                                  dump("Error loading page\n");
163                              }
164                          }
165                      };
166                  
167                      // send request
168                      req.send();
169 lawrence.luo 1.2     
170                      
171                      
172                  }
173                  
174                  
175                  
176                  
177                  /**
178                  *Function to show an overlay for editing config settings
179                  */
180                  function showEditOverlay(element) {
181                      //uncheck both checkboxes
182                      document.change_setting.checkbox_planned.checked = false;
183                      document.change_setting.checkbox_current.checked = false;
184                      currentElement = element;
185                      var propertyName = element.id;   
186                      propertyName = propertyName.replace("edit_","");  
187                      var title = document.getElementById("settings_title");
188                      title.innerHTML="Setting being changed: <b>" + propertyName + "</b>";	
189                      // get the type of the property
190 lawrence.luo 1.2     var typeOfProperty = document.getElementById("row_"+propertyName).cells[4].innerHTML;
191                      var dynamic = document.getElementById("row_"+propertyName).cells[2].innerHTML;
192                      //if cell contains "red" (= graphics red_circle) grey out the checkbox
193                      if (dynamic.indexOf("red") != -1)
194                      {
195                          document.change_setting.checkbox_current.disabled = true;
196                      }
197                      else
198                      {
199                          document.change_setting.checkbox_current.disabled = false;
200                      }
201                  	// show dropdown menu instead of text field if value is boolean
202                  	if (typeOfProperty == "false" || typeOfProperty == "true") 
203                  	{
204                  		document.getElementById("input_area").innerHTML = "<select name='input_value' ><option value='true'>true</option><option value='false'>false</option></select>";
205                  	} 
206                  	else 
207                  	{
208                          //get the current value from the table
209                          var currentValue = document.getElementById("row_"+propertyName).cells[1].textContent;
210                  		document.getElementById("input_area").innerHTML = "<input id='input_field' name='input_value' type='text' style='width:90%' onkeypress='enableApplyButton()' value='"+currentValue+"'>";   
211 lawrence.luo 1.2     }
212                      el = document.getElementById("overlay");
213                      el.style.visibility = "visible";
214                      
215                      //select content
216                      var inputField = document.getElementById("input_field");
217                      if (inputField != null)
218                      {
219                          inputField.select();            
220                      } 
221                  }
222                  
223                  /**
224                  *Function to show an overlay for resetting config settings
225                  */
226                  function showResetOverlay(element) {    
227                      //uncheck both checkboxes
228                      document.reset_setting.checkbox_planned_reset.checked = false;
229                      document.reset_setting.checkbox_current_reset.checked = false;
230                      currentElement = element;
231                      var propertyName = element.id;   
232 lawrence.luo 1.2     propertyName = propertyName.replace("reset_","");  
233                      var title = document.getElementById("reset_title");
234                      title.innerHTML="Setting being resetted: <b>" + propertyName + "</b>";	
235                      var dynamic = document.getElementById("row_"+propertyName).cells[2].innerHTML;
236                      
237                      //if cell contains "red" (= graphics red_circle) grey out the checkbox
238                      if (dynamic.indexOf("red") != -1)
239                      {
240                          document.reset_setting.checkbox_current_reset.disabled = true;
241                      }
242                      else
243                      {
244                          document.reset_setting.checkbox_current_reset.disabled = false;
245                      }
246                      el = document.getElementById("overlay_reset");
247                      el.style.visibility = "visible";
248                  }
249                  
250                  /**
251                  *Function to hide the overlay window
252                  */
253 lawrence.luo 1.2 function hide_overlay(element, overlayID) {
254                      el = document.getElementById(overlayID);
255                      el.style.visibility = "hidden";
256                      currentElement = null;
257                      
258                      //remove possible text content of any status bars
259                      document.getElementById("settings_errorbar").textContent = "";
260                      document.getElementById("reset_errorbar").textContent = "";
261                   
262                  }
263                  
264                  /**
265                   * function to actually set the value of the property entered in the form
266                   */
267                  function processFormData(valueCurrent, valuePlanned, valueToSet){
268                      //disable apply button
269                      document.change_setting.apply.disabled = true;
270                      //check if both checkboxes are unchecked and tell the user to check at least one
271                      if (!valueCurrent.checked && !valuePlanned.checked)
272                      {
273                           var temp = document.getElementById("settings_errorbar");
274 lawrence.luo 1.2          temp.innerHTML = "<FONT COLOR='#DE320B'> check at least one checkbox </FONT>";
275                           return;
276                       }
277                      
278                      var propertyValue = valueToSet.value;
279                      
280                      //Create requestURL
281                      var ref = refArray[currentElement.id.replace("edit_","")];
282                      var methodURL = ref + "/UpdatePropertyValue";
283                      var requestURL=updateConfigURL+methodURL;
284                      
285                      //Create the request content for Post 
286                      var requestContent=
287                          {
288                      		"kind": " methodrequest",
289                      		"self": requestURL,
290                      		"method": "UpdatePropertyValue",
291                      		"parameters":
292                      		    {
293                      	         "PropertyValue":propertyValue,
294                      	         "resetvalue":false,
295 lawrence.luo 1.2     	         "setcurrentvalue":valueCurrent.checked,
296                      	         "setPlannedValue":valuePlanned.checked
297                      		    }
298                      	}
299                      	
300                      genericRequestPost(requestURL,requestContent, processRequestResult, true);
301                      //hide_overlay(null);  
302                      
303                  }
304                  
305                  /**
306                   * function to reset current or planned value to default values
307                   */
308                  function processReset(valueCurrent, valuePlanned){
309                      var ref = refArray[currentElement.id.replace("reset_","")];
310                      var methodURL = ref + "/UpdatePropertyValue";
311                      var requestURL=updateConfigURL+methodURL;
312                      
313                      var requestContent=
314                  	{
315                  		"kind": " methodrequest",
316 lawrence.luo 1.2 		"self": requestURL,
317                  		"method": "UpdatePropertyValue",
318                  		"parameters": 
319                  		{
320                  	        "resetvalue":true,
321                  	        "setcurrentvalue":valueCurrent.checked,
322                  	        "setPlannedValue":valuePlanned.checked
323                  		}
324                  	}
325                      
326                      genericRequestPost(requestURL,requestContent, processRequestResult, true);
327                      //hide_overlay(null);
328                  
329                      
330                      
331                  }
332                  
333                  function processRequestResult(response){
334                      //show info on correct error bar depending on currentElement
335                  	
336                      var barToShow;
337 lawrence.luo 1.2     if (currentElement.id.indexOf("edit") != -1)
338                          {
339                              barToShow = "settings_errorbar";
340                          }
341                      else if ((currentElement.id.indexOf("reset") != -1))
342                          {
343                              barToShow = "reset_errorbar";
344                          }
345                      else
346                          {
347                              return;
348                          }
349                      var result = JSON.parse(response);
350                      //for positive responses the property 'ReturnValue' is contained, but double check that here.
351                      if ('returnvalue' in result)
352                          {
353                              if (result.returnvalue == true)
354                                  {
355                                      var temp = document.getElementById(barToShow);
356                                      temp.title = "";
357                                      temp.innerHTML = "<FONT COLOR='#1BE042'>successful</FONT>";
358 lawrence.luo 1.2                     //redraw the table
359                                      reloadTable(document.getElementById('configTable'));                  
360                                                   
361                                  }
362                             
363                          }
364                      
365                  }
366                  
367                  function processRequestError(response){
368                      //show info on correct error bar depending on currentElement
369                      var barToShow;
370                      if (currentElement.id.indexOf("edit") != -1)
371                          {
372                              barToShow = "settings_errorbar";
373                          }
374                      else if ((currentElement.id.indexOf("reset") != -1))
375                          {
376                              barToShow = "reset_errorbar";
377                          }
378                      else
379 lawrence.luo 1.2         {
380                              return;
381                          }
382                      var result = JSON.parse(response);
383                      if ('message' in result)
384                          {
385                              if (result.message != "")
386                                  {
387                                       var temp = document.getElementById(barToShow);
388                                       temp.innerHTML = "<FONT COLOR='#DE320B'> failure (hover here for details) </FONT>";
389                                       temp.title = result.details;
390                                  }
391                             
392                          }
393                      
394                  }
395                  
396                  function enableApplyButton()
397                  {
398                      document.change_setting.apply.disabled = false;
399                  }
400 lawrence.luo 1.2 
401                  

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2