{% extends g.theme.master %}
{% block title %}{{c.project.name}} / Tools{% endblock %}
{% block header %}Select Tools for {{c.project.shortname}}{% endblock %}
{% block content %}
{% if c.project.deleted %}
<div class="notice">This project has been deleted and is not visible to non-admin users</div>
{% endif %}
{% if h.has_project_access('tool')() %}
<p>Drag and drop tools to reorder.</p>
{% endif %}
<table>
<thead>
<tr>
<th>Type</th>
<th>Mount Point</th>
<th>Label</th>
{% if h.has_project_access('tool')() %}
<th>Edit</th>
<th></th>
{% endif %}
</tr>
</thead>
<tbody id="tool_admin">
{% for item in mounts %}
{% set i = loop.index0 %}
<tr class="sortables">
{% if 'ac' in item %}
<td>Tool: {{item['ac'].tool_name}}</td>
<td>{{item['ac'].options.mount_point}}</td>
<td>
<form method="POST" action="update_mounts" id="mounts_edit">
<input type="hidden"
name="tool-{{i}}.mount_point"
class="mount_point"
value="{{item['ac'].options.mount_point}}"/>
<input type="hidden"
name="tool-{{i}}.ordinal"
value="{{'ordinal' in item['ac'].options and item['ac'].options.ordinal or 0}}"/>
{% if h.has_project_access('tool')() and item['ac'].load().installable %}
<div class="editable viewing span-15 last">
<div class="viewer">{{item['ac'].options.mount_label}}</div>
<div class="editor">
<input type="text"
name="tool-{{i}}.mount_label"
value="{{item['ac'].options.mount_label}}"/>
</div>
</div>
{% else %}
<div>
{{item['ac'].options.mount_label}}
</div>
{% endif %}
</form>
</td>
<td>
{% if h.has_project_access('tool')() and item['ac'].load().installable %}
<a href="{{item['ac'].options.mount_point}}/"
class="ico-l">
<b class="ui-icon ui-icon-pencil"></b> <span>Edit</span>
</a>
{% endif %}
</td>
<td>
<form method="POST" action="update_mounts" id="mounts_edit">
<input type="hidden"
name="tool-{{i}}.mount_point"
value="{{item['ac'].options.mount_point}}"/>
<input name="tool-{{i}}.delete" type="hidden" value="Delete"/>
{% if h.has_project_access('tool')() and item['ac'].load().installable %}
<input class="mount_delete" type="button" value="Delete"/>
{% endif %}
</form>
</td>
{% endif %}
{% if 'sub' in item and not item['sub'].deleted %}
<td>Subproject</td>
<td>{{item['sub'].shortname}}</td>
<td>
<form method="POST" action="update_mounts" id="mounts_edit">
<input type="hidden"
name="subproject-{{i}}.shortname"
class="shortname"
value="{{item['sub'].shortname}}"/>
<input type="hidden"
name="subproject-{{i}}.ordinal"
value="{{'ordinal' in item['sub'] and item['sub'].ordinal or 0}}"/>
<div class="editable viewing span-15 last">
<div class="viewer">{{item['sub'].name}}</div>
<div class="editor">
<input type="text"
name="subproject-{{i}}.name"
value="{{item['sub'].name}}"/>
</div>
</div>
</form>
</td>
{% if h.has_project_access('tool')() %}
<td><a href="{{item['sub'].url() + 'admin/'}}" class="ico-l">
<b class="ui-icon ui-icon-pencil"></b> <span>Edit</span>
</a></td>
{% endif %}
<td>
<form method="POST" action="update_mounts" id="mounts_edit">
<input type="hidden"
name="subproject-{{i}}.shortname"
value="{{item['sub'].shortname}}"/>
<input name="subproject-{{i}}.delete" type="hidden" value="Delete"/>
{% if h.has_project_access('tool')() %}
<input class="mount_delete" type="button" value="Delete"/>
{% endif %}
</form>
</td>
{% endif %}
</tr>
{% endfor %}
<form method="POST" action="update_mounts">
<input type="hidden" name="new.ordinal" value="{{installable_tools|length + c.project.direct_subprojects|length}}"/>
{% if h.has_project_access('tool')() %}
<tr>
<td>
<select name="new.ep_name" class="new_ep_name">
<option value="" disabled="disabled">New Tool</option>
{% for tool in installable_tools %}
<option value="{{tool.name}}">{{tool.app.tool_label}}
{{'(%s)' % tool.app.status if tool.app.status != 'production' else ''}}
</option>
{% endfor %}
<option value="">Subproject</option>
</select>
</td>
<td>
<input name="new.mount_point" class="new_mount_point"/>
</td>
<td>
<input name="new.mount_label" class="new_mount_label"/>
</td>
<td colspan="2">
<input type="submit" value="Install" name="new.install"/>
</td>
</tr>
{% endif %}
</form>
</tbody>
</table>
{% if h.has_project_access('tool')() %}
<input type="button" id="save_order" value="Save Tool Order" style="display:none" />
<div id="delete-confirm">Warning: This will destroy all data in this tool and is non reversable!</div>
{% endif %}
{% endblock %}
{% block extra_js %}
<script type="text/javascript">
var form_to_delete = null;
var defaults = {
{% for tool in installable_tools %}
'{{tool.name}}':{'default_label':'{{tool.app.default_mount_label}}','default_mount':'{{tool.app.default_mount_point}}'},
{% endfor %}
};
$('select.new_ep_name').change(function() {
var tool = defaults[$(this).val()];
var row = $(this).closest('tr')
row.find('input.new_mount_point').val(tool.default_mount);
row.find('input.new_mount_label').val(tool.default_label);
});
{% if h.has_project_access('tool')() %}
/*<![CDATA[*/
$('#tool_admin').sortable({
items: 'tr.sortables',
axis: 'y',
update: function(e){
$('#save_order').show();
}
});
$('#save_order').click(function(e){
var sortables = $('#tool_admin .sortables');
var tools = 0
var subs = 0
var params = {}
for(var i=0,len=sortables.length; i<len; i++){
var item = $(sortables[i])
var mount_point = item.find('input.mount_point');
var shortname = item.find('input.shortname');
if(mount_point.length){
params['tools-'+tools+'.mount_point']=mount_point.val();
params['tools-'+tools+'.ordinal']=i;
tools++;
}
if(shortname.length){
params['subs-'+subs+'.shortname']=shortname.val();
params['subs-'+subs+'.ordinal']=i;
subs++;
}
}
$.post('update_mount_order', params, function(){
location.reload();
});
});
$("#delete-confirm").dialog({
resizable: false,
height:200,
modal: true,
autoOpen: false,
buttons: {
'Delete': function() {
form_to_delete.submit();
$(this).dialog('close');
form_to_delete = null;
},
Cancel: function() {
$(this).dialog('close');
form_to_delete = null;
}
}
});
$('input.mount_delete').click(function() {
form_to_delete = this.parentNode;
$('#delete-confirm').dialog('open');
$('div.ui-dialog-buttonpane > button:last').focus();
return false;
});
/*]]>*/
{% endif %}
</script>
{% endblock %}