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

Revert "Remove dependency on jquery-form" #35255

Merged
merged 1 commit into from
Oct 23, 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,11 +63,7 @@
self.paymentMethod = ko.observable();

self.submitForm = function () {
const $form = $('#' + self.formId);
$.ajax({
url: $form.attr("action"),
data: Object.fromEntries(new FormData($form.get(0))),
method: 'POST',
$('#' + self.formId).ajaxSubmit({
success: self.handleSuccess,
error: self.handleGeneralError,
});
Expand Down Expand Up @@ -204,13 +200,10 @@
self.removeSavedCard = function () {
self.isRemovingCard(true);
self.showConfirmRemoveCard(false);
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),
$('#' + self.formId).ajaxSubmit({
data: {
removeCard: true,
},
success: function (response) {
self.handleProcessingErrors(response);
for (var i = 0; i < self.handlers.length; i++) {
Expand Down
15 changes: 3 additions & 12 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,21 +109,15 @@
};
_showMembershipUpdating();
$(this).find(':button').prop('disabled', true);
$.ajax({
url: $(this).attr("action"),
method: "POST",
data: Object.fromEntries(new FormData(this)),
$(this).ajaxSubmit({
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();
$.ajax({
url: $(this).attr("action"),
method: "POST",
data: Object.fromEntries(new FormData(this)),
$(this).ajaxSubmit({
success: outcome(true, "Group settings", "#edit-group-settings", "Edit Settings"),
error: outcome(false, "Group settings", "#edit-group-settings"),
});
Expand All @@ -138,10 +132,7 @@
});
$('#group-data-form').submit(function () {
$(this).find(':button').prop('disabled', true);
$.ajax({
url: $(this).attr("action"),
method: "POST",
data: Object.fromEntries(new FormData(this)),
$(this).ajaxSubmit({
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;

Check failure on line 60 in corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap3/crud_paginated_list.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

Expected '===' and instead saw '=='
});

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

self.allPages = ko.computed(function () {
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));
var last_ind = self.maxPage() + 1;

Check failure on line 91 in corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap3/crud_paginated_list.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

Identifier 'last_ind' is not in camel case
if (self.maxPage() <= 5 || self.currentPage() <= 3)
return _.range(1, Math.min(last_ind, 6));

Check failure on line 93 in corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap3/crud_paginated_list.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

Expected { after 'if' condition
if (self.currentPage() >= self.maxPage() - 2)
return _.range(self.maxPage() - 4, last_ind);

Check failure on line 95 in corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap3/crud_paginated_list.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

Expected { after 'if' condition
return _.range(self.currentPage() - 2, Math.min(last_ind, self.currentPage() + 3));
});

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

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

self.deleteItem = function (paginatedItem) {
self.deleteItem = function (paginatedItem, event) {

Check failure on line 200 in corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap3/crud_paginated_list.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'event' is defined but never used
var pList = self.paginatedList();
paginatedItem.dismissModals();
self.paginatedList(_(pList).without(paginatedItem));
Expand Down Expand Up @@ -247,10 +246,9 @@
return null;
};

self.initRow = function () {
self.initRow = function (rowElems, paginatedItem) {

Check failure on line 249 in corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap3/crud_paginated_list.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'rowElems' is defined but never used

Check failure on line 249 in corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap3/crud_paginated_list.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'paginatedItem' is defined but never used
// Intended to be overridden with additional initialization for
// each row in the paginated list.
// Arguments: rowElems, paginatedItem
};

return self;
Expand Down Expand Up @@ -298,12 +296,14 @@
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();
$.ajax({
method: 'POST',
data: Object.fromEntries(formData),
$updateForm.ajaxSubmit({
url: "",
type: 'post',
dataType: 'json',
data: {
action: 'update',
},
success: function (data) {
if (data.updatedItem) {
self.dismissModals();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 @@ -65,15 +66,11 @@ hqDefine('hqwebapp/js/bootstrap3/email-request', [
} else if (!self.isRequestReportSubmitting) {
self.$submitBtn.button('loading');
self.cancelBtnEnabled(false);
self.reportUrl(location.href);
self.isRequestReportSubmitting = true;
$.ajax({
method: "POST",
self.$formElement.ajaxSubmit({
type: "POST",
url: self.$formElement.attr('action'),
data: new FormData(self.$formElement.get(0)),
contentType: false,
processData: false,
enctype: 'multipart/form-data',
beforeSerialize: hqwebappRequestReportBeforeSerialize,
beforeSubmit: hqwebappRequestReportBeforeSubmit,
success: hqwebappRequestReportSucccess,
error: hqwebappRequestReportError,
});
Expand All @@ -87,7 +84,7 @@ hqDefine('hqwebapp/js/bootstrap3/email-request', [

self.resetForm = function () {
self.$formElement.find("button[type='submit']").button('reset');
self.$formElement.get(0).reset();
self.$formElement.resetForm();
self.cancelBtnEnabled(true);
self.$submitBtn.button('reset');
resetErrors();
Expand All @@ -109,6 +106,14 @@ 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;

Check failure on line 62 in corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap5/crud_paginated_list.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

Expected '===' and instead saw '=='
});

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

self.allPages = ko.computed(function () {
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));
var last_ind = self.maxPage() + 1;

Check failure on line 93 in corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap5/crud_paginated_list.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

Identifier 'last_ind' is not in camel case
if (self.maxPage() <= 5 || self.currentPage() <= 3)
return _.range(1, Math.min(last_ind, 6));

Check failure on line 95 in corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap5/crud_paginated_list.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

Expected { after 'if' condition
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));
});

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

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

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

return self;
Expand Down Expand Up @@ -296,12 +294,14 @@
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();
$.ajax({
method: 'POST',
data: Object.fromEntries(formData),
$updateForm.ajaxSubmit({
url: "",
type: 'post',
dataType: 'json',
data: {
action: 'update',
},
success: function (data) {
if (data.updatedItem) {
self.dismissModals();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
"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 8 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 @@ -68,15 +69,11 @@
} else if (!self.isRequestReportSubmitting) {
self.$submitBtn.changeButtonState('loading');
self.cancelBtnEnabled(false);
self.reportUrl(location.href);
self.isRequestReportSubmitting = true;
$.ajax({
method: "POST",
self.$formElement.ajaxSubmit({
type: "POST",
url: self.$formElement.attr('action'),
data: new FormData(self.$formElement.get(0)),
contentType: false,
processData: false,
enctype: 'multipart/form-data',
beforeSerialize: hqwebappRequestReportBeforeSerialize,
beforeSubmit: hqwebappRequestReportBeforeSubmit,
success: hqwebappRequestReportSucccess,
error: hqwebappRequestReportError,
});
Expand All @@ -90,7 +87,7 @@

self.resetForm = function () {
self.$formElement.find("button[type='submit']").changeButtonState('reset');
self.$formElement.get(0).reset();
self.$formElement.resetForm();
self.cancelBtnEnabled(true);
self.$submitBtn.changeButtonState('reset');
resetErrors();
Expand All @@ -112,6 +109,14 @@
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,6 +20,7 @@

<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,6 +5,7 @@
<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,6 +5,7 @@
<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,5 +1,6 @@
{% 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