% if c.visual.allow_custom_hooks_settings:
${h.form(url('admin_settings_hooks'), method='post')}
<div class="form">
      <div class="form-group">
        <h4>${_('Custom Global Mercurial Hooks')}</h4>
        <span class="help-block">${_('Hooks can be used to trigger actions on certain events such as push / pull. They can trigger Python functions or external applications.')}</span>
        %for hook in c.custom_hooks:
            <div class="form-group form-inline" id="${'id%s' % hook.ui_id }">
                <% input_id = hook.ui_key.replace('.', '_') %>
                    <label class="control-label" for="${input_id}" title="${hook.ui_key}">${hook.ui_key}</label>
                    <div>
                        ${h.hidden('hook_ui_key',hook.ui_key,id='hook_ui_key_'+input_id)}
                        ${h.hidden('hook_ui_value',hook.ui_value,id='hook_ui_value_'+input_id)}
                        ${h.text('hook_ui_value_new',hook.ui_value,id=input_id,size=50,class_='form-control')}
                        <button type="button" class="btn btn-default btn-xs"
                            onclick="delete_hook(${hook.ui_id},'${'id%s' % hook.ui_id }')">
                            <i class="icon-trashcan"></i>
                            ${_('Delete')}
                        </button>
                    </div>
            </div>
        %endfor

        <div class="form-group form-inline">
            <label>
                ${h.text('new_hook_ui_key',size=15,class_='form-control')}
            </label>
            <div>
                ${h.text('new_hook_ui_value',size=50,class_='form-control')}
            </div>
        </div>
        <div class="form-group">
            <div class="buttons">
                ${h.submit('save',_('Save'),class_="btn btn-default")}
            </div>
        </div>
      </div>
</div>
${h.end_form()}

<div class="form">
      <div class="form-group">
      <h4>${_('Git Hooks')}</h4>
      <span class="help-block">${h.HTML(_('Kallithea has no support for custom Git hooks. Kallithea will use Git post-receive hooks internally. Installation of these hooks is managed in %s.')) % (h.literal('''<a href="%s">%s</a>''') % (h.url('admin_settings_mapping'), _('Remap and Rescan')))}</span>
</div>

% else:
      <h4>${_('Custom Hooks are not enabled')}</h4>
% endif

<script>
'use strict';
function delete_hook(hook_id, field_id) {
    var sUrl = ${h.js(h.url('admin_settings_hooks_delete'))};
    function success() {
            $('#' + field_id).remove();
        }
    function failure() {
            alert(${h.js(_('Failed to remove hook'))});
        }
    var postData = {'hook_id': hook_id};
    ajaxPOST(sUrl, postData, success, failure);
}
</script>
