Skip to content

Commit

Permalink
Merge pull request #33989 from dimagi/bmb/split-widgets-b5
Browse files Browse the repository at this point in the history
[B5] split widgets.js into bootstrap 3 and 5 versions
  • Loading branch information
biyeun committed Jan 19, 2024
2 parents 3854d79 + 31a28d0 commit 5ce2a44
Show file tree
Hide file tree
Showing 45 changed files with 176 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ hqDefine("app_manager/js/app_exchange", [
"jquery",
"knockout",
'analytix/js/kissmetrix',
"hqwebapp/js/widgets", // hqwebapp-select2 for versions
"hqwebapp/js/bootstrap3/widgets", // hqwebapp-select2 for versions
], function (
$,
ko,
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/app_manager/static/app_manager/js/app_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ hqDefine("app_manager/js/app_view", function () {
success: function (content) {
self.load_state('loaded');
self.multimedia_page_html(content);
hqImport("hqwebapp/js/widgets").init();
hqImport("hqwebapp/js/bootstrap3/widgets").init();
},
error: function (data) {
if (data.hasOwnProperty('responseJSON')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ hqDefine('app_manager/js/manage_releases_by_location', [
'hqwebapp/js/initial_page_data',
'hqwebapp/js/assert_properties',
'locations/js/search',
'hqwebapp/js/widgets', // using select2/dist/js/select2.full.min for ko-select2 on location select
'hqwebapp/js/bootstrap3/widgets', // using select2/dist/js/select2.full.min for ko-select2 on location select
'translations/js/app_translations',
], function (
$,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<script src="{% static "jsdiff/diff.js" %}"></script>
<script src="{% static 'app_manager/js/releases/app_diff.js' %}"></script>
<script src="{% static 'app_manager/js/releases/update_prompt.js' %}"></script>
<script src="{% static 'hqwebapp/js/widgets.js' %}"></script>
<script src="{% static 'hqwebapp/js/bootstrap3/widgets.js' %}"></script>
<script src="{% static 'app_manager/js/supported_languages.js' %}"></script>
<script src="{% static 'app_manager/js/settings/translations.js' %}"></script>
<script src="{% static 'app_manager/js/settings/password_setter.jquery.js' %}"></script>
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/case_importer/static/case_importer/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ hqDefine("case_importer/js/main", [
'hqwebapp/js/initial_page_data',
'case_importer/js/import_history',
'case_importer/js/excel_fields',
'hqwebapp/js/widgets',
'hqwebapp/js/bootstrap3/widgets',
], function (
$,
_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ hqDefine('commtrack/js/products_and_programs_main', [
'underscore',
'hqwebapp/js/initial_page_data',
'commtrack/js/base_list_view_model',
'hqwebapp/js/widgets', // "Additional Information" on product page uses a .hqwebapp-select2
'hqwebapp/js/bootstrap3/widgets', // "Additional Information" on product page uses a .hqwebapp-select2
], function (
$,
ko,
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/custom_data_fields/edit_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _make_field(self, field):
validators=[validator])
elif field.choices:
# If form uses knockout, knockout must have control over the select2.
# Otherwise, use .hqwebapp-select2 and hqwebapp/js/widgets to make the select2.
# Otherwise, use .hqwebapp-select2 and hqwebapp/js/bootstrap3/widgets to make the select2.
attrs = {
'data-placeholder': _('Select one'),
'data-allow-clear': 'true',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ hqDefine("data_interfaces/js/case_dedupe_main", [
'hqwebapp/js/initial_page_data',
'data_interfaces/js/case_property_input',
'data_interfaces/js/case_rule_criteria',
'hqwebapp/js/widgets',
'hqwebapp/js/bootstrap3/widgets',
], function (
$,
ko,
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/domain/static/domain/js/info_basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ hqDefine("domain/js/info_basic", [
'jquery',
'hqwebapp/js/select_2_ajax_widget', // for call center case owner
'select2/dist/js/select2.full.min',
'hqwebapp/js/widgets',
'hqwebapp/js/bootstrap3/widgets',
], function (
$
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
hqDefine('domain/js/internal_subscription_management', [
'jquery',
'knockout',
'hqwebapp/js/widgets',
'hqwebapp/js/bootstrap3/widgets',
], function (
$,
ko
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% load i18n %}
{% load hq_shared_tags %}

{% requirejs_main "hqwebapp/js/widgets" %}
{% requirejs_main "hqwebapp/js/bootstrap3/widgets" %}

{% block page_content %}
<p class="lead">
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/events/static/events/js/event_attendees.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ hqDefine("events/js/event_attendees",[
'hqwebapp/js/initial_page_data',
'jquery.rmi/jquery.rmi',
'locations/js/widgets',
"hqwebapp/js/widgets",
"hqwebapp/js/bootstrap3/widgets",
"hqwebapp/js/bootstrap3/components.ko", // for pagination
], function (
$,
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/events/static/events/js/new_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ hqDefine("events/js/new_event", [
"hqwebapp/js/multiselect_utils",
"hqwebapp/js/initial_page_data",
"locations/js/widgets",
"hqwebapp/js/widgets",
"hqwebapp/js/bootstrap3/widgets",
"jquery-ui/ui/widgets/datepicker",
], function (
$,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{% block js %}{{ block.super }}
{% compress js %}
<script src="{% static 'hqwebapp/js/widgets.js' %}"></script>
<script src="{% static 'hqwebapp/js/bootstrap3/widgets.js' %}"></script>
{% endcompress js %}
{% endblock js %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{% block js %}{{ block.super }}
{% compress js %}
<script src="{% static 'hqwebapp/js/widgets.js' %}"></script>
<script src="{% static 'hqwebapp/js/bootstrap3/widgets.js' %}"></script>
<script src="{% static 'app_manager/js/widgets.js' %}"></script>
{% endcompress js %}
{% endblock js %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
hqDefine("hqwebapp/js/widgets",[
hqDefine("hqwebapp/js/bootstrap3/widgets",[
'jquery',
'underscore',
'@mapbox/mapbox-gl-geocoder/dist/mapbox-gl-geocoder.min',
Expand Down
125 changes: 125 additions & 0 deletions corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap5/widgets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
hqDefine("hqwebapp/js/bootstrap5/widgets",[
'jquery',
'underscore',
'@mapbox/mapbox-gl-geocoder/dist/mapbox-gl-geocoder.min',
'hqwebapp/js/initial_page_data',
'select2/dist/js/select2.full.min',
'jquery-ui/ui/widgets/datepicker',
], function ($, _, MapboxGeocoder, initialPageData) {
var init = function () {
var MAPBOX_ACCESS_TOKEN = initialPageData.get(
"mapbox_access_token"
);
// .hqwebapp-select2 is a basic select2-based dropdown or multiselect
_.each($(".hqwebapp-select2"), function (element) {
$(element).select2({
width: '100%',
});
if (window.USE_BOOTSTRAP5 && $(element).hasClass('is-invalid')) {
$(element).data('select2').$container.addClass('is-invalid');
}
if (window.USE_BOOTSTRAP5 && $(element).hasClass('is-valid')) {
$(element).data('select2').$container.addClass('is-valid');
}
});

// .hqwebapp-autocomplete also allows for free text entry
_.each($(".hqwebapp-autocomplete"), function (input) {
var $input = $(input);
$input.select2({
multiple: true,
tags: true,
width: '100%',
});
});

_.each($(".hqwebapp-autocomplete-email"), function (input) {
var $input = $(input);
$input.select2({
multiple: true,
placeholder: ' ',
tags: true,
tokenSeparators: [','],
width: '100%',
createTag: function (params) {
// Support pasting in comma-separated values
var terms = parseEmails(params.term);
if (terms.length === 1) {
return {
id: terms[0],
text: terms[0],
};
}
$input.select2('close');
var values = $input.val() || [];
if (!_.isArray(values)) {
values = [values];
}
_.each(terms, function (term) {
if (!_.contains(values, term)) {
$input.append(new Option(term, term));
values.push(term);
}
});
$input.val(values).trigger("change");

return null;
},
});
});

_.each($(".geocoder-proximity"), function (input) {
var $input = $(input).find('input');

function getGeocoderItem(item) {
var inputEl = $input;
var geoObj = {};
geoObj.place_name = item.place_name;
geoObj.coordinates = {
longitude: item.geometry.coordinates[0],
latitude: item.geometry.coordinates[1],
};
inputEl.attr("value", JSON.stringify(geoObj));
return item.place_name;
}

function getGeocoderValue() {
var geocoderValue = $input.val();
if (geocoderValue) {
geocoderValue = JSON.parse(geocoderValue);
return geocoderValue.place_name;
}
return null;
}

var geocoder = new MapboxGeocoder({
accessToken: MAPBOX_ACCESS_TOKEN,
types:
"country,region,place,postcode,locality,neighborhood",
getItemValue: getGeocoderItem,
});

geocoder.addTo(".geocoder-proximity");
var geocoderValue = getGeocoderValue();
if (geocoderValue) {
geocoder.setInput(getGeocoderValue());
}
});

$('.date-picker').datepicker({ dateFormat: "yy-mm-dd" });
};

var parseEmails = function (input) {
return $.trim(input).split(/[, ]\s*/);
};

$(function () {
init();
});

return {
init: init,
parseEmails: parseEmails, // export for testing
};
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ hqDefine("hqwebapp/js/maintenance_alerts",[
'jquery',
'knockout',
'hqwebapp/js/initial_page_data',
'hqwebapp/js/widgets',
'hqwebapp/js/bootstrap3/widgets',
], function ($, ko, initialPageData) {
$(function () {
var alertFormModel = {
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/hqwebapp/static/hqwebapp/spec/widgets_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env mocha */
hqDefine("hqwebapp/spec/widgets_spec", [
'hqwebapp/js/widgets',
'hqwebapp/js/bootstrap3/widgets',
], function (
widgets
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
+++
@@ -1,4 +1,4 @@
-hqDefine("hqwebapp/js/bootstrap3/widgets",[
+hqDefine("hqwebapp/js/bootstrap5/widgets",[
'jquery',
'underscore',
'@mapbox/mapbox-gl-geocoder/dist/mapbox-gl-geocoder.min',
2 changes: 1 addition & 1 deletion corehq/apps/locations/static/locations/js/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ hqDefine("locations/js/location", [
'locations/js/location_drilldown',
'locations/js/location_tree',
'hqwebapp/js/select_2_ajax_widget',
'hqwebapp/js/widgets', // custom data fields use a .hqwebapp-select2
'hqwebapp/js/bootstrap3/widgets', // custom data fields use a .hqwebapp-select2
'locations/js/widgets',
], function (
$,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ hqDefine("reminders/js/reminders.keywords.ko", [
"jquery",
"knockout",
"hqwebapp/js/initial_page_data",
"hqwebapp/js/widgets", // .hqwebapp-select2 for survey dropdown
"hqwebapp/js/bootstrap3/widgets", // .hqwebapp-select2 for survey dropdown
], function (
$,
ko,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ hqDefine("reports/js/edit_scheduled_report", [
"hqwebapp/js/initial_page_data",
"hqwebapp/js/toggles",
"hqwebapp/js/multiselect_utils",
"hqwebapp/js/widgets", // autocomplete widget for email recipient list
"hqwebapp/js/bootstrap3/widgets", // autocomplete widget for email recipient list
"jquery-ui/ui/widgets/datepicker",
'hqwebapp/js/bootstrap3/components.ko', // select toggle widget
], function (
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/reports/static/reports/js/hq_report.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ hqDefine("reports/js/hq_report", [
'hqwebapp/js/bootstrap3/alert_user',
'analytix/js/kissmetrix',
'hqwebapp/js/initial_page_data',
'hqwebapp/js/widgets', //multi-emails
'hqwebapp/js/bootstrap3/widgets', //multi-emails
], function (
$,
ko,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<script src="{% static 'reports/js/project_health_dashboard.js' %}"></script>
<script src="{% static 'reports/js/aggregate_user_status.js' %}"></script>
<script src="{% static 'reports/js/user_history.js' %}"></script>
<script src="{% static 'hqwebapp/js/widgets.js' %}"></script>
<script src="{% static 'hqwebapp/js/bootstrap3/widgets.js' %}"></script>
{% endcompress %}
{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/settings/static/settings/js/user_api_keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ hqDefine("settings/js/user_api_keys", [
'underscore',
"hqwebapp/js/initial_page_data",
"hqwebapp/js/bootstrap3/crud_paginated_list",
'hqwebapp/js/widgets',
'hqwebapp/js/bootstrap3/widgets',
], function (
$,
ko,
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/sms/static/sms/js/gateway_list.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
hqDefine("sms/js/gateway_list", [
"hqwebapp/js/bootstrap3/crud_paginated_list_init",
"hqwebapp/js/widgets",
"hqwebapp/js/bootstrap3/widgets",
], function () {
// No page-specific logic, just need to collect the dependencies above
});
2 changes: 1 addition & 1 deletion corehq/apps/sms/static/sms/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ hqDefine("sms/js/settings", [
'hqwebapp/js/select2_handler',
'hqwebapp/js/bootstrap3/components.ko', // select toggle widget
'bootstrap-timepicker/js/bootstrap-timepicker',
'hqwebapp/js/widgets', //multi-emails
'hqwebapp/js/bootstrap3/widgets', //multi-emails
], function(
$,
ko,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ hqDefine("smsbillables/js/smsbillables.rate_calc", [
'knockout',
'underscore',
'hqwebapp/js/select2_handler',
'hqwebapp/js/widgets', // the public sms page uses a .hqwebapp-select2 for country input
'hqwebapp/js/bootstrap3/widgets', // the public sms page uses a .hqwebapp-select2 for country input
], function (
$,
ko,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
{% compress js %}
<script src="{% static 'select2/dist/js/select2.full.min.js' %}"></script>
<script src="{% static 'hqwebapp/js/select2_knockout_bindings.ko.js' %}"></script>
<script src="{% static 'hqwebapp/js/widgets.js' %}"></script>
<script src="{% static 'hqwebapp/js/bootstrap3/widgets.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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ hqDefine("translations/js/app_translations", [
"underscore",
"hqwebapp/js/initial_page_data",
"app_manager/js/widgets",
"hqwebapp/js/widgets", // .hqwebapp-select2
"hqwebapp/js/bootstrap3/widgets", // .hqwebapp-select2
], function (
$,
_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% load hq_shared_tags %}
{% load i18n %}

{% requirejs_main "hqwebapp/js/widgets" %}
{% requirejs_main "hqwebapp/js/bootstrap3/widgets" %}

{% block page_content %}
<div id="blacklist-trans-form" class="tab-pane">
Expand Down

0 comments on commit 5ce2a44

Please sign in to comment.