<% @pageName = @myView == "resource" ? "Resource" : "Fence Device" %>
<tr id="<%=@myView%>_title_row" {{bind-attr style="Pcs.<%=@myView%>_page"}}><td id="page_header" colspan=3>
<%= @myView == "resource" ? "RESOURCES" : "FENCE DEVICES" %>
    </td>
  </tr>
  <tr id="<%=@myView%>_header_row" {{bind-attr style="Pcs.<%=@myView%>_page"}}>
    <td id="remove_add" class="borderbottom">
      <div class="x sprites"></div><div class=link">&nbsp;
	<% if @myView == "resource" %>
	  <a href="#" onclick='verify_remove("resource");return false;'>
	<% else %>
	  <a href="#" onclick='verify_remove("stonith", null, "Remove device(s)", "Fence Device Removal");return false;'>
	<% end %>
      Remove</a>&nbsp;&nbsp;&nbsp;&nbsp;</div>
  <div class="plus sprites"></div><div class="link">&nbsp;
    <% if @myView == "resource" %>
      <a href="#" onclick="$('#add_resource').dialog({title: 'Add Resource', modal:true, width: 'auto'});return false;">
    <% else %>
      <a href="#" onclick="$('#add_stonith').dialog({title: 'Add Fence Device', modal:true, width: 'auto'});return false;">
    <% end %>
  Add</a>&nbsp;&nbsp;&nbsp;&nbsp;</div>
    <% if @myView == "resource" %>
      <div class="plus sprites"></div><div class="link">&nbsp;<a href="#" onclick="create_group();return false;">Create Group</a></div>
    <% end %>
    </td>
    <td class="borderbottom">&nbsp;</td>
    <td id="tab_name" width="125">
      <div style="float: left">&nbsp;Edit <%= @pageName%>&nbsp;</div><div class="check sprites"></div>
    </td>
  </tr>
  <tr id="<%=@myView%>_list_row" {{bind-attr style="Pcs.<%=@myView%>_page"}}>
    <td id="<%=@myView%>_list" class="node_list">
      <%= erb :_resource_list %>
    </td>
	<td id="node_info" colspan=2>
	  <div id="<%=@myView%>_info_div" {{bindAttr style="Pcs.resourcesController.cur_resource_info_style"}}>
	  <div id="test">
	    <div id="node_info_header">
	      <div id="<%=@myView%>_info_header_title" class="node_info_header_title" >Edit <%= @pageName %>&nbsp;</div>
	      <div id="node_info_header_title_name">
		{{Pcs.resourcesController.cur_resource.name}}
	      </div>
	      <div>
{{#if Pcs.resourcesController.cur_resource.group}}
 &nbsp;({{Pcs.resourcesController.cur_resource.group}})
{{/if}}
	      </div>
	    </div>

	    <div id="node_sub_info">
	      <table>
		<tr>
		  <td><input disabled style="margin-right: 50px;" type="text" {{bind-attr value="Pcs.resourcesController.cur_resource.name"}} size="35" class="text_field"></td>
		  <td><div style="margin-right: 8px;" class="check sprites"></div></td>
		  <td>
		  {{#if Pcs.resourcesController.cur_resource.failed}}
		    <div id="res_status" class="status-offline">Failed</div>
                  {{else}}
		  {{#if Pcs.resourcesController.cur_resource.active}}
		    <div id="res_status" class="status">Running
		      {{#if Pcs.resourcesController.cur_resource.disabled}}
		        (Disabled)
		      {{/if}}
		    </div>
		  {{else}}
		    <div id="res_status" class="status-offline">
		      Inactive
		      {{#if Pcs.resourcesController.cur_resource.disabled}}
		        (Disabled)
		      {{/if}}
		     </div>
		  {{/if}}
		  {{/if}}
		  </td>
		</tr>
	      </table>
	    </div>

	    <div id="node_options_buttons">
	      <% if @myView == "resource" %>
		<div class="checkdark sprites" style="float: left"></div>
		<div id="resource_start_link" class="link">Enable</div>
		<div class="cancel sprites" style="float: left"></div>
		<div id="resource_stop_link" class="link">Disable</div>
		<div class="restart sprites" style="float: left"></div>
		<div id="resource_cleanup_link" class="link">Cleanup</div>
		<div class="xdark sprites" style="float: left"></div>
		<div id="resource_delete_link" class="link">Remove</div>
	      <% else %>
		<div class="xdark sprites" style="float: left"></div>
		<div id="stonith_delete_link" class="link">Remove</div>
		<div class="restart sprites" style="float: left"></div>
		<div id="stonith_cleanup_link" class="link">Cleanup</div>
	      <% end %>
	      <!--
	      <div class="move sprites" style="float: left"></div>
	      <div id="resource_move_link" class="link">Move</div>
	      <div class="history sprites" style="float: left"></div>
	      <div id="resource_history_link" class="link">History</div>
	      -->
	    </div>

	    <div id="node_details">
	      <table style="margin-bottom:25px;"><tr>
		  <td nowrap><div class="bold">Current Location:</div></td>
		  <td><div id="cur_res_loc" class="reg">
			{{Pcs.resourcesController.cur_resource.node_list}}
		  </div> </td>
		</tr>
	      </table>
	      <% if @myView == "resource" %>
	      <table style="clear:left;float:left">
		<tr><td style="display: block;" onclick="show_hide_constraints(this)" class="datatable_header hover-pointer" id="location_constraints"><span style="" class="downarrow sprites"></span><span style="display: none;" class="rightarrow sprites"></span>Resource Location Preferences ({{#if Pcs.resourcesController.cur_resource.location_constraints}}{{Pcs.resourcesController.cur_resource.location_constraints.length}}{{else}}0{{/if}})</td></tr>
		<tr><td>
		    <div id="locationdep">
		      <table class="datatable">
			<tr><th>Node/Rule</th><th>Score</th><th>Remove</th></tr>
			{{#each Pcs.resourcesController.cur_resource.location_constraints}}
			<tr>
			{{#if rule_string}}
			  <td style="white-space: normal;">{{rule_string}}</td>
			  <td>{{#if score-attribute}}{{score-attribute}}{{else}}{{score}}{{/if}}</td>
			  <td {{bind-attr rule_id="id"}} style="text-align:center">
			    {{#unless temp}}
				<a onclick="remove_constraint_rule($(this).parent().attr('rule_id'));return false;" href="#" class="remove">X</a>
			    {{/unless}}
			  </td>
			{{else}}
			  <td>{{node}}</td>
			  <td>{{score}}</td>
			  <td {{bind-attr constraint_id="id"}} style="text-align:center">
			    {{#unless temp}}
				<a onclick="remove_constraint($(this).parent().attr('constraint_id'));return false;" href="#" class="remove">X</a>
			    {{/unless}}
			  </td>
			{{/if}}
			</tr>
		        {{/each}}
                        {{#unless Pcs.resourcesController.cur_resource.location_constraints}}
			<tr><td style="color: gray;">NONE</td><td></td><td></td></tr>
		        {{/unless}}
			<tr id="new_res_loc">
			  <td><input type="text" name="node_id"></td>
			  <td><input type="text" name="score" size="5"></td>
			  <td><button type="button" onclick="add_constraint('#new_res_loc','loc', false);" name="add">Add</button></td>
			</tr>
		      </table>
		    </div>
		  </td>
		</tr>
	      </table>
	      <table style="clear:left;float:left;">
		<tr><td style="display: block;" onclick="show_hide_constraints(this)" class="datatable_header hover-pointer" id="ordering_constraints"><span style="" class="downarrow sprites"></span><span style="display: none;" class="rightarrow sprites"></span>Resource Ordering Preferences ({{#if Pcs.resourcesController.cur_resource.ordering_constraints.length}}{{Pcs.resourcesController.cur_resource.ordering_constraints.length}}{{else}}0{{/if}})</td></tr>
		<tr><td>
		    <div id="locationdep">
		      <table class="datatable">
			<tr><th>Resource</th><th>Action</th><th>Before/After</th><th>Action</th><th>Score</th><th>Remove</th></tr>
		        {{#each Pcs.resourcesController.cur_resource.ordering_constraints}}	
			  <tr><td>{{other_rsc}}</td>
			    {{#if before}}
			      <td>{{#if first-action}}{{first-action}}s{{else}}starts{{/if}}</td>
			      <td>before {{then}}</td>
			      <td>{{#if then-action}}{{then-action}}s{{else}}starts{{/if}}</td>
			    {{else}}
			      <td>{{#if then-action}}{{then-action}}s{{else}}starts{{/if}}</td>
			      <td>after {{first}}</td>
			      <td>{{#if first-action}}{{first-action}}s{{else}}starts{{/if}}</td>
			    {{/if}}
			    <td>{{score}}</td>
			    <td {{bind-attr constraint_id="id"}} style="text-align:center">
				  <a onclick="remove_constraint($(this).parent().attr('constraint_id'));return false;" href="#" class="remove">X</a>
			    </td>
			  </tr>
 			{{/each}}
			{{#unless Pcs.resourcesController.cur_resource.ordering_constraints}}
			  <tr><td style="color: gray;">NONE</td><td></td><td></td><td></td><td></td><td></td></tr>
			{{/unless}}
			<tr id="new_res_orc">
			  <td><input type="text" name="target_res_id"></td>
			  <td>
			    <select name="target_action">
			      <option value="start">starts</option>
			      <option value="promote">promotes</option>
			      <option value="demote">demotes</option>
			      <option value="stop">stops</option>
			    </select>
			  </td>
			  <td>
			    <select name="order">
			      <option value="after">after</option>
			      <option value="before">before</option>
			    </select>
			    {{Pcs.resourcesController.cur_resource.name}}
			  </td>
			  <td>
			    <select name="res_action">
			      <option value="start">starts</option>
			      <option value="promote">promotes</option>
			      <option value="demote">demotes</option>
			      <option value="stop">stops</option>
			    </select>
			  </td>
			  <td><input type="text" name="score" size="5"></td>
			  <td><button type="button" onclick="add_constraint('#new_res_orc','ord', false);" name="add">Add</button></td>
			</tr>
		      </table>
		    </div>
		  </td>
		</tr>
	      </table>
        <table style="clear:left;float:left;">
          <tr><td style="display: block;" onclick="show_hide_constraints(this)" class="datatable_header hover-pointer" id="ordering_set_constraints"><span style="" class="downarrow sprites"></span><span style="display: none;" class="rightarrow sprites"></span>Resource Ordering Set Preferences ({{#if Pcs.resourcesController.cur_resource.ordering_set_constraints.length}}{{Pcs.resourcesController.cur_resource.ordering_set_constraints.length}}{{else}}0{{/if}})</td></tr>
          <tr><td>
            <div id="locationdep">
              <table class="datatable">
                <tr>
                  <th>Preference Name/Set of Resources</th>
                  <th style="text-align: center;">Remove</th>
                </tr>
                {{#each Pcs.resourcesController.cur_resource.ordering_set_constraints}}
                <tr>
                  <td>{{id}}</td>
                  <td {{bind-attr constraint_id="id"}} style="text-align:center;">
                    <a onclick="remove_constraint($(this).parent().attr('constraint_id')); return false;" href="#" class="remove">X</a>
                  </td>
                </tr>
                {{#each sets}}
                <tr>
                  <td style="padding-left:2em;">Set:{{#each rsc in resources}} {{rsc}}{{/each}}</td>
                  <td></td>
                </tr>
                {{/each}}
                {{/each}}
                {{#unless Pcs.resourcesController.cur_resource.ordering_set_constraints}}
                  <tr><td style="color: gray;">NONE</td><td></td></tr>
                {{/unless}}
                <tr id="new_res_orc_set" title="Enter the resources you want to be in one set into the 'Set' field separated by space.
Use the 'New Set' button to create more sets.
Use the 'Add' button to submit the form.">
                  <td>Set: <input type="text" name="resource_ids[]"></td>
                  <td style="vertical-align: bottom;">
                    <button type="button" onclick="new_constraint_set_row('#new_res_orc_set');" name="new-row">New Set</button>
                    <button type="button" onclick="add_constraint_set('#new_res_orc_set', 'ord', false);" name="add">Add</button>
                  </td>
                </tr>
              </table>
            </div>
          </td></tr>
        </table>
	      <table style="clear:left;float:left">
		<tr><td onclick="show_hide_constraints(this)" class="datatable_header hover-pointer" id="colocation_constraints"><span style="" class="downarrow sprites"></span><span style="display: none;" class="rightarrow sprites"></span>Resource Colocation Preferences ({{#if Pcs.resourcesController.cur_resource.colocation_constraints.length}}{{Pcs.resourcesController.cur_resource.colocation_constraints.length}}{{else}}0{{/if}})</td></tr>
		<tr><td>
		    <div id="locationdep">
		      <table class="datatable">
			<tr><th>Resource</th><th>Together/Apart</th><th>Score</th><th>Remove</th></tr>
			{{#each Pcs.resourcesController.cur_resource.colocation_constraints}}
			  <tr><td>{{other_rsc}}</td>
			    <td>{{together}}</td>
			    <td>{{score}}</td>
			    <td {{bind-attr constraint_id="id"}} style="text-align:center">
				  <a onclick="remove_constraint($(this).parent().attr('constraint_id'));return false;" href="#" class="remove">X</a>
			    </td>
			  </tr>
                        {{/each}}
 			{{#unless Pcs.resourcesController.cur_resource.colocation_constraints}}
			  <tr><td style="color: gray;">NONE</td><td></td><td></td><td></td></tr>
 			{{/unless}}
			<tr id="new_res_col">
			  <td><input type="text" name="target_res_id"></td>
			  <td><select name="colocate"><option value="together">Together<option value="apart">Apart</select></td>
			  <td><input type="text" name="score" size="5"></td>
			  <td><button type="button" onclick="add_constraint('#new_res_col','col', false);" name="add">Add</button></td>
			</tr>

		      </table>
		    </div>
		  </td>
		</tr>
	      </table>
	      <table style="clear:left;float:left">
		<tr><td onclick="show_hide_constraints(this)" class="datatable_header hover-pointer" id="meta_attr"><span style="" class="downarrow sprites"></span><span style="display: none;" class="rightarrow sprites"></span>Resource Meta Attributes ({{#if Pcs.resourcesController.cur_resource.meta_attr.length}}{{Pcs.resourcesController.cur_resource.meta_attr.length}}{{else}}0{{/if}})</td></tr>
		<tr><td>
		    <div id="locationdep">
		      <table class="datatable">
			<tr><th>Meta Attribute</th><th>Value</th><th>Remove</th></tr>
			{{#each Pcs.resourcesController.cur_resource.meta_attr}}
			<tr><td>{{this.key}}</td>
			    <td>{{this.value}}</td>
			    <td {{bind-attr meta_attr_key="this.key"}} {{bind-attr meta_attr_res="this.parent"}} style="text-align:center">
				  <a onclick="remove_meta_attr($(this).parent());return false;" href="#" class="remove">X</a>
			    </td>
			  </tr>
                        {{/each}}
 			{{#unless Pcs.resourcesController.cur_resource.meta_attr}}
			  <tr><td style="color: gray;">NONE</td><td></td><td></td></tr>
 			{{/unless}}
			<tr id="new_meta_col">
			  <td><input type="text" name="new_meta_key" size="20"></td>
			  <td><input type="text" name="new_meta_value" size="20"></td>
			  <td><button type="button" onclick="add_meta_attr('#new_meta_col');" name="add">Add</button></td>
			</tr>

		      </table>
		    </div>
		  </td>
		</tr>
	      </table>
          <br style="clear:left;">
	    </div>
	  <% end %>

	    <table style="clear:left;float:left;margin-top:25px;">
	      <% if @myView == "resource" and false %>
	      <tr>
		<td class="bold">Class:</td>
		<td class="reg">
		{{Pcs.resourcesController.cur_resource.res_class}}
		</td>
		<td style="padding-left:10px;" class="bold">Provider:</td>
		<td class="reg">
		{{Pcs.resourcesController.cur_resource.res_provider}}
		</td>
	      </tr>
	      <% end %>
	      <tr>
		<td class="bold">Type:</td>
		<td class="reg">
		{{Pcs.resourcesController.cur_resource.agentname}}
		</td>
	      </tr>
	    </table>

	    <% if @myView == "resource" %>
	      <div style="clear:left;" id="resource_agent_form"></div>
	    <% else %>
	      <div style="clear:left;" id="stonith_agent_form"></div>
	    <% end %>
	    {{#if Pcs.resourcesController.no_resources}}
	      <span id="node_info_header"><span id="node_info_header_title">No resources have been configured</span></span>
	     {{/if}}
	    </div>
	  </td>
	</tr>
    <% if @myView == "resource" %>
      </div>
    </table>
    <div id="add_resource" style="display: none;">
      <table id="resource_selector" style="clear:left;float:left;margin-top:25px;">
	<tr>
	  <td class="bold">Class/Provider</td>
	  <td>
	    <%
	      class_providers = []
	      @resource_agents.keys.each {|k|
		class_providers << k[0,k.rindex(':')]
	      }
	      class_providers.uniq!
	      class_providers.sort!
	    %>
	    <select id="resource_class_provider_selector">
	      <% class_providers.each {|cp| %>
		<option <%= "selected" if cp == "ocf:heartbeat" %> value="<%=cp%>"><%=cp%></option>
	      <% } %>
	    </select>
	  </td>
	</tr>
	<tr>
	  <td class="bold">Type</td>
	  <td>
	    <select id="all_ra_types" style="display:none;">
	      <% @resource_agents.keys.sort_by{|a|a.downcase}.each { |key| %>
		<option width=250px  value="<%=key%>"><%=key[(key.rindex(':')+1)..-1]%></option>
	      <% } %>
	    </select>
	    <select id="add_ra_type" onchange="load_resource_form($('#new_resource_agent'), this.value);">
	      <% @resource_agents.keys.sort_by{|a|a.downcase}.each { |key| %>
		<option width=250px <%= key == "ocf::heartbeat:IPaddr2" ? "selected" : "" %> value="<%=key%>"><%=key%></option>
	      <% } %>
	    </select>
	  </td>
	</tr>
      </table>
      <div id="new_resource_agent">
      </div>
    </div>
    <div id="add_stonith" style="display: none;">
      <table id="stonith_selector" style="clear:left;float:left;margin-top:25px;">
	<tr>
	  <td class="bold">Type</td>
	  <td>
	    <select id="add_stonith_type" onchange="load_resource_form($('#new_stonith_agent'),this.value,true);">
	      <% @stonith_agents.keys.sort_by{|a|a.downcase}.each { |name| %>
		<option width=250px <%= @stonith_agents[name]["type"] == "fence_apc" ? "selected" : "" %> value="<%=@stonith_agents[name]["type"]%>"><%=@stonith_agents[name]["type"]%></option>
	    <% } %>
	    </select>
	  </td>
	</tr>
      </table>
      <div id="new_stonith_agent">
      </div>
    </div>
    <div id="add_group" style="display: none;">
      <form method=POST onkeypress="if (event.keyCode == 13) {$(this).parent().parent().find('.ui-dialog-buttonpane button:eq(1)').trigger('click');return false;} " action="/resource_group_add">
	<p style="font-size:12px;">Group Name:</p><input name="resource_group" type=text>
	<input id="resources_to_add_to_group"  type=hidden name="resources" value="">
      </form>
    </div>
    <div id="verify_remove" style="display: none;">
      <p style="font-size:12px;">Are you sure you want to remove the following resource(s)?</p>
      <span id="resource_to_remove"></span>
    </div>
    <% end %>
