layerindex-web/templates/layerindex/editlayer.html
Paul Eggleton b5074ed2aa Top bar functions improvements
* Change Submit layer link into a button
* Ensure tools dropdown menu doesn't show on layer submit/edit page

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
2013-09-05 00:31:23 +01:00

266 lines
11 KiB
HTML

{% extends "base.html" %}
{% load i18n %}
{% comment %}
layerindex-web - layer editing form page template
Copyright (C) 2013 Intel Corporation
Licensed under the MIT license, see COPYING.MIT for details
{% endcomment %}
<!--
{% block title_append %} - edit layer{% endblock %}
-->
{% block topfunctions %}
<!-- Remove submit link/tools drop-down added by base.html, otherwise clicking it may lose changes -->
{% endblock %}
{% block content %}
{% autoescape on %}
<div class="container-fluid">
<div class="row-fluid">
{% block heading %}
<div class="page-header">
<h1>Edit layer</h1>
</div>
{% endblock %}
{% block formtop %}
{% endblock %}
<form id="edit_layer_form" method="post">
{% csrf_token %}
{% for hidden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
<div class="formfields">
{% for field in form.visible_fields %}
{% if field.name != 'captcha' %}
{% if field.errors %}
<div class="control-group alert alert-error">
{{ field.errors }}
{% else %}
<div class="control-group">
{% endif %}
<div class="control-label">
{{ field.label_tag }}
</div>
<div class="controls">
{% if field.name = 'deps' %}
<div class="scrolling">
<table><tbody>
{% for deplayer in deplistlayers %}
{% if deplayer.id in form.checked_deps %}
<tr>
<td class="checkboxtd"><input type="checkbox" name="deps" value="{{ deplayer.id }}" id="id_deps_{{forloop.counter}}" checked="checked" /></td>
{% if deplayer.status = 'N' %}
<td><label class="muted" for="id_deps_{{forloop.counter}}">{{ deplayer.name }} (unpublished)</label></td>
{% else %}
<td><label for="id_deps_{{forloop.counter}}">{{ deplayer.name }}</label></td>
{% endif %}
</tr>
{% endif %}
{% endfor %}
{% for deplayer in deplistlayers %}
{% if not deplayer.id in form.checked_deps %}
<tr>
<td class="checkboxtd"><input type="checkbox" name="deps" value="{{ deplayer.id }}" id="id_deps_{{forloop.counter}}" /></td>
{% if deplayer.status = 'N' %}
<td><label class="muted" for="id_deps_{{forloop.counter}}">{{ deplayer.name }} (unpublished)</label></td>
{% else %}
<td><label for="id_deps_{{forloop.counter}}">{{ deplayer.name }}</label></td>
{% endif %}
</tr>
{% endif %}
{% endfor %}
</tbody></table>
</div>
{% else %}
{{ field }}
{% endif %}
<span class="help-inline custom-help">
{{ field.help_text }}
</span>
</div>
</div>
{% endif %}
{% endfor %}
</div>
<h3 id="maintainers">Maintainers</h3>
{{ maintainerformset.non_form_errors }}
{{ maintainerformset.management_form }}
{% for maintainerform in maintainerformset %}
<div class="maintainerform" id="maintainerform-{{forloop.counter0}}">
<h4>Maintainer {{forloop.counter}}</h4>
<div class="maintainerformfields">
{% for hidden in maintainerform.hidden_fields %}
{{ hidden }}
{% endfor %}
{% for field in maintainerform.visible_fields %}
{% if field.errors %}
<div class="control-group alert alert-error">
{{ field.errors }}
{% else %}
<div class="control-group">
{% endif %}
<div class="control-label">
{{ field.label_tag }}
</div>
<div class="controls">
{{ field }}
<span class="help-inline custom-help">
{{ field.help_text }}
</span>
</div>
</div>
{% endfor %}
</div>
</div>
{% endfor %}
<p><a href="#" class="btn btn-small" id="addanothermaintainer"><i class="icon-plus"></i>Add maintainer</a><p>
{% if form.captcha %}
<div class="captchafield">
<h3>Verification</h3>
{% if form.captcha.errors %}
<div class="control-group alert alert-error">
{{ form.captcha.errors }}
{% else %}
<div class="control-group">
{% endif %}
<div class="controls">
{{ form.captcha }}
<span class="help-inline custom-help">
{{ form.captcha.help_text }}
</span>
</div>
</div>
</div>
{% endif %}
<div class="submitbuttons">
{% block submitbuttons %}
<input type="submit" value="Save layer" class="btn btn-primary btn-large submitbutton" />
<a href="{{ return_url }}" class="btn btn-large">Cancel</a>
{% endblock %}
</div>
</form>
</div>
</div>
{% endautoescape %}
{% endblock %}
{% block scripts %}
<script>
if (typeof String.prototype.startsWith != 'function') {
String.prototype.startsWith = function (str){
return this.slice(0, str.length) == str;
};
}
auto_web_fields = function (e) {
repoval = $('#id_vcs_url').val()
if( repoval[repoval.length-1] == '/' )
repoval = repoval.slice(0, repoval.length-1)
if( repoval.startsWith('git://git.openembedded.org/') ) {
reponame = repoval.replace(/^.*\//, '')
$('#id_vcs_web_url').val('http://cgit.openembedded.org/cgit.cgi/' + reponame)
$('#id_vcs_web_tree_base_url').val('http://cgit.openembedded.org/cgit.cgi/' + reponame + '/tree/%path%?h=%branch%')
$('#id_vcs_web_file_base_url').val('http://cgit.openembedded.org/cgit.cgi/' + reponame + '/tree/%path%?h=%branch%')
}
else if( repoval.indexOf('git.yoctoproject.org/') > -1 ) {
reponame = repoval.replace(/^.*\//, '')
$('#id_vcs_web_url').val('http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame)
$('#id_vcs_web_tree_base_url').val('http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame + '/tree/%path%?h=%branch%')
$('#id_vcs_web_file_base_url').val('http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame + '/tree/%path%?h=%branch%')
}
else if( repoval.indexOf('github.com/') > -1 ) {
reponame = repoval.replace(/^.*github.com\//, '')
reponame = reponame.replace(/.git$/, '')
$('#id_vcs_web_url').val('http://github.com/' + reponame)
$('#id_vcs_web_tree_base_url').val('http://github.com/' + reponame + '/tree/%branch%/')
$('#id_vcs_web_file_base_url').val('http://github.com/' + reponame + '/blob/%branch%/')
}
else if( repoval.indexOf('gitorious.org/') > -1 ) {
reponame = repoval.replace(/^.*gitorious.org\//, '')
reponame = reponame.replace(/.git$/, '')
$('#id_vcs_web_url').val('http://gitorious.org/' + reponame)
$('#id_vcs_web_tree_base_url').val('http://gitorious.org/' + reponame + '/trees/%branch%/')
$('#id_vcs_web_file_base_url').val('http://gitorious.org/' + reponame + '/blobs/%branch%/')
}
else if( repoval.indexOf('bitbucket.org/') > -1 ) {
reponame = repoval.replace(/^.*bitbucket.org\//, '')
reponame = reponame.replace(/.git$/, '')
$('#id_vcs_web_url').val('http://bitbucket.org/' + reponame)
$('#id_vcs_web_tree_base_url').val('http://bitbucket.org/' + reponame + '/src/%branch%/%path%?at=%branch%')
$('#id_vcs_web_file_base_url').val('http://bitbucket.org/' + reponame + '/src/%branch%/%path%?at=%branch%')
}
};
split_email = function() {
// Split email name/email address pairs
name_input = $(this)
split_regex = /^"?([^"@$<>]+)"? *<([^<> ]+)>[ -]*(.*)?$/
matches = split_regex.exec(name_input.val())
if( matches ){
name_input.val($.trim(matches[1]))
email_id = name_input.attr('id').replace('-name', '-email')
$('#' + email_id).val($.trim(matches[2]))
resp_id = email_id.replace('-email', '-responsibility')
currval = $('#' + resp_id).val()
// Set the responsibility with the remainder of the value unless the user has entered a value for
// responsibility already
if( currval == window['last_' + resp_id] || currval == "" ) {
newval = $.trim(matches[3])
$('#' + resp_id).val(newval)
window['last_' + resp_id] = newval
}
}
}
expand_maintainer = function() {
for(i=0;i<{{ maintainerformset.total_form_count }};i++) {
maintbox = $('#maintainerform-' + i)
if( maintbox.is(':hidden') ) {
maintbox.slideToggle();
if( i == {{maintainerformset.total_form_count}} - 1 )
$('#addanothermaintainer').hide()
break
}
}
return false;
}
$(document).ready(function() {
$('.maintainerform').hide()
for(i=0;i<{{ maintainerformset.total_form_count }};i++) {
name_input = $('#id_layermaintainer_set-' + i + '-name')
name_input.change(split_email)
resp_id = 'id_layermaintainer_set-' + i + '-responsibility'
window['last_' + resp_id] = ""
if( i==0 || name_input.val() )
$('#maintainerform-' + i).show()
}
$('#addanothermaintainer').click(expand_maintainer)
$('#id_vcs_url').change(auto_web_fields)
firstfield = $("#edit_layer_form input:text, #edit_layer_form textarea").first();
if( ! firstfield.val() )
firstfield.focus()
});
</script>
{% endblock %}