-
-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33989 from dimagi/bmb/split-widgets-b5
[B5] split widgets.js into bootstrap 3 and 5 versions
- Loading branch information
Showing
45 changed files
with
176 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
corehq/apps/domain/static/domain/js/internal_subscription_management.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ps/hqwebapp/static/hqwebapp/js/widgets.js → .../static/hqwebapp/js/bootstrap3/widgets.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap5/widgets.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
corehq/apps/hqwebapp/tests/data/bootstrap5_diffs/javascript/hqwebapp/widgets.js.diff.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.