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

[webpack] Multiselect pages #35413

Merged
merged 11 commits into from
Nov 22, 2024
1 change: 1 addition & 0 deletions corehq/apps/events/static/events/js/new_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"locations/js/widgets",
"hqwebapp/js/bootstrap3/widgets",
"jquery-ui/ui/widgets/datepicker",
"commcarehq",
], function (
$,
ko,
Expand Down Expand Up @@ -40,7 +41,7 @@
multiselectUtils.createFullMultiselectWidget('id_attendance_takers', ATTENDANCE_TAKER_PROPS);

function eventViewModel(initialData) {
'use strict';

Check warning on line 44 in corehq/apps/events/static/events/js/new_event.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'use strict' is unnecessary inside of modules
var self = {};

// Disable the submit button unless attendance takers are present
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/events/templates/events/new_event.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% load crispy_forms_tags %}
{% load i18n %}

{% requirejs_main 'events/js/new_event' %}
{% js_entry_b3 'events/js/new_event' %}

{% block page_content %}
{% initial_page_data 'current_values' form.current_values %}
Expand Down
32 changes: 19 additions & 13 deletions corehq/apps/hqwebapp/static/hqwebapp/js/multiselect_utils.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"use strict";

Check warning on line 1 in corehq/apps/hqwebapp/static/hqwebapp/js/multiselect_utils.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'use strict' is unnecessary inside of modules
hqDefine('hqwebapp/js/multiselect_utils', [
"jquery",
"knockout",
"underscore",
"hqwebapp/js/assert_properties",
"multiselect/js/jquery.multi-select",
"quicksearch/dist/jquery.quicksearch.min",
], function (
$,
ko,
Expand Down Expand Up @@ -100,15 +99,28 @@
selectableSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selectable:not(.ms-selected)',
selectionSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selection.ms-selected';

that.search_left = $selectableSearch.quicksearch(selectableSearchString)
const _search = function (query, itemSelector) {
$(itemSelector).each(function (index, item) {
const $item = $(item);
if (!query || $item.text().indexOf(query) !== -1) {
$item.removeClass(window.USE_BOOTSTRAP5 ? "d-none" : "hide");
} else {
$item.addClass(window.USE_BOOTSTRAP5 ? "d-none" : "hide");
}
});
};

that.search_left = $selectableSearch
.on('keydown', function (e) {
if (e.which === 40) { // down arrow, was recommended by loudev docs
that.$selectableUl.focus();
return false;
}
})
.on('keyup change search input', function () {
// disable add all functionality so that user is not confused
_search($selectableSearch.val(), selectableSearchString);

// disable add all functionality so that user is not confused
if (that.search_left.val().length > 0) {
$('#' + selectAllId).addClass('disabled').prop('disabled', true);
} else {
Expand All @@ -118,15 +130,17 @@
}
});

that.search_right = $selectionSearch.quicksearch(selectionSearchString)
that.search_right = $selectionSearch
.on('keydown', function (e) {
if (e.which === 40) { // down arrow, was recommended by loudev docs
that.$selectionUl.focus();
return false;
}
})
.on('keyup change search input', function () {
// disable remove all functionality so that user is not confused
_search($selectionSearch.val(), selectionSearchString);

// disable remove all functionality so that user is not confused
if (that.search_right.val().length > 0) {
$('#' + removeAllId).addClass('disabled').prop('disabled', true);
} else if (!disableModifyAllActions) {
Expand All @@ -135,22 +149,14 @@
});
},
afterSelect: function () {
this.search_left.cache();
// remove search option so that user doesn't get confused
this.search_right.val('').search('');
if (!disableModifyAllActions) {
$('#' + removeAllId).removeClass('disabled').prop('disabled', false);
}
this.search_right.cache();
},
afterDeselect: function () {
// remove search option so that user doesn't get confused
this.search_left.val('').search('');
if (!disableModifyAllActions) {
$('#' + selectAllId).removeClass('disabled').prop('disabled', false);
}
this.search_left.cache();
this.search_right.cache();
},
});

Expand Down
1 change: 0 additions & 1 deletion corehq/apps/hqwebapp/templates/hqwebapp/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@
{% if request.use_multiselect and not use_js_bundler %}
{% compress js %}
<script src="{% static 'multiselect/js/jquery.multi-select.js' %}"></script>
<script src="{% static 'quicksearch/dist/jquery.quicksearch.min.js' %}"></script>
<script src="{% static 'hqwebapp/js/multiselect_utils.js' %}"></script>
{% endcompress %}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
+ "hqwebapp/js/bootstrap5/widgets", // autocomplete widget for email recipient list
"jquery-ui/ui/widgets/datepicker",
'hqwebapp/js/components/select_toggle',
], function (
"commcarehq",
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
{% load i18n %}


-{% requirejs_main 'reports/js/bootstrap3/edit_scheduled_report' %}
+{% requirejs_main_b5 'reports/js/bootstrap5/edit_scheduled_report' %}
-{% js_entry_b3 'reports/js/bootstrap3/edit_scheduled_report' %}
+{% js_entry 'reports/js/bootstrap5/edit_scheduled_report' %}

{% block page_content %}
{% initial_page_data 'is_configurable_map' is_configurable_map %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ hqDefine("linked_domain/js/domain_links", [
'hqwebapp/js/components/pagination',
'hqwebapp/js/components/search_box',
'hqwebapp/js/select2_knockout_bindings.ko', // selects2 for fields
'commcarehq',
], function (
RMI,
initialPageData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% load hq_shared_tags %}
{% load i18n %}

{% requirejs_main "linked_domain/js/domain_links" %}
{% js_entry_b3 "linked_domain/js/domain_links" %}

{% block additional_initial_page_data %}
{% initial_analytics_data 'appcues.linked_status' linked_status %}
Expand Down
1 change: 1 addition & 0 deletions corehq/apps/registry/static/registry/js/registry_edit.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/registry/static/registry/js/registry_edit.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'use strict' is unnecessary inside of modules
hqDefine("registry/js/registry_edit", [
'moment',
'knockout',
Expand All @@ -13,6 +13,7 @@
'hqwebapp/js/bootstrap5/main', // makeHqHelp
'hqwebapp/js/multiselect_utils',
'hqwebapp/js/components/inline_edit',
'commcarehq',
], function (
moment,
ko,
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/registry/templates/registry/registry_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% endcompress %}
{% endblock %}

{% requirejs_main_b5 'registry/js/registry_edit' %}
{% js_entry 'registry/js/registry_edit' %}

{% block page_content %}
{% initial_page_data "registry" registry %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ hqDefine("reports/js/bootstrap3/edit_scheduled_report", [
"hqwebapp/js/bootstrap3/widgets", // autocomplete widget for email recipient list
"jquery-ui/ui/widgets/datepicker",
'hqwebapp/js/components/select_toggle',
"commcarehq",
], function (
$,
_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ hqDefine("reports/js/bootstrap5/edit_scheduled_report", [
"hqwebapp/js/bootstrap5/widgets", // autocomplete widget for email recipient list
"jquery-ui/ui/widgets/datepicker",
'hqwebapp/js/components/select_toggle',
"commcarehq",
], function (
$,
_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% load i18n %}


{% requirejs_main 'reports/js/bootstrap3/edit_scheduled_report' %}
{% js_entry_b3 'reports/js/bootstrap3/edit_scheduled_report' %}

{% block page_content %}
{% initial_page_data 'is_configurable_map' is_configurable_map %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% load i18n %}


{% requirejs_main_b5 'reports/js/bootstrap5/edit_scheduled_report' %}
{% js_entry 'reports/js/bootstrap5/edit_scheduled_report' %}

{% block page_content %}
{% initial_page_data 'is_configurable_map' is_configurable_map %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<script src="{% static 'hqwebapp/js/bootstrap3/widgets.js' %}"></script>
<script src="{% static 'hqwebapp/js/bootstrap3/main.js' %}"></script>
<script src="{% static 'multiselect/js/jquery.multi-select.js' %}"></script>
<script src="{% static 'quicksearch/dist/jquery.quicksearch.min.js' %}"></script>
<script src="{% static 'hqwebapp/js/multiselect_utils.js' %}"></script>
{% endcompress %}
</head>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ <h6>Quick Links</h6>
<script src="{% static 'hqwebapp/js/bootstrap5/main.js' %}"></script>
<script src="{% static 'hqwebapp/js/select_2_ajax_widget.js' %}"></script>
<script src="{% static 'multiselect/js/jquery.multi-select.js' %}"></script>
<script src="{% static 'quicksearch/dist/jquery.quicksearch.min.js' %}"></script>
<script src="{% static 'hqwebapp/js/multiselect_utils.js' %}"></script>
<script src="{% static 'ace-builds/src-min-noconflict/ace.js' %}"></script>
<script src="{% static 'ace-builds/src-min-noconflict/mode-python.js' %}"></script>
Expand Down
1 change: 1 addition & 0 deletions corehq/apps/users/static/users/js/edit_commcare_user.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/users/static/users/js/edit_commcare_user.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'use strict' is unnecessary inside of modules

hqDefine('users/js/edit_commcare_user', [
'jquery',
Expand All @@ -15,6 +15,7 @@
'registration/js/bootstrap3/password',
'select2/dist/js/select2.full.min',
'eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min',
'commcarehq',
], function (
$,
ko,
Expand Down
1 change: 1 addition & 0 deletions corehq/apps/users/static/users/js/edit_web_user.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict';

Check warning on line 1 in corehq/apps/users/static/users/js/edit_web_user.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'use strict' is unnecessary inside of modules

hqDefine('users/js/edit_web_user', [
'jquery',
'hqwebapp/js/initial_page_data',
'users/js/custom_data_fields',
'locations/js/widgets',
'commcarehq',
], function (
$,
initialPageData,
Expand Down
1 change: 1 addition & 0 deletions corehq/apps/users/static/users/js/filtered_download.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ hqDefine('users/js/filtered_download', [
'locations/js/widgets', // location search
'hqwebapp/js/components/select_toggle',
'hqwebapp/js/bootstrap3/knockout_bindings.ko', // slideVisible binding
'commcarehq',
], function (
$,
ko,
Expand Down
5 changes: 2 additions & 3 deletions corehq/apps/users/static/users/js/invite_web_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
'knockout',
'hqwebapp/js/initial_page_data',
'users/js/custom_data_fields',
'hqwebapp/js/toggles',
'hqwebapp/js/bootstrap3/validators.ko',
'locations/js/widgets',
'commcarehq',
], function (
$,
ko,
initialPageData,
customDataFields,
toggles
customDataFields
) {
'use strict';

Check warning on line 15 in corehq/apps/users/static/users/js/invite_web_user.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'use strict' is unnecessary inside of modules

var inviteWebUserFormHandler = function () {
var self = {},
Expand Down
1 change: 1 addition & 0 deletions corehq/apps/users/static/users/js/mobile_workers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* as well as a minimum length requirment (the length is configurable).
* - If any validation is being used, we automatically generate a suggested password that passes validation.
*/
'use strict';

Check warning on line 18 in corehq/apps/users/static/users/js/mobile_workers.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'use strict' is unnecessary inside of modules

hqDefine("users/js/mobile_workers",[
'jquery',
Expand All @@ -32,6 +32,7 @@
'hqwebapp/js/components/search_box',
'hqwebapp/js/bootstrap3/validators.ko', // email address validation
'eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min',
'commcarehq',
], function (
$,
ko,
Expand All @@ -44,7 +45,7 @@
locationsWidgets,
customDataFields
) {
'use strict';

Check warning on line 48 in corehq/apps/users/static/users/js/mobile_workers.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'use strict' is unnecessary inside of modules
// These are used as css classes, so the values of success/warning/error need to be what they are.
var STATUS = {
NONE: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% load hq_shared_tags %}
{% load i18n %}

{% requirejs_main 'users/js/edit_commcare_user' %}
{% js_entry_b3 'users/js/edit_commcare_user' %}

{% block page_content %}
{% initial_page_data "couch_user_id" couch_user.user_id %}
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/users/templates/users/edit_web_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% load hq_shared_tags %}
{% load i18n %}

{% requirejs_main 'users/js/edit_web_user' %}
{% js_entry_b3 'users/js/edit_web_user' %}

{% block page_content %}
{% initial_page_data 'can_edit_original_profile' can_edit_original_profile %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% load i18n %}
{% load crispy_forms_tags %}

{% requirejs_main 'users/js/filtered_download' %}
{% js_entry_b3 'users/js/filtered_download' %}

{% block page_content %}
{% initial_page_data 'count_users_url' count_users_url %}
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/users/templates/users/invite_web_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% load crispy_forms_tags %}
{% load i18n %}

{% requirejs_main 'users/js/invite_web_user' %}
{% js_entry_b3 'users/js/invite_web_user' %}

{% block page_content %}
{% initial_page_data 'custom_fields_slugs' custom_fields_slugs %}
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/users/templates/users/mobile_workers.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% load hq_shared_tags %}
{% load crispy_forms_tags %}

{% requirejs_main 'users/js/mobile_workers' %}
{% js_entry_b3 'users/js/mobile_workers' %}

{% block page_content %}
{% initial_page_data 'can_access_all_locations' can_access_all_locations %}
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
"nprogress": "0.2.0",
"nvd3": "1.1.10",
"nvd3-1.8.6": "npm:nvd3#1.8.6",
"quicksearch": "DeuxHuitHuit/quicksearch#2.2.1",
"requirejs": "2.3.7",
"requirejs-babel7": "^1.3.2",
"select2": "4.1.0-rc.0",
Expand Down
1 change: 1 addition & 0 deletions webpack/webpack.b3.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = Object.assign({}, commonDefault, {
new webpack.ProvidePlugin({
'$': 'jquery',
'jQuery': 'jquery', // needed for bootstrap 3 to work
'window.jQuery': 'jquery',
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean webpack is making jQuery globally available? Why is it needed? Would it make sense to add a comment here about that?

Is it possibly related to quicksearch, which is removed in a later commit in this PR?

The same applies to webpack/webpack.common.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it does. The two previous lines do something pretty similar by automatically importing jQuery everywhere. It's needed because the multiselect library expects window.jQuery: https://github.com/lou/multi-select/blob/57fb8d3f5d27a0e1058f63921cdb26b4d30da361/js/jquery.multi-select.js#L544

}),
new hqPlugins.EntryChunksPlugin({
filename: 'manifest_b3.json',
Expand Down
1 change: 1 addition & 0 deletions webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ module.exports = {
new webpack.ProvidePlugin({
'$': 'jquery',
'jQuery': 'jquery', // needed for bootstrap to work
'window.jQuery': 'jquery',
}),
new hqPlugins.EntryChunksPlugin(),
],
Expand Down
Loading
Loading