0001-Feature-601-Adds-custom-variables-section-to-the-wiz.patch

Hector Sanjuan, 04/29/2011 04:51 PM

Download (5.27 KB)

View differences:

src/sunstone/public/js/plugins/templates-tab.js
448 448
			  </div>\
449 449
\
450 450
\
451
              <!--custom variables -->\
452
			  <div class="vm_section" id="custom_var">\
453
			  	<div class="show_hide" id="add_context_cb">\
454
			  	  <h3>Add custom variables <a id="add_custom_var" class="icon_left" href="#"><span class="ui-icon ui-icon-plus" /></a></h3>\
455
			    </div>\
456
			  <fieldset><legend>Custom variables</legend>\
457
              <div class="vm_param kvm_opt xen_opt vmware_opt">\
458
                    <label for="custom_var_name">Name:</label>\
459
                    <input type="text" id="custom_var_name" name="custom_var_name" />\
460
                    <div class="tip">Name for the custom variable</div>\
461
              </div>\
462
              <div class="vm_param kvm_opt xen_opt">\
463
                    <label for="custom_var_value">Value:</label>\
464
                    <input type="text" id="custom_var_value" name="custom_var_value" />\
465
                    <div class="tip">Value of the custom variable</div>\
466
              </div>\
467
              <div class="">\
468
                    <button class="add_remove_button add_button" id="add_custom_var_button" value="add_custom_var">Add</button>\
469
                    <button class="add_remove_button" id="remove_custom_var_button" value="remove_custom_var">Remove selected</button>\
470
                    <div class="clear"></div>\
471
                    <label for="custom_var_box">Current variables:</label>\
472
                    <select id="custom_var_box" name="custom_var_box" style="width:150px;height:100px;" multiple>\
473
                    </select>\
474
              </div>\
475
              </fieldset>\
476
              </div>\
451 477
			  <!-- submit -->\
452 478
			 <fieldset>\
453 479
			  <div class="form_buttons">\
......
1588 1614
		});
1589 1615
	};
1590 1616
    
1617
    //set up the custom variables section
1618
    var custom_variables_setup = function(){
1619
        $('fieldset',section_custom_var).hide();
1620

  
1621
        $('#add_custom_var',section_custom_var).click(function(){
1622
                $('fieldset',section_custom_var).toggle();
1623
                return false;
1624
        });
1625

  
1626
        $('#add_custom_var_button', section_custom_var).click(
1627
        function(){
1628
            var name = $('#custom_var_name',section_custom_var).val();
1629
            var value = $('#custom_var_value',section_custom_var).val();
1630
            if (!name.length || !value.length) {
1631
                notifyError("Custom variable name and value must be\
1632
                filled in");
1633
                return false;
1634
            }
1635
            option= '<option value=\''+value+'\' name=\''+name+'\'>'+
1636
            name+'='+value+
1637
            '</option>';
1638
            $('select#custom_var_box',section_custom_var).append(option);
1639
            return false; 
1640
        });
1641

  
1642
        $('#remove_custom_var_button', section_custom_var).click(
1643
            function(){
1644
                box_remove_element(section_custom_var,'#custom_var_box');
1645
                return false; 
1646
        });
1647
    }
1648

  
1591 1649
    //***CREATE VM DIALOG MAIN BODY***
1592 1650
    
1593 1651
    $('div#dialogs').append('<div title="Create VM Template" id="create_template_dialog"></div>');
......
1625 1683
	var section_context = $('#context');
1626 1684
	var section_placement = $('#placement');
1627 1685
	var section_raw = $('#raw');
1686
    var section_custom_var = $('#custom_var');
1628 1687

  
1629 1688
	//Different selector for items of kvm and xen (mandatory and optional)
1630 1689
	var items = '.vm_param input,.vm_param select';
......
1667 1726
	context_setup();
1668 1727
	placement_setup();
1669 1728
	raw_setup();
1729
    custom_variables_setup();
1670 1730

  
1671 1731
    //Process form
1672 1732
	$('button#create_template_form_easy').click(function(){
1673 1733
		//validate form
1674 1734

  
1675 1735
		var vm_json = {};
1736
        var name,value,boot_method;
1676 1737

  
1677 1738
		//process capacity options
1678 1739
		var scope = section_capacity;
......
1722 1783

  
1723 1784
        //context
1724 1785
        scope = section_context;
1725
        var context = $('#CONTEXT',scope).val();
1726 1786
        vm_json["CONTEXT"] = {};
1727 1787
        $('#context_box option',scope).each(function(){
1728 1788
            name = $(this).attr("name");
......
1739 1799
		vm_json["RAW"] = {};
1740 1800
		addSectionJSON(vm_json["RAW"],scope);
1741 1801

  
1802
        //custom vars
1803
        scope = section_custom_var;
1804
        $('#custom_var_box option',scope).each(function(){
1805
            name = $(this).attr("name");
1806
            value = $(this).val();
1807
            vm_json[name]=value;
1808
        });
1809

  
1742 1810
        // remove empty elements
1743 1811
        vm_json = removeEmptyObjects(vm_json);
1744 1812

  
1745
-