Skip to content

Commit

Permalink
Merge pull request #122 from iMMAP/fix/multiple_activity_fixes
Browse files Browse the repository at this point in the history
[FIX] - Target locations Duplicate and Delete buttons and show/hide Zone
  • Loading branch information
shtayeb authored Dec 19, 2023
2 parents 3704a55 + 462f8d1 commit 2d5ecaf
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
<div>
<button href="#"
data-url="{% url 'copy_location' project=project.pk location=target_location_form.instance.pk %}"
data-return-url="{% url 'create_project_activity_plan' project=project.pk %}"
data-type="copy"
data-record-name="target location"
class="btn btn-gray-outline show_confirm"><span class="btn-text">Duplicate</span><span class="icon-copy-outline"></span>
data-name="target location"
class="btn btn-gray-outline show-sw-action-popup">
<span class="icon-copy"></span>
<span class="btn-text">Duplicate</span>
</button>
<button href="#"
data-url="{% url 'delete_location' target_location_form.instance.pk %}"
data-return-url="{% url 'create_project_activity_plan' project=project.pk %}"
data-type="delete"
data-record-name="target location"
class="btn btn-gray-outline show_confirm">
data-url="{% url 'delete_location' target_location_form.instance.pk %}"
data-type="delete"
data-name="target location"
class="btn btn-gray-outline show-sw-action-popup">
<span class="icon-trashbin"></span>
<span class="btn-text">Delete</span>
</button>
Expand Down
16 changes: 14 additions & 2 deletions src/rh/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ def load_locations_details(request):
[f'<option value="{location.pk}">{location}</option>' for location in parent.children.order_by("name")]
)
+ "</optgroup>"
if parent.children.exists()
else ""
for parent in parents
]
)
Expand Down Expand Up @@ -900,7 +902,12 @@ def copy_target_location(request, project, location):
new_location.state = "draft"
new_location.title = f"[COPY] - {target_location.title}"
new_location.save()
return JsonResponse({"success": True})

url = reverse("create_project_activity_plan", args=[project.pk])

# Return the URL in a JSON response
response_data = {"redirect_url": url}
return JsonResponse(response_data)


@cache_control(no_store=True)
Expand All @@ -910,7 +917,12 @@ def delete_target_location(request, pk):
target_location = get_object_or_404(TargetLocation, pk=pk)
if target_location:
target_location.delete()
return JsonResponse({"success": True})

url = reverse("create_project_activity_plan", args=[target_location.project.pk])

# Return the URL in a JSON response
response_data = {"redirect_url": url}
return JsonResponse(response_data)


#############################################
Expand Down
22 changes: 15 additions & 7 deletions src/static/rh/js/activity_planning.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ function updateLocationBlockTitles(locationPrefix) {


/**
* TODO: Make it generic
* Get Districts and Zpnes for Target Location Form
**/
function getLocations(locationPrefix, locationType, parentType, clearZone=null) {
Expand Down Expand Up @@ -365,17 +366,24 @@ function getLocations(locationPrefix, locationType, parentType, clearZone=null)
xhr.setRequestHeader("X-CSRFToken", csrftoken);
},
success: function (data) {
if (data) {
// Clear zone if needed
if (parentType === 'province' && clearZone === true) {
$(`#id_${locationPrefix}-zone`).html('').val('');
}

debugger

// Clear zone if needed
if (parentType === 'province' && clearZone === true) {
$(`#id_${locationPrefix}-zone`).html('').val('');
}
if (data){
// Update the location select element
$(`#id_${locationPrefix}-${locationType}`).html(data);
$(`select#id_${locationPrefix}-${locationType}`).val(selectedLocations);

}

if(locationType == 'zone' && data === ''){
$(`#id_${locationPrefix}-${locationType}`).parent().hide();
}else{
$(`#id_${locationPrefix}-${locationType}`).parent().show();
}

},
error: function (error) {
console.log('Error fetching empty form:', error);
Expand Down

0 comments on commit 2d5ecaf

Please sign in to comment.