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

Remove dependency on jquery-form #35240

Merged
merged 8 commits into from
Oct 22, 2024
Merged
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/accounting/static/accounting/js/payment_method_handler.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'use strict' is unnecessary inside of modules
hqDefine('accounting/js/payment_method_handler', [
'jquery',
'knockout',
Expand Down Expand Up @@ -63,7 +63,11 @@
self.paymentMethod = ko.observable();

self.submitForm = function () {
$('#' + self.formId).ajaxSubmit({
const $form = $('#' + self.formId);
$.ajax({
url: $form.attr("action"),
data: Object.fromEntries(new FormData($form.get(0))),
method: 'POST',
success: self.handleSuccess,
error: self.handleGeneralError,
});
Expand Down Expand Up @@ -200,10 +204,13 @@
self.removeSavedCard = function () {
self.isRemovingCard(true);
self.showConfirmRemoveCard(false);
$('#' + self.formId).ajaxSubmit({
data: {
removeCard: true,
},
const $form = $('#' + self.formId);
let formData = new FormData($form.get(0));
formData.set("removeCard", true);
$.ajax({
url: $form.attr("action"),
method: "POST",
data: Object.fromEntries(formData),
success: function (response) {
self.handleProcessingErrors(response);
for (var i = 0; i < self.handlers.length; i++) {
Expand Down
15 changes: 12 additions & 3 deletions corehq/apps/groups/static/groups/js/group_members.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/groups/static/groups/js/group_members.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'use strict' is unnecessary inside of modules
hqDefine("groups/js/group_members", [
"jquery",
"underscore",
Expand Down Expand Up @@ -109,15 +109,21 @@
};
_showMembershipUpdating();
$(this).find(':button').prop('disabled', true);
$(this).ajaxSubmit({
$.ajax({
url: $(this).attr("action"),
method: "POST",
data: Object.fromEntries(new FormData(this)),
success: outcome(true, "Group membership", "#edit_membership", "Edit Group Membership", _hideMembershipUpdating),
error: outcome(false, "Group membership", "#edit_membership", _hideMembershipUpdating),
});
return false;
});
$('#edit-group-settings').submit(function () {
$(this).find('.modal-footer :button').disableButton();
$(this).ajaxSubmit({
$.ajax({
url: $(this).attr("action"),
method: "POST",
data: Object.fromEntries(new FormData(this)),
success: outcome(true, "Group settings", "#edit-group-settings", "Edit Settings"),
error: outcome(false, "Group settings", "#edit-group-settings"),
});
Expand All @@ -132,7 +138,10 @@
});
$('#group-data-form').submit(function () {
$(this).find(':button').prop('disabled', true);
$(this).ajaxSubmit({
$.ajax({
url: $(this).attr("action"),
method: "POST",
data: Object.fromEntries(new FormData(this)),
success: outcome(true, "Group data", "#group-data-form", "Edit Group Data"),
error: outcome(false, "Group data", "#group-data-form"),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
options,
paginatedItem
) {
'use strict';

Check warning on line 18 in corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap3/crud_paginated_list.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'use strict' is unnecessary inside of modules
options = options || {};

var self = {};
Expand Down Expand Up @@ -57,7 +57,7 @@
});

self.isPaginatedListEmpty = ko.computed(function () {
return self.paginatedList().length == 0;
return self.paginatedList().length === 0;
});

self.isNewListVisible = ko.computed(function () {
Expand Down Expand Up @@ -88,12 +88,14 @@
});

self.allPages = ko.computed(function () {
var last_ind = self.maxPage() + 1;
if (self.maxPage() <= 5 || self.currentPage() <= 3)
return _.range(1, Math.min(last_ind, 6));
if (self.currentPage() >= self.maxPage() - 2)
return _.range(self.maxPage() - 4, last_ind);
return _.range(self.currentPage() - 2, Math.min(last_ind, self.currentPage() + 3));
var lastIndex = self.maxPage() + 1;
if (self.maxPage() <= 5 || self.currentPage() <= 3) {
return _.range(1, Math.min(lastIndex, 6));
}
if (self.currentPage() >= self.maxPage() - 2) {
return _.range(self.maxPage() - 4, lastIndex);
}
return _.range(self.currentPage() - 2, Math.min(lastIndex, self.currentPage() + 3));
});

self.utils = {
Expand Down Expand Up @@ -143,16 +145,15 @@
};

self.initCreateForm = function () {
var $createForm = $("#create-item-form");
const $createForm = $("#create-item-form");
$createForm.submit(function (e) {
e.preventDefault();
$createForm.ajaxSubmit({
url: "",
type: 'post',
let formData = new FormData($createForm.get(0));
formData.set("action", "create");
$.ajax({
method: 'POST',
dataType: 'json',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite follow why we keep dataType: 'json' in this request but remove it in the other modified request in this file? Same goes for the b5 version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are spurious changes, I must have made them while troubleshooting and then not changed them back. Reading the docs now, it'd be fine to leave off dataType altogether in this code (for a default value, the docs say it makes an intelligent guess).

data: {
'action': 'create',
},
data: Object.fromEntries(formData),
statusCode: self.handleStatusCode,
success: function (data) {
$createForm[0].reset();
Expand Down Expand Up @@ -197,7 +198,7 @@
self.changePage(1);
};

self.deleteItem = function (paginatedItem, event) {
self.deleteItem = function (paginatedItem) {
var pList = self.paginatedList();
paginatedItem.dismissModals();
self.paginatedList(_(pList).without(paginatedItem));
Expand Down Expand Up @@ -246,9 +247,10 @@
return null;
};

self.initRow = function (rowElems, paginatedItem) {
self.initRow = function () {
// Intended to be overridden with additional initialization for
// each row in the paginated list.
// Arguments: rowElems, paginatedItem
};

return self;
Expand Down Expand Up @@ -296,14 +298,12 @@
var $updateForm = $(elems).find('.update-item-form');
if ($updateForm) {
$updateForm.submit(function (e) {
let formData = new FormData($updateForm.get(0));
formData.set("action", "update");
e.preventDefault();
$updateForm.ajaxSubmit({
url: "",
type: 'post',
dataType: 'json',
data: {
action: 'update',
},
$.ajax({
method: 'POST',
data: Object.fromEntries(formData),
success: function (data) {
if (data.updatedItem) {
self.dismissModals();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
hqDefine('hqwebapp/js/bootstrap3/email-request', [
"jquery",
"knockout",
"jquery-form/dist/jquery.form.min",
"hqwebapp/js/bootstrap3/hq.helpers",
], function ($, ko) {

Expand Down Expand Up @@ -66,11 +65,15 @@ hqDefine('hqwebapp/js/bootstrap3/email-request', [
} else if (!self.isRequestReportSubmitting) {
self.$submitBtn.button('loading');
self.cancelBtnEnabled(false);
self.$formElement.ajaxSubmit({
type: "POST",
self.reportUrl(location.href);
self.isRequestReportSubmitting = true;
$.ajax({
method: "POST",
url: self.$formElement.attr('action'),
beforeSerialize: hqwebappRequestReportBeforeSerialize,
beforeSubmit: hqwebappRequestReportBeforeSubmit,
data: new FormData(self.$formElement.get(0)),
contentType: false,
processData: false,
enctype: 'multipart/form-data',
success: hqwebappRequestReportSucccess,
error: hqwebappRequestReportError,
});
Expand All @@ -84,7 +87,7 @@ hqDefine('hqwebapp/js/bootstrap3/email-request', [

self.resetForm = function () {
self.$formElement.find("button[type='submit']").button('reset');
self.$formElement.resetForm();
self.$formElement.get(0).reset();
self.cancelBtnEnabled(true);
self.$submitBtn.button('reset');
resetErrors();
Expand All @@ -106,14 +109,6 @@ hqDefine('hqwebapp/js/bootstrap3/email-request', [
self.recipientsErrorMessage(null);
}

function hqwebappRequestReportBeforeSerialize() {
self.reportUrl(location.href);
}

function hqwebappRequestReportBeforeSubmit() {
self.isRequestReportSubmitting = true;
}

function hqwebappRequestReportSucccess() {
self.isRequestReportSubmitting = false;
self.isReportSent = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
options,
paginatedItem
) {
'use strict';

Check warning on line 20 in corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap5/crud_paginated_list.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'use strict' is unnecessary inside of modules
options = options || {};

var self = {};
Expand Down Expand Up @@ -59,7 +59,7 @@
});

self.isPaginatedListEmpty = ko.computed(function () {
return self.paginatedList().length == 0;
return self.paginatedList().length === 0;
});

self.isNewListVisible = ko.computed(function () {
Expand Down Expand Up @@ -90,12 +90,14 @@
});

self.allPages = ko.computed(function () {
var last_ind = self.maxPage() + 1;
if (self.maxPage() <= 5 || self.currentPage() <= 3)
return _.range(1, Math.min(last_ind, 6));
if (self.currentPage() >= self.maxPage() - 2)
return _.range(self.maxPage() - 4, last_ind);
return _.range(self.currentPage() - 2, Math.min(last_ind, self.currentPage() + 3));
var lastIndex = self.maxPage() + 1;
if (self.maxPage() <= 5 || self.currentPage() <= 3) {
return _.range(1, Math.min(lastIndex, 6));
}
if (self.currentPage() >= self.maxPage() - 2) {
return _.range(self.maxPage() - 4, lastIndex);
}
return _.range(self.currentPage() - 2, Math.min(lastIndex, self.currentPage() + 3));
});

self.utils = {
Expand Down Expand Up @@ -145,16 +147,15 @@
};

self.initCreateForm = function () {
var $createForm = $("#create-item-form");
const $createForm = $("#create-item-form");
$createForm.submit(function (e) {
e.preventDefault();
$createForm.ajaxSubmit({
url: "",
type: 'post',
let formData = new FormData($createForm.get(0));
formData.set("action", "create");
$.ajax({
method: 'POST',
dataType: 'json',
data: {
'action': 'create',
},
data: Object.fromEntries(formData),
statusCode: self.handleStatusCode,
success: function (data) {
$createForm[0].reset();
Expand Down Expand Up @@ -250,9 +251,10 @@
return null;
};

self.initRow = function (rowElems, paginatedItem) {
self.initRow = function () {
// Intended to be overridden with additional initialization for
// each row in the paginated list.
// Arguments: rowElems, paginatedItem
};

return self;
Expand Down Expand Up @@ -294,14 +296,12 @@
var $updateForm = $(elems).find('.update-item-form');
if ($updateForm) {
$updateForm.submit(function (e) {
let formData = new FormData($updateForm.get(0));
formData.set("action", "update");
e.preventDefault();
$updateForm.ajaxSubmit({
url: "",
type: 'post',
dataType: 'json',
data: {
action: 'update',
},
$.ajax({
method: 'POST',
data: Object.fromEntries(formData),
success: function (data) {
if (data.updatedItem) {
self.dismissModals();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
"jquery",
"knockout",
"es6!hqwebapp/js/bootstrap5_loader",
"jquery-form/dist/jquery.form.min",
"hqwebapp/js/bootstrap5/hq.helpers",
], function ($, ko, bootstrap) {
'use strict';

Check warning on line 7 in corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap5/email-request.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'use strict' is unnecessary inside of modules

var EmailRequest = function (modalId, formId) {
let self = {};
Expand Down Expand Up @@ -69,11 +68,15 @@
} else if (!self.isRequestReportSubmitting) {
self.$submitBtn.changeButtonState('loading');
self.cancelBtnEnabled(false);
self.$formElement.ajaxSubmit({
type: "POST",
self.reportUrl(location.href);
self.isRequestReportSubmitting = true;
$.ajax({
method: "POST",
url: self.$formElement.attr('action'),
beforeSerialize: hqwebappRequestReportBeforeSerialize,
beforeSubmit: hqwebappRequestReportBeforeSubmit,
data: new FormData(self.$formElement.get(0)),
contentType: false,
processData: false,
enctype: 'multipart/form-data',
success: hqwebappRequestReportSucccess,
error: hqwebappRequestReportError,
});
Expand All @@ -87,7 +90,7 @@

self.resetForm = function () {
self.$formElement.find("button[type='submit']").changeButtonState('reset');
self.$formElement.resetForm();
self.$formElement.get(0).reset();
self.cancelBtnEnabled(true);
self.$submitBtn.changeButtonState('reset');
resetErrors();
Expand All @@ -109,14 +112,6 @@
self.recipientsErrorMessage(null);
}

function hqwebappRequestReportBeforeSerialize() {
self.reportUrl(location.href);
}

function hqwebappRequestReportBeforeSubmit() {
self.isRequestReportSubmitting = true;
}

function hqwebappRequestReportSucccess() {
self.isRequestReportSubmitting = false;
self.isReportSent = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

<script src="{% static 'jquery/dist/jquery.min.js' %}"></script>
{% compress js %}
<script src="{% static 'jquery-form/dist/jquery.form.min.js' %}"></script>
<script src="{% static 'jquery.cookie/jquery.cookie.js' %}"></script>
<script src="{% static 'jquery.rmi/jquery.rmi.js' %}"></script>
{% endcompress %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<script src="{% static 'hqwebapp/js/lib/modernizr.js' %}"></script>

<script src="{% static 'jquery/dist/jquery.min.js' %}"></script>
<script src="{% static 'jquery-form/dist/jquery.form.min.js' %}"></script>
<script src="{% static 'jquery.cookie/jquery.cookie.js' %}"></script>
<script src="{% static 'jquery.rmi/jquery.rmi.js' %}"></script>
<script src="{% static 'bootstrap/dist/js/bootstrap.min.js' %}"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<script src="{% static 'hqwebapp/js/lib/modernizr.js' %}"></script>

<script src="{% static 'jquery/dist/jquery.min.js' %}"></script>
<script src="{% static 'jquery-form/dist/jquery.form.min.js' %}"></script>
<script src="{% static 'jquery.cookie/jquery.cookie.js' %}"></script>
<script src="{% static 'jquery.rmi/jquery.rmi.js' %}"></script>
<script src="{% static 'bootstrap5/dist/js/bootstrap.bundle.min.js' %}"></script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% load hq_shared_tags %}
<script src="{% static 'jquery/dist/jquery.min.js' %}"></script>
<script src="{% static 'jquery-form/dist/jquery.form.min.js' %}"></script>
<script src="{% static 'jquery.cookie/jquery.cookie.js' %}"></script>
<script src="{% static 'jquery.rmi/jquery.rmi.js' %}"></script>
<script src="{% static 'bootstrap/dist/js/bootstrap.min.js' %}"></script>
Expand Down
Loading
Loading