Skip to content

Commit

Permalink
Merge pull request #1747 from akvo/#1744-editor-dates
Browse files Browse the repository at this point in the history
[Fixes #1744] Toggle between planned and actual dates
  • Loading branch information
KasperBrandt committed Aug 19, 2015
2 parents d55df17 + c6839b5 commit 84fce5b
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 57 deletions.
49 changes: 25 additions & 24 deletions akvo/rsr/models/publishing_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,32 @@ def clean(self):
code='subtitle')
)

if not self.project.project_plan_summary:
if self.project.status == 'N':
validation_errors.append(
ValidationError(_('Project needs to have the project plan summary filled in.'),
code='summary')
ValidationError(_('Project needs to have a status.'),
code='status')
)

if not self.project.goals_overview:
if not (self.project.date_start_planned or self.project.date_start_actual):
validation_errors.append(
ValidationError(_('Project needs to have the goals overview field filled in.'),
code='goals_overview')
ValidationError(
_('Project needs to have the planned or actual start date field filled '
'in.'), code='start_date')
)

if not self.project.date_start_planned:
if not self.project.current_image:
validation_errors.append(
ValidationError(
_('Project needs to have the planned start date field filled in.'),
code='goals_overview')
ValidationError(_('Project needs to have a photo.'),
code='current_image')
)

if not self.project.partners:
if not self.project.sync_owner:
validation_errors.append(
ValidationError(_('Project needs to have at least one valid partner.'),
code='partners')
ValidationError(_('Project needs to have a reporting organisation.'),
code='reporting_org')
)
elif not self.project.partnerships.filter(

if not self.project.partnerships.filter(
partner_type__in=['field', 'funding', 'support']
).exists():
validation_errors.append(
Expand All @@ -85,16 +86,16 @@ def clean(self):
)
break

if not self.project.sync_owner:
if not self.project.project_plan_summary:
validation_errors.append(
ValidationError(_('Project needs to have a reporting organisation.'),
code='reporting_org')
ValidationError(_('Project needs to have the project plan summary filled in.'),
code='summary')
)

if not self.project.current_image:
if not self.project.goals_overview:
validation_errors.append(
ValidationError(_('Project needs to have a photo.'),
code='current_image')
ValidationError(_('Project needs to have the goals overview field filled in.'),
code='goals_overview')
)

if not self.project.locations.all():
Expand All @@ -104,7 +105,7 @@ def clean(self):
)
else:
for location in self.project.locations.all():
if not location.latitude or not location.longitude or not location.country:
if not (location.latitude and location.longitude and location.country):
validation_errors.append(
ValidationError(
_('All locations need to have a latitude, longitude and country '
Expand Down Expand Up @@ -133,10 +134,10 @@ def clean(self):
)
else:
for sector in self.project.sectors.all():
if not sector.sector_code:
if not (sector.sector_code and sector.vocabulary):
validation_errors.append(
ValidationError(_('All sectors need to have a sector code.'),
code='sector')
ValidationError(_('All sectors need to have a sector code and '
'vocabulary.'), code='sector')
)
break

Expand Down
150 changes: 117 additions & 33 deletions akvo/templates/myrsr/project_editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,34 +187,46 @@ <h5>{% trans 'Related projects' %}<span class="glyphicon glyphicon-info-sign inf
</div>
<div class="form-group">
<div class="row">
<div class="col-md-6 control priority1 datepicker-container"
data-id="eventFromPlanned"
data-child="{{ project.date_start_planned|date:"d/m/Y" }}"
data-label="{% trans 'Start date (planned)' %}"
data-helptext="{% trans 'Enter the original start date of the project (DD/MM/YYYY).' %}"
data-classes="priority1"></div>
<div class="col-md-6 control datepicker-container"
data-id="eventEndPlanned"
data-child="{{ project.date_end_planned|date:"d/m/Y" }}"
data-label="{% trans 'End date (planned)' %}"
data-helptext="{% trans 'Enter the original end date of the project (DD/MM/YYYY).' %}"
data-classes="priority2"></div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-6 control datepicker-container"
data-id="eventFromActual"
data-child="{{ project.date_start_actual|date:"d/m/Y" }}"
data-label="{% trans 'Start date (actual)' %}"
data-helptext="{% trans 'Enter the actual start date of the project (DD/MM/YYYY).' %}"
data-classes="priority2"></div>
<div class="col-md-6 control datepicker-container"
data-id="eventEndActual"
data-child="{{ project.date_end_actual|date:"d/m/Y" }}"
data-label="{% trans 'End date (actual)' %}"
data-helptext="{% trans 'Enter the actual end date of the project (DD/MM/YYYY).' %}"
data-classes="priority2"></div>
<div class="col-md-6">
<div class="control datepicker-container {% if project.date_start_actual %}hidden{% endif %}"
id="planned-start-date-container"
data-id="eventFromPlanned"
data-child="{{ project.date_start_planned|date:"d/m/Y" }}"
data-label="{% trans 'Start date (planned)' %}"
data-helptext="{% trans 'Enter the original start date of the project (DD/MM/YYYY).' %}"
data-classes="priority{% if not project.date_start_actual %}1{% else %}2{% endif %}"></div>
<div class="control datepicker-container {% if not project.date_start_actual %}hidden{% endif %}"
id="actual-start-date-container"
data-id="eventFromActual"
data-child="{{ project.date_start_actual|date:"d/m/Y" }}"
data-label="{% trans 'Start date (actual)' %}"
data-helptext="{% trans 'Enter the actual start date of the project (DD/MM/YYYY).' %}"
data-classes="priority{% if project.date_start_actual %}1{% else %}2{% endif %}"></div>
<p>
<input type="checkbox" id="start-date-toggle" {% if project.date_start_actual %}checked{% endif %} onchange="toggleStartDate(this)">
<span style="font-size: 0.9em; color: rgba(44, 42, 116, 0.5);">{% trans 'Show actual start date' %}</span>
</p>
</div>
<div class="col-md-6">
<div class="control datepicker-container {% if project.date_end_actual %}hidden{% endif %}"
id="planned-end-date-container"
data-id="eventEndPlanned"
data-child="{{ project.date_end_planned|date:"d/m/Y" }}"
data-label="{% trans 'End date (planned)' %}"
data-helptext="{% trans 'Enter the original end date of the project (DD/MM/YYYY).' %}"
data-classes="priority2"></div>
<div class="control datepicker-container {% if not project.date_end_actual %}hidden{% endif %}"
id="actual-end-date-container"
data-id="eventEndActual"
data-child="{{ project.date_end_actual|date:"d/m/Y" }}"
data-label="{% trans 'End date (actual)' %}"
data-helptext="{% trans 'Enter the actual end date of the project (DD/MM/YYYY).' %}"
data-classes="priority2"></div>
<p>
<input type="checkbox" id="end-date-toggle" {% if project.date_end_actual %}checked{% endif %} onchange="toggleEndDate(this)">
<span style="font-size: 0.9em; color: rgba(44, 42, 116, 0.5);">{% trans 'Show actual end date' %}</span>
</p>
</div>
</div>
</div>
<div class="form-group">
Expand Down Expand Up @@ -1223,7 +1235,7 @@ <h5>{% trans 'Keywords' %}</h5>
fundingInputNode.className += ' priority1';

labelNode = fundingNode.getElementsByTagName('label')[0];
labelNode.innerHTML = labelNode.innerHTML.replace('Funding amount', 'Funding amount<span class="mandatory">*</span>')
labelNode.innerHTML = labelNode.innerHTML.replace('Funding amount', 'Funding amount<span class="mandatory">*</span>');
} else {
fundingInputNode.value = '';
fundingInputNode.setAttribute('disabled', '');
Expand Down Expand Up @@ -1369,20 +1381,20 @@ <h5>{% trans 'Keywords' %}</h5>
if (node.checked) {
// User wants to upload document
if (documentUrl.className.indexOf('hidden') === -1) {
documentUrl.className += ' hidden'
documentUrl.className += ' hidden';
}

if (documentUpload.className.indexOf('hidden') > -1) {
documentUpload.className = documentUpload.className.replace('hidden', '')
documentUpload.className = documentUpload.className.replace('hidden', '');
}
} else {
// User wants to indicate URL
if (documentUpload.className.indexOf('hidden') === -1) {
documentUpload.className += ' hidden'
documentUpload.className += ' hidden';
}

if (documentUrl.className.indexOf('hidden') > -1) {
documentUrl.className = documentUrl.className.replace('hidden', '')
documentUrl.className = documentUrl.className.replace('hidden', '');
}
}
}
Expand All @@ -1399,6 +1411,78 @@ <h5>{% trans 'Keywords' %}</h5>
helpText.className += ' hidden';
}
}

function toggleStartDate(node) {
var startDateActual, startDatePlanned, startDateActualInput, startDatePlannedInput, startDateActualLabel, startDatePlannedLabel, mandatoryNode;

startDateActual = document.getElementById('actual-start-date-container');
startDatePlanned = document.getElementById('planned-start-date-container');
startDateActualInput = startDateActual.getElementsByTagName('input')[0];
startDatePlannedInput = startDatePlanned.getElementsByTagName('input')[0];
startDateActualLabel = startDateActual.getElementsByTagName('label')[0];
startDatePlannedLabel = startDatePlanned.getElementsByTagName('label')[0];

mandatoryNode = document.createElement('span');
mandatoryNode.className = 'mandatory';
mandatoryNode.innerHTML= '*';

if (node.checked) {
// Show actual start date, as mandatory field
if (startDatePlanned.className.indexOf('hidden') === -1) {
startDatePlanned.className += ' hidden';
startDatePlannedInput.className = startDatePlannedInput.className.replace('priority1', 'priority2');
}

if (startDateActual.className.indexOf('hidden') > -1) {
startDateActual.className = startDateActual.className.replace('hidden', '');
startDateActualInput.className = startDateActualInput.className.replace('priority2', 'priority1');
}

startDateActualLabel.insertBefore(mandatoryNode, startDateActualLabel.getElementsByTagName('span')[0]);
startDatePlannedLabel.innerHTML = startDatePlannedLabel.innerHTML.replace('<span class="mandatory">*</span>', '')
} else {
// Show planned start date, as mandatory field
if (startDateActual.className.indexOf('hidden') === -1) {
startDateActual.className += ' hidden';
startDateActualInput.className = startDateActualInput.className.replace('priority1', 'priority2');
}

if (startDatePlanned.className.indexOf('hidden') > -1) {
startDatePlanned.className = startDatePlanned.className.replace('hidden', '');
startDatePlannedInput.className = startDatePlannedInput.className.replace('priority2', 'priority1');
}

startDatePlannedLabel.insertBefore(mandatoryNode, startDatePlannedLabel.getElementsByTagName('span')[0]);
startDateActualLabel.innerHTML = startDateActualLabel.innerHTML.replace('<span class="mandatory">*</span>', '')
}
}

function toggleEndDate(node) {
var endDateActual, endDatePlanned;

endDateActual = document.getElementById('actual-end-date-container');
endDatePlanned = document.getElementById('planned-end-date-container');

if (node.checked) {
// Show actual end date
if (endDatePlanned.className.indexOf('hidden') === -1) {
endDatePlanned.className += ' hidden';
}

if (endDateActual.className.indexOf('hidden') > -1) {
endDateActual.className = endDateActual.className.replace('hidden', '');
}
} else {
// Show planned end date
if (endDateActual.className.indexOf('hidden') === -1) {
endDateActual.className += ' hidden';
}

if (endDatePlanned.className.indexOf('hidden') > -1) {
endDatePlanned.className = endDatePlanned.className.replace('hidden', '');
}
}
}
</script>

<script type="application/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>
Expand Down

0 comments on commit 84fce5b

Please sign in to comment.