mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			198 lines
		
	
	
		
			7.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			198 lines
		
	
	
		
			7.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
|  /**
 | |
|  *  Copyright (C) 2010 Cloud.com, Inc.  All rights reserved.
 | |
|  * 
 | |
|  * This software is licensed under the GNU General Public License v3 or later.
 | |
|  * 
 | |
|  * It is free software: you can redistribute it and/or modify
 | |
|  * it under the terms of the GNU General Public License as published by
 | |
|  * the Free Software Foundation, either version 3 of the License, or any later version.
 | |
|  * This program is distributed in the hope that it will be useful,
 | |
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | |
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | |
|  * GNU General Public License for more details.
 | |
|  * 
 | |
|  * You should have received a copy of the GNU General Public License
 | |
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |
|  * 
 | |
|  */
 | |
| 
 | |
| function networkOfferingGetSearchParams() {
 | |
|     var moreCriteria = [];	
 | |
|    
 | |
| 	var searchInput = $("#basic_search").find("#search_input").val();	 
 | |
|     if (searchInput != null && searchInput.length > 0) {	           
 | |
|         moreCriteria.push("&keyword="+todb(searchInput));	       
 | |
|     }     
 | |
| 
 | |
| 	var $advancedSearchPopup = getAdvancedSearchPopupInSearchContainer();
 | |
| 	if ($advancedSearchPopup.length > 0 && $advancedSearchPopup.css("display") != "none" ) {	
 | |
|         var availability = $advancedSearchPopup.find("#adv_search_availability").val();				
 | |
| 	    if (availability!=null && availability.length > 0) 
 | |
| 		    moreCriteria.push("&availability="+todb(availability));	
 | |
| 		
 | |
| 		var traffictype = $advancedSearchPopup.find("#adv_search_traffictype").val();				
 | |
| 	    if (traffictype!=null && traffictype.length > 0) 
 | |
| 		    moreCriteria.push("&traffictype="+todb(traffictype));	        
 | |
|        
 | |
| 	} 	
 | |
| 		
 | |
| 	return moreCriteria.join("");         
 | |
| }
 | |
| 
 | |
| function afterLoadNetworkOfferingJSP() {   
 | |
|     $readonlyFields  = $("#tab_content_details").find("#name, #displaytext, #availability");
 | |
|     $editFields = $("#tab_content_details").find("#name_edit, #displaytext_edit, #availability_edit");     
 | |
| }
 | |
| 
 | |
| function doEditNetworkOffering($actionLink, $detailsTab, $midmenuItem1) {       
 | |
|     $readonlyFields.hide();
 | |
|     $editFields.show();  
 | |
|     $detailsTab.find("#cancel_button, #save_button").show();
 | |
|     
 | |
|     $detailsTab.find("#cancel_button").unbind("click").bind("click", function(event){    
 | |
|         cancelEditMode($detailsTab);     
 | |
|         return false;
 | |
|     });
 | |
|     $detailsTab.find("#save_button").unbind("click").bind("click", function(event){        
 | |
|         doEditNetworkOffering2($actionLink, $detailsTab, $midmenuItem1, $readonlyFields, $editFields);   
 | |
|         return false;
 | |
|     });   
 | |
| }
 | |
| 
 | |
| function doEditNetworkOffering2($actionLink, $detailsTab, $midmenuItem1, $readonlyFields, $editFields) {     
 | |
|     var jsonObj = $midmenuItem1.data("jsonObj");
 | |
|     var id = jsonObj.id;
 | |
|     
 | |
|     // validate values   
 | |
|     var isValid = true;					
 | |
|     isValid &= validateString("Name", $detailsTab.find("#name_edit"), $detailsTab.find("#name_edit_errormsg"), true);		
 | |
|     isValid &= validateString("Display Text", $detailsTab.find("#displaytext_edit"), $detailsTab.find("#displaytext_edit_errormsg"), true);				
 | |
|     if (!isValid) 
 | |
|         return;	
 | |
|      
 | |
|     var array1 = [];    
 | |
|     var name = $detailsTab.find("#name_edit").val();
 | |
|     array1.push("&name="+todb(name));
 | |
|     
 | |
|     var displaytext = $detailsTab.find("#displaytext_edit").val();
 | |
|     array1.push("&displayText="+todb(displaytext));
 | |
| 	
 | |
| 	var availability = $detailsTab.find("#availability_edit").val();
 | |
|     array1.push("&availability="+todb(availability));	
 | |
| 	
 | |
| 	$.ajax({
 | |
| 	    data: createURL("command=updateNetworkOffering&id="+id+array1.join("")),
 | |
| 		dataType: "json",
 | |
| 		success: function(json) {			    
 | |
| 		    var jsonObj = json.updatenetworkofferingresponse.networkoffering;   		    
 | |
| 		    networkOfferingToMidmenu(jsonObj, $midmenuItem1);
 | |
| 		    networkOfferingToRightPanel($midmenuItem1);	
 | |
| 		    
 | |
| 		    $editFields.hide();      
 | |
|             $readonlyFields.show();       
 | |
|             $("#save_button, #cancel_button").hide();     	  
 | |
| 		}
 | |
| 	});
 | |
| }
 | |
| 
 | |
| function networkOfferingToMidmenu(jsonObj, $midmenuItem1) {  
 | |
|     $midmenuItem1.attr("id", getMidmenuId(jsonObj));  
 | |
|     $midmenuItem1.data("jsonObj", jsonObj); 
 | |
|      
 | |
|     /*    
 | |
|     var $iconContainer = $midmenuItem1.find("#icon_container").show();   
 | |
|     $iconContainer.find("#icon").attr("src", "images/midmenuicon_system_networkOffering.png");	
 | |
|     */
 | |
|     
 | |
|     $midmenuItem1.find("#first_row").text(fromdb(jsonObj.name).substring(0,25)); 
 | |
|     $midmenuItem1.find("#second_row").text(fromdb(jsonObj.type).substring(0,25));  
 | |
| }
 | |
| 
 | |
| function networkOfferingToRightPanel($midmenuItem1) {
 | |
|     copyActionInfoFromMidMenuToRightPanel($midmenuItem1);
 | |
|     $("#right_panel_content").data("$midmenuItem1", $midmenuItem1);
 | |
|     networkOfferingJsonToDetailsTab();   
 | |
| }
 | |
| 
 | |
| function networkOfferingJsonToDetailsTab() { 
 | |
|     var $midmenuItem1 = $("#right_panel_content").data("$midmenuItem1");
 | |
|     if($midmenuItem1 == null)
 | |
|         return;
 | |
|     
 | |
|     var jsonObj = $midmenuItem1.data("jsonObj");
 | |
|     if(jsonObj == null)
 | |
|         return;
 | |
|      
 | |
|     var $thisTab = $("#right_panel_content #tab_content_details");  
 | |
|     $thisTab.find("#tab_container").hide(); 
 | |
|     $thisTab.find("#tab_spinning_wheel").show();   
 | |
|     
 | |
|     var id = jsonObj.id;
 | |
|     
 | |
|     var jsonObj;   
 | |
|     $.ajax({
 | |
|         data: createURL("command=listNetworkOfferings&id="+id),
 | |
|         dataType: "json",
 | |
|         async: false,
 | |
|         success: function(json) {  
 | |
|             var items = json.listnetworkofferingsresponse.networkoffering;
 | |
|             if(items != null && items.length > 0) {
 | |
|                 jsonObj = items[0];
 | |
|                 $midmenuItem1.data("jsonObj", jsonObj);  
 | |
|             }
 | |
|         }
 | |
|     });       
 | |
|     
 | |
|     $thisTab.find("#id").text(fromdb(jsonObj.id));
 | |
|         
 | |
|     $thisTab.find("#grid_header_title").text(fromdb(jsonObj.name));
 | |
|     $thisTab.find("#name").text(fromdb(jsonObj.name));
 | |
|     $thisTab.find("#name_edit").val(fromdb(jsonObj.name));
 | |
|     
 | |
|     $thisTab.find("#displaytext").text(fromdb(jsonObj.displaytext));
 | |
|     $thisTab.find("#displaytext_edit").val(fromdb(jsonObj.displaytext));
 | |
|      
 | |
|     $thisTab.find("#availability").text(fromdb(jsonObj.availability));     
 | |
|     $thisTab.find("#availability_edit").val(fromdb(jsonObj.availability)); 
 | |
|      
 | |
|     setBooleanReadField(jsonObj.isdefault, $thisTab.find("#isdefault"));
 | |
|     setBooleanReadField(jsonObj.specifyvlan, $thisTab.find("#specifyvlan"));
 | |
|       
 | |
|     $thisTab.find("#rate").text(fromdb(jsonObj.networkrate) + " Mb/s");
 | |
|     $thisTab.find("#traffictype").text(fromdb(jsonObj.traffictype));
 | |
|    
 | |
|     //actions ***
 | |
|     var $actionMenu = $("#right_panel_content #tab_content_details #action_link #action_menu");
 | |
|     $actionMenu.find("#action_list").empty();    
 | |
|     buildActionLinkForTab("Edit Network Offering", networkOfferingActionMap, $actionMenu, $midmenuItem1, $thisTab);	  
 | |
|     
 | |
|     $thisTab.find("#tab_spinning_wheel").hide();    
 | |
|     $thisTab.find("#tab_container").show();         
 | |
| }
 | |
| 
 | |
| function networkOfferingClearRightPanel() {
 | |
|     networkOfferingClearDetailsTab();
 | |
| }
 | |
| 
 | |
| function networkOfferingClearDetailsTab() {
 | |
|     var $thisTab = $("#right_panel_content").find("#tab_content_details");     
 | |
|     $thisTab.find("#id").text("");    
 | |
|     $thisTab.find("#grid_header_title").text("");
 | |
|     $thisTab.find("#name").text("");
 | |
|     $thisTab.find("#name_edit").val("");    
 | |
|     $thisTab.find("#displaytext").text("");
 | |
|     $thisTab.find("#displaytext_edit").val("");    
 | |
|     $thisTab.find("#disksize").text("");
 | |
|     $thisTab.find("#tags").text("");   
 | |
|     $thisTab.find("#domain").text("");   
 | |
|     
 | |
|     var $actionMenu = $("#right_panel_content #tab_content_details #action_link #action_menu");
 | |
|     $actionMenu.find("#action_list").empty(); 
 | |
|     $actionMenu.find("#action_list").append($("#no_available_actions").clone().show());
 | |
| }
 | |
| 
 | |
| var networkOfferingActionMap = {   
 | |
|     "Edit Network Offering": {
 | |
|         dialogBeforeActionFn: doEditNetworkOffering
 | |
|     }
 | |
| }  
 |