Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case Management Page: Fixes minor issues with saved polygon filters and disbursement #35257

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';

Check warning on line 1 in corehq/apps/geospatial/static/geospatial/js/case_management.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'use strict' is unnecessary inside of modules

hqDefine("geospatial/js/case_management", [
"jquery",
Expand Down Expand Up @@ -48,7 +48,6 @@
var self = {};

self.isBusy = ko.observable(false);
self.showParams = ko.observable(false);
self.parameters = ko.observableArray([]);

self.disbursementErrorMessage = ko.observable('');
Expand Down Expand Up @@ -135,7 +134,7 @@
}

self.parameters(parametersList);
self.showParams(true);
$('#disbursement-params').show();
};

let userData = users.map(function (c) {
Expand Down
62 changes: 44 additions & 18 deletions corehq/apps/geospatial/static/geospatial/js/models.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';

Check warning on line 1 in corehq/apps/geospatial/static/geospatial/js/models.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'use strict' is unnecessary inside of modules
hqDefine('geospatial/js/models', [
'jquery',
'knockout',
Expand Down Expand Up @@ -662,12 +662,40 @@
}
};

self.clearSelectedPolygonFilter = function clearSelectedPolygonFilter() {
self.clearSelectedPolygonFilter = function () {
if (!clearDisbursementBeforeProceeding()) {
return;
}

self.selectedSavedPolygonId('');
self.clearActivePolygon();
updateSelectedSavedPolygonParam();
};

function clearDisbursementBeforeProceeding() {
let proceedFurther = true;
if (self.mapObj.hasDisbursementLayers()) {
// hide it by default and show it only if necessary
$('#disbursement-clear-message').hide();
if (confirmForClearingDisbursement()) {
self.mapObj.removeDisbursementLayers();
$('#disbursement-clear-message').show();
$('#disbursement-params').hide();
proceedFurther = true;
} else {
proceedFurther = false;
}
}
return proceedFurther;
}

function confirmForClearingDisbursement() {
return confirm(
gettext("Warning! This action will clear the current disbursement. " +
"Please confirm if you want to proceed.")
);
}

self.exportSelectedPolygonGeoJson = function (data, event) {
if (self.activeSavedPolygon()) {
const convertedData = 'application/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(self.activeSavedPolygon().geoJson));
Expand All @@ -679,6 +707,10 @@
};

self.deleteSelectedPolygonFilter = function () {
if (!clearDisbursementBeforeProceeding()) {
return;
}

const deleteGeoJSONUrl = initialPageData.reverse('geo_polygon', self.selectedSavedPolygonId());
$.ajax({
type: 'DELETE',
Expand Down Expand Up @@ -720,24 +752,13 @@
return;
}

// hide it by default and show it only if necessary
$('#disbursement-clear-message').hide();
if (mapObj.hasDisbursementLayers()) {
let confirmation = confirm(
gettext("Warning! This action will clear the current disbursement. " +
"Please confirm if you want to proceed.")
);
if (confirmation) {
if (mapObj.removeDisbursementLayers()) {
$('#disbursement-clear-message').show();
}
} else {
// set flag
self.resettingSavedPolygon = true;
self.selectedSavedPolygonId(self.oldSelectedSavedPolygonId());
return;
}
if (!clearDisbursementBeforeProceeding()) {
// set flag
self.resettingSavedPolygon = true;
self.selectedSavedPolygonId(self.oldSelectedSavedPolygonId());
return;
}

self.clearActivePolygon();

createActivePolygonLayer(polygonObj);
Expand Down Expand Up @@ -775,6 +796,11 @@
if (!validateSavedPolygonName(name)) {
return;
}

if (!clearDisbursementBeforeProceeding()) {
return;
}

data['name'] = name;
$.ajax({
type: 'post',
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/geospatial/templates/case_management.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
Previous disbursement was cleared.
{% endblocktrans %}
</div>
<div id="disbursement-params" class="alert alert-info" data-bind="visible: showParams()">
<div id="disbursement-params" class="alert alert-info" style="display: none">
<h4>{% trans 'Disbursement parameters' %}</h4>
<!-- ko foreach: parameters -->
<span style="padding-right: 1em">
Expand Down
Loading