header “Launch new instance”

subheader “#{image.id}”

.hidden_content

- hardware_profiles.each do |profile|
  %iv{ :'data-role' => :fieldcontain, :id => "hwp_properties_#{profile.name}", :class => 'property_block'}
    - profile.properties.reject { |prop| prop.fixed? }.each do |prop|
      %abel{ :for => "#{prop.param}_#{profile.name}", :class => 'ui-input-text' }=prop.name
      %san.radio-group-details
        - if prop.kind == :enum
          %slect{ :size => 1, :name => prop.param }
            - for v in prop.values
              %ption= v
              = prop.unit
        - elsif prop.kind == :range
          %nput{ :type => :range, :value => prop.first, :min => prop.first, :max => prop.last, :name => prop.param}
        - else
          %nput{ :name => prop.param, :size => 10, :value => "#{prop.default}" }= prop.unit

%div{ :'data-role' => :content, :'data-theme' => 'c', :class => 'middle-dialog'}

%orm{ :action => instances_url, :method => :post, :class => :new_instance, :enctype => 'multipart/form-data', :'data-ajax' => 'false'}
  %nput{ :name => :image_id, :type => :hidden, :value => instance.image_id }/

  - if driver.class.has_feature?(:instances, :user_name)
    %iv{ 'data-role' => :fieldcontain }
      %abel{ :for => :name} Instance name:
      %nput{ :type => :text, :id => :name, :name => :name, :value => '' }

  - if additional_features_for?(:instances, [:user_name])
    %iv{ 'data-role' => :collapsible, 'data-collapsed' => "true"}
      %3 Additional parameters

      - if driver.class.has_feature?(:instances, :user_data)
        %iv{ 'data-role' => :fieldcontain }
          %abel{ :for => :user_data} Base64 encoded user-data:
          %extarea{ :id => :user_data, :name => :user_data, :value => '' }
          %r/
          %{ :href => "", :onclick => 'encodeb64();', :'data-ajax' => 'false'} Encode data

      - if driver.class.has_feature?(:instances, :first_boot_dev)
        %ieldset{ :'data-role' => 'controlgroup', 'data-iconpos' => 'right'}
          %egend First boot device:
          %nput{ :name => 'first_boot_dev', :id => :first_boot_dev_hd, :value => 'hd', :checked => 'checked', :type => 'radio'}
          %abel{ :for => :first_boot_dev_hd} Hard Disk
          %nput{ :name  => 'first_boot_dev', :id => :first_boot_dev_network, :value => 'network', :type => "radio"}
          %abel{ :for => :first_boot_dev_network} Network

      - if driver.class.has_feature?(:instances, :instance_count)
        %iv{ 'data-role' => :fieldcontain }
          %abel{ :for => :instance_count} # of instances to be launched:
          %nput{ :type => :text, :id => :instance_count, :name => :instance_count, :value => '1' }

      - if driver.class.has_feature?(:instances, :metrics)
        %iv{ 'data-role' => :fieldcontain }
          %abel{ :for => :metrics} Enable metrics for this instance
          %nput{ :type => :checkbox, :id => :metrics, :name => :metrics, :checked => 'false' }

      - if driver.class.has_feature?(:instances, :authentication_key)
        %iv{ 'data-role' => :fieldcontain }
          %abel{ :for => :keyname, :class => 'ui-input-text'} Instance SSH key:
          %slect{:name => 'keyname', :'data-native-menu' => "true" }
            %ption{ :value => ''} None
            - keys.each do |key|
              %ption{ :value => key.id } #{key.id}

      - if driver.class.has_feature?(:instances, :register_to_load_balancer)
        %iv{ 'data-role' => :fieldcontain }
          %abel{ :for => :load_balancer_id, :class => 'ui-input-text'} Register to loadbalancer:
          %slect{:name => 'load_balancer_id', :'data-native-menu' => "true" }
            %ption{ :value => ''} None
            - load_balancers.each do |load_balancer|
              %ption{:value => load_balancer.id} #{load_balancer.id}

      - if driver.class.has_feature?(:instances, :firewalls)
        %iv{ 'data-role' => :fieldcontain }
          %ieldset{ :'data-role' => 'controlgroup'}
            %egend Register to firewall:
            - firewalls.each_index do |i|
              - if firewalls[i].name == 'default'
                %nput{:type => :checkbox, :value => firewalls[i].name, :name => "firewalls#{i}", :checked => :true, :id => "firewalls#{i}"}/
                %abel{:for => "firewalls#{i}"} Default
              - else
                %nput{:type => :checkbox, :value => firewalls[i].name, :name => "firewalls#{i}", :id => "firewalls#{i}"}/
                %abel{:for => "firewalls#{i}"}=firewalls[i].name

      - if driver.class.has_feature?(:instances, :user_files)
        %iv{ 'data-role' => :fieldcontain }
          %3 Make user data file(s) available in launched Instance
          %4 The path specified for each file below is where the data will be made available on the launched Instance.
          - for i in 1..5
            %4 User file #{i}
            %nput{ :type => :text, :id => "path#{i}", :name => "path#{i}", :value => ""} Path #{i}
            %nput{ :type => "file", :name => "content#{i}", :size => 50 }

  - if !hardware_profiles.empty?
    %iv{ 'data-role' => :fieldcontain }
      %3 Instance profile
      %ieldset{ :'data-role' => :fieldcontain}
        - hardware_profiles.each do |profile|
          %nput{ :type => :radio, :name => 'hwp_id', :value => profile.id, :id => profile.name, :'data-theme' => 'b'}/
          %abel{ :for => profile.name, :onclick => "expandHWP('#{profile.name}');"}="#{profile.name} - #{profile.memory} MB"
          %iv{ :'data-role' => :fieldcontain, :id => "property_container_#{profile.name}", :class => 'hwp_properties'}

  - if !realms.empty?
    %iv{ 'data-role' => :fieldcontain }
      %3 Where do you want it?
      %ieldset{ :'data-role' => :fieldcontain}
        %egend
        - realms.each do |realm|
          %iv{ :'data-role' => :fieldcontain}
            %abel{ :for => realm.id }= "#{realm.name}, #{realm.limit}"
            %nput{ :type => :radio, :name => 'realm_id', :value => realm.id, :id => realm.id, :'data-theme' => 'b' }/

  %utton{ :type => :submit} Create instance