Dirty form changes pending cleanup
This commit is contained in:
parent
1979517706
commit
8f6bab104e
|
@ -84,6 +84,32 @@ class ViewController(BaseController):
|
|||
vars = {'data': data, 'errors': errors, 'error_summary': error_summary, 'harvesters': harvesters_info}
|
||||
|
||||
c.groups = self._get_publishers()
|
||||
|
||||
states = [{'text': 'active', 'value': 'True'},
|
||||
{'text': 'withdrawn', 'value': 'False'},]
|
||||
|
||||
harvest_list = []
|
||||
for harvester in harvesters_info:
|
||||
harvest_list.append({'text':harvester['title'], 'value': harvester['name']})
|
||||
|
||||
|
||||
items = [
|
||||
{'name': 'url', 'control': 'input', 'label': _('URL for source of metadata'), 'placeholder': _('')},
|
||||
{'name': 'type', 'control': 'select', 'options': harvest_list, 'label': _('Source type'), 'placeholder': _('')},
|
||||
{'name': 'title', 'control': 'input', 'label': _('Title'), 'placeholder': _('')},
|
||||
{'name': 'description', 'control': 'textarea', 'label': _('Description'), 'placeholder': _('About page text')},]
|
||||
|
||||
if c.groups:
|
||||
pubs = []
|
||||
for group in c.groups:
|
||||
pubs.append({'text':group['title'], 'value': group['id']})
|
||||
items.append({'name': 'publisher_id', 'control': 'select', 'options': pubs, 'label': _('Publisher'), 'placeholder': _('')})
|
||||
|
||||
items += [
|
||||
{'name': 'config', 'control': 'textarea', 'label': _('Configuration'), 'placeholder': _('About page text')},
|
||||
{'name': 'active', 'control': 'select', 'options': states, 'label': _('State'), 'placeholder': _('')},
|
||||
]
|
||||
vars['form_items'] = items
|
||||
c.form = render('source/new_source_form.html', extra_vars=vars)
|
||||
return render('source/new.html')
|
||||
|
||||
|
@ -139,7 +165,41 @@ class ViewController(BaseController):
|
|||
vars = {'data': data, 'errors': errors, 'error_summary': error_summary, 'harvesters': harvesters_info}
|
||||
|
||||
c.groups = self._get_publishers()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
states = [{'text': 'active', 'value': 'True'},
|
||||
{'text': 'withdrawn', 'value': 'False'},]
|
||||
|
||||
harvest_list = []
|
||||
for harvester in harvesters_info:
|
||||
harvest_list.append({'text':harvester['title'], 'value': harvester['name']})
|
||||
|
||||
|
||||
items = [
|
||||
{'name': 'url', 'control': 'input', 'label': _('URL for source of metadata'), 'placeholder': _('')},
|
||||
{'name': 'type', 'control': 'select', 'options': harvest_list, 'label': _('Source type'), 'placeholder': _('')},
|
||||
{'name': 'title', 'control': 'input', 'label': _('Title'), 'placeholder': _('')},
|
||||
{'name': 'description', 'control': 'textarea', 'label': _('Description'), 'placeholder': _('About page text')},]
|
||||
|
||||
if c.groups:
|
||||
pubs = []
|
||||
for group in c.groups:
|
||||
pubs.append({'text':group['title'], 'value': group['id']})
|
||||
items.append({'name': 'publisher_id', 'control': 'select', 'options': pubs, 'label': _('Publisher'), 'placeholder': _('')})
|
||||
|
||||
items += [
|
||||
{'name': 'config', 'control': 'textarea', 'label': _('Configuration'), 'placeholder': _('About page text')},
|
||||
{'name': 'active', 'control': 'select', 'options': states, 'label': _('State'), 'placeholder': _('')},
|
||||
]
|
||||
vars['form_items'] = items
|
||||
|
||||
|
||||
|
||||
c.form = render('source/new_source_form.html', extra_vars=vars)
|
||||
|
||||
return render('source/edit.html')
|
||||
|
||||
def _save_edit(self,id):
|
||||
|
|
|
@ -1,89 +1,8 @@
|
|||
<form id="source-new" class="ckan" method="post"
|
||||
py:attrs="{'class':'has-errors'} if errors else {}"
|
||||
xmlns:i18n="http://genshi.edgewall.org/i18n"
|
||||
xmlns:py="http://genshi.edgewall.org/"
|
||||
xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
{% import 'macros/form.html' as form %}
|
||||
|
||||
<div class="error-explanation" py:if="error_summary">
|
||||
<h2>Errors in form</h2>
|
||||
<p>The form contains invalid entries:</p>
|
||||
<ul>
|
||||
<li py:for="key, error in error_summary.items()">${"%s: %s" % (key, error)}</li>
|
||||
</ul>
|
||||
</div>
|
||||
<form id="source-new" class="form-horizontal" method="post">
|
||||
|
||||
<fieldset>
|
||||
<legend>Details</legend>
|
||||
<dl>
|
||||
<dt><label class="field_req" for="url">URL for source of metadata *</label></dt>
|
||||
<dd><input id="url" name="url" size="80" type="text" value="${data.get('url', '')}" /></dd>
|
||||
<dd class="field_error" py:if="errors.get('url', '')">${errors.get('url', '')}</dd>
|
||||
<dd class="instructions basic">This should include the <tt>http://</tt> part of the URL</dd>
|
||||
<dt><label class="field_req" for="type">Source Type *</label></dt>
|
||||
<dd>
|
||||
<select id="type" name="type">
|
||||
<py:for each="harvester in harvesters">
|
||||
<option value="${harvester.name}" py:attrs="{'selected': 'selected' if data.get('type', '') == harvester.name else None, 'data-config': harvester.show_config}" >${harvester.title}</option>
|
||||
</py:for>
|
||||
</select>
|
||||
</dd>
|
||||
<dd class="field_error" py:if="errors.get('type', '')">${errors.get('type', '')}</dd>
|
||||
<dd class="instructions basic">Which type of source does the URL above represent?
|
||||
<ul>
|
||||
<py:for each="harvester in harvesters">
|
||||
<li><span class="harvester-title">${harvester.title}</span>: ${harvester.description}</li>
|
||||
</py:for>
|
||||
</ul>
|
||||
</dd>
|
||||
|
||||
<dt class="harvest-source-title"><label class="field_req" for="title">Title</label></dt>
|
||||
<dd class="harvest-source-title"><input id="title" name="title" size="80" type="text" value="${data.get('title', '')}" /></dd>
|
||||
<dd class="harvest-source-title field_error" py:if="errors.get('title', '')">${errors.get('title', '')}</dd>
|
||||
<dd class="harvest-source-title instructions basic">This will be shown as the datasets source.</dd>
|
||||
|
||||
<dt><label class="field_opt" for="description">Description</label></dt>
|
||||
<dd><textarea id="description" name="description" cols="30" rows="2" style="height:75px">${data.get('description', '')}</textarea></dd>
|
||||
<dd class="instructions basic">You can add your own notes here about what the URL above represents to remind you later.</dd>
|
||||
|
||||
<dt py:if="c.publisher_auth"><label class="field_opt" for="groups__${len(data.get('groups', []))}__id">Publisher</label></dt>
|
||||
<dd py:if="c.publisher_auth and c.groups">
|
||||
<select id="publisher_id" name="publisher_id">
|
||||
<py:for each="group in c.groups">
|
||||
<option value="${group['id']}" py:attrs="{'selected': 'selected' if group['id'] == data.get('publisher_id',None) else None}">${group['title']}</option>
|
||||
</py:for>
|
||||
</select>
|
||||
</dd>
|
||||
<dd py:if="c.publisher_auth and not c.groups"><em>Cannot add any publishers.</em></dd>
|
||||
|
||||
|
||||
<dt class="harvest-source-config"><label class="field_opt" for="config">Configuration</label></dt>
|
||||
<dd class="harvest-source-config"><textarea id="config" name="config" cols="30" rows="2" style="height:75px">${data.get('config', '')}</textarea></dd>
|
||||
|
||||
<dt><label class="field_opt" for="active">State</label></dt>
|
||||
<dd>
|
||||
<select id="active" name="active">
|
||||
<option py:attrs="{'selected': 'selected' if data.get('active') or not 'active' in data else None}" value="True">active</option>
|
||||
<option py:attrs="{'selected': 'selected' if 'active' in data and not data.get('active') else None}" value="False">withdrawn</option>
|
||||
</select>
|
||||
<py:if test="data.get('active') or not 'active' in data">
|
||||
<div>This harvest source is <span class="source-state-active">Active</span></div>
|
||||
</py:if>
|
||||
<py:if test="'active' in data and not data.get('active')">
|
||||
<div>This harvest source is <span class="source-state-inactive">Withdrawn</span></div>
|
||||
</py:if>
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
</fieldset>
|
||||
{{ form.errors(error_summary) }}
|
||||
{{ form.autoform(form_items, data, errors) }}
|
||||
<input id="save" name="save" value="Save" type="submit" class="btn"/> or <a href="/harvest">Return to the harvest sources list</a>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$("#type").change(function(){
|
||||
var show_config = ($("#type option:selected").attr("data-config") == "True");
|
||||
if (!show_config) $("#config").val("");
|
||||
$("#config").attr("disabled", !show_config);
|
||||
});
|
||||
$("#type").trigger("change");
|
||||
});
|
||||
</script>
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue