{"version":3,"file":"charity_search-DzioyGjh.js","sources":["../../../app/assets/javascripts/stimulus_controllers/donations/helpers.js","../../../app/assets/javascripts/page_includes/charity_search.js"],"sourcesContent":["export const selectedCustomDonationOptions = (customDonationInput) => {\n return [...customDonationInput.options].filter((x) => x.selected)\n}\n\nexport const selectedCauses = (containerElement) => {\n const checkedCauseInputs = containerElement.querySelectorAll('input.checkbox-cause:checked')\n\n return [...checkedCauseInputs]\n}\n\nexport const formatDropdown = (obj) => {\n // Handle Searching... placeholder or user-input tag\n if (obj.loading || obj.newTag) {\n return obj.text\n // Format group headers\n } else if (obj.children) {\n return `${obj.text} (${obj.children.length}) ${generateFlag(obj.countryCode)}`\n } else {\n return generateFormattedOptionText(obj.charity, formattedCharityNumber(obj))\n }\n}\n\nexport const formatUsOnlyDropdown = (obj) => {\n // Handle Searching... placeholder\n if (obj.loading) {\n return obj.text\n } else {\n let charity = obj.charity\n\n const charity_number = charity.ein ? `EIN: ${charity.ein}` : false\n\n let formattedOptionText = generateFormattedOptionText(charity, charity_number)\n\n return formattedOptionText\n }\n}\n\nexport const generateFlag = (countryCode) => {\n // Flag emojis are the combination of Unicode characters for each letter of a two-digit country code\n // This splits the letters to get the codes and then joins them\n return countryCode\n .split('')\n .map((letter) => {\n return String.fromCodePoint(letter.toLowerCase().charCodeAt() + 127365)\n })\n .join('')\n}\n\nexport const formatSelection = (obj) => {\n // This is hacky and can probably be refactored, but\n // storing country code under \"title\" because that\n // key persists when chips pass back through formatting\n return `${obj.text} ${generateFlag(obj.title)}`\n}\n\nexport const formatOPDSelection = (obj) => {\n if (!isNaN(obj.id) && obj.text != 'Search by charity names' && obj.charity) {\n // filter(Boolean) removes any elements in the array that are falsey\n return [obj.text, formattedCharityNumber(obj)].filter(Boolean).join(' - ')\n } else {\n return `${obj.text}`\n }\n}\n\n// Handling Charity Search Inputs\n// If no countries are selected, rather than disable the charity search\n// (which prevents a user from removing already-selected charities),\n// we'll give a search length of Infinity so a search is never initiated\n// and the dropdown message to select a country remains. Otherwise,\n// searches including \"US\" require three characters, and all other searches\n// require no typeahead.\nexport const inputLength = (countries) => {\n if (!countries.length) {\n return Infinity\n } else if (countries.some((el) => el.id === 'US')) {\n return 3\n } else {\n return 0\n }\n}\n\nfunction generateFormattedOptionText(charity, charity_number) {\n // Create an array with unique values from charity city and state, then filter out\n // any null values and separate multiple values with a comma\n const location = [...new Set([charity.city, charity.state])].filter(Boolean).join(', ')\n return [charity.name, location, charity_number].filter(Boolean).join(' - ')\n}\n\nfunction formattedCharityNumber(obj) {\n let charity = obj.charity\n // Since some GG charities are returned without an ein or registered_charity_number,\n // check for valid values and exclude 'charity no.' if none present\n return charity.ein || charity.registered_charity_number\n ? `charity no. ${charity.ein || charity.registered_charity_number}`\n : false\n}\n","import { formatUsOnlyDropdown } from '@/javascripts/stimulus_controllers/donations/helpers'\n// Currently, default options for a single-charity US-only Select2 Search\n// Used in US Off Portal Volunteering Log Modal and as starting option\n// for Donation Global Giving Search and Off Portal Donation Upload\nlet select2Defaults = {\n escapeMarkup(markup) {\n return markup\n },\n closeOnSelect: true,\n placeholder: 'Search by charity names',\n minimumInputLength: 3,\n templateResult: formatUsOnlyDropdown,\n ajax: {\n url: '/charities/search',\n dataType: 'json',\n delay: 250,\n language: {\n inputTooShort: function () {\n return 'Please enter at least 3 or more characters'\n }\n },\n data({ term }) {\n return {\n charity_name: term,\n countries: ['US']\n }\n },\n processResults(data) {\n return {\n results: data['US'].map((charity) => {\n return {\n id: charity.id,\n text: `${charity.name} (EIN: ${charity.ein})`,\n title: 'US',\n charity: charity\n }\n })\n }\n },\n cache: true\n }\n}\n\ndocument.addEventListener('DOMContentLoaded', () => {\n // Initialize Select2 in modals\n $('.volunteer-log-charity-select').select2({\n ...select2Defaults,\n dropdownParent: $('#offportal-usa-volunteer-modal')\n })\n\n // The below pages offer a country select, but since we always load with\n // US selected as a default, we can initialize with US-centric settings from above\n // And update via stimulus controller if the user changes countries\n})\n"],"names":["selectedCustomDonationOptions","customDonationInput","x","selectedCauses","containerElement","formatDropdown","obj","generateFlag","generateFormattedOptionText","formattedCharityNumber","formatUsOnlyDropdown","charity","charity_number","countryCode","letter","formatSelection","formatOPDSelection","inputLength","countries","el","location","select2Defaults","markup","term","data"],"mappings":"AAAY,MAACA,EAAiCC,GACrC,CAAC,GAAGA,EAAoB,OAAO,EAAE,OAAQC,GAAMA,EAAE,QAAQ,EAGrDC,EAAkBC,GAGtB,CAAC,GAFmBA,EAAiB,iBAAiB,8BAA8B,CAE9D,EAGlBC,EAAkBC,GAEzBA,EAAI,SAAWA,EAAI,OACdA,EAAI,KAEFA,EAAI,SACN,GAAGA,EAAI,IAAI,KAAKA,EAAI,SAAS,MAAM,KAAKC,EAAaD,EAAI,WAAW,CAAC,GAErEE,EAA4BF,EAAI,QAASG,EAAuBH,CAAG,CAAC,EAIlEI,EAAwBJ,GAAQ,CAE3C,GAAIA,EAAI,QACN,OAAOA,EAAI,KACN,CACL,IAAIK,EAAUL,EAAI,QAElB,MAAMM,EAAiBD,EAAQ,IAAM,QAAQA,EAAQ,GAAG,GAAK,GAI7D,OAF0BH,EAA4BG,EAASC,CAAc,CAGjF,CACA,EAEaL,EAAgBM,GAGpBA,EACJ,MAAM,EAAE,EACR,IAAKC,GACG,OAAO,cAAcA,EAAO,YAAa,EAAC,WAAU,EAAK,MAAM,CACvE,EACA,KAAK,EAAE,EAGCC,EAAmBT,GAIvB,GAAGA,EAAI,IAAI,IAAIC,EAAaD,EAAI,KAAK,CAAC,GAGlCU,EAAsBV,GAC7B,CAAC,MAAMA,EAAI,EAAE,GAAKA,EAAI,MAAQ,2BAA6BA,EAAI,QAE1D,CAACA,EAAI,KAAMG,EAAuBH,CAAG,CAAC,EAAE,OAAO,OAAO,EAAE,KAAK,KAAK,EAElE,GAAGA,EAAI,IAAI,GAWTW,EAAeC,GACrBA,EAAU,OAEJA,EAAU,KAAMC,GAAOA,EAAG,KAAO,IAAI,EACvC,EAEA,EAJA,IAQX,SAASX,EAA4BG,EAASC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