layerindex-web/templates/layerindex/editlayer.html
Paul Eggleton aa2c67c92d Fix fields not saving their values when disabled
We grey out some fields because we don't want to allow the user to
change them. However, we were setting the "disabled" jQuery property to
do this, and this results in the read value for the form field being
blank and thus the field in the database being blank. Set the "readonly"
property instead to get the correct behaviour.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
2013-09-13 11:29:32 +01:00

291 lines
12 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;
};
}
function AutoWebFields(repoval) {
if( repoval[repoval.length-1] == '/' )
repoval = repoval.slice(0, repoval.length-1)
if( repoval.startsWith('git://git.openembedded.org/') ) {
reponame = repoval.replace(/^.*\//, '')
this.vcs_web_url = 'http://cgit.openembedded.org/cgit.cgi/' + reponame
this.vcs_web_tree_base_url = 'http://cgit.openembedded.org/cgit.cgi/' + reponame + '/tree/%path%?h=%branch%'
this.vcs_web_file_base_url = 'http://cgit.openembedded.org/cgit.cgi/' + reponame + '/tree/%path%?h=%branch%'
}
else if( repoval.indexOf('git.yoctoproject.org/') > -1 ) {
reponame = repoval.replace(/^.*\//, '')
this.vcs_web_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame
this.vcs_web_tree_base_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame + '/tree/%path%?h=%branch%'
this.vcs_web_file_base_url = '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$/, '')
this.vcs_web_url = 'http://github.com/' + reponame
this.vcs_web_tree_base_url = 'http://github.com/' + reponame + '/tree/%branch%/'
this.vcs_web_file_base_url = 'http://github.com/' + reponame + '/blob/%branch%/'
}
else if( repoval.indexOf('gitorious.org/') > -1 ) {
reponame = repoval.replace(/^.*gitorious.org\//, '')
reponame = reponame.replace(/.git$/, '')
this.vcs_web_url = 'http://gitorious.org/' + reponame
this.vcs_web_tree_base_url = 'http://gitorious.org/' + reponame + '/trees/%branch%/'
this.vcs_web_file_base_url = 'http://gitorious.org/' + reponame + '/blobs/%branch%/'
}
else if( repoval.indexOf('bitbucket.org/') > -1 ) {
reponame = repoval.replace(/^.*bitbucket.org\//, '')
reponame = reponame.replace(/.git$/, '')
this.vcs_web_url = 'http://bitbucket.org/' + reponame
this.vcs_web_tree_base_url = 'http://bitbucket.org/' + reponame + '/src/%branch%/%path%?at=%branch%'
this.vcs_web_file_base_url = 'http://bitbucket.org/' + reponame + '/src/%branch%/%path%?at=%branch%'
}
else {
this.vcs_web_url = ''
this.vcs_web_tree_base_url = ''
this.vcs_web_file_base_url = ''
}
}
auto_web_fields = function (e) {
repoval = $('#id_vcs_url').val()
awf = new AutoWebFields(repoval)
if (awf.vcs_web_url) {
if (e) {
$('#id_vcs_web_url').val(awf.vcs_web_url)
$('#id_vcs_web_tree_base_url').val(awf.vcs_web_tree_base_url)
$('#id_vcs_web_file_base_url').val(awf.vcs_web_file_base_url)
}
$('#id_vcs_web_url').prop('readonly', true);
$('#id_vcs_web_tree_base_url').prop('readonly', true);
$('#id_vcs_web_file_base_url').prop('readonly', true);
}
else {
$('#id_vcs_web_url').prop('readonly', false);
$('#id_vcs_web_tree_base_url').prop('readonly', false);
$('#id_vcs_web_file_base_url').prop('readonly', false);
}
};
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)
auto_web_fields(null)
firstfield = $("#edit_layer_form input:text, #edit_layer_form textarea").first();
if( ! firstfield.val() )
firstfield.focus()
});
</script>
{% endblock %}