{
"version": 3,
"sources": ["../../../../../../../src/js/i18n/datepicker/jquery.ui.datepicker-nl.js", "../../../../../../../src/js/lib/gettext.js", "../../../../../../../src/js/i18n/nl.js", "../../../../../../../src/js/lib/polyfills/url-search-params.js", "../../../../../../../src/js/lib/text-utils.js", "../../../../../../../src/js/lib/errors.js", "../../../../../../../src/js/lib/collect-values.js", "../../../../../../../src/js/lib/vars.js", "../../../../../../../src/js/lib/case-exit.js", "../../../../../../../src/js/lib/a11y.js", "../../../../../../../src/js/lib/escape.js", "../../../../../../../src/js/lib/notify.js", "../../../../../../../src/js/lib/conf.js", "../../../../../../../src/js/lib/location.js", "../../../../../../../src/js/lib/ajax.js", "../../../../../../../src/js/lib/settled.js", "../../../../../../../src/js/lib/bbi.js", "../../../../../../../src/js/lib/control-helpers.js", "../../../../../../../src/js/lib/quotable.js", "../../../../../../../src/js/lib/dates.js", "../../../../../../../src/js/lib/feature-queries.js", "../../../../../../../src/js/lib/form-widgets.js", "../../../../../../../src/js/lib/dynprops.js", "../../../../../../../src/js/lib/hooks.js", "../../../../../../../src/js/lib/control.js", "../../../../../../../src/js/lib/types.js", "../../../../../../../src/js/lib/control-validation.js", "../../../../../../../src/js/lib/groupings.js", "../../../../../../../src/js/lib/font-classes.js", "../../../../../../../src/js/lib/names.js", "../../../../../../../src/js/lib/form-groups.js", "../../../../../../../src/js/lib/form-widgets-definitions.js", "../../../../../../../src/js/lib/numerals.js", "../../../../../../../src/js/lib/url-utils.js", "../../../../../../../src/js/lib/utils.js", "../../../../../../../src/js/lib/jumplist.js", "../../../../../../../src/js/lib/user-info.js", "../../../../../../../src/js/lib/permissions.js", "../../../../../../../src/js/lib/$.scrollTo.js", "../../../../../../../src/js/json.js", "../../../../../../../src/plugins/a11y-describedby/a11y-describedby.js", "../../../../../../../src/plugins/asterisk/asterisk.js", "../../../../../../../src/plugins/auto-next-when-only-radio/auto-next-when-only-radio.js", "../../../../../../../src/plugins/bb-xarea/bb-xarea.js", "../../../../../../../src/custom/pvdb/plugins/dialog/dialog.js", "../../../../../../../src/plugins/grid-rowspan/grid-rowspan.js", "../../../../../../../src/plugins/has-no-next/has-no-next.js", "../../../../../../../src/plugins/has-required/has-required.js", "../../../../../../../src/plugins/heading2-3/heading2-3.js", "../../../../../../../src/custom/pvdb/plugins/high-on-info-ng/high-on-info-ng.js", "../../../../../../../src/plugins/history/history.js", "../../../../../../../src/plugins/mustache/mustache.js", "../../../../../../../src/plugins/showdown/showdown.js", "../../../../../../../src/plugins/showdown-converter/showdown-converter.js", "../../../../../../../src/plugins/info-template/info-template.js", "../../../../../../../src/plugins/jquery.xarea/jquery.xarea.js", "../../../../../../../src/plugins/md-labels/md-labels.js", "../../../../../../../src/plugins/model-filter/model-filter.js", "../../../../../../../src/plugins/modelitem/modelitem.js", "../../../../../../../src/plugins/optional/optional.js", "../../../../../../../src/plugins/progressbar/progressbar.js", "../../../../../../../src/plugins/questionlabelgroup-ng/questionlabelgroup-ng.js", "../../../../../../../src/custom/pvdb/plugins/questionlabelgroup-wrapping-input/questionlabelgroup-wrapping-input.js", "../../../../../../../src/plugins/reset-password/reset-password.js", "../../../../../../../src/plugins/selected-model/selected-model.js", "../../../../../../../src/plugins/show-server-side-validation/show-server-side-validation.js"],
"sourcesContent": ["/* Dutch (UTF-8) initialisation for the jQuery UI date picker plugin. */\n/* Written by Mathias Bynens */\njQuery(function($){\n\t$.datepicker.regional.nl = {\n\t\tcloseText: 'Sluiten',\n\t\tprevText: '\u2190',\n\t\tnextText: '\u2192',\n\t\tcurrentText: 'Vandaag',\n\t\tmonthNames: ['januari', 'februari', 'maart', 'april', 'mei', 'juni',\n\t\t'juli', 'augustus', 'september', 'oktober', 'november', 'december'],\n\t\tmonthNamesShort: ['jan', 'feb', 'mrt', 'apr', 'mei', 'jun',\n\t\t'jul', 'aug', 'sep', 'okt', 'nov', 'dec'],\n\t\tdayNames: ['zondag', 'maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag'],\n\t\tdayNamesShort: ['zon', 'maa', 'din', 'woe', 'don', 'vri', 'zat'],\n\t\tdayNamesMin: ['zo', 'ma', 'di', 'wo', 'do', 'vr', 'za'],\n\t\tweekHeader: 'Wk',\n\t\tdateFormat: 'dd-mm-yy',\n\t\tfirstDay: 1,\n\t\tisRTL: false,\n\t\tshowMonthAfterYear: false,\n\t\tyearSuffix: ''};\n\t$.datepicker.setDefaults($.datepicker.regional.nl);\n});\n", "/******* Translations ******/\n\nconst dicts = {};\n\nlet dict = {};\n\n// gettext stub\nfunction _(s, fb) {\n return dict[s] || fb || s;\n}\n\n_.tagged = (strings, ...values) =>\n strings.reduce((acc, cur, idx) => acc + cur + _(values[idx] || \"\"), \"\");\n\n_.taggedWithin =\n prefix =>\n (strings, ...values) =>\n strings.reduce(\n (acc, cur, idx) =>\n acc +\n cur +\n (_(prefix, { [values[idx]]: values[idx] })[values[idx]] ||\n values[idx] ||\n \"\"),\n \"\"\n );\n\n_.set = function (ob) {\n const lang = ob[\"lang\"] || _(\"lang\"); // Either provided or current lang?\n if (!dicts[lang]) {\n dicts[lang] = {};\n }\n for (let [key, val] of Object.entries(ob)) {\n // Set only if not set before (by _.set, or by _.addTranslations)\n dicts[lang][key] || (dicts[lang][key] = val);\n }\n dict = dicts[lang];\n};\n\n_.addTranslations = function (translations) {\n for (var term in translations) {\n if (translations.hasOwnProperty(term))\n for (var lang in translations[term]) {\n if (!dicts[lang]) dicts[lang] = {};\n // Always override what has been set before\n dicts[lang][term] = translations[term][lang];\n }\n }\n};\n\nObject.freeze(_);\n\nexport { _ };\n", "import { _ } from \"$json/lib/gettext\";\n\nconst strings = {\n \"lang\": \"nl\",\n \"Doubleclick to go back to this question\":\n \"Dubbelklikken om naar deze vraag terug te springen\",\n \"create a new case\": \"maak een nieuwe casus aan\",\n \"new\": \"nieuw\",\n \"Delete\": \"Verwijder\",\n \"case\": \"casus\",\n \"cases\": \"casus\",\n \"Last opened\": \"Laatst geopend\",\n \"created\": \"gemaakt\",\n \"report\": \"rapport\",\n \"Sun\": \"Zo\",\n \"Mon\": \"Ma\",\n \"Tue\": \"Di\",\n \"Wed\": \"Wo\",\n \"Thu\": \"Do\",\n \"Fri\": \"Vr\",\n \"Sat\": \"Za\",\n \"Jan\": \"Jan\",\n \"Feb\": \"Feb\",\n \"Mar\": \"Maart\",\n \"Apr\": \"April\",\n \"May\": \"Mei\",\n \"June\": \"Juni\",\n \"July\": \"Juli\",\n \"Aug\": \"Aug\",\n \"Sep\": \"Sep\",\n \"Oct\": \"Okt\",\n \"Nov\": \"Nov\",\n \"Dec\": \"Dec\",\n \"press enter to accept\": \"accepteer met ENTER\",\n \"filter cases by name\": \"zoek casus op naam\",\n \"field--value\": \"deze waarde\",\n \"field--date\": \"deze datum\",\n \"field--field\": \"dit veld\",\n \"field--list\": \"deze opties\",\n \"quoted--value\": \"de waarde \u201C{quotable}\u201D\",\n \"quoted--date\": \"de datum \u201C{quotable}\u201D\",\n \"quoted--field\": \"het veld \u201C{quotable}\u201D\",\n \"quoted--list\": \"de opties in \u201C{quotable}\u201D\",\n \"Date required\":\n \"{quotable--init} is verplicht; gebruik het formaat dd\u200A-\u200Amm\u200A-\u200Aj\u200Aj\u200Aj\u200Aj.\",\n \"Input required\": \"{quotable--init} is verplicht\",\n \"Choice required\": \"Keuze uit {quotable} is verplicht\",\n \"Field required\": \"{quotable--init} is verplicht\",\n \"Value has to lie between {minimum} and {maximum}\":\n \"{quotable--init} moet tussen {minimum} en {maximum} liggen\",\n \"Date has to lie between {minimum} and {maximum}\":\n \"{quotable--init} moet tussen {minimum} en {maximum} liggen; gebruik het formaat dd-mm-jjjj.\",\n \"Negative number or zero expected\":\n \"{quotable--init} moet negatief zijn of nul\",\n \"Negative number expected\": \"{quotable--init} moet negatief zijn\",\n \"Value has to lie below {maximum}\":\n \"{quotable--init} moet lager zijn dan {maximum+1}\",\n \"Positive number or zero expected\": \"{quotable} moet positief zijn of nul\",\n \"Positive number expected\": \"{quotable} moet hoger zijn dan nul\",\n \"Value has to lie above {minimum}\":\n \"{quotable--init} moet hoger zijn dan {minimum-1}\",\n \"A date after {maximum} is not allowed\":\n \"{quotable--init} n\u00E1 {maximum} is niet toegestaan; gebruik het formaat dd-mm-jjjj.\",\n \"A date before {minimum} is not allowed\":\n \"{quotable--init} v\u00F3\u00F3r {minimum} is niet toegestaan; gebruik het formaat dd-mm-jjjj.\",\n \"Invalid date\":\n \"{quotable--init} is ongeldig; gebruik het formaat dd-mm-jjjj.\",\n \"Invalid number\": \"{quotable--init} is geen getal\",\n \"Text length exceeds the maximum of {0} characters\":\n \"{quotable--init} mag maximaal {maxlength} karakters bevatten\",\n \"click for more...\": \"klik voor meer...\",\n \" (click to open link)\": \" (klik om link te openen)\",\n \"Are you sure? This will reset all values.\":\n \"Weet u het zeker? Dit zal alle ingevulde velden leegmaken.\",\n \"Yesterday\": \"Gisteren\",\n \"No valid session\": \"Ongeldige gebruikersnaam of wachtwoord\",\n \"Maximum allowed characters: {0}\": \"Maximaal {0} karakters toegestaan\",\n \"No interfaces to show\":\n \"Geen zichtbare elementen (vragen, tekstvelden) gedefinieerd\",\n // feedback\n \"Feedback\": \"Feedback\",\n \"describe the problem\": \"omschrijf het probleem\",\n \"Please do not collate issues.\": \"Een melding per keer!\",\n \"Please send only feedback about the currently visible question or questions; information about these will be sent back to the developers.\":\n \"Geef alleen feedback over de vraag of vragen die je op dit moment op je scherm ziet; informatie over die vragen wordt namelijk meegezonden naar de ontwikkelaars.\",\n \"send\": \"verstuur\",\n \"Thanks for your feedback!\": \"Bedankt voor uw melding!\",\n \"Interface has failed (probably a failing SOAP or database connection)\":\n \"Interface gefaald (waarschijnlijk een falende SOAP- of databasekoppeling)\",\n \"Choose...\": \"Kies...\",\n \"Choose or type...\": \"Kies of typ...\",\n \"cUMWrongUserNamePassword\": \"Ongeldige gebruikersnaam of wachtwoord\",\n \"cWebCaseIsRunning\":\n \"Casus laden is niet gelukt; deze casus wordt al gedraaid in een andere sessie\",\n \"The model you are trying to open does not exist\":\n \"Het beslismodel dat u probeert te openen bestaat niet\",\n \"You may now safely close this window\": \"U kunt het venster nu sluiten\",\n \"user name\": \"gebruikersnaam\",\n \"password\": \"wachtwoord\",\n \"Your models\": \"Uw modellen\",\n \"Your sessions\": \"Uw sessies\",\n \"log in\": \"inloggen\",\n \"load session\": \"Lees uw gegevens in\",\n \"load\": \"inlezen\",\n \"Choose the session file you saved earlier\":\n \"Kies het gegevensbestand dat u de vorige keer hebt opgeslagen\",\n \"Error loading session (wrong data)\":\n \"Inlezen gegevens mislukt (verkeerde gegevens).\",\n \"Please login\": \"Gelieve in te loggen\",\n \"open\": \"open\",\n \"copy\": \"kopie\",\n 'You have no tickets left for model \"{0}\"':\n 'Uw strippenkaart voor model \"{0}\" is op',\n \"__digitgroupingchar__\": \".\",\n \"__radixpoint__\": \",\",\n \"__digitgroupingrules__\": [3],\n \"attachments\": \"bijlagen\",\n \"your documents\": \"uw documenten\",\n \"saved sessions\": \"bewaarde sessies\",\n \"We are currently updating. Please try again later.\":\n \"Er is momenteel een update aan de gang, probeert u het binnenkort nogmaals.\",\n \"case name\": \"casusnaam\",\n \"dateplaceholder\": \"dd\u200A-\u200Amm\u200A-\u200Aj\u200Aj\u200Aj\u200Aj\",\n \"Error: No response from server, server probably down\":\n \"Fout: Server is tijdelijk buiten gebruik. U moet zich opnieuw aanmelden.\",\n \"Session has timed out. Please log in again.\":\n \"De sessie is afgelopen. U moet zich opnieuw aanmelden.\",\n \"first {0} results\": \"eerste {0} resultaten\",\n \"previous {0} results\": \"vorige {0} resultaten\",\n \"next {0} results\": \"volgende {0} resultaten\",\n \"last {0} results\": \"laatste {0} resultaten\",\n \"results {0} to {1} from {2}\": \"resultaten {0} tot {1} van {2}\",\n \"add row\": \"Voeg rij toe\",\n \"insert row\": \"voeg rij in\",\n \"delete row\": \"verwijder rij\",\n \"There are errors, please double check your answers.\":\n \"Er zijn nog fouten, gelieve uw antwoorden nogmaals na te gaan.\",\n \"cancel\": \"annuleer\",\n \"Something went wrong; see the server log for more information.\":\n \"Er is iets misgegaan; bekijk de server log voor meer informatie\"\n};\n\n_.set(strings);\n\nexport { strings };\n", "/*! (c) Andrea Giammarchi - ISC */\nvar self = window || /* istanbul ignore next */ {};\ntry {\n (function (URLSearchParams, plus) {\n if (\n new URLSearchParams(\"q=%2B\").get(\"q\") !== plus ||\n new URLSearchParams({ q: plus }).get(\"q\") !== plus ||\n new URLSearchParams([[\"q\", plus]]).get(\"q\") !== plus ||\n new URLSearchParams(\"q=\\n\").toString() !== \"q=%0A\" ||\n new URLSearchParams({ q: \" &\" }).toString() !== \"q=+%26\" ||\n new URLSearchParams({ q: \"%zx\" }).toString() !== \"q=%25zx\"\n )\n throw URLSearchParams;\n self.URLSearchParams = URLSearchParams;\n })(URLSearchParams, \"+\");\n} catch (URLSearchParams) {\n (function (Object, String, isArray) {\n \"use strict\";\n var create = Object.create;\n var defineProperty = Object.defineProperty;\n var find = /[!'\\(\\)~]|%20|%00/g;\n var findPercentSign = /%(?![0-9a-fA-F]{2})/g;\n var plus = /\\+/g;\n var replace = {\n \"!\": \"%21\",\n \"'\": \"%27\",\n \"(\": \"%28\",\n \")\": \"%29\",\n \"~\": \"%7E\",\n \"%20\": \"+\",\n \"%00\": \"\\x00\"\n };\n var proto = {\n append: function (key, value) {\n appendTo(this._ungap, key, value);\n },\n delete: function (key) {\n delete this._ungap[key];\n },\n get: function (key) {\n return this.has(key) ? this._ungap[key][0] : null;\n },\n getAll: function (key) {\n return this.has(key) ? this._ungap[key].slice(0) : [];\n },\n has: function (key) {\n return key in this._ungap;\n },\n set: function (key, value) {\n this._ungap[key] = [String(value)];\n },\n forEach: function (callback, thisArg) {\n var self = this;\n for (var key in self._ungap) self._ungap[key].forEach(invoke, key);\n function invoke(value) {\n callback.call(thisArg, value, String(key), self);\n }\n },\n toJSON: function () {\n return {};\n },\n toString: function () {\n var query = [];\n for (var key in this._ungap) {\n var encoded = encode(key);\n for (var i = 0, value = this._ungap[key]; i < value.length; i++) {\n query.push(encoded + \"=\" + encode(value[i]));\n }\n }\n return query.join(\"&\");\n }\n };\n for (var key in proto)\n defineProperty(URLSearchParams.prototype, key, {\n configurable: true,\n writable: true,\n value: proto[key]\n });\n self.URLSearchParams = URLSearchParams;\n function URLSearchParams(query) {\n var dict = create(null);\n defineProperty(this, \"_ungap\", { value: dict });\n switch (true) {\n case !query:\n break;\n case typeof query === \"string\":\n if (query.charAt(0) === \"?\") {\n query = query.slice(1);\n }\n for (\n var pairs = query.split(\"&\"), i = 0, length = pairs.length;\n i < length;\n i++\n ) {\n var value = pairs[i];\n var index = value.indexOf(\"=\");\n if (-1 < index) {\n appendTo(\n dict,\n decode(value.slice(0, index)),\n decode(value.slice(index + 1))\n );\n } else if (value.length) {\n appendTo(dict, decode(value), \"\");\n }\n }\n break;\n case isArray(query):\n for (var i = 0, length = query.length; i < length; i++) {\n var value = query[i];\n appendTo(dict, value[0], value[1]);\n }\n break;\n case \"forEach\" in query:\n query.forEach(addEach, dict);\n break;\n default:\n for (var key in query) appendTo(dict, key, query[key]);\n }\n }\n\n function addEach(value, key) {\n appendTo(this, key, value);\n }\n\n function appendTo(dict, key, value) {\n var res = isArray(value) ? value.join(\",\") : value;\n if (key in dict) dict[key].push(res);\n else dict[key] = [res];\n }\n\n function decode(str) {\n return decodeURIComponent(\n str.replace(findPercentSign, \"%25\").replace(plus, \" \")\n );\n }\n\n function encode(str) {\n return encodeURIComponent(str).replace(find, replacer);\n }\n\n function replacer(match) {\n return replace[match];\n }\n })(Object, String, Array.isArray);\n}\n\n(function (URLSearchParamsProto) {\n var iterable = false;\n try {\n iterable = !!Symbol.iterator;\n } catch (o_O) {}\n\n /* istanbul ignore else */\n if (!(\"forEach\" in URLSearchParamsProto)) {\n URLSearchParamsProto.forEach = function forEach(callback, thisArg) {\n var self = this;\n var names = Object.create(null);\n this.toString()\n .replace(/=[\\s\\S]*?(?:&|$)/g, \"=\")\n .split(\"=\")\n .forEach(function (name) {\n if (!name.length || name in names) return;\n (names[name] = self.getAll(name)).forEach(function (value) {\n callback.call(thisArg, value, name, self);\n });\n });\n };\n }\n\n /* istanbul ignore else */\n if (!(\"keys\" in URLSearchParamsProto)) {\n URLSearchParamsProto.keys = function keys() {\n return iterator(this, function (value, key) {\n this.push(key);\n });\n };\n }\n\n /* istanbul ignore else */\n if (!(\"values\" in URLSearchParamsProto)) {\n URLSearchParamsProto.values = function values() {\n return iterator(this, function (value, key) {\n this.push(value);\n });\n };\n }\n\n /* istanbul ignore else */\n if (!(\"entries\" in URLSearchParamsProto)) {\n URLSearchParamsProto.entries = function entries() {\n return iterator(this, function (value, key) {\n this.push([key, value]);\n });\n };\n }\n\n /* istanbul ignore else */\n if (iterable && !(Symbol.iterator in URLSearchParamsProto)) {\n URLSearchParamsProto[Symbol.iterator] = URLSearchParamsProto.entries;\n }\n\n /* istanbul ignore else */\n if (!(\"sort\" in URLSearchParamsProto)) {\n URLSearchParamsProto.sort = function sort() {\n var entries = this.entries(),\n entry = entries.next(),\n done = entry.done,\n keys = [],\n values = Object.create(null),\n i,\n key,\n value;\n while (!done) {\n value = entry.value;\n key = value[0];\n keys.push(key);\n if (!(key in values)) {\n values[key] = [];\n }\n values[key].push(value[1]);\n entry = entries.next();\n done = entry.done;\n }\n // not the champion in efficiency\n // but these two bits just do the job\n keys.sort();\n for (i = 0; i < keys.length; i++) {\n this.delete(keys[i]);\n }\n for (i = 0; i < keys.length; i++) {\n key = keys[i];\n this.append(key, values[key].shift());\n }\n };\n }\n\n function iterator(self, callback) {\n var items = [];\n self.forEach(callback, items);\n return iterable\n ? items[Symbol.iterator]()\n : {\n next: function () {\n var value = items.shift();\n return { done: value === undefined, value: value };\n }\n };\n }\n\n /* istanbul ignore next */\n (function (Object) {\n var dP = Object.defineProperty,\n gOPD = Object.getOwnPropertyDescriptor,\n createSearchParamsPollute = function (search) {\n function append(name, value) {\n URLSearchParamsProto.append.call(this, name, value);\n name = this.toString();\n search.set.call(this._usp, name ? \"?\" + name : \"\");\n }\n function del(name) {\n URLSearchParamsProto.delete.call(this, name);\n name = this.toString();\n search.set.call(this._usp, name ? \"?\" + name : \"\");\n }\n function set(name, value) {\n URLSearchParamsProto.set.call(this, name, value);\n name = this.toString();\n search.set.call(this._usp, name ? \"?\" + name : \"\");\n }\n return function (sp, value) {\n sp.append = append;\n sp.delete = del;\n sp.set = set;\n return dP(sp, \"_usp\", {\n configurable: true,\n writable: true,\n value: value\n });\n };\n },\n createSearchParamsCreate = function (polluteSearchParams) {\n return function (obj, sp) {\n dP(obj, \"_searchParams\", {\n configurable: true,\n writable: true,\n value: polluteSearchParams(sp, obj)\n });\n return sp;\n };\n },\n updateSearchParams = function (sp) {\n var append = sp.append;\n sp.append = URLSearchParamsProto.append;\n URLSearchParams.call(sp, sp._usp.search.slice(1));\n sp.append = append;\n },\n verifySearchParams = function (obj, Class) {\n if (!(obj instanceof Class))\n throw new TypeError(\n \"'searchParams' accessed on an object that \" +\n \"does not implement interface \" +\n Class.name\n );\n },\n upgradeClass = function (Class) {\n var ClassProto = Class.prototype,\n searchParams = gOPD(ClassProto, \"searchParams\"),\n href = gOPD(ClassProto, \"href\"),\n search = gOPD(ClassProto, \"search\"),\n createSearchParams;\n if (!searchParams && search && search.set) {\n createSearchParams = createSearchParamsCreate(\n createSearchParamsPollute(search)\n );\n Object.defineProperties(ClassProto, {\n href: {\n get: function () {\n return href.get.call(this);\n },\n set: function (value) {\n var sp = this._searchParams;\n href.set.call(this, value);\n if (sp) updateSearchParams(sp);\n }\n },\n search: {\n get: function () {\n return search.get.call(this);\n },\n set: function (value) {\n var sp = this._searchParams;\n search.set.call(this, value);\n if (sp) updateSearchParams(sp);\n }\n },\n searchParams: {\n get: function () {\n verifySearchParams(this, Class);\n return (\n this._searchParams ||\n createSearchParams(\n this,\n new URLSearchParams(this.search.slice(1))\n )\n );\n },\n set: function (sp) {\n verifySearchParams(this, Class);\n createSearchParams(this, sp);\n }\n }\n });\n }\n };\n try {\n upgradeClass(HTMLAnchorElement);\n if (/^function|object$/.test(typeof URL) && URL.prototype)\n upgradeClass(URL);\n } catch (meh) {}\n })(Object);\n})(self.URLSearchParams.prototype, Object);\nexport default self.URLSearchParams;\n", "/******* positionalFormat() BEGIN ******/\n\n/* https://github.com/pft/javascript/blob/master/positionalformat.js\n *\n * Copyright (C) 2006-2013 Niels Giesen.\n *\n * Contact: \n *\n * Author: Niels Giesen\n * Keywords: JavaScript, formatting, String\n *\n * This file is dual-licensed under either the BSD license or the\n * GNU Affero General Public License.\n *\n * positionalFormat enables you to replace numbers enclosed in curly braces (C# format\n * apparently) with positional arguments (that can be reused), like\n * this:\n *\n * positionalFormat('argument { 1 } (or is it { 2 }, or { 0 }?) comes { 1 }',3,'first',1)\n *\n * evals to:\n *\n * \"argument first (or is it 1, or 3?) comes first\"\n */\n\nexport function positionalFormat(str) {\n var args = arguments;\n return str.replace(/{\\s*(\\d+)\\s*}/g, function (match, num) {\n return args[parseInt(num) + 1] !== undefined\n ? args[parseInt(num) + 1]\n : match;\n });\n}\n\n/******* positionalFormat() END ******/\n\nexport function format(str, ob = {}) {\n return str.replace(/{\\s*([^{]+?)\\s*}/g, function (match, sub) {\n return ob[sub] !== undefined ? ob[sub] : sub;\n });\n}\n\n// export function formatPlus(str, ob = {}) {\n// return str.replace(/{\\s*([^{]+?)\\s*}/g, function (match, subwithstuff) {\n// const subs = subwithstuff.split(/\\|/);\n// console.log(subs);\n// return subs.reduce((acc, cur) => {\n// if (ob[cur] === undefined) return acc;\n// return ob[cur];\n// }, subs[0]);\n// // if (ob[sub] === undefined) return sub;\n// // if (!directives) return ob[sub] !== undefined ? ob[sub] : sub;\n// // if (\n// // directives.startsWith(\"+\") &&\n// // !Number.isNaN(ob[sub]) &&\n// // !Number.isNaN(Number(directives.slice(1)))\n// // )\n// // return Number(ob[sub]) + Number(directives.slice(1));\n// // if (\n// // directives.startsWith(\"-\") &&\n// // !Number.isNaN(ob[sub]) &&\n// // !Number.isNaN(Number(directives.slice(1)))\n// // )\n// // return Number(ob[sub]) + Number(directives.slice(1));\n// // const [sub, directives] = subwithstuff.split(/\\|/);\n// // if (ob[sub] === undefined) return sub;\n// // if (!directives) return ob[sub] !== undefined ? ob[sub] : sub;\n// // if (\n// // directives.startsWith(\"+\") &&\n// // !Number.isNaN(ob[sub]) &&\n// // !Number.isNaN(Number(directives.slice(1)))\n// // )\n// // return Number(ob[sub]) + Number(directives.slice(1));\n// // if (\n// // directives.startsWith(\"-\") &&\n// // !Number.isNaN(ob[sub]) &&\n// // !Number.isNaN(Number(directives.slice(1)))\n// // )\n// // return Number(ob[sub]) + Number(directives.slice(1));\n// return ob[sub];\n// });\n// }\n\nexport const formatPlus = format;\n\n// (str, ob = {}) {\n// return str.replace(/{\\s*([^{]+?)\\s*}/g, function (match, subwithstuff) {\n// const subs = subwithstuff.split(/\\|/);\n// console.log(subs);\n// return subs.reduceRight((acc, cur) => {\n// if (ob[cur] === undefined) return acc;\n// return ob[cur];\n// }, subs[0]);\n// // if (ob[sub] === undefined) return sub;\n// // if (!directives) return ob[sub] !== undefined ? ob[sub] : sub;\n// // if (\n// // directives.startsWith(\"+\") &&\n// // !Number.isNaN(ob[sub]) &&\n// // !Number.isNaN(Number(directives.slice(1)))\n// // )\n// // return Number(ob[sub]) + Number(directives.slice(1));\n// // if (\n// // directives.startsWith(\"-\") &&\n// // !Number.isNaN(ob[sub]) &&\n// // !Number.isNaN(Number(directives.slice(1)))\n// // )\n// // return Number(ob[sub]) + Number(directives.slice(1));\n// // const [sub, directives] = subwithstuff.split(/\\|/);\n// // if (ob[sub] === undefined) return sub;\n// // if (!directives) return ob[sub] !== undefined ? ob[sub] : sub;\n// // if (\n// // directives.startsWith(\"+\") &&\n// // !Number.isNaN(ob[sub]) &&\n// // !Number.isNaN(Number(directives.slice(1)))\n// // )\n// // return Number(ob[sub]) + Number(directives.slice(1));\n// // if (\n// // directives.startsWith(\"-\") &&\n// // !Number.isNaN(ob[sub]) &&\n// // !Number.isNaN(Number(directives.slice(1)))\n// // )\n// // return Number(ob[sub]) + Number(directives.slice(1));\n// return ob[sub];\n// });\n// }\n", "import { positionalFormat } from \"./text-utils.js\";\nimport { _ } from \"./gettext.js\";\n\nconst CODES = {\n cException: 1,\n cHTMLFormLoadCaseNotFound: 2,\n cHTMLMenuFileNotFound: 3,\n cWebModelIDDifferent: 4,\n cWebPleaseLogin: 5,\n cGetFileNotAllowed: 6,\n cGetDocumentNotFound: 7,\n cUMWrongUserNamePassword: 8,\n cWebSessionTimeOut: 9,\n cWebNoModelID: 10,\n cWebIllegalAccess: 11,\n cWebModelNotFound: 12,\n cWebCaseIsRunning: 13,\n cEngineLoadCaseFailed: 14, // Was: 3\n cEngineUpgrading: 15,\n cEngineNoInterfacesToShow: 16,\n cEngineLoadCaseFailedNotFound: 17,\n cEngineLoadCaseFailedWrongType: 18,\n cEngineLoadCaseFailedWrongData: 19,\n cWebOpenIsCalledWithUniqueID: 20,\n cTechGraphVizNotInstalled: 21,\n cGraphVizSessionNotFound: 22,\n cUMUserNotFound: 23,\n cUMModelNotFound: 24,\n cUMCaseNotFound: 25,\n cWebAdminNotAllowed: 26,\n cEngineGotoNodeFailed: 27,\n cPreviewNoCaseFound: 28,\n cTechUploadedFileToLarge: 29,\n cWebSaveCaseNotAllowed: 30,\n cWebSaveCaseFailed: 31,\n cInvalidUpload: 53\n};\n\nconst CODESREV = Object.fromEntries(\n Object.entries(CODES).map(([key, value]) => [value, key])\n);\n\n// Translate error - put translation in message property, return\n// error.\nfunction translate(_error) {\n const error = Object.assign({}, _error);\n // New API\n switch (error.code) {\n case CODES.cException:\n error.message = _(\n \"Something went wrong; see the server log for more information.\"\n );\n break;\n case CODES.cWebSessionTimeOut:\n error.message = _(\"Session has timed out. Please log in again.\");\n break;\n case CODES.cEngineLoadCaseFailed:\n switch (error.subcode) {\n case 1004:\n error.message = positionalFormat(\n _('You have no tickets left for model \"{0}\"'),\n error.summary\n .substring(56, error.summary.length - 1)\n .replace(/_/g, \" \")\n );\n break;\n default:\n error.message = error.summary; // Won't translate for now, may be st. like \"Loading case failed (xxx.mdl)\"\n }\n break;\n case CODES.cEngineLoadCaseFailedWrongData:\n error.message = _(\"Error loading session (wrong data)\");\n break;\n default:\n switch (error.subcode) {\n case 1002:\n error.message = _(\n \"We are currently updating. Please try again later.\"\n );\n break;\n case 1009:\n case 1025:\n error.message = positionalFormat(\n _('Infinite loop detected in {0}\"'),\n // Might be embedded though (in 1 or in 14...)\n error.summary.slice(18, error.summary.indexOf(\", infinite\"))\n );\n break;\n case 1010:\n error.message = _(\n \"Interface has failed (probably a failing SOAP or database connection)\"\n );\n break;\n default:\n error.message = _(CODESREV[error.code], _(error.summary));\n }\n }\n return error;\n}\n\nexport { CODES, translate };\n", "/* global URLSearchParams FormData */\n\nimport { mapConcat, either, when } from \"./functional.js\";\n\nconst ATTR_SNAME = \"data-server-name\";\nconst ATTR_SVALUE = \"data-server-value\";\nconst CONTAINER_SELECTOR = \"#bb-q .group.selected\";\n\nconst INPUT_SELECTOR = mapConcat(\n [\"input\", \"textarea\", \"select\"],\n function (c) {\n return c + \"[name]:not([disabled])\";\n },\n \", \"\n);\n\nconst inputsOf = container => container.querySelectorAll(INPUT_SELECTOR);\n\nconst isEmptyRadioValue = val => val === null;\nconst isEmptyCheckboxValue = val => val === false;\nconst isCheckedCheckboxValue = val => val === true;\n\nfunction collectWithin({\n params = null, // Object with an .append method, taking two params\n flavor = URLSearchParams, // Constructor for an object with an .append method, taking two params, used when params is not provided\n container = document.querySelector(CONTAINER_SELECTOR),\n omitFn = isEmptyCheckboxValue,\n changeFn = when(isCheckedCheckboxValue, () => \"on\"),\n collector = inputsOf\n} = {}) {\n return _collectAll(\n collector(container),\n params || new flavor(),\n omitFn,\n changeFn\n );\n}\n\nfunction _collectAll(nodeList, params, omitFn, changeFn) {\n for (const node of nodeList) {\n const val = valueOf(node),\n name = node.getAttribute(ATTR_SNAME) || node.getAttribute(\"name\");\n if (!either(isEmptyRadioValue, omitFn, val)) {\n params.append(name, changeFn(val));\n }\n }\n return params;\n}\n\nfunction valueOf(node) {\n if (node.hasAttribute(ATTR_SVALUE)) return node.getAttribute(ATTR_SVALUE);\n switch (node.type) {\n case \"radio\":\n return node.checked ? node.value : null; // Do not collect unchecked radios -- stripped in collectAll.\n case \"checkbox\":\n /* Collect unchecked checkboxes as false -- goes against usual form submission,\n but we need this for Studio API (using JSON). Stripped out by collectAll() unless provided with a omitFn. */\n if (!node.checked) return false;\n return node.hasAttribute(\"value\") // NOT the property -- this would still be \"on\".\n ? node.value // A checkbox should send either its value or\n : true; // Return Boolean true instead of \"on\", to be changed by collectAll() with changeFn,\n // or leave it at true (for JSON communication for instance) */\n default:\n return String(node.value).replace(/\\r?\\n/g, \"\\r\\n\");\n }\n}\n\nconst serializeQuestions = () =>\n collectWithin({}).toString().replace(/\\r?\\n/g, \"%0D%0A\");\n\nexport { valueOf, serializeQuestions, collectWithin };\n", "/* global $ FormData URLSearchParams */\nlet _vars = {};\n\nconst SESSION_KEYS = [\"dbname\", \"sessionid\", \"uniqueid\"];\nconst NAV_KEYS = [\"screenid\", ...SESSION_KEYS];\n\nObject.freeze(SESSION_KEYS);\nObject.freeze(NAV_KEYS);\n\nfunction setValueInVars(data, key) {\n if (typeof data[key] != \"undefined\") _vars[key] = data[key];\n}\n\nexport function setVars(data) {\n setValueInVars(data, \"version\");\n setValueInVars(data, \"uniqueid\");\n setValueInVars(data, \"replyserveraddress\");\n setValueInVars(data, \"replyserverport\");\n setValueInVars(data, \"proxyredirect\");\n setValueInVars(data, \"sessionid\");\n setValueInVars(data, \"modelname\");\n setValueInVars(data, \"dbname\");\n setValueInVars(data, \"modelid\");\n setValueInVars(data, \"showdeleteinmenu\");\n setValueInVars(data, \"showdatecreated\");\n setValueInVars(data, \"showreport\");\n setValueInVars(data, \"userinfo\");\n setValueInVars(data, \"showcopycase\");\n setValueInVars(data, \"screenid\");\n var version = getVar(\"version\");\n if (typeof version === \"string\") _vars[\"version\"] = version.split(\".\");\n}\n\nexport function getVar(string, obj) {\n return $.extend({}, _vars, obj)[string];\n}\n\n/**\n * Unset either all vars, or only those present in param vars\n *\n * @param {Array} vars An array of variable keys to delete\n *\n **/\nfunction unsetVars(arr) {\n if (!arr) return (_vars = {});\n arr.forEach(function (key) {\n delete _vars[key];\n });\n return _vars;\n}\n\nfunction collect(keys, collector = new FormData(), obj) {\n function append(key) {\n const val = getVar(key, obj);\n if (val !== undefined) collector.append(key, getVar(key, obj));\n }\n if (Array.isArray(keys)) {\n keys.forEach(append);\n } else {\n append(keys);\n }\n return collector;\n}\n\nfunction querify(keys, obj) {\n const usp = collect(keys, new URLSearchParams(), obj);\n return usp.toString();\n}\n\nexport default {\n querify,\n setVars,\n getVar,\n unsetVars,\n collect,\n NAV_KEYS,\n SESSION_KEYS\n};\n", "/* global URLSearchParams */\nimport \"./polyfills/url-search-params.js\";\nimport { Mode } from \"./mode.js\";\nimport { serializeQuestions } from \"./collect-values.js\";\nimport Vars from \"./vars.js\";\n\nexport const shouldExit = () =>\n Mode.get(\"hasModel\") && Boolean(Vars.getVar(\"sessionid\"));\n\nexport const onEnd = () => {\n if (!shouldExit()) return;\n if (!navigator.sendBeacon) return;\n const data = [\n \"step=exitdelayed\",\n Vars.querify(Vars.NAV_KEYS),\n \"fmt=json\",\n serializeQuestions()\n ]\n .filter(Boolean)\n .join(\"&\");\n\n const usp = new URLSearchParams(data);\n\n navigator.sendBeacon(\"/action\", usp);\n};\n\nfunction addEndListener() {\n // Update state before navigating away, but do not logout\n if (\"onpagehide\" in window) {\n window.addEventListener(\"pagehide\", onEnd);\n } else {\n window.addEventListener(\"unload\", onEnd, false);\n }\n}\n\nexport function removeEndListener() {\n // Update state before navigating away, but do not logout\n if (\"onpagehide\" in window) {\n window.removeEventListener(\"pagehide\", onEnd);\n } else {\n window.removeEventListener(\"unload\", onEnd, false);\n }\n}\n\naddEndListener();\n", "/* global $ */\nimport \"./a11y-user-detect.js\";\nimport { _ } from \"./gettext.js\";\n\n/*** A11y BEGIN ***/\nexport const A11y = {\n log: function (message) {\n var logdiv = document.getElementById(\"a-logdiv\");\n if (logdiv) logdiv.innerHTML = \"
\" + message + \"
\";\n }\n};\n\n/**\n * Datepicker a11y enhancements\n */\nexport const observeDatepickers = (function () {\n var init = false;\n return function initDateObservance() {\n var picker, observer;\n\n if (init || !(\"MutationObserver\" in window)) {\n init = true;\n return;\n }\n\n $(document).on(\"blur\", '[data-type=\"datetimepicker\"]', function () {\n A11y.log(\"\");\n });\n\n function observation(records, instance) {\n try {\n var infocus =\n document.activeElement.className.split(\" \").indexOf(\"hasDatepicker\") >\n -1;\n } catch (e) {\n // there mayn't be an activeElement, in which case className is undefined.\n }\n if (infocus) {\n var message = [\n $(\".ui-state-hover\").text(),\n $(\".ui-datepicker-month [selected]\").text(),\n $(\".ui-datepicker-year [selected]\").text()\n ].join(\" \");\n A11y.log(message + \", \" + _(\"press enter to accept\"));\n }\n }\n\n picker = document.getElementById(\"ui-datepicker-div\");\n\n if (picker) {\n observer = new window.MutationObserver(observation);\n observer.observe(picker, { attributes: true });\n init = true;\n }\n };\n})();\n", "let escapeHTML = (function () {\n var entityMap = {\n \"&\": \"&\",\n \"<\": \"<\",\n \">\": \">\",\n '\"': \""\",\n \"'\": \"'\",\n \"/\": \"/\"\n };\n var re = new RegExp(\"[&<>\\\"'/]\", \"g\");\n return function escapeHTML(string) {\n return String(string).replace(re, function (s) {\n return entityMap[s];\n });\n };\n})();\n\nconst escaped = (strings, ...values) =>\n strings.reduce(\n (acc, cur, idx) =>\n acc + cur + (values.length > idx ? escapeHTML(values[idx]) : \"\"),\n \"\"\n );\n\nexport { escapeHTML, escaped };\n", "import { Mode } from \"./mode.js\";\n\n/*** NOTIFICATIONS BEGIN ***/\nlet message;\n// Notification can either be a String or an object with a message\n// property. When supplying an object, the message property will be\n// shown to the user, but the entire object will be given to\n// console.error.\nfunction notify(options = { keepalive: false, html: false }, notification) {\n if (!notification) return;\n var text = notification.message || notification,\n timeout = 5000;\n if (\n typeof console !== \"undefined\" &&\n console &&\n typeof console.error === \"function\"\n )\n console.error(notification);\n message = { notification, options };\n Mode.set(\"hasMessage\");\n if (options.html) {\n document\n .querySelectorAll(\".bb-notification\")\n .forEach(area => (area.innerHTML = text));\n } else {\n document\n .querySelectorAll(\".bb-notification\")\n .forEach(area => (area.textContent = text));\n }\n if (!options.keepalive)\n window.setTimeout(Mode.unset.bind(Mode, \"hasMessage\"), timeout);\n}\n\nexport { notify, message };\n/*** NOTIFICATIONS END ***/\n", "/*** CONFIG BEGIN ***/\n\nimport conf from \"$conf.json\";\nimport { has } from \"./functional.js\";\n\nconf.a11y = Object.assign(\n {\n captions: false,\n optionfieldsets: false,\n strictlegends: false\n },\n conf.a11y\n);\n\nfunction propFinder(ob, prefix) {\n if (prefix) ob = find(prefix);\n\n function find(prop, fallback) {\n if (ob === undefined) return fallback;\n if (prop === undefined) return fallback;\n var leafs = prop.split(\".\").filter(Boolean),\n leaf = ob;\n while (has(leafs[0], leaf)) {\n leaf = leaf[leafs.shift()];\n }\n if (leafs.length === 0) return leaf;\n return fallback;\n }\n\n return find;\n}\n\nexport { conf, propFinder };\n\n/*** CONFIG END ***/\n", "import { conf } from \"./conf\";\nexport const fromApiServer = s =>\n s.startsWith(\"http://\") || s.startsWith(\"https://\")\n ? s\n : [conf.apiserver, s].filter(Boolean).join(\"/\");\n", "/* global jQuery */\nlet $ = jQuery;\n\nimport { escapeHTML } from \"./escape.js\";\nimport { notify } from \"./notify.js\";\nimport { _ } from \"./gettext.js\";\nimport { fromApiServer } from \"./location.js\";\n\n/**\n * Keep track of ajax requests + some convenience\n *\n * Exports busy and replace to bb.ajax object for plugins to use.\n */\nvar Ajax = {\n busy: false,\n last: null,\n direction: null,\n\n defaultOptions: {\n dataType: \"json\",\n type: \"POST\",\n url: \"action\",\n cache: false,\n async: true,\n success: checkJSON,\n error: onJSONError\n },\n\n post: function (options) {\n const _options = Object.assign({}, Ajax.defaultOptions, options, {\n url: fromApiServer(options.url || Ajax.defaultOptions.url)\n });\n $(document).trigger(\"bb:prePost\", _options);\n return $.ajax(_options);\n },\n\n replace: function (obj) {\n Ajax.last && Ajax.last.abort();\n Ajax.last = Ajax.post(obj);\n return Ajax.last;\n },\n\n release: function () {\n Ajax.busy = false;\n $(\".group.selected\").prop(\"disabled\", false);\n }\n};\n\n/**\n * Convenience method, like getJSON, but with POST\n *\n * @param {String} url URL where we POST to\n * @param {Object|String} data POST data\n *\n * Use Ajax.post instead if you want to overrule any default\n * settings from Ajax.defaultOptions.\n */\n$.postJSON = function (url, data) {\n return Ajax.post({ url: url, data: data });\n};\n\n/**\n * The default JSON error handler.\n *\n * Set appropriate flags, let user now what went wrong (as good as\n * possible).\n *\n * Trigger custom 'bb:jsonError' event on document.\n *\n * @param {Object} data XMLHTTPRequest object\n * @param {String} err Error message\n */\nfunction onJSONError(data, err) {\n Ajax.release();\n $(document).trigger(\"bb:jsonError\", data, err);\n if (data.responseText === undefined) {\n if (data.statusText === \"abort\");\n else {\n notify(\n { html: false, keepalive: true },\n _(\"Error: No response from server, server probably down\")\n );\n }\n } else if ($.trim(data.responseText) === \"\") {\n notify(\n { html: false, keepalive: true },\n _(\"Error: No response from server, server probably down\")\n );\n } else {\n notify(\n { html: true, keepalive: true },\n \"Error: \" +\n escapeHTML(err) +\n \" Response was: \" +\n \"
\" +\n escapeHTML(data.responseText) +\n \"
\"\n );\n }\n}\n\n/**\n * Indicate further processing ought to be skipped when this symbol is\n * set on JSON data.\n * @example\n import { stopDispatches } from \"$json/lib/ajax\";\n $(document).on(\"bb:preHandleData\", (event, data) => {\n event.stopImmediatePropagation(); // prevent further bb:preHandleData handlers.\n data[stopDispatches] = true;\n })\n * @constant\n * @type {Symbol}\n */\nexport const stopDispatches = Symbol(\"Skip all further dispatches\");\n\n/**\n Set this symbol to a promise on ajax data, and it shall be awaited\n before the next *handleData is run.\n*/\nconst awaiting = Symbol(\"awaiting promise\");\n\n/**\n * The default AJAX success handler. Perform actions on data.\n\n *\n * If data is not a JSON object, do nothing.\n *\n * @todo Either check data against JSON API, in some way or the\n * other, or make sure this function doesn't get called in the\n * first place when we're dealing with a non-core request; as\n * checkJSON is currently bound to ALL $.ajax requests,\n * this function may also fire for non-core requests.\n *\n * @param {Object} data 'JSON object according to BB JSON API'\n * @param {String} status Status of XHR\n * @param {Object} req The XHR object retrieving the resource\n *\n * @return undefined\n */\nasync function checkJSON(data, status, req) {\n if (typeof req.responseJSON !== \"undefined\") {\n // Since subsequent events may mess with the responseJSON\n // object, give (debuggers) the option to see the raw stuff.\n // Could be solved with a service worker instead.\n $(document).trigger(\"bb:responseText\", req.responseText);\n // use bb:preHandleData to change the JSON object for later invocations\n $(document).trigger(\"bb:preHandleData\", data);\n if (data[stopDispatches]) return;\n await data[awaiting];\n // handleData has the main stuff - the core rendering\n $(document).trigger(\"bb:handleData\", data);\n if (data[stopDispatches]) return;\n await data[awaiting];\n\n // use bb:postHandleData to change the DOM after initial rendering\n $(document).trigger(\"bb:postHandleData\", data);\n if (data[stopDispatches]) return;\n await data[awaiting];\n\n // finalHandleData may not change the DOM, but set focus for instance.\n $(document).trigger(\"bb:finalHandleData\", data);\n if (data[stopDispatches]) return;\n }\n}\n\nexport { Ajax, checkJSON, awaiting };\n", "import { Mode } from \"./mode.js\";\n\nexport const setSettled = () => Mode.set(\"isSettled\");\n", "/* global $, URLSearchParams */\nimport { setSettled } from \"./settled.js\";\nimport { removeEndListener } from \"./case-exit.js\";\n\nfunction BBI(options) {\n options = options || {};\n if (options.redirect_uri) {\n /** Example response:\n *\n * {\n * \"bbis\" : \"test\",\n * \"authid\" : \"Stubby\",\n * \"redirect_uri\" : \"https:\\/\\/HOST:8078\\/login?returnurl=http%3A%2F%2Fhost%3A80%2Fbbisreturns%3Fbbis%3Dtest&state=1507301556%3AGUID&authid=Stubby\",\n * \"url\": \"http:\\/\\/HOST:80\\/bbisreturns?bbis=test\",\n * \"state\": \"1507301556:6F2146D3-E0E6-4EB2-9DE4-2F31670B80D6\"\n * }\n *\n */\n var path = window.location.pathname.split(\"/\"),\n template = path.pop() || \"inlog.html\",\n returnurl =\n window.location.origin +\n path.concat(template).join(\"/\") +\n \"?\" +\n $.param({ bbis: options.bbis }),\n server = options.redirect_uri.split(\"?\")[0]; // The identity server sans params\n this.params = Object.assign({}, options.extraparams, {\n returnurl,\n authid: options.authid,\n // Add specific HTML page to state:\n state: options.state\n });\n this.url = server + \"?\" + $.param(this.params);\n this.stage = 1;\n } else {\n this.params = $.extend($.parseQuery(), { fmt: \"json\" });\n this.stage = 2;\n }\n return this;\n}\n\nBBI.prototype.authenticate = function () {\n if (!this.stage) throw \"BBI was not properly initialized\";\n if (this.stage === 1) {\n removeEndListener();\n window.location.href = this.url;\n } else if (this.stage === 2) {\n $.postJSON(\"bbisreturns\", this.params).then(setSettled);\n }\n};\n\nexport { BBI };\n", "import { escapeHTML } from \"./escape.js\";\nimport {\n allPass,\n anyPass,\n both,\n complement,\n compose,\n either,\n F,\n has,\n ifElse,\n pipe,\n prop,\n propEq,\n type\n} from \"./functional.js\";\nexport const isOptional = allPass([\n complement(prop(\"notnull\")),\n either(\n complement(prop(\"stringmask\")),\n pipe(prop(\"stringmask\"), RegExp, re => re.test(\"\"))\n )\n]);\n\nexport const isVisible = prop(\"visible\");\n\nexport const isLabel = either(\n propEq(\"name\", \"label\"),\n propEq(\"controltype\", \"label\")\n);\n\nexport const isOption = either(\n propEq(\"controltype\", \"radio\"),\n propEq(\"controltype\", \"checkbox\")\n);\n\nexport const isLink = propEq(\"name\", \"linklabel\");\n\nexport const isTextual = either(isLabel, isLink);\n\nexport const isPicture = propEq(\"controltype\", \"picture\");\n\nexport const isQuestion = complement(either(isTextual, isPicture));\n\nexport const isReadOnly = both(\n isQuestion,\n either(\n ifElse(has(\"originalreadonly\"), prop(\"originalreadonly\"), prop(\"readonly\")),\n propEq(\"visible\", false)\n )\n);\n\nexport const isValidatable = ifElse(\n either(isReadOnly, propEq(\"visible\", false)),\n F,\n anyPass([\n has(\"minimum\"),\n has(\"maximum\"),\n both(has(\"maxlength\"), complement(propEq(\"maxlength\", 0))),\n prop(\"notnull\"),\n compose(s => s === \"string\", type, prop(\"stringmask\"))\n ])\n);\n\nexport const renderAttribs = attr =>\n Object.entries(attr).reduce(\n (acc, [key, value]) => acc + ` ${key}=\"${escapeHTML(value)}\"`,\n \"\"\n );\n\nexport const setAttribs = (elt, attr) =>\n Object.entries(attr).forEach(([key, value]) => elt.setAttribute(key, value));\n\nexport const bbmClass = stylename =>\n `bbm-${stylename.toLowerCase().replace(/[^a-z0-9]/g, \"-\")}`;\n", "import {\n assoc,\n hasPath,\n chain,\n compose,\n either,\n path,\n prop,\n toLower,\n toUpper,\n ifElse,\n juxt,\n when\n} from \"./functional.js\";\nimport { format } from \"./text-utils.js\";\nimport { _ } from \"./gettext.js\";\n\nconst fieldDesignators = {\n datetimepicker: \"field--date\",\n numedit: \"field--value\",\n radio: \"field--list\",\n checkmultilist: \"field--list\",\n customlist: \"field--list\",\n combobox: \"field--list\",\n listbox: \"field--list\",\n multilist: \"field--list\",\n any: \"field--field\"\n};\n\nconst fieldKey = compose(\n controltype => fieldDesignators[controltype] || fieldDesignators[\"any\"],\n prop(\"controltype\")\n);\n\nconst generic = compose(key => _(key), fieldKey);\n\nconst genericQuoted = compose(\n key => _(key), // Runtime!\n key => key.replace(\"field--\", \"quoted--\"),\n fieldKey\n);\nexport const quotable = compose(\n when(\n prop(\"quotable\"),\n chain(\n assoc(\"quotable--init\"),\n compose(s => s.slice(0, 1).toUpperCase() + s.slice(1), prop(\"quotable\"))\n )\n ),\n when(\n prop(\"quotable\"),\n chain(assoc(\"quotable--upper\"), compose(toUpper, prop(\"quotable\")))\n ),\n when(\n prop(\"quotable\"),\n chain(assoc(\"quotable--lower\"), compose(toLower, prop(\"quotable\")))\n ),\n chain(assoc(\"quotable\"), either(path([\"metadata\", \"quotable\"]), generic)),\n ifElse(\n hasPath([\"metadata\", \"quotable\"]),\n compose(assoc(\"<<\", _(\"<<\", \"\u00AB\")), assoc(\">>\", _(\">>\", \"\u00BB\"))),\n compose(assoc(\"<<\", \"\"), assoc(\">>\", \"\"))\n ),\n chain(\n assoc(\"quoted--init\"),\n compose(s => s.slice(0, 1).toUpperCase() + s.slice(1), prop(\"quoted\"))\n ),\n ifElse(\n hasPath([\"metadata\", \"quotable\"]),\n chain(\n assoc(\"quoted\"),\n compose(\n arr => format(...arr),\n juxt([\n genericQuoted,\n compose(quotable => ({ quotable }), path([\"metadata\", \"quotable\"]))\n ])\n )\n ),\n chain(assoc(\"quoted\"), generic)\n )\n);\n", "/* global $ */\nimport { quotable } from \"./quotable.js\";\nimport {\n apply,\n assoc,\n cond,\n compose,\n dec,\n equals,\n identity,\n lensPath,\n mergeLeft,\n match,\n over,\n path,\n pipe,\n tail,\n test,\n T\n} from \"./functional.js\";\nimport { _ } from \"./gettext.js\";\nimport { format, formatPlus } from \"./text-utils.js\";\n\n/*** DATE UTILITIES BEGIN ***/\nDate.prototype.toHoursAndMinutes = function () {\n var hours = this.getHours();\n var minutes = this.getMinutes();\n if (hours < 10) hours = \"0\" + hours;\n if (minutes < 10) minutes = \"0\" + minutes;\n return hours + \":\" + minutes;\n};\nconst dateTimeRe = /^\\/Date\\((-?\\d+)\\)\\/$/,\n pureDateRe = /^(\\d{4})-(\\d{2})-(\\d{2})$/,\n ISO8601DateTimeInZuluRe =\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d{3})?)?Z$/;\n\n/*\n * Convert JSON date string to a Date object and return it.\n *\n * @{datestring}:\n *\n * An ISO-8601 datetime string in Zulu Time\n *\n * OR\n *\n * a JSON date string of the form\n *\n * \"/Date(102938293293)/\"\n *\n * where the numerical part is\n * seconds from epoch\n *\n * OR:\n *\n * a date formatted as \"yyyy-mm-dd\"\n *\n * OR:\n *\n * undefined -> undefined\n *\n */\nconst date = (...args) => new Date(...args);\n\nexport const parseDate = cond([\n [equals(0), () => undefined],\n [equals(undefined), identity],\n [equals(\"\"), identity],\n [\n test(pureDateRe),\n // Note if we were to pass pureDates to new Date as a valid\n // DateStamp, the engine will interpret it as 0:00 Zulu\n // time. Which, in this very case, is probably not what we\n // want. We want the date as in the minds of the case (min/max in\n // a calendar etc). It should be represented 'as is' to the user,\n // so 2022-02-09 may never become 2022-02-08 in users TZ, so\n // interpret it according in users TZ.\n pipe(match(pureDateRe), tail, over(lensPath([1]), dec), apply(date))\n ],\n [test(ISO8601DateTimeInZuluRe), date],\n [test(dateTimeRe), pipe(match(dateTimeRe), path([1]), parseInt, date)],\n [\n T,\n thing => {\n throw `Not a date in our book: ${thing}`;\n }\n ]\n]);\n\nexport const leadWithZeroes = string =>\n string.replace(/([^0-9]|^)([0-9]{3})([^0-9]|$)/, \"$10$2$3\");\n\n/**\n *\n * @param {Object} spec Object describing a control conforming to the BB json api.\n * @param {String} value The value to be checked\n * @returns {Boolean|Error} true when value is according to spec\n * @throws Localized error message\n */\nexport function checkDate(spec = { notnull: false }, value) {\n const UIFormat = $.datepicker._defaults.dateFormat;\n const formatDate = $.datepicker.formatDate.bind($.datepicker);\n var date, mindate, maxdate;\n if (!spec.notnull && value.trim() === \"\") {\n return true;\n }\n const metadata = spec.metadata || {};\n try {\n date = valueToDate(UIFormat, value); // $.datepicker.parseDate(UIFormat, value); // This line may throw an error.\n } catch (e) {\n //couldn't parse - throw a translatable error message\n throw formatPlus(\n metadata.errdateinvalid || _(\"Invalid date\"),\n compose(assoc(\"value\", value), quotable)(spec)\n );\n }\n if (date === null) {\n if (spec.notnull) {\n throw format(\n metadata.errrequired || _(\"Date required\"),\n compose(assoc(\"value\", value), quotable)(spec)\n );\n }\n return true;\n }\n (mindate = parseDate(spec.minimum)), (maxdate = parseDate(spec.maximum));\n if (!(mindate || maxdate)) return true; // Neither is set\n const fmindate = formatDate(UIFormat, mindate),\n fmaxdate = formatDate(UIFormat, maxdate);\n const quotableDate = compose(\n mergeLeft({\n value,\n minimum: fmindate,\n maximum: fmaxdate\n }),\n quotable\n )(spec);\n try {\n if (mindate && !maxdate && date < mindate)\n throw (\n metadata.errdatebeforemimimum ||\n _(\"A date before {minimum} is not allowed\")\n );\n else if (mindate && maxdate && (date < mindate || maxdate < date))\n throw (\n metadata.errdatenotinrange ||\n _(\"Date has to lie between {minimum} and {maximum}\")\n );\n else if (maxdate && !mindate && maxdate < date)\n throw (\n metadata.errdateaftermaximum ||\n _(\"A date after {maximum} is not allowed\")\n );\n } catch (e) {\n throw format(e, quotableDate);\n }\n return true;\n}\n\nexport const valueToDate = (format, value) => {\n let date;\n try {\n date = $.datepicker.parseDate(format, value);\n } catch (e) {\n const yyyycleanformat = format.replace(/[^mdy]/g, \"\").replace(\"yy\", \"yyyy\"),\n clean = value.replace(/[^0-9]/g, \"\");\n date = new Date();\n const yearindex = yyyycleanformat.indexOf(\"yyyy\");\n // If year was less than 4 digits, and not at end, adjust indices of other fields.\n const adjustment = yearindex === 0 ? clean.length - 8 : 0;\n let year = Number(clean.substr(yearindex, 4 + adjustment));\n if (year <= 99) {\n const cutoffyear = Number.isInteger(\n $.datepicker._defaults.shortYearCutoff\n )\n ? $.datepicker._defaults.shortYearCutoff\n : (date.getYear() % 100) +\n Number($.datepicker._defaults.shortYearCutoff);\n // Note: this will become odd if current year approaches end of\n // century. Let's say we live in 2099. User enters 98 -> fine.\n // Is below 109. User enters 02 => not fine. Still below 109.\n // But jQuery UI should also fix this. And it's still a long time.\n const century = (date.getFullYear() / 100) >> 0;\n if (year <= cutoffyear) {\n year += century * 100;\n } else {\n year += (century - 1) * 100;\n }\n }\n const month = Math.max(\n 0,\n Number(clean.substr(yyyycleanformat.indexOf(\"mm\") + adjustment, 2)) - 1\n );\n const dom = Number(\n clean.substr(yyyycleanformat.indexOf(\"dd\") + adjustment, 2)\n );\n date.setFullYear(year);\n date.setMonth(month);\n date.setDate(dom);\n if (\n date.getFullYear() !== year ||\n date.getMonth() !== month ||\n date.getDate() !== dom\n ) {\n throw \"invalid date\";\n }\n }\n return date;\n};\n\nexport const onChangeDate = ev => {\n let date;\n try {\n date = valueToDate($.datepicker._defaults.dateFormat, ev.target.value);\n } catch (e) {\n // ignore\n } finally {\n if (date) {\n ev.target.value = leadWithZeroes(\n $.datepicker.formatDate($.datepicker._defaults.dateFormat, date)\n );\n }\n }\n};\n\nexport const humanDate = (function () {\n var now = new Date();\n var hour0 = now.setHours(0, 0, 0, 0);\n var dayinms = 1000 * 60 * 60 * 24;\n var hour24 = hour0 + dayinms;\n var thisyear = now.getYear();\n var daysofweek = [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"].map(\n function (day) {\n return _(day);\n }\n );\n var monthsofyear = [\n \"Jan\",\n \"Feb\",\n \"Mar\",\n \"Apr\",\n \"May\",\n \"June\",\n \"July\",\n \"Aug\",\n \"Sep\",\n \"Oct\",\n \"Nov\",\n \"Dec\"\n ].map(function (month) {\n return _(month);\n });\n function isToday(ms) {\n return ms > hour0 && ms < hour24;\n }\n function isYesterday(ms) {\n return hour0 > ms && ms > hour0 - dayinms;\n }\n function isLastWeek(ms) {\n return ms > hour0 - dayinms * 6;\n }\n function isThisYear(date) {\n return thisyear == date.getYear();\n }\n function humanDate(date) {\n if (!(date instanceof Date)) throw \"Expects a Date object\";\n var ms = date.valueOf();\n var hm = \"\";\n hm = date.toHoursAndMinutes();\n if (isToday(ms)) {\n return hm;\n }\n if (isYesterday(ms)) {\n return _(\"Yesterday\") + \", \" + hm;\n }\n if (isLastWeek(ms)) {\n return daysofweek[date.getDay()] + \" \" + hm;\n }\n return (\n date.getDate() +\n \" \" +\n monthsofyear[date.getMonth()] +\n (isThisYear(date) ? \"\" : \" \" + date.getFullYear()) +\n \", \" +\n hm\n );\n }\n return humanDate;\n})();\n", "import { compose, either, isNil, not, path } from \"./functional.js\";\n\n/* editPolicy may be \"return\", \"stay\", or undefined, meaning off */\nexport const editPolicy = path([\"arbitrary\", \"core\", \"editPolicy\"]);\n\nexport const canEditEarlier = compose(not, isNil, editPolicy);\n\nconst isLabelValueDynamic = compose(\n value => value === true,\n path([\"arbitrary\", \"core\", \"isLabelValueDynamic\"])\n);\n\nconst preferUpdate = compose(\n value => value === true,\n path([\"arbitrary\", \"core\", \"preferUpdate\"])\n);\n\nexport const mustUpdate = either(preferUpdate, canEditEarlier);\n\nexport const updateLabels = either(mustUpdate, isLabelValueDynamic);\n", "const _Widgets = {};\n\nexport function registerWidget(options) {\n _Widgets[options.name] = options;\n}\nexport function getWidget(name) {\n return _Widgets[name];\n}\n", "/* global $ */\n\nimport { parseDate } from \"./dates\";\nimport { isReadOnly, isValidatable } from \"./control-helpers\";\nimport { updateLabels } from \"./feature-queries.js\";\nimport { conf } from \"./conf.js\";\nimport { getWidget } from \"./form-widgets.js\";\nimport { anyPass, has, prop } from \"./functional.js\";\nconst Dynprops = {};\n\n// Update the control element\nDynprops.update = function ($widget, control, Updates, requestor) {\n if (!$widget.get(0)) return;\n const oldval = $widget.val();\n\n const updates = Object.keys(Updates);\n const definition = getWidget(control.controltype);\n $widget.removeData([\"validated\"]);\n\n /** isForNotNull **/\n if (has(\"isForNotNull\", Updates)) {\n $widget.toggleClass(\"bb-for-required\", Boolean(control.isForNotNull));\n $widget.toggleClass(\"bb-for-optional\", !control.isForNotNull);\n }\n\n /** Placeholder **/\n if (has(\"placeholder\", Updates) > -1) {\n $widget.attr(\"placeholder\", control.placeholder);\n }\n\n /** Visible **/\n if (has(\"visible\", Updates)) {\n if (control.identifier === \"gformulier.gegevens.geschil_partner\")\n $widget.attr(\"aria-hidden\", !control.visible);\n $widget.attr(\"data-visible\", control.visible);\n\n if (control.visible) {\n window.setTimeout(function () {\n $widget.removeAttr(\"hidden\");\n }, 80);\n } else {\n window.setTimeout(function () {\n $widget.attr(\"hidden\", !control.visible);\n }, 80);\n }\n }\n\n /** Value **/\n if (has(\"value\", Updates)) {\n if (updateLabels(conf)) {\n /**\n @done: linklabel, listlabel, checkmultilist, memo, combobox, radio,\n checkbox, numedit, datetimepicker, edit, grid, multilist(?), listbox(?)\n @todo: freebox.\n\n NOTE: A widget currently can change itself *only* if\n they are registered with allowUpdatingSelf : true\n\n Widgets within a grid can update other widgets in a grid.\n */\n if (definition.setValue) {\n definition.setValue($widget.get(0), control.value, requestor, Updates);\n }\n }\n }\n\n /** Readonly **/\n if (\n anyPass([has(\"readonly\"), has(\"originalreadonly\"), has(\"visible\")], Updates)\n ) {\n const readonly = isReadOnly(control);\n if (typeof definition.onreadonly === \"function\") {\n definition.onreadonly($widget.get(0), readonly);\n } else {\n $widget.prop(\"disabled\", readonly);\n }\n }\n\n /** Minimum **/\n if (has(\"minimum\", Updates)) {\n $widget.attr(\"min\", control.minimum);\n if (control.controltype === \"datetimepicker\") {\n if (control.minimum) {\n $widget.datepicker(\"option\", \"minDate\", parseDate(control.minimum));\n }\n }\n }\n\n /** Maximum **/\n if (has(\"maximum\", Updates)) {\n $widget.attr(\"max\", control.maximum);\n if (control.controltype === \"datetimepicker\") {\n if (control.maximum) {\n $widget.datepicker(\"option\", \"maxDate\", parseDate(control.maximum));\n }\n }\n }\n\n /** Maxlength **/\n if (has(\"maxlength\", Updates)) {\n if (control.maxlength === 0) $widget.removeAttr(\"maxlength\");\n else $widget.attr(\"maxlength\", control.maxlength);\n }\n\n /** Let user know something changed perhaps against their intent. **/\n if (oldval !== $widget.val()) {\n $widget.addClass(\"bb-programmatically-changed\");\n $widget.trigger(\"change\", { programmatically: true });\n self.setTimeout(function () {\n $widget.removeClass(\"bb-programmatically-changed\");\n }, 1000);\n }\n\n /** Notnull **/\n if (has(\"notnull\", Updates)) {\n if (typeof definition.onrequired === \"function\") {\n definition.onrequired($widget.get(0), control.notnull);\n } else {\n $widget.attr(\"aria-required\", control.notnull);\n }\n if (control.notnull) {\n $widget.addClass(\"notnull\");\n } else {\n $widget.removeClass(\"notnull\");\n }\n }\n\n if (isValidatable(control)) {\n $widget.attr(\"aria-errormessage\", `${control.id}--error`);\n $widget.addClass(\"validatable\");\n } else {\n $widget.removeAttr(\"aria-errormessage\");\n $widget.removeClass(\"validatable\");\n }\n\n if (updates.length > 0) {\n const event = new CustomEvent(\"bb:updatedControl\", {\n detail: { control, Updates },\n bubbles: true\n });\n $widget.get(0).dispatchEvent(event);\n $(document).trigger(\"bb:updated\", [$widget, control, updates]);\n }\n};\n\n$.fn.extend({\n updateControl: function (controls, requestor) {\n return this.each(function () {\n const $this = $(this),\n control = $this.data(\"control\");\n if (\n this === requestor &&\n !prop(\"allowUpdatingSelf\", getWidget(control.controltype))\n ) {\n // This was the one requesting an update\n return this;\n }\n if (!control) throw (\"No updateControl defined for\", $this);\n const id = control.id,\n update = controls.find(function (c) {\n return c.id === id;\n }),\n // updates = [],\n Updates = {},\n props = [\n \"maxlength\",\n \"isForNotNull\",\n \"minimum\",\n \"maximum\",\n \"notnull\",\n \"readonly\",\n \"originalreadonly\",\n \"placeholder\",\n \"precision\",\n \"stringmask\",\n \"errortext\",\n \"visible\",\n \"value\",\n \"columns\",\n \"text\"\n ];\n // Caron-syntax used in label, therefore no (text) interface\n // returned -- should not mix and match dynprops with empty\n // labels! Do not allow this to error on the user though!\n\n // Does also handle (cause to ignore) labels within a grid!\n if (typeof update === \"undefined\") {\n return this;\n // update = $.extend({}, control, {visible: false});\n }\n for (var i in props) {\n if (control[props[i]] !== update[props[i]]) {\n Updates[props[i]] = { from: control[props[i]], to: update[props[i]] };\n control[props[i]] = update[props[i]];\n // updates.push(props[i]);\n }\n }\n Dynprops.update($this, control, Updates, requestor);\n return this;\n });\n }\n});\n\nexport { Dynprops };\n", "const Hooks = new Map();\n\nexport const registerHook = key => hook => {\n if (typeof hook !== \"function\") throw \"Can only add a function as a hook\";\n Hooks.set(key, hook);\n};\n\nexport const runHook =\n key =>\n (...args) => {\n if (Hooks.has(key)) Hooks.get(key)(...args);\n };\n", "/* global $ */\nimport { bbmClass, isReadOnly, renderAttribs } from \"./control-helpers\";\nimport { Dynprops } from \"./dynprops\";\nimport { escaped, escapeHTML } from \"./escape.js\";\nimport { conf, propFinder } from \"./conf\";\nimport { getWidget } from \"./form-widgets.js\";\nimport {\n assoc,\n both,\n compose,\n complement,\n has,\n hasPath,\n isNil,\n not,\n prop\n} from \"./functional.js\";\nimport { runHook } from \"./hooks.js\";\nimport { Mode } from \"./mode.js\";\n\nconst arbitraryCoreProp = propFinder(conf, \"arbitrary.core\");\n\n/**\n * Create a control widget, then insert it into the DOM\n *\n * @param {Object} control A control object as defined in the JSON API. The one to render + add.\n * @param {Object} group The group object to which this control belongs.\n * @param {Element} wGroup Element whereto this control should be added. *NOTE* that this need not be a .bb-group\n *\n * @return undefined\n *\n * @todo Simplify parameter list.\n */\nfunction wControl(control, group, wGroup) {\n control._group = group;\n let attribs = {};\n let widget;\n const enabled = group.current || complement(isReadOnly)(control);\n // Has been rendered\n if (control.$elt) {\n $(wGroup).append(control.$elt);\n return control.$elt;\n }\n if (compose(has(\"fixup\"), getWidget)(control.controltype))\n compose(fn => fn(control), prop(\"fixup\"), getWidget)(control.controltype);\n\n if (control.datatype) attribs[\"data-datatype\"] = control.datatype;\n\n if (control.meta)\n for (let d in control.meta) {\n if (both(has(d), compose(not, isNil, prop(d)))(control.meta))\n attribs[\"data-\" + d] = escape(control.meta[d]);\n }\n if (control.metadata) {\n attribs[\"data-metadata-keys\"] = Object.keys(control.metadata)\n .map(s => s.replace(/\\s/g, \"-\"))\n .join(\" \");\n }\n if (control.aria)\n for (let a in control.aria) {\n if (has(a, control.aria)) attribs[\"aria-\" + a] = control.aria[a];\n }\n\n if (control.name) {\n attribs[\"name\"] = control.name;\n }\n\n const wdef = getWidget(control.controltype);\n if (!wdef) {\n console.warn(`No widget definition for ${control.controltype}`);\n return null;\n }\n const tagName = wdef.tagName;\n attribs = wdef.attribs(attribs, control, enabled);\n\n attribs[\"data-type\"] = control.controltype;\n if (tagName) {\n widget = $(\"<\" + tagName + \" \" + renderAttribs(attribs) + \"/>\");\n } else {\n widget = $(wdef.render(control, group, attribs));\n if (!widget) return null;\n }\n\n if (control.className) {\n widget.addClass(control.className);\n }\n control.$elt = widget;\n control._elt = widget.get(0);\n\n if (wdef && wdef.tagName) {\n /**\n Okay, some (older) definitions have a tagName definition ->\n from which a quite empty skeleton widget is created.\n\n Afterwards, they fill that very widget with a render function\n of a different signature than usual:\n\n Instead of (control (plain object), group (plain object), attribs (array)), they get\n (control (plain object), widget (jQuery collection), group (plain object))).\n\n */\n wdef.render(control, widget, group);\n }\n\n // attach an id whenever meaningful:\n // if (control.id && /\\d+$/.test(control.id))\n if (control.id) {\n // id used not to be safe, but now we prepend the groupid, making it safe.\n widget.attr(\"id\", control.id);\n }\n if (control._originalid) {\n // Use data-id for stuff refering to the interface, no matter in which group it is, such as informationsources.\n widget.attr(\"data-id\", control._originalid);\n }\n\n if (hasPath([\"metadata\", \"autocomplete\"], control)) {\n widget\n .attr(\"data-server-name\", control.name)\n .attr(\"name\", control.metadata.autocomplete)\n .attr(\"autocomplete\", control.metadata.autocomplete);\n }\n\n $(wGroup).append(widget);\n\n /* Insert a space between elements so that elements are reasonably\n * well-placed when CSS is disabled.\n */\n $(wGroup).append(\" \");\n\n // Tooltips:\n if (control.hint) {\n if (enabled) Mode.set(\"hasHints\");\n runHook(\"hinter\")(widget, assoc(\"enabled\", enabled, control));\n }\n widget.data(\"control\", control);\n\n /**\n * Dynamic properties\n */\n var dynprops = [\n \"maxlength\",\n \"minimum\",\n \"maximum\",\n \"notnull\",\n \"isForNotNull\",\n \"readonly\",\n \"precision\",\n \"stringmask\",\n \"errortext\",\n \"placeholder\"\n ],\n dynpropsforus = {};\n\n for (var ii in dynprops) {\n if (has(dynprops[ii], control))\n dynpropsforus[dynprops[ii]] = { to: control[dynprops[ii]] }; // .push(dynprops[ii]);\n }\n\n if (has(\"visible\", control) && control.visible === false) {\n dynpropsforus[\"visible\"] = { to: false }; // .push(dynprops[ii]);\n }\n // dynpropsforus.push(\"visible\");\n\n widget.data(\"anchor\", widget);\n\n if (wdef && wdef.afterRender) {\n wdef.afterRender(widget, control);\n }\n\n if (shouldWrap(control)) {\n wrapInlineInput(widget);\n }\n\n /* Allow class-based styling */\n if (control[\"font-class\"]) {\n widget.addClass(bbmClass(control[\"font-class\"]));\n }\n\n /**\n * Two things:\n * - Put control tags in data-tags of Element.\n * - Make TAG known to CSS as bb-tagged-TAG.\n */\n if (control[\"tags\"] instanceof Array) {\n $(widget).data(\"tags\", control[\"tags\"]);\n $.each(control[\"tags\"], function (i, tag) {\n widget.addClass(\"bb-tagged-\" + tag);\n });\n }\n\n Dynprops.update(widget, control, dynpropsforus);\n\n return widget;\n}\n\nfunction shouldWrap(control) {\n return (\n control.prelabel ||\n control.postlabel ||\n (arbitraryCoreProp(\"wrapAllSingleLiners\") === true &&\n compose(prop(\"couldWrap\"), getWidget)(control.controltype)) ||\n (control.placeholder &&\n arbitraryCoreProp(\"accessiblePlaceholders\") === true &&\n compose(prop(\"couldWrap\"), getWidget)(control.controltype))\n );\n}\n\nfunction wrapInlineInput(widget) {\n var control = widget.data(\"control\"),\n prelabel = control.prelabel,\n postlabel = control.postlabel;\n var anchor = widget.data(\"anchor\");\n var wraptag = \"span\";\n if (anchor.get(0).nodeName === \"DIV\") wraptag = \"div\";\n anchor.wrapAll(\n \"<\" +\n wraptag +\n ' data-wraps-type=\"' +\n control.controltype +\n '\" class=\"bb-input-wrap\">' +\n wraptag +\n \">\"\n );\n anchor = anchor.parent();\n widget.data(\"anchor\", anchor);\n anchor.data({\n control: control,\n type: control.controltype\n });\n if (prelabel)\n anchor.prepend(\n '' +\n escapeHTML(prelabel) +\n \"\"\n );\n if (control.placeholder && arbitraryCoreProp(\"accessiblePlaceholders\")) {\n widget\n .get(0)\n .setAttribute(\n \"aria-describedby\",\n (\n (widget.get(0).getAttribute(\"aria-describedby\") || \"\") +\n ` ${control.id}--placeholder`\n ).trim()\n );\n anchor.append(\n `${escapeHTML(control.placeholder)}`\n );\n }\n if (postlabel)\n anchor.append(\n '' +\n escapeHTML(postlabel) +\n \"\"\n );\n}\n\nconst getControl = elt => $.data(elt, \"control\");\n\nexport { getControl, wControl };\n", "export const listtypes = {\n radio: \"LIST\",\n checkmultilist: \"LIST\",\n customlist: \"LIST\",\n combobox: \"BOX\",\n listbox: \"BOX\",\n multilist: \"BOX\"\n};\n", "/* global $ */\nimport { getWidget } from \"./form-widgets.js\";\nimport {\n always,\n assoc,\n either,\n tap,\n cond,\n path,\n propEq,\n T\n} from \"./functional.js\";\nimport { _ } from \"./gettext.js\";\nimport { format, formatPlus } from \"./text-utils.js\";\nimport { listtypes } from \"./types.js\";\nimport { compose } from \"./functional.js\";\nimport { quotable } from \"./quotable.js\";\n\n// Validate actual input, return true if it's ok, throw an error otherwise.\nexport function validateInput(node) {\n const $node = $(node),\n control = $node.data(\"control\");\n let ok = true,\n re,\n errortext,\n val,\n category;\n\n if (control === undefined) {\n throw \"Not a BB widget\";\n }\n\n if (control.visible === false) {\n return true;\n }\n category = listtypes[control.controltype];\n\n val = $node.val();\n\n if (control.stringmask) {\n re = new RegExp(control.stringmask);\n if (!re.test(val))\n throw format(\n control.errortext,\n compose(assoc(\"value\", val), quotable)(control)\n );\n }\n if (control.notnull) {\n if (category === \"LIST\") {\n ok = $node.is(\":has(:checked)\");\n } else if (category === \"BOX\") {\n // There could be a faux, checked, option telling us to\n // fill in the field. That is the second check here.\n ok = val !== null && val !== \"\";\n } else if (control.controltype == \"checkbox\") {\n ok = $node.is(\":checked\");\n } else if (control.controltype === \"grid\") {\n if (control.addallowed === false) {\n const checkable = control.columns.find(\n either(\n propEq(\"controltype\", \"radiobutton\"),\n propEq(\"controltype\", \"checkbox\")\n )\n );\n if (checkable) {\n ok = $node.is(\":has(:checked)\");\n }\n } else {\n // A required grid should have at least one row.\n // But if no rows **can** be added it would be rude and confusing to complain to the end-user.\n ok = control.value.length > 0 || control.addallowed === false;\n }\n } else {\n re = /\\S/;\n ok = re.test(val);\n }\n if (!ok) {\n throw cond([\n [path([\"metadata\", \"errrequired\"]), path([\"metadata\", \"errrequired\"])],\n [\n propEq(\"controltype\", \"datetimepicker\"),\n compose(c => formatPlus(_(\"Date required\"), c), quotable)\n ],\n [\n always([\"BOX\", \"LIST\"].indexOf(category) > -1),\n compose(c => format(_(\"Choice required\"), c), quotable)\n ],\n [T, compose(c => format(_(\"Field required\"), c), quotable)]\n ])(control);\n }\n }\n if (control.maxlength && control.maxlength > 0) {\n ok = val.length <= control.maxlength;\n if (!ok) {\n throw format(\n path([\"metadata\", \"errtexttoolong\"])(control) ||\n _(\"Text length exceeds the maximum of {maxlength} characters\"),\n quotable(control)\n );\n }\n }\n if (getWidget(control.controltype).validate) {\n return getWidget(control.controltype).validate(control, val);\n }\n return true;\n}\n", "import {\n groupWith,\n map,\n filter,\n pipe,\n path,\n strictUniq,\n lensPath\n} from \"./functional.js\";\n\nconst pathToGroup = [\"metadata\", \"group\"];\nexport const pathGroup = path(pathToGroup);\nexport const lensGroup = lensPath([\"metadata\", \"group\"]);\n\nconst areOfOneQuestion = (a, b) => a.isfor === b.id || b.isfor === a.id;\n\nexport const groupInner = groupWith(areOfOneQuestion);\n\nconst InfinityIfMinus1 = num => (num + 1 || Infinity) - 1;\nconst indexOfOrInfinity = (sub, s) => InfinityIfMinus1(s.indexOf(sub));\nexport const baseGroup = s => s.substr(0, indexOfOrInfinity(\".\", s));\nexport const tailGroup = s => s.substr(indexOfOrInfinity(\".\", s) + 1);\n\nconst belongTogether = (a, b) =>\n areOfOneQuestion(a, b) ||\n (pathGroup(a) &&\n pathGroup(b) &&\n baseGroup(pathGroup(a)) === baseGroup(pathGroup(b)));\n\nexport const groupOuter = groupWith(belongTogether);\n\nexport const groupClasses = pipe(\n map(path[(\"metadata\", \"groupClasses\")]),\n filter(Boolean),\n strictUniq\n);\n\nexport const doGrouping = path([\"arbitrary\", \"core\", \"form-group\", \"on\"]);\n", "export const normalize = s => s.toLowerCase().replace(/[^a-z0-9]/g, \"-\");\n", "import { path, either, compose, prop } from \"./functional.js\";\nimport { conf } from \"./conf.js\";\n\n/**\n\nName keys follow this pattern:\n\n__\n\n is any of:\n\n- GROUPING: subgroup of questions and/or texts and/or links\n- ITEM: a question and/or text and/or link\n- QUESTION: a question (is also an item)\n- TEXT: a top level text (not a label for a question)\n- LINK: a top level link (so: not inside markdown)\n- PICTURE: a top level image (so : nto inside markdown)\n\nGROUPING ::= ITEM+\nITEM ::= QUESTION | TEXT | LINK | PICTURE\n\n is any of:\n\n- _CLASS_ : the css class to put on this type \n- _PREFIX_: a css class prefix\n- _DATA_: a data- attribute\n\nwhere can be anything.\n\nThe default values for those keys, thus the strings that willl be used\nin the generated DOM, are provided in nameDefaults. They can be\noverwritten in the `conf.json` file in the property\n`core.form-group.names` in order to retrofit older or other naming\nschemes.\n\n*/\n\nexport const /* A grouping groups items */\n GROUPING_CLASS = \"grouping-class\", // Class of grouping\n GROUPING_PREFIX_TYPE = \"grouping-prefix-type\", // prefix for -question, -text or -author\n GROUPING_DATA_NAME = \"grouping-data-name\", // data attribute conveying author provided group name\n GROUPING_DATA_LEVEL = \"grouping-data-level\", // grouping level, 1-based\n ITEM_PREFIX_AUTHORCLASS = \"item-prefix-authorclass\", // prefix for author class set with cssclasses on the metadata\n QUESTION_CLASS = \"question-class\", //: \"bb-questionlabelgroup\",\n QUESTION_PREFIX_TYPE = \"question-prefix-type\", //: \"bb-itype\",\n QUESTION_PREFIX_PROPERTY = \"question-prefix-property\", //: \"bb-itype\",\n QUESTION_DATA_LAYOUT = \"question-data-layout\", //: \"data-form-group-layout\",\n QUESTION_PREFIX_AUTHORSTYLE = \"question-prefix-authorstyle\", //: \"bb-g-\",\n QUESTION_CLASS_NOLABEL = \"question-class-nolabel\"; //: \"form-group__question--no-label\",\n\nconst nameDefaults = {\n [GROUPING_CLASS]: \"form-group\",\n [GROUPING_PREFIX_TYPE]: \"form-group-\",\n [GROUPING_DATA_NAME]: \"data-form-group-name\",\n [GROUPING_DATA_LEVEL]: \"data-form-group-level\",\n [ITEM_PREFIX_AUTHORCLASS]: \"form-group__item--author-class-\",\n [QUESTION_CLASS]: \"bb-questionlabelgroup\",\n [QUESTION_PREFIX_TYPE]: \"bb-itype\",\n [QUESTION_PREFIX_PROPERTY]: \"question-\", //: \"bb-itype\",\n [QUESTION_DATA_LAYOUT]: \"data-form-group-layout\",\n [QUESTION_PREFIX_AUTHORSTYLE]: \"bb-g-\",\n [QUESTION_CLASS_NOLABEL]: \"form-group__question--no-label\"\n};\n\n// const fg = {\n// [GROUPING_CLASS]: \"no-form-group-outer\",\n// [GROUPING_PREFIX_TYPE]: \"form-group-\",\n// [QUESTION_CLASS]: \"bb-questionlabelgroup p-form-group\",\n// [QUESTION_PREFIX_TYPE]: \"bb-itype-\",\n// [QUESTION_DATA_LAYOUT]: \"data-p-form-group-layout-type\",\n// [QUESTION_CLASS_NOLABEL]: \"p-form-group-orphaned\"\n// };\n\n// const bem_example = {\n// [GROUPING_CLASS]: \"form-group\",\n// [GROUPING_PREFIX_TYPE]: \"form-group-\",\n// [ITEM_PREFIX_AUTHORCLASS]: \"form-group__item--author-class-\",\n// [QUESTION_CLASS]: \"bb-questionlabelgroup\",\n// [QUESTION_PREFIX_TYPE]: \"form-group__question-\",\n// [QUESTION_DATA_LAYOUT]: \"data-form-group-layout\",\n// [QUESTION_PREFIX_AUTHORSTYLE]: \"form-group__question--author-style-\"\n// };\n\nconst pathToNames = path([\"arbitrary\", \"core\", \"form-group\", \"names\"]);\n\nexport const names = propArg =>\n either(compose(prop(propArg), pathToNames), _ => prop(propArg, nameDefaults))(\n conf\n );\n", "/* global $ */\nimport {\n all,\n both,\n curry,\n filter,\n has,\n compose,\n ifElse,\n head,\n path,\n prop,\n propEq,\n any,\n find,\n pathOr,\n split,\n join,\n map,\n when,\n tap,\n cond,\n not\n} from \"./functional.js\";\nimport {\n isTextual,\n isPicture,\n isQuestion,\n isVisible\n} from \"./control-helpers.js\";\nimport { groupOuter, baseGroup, tailGroup, pathGroup } from \"./groupings\";\nimport { normalize } from \"./font-classes\";\nimport { getWidget } from \"./form-widgets.js\";\nimport { conf } from \"./conf\";\nimport * as n from \"./names.js\";\nimport { names } from \"./names.js\";\n\nconst doTopLevel = pathOr(true, [\n \"arbitrary\",\n \"core\",\n \"form-group\",\n \"toplevel\"\n]);\n\nconst doLegends = pathOr(true, [\n \"arbitrary\",\n \"core\",\n \"form-group\",\n \"doLegends\"\n]);\n\nconst getLayout = type =>\n pathOr(compose(prop(\"layout\"), getWidget)(type), [\n \"arbitrary\",\n \"form-group\",\n type\n ]);\n\nconst getGroupName = compose(when(Boolean, baseGroup), pathGroup, head);\n\n// Interface Font Style\nconst questionGroupClass = compose(\n s => names(n.QUESTION_PREFIX_AUTHORSTYLE) + s,\n normalize,\n prop(\"font-class\")\n);\n\n// interface metadata: cssclasses=\nexport const extraClasses = prefix =>\n compose(\n when(\n Boolean,\n compose(\n join(\" \"),\n map(compose(s => names(prefix) + s, normalize)),\n split(\" \")\n )\n ),\n path([\"metadata\", \"cssclasses\"])\n );\n\nconst asciify = s => s.replace(/[^a-z-]/g, \"-\");\n\nconst areAllInvisible = compose(not, any(isVisible));\nconst areAllReadonly = both(\n any(both(isQuestion, isVisible)),\n compose(all(prop(\"originalreadonly\")), filter(both(isQuestion, isVisible)))\n);\n\nconst areAllNotNull = both(\n any(both(isQuestion, isVisible)),\n compose(all(prop(\"notnull\")), filter(both(isQuestion, isVisible)))\n);\n\nconst updateClassWhen = curry((className, fn, controls, elt) => {\n elt.classList.toggle(className, fn(controls));\n});\n\nconst setReadonlyFGClass = updateClassWhen(\n names(n.GROUPING_PREFIX_TYPE) + \"-readonly\",\n areAllReadonly\n);\nconst setEmptyFGClass = updateClassWhen(\n names(n.GROUPING_PREFIX_TYPE) + \"-empty\",\n areAllInvisible\n);\nconst setRequiredFGClass = updateClassWhen(\n names(n.GROUPING_PREFIX_TYPE) + \"-required\",\n areAllNotNull\n);\n\nconst setReadonlyQClass = updateClassWhen(\n names(n.QUESTION_PREFIX_PROPERTY) + \"-readonly\",\n areAllReadonly\n);\nconst setEmptyQClass = updateClassWhen(\n names(n.QUESTION_PREFIX_PROPERTY) + \"-empty\",\n areAllInvisible\n);\nconst setRequiredQClass = updateClassWhen(\n names(n.QUESTION_PREFIX_PROPERTY) + \"-required\",\n areAllNotNull\n);\n\nexport const createFormGroup = (wControl, group, level) => c => {\n let formGroup;\n const groupName = getGroupName(c);\n\n if (\n groupName ||\n (doTopLevel(conf) &&\n (doLegends(conf) || !all(propEq(\"controltype\", \"legend\"))(c)))\n ) {\n formGroup = document.createElement(\"div\");\n formGroup.className = names(n.GROUPING_CLASS);\n formGroup.setAttribute(names(n.GROUPING_DATA_LEVEL), level);\n setEmptyFGClass(c, formGroup);\n setReadonlyFGClass(c, formGroup);\n setRequiredFGClass(c, formGroup);\n formGroup.addEventListener(\"bb:updatedControl\", ({ detail }) => {\n if (has(\"visible\", detail.Updates)) {\n setEmptyFGClass(c, formGroup);\n }\n if (has(\"readonly\", detail.Updates)) {\n setReadonlyFGClass(c, formGroup);\n }\n if (has(\"notnull\", detail.Updates)) {\n setRequiredFGClass(c, formGroup);\n }\n });\n if (groupName) {\n formGroup.setAttribute(names(n.GROUPING_DATA_NAME), asciify(groupName));\n formGroup.classList.add(names(n.GROUPING_PREFIX_TYPE) + \"-author\");\n } else if (find(isQuestion, c)) {\n formGroup.classList.add(names(n.GROUPING_PREFIX_TYPE) + \"-interface\");\n } else if (compose(isPicture, head)(c)) {\n formGroup.classList.add(names(n.GROUPING_PREFIX_TYPE) + \"-picture\");\n } else if (compose(isTextual, head)(c)) {\n formGroup.classList.add(names(n.GROUPING_PREFIX_TYPE) + \"-text\");\n }\n } else {\n formGroup = document.createDocumentFragment();\n }\n\n const cWithin = compose(\n groupOuter,\n map(\n when(\n pathGroup,\n tap(control =>\n compose(\n ifElse(\n s => s === \"\",\n () => delete control.metadata.group,\n group => (control.metadata.group = group)\n ),\n tailGroup\n )(control.metadata.group)\n )\n )\n )\n )(c);\n cWithin.forEach(\n cond([\n [\n getGroupName,\n compose(\n n => formGroup.appendChild(n),\n createFormGroup(wControl, group, level + 1)\n )\n ],\n [\n any(isQuestion),\n controls => {\n const answer = find(isQuestion, controls);\n const classes = [\n names(n.QUESTION_CLASS),\n `${names(n.QUESTION_PREFIX_TYPE)}-${answer.controltype}`,\n questionGroupClass(answer),\n extraClasses(n.ITEM_PREFIX_AUTHORCLASS)(answer),\n controls.length === 1 && names(n.QUESTION_CLASS_NOLABEL)\n ].filter(Boolean);\n const qlg = document.createElement(\"div\");\n qlg.setAttribute(\n names(n.QUESTION_DATA_LAYOUT),\n answer._layout || getLayout(answer.controltype)(conf)\n );\n qlg.className = classes.join(\" \");\n setEmptyQClass(controls, qlg);\n setReadonlyQClass(controls, qlg);\n setRequiredQClass(controls, qlg);\n qlg.addEventListener(\"bb:updatedControl\", ({ detail }) => {\n if (has(\"visible\", detail.Updates)) {\n setEmptyQClass(controls, qlg);\n }\n if (has(\"readonly\", detail.Updates)) {\n setReadonlyQClass(controls, qlg);\n }\n if (has(\"notnull\", detail.Updates)) {\n setRequiredQClass(controls, qlg);\n }\n });\n controls.forEach(c => wControl(c, group, $(qlg)));\n formGroup.appendChild(qlg);\n }\n ],\n [\n () => true,\n map(c => {\n const $widget = wControl(c, group, $(formGroup));\n if ($widget)\n $widget.addClass(extraClasses(n.ITEM_PREFIX_AUTHORCLASS)(c));\n })\n ]\n ])\n );\n return formGroup;\n};\n", "/* global $ */\nimport { html, render } from \"lit\";\nimport { Maybe } from \"@cahmoraes93/maybe\";\nimport { A11y, observeDatepickers } from \"./a11y.js\";\nimport { conf, propFinder } from \"./conf.js\";\nimport { wControl, getControl } from \"./control.js\";\nimport { quotable } from \"./quotable.js\";\nimport {\n isLabel,\n isOption,\n isQuestion,\n isReadOnly,\n renderAttribs,\n setAttribs\n} from \"./control-helpers.js\";\nimport { checkDate, onChangeDate, parseDate, leadWithZeroes } from \"./dates.js\";\nimport { escapeHTML } from \"./escape.js\";\nimport { registerWidget } from \"./form-widgets.js\";\nimport {\n allPass,\n always,\n applyTo,\n both,\n compose,\n chain,\n dec,\n dissoc,\n find,\n F,\n gt,\n head,\n has,\n ifElse,\n inc,\n join,\n map,\n mergeLeft,\n path,\n propEq,\n when,\n pathEq,\n reverse,\n pipe,\n lensPath,\n lensProp,\n over,\n append,\n assoc,\n infichain,\n toLower,\n omit,\n nth,\n prop,\n propOr,\n equals,\n tap\n} from \"./functional.js\";\n\nimport { _ } from \"./gettext.js\";\nimport { fromApiServer } from \"./location.js\";\nimport { forceInRange, Numerals } from \"./numerals.js\";\nimport { format, formatPlus } from \"./text-utils.js\";\nimport { urlutils } from \"./url-utils.js\";\n\nconst arbitraryCoreProp = propFinder(conf, \"arbitrary.core\");\n\nfunction disconnectValue({ input, value, filter = x => x }) {\n input.setAttribute(\"data-server-value\", value);\n $(input).on(\"change\", function () {\n try {\n var newVal = filter(input.value, input);\n } catch (e) {\n //\n } finally {\n if (typeof newVal !== \"undefined\") {\n input.setAttribute(\"data-server-value\", newVal);\n }\n }\n });\n}\n\nconst noAttribs = always({});\n\nconst omitName = dissoc(\"name\");\nconst omitRequired = dissoc(\"aria-required\");\n\nconst emptyTag = (tagName, attribs) => {\n const elt = document.createElement(tagName);\n setAttribs(elt, attribs);\n return elt;\n};\nconst valueInside = (control, attribs, tagName) => {\n const elt = emptyTag(tagName, attribs);\n if (tagName === \"textarea\") {\n elt.value = control.value;\n } else {\n elt.innerHTML =\n control.text || escapeHTML(control.value).replace(/\\r?\\n/g, \" \");\n }\n return elt;\n};\n\nconst checkbox = {\n name: \"checkbox\",\n render: (control, group, attribs) => {\n return emptyTag(\"input\", attribs);\n },\n attribs: (attr, control, enabled) =>\n Object.assign(\n {},\n attr,\n {\n type: \"checkbox\"\n },\n //Interface already has got a value server-side, so not\n //sending it back poses no problem.\n control.value && { checked: true }\n ),\n setValue: (input, value, requestor) => {\n input.checked = value;\n },\n layout: \"inline\"\n};\n\nregisterWidget(checkbox);\n\nconst picture = {\n name: \"picture\",\n render: (control, group, attribs) => emptyTag(\"img\", attribs),\n attribs: (attr, control, enabled) =>\n Object.assign({}, attr, {\n alt: control.alttext,\n src: fromApiServer(control.filename)\n })\n};\n\nregisterWidget(picture);\n\nexport const edit = {\n name: \"edit\",\n couldWrap: true,\n attribs: (attr, control, enabled) =>\n Object.assign({}, attr, {\n type: \"text\",\n autocomplete: \"off\",\n value: control.value\n }),\n render: (control, group, attribs) => emptyTag(\"input\", attribs),\n setValue: (input, value) => {\n input.value = value;\n },\n layout: \"aside\"\n};\n\nregisterWidget(edit);\n\nconst memo = {\n name: \"memo\",\n attribs: (attr, control, enabled) => {\n // const attribs = [\"name\", control.name];\n // if (control.width && control.height && control[\"font-size\"]) {\n // attribs.cols= parseInt(control.width / (control[\"font-size\"] * 0.75))\n // attribs.rows = parseInt(control.height / (control[\"font-size\"] * 1.5))\n // }\n // return [...attr, ...attribs];\n return attr;\n },\n render: (control, group, attribs) => {\n return valueInside(control, attribs, \"textarea\");\n },\n setValue: edit.setValue,\n layout: \"below\"\n};\n\nregisterWidget(memo);\n\nconst label = {\n name: \"label\",\n fixup: control => {\n control.value = (control.value || \"\").replace(/\\r\\n/g, \"\\n\"); // Normalize Windows-style (typewriter) newlines\n return control;\n },\n attribs: (attr, control, enabled) =>\n Object.assign(\n omitName(attr),\n enabled && control.isFor && { for: control.isFor },\n {\n class: `${\n control.isfor || has(\"colname\", control) ? \"bb-label\" : \"bb-text\"\n } bb-md-able`\n }\n ),\n render: (control, group, attribs) => {\n return valueInside(\n control,\n attribs,\n control._subtype === \"heading\"\n ? \"h\" + Math.min(6, control._level || 2)\n : control.isFor\n ? \"label\"\n : \"div\"\n );\n },\n setValue: (input, value) => {\n input.innerHTML = escapeHTML(value).replace(/\\r?\\n/g, \" \");\n }\n};\n\nregisterWidget(label);\n\nexport const linklabel = {\n name: \"linklabel\",\n fixup: control => {\n control.value = control.value.trim();\n // Fix 'empty' or JS-links\n if (urlutils.isEmptyish(control.url) || urlutils.isJS(control.url)) {\n if (urlutils.isJS(control.url)) control.value = urlutils.JSAlertMessage;\n delete control.url;\n }\n return control;\n },\n attribs: (attr, control, enabled) => {\n let linkClassName = \"\";\n\n if (control.url) {\n attr[\"href\"] = fromApiServer(control.url);\n if (control.url.match(/mailto:/)) {\n attr[\"type\"] = \"email\";\n linkClassName = \"mail\";\n } else {\n linkClassName = \"bb-external\";\n if (control.isreport) linkClassName += \" report\";\n var mimetype = control.mimetype || urlutils.mimetype(control.url);\n if (mimetype) {\n attr[\"type\"] = mimetype.mimetype;\n linkClassName += \" \" + mimetype.ext;\n }\n }\n if (control.url[0] !== \"#\") attr[\"target\"] = \"_blank\";\n }\n linkClassName += \" bb-text\";\n attr[\"class\"] = linkClassName;\n return omitName(attr);\n },\n render: (control, group, attribs) => {\n return valueInside(control, attribs, \"a\");\n },\n setValue: (input, value) => {\n input.innerHTML = escapeHTML(value).replace(/\\r?\\n/g, \" \");\n },\n layout: \"below\"\n};\n\nregisterWidget(linklabel);\n\nconst listlabel = {\n name: \"listlabel\",\n attribs: compose(\n omitName,\n omitRequired,\n mergeLeft({\n type: \"listlabel\",\n class: \"listlabel\"\n })\n ),\n item: item =>\n `
\"\n );\n };\n\nfunction isCaseCurrent(casus) {\n return (\n casus.sessionid == Vars.getVar(\"sessionid\") &&\n casus.dbname == Vars.getVar(\"dbname\")\n );\n}\n\nfunction deleteCase(dbname, sessionid, uniqueid) {\n // Ajax.last && Ajax.last.abort();\n // todo: voeg nieuwe waarden toe aan object.\n Ajax.post({\n url: \"delete\",\n data: {\n dbname,\n sessionid,\n uniqueid,\n fmt: \"json\"\n }\n });\n}\n\n$(document).on(\"click keydown\", \".bb-case-delete\", function (ev) {\n if (ev.type === \"keydown\" && ev.keyCode !== KEYS.ENTER) return;\n $(this).parents(\".bb-case\").deleteme();\n});\n\nfunction newcase(dbname, newname, params = {}) {\n const data = Object.assign(\n {},\n Object(params) === params && params,\n {\n dbname: dbname,\n uniqueid: Vars.getVar(\"uniqueid\"),\n step: \"open\",\n fmt: \"json\"\n },\n newname && { newname }\n );\n if (Vars.getVar(\"sessionid\"))\n step(\"exit\", function (jsondata) {\n Ajax.busy = false;\n if (jsondata.status === \"Ready\") {\n Ajax.replace({ data: data });\n }\n });\n else {\n Ajax.replace({ data: data });\n }\n}\n\n$(document).on(\"click keydown\", \".bb-newname\", function (ev) {\n if (ev.type === \"click\" || aintTheEnterKey(ev)) ev.stopPropagation();\n return true;\n});\n\n$(document).on(\"click keydown\", \".bb-newcase\", function (ev) {\n if (aintTheEnterKey(ev)) return true;\n const $this = $(this),\n dbname =\n this.getAttribute(\"data-bb:dbname\") ||\n $this.parents(\".bb-model\").attr(\"data-bb:dbname\"),\n newname = $this.find(\".bb-newname\").val(),\n params = collectAttributes(\"data-bb:params-\", this);\n newcase(dbname, newname, params);\n return false;\n});\n\n/*** CASES END ***/\n\n/*** MODELS BEGIN ***/\nvar Models = {\n selector: \"#bb-models\",\n modelitem: function (model) {\n model.uniqueid = Vars.getVar(\"uniqueid\");\n return (\n (bb.createModelItem && bb.createModelItem(model)) ||\n (function (model) {\n var dbname = model.dbname;\n return (\n '
' +\n \"
\" +\n '\" +\n \"
\" +\n '
\" +\n \"
\"\n );\n })(model)\n );\n },\n // Enhance Model with extra computed properties:\n enhanceModel: function (model) {\n model._selectedclass = model.selected ? \"selected\" : \"\";\n model._nicename = model.modelname.replace(/_/g, \" \");\n if (model.lastupdate) {\n model._date = parseDate(model.lastupdate);\n model._humandate = humanDate(model._date);\n }\n if (model.modelinfo) {\n model._liner_notes = model.modelinfo.split(/(?:\\r?\\n|\\\\r\\\\n|\\\\n)/);\n }\n if (model.authorinfo) {\n model._author_notes = model.authorinfo.split(/(?:\\r?\\n|\\\\r\\\\n|\\\\n)/);\n }\n return model;\n },\n update: function (data) {\n var models = data.models;\n models.sort(compareVersionsOn.bind(null, \"modelname\"));\n\n var explicit = models.filter(function (m) {\n return typeof m[\"order\"] === \"number\";\n });\n if (explicit[0]) {\n explicit.sort(function (a, b) {\n return (\n a[\"order\"] - b[\"order\"] ||\n compareVersions(String(a[\"order\"]), String(b[\"order\"]))\n );\n });\n models = models.filter(function (m) {\n // absent (undefined) or the empty string\n return typeof m[\"order\"] !== \"number\";\n });\n models = explicit.concat(models);\n }\n\n this.empty();\n var self = this;\n $(this.selector).append(\n $.map(models, function (model) {\n return self.modelitem(self.enhanceModel(model));\n })\n );\n },\n empty: function () {\n $(this.selector).empty();\n }\n};\n\n$(document).on(\"click keydown\", \".bb-model-cases\", function (ev) {\n if (aintTheEnterKey(ev)) return;\n var $this = $(this),\n dbname =\n this.getAttribute(\"data-bb:dbname\") ||\n $this.parents(\".bb-model\").attr(\"data-bb:dbname\");\n Ajax.replace({\n url: \"menu\",\n data: {\n dbname: dbname,\n uniqueid: Vars.getVar(\"uniqueid\"),\n fmt: \"json\"\n },\n dataType: \"json\"\n });\n});\n/*** MODELS END ***/\n\n/*** NAVIGATION, REQUESTS BEGIN ***/\n\n/**\n * Request 'action'\n *\n * @param {String} direction One of 'prior', 'next', 'exit', 'runtonode', 'gotonode', 'update' or 'updatemis'\n * @param {Function} cb Callback function to run on succes, defaults to checkJSON()\n * @param {Object} options Object, with possible keys: 'fullnodename' : 'graph.node',\n * 'groupid' : 'groupid-iteration',\n * 'sync' : Boolean\n */\nfunction step(direction, cb, options = {}) {\n Validation.reset();\n if (Ajax.busy) return;\n\n Ajax.last && Ajax.last.abort();\n Ajax.direction = direction;\n Ajax.row = Ajax.direction === \"update\" && options && options.update;\n\n try {\n if (\n [\"next\", \"skip\"].includes(direction) &&\n $(\"#bb-q .group:not([disabled]) .validatable:visible\")\n .validate({ silent: false, justhide: false, requestUpdate: false })\n .filter(\"[aria-invalid=true]\").length > 0\n )\n throw new Error(\"There are errors, please double check your answers.\");\n\n const container = either(prop(\"groupElt\"), () =>\n document.querySelector(\".group.selected\")\n )(options);\n const screenid = Vars.getVar(\"screenid\");\n const groupid = $.data(container).groupid;\n Ajax.groupid = groupid;\n\n // todo: voeg nieuwe waarden toe aan object.\n if (!(direction === \"prior\" && Mode.get(\"hasNoPrior\"))) {\n const ajaxOptions = {\n async: true && (!options || !options.sync), //See noted render() as a reason for this.\n data: [\n \"step=\" + direction,\n direction === \"update\" && options && options.update\n ? \"update=\" + encodeURIComponent(options.update)\n : \"\",\n direction === \"runtonode\"\n ? \"fullnodename=\" + options.fullnodename\n : \"\",\n direction === \"gotonode\" ? \"groupid=\" + options.groupid : \"\",\n Vars.querify(Vars.SESSION_KEYS),\n \"screenid=\" + groupid,\n \"fmt=json\",\n collectWithin({\n container,\n params: new URLSearchParams(options.extraparams)\n })\n .toString()\n .replace(/\\r?\\n/g, \"%0D%0A\")\n ]\n .filter(Boolean)\n .join(\"&\"),\n success: function (data, status, req) {\n data._direction = direction;\n data._passed = options && options.pass;\n data._isUpdate = propEq(\"isUpdate\", true, options);\n // if (direction === \"update\" && groupid !== screenid && editPolicy(conf) === \"stay\") {\n // container.classList.remove(\"unselected\");\n // container.classList.add(\"selected\");\n\n // // Do not render, just update\n // Ajax.release();\n // Vars.setVars(data);\n // updateDynProps(data);\n // } else\n\n if (groupid !== screenid && editPolicy(conf) === \"return\") {\n // Do not render, we're going back again. This would be\n // nice, but we do need some values to be rerendered -\n // warranting redraw of nodes after the edited one.\n\n Ajax.release();\n Vars.setVars(data);\n } else if (options && options.cbIsAdditional) {\n options.cbIsAdditional === \"before\" && cb && cb(data, status, req);\n checkJSON(data, status, req);\n options.cbIsAdditional !== \"before\" && cb && cb(data, status, req);\n } else {\n (cb || checkJSON)(data, status, req);\n }\n if (\n Ajax.row &&\n groupid === screenid &&\n compose(\n when(Boolean, any(propEq(\"dynamic\", true))),\n prop(\"groups\")\n )(data)\n ) {\n console.info(\n \"Requesting an extra update for dynprops. Should be handled by server instead\"\n );\n window.setTimeout(bb.update, 0);\n }\n }\n };\n\n if (\n screenid !== undefined &&\n direction !== \"update\" &&\n groupid !== screenid\n ) {\n console.warn(\n `groupid ${groupid} is not the current screenid ${screenid}, but no update was requested`\n );\n }\n if (direction === \"update\" && groupid !== screenid) {\n // Hold your breath, first go back, so as to put server pointer at the right node.\n bb.gotonode(\n // Will get the .selected\n groupid,\n data => {\n Ajax.release();\n Vars.setVars(data); // Sets screenid\n Ajax.direction = direction;\n // Is always \"update\", actually;\n Ajax.row = direction === \"update\" && options && options.update;\n Ajax.groupid = groupid;\n const req = Ajax.post(ajaxOptions); // Gets the original callback, if any.\n if (editPolicy(conf) === \"return\")\n req.then(data => {\n Ajax.release();\n Vars.setVars(data);\n\n bb.gotonode(\n screenid,\n () => {\n // The gotonode invocation just overwrote the direction and row.\n Ajax.direction = direction;\n Ajax.row =\n direction === \"update\" && options && options.update;\n if (!Ajax.row) cb && cb();\n },\n {\n cbIsAdditional: \"before\",\n groupElt: container,\n isUpdate: true\n }\n );\n });\n },\n { sync: false, cbIsAdditional: false }\n );\n } else {\n Ajax.post(ajaxOptions);\n }\n }\n } catch (e) {\n $(document).trigger(\"bb:userError\", e.message);\n A11y.log(_(e.message));\n }\n}\n\nlet lastUpdateRequest;\n\nfunction requestDynProps(input) {\n if (Ajax.busy) return;\n\n var thisUpdateRequest;\n\n Ajax.last && Ajax.last.abort();\n Ajax.direction = \"update\";\n // Ajax.row = Ajax.direction === 'update' && options && options.update;\n\n const ajaxOptions = {\n async: true,\n data: [\n \"step=update\",\n Vars.querify(Vars.NAV_KEYS),\n \"fmt=json\",\n serializeQuestions()\n ]\n .filter(Boolean)\n .join(\"&\"),\n success: (...args) => {\n if (thisUpdateRequest === lastUpdateRequest) {\n $(document).trigger(\"bb:preHandleData\", ...args);\n updateDynProps(args[0], input);\n }\n }\n };\n lastUpdateRequest = thisUpdateRequest = Ajax.post(ajaxOptions);\n}\n\n// bb:prePost handler always goes off on bb.ajax.post.\n$(document).on(\"bb:prePost\", function (event, options) {\n if (includes(options.url, [\"action\", \"open\", \"bbisreturns\"]))\n if (!includes(Ajax.direction, [\"update\", \"updatemis\"]))\n $(document).trigger(\"bb:preStep\", options);\n});\n\n// bb:preStep handler goes off after user-initiated, possibly\n// expensive, actions.\n$(document).on(\"bb:preStep\", function () {\n Ajax.busy = true;\n // Hide lingering calendars\n $(\".group.selected .hasDatepicker\").datepicker(\"hide\");\n A11y.log(\"\");\n});\n\n// Save\n$(document).on(\"click\", \".bb-save\", function () {\n step(\"save\", null);\n});\n\n// Update\n$(document).on(\"click\", \"[name=update]\", function (ev) {\n step(\"update\", null, {\n update: $(this).val(),\n groupElt: ev.target.closest(\".group\")\n });\n});\n\n// Prior\n$(document).on(\"click\", \".bb-prior\", function () {\n step(\"prior\");\n});\n\n// Next\n$(document).on(\"click\", \".bb-next\", function (ev) {\n bb.next();\n ev.preventDefault();\n ev.stopImmediatePropagation();\n return false;\n});\n\n// Skip\n$(document).on(\"click\", \".bb-skip\", function (ev) {\n bb.skip();\n ev.preventDefault();\n ev.stopImmediatePropagation();\n return false;\n});\n\n$(document).on(\"keydown\", \".group a\", function (ev) {\n if (\n ev.shiftKey &&\n ev.keyCode === KEYS.ENTER &&\n ev.target.href.substr(-1) !== \"#\"\n ) {\n // true link BUT SHIFT + ENTER\n bb.next();\n ev.preventDefault();\n ev.stopImmediatePropagation();\n return false;\n }\n return true;\n});\n\n// Close\n$(document).on(\"click\", \".bb-close\", function () {\n logout();\n self.close();\n $(\"body\").html(_(\"You may now safely close this window\"));\n});\n\n// Restart\n$(document).on(\"click\", \".bb-restart\", function (event) {\n if (\n \"noconfirm\" in event.currentTarget.dataset ||\n confirm(_(\"Are you sure? This will reset all values.\"))\n )\n bb.restart();\n return false;\n});\n\n/**\n * Log out\n *\n * @param {Boolean} ev Either a jQuery event or not\n * @param {Function} cb Callback function to be run after logout.\n * Supercedes default action on Ajax request. @see Ajax.post.\n */\n\nconst timedOutResponse = () => ({\n error: {\n code: 9 //Errors.CODES.cWebSessionTimeOut\n }\n});\n\nfunction logout(ev, cb) {\n if (Vars.getVar(\"uniqueid\")) {\n exit(function () {\n const options = {\n url: \"logout\",\n data: \"fmt=json&\" + Vars.querify(\"uniqueid\"),\n async: false\n };\n // When called directly, which\n if (cb instanceof Function) {\n options.success = options.error = cb;\n }\n Ajax.post(options);\n });\n } else {\n console && console.info && console.info(\"Fake logging out, ID is missing\");\n const mockResponse = timedOutResponse();\n ((cb instanceof Function && cb) || checkJSON)(mockResponse, 200, {\n responseJSON: mockResponse,\n responseText: JSON.stringify(mockResponse)\n });\n }\n return false;\n}\n\n$(document).on(\"click\", \".bb-logout\", logout);\n$(document).on(\"keydown\", \".bb-logout\", function (ev) {\n if (ev.keyCode !== KEYS.ENTER && ev.keyCode !== KEYS.SPACE) return true;\n logout(ev);\n return false;\n});\n\n/** Exit\n *\n * Exit the current case;\n * @param {Function} fun Function to execute after having exited.\n * If exiting isn't necessary, still execute fun.\n */\nfunction exit(fun, sync = true) {\n if (typeof fun !== \"function\")\n // Could be an event object on .bb-stop\n fun = undefined;\n if (shouldExit()) {\n step(\"exit\", fun, { sync });\n } else fun && fun();\n}\n\n$(document).on(\"click\", \".bb-stop\", exit);\n\n// Request 'getuserinfo'\nfunction getUserInfo() {\n $.postJSON(\"getuserinfo\", Vars.querify(\"uniqueid\") + \"&fmt=json\");\n}\n\n/*** NAVIGATION, REQUESTS END ***/\n\n/*** MENU BEGIN ***/\n\nfunction setupMenu() {\n $(\".bb-settings\").attr({ target: \"blank\" });\n}\n\n// Open WebAdmin (in new page)\nfunction openSettings() {\n var href = fromApiServer(\"webadmin\" + \"?\" + Vars.querify(\"uniqueid\"));\n window.open(href);\n return false;\n}\n\n$(document).on(\"click\", \".bb-settings\", openSettings);\n$(document).on(\"keydown\", \".bb-settings\", function (ev) {\n if (ev.keyCode !== KEYS.ENTER && ev.keyCode !== KEYS.SPACE) return true;\n openSettings(ev);\n return false;\n});\n\n/** menu\n *\n * Open menu (model overview)\n * @param {String|Object|undefined} creds Optional credentials,\n * defaults to fmt:json and uniqueid\n */\nfunction menu(creds) {\n return $.postJSON(\n \"menu\",\n creds || {\n fmt: \"json\",\n uniqueid: Vars.getVar(\"uniqueid\")\n }\n );\n}\n\n/** exitthenmenu\n *\n * Exit a case, then open a menu\n * @param {Event} ev Optional event whose propagation will be stopped\n */\nfunction exitthenmenu(ev) {\n exit(function () {\n menu();\n });\n ev && ev.stopPropagation && ev.stopPropagation();\n}\n\n$(document).on(\"click\", \".bb-openmodels\", exitthenmenu);\n$(document).on(\"keydown\", \".bb-openmodels\", function (ev) {\n if (ev.keyCode !== KEYS.ENTER) return;\n exitthenmenu(ev);\n});\n\n/*** MENU END ***/\n\n/*** MISC UI BEGIN ***/\n\nfunction hideLogin() {\n $(\"form#bb-login\").hide();\n}\n\n/**\n * Simple class toggling to implement collapsing/expanding widgets.\n *\n * Needs CSS styling and / or Event handler registered on custom\n * jQuery 'bb:collapsing' Event.\n */\n$(document).on(\"click keydown\", \".bb-collapsable .bb-collapser\", function (ev) {\n if (aintTheEnterKey(ev) || ev.shiftKey) return true;\n $(this)\n .closest(\".bb-collapsable\")\n .toggleClass(\"bb-collapsed\")\n .trigger(\"bb:collapsing\");\n return false;\n});\n\n/*** MISC UI END ***/\n\n/*** DATA HANDLERS BEGIN ***/\n\n/**\n * Default handlers for JSON object.\n *\n * Order in which these handlers are executed are:\n *\n * bb:preHandleData\n * bb:handleData\n * bb:postHandleData\n * bb:finalHandleData\n */\n\n$(document).on(\"bb:preHandleData\", function (event, data) {\n if (data && data.groups) {\n data.groups.forEach(function (group) {\n const groupid = group.groupid;\n group.controls.forEach(function (control) {\n control._originalid = control.id;\n control.id = groupid + \"-\" + control.id;\n if (control.isfor) {\n control._originalisfor = control.isfor;\n control.isfor = groupid + \"-\" + control.isfor;\n }\n if (control.controltype === \"label\") {\n control.value = control.value.trim();\n if (control.isfor && control.value)\n control.value = control.value + \" \";\n }\n if (\n control.controltype === \"memo\" &&\n control.maxlength > 0 &&\n !control.placeholder\n ) {\n control.placeholder = positionalFormat(\n _(\"Maximum allowed characters: {0}\"),\n control.maxlength\n );\n }\n });\n });\n }\n});\n/**\n * Default handler for JSON object.\n *\n * Sets mode, variables, calls functions to update UI.\n *\n */\nfunction onHandleData(event, data) {\n // Save previous modus - it will be the next modus if unset.\n var modus = $(\"body\").attr(\"data-modus\"); // Either 'model', 'menu', or 'none'\n\n Mode.unset(\"hasMessage\");\n if (typeof data == \"undefined\") return;\n if (typeof document.selection != \"undefined\")\n try {\n document.selection.removeAllRanges();\n } catch (e) {\n // tryCatch was there for IE's sake. probably because we were\n // using Selection.empty()\n }\n\n // Fix error objects - they are a mess\n if (data.error) {\n data.error = Errors.translate(data.error);\n // Do not throw the error just yet - we may need it to\n // get in the right mode\n }\n\n Vars.setVars(data);\n\n if (data.userinfo) {\n Mode.set(\"isLoggedIn\");\n setRole();\n setupMenu();\n return;\n }\n\n if (\n data.error &&\n ([\n Errors.CODES.cWebPleaseLogin,\n Errors.CODES.cUMWrongUserNamePassword,\n Errors.CODES.cWebSessionTimeOut\n ].indexOf(data.error.code) > -1 ||\n data.error.code === \"UNAUTHORIZED\")\n ) {\n // Do nothing\n } else if (has(\"bbis\", data)) {\n // Authenticate through BBI\n new BBI(data).authenticate();\n return;\n } else if (Vars.getVar(\"uniqueid\")) {\n // We are apparently logged in\n hideLogin();\n if (!Vars.getVar(\"userinfo\")) {\n // Get user information\n getUserInfo();\n }\n }\n\n // \"DrawScreen: end\"\n /* Only set modus if this is possibly mode-changing data (e.g.\n * DON'T even go here when data.userinfo is true).\n */\n if (data.status || data.groups || data.cases || data.models || data.error) {\n if (data.groups) modus = \"model\";\n else if (\n data.models ||\n data.cases ||\n (data.status && data.status == \"Ready\")\n ) {\n modus = \"menu\";\n } else if (data.status && data.status == \"logout successful\") {\n modus = \"none\";\n } else if (data.error && data.error.code === Errors.CODES.cWebPleaseLogin) {\n modus = \"none\";\n } else if (\n data.error &&\n data.error.code === Errors.CODES.cUMWrongUserNamePassword\n ) {\n modus = \"none\";\n } else if (\n data.error &&\n data.error.code === Errors.CODES.cWebSessionTimeOut\n ) {\n modus = \"none\";\n } else if (data.error && data.error.code === \"READY\") {\n modus = \"menu\";\n }\n $(\"body\").attr(\"data-modus\", modus);\n // Set current modus\n\n // Clean up state vars that were left over\n if (modus === \"menu\") {\n Vars.unsetVars([\"sessionid\", \"screenid\"]); // Session specific data\n }\n if (modus === \"none\") {\n const perms = permissions();\n Vars.unsetVars();\n perms.forEach(p => {\n Mode.toggle(p, false, false);\n });\n }\n\n // Will need to be seen with every control\n Mode.unset(\"hasHints\");\n\n if (!data.error)\n Mode.toggle(\"hasNoModelsShown\", modus !== \"menu\")\n\n .toggle(\"hasModel\", modus === \"model\")\n\n .toggle(\"hasMenu\", modus === \"menu\")\n\n .toggle(\n \"hasModels\",\n modus === \"menu\" && !!data.models && !!data.models.length\n )\n\n .toggle(\n \"hasCases\",\n modus === \"menu\" && !!data.cases && !!data.cases.length\n )\n\n .toggle(\n \"hasJumplist\",\n modus === \"model\" && !!data.jumplist && !!data.jumplist.length\n )\n\n .toggle(\n \"hasInformationsources\",\n modus === \"model\" &&\n data.informationsources &&\n !!data.informationsources.length\n )\n\n .toggle(\"hasNoPrior\", modus === \"model\" && !data.hasprevious)\n\n .toggle(\"hasNoNext\", modus === \"model\" && !data.hasnext);\n\n Mode.toggle(\"isLoggedIn\", modus !== \"none\");\n\n if (modus === \"none\") {\n Mode.unset(\"isDeepLinked\");\n setRole(); // Sets Mode\n }\n if (modus !== \"model\") {\n Mode.unset(\"isValidated\");\n }\n }\n\n if (\n data.error &&\n !includes(data.error.code, propOr([], \"ignoredErrorCodes\", conf))\n ) {\n notify(\n {\n keepalive: path([\"arbitrary\", \"core\", \"notify\", \"keepalive\"], conf),\n html: false\n },\n data.error\n );\n }\n\n // View updates\n if (data.modeldescription) {\n $(\".bb-modelname\")\n .text(data.modeldescription.replace(/_/g, \" \"))\n .attr(\"lang\", data.modellanguage);\n } else if (modus !== \"model\") {\n $(\".bb-modelname\").text(\"\");\n }\n\n if (modus !== \"model\") {\n $(\"#bb-q\").empty();\n }\n\n if (modus !== \"menu\") {\n Cases.empty();\n Models.empty();\n }\n\n if (modus === \"none\") {\n resetLogin();\n }\n\n if (modus === \"none\") {\n Mode.unset(\"hasModel\")\n .unset(\"hasNoModelsShown\")\n .unset(\"hasMenu\")\n .unset(\"hasModels\")\n .unset(\"hasCases\")\n .unset(\"hasJumplist\")\n .unset(\"hasInformationsources\")\n .unset(\"hasNoPrior\")\n .unset(\"hasNoNext\");\n }\n\n if (modus === \"menu\") {\n if (data.models && !!data.models.length) {\n Models.update(data);\n }\n if (data.cases && !!data.cases.length) {\n Cases.update(data.cases);\n }\n }\n\n if (modus === \"model\") {\n if (data.groups) {\n Validation.reset();\n $(document).trigger(\"bb:renderQuestions\", data);\n }\n Validation.setMode(); // Sets Mode\n\n $(\".bb-openattachments\").attr(\"href\", urlutils.getFiles());\n\n // if (data.informationsources){\n // runHook(\"informationsources\")(data.informationsources);\n // }\n if (data.jumplist) {\n Jumplist.type = arbitraryCoreProp(\"jumplist.type\") || \"ul\";\n Jumplist.draw(data.jumplist);\n }\n }\n}\n\n$(document).on(\"bb:handleData\", onHandleData);\n\n/**\n * Default final handler for JSON object.\n *\n * Runs after any DOM updates. Should only be used for focusing or non-UI stuff.\n *\n * Do not override (unless you know exactly what you are doing) --\n * just augment it if need be.\n *\n */\n$(document).on(\"bb:finalHandleData\", function () {\n bb.ajax.release();\n});\n\nlet returnfocusto, returnSelection;\n\nconst $document = $(document);\n\n$document.on(\"focus\", \":input\", ev => {\n const activeElement = ev.target;\n returnfocusto = activeElement.getAttribute(\"id\");\n if (activeElement.value)\n returnSelection = {\n selectionStart: 0,\n selectionEnd: activeElement.value.length,\n selectionDirection: \"forward\"\n };\n});\n\n$document.on(\"keydown\", \":input\", ev => {\n const activeElement = ev.target;\n const { selectionStart, selectionEnd, selectionDirection } = activeElement;\n returnSelection = { selectionStart, selectionEnd, selectionDirection };\n});\n\nfunction returnfocus() {\n try {\n let elt = document.querySelector(`[id=\"${returnfocusto}\"]`);\n if (elt) {\n elt.focus();\n if (elt.classList.contains(\"hasDatepicker\")) {\n $(elt).datepicker(\"widget\").hide();\n }\n let { selectionStart, selectionEnd, selectionDirection } =\n returnSelection;\n elt.setSelectionRange(selectionStart, selectionEnd, selectionDirection);\n }\n } catch (e) {\n // Checkbox throw an error that some object is not or no\n // longer usable. But how may we check?\n\n // Number inputs and such\n e.select && e.select();\n return true;\n }\n return false;\n}\n\nfunction focusHandler(event, data) {\n if (data.groups) {\n window.setTimeout(function () {\n const [grid, row] = (Ajax.row || \"\").split(\".\");\n var $input,\n focusstring = \":input:visible:enabled:not([readonly]):last\";\n if (row) {\n if (row === \"+\") {\n // Addbutton for entire grid\n $input = $(`.group [name=\"update\"][value=\"${grid}.+\"]`);\n } else {\n $input = $(\n '.group [name=\"' +\n grid +\n '\"] tbody tr:nth(' +\n row +\n \") \" +\n focusstring\n );\n // Might've been the last row - then focus the butlast one\n if (!$input.length)\n $input = $(\n '.group [name=\"' +\n grid +\n '\"] tbody tr:nth(' +\n (parseInt(row) - 1) +\n \") \" +\n focusstring\n );\n // Empty table? Focus addbutton\n if (!$input.length)\n $input = $(`.group [name=\"update\"][value=\"${grid}.+\"]`);\n }\n if ($input.length) {\n $input.trigger(\"focus\");\n }\n } else {\n // focus was lost\n if (\n both(\n complement(propEq(\"_isUpdate\", true)),\n complement(propEq(\"_direction\", \"update\"))\n )(data) ||\n (Mode.get(\"a-keyboard-user\") &&\n document.activeElement === document.body &&\n !returnfocus())\n ) {\n $(\".group.selected\").trigger(\"focus\");\n const e_group = document.querySelector(\".group.selected\");\n if (e_group === null) return;\n e_group.focus();\n if (doScrollToSelected(conf)) {\n if (e_group.previousElementSibling) {\n e_group.scrollIntoView({\n behavior: window.matchMedia(\"(prefers-reduced-motion: reduce)\")\n .matches\n ? \"auto\"\n : \"smooth\"\n });\n }\n }\n }\n }\n }, 0);\n return;\n }\n if (data.models && (!data.cases || !data.cases.length)) {\n $(\".bb-model-name:first\").trigger(\"focus\");\n $(\".bb-model.selected .bb-model-name:first\").trigger(\"focus\");\n return;\n }\n if (data.cases) {\n $(\"#bb-cases tbody .bb-case .bb-case-name:first\").trigger(\"focus\");\n return;\n }\n $(\"form#bb-login input[name=username]\").trigger(\"focus\");\n}\n\nfunction setupFocusHandler(event, data) {\n if (data.uniqueid) {\n $(document).on(\"bb:finalHandleData\", focusHandler);\n $(document).off(\"bb:finalHandleData\", setupFocusHandler);\n }\n}\n\n$(document).on(\"bb:finalHandleData\", setupFocusHandler);\n\nfunction updateDynProps(fulldata, input) {\n var data = {\n groups: fulldata.groups\n };\n $(document).trigger(\"bb:willUpdate\", fulldata);\n if (data && data.groups) {\n var group = data.groups.filter(function (group) {\n return group.current;\n })[0];\n let controls = sortControls(group.controls.slice(0), []);\n $(\n '.group [data-datatype^=\"datades:\"], .group [data-type=\"label\"]'\n ).updateControl(controls, input);\n Validation.setMode();\n }\n $(document).trigger(\"bb:hasUpdated\", fulldata);\n}\n\n$(document).on(\"bb:updated\", function (event, $widget, control, updates) {\n if (updates.indexOf(\"visible\") > -1 && control.identifier) {\n var $parent = $widget.parents(\".bb-questionlabelgroup\");\n if (control.visible) {\n $parent.attr(\"data-visible\", control.visible);\n window.setTimeout(function () {\n $parent.removeAttr(\"hidden\").attr(\"data-visible\", control.visible);\n }, 80);\n } else {\n $parent.attr(\"data-visible\", control.visible);\n window.setTimeout(function () {\n $parent.attr(\"hidden\", true);\n }, 80);\n }\n }\n});\n\n/*** DATA HANDLERS END ***/\n\n/*** VALIDATION BEGIN ***/\n\n/**\n * @Class Validation object.\n *\n */\nvar Validation = {\n /**\n * @member @private {Array} Stack of to-be-validated elemenents\n */\n _stack: [],\n /**\n * @member {Function}\n * @return undefined\n */\n reset: function () {\n this._stack = [];\n },\n /**\n * @member {Function}\n * @return {Element} Next Element eligible for validation\n */\n next: function () {\n return this._stack.pop();\n },\n /**\n * @member {Function}\n * @param {Element} el Element we want to be validated in due time\n */\n add: function (el) {\n this._stack.push(el);\n }\n};\n\n/**\n * Are all inputs valid?\n * @return {Boolean} Whether all inputs pass the test\n */\nValidation.allValid = function () {\n return (\n $.grep(\n $(\n '.group:not([disabled]) .validatable, .group:not([disabled]) [data-datatype^=\"datades:\"]'\n )\n .validate({ silent: true })\n .map(function () {\n return $(this).data(\"validated\");\n }),\n function (val) {\n return val === false;\n }\n ).length === 0\n );\n};\n\n/**\n * Update isValidated Mode\n * @return undefined\n */\nValidation.setMode = function () {\n Mode.toggle(\"isValidated\", Validation.allValid());\n};\n\n/**\n * Live Validation instructions\n */\n$(document).on(\"keyup change\", \"body.hasModel\", Validation.setMode);\n\n// Push the input just left onto the validation stack\n$(document).on(\"focusout\", \"#bb-q .group .validatable\", function () {\n var me = $(this);\n Validation.add(me[0]);\n});\n\n$.fn.extend({\n geterrorelt: function () {\n var $this = $(this);\n return $this.data(\"$error\") || $();\n },\n showValidation: function (options, ok, error) {\n var $this = $(this),\n node = $this.get(0);\n\n var errortext;\n if (error instanceof Error) errortext = error.message;\n else errortext = error;\n\n if (!document.body.contains(node)) {\n // console.log('Trying to validate unconnected', this)\n return;\n }\n $this.data(\"validated\", ok);\n\n if (!ok) {\n var $error = $this.geterrorelt(),\n $anchor = $this.is(\"input[type=checkbox]\")\n ? $this.next()\n : $this.data(\"anchor\");\n\n $this.attr(\"aria-invalid\", true);\n\n if ($error.length === 0) {\n if (!options.silent && !options.justhide) {\n $error = $(\n ``\n );\n $this.data(\"$error\", $error);\n }\n }\n // If there was already an error element, and the input is\n // still invalid but (reason and therefore) the errortext\n // has changed, change the error text shown to the user.\n if ($error.length > 0) {\n if ($error.data(\"lasterrortext\") !== errortext) {\n $error.data(\"lasterrortext\", errortext);\n $error.text(errortext);\n }\n }\n if (!options.silent && !options.justhide) {\n $this.addClass(\"error invalid\");\n // (re-)attach $error.\n $anchor.after($error);\n // This may be necessary:\n $(\"#bb-wrapmodel\").scrollTo($error);\n // Allow complicated widgets to fix stuff afterwards\n $this.trigger(\"bb:errorOn\", [errortext, $anchor, $error]);\n }\n } else {\n $this.attr(\"aria-invalid\", false);\n $this.geterrorelt().remove();\n $this.removeClass(\"error invalid\");\n $this.addClass(\"validated\");\n // Allow complicated widgets to fix stuff afterwards\n $this.trigger(\"bb:errorOff\");\n\n if (!options.silent && options.requestUpdate) {\n if (Mode.get(\"hasDynamicInterfaces\")) {\n requestDynProps(node);\n }\n }\n }\n },\n // Validate input\n // OPTIONS: silent, justhide\n validate: function (options) {\n if (!options) {\n options = {};\n }\n if (options.silent === undefined) {\n options.silent = false;\n }\n if (options.justhide === undefined) {\n options.justhide = false;\n }\n // requestUpdate needs to be false whenever validation is done\n // upon node navigation (next, skip), in order to avoid useless\n // server requests. Also, on validating for just showing errors\n // on tabbing away, we want not to request an update - that is\n // already taken care of by the onChange event\n if (options.requestUpdate === undefined) {\n options.requestUpdate = true;\n }\n\n // Argument noui says: do not update the ui (i.e. do not show nor hide any errors).\n return $(this).each(function () {\n var $this = $(this),\n ok = true,\n errortext;\n\n try {\n // Let actual validation be performed by other method.\n ok = validateInput($this);\n } catch (err) {\n ok = false;\n errortext = err;\n }\n\n return $this.showValidation(options, ok, errortext);\n });\n }\n});\n\n// Check when tabbing / clicking to new input - we want to show\n// validation while tabbing through, but not tabbing. onChange we want\n// to hide validation errors, but not show them immediately.\n$(document).on(\"focusin\", \":input\", function () {\n let validatable;\n while ((validatable = Validation.next())) {\n validatable = $(validatable);\n if ($(this).is(\":radio\")) {\n //Only validate when really outside of the radiogroup\n if (!$(this).parent(\".radiogroup\").has(validatable))\n validatable.validate({ requestUpdate: false });\n } else {\n if (validatable.get(0) != $(this).get(0))\n validatable.validate({ requestUpdate: false });\n }\n }\n});\n\n$(document).on(\n \"change\",\n \"#bb-q .group.selected :input:not(button)\",\n function () {\n var $this = $(this),\n options = { silent: false, justhide: true };\n if ($this.is(\":radio\")) {\n // validating radio???\n $this.parents(\".radiogroup\").validate(options);\n } else {\n $this.validate(options);\n }\n }\n);\n\n// Always check checkboxes onchange\n$(document).on(\"change\", \"#bb-q .group :checkbox\", function () {\n $(this).parents(\".checklist\").validate();\n});\n\nfunction debounce(func, wait, immediate) {\n var timeout;\n return function () {\n var context = this,\n args = arguments;\n var later = function () {\n timeout = null;\n if (!immediate) func.apply(context, args);\n };\n var callNow = immediate && !timeout;\n window.clearTimeout(timeout);\n timeout = window.setTimeout(later, wait);\n if (callNow) func.apply(context, args);\n };\n}\n\nconst eltControltype = compose(prop(\"controltype\"), getControl);\n\nconst doChangeOnKeyDown = elt => {\n const setting = path([\"arbitrary\", \"core\", \"update-on-typing\"])(conf);\n return (\n setting === \"always\" ||\n (setting instanceof Array && includes(eltControltype(elt), setting))\n );\n};\n\nfunction keyDown() {\n if (doChangeOnKeyDown(this)) $(this).data(\"valBefore\", $(this).val());\n}\n\n$(document).on(\n \"keydown\",\n \"#bb-q .group.selected :input:not(button)\",\n debounce(keyDown, 32, true)\n);\n\n$(document).on(\n \"keyup\",\n \"#bb-q .group.selected :input:not(button)\",\n function () {\n if (doChangeOnKeyDown(this)) {\n var $this = $(this),\n before = $this.data(\"valBefore\"),\n val = $this.val();\n if (before !== undefined && before !== val) {\n $this.trigger(\"change\");\n $this.removeData(\"valBefore\");\n }\n }\n }\n);\n/*** VALIDATION END ***/\n\n/*** HINTS, TOOLTIPS BEGIN ***/\n// Move to plugin core:tooltips\n/*** HINTS, TOOLTIPS END ***/\n\n/*** RENDERING 'ENGINE' BEGIN ***/\nconst doScrollToSelected = compose(\n val => val !== false,\n path([\"arbitrary\", \"core\", \"scrollToSelectedGroup\"])\n);\nconst setDynamicMode = tap(\n group =>\n group.current && Mode.toggle(\"hasDynamicInterfaces\", Boolean(group.dynamic))\n);\n\n/**\n * Render questions / labels (i.o.w. the main interaction\n * interface) This function is only called when there are actually\n * screens in need of rendering. Therefore, it need not check the JSON\n * object\n *\n * @param ev {Event} The event that triggered this function\n * @param data {Object} 'JSON'-object conforming to BB JSON API.\n */\nfunction renderGroups(ev, data) {\n // Save previous id\n var previd = $(\"#bb-q\" + \" .group.selected\").data(\"groupid\"),\n groups = data.groups,\n $bbq = $(\"#bb-q\");\n\n // Begin -- Only update what is new or was .selected before! There\n // is a problem with $.ajax calls when fast-clicking => therefore\n // step has {async: false}\n //\n // FIXME: when user press next, while\n // there is no next, a node too many is inserted. This can be\n // fixed now the server passes along the node id of a group.\n\n groups.forEach(setGroupTitle);\n if (![\"open\", \"exit\"].includes(Ajax.direction) && mustUpdate(conf)) {\n // Prepare DOM -- remove unneeded or to be re-rendered .groups\n for (let group of document.querySelectorAll(\".group\")) {\n if (complement(any(propEq(\"groupid\", group.dataset[\"gid\"])))(groups)) {\n // Remove a group if not in response\n group.parentNode.removeChild(group);\n } else if (Ajax.row && group.dataset[\"gid\"] === Ajax.groupid) {\n // When adding/deleting rows, safe the space where the group\n // was (entire group will be re-rendered)\n const gob = find(propEq(\"groupid\", group.dataset[\"gid\"]))(groups);\n const tempNode = document.createComment(\"group\");\n group.parentNode.replaceChild(tempNode, group);\n gob._tempNode = tempNode;\n }\n }\n compose(\n map(\n compose(\n ifElse(\n ({ groupid }) =>\n document.querySelector(`.group[data-gid=\"${groupid}\"]`),\n group => {\n updateDynProps({\n groups: [{ current: true, controls: group.controls }]\n });\n const elt = document.querySelector(\n `.group[data-gid=\"${group.groupid}\"]`\n );\n setSelectedStateAttributes(elt, group);\n },\n renderGroup\n ),\n setDynamicMode\n )\n ),\n sortGroups\n )(groups);\n } else {\n // Always remove .selected:\n $(\".group.selected\", $bbq).remove();\n if (Ajax.direction == \"next\" && groups.length > 1) {\n // Re-render only previous group and current group\n groups = groups.filter(function (group) {\n return group.current || group.groupid === previd;\n });\n } else if (\n Ajax.direction == \"prior\" &&\n $(\"#bb-q .group\").length > 0 &&\n groups.length > 1\n ) {\n // Re-render only current group\n groups = groups.filter(function (group) {\n return group.current;\n });\n } else $bbq.empty();\n // End -- Only update what is new!\n\n $bbq.hide();\n compose(map(compose(renderGroup, setDynamicMode)), sortGroups)(groups);\n }\n $bbq.attr(\"lang\", data.modellanguage).show();\n\n // Old questionlabelgroup plugin:\n if (!doGrouping(conf)) {\n (bb.questionlabelgroup || questionlabelgroup)();\n\n $('.bb-questionlabelgroup:has([data-datatype][data-visible=\"false\"])').attr(\n {\n \"data-visible\": false,\n \"hidden\": true\n }\n );\n }\n}\n\nfunction sortGroups(groups) {\n // Fix insertion order\n return groups.sort(function (a, b) {\n return a.order - b.order;\n });\n}\n\nfunction sortControls(a, b) {\n if (!a[0]) return b.reverse();\n var ac = a.shift(),\n bc = b[0];\n if (\n bc &&\n ac.controltype === \"label\" &&\n !ac.datatype && // Label with a datatype is a text interface\n bc._sorted === undefined &&\n bc.controltype !== \"label\" &&\n (bc.controltype !== \"linklabel\" || bc.isreport) &&\n bc.controltype !== \"checkbox\"\n ) {\n // Reverse input with label\n b.shift();\n bc._sorted = true; // Instruct next recursion not to touch the control\n if (has(\"notnull\", bc)) ac.isForNotNull = bc.notnull;\n if (has(\"readonly\", bc)) ac.readonly = bc.readonly;\n ac.dynamic = bc.dynamic = /^datades:/.test(bc.datatype);\n ac.metadata = Object.assign({}, bc.metadata, ac.metadata);\n bc.meta = bc.meta || {}; // Associate input with label\n bc.meta.label = (ac.value || \"\").trim();\n bc.aria = bc.aria || {}; // Associate input with label\n if (bc.notnull) bc.aria.required = true;\n if (ac.notnull) ac.aria.required = true;\n // Associate input (group) with label.\n if (\n [\"radio\", \"checkmultilist\", \"listbox\", \"multilist\"].includes(\n bc.controltype\n )\n ) {\n if (bb.conf.a11y.optionfieldsets) {\n ac.controltype = \"legend\";\n ac.className = \"bb-label\";\n } else {\n bc.aria.labelledby = ac.id;\n }\n } else if (bc.controltype === \"grid\") {\n if (bb.conf.a11y.captions) {\n ac.controltype = \"caption\";\n bc.caption = ac;\n } else {\n bc.aria.labelledby = ac.id;\n }\n } else {\n ac.isFor = bc.id;\n }\n return sortControls(a, [bc, ac].concat(b));\n } else {\n if (\n bc &&\n ac.controltype === \"label\" &&\n !ac.datatype && // Label with a datatype is a text interface\n bc.controltype === \"checkbox\"\n ) {\n ac.isFor = bc.id; // Associate label with checkbox (that comes before)\n if (has(\"notnull\", bc)) ac.isForNotNull = bc.notnull;\n if (has(\"readonly\", bc)) ac.readonly = bc.readonly;\n ac.dynamic = /^datades:/.test(bc.datatype);\n ac.metadata = Object.assign({}, bc.metadata, ac.metadata);\n bc.meta = bc.meta || {}; // Associate input with label\n bc.meta.label = (ac.value || \"\").trim();\n bc.aria = bc.aria || {};\n if (bc.notnull) bc.aria.required = true;\n if (ac.notnull) ac.aria.required = true;\n }\n return sortControls(a, [ac].concat(b));\n }\n}\n\nfunction setGroupTitle(group) {\n var controls = group.controls;\n // It's a title, if:\n // there are two 1st is label Not a 'text' interface 1st doesnt control any\n if (\n controls[1] &&\n controls[0].controltype === \"label\" &&\n !controls[0].datatype &&\n !controls[0].isfor\n ) {\n controls[0].controltype = \"legend\";\n group.screentitle = controls[0].value;\n }\n}\n\nconst setSelectedStateAttributes = (elt, group) => {\n elt.classList.toggle(\"selected\", group.current);\n elt.classList.toggle(\"unselected\", !group.current);\n if (group.current || canEditEarlier(conf)) {\n elt.removeAttribute(\"aria-hidden\");\n elt.removeAttribute(\"disabled\");\n } else {\n elt.setAttribute(\"aria-hidden\", true);\n elt.setAttribute(\"disabled\", \"disabled\");\n }\n};\n\nconst hasStatusRole = pathEq([\"metadata\", \"role\"], \"status\");\n\nfunction renderGroup(group) {\n var controls = group.controls,\n wGroup = $(\n '\"\n );\n\n // If this has a dupe, first remove the old one:\n $(\".group\").each(function () {\n if ($(this).data(\"groupid\") === group.groupid) $(this).remove();\n });\n\n const elt = wGroup.get(0);\n elt.dataset[\"gid\"] = group[\"groupid\"];\n wGroup.data(\"groupid\", group[\"groupid\"]);\n\n controls = sortControls(controls.slice(0), []);\n\n if (doGrouping(conf)) controls = groupOuter(controls);\n\n $(controls).each(function (i, c) {\n if (doGrouping(conf)) {\n elt.appendChild(createFormGroup(wControl, group, 1)(c));\n } else wControl(c, group, elt);\n });\n\n elt.classList.add(\"bb-screenmode-\" + group.screenmode);\n elt.setAttribute(\"data-node\", group.name);\n if (!bb.getVar(\"wrongOrder\")) elt.setAttribute(\"data-bb:order\", group.order);\n\n setSelectedStateAttributes(elt, group);\n\n if (group._tempNode) {\n group._tempNode.parentNode.replaceChild(elt, group._tempNode);\n delete group._tempNode;\n } else {\n if (group.screenmode == \"addtop\") $(\"#bb-q\").prepend(elt);\n else $(\"#bb-q\").append(elt);\n }\n}\n\n/**\n * Wrap questions + accompanying labels in a single group\n *\n * This function may be overriden by assigning a function to bb.questionlabelgroup\n * @see Plugin questionlabelgroup-ng\n *\n * @return undefined\n */\nfunction questionlabelgroup() {\n $(\".group:not(:has(.bb-questionlabelgroup))>.bb-label\").each(function () {\n var $this = $(this);\n var input = $this.next(\n \":not(label):not(a):not([type=checkbox]):not(img):not(.clearfix)\"\n );\n var itype = input.data(\"type\");\n var questionandlabel = $this.add(input);\n\n if (questionandlabel.length > 1)\n questionandlabel.wrapAll(\n ''\n );\n else {\n questionandlabel = $this.prev(\"[type=checkbox]\").add(this);\n if (questionandlabel.length > 1)\n questionandlabel.wrapAll(\n ''\n );\n }\n questionandlabel\n .parent(\".bb-questionlabelgroup\")\n .append('');\n $.each(\n questionandlabel.parent(\".bb-questionlabelgroup\").find(\"[data-type]\"),\n function () {\n var $this = $(this);\n if ($this.attr(\"class\")) {\n var classname = $this.attr(\"class\").match(/\\bbbm-[a-z0-9-]+\\b/);\n if (classname) {\n classname = classname[0].replace(/\\bbbm-/, \"bb-g-\");\n $this.parents(\".bb-questionlabelgroup\").addClass(classname);\n }\n }\n }\n );\n });\n}\n\n/*** RENDERING 'ENGINE' END ***/\n\n/*** 'COMPLEX' WIDGET BEHAVIOUR BEGIN ***/\n\n/**\n * Radiogroup and checklist enhancements\n */\n\n$(document)\n .on(\"change programmatically-changed\", \".bb-option\", function (ev) {\n var $this = $(this);\n $this.toggleClass(\"checked\", ev.target.checked);\n if (ev.target.type === \"radio\" && ev.target.checked) {\n $this.siblings().removeClass(\"checked\");\n }\n })\n .on(\"focus\", \".bb-option\", function (ev) {\n $(this).addClass(\"focus\");\n if (ev.target.type === \"radio\") {\n ev.preventDefault();\n ev.stopImmediatePropagation();\n return false;\n }\n return true;\n })\n .on(\"blur\", \".bb-option\", function () {\n $(this).removeClass(\"focus\");\n })\n .on(\n \"keydown\",\n \".radiogroup .bb-option\",\n // Fix the odd default behaviour of selecting upon focus\n function (ev) {\n var $other,\n chars = [37, 38, 39, 40],\n // left, up, right, down\n idx = chars.indexOf(ev.keyCode);\n if (idx === -1) return true;\n\n $other =\n idx < 2 // 'prev' chars\n ? $(this).prev().find('input[type=\"radio\"]')\n : $(this).next().find('input[type=\"radio\"]');\n\n // At beginning or end... go around (Edge selects otherwise...).\n if (!$other.length) {\n $other =\n idx < 2 // 'prev' chars\n ? $(this).siblings().last().find('input[type=\"radio\"]')\n : $(this).siblings().first().find('input[type=\"radio\"]');\n }\n if ($other.length) {\n $other.trigger(\"focus\");\n ev.preventDefault();\n ev.stopImmediatePropagation();\n return false;\n }\n return true;\n }\n );\n\n/*** 'COMPLEX' WIDGET BEHAVIOUR END ***/\n\n/*** LINKS BEGIN ***/\n\n/**\n * Original code moved to plugin rewrite-links\n *\n */\n\n/*** LINKS END ***/\n\n/*** TOKENCHANNEL BEGIN ***/\n\n$(document).on(\"bb:preHandleData\", (_, data) => {\n if (has(\"uniqueid\", data)) {\n token.setToken(prop(\"uniqueid\", data));\n }\n});\n\n$(document).on(\"bb:preHandleData\", (_, data) => {\n // document.body.dispatchEvent(new customEvent(\"bb:storeToken\", { bubbles: true, })\n if (has(\"uniqueid\", data)) {\n token.setToken(prop(\"uniqueid\", data));\n }\n});\n\n$(document).on(\"bb:mode:isLoggedIn\", (_event, bool) => {\n if (!bool) {\n token\n .getHash()\n .then(tokenHash => token.postMessage({ tokenHash, type: \"loggedOut\" }));\n }\n});\n\ntoken.addEventListener(\"message\", message => {\n token.getHash().then(hash => {\n if (message.data.tokenHash === hash) {\n if (message.data.type === \"loggedOut\") window.close() || logout();\n }\n });\n});\n\n/*** TOKENCHANNEL END ***/\n\n/*** EXPORTS BEGIN ***/\n\nbb.escapeHTML = escapeHTML;\nbb.exit = exit;\nbb.deleteCase = deleteCase;\nbb.logout = logout;\nbb.menu = menu;\n\nbb.authenticate = token => Vars.setVars({ uniqueid: token });\nbb.newcase = newcase;\nbb.step = step;\nbb.restart = function restart() {\n newcase(Vars.getVar(\"dbname\"));\n};\nbb.rewind = function rewind(cb, options) {\n step(\"rewind\", cb, options);\n};\nbb.update = function update(cb, options) {\n step(\"update\", cb, options);\n};\nbb.updatemis = function updatemis(options) {\n step(\"updatemis\", $.noop, options);\n};\nbb.next = function next(cb, options) {\n step(\"next\", cb, options);\n};\nbb.prior = function prior(cb, options) {\n step(\"prior\", cb, options);\n};\nbb.skip = function skip(cb, options) {\n step(\"skip\", cb, options);\n};\nbb.gotonode = function gotonode(groupid, cb, options = null) {\n step(\"gotonode\", cb, Object.assign({}, { groupid }, options));\n};\nbb.runtonode = function runtonode(nodename, cb) {\n step(\"runtonode\", cb, { fullnodename: nodename });\n};\nbb.getVar = Vars.getVar;\nbb.notify = notify.bind(null, {});\nbb.ajax = {\n replace: Ajax.replace,\n busy: function () {\n return Ajax.busy;\n },\n release: Ajax.release,\n post: Ajax.post,\n direction: function () {\n return Ajax.direction;\n }\n};\nbb.URL = urlutils;\nbb.Numerals = Numerals;\nbb.Plugins = bb.Plugins || {};\nbb.Validation = Validation;\nbb.positionalFormat = positionalFormat;\nbb.humanDate = humanDate;\nbb.propFinder = propFinder;\nbb.requestDynProps = requestDynProps;\n// Window-export some stuff used in bookmarklets.\nwindow.bb = {\n restart: bb.restart,\n getVar: bb.getVar,\n requestDynProps: bb.requestDynProps,\n Mode,\n menu\n};\n\n/*** EXPORTS END ***/\n\nexport { bb, _, _ as gt };\n", "/* a11y-describedby:\n *\n * - Describe group with all its standard remarks\n * - Describe input by any non-standard remark labels directly\n * preceding it\n *\n * Author: Niels Giesen\n * Copyright 2016 Berkeley Bridge\n *\n */\nimport { tap, when, compose, prop, path, find } from \"$json/lib/functional\";\n\n$(document).on(\"bb:preHandleData\", function (event, data) {\n if (data && data.groups) {\n $.each(data.groups, function (_, group) {\n var remarks = [],\n pretexts = [];\n $.each(group.controls, function (idx, control) {\n if (control[\"font-class\"].toLowerCase() === \"standard remark\") {\n remarks.push(control.id);\n } else if (control.datatype && control.controltype === \"label\") {\n pretexts.push(control.id);\n }\n const explicitId = path([\"metadata\", \"describedby\"], control);\n if (explicitId) {\n compose(\n when(\n Boolean,\n compose(id => pretexts.push(id), prop(\"id\"))\n ),\n find(c => c.identifier && c.identifier.endsWith(`.${explicitId}`)),\n prop(\"controls\")\n )(group);\n }\n if (control.datatype && control.controltype !== \"label\") {\n maybeSetDescription(control, pretexts);\n pretexts = [];\n }\n });\n maybeSetDescription(group, remarks);\n });\n }\n});\n\nfunction maybeSetDescription(thing, description_ids) {\n if (description_ids.length) {\n thing.aria = thing.aria || {};\n thing.aria.describedby = description_ids.join(\" \");\n }\n}\n", "/* asterisk:\n *\n * Add asterisk to labels for required fields\n *\n * Author: Niels Giesen\n * Copyright 2015 Berkeley Bridge\n *\n */\n(function ($, win, doc) {\n function appendAsterisk(child) {\n if (child.nodeType === 3 /* Node.TEXT_NODE */) {\n var val = child.nodeValue,\n space = \"\",\n words = val.split(\" \"),\n lastword = words.pop();\n // json.js adds a space for visual purposes\n if (lastword === \"\") {\n space = \" \";\n lastword = words.pop();\n }\n child.nodeValue = words.join(\" \");\n child.parentNode.insertAdjacentHTML(\n \"beforeEnd\",\n ' ' +\n lastword +\n ` *` +\n \"\" +\n space\n );\n } else if (child.nodeType === 1 /* Node.ELEMENT_NODE */) {\n if (child.lastChild) appendAsterisk(child.lastChild);\n }\n }\n\n $(doc).on(\"bb:updated\", function (event, $widget, control, updates) {\n if (updates.indexOf(\"isForNotNull\") > -1) {\n if (control.isForNotNull) {\n appendAsterisk($widget.get(0).lastChild);\n } else {\n const $stick = $widget.find(\".bb-p-asterisk-stick\");\n if (!$stick.get(0)) return;\n $stick.find(\"sup\").remove();\n const textnode = $stick.get(0).childNodes[0];\n if (textnode) $(textnode).unwrap();\n }\n }\n });\n})(jQuery, window, document);\n", "/* global $ */\n/* auto-next:\n *\n * Automatically go next on selection of radiogroup option, when that\n * radiogroup is the only editable question in the node.\n *\n * This behaviour used to be provided by our core module, but there\n * were many users who did not like it and disabled it by using the\n * now removed plugin `no-auto-next'.\n *\n * The behaviour is now reversed: automatically going next is not\n * supported by default, and if you do want it, use this plugin.\n *\n * Author: Niels Giesen\n * Copyright 2013, 2015, 2020 Berkeley Bridge\n *\n * Dependcy: questionlabelgroup-ng (or similar grouper?)\n *\n */\n\nimport { bb } from \"$json\";\nimport { isQuestion, isVisible, isReadOnly } from \"$json/lib/control-helpers\";\nimport {\n allPass,\n both,\n complement,\n compose,\n filter,\n length,\n map,\n pathOr,\n propEq,\n when\n} from \"$json/lib/functional\";\n\nlet evenWhenDynamic = pathOr(false, [\n \"arbitrary\",\n \"auto-next-when-only-radio\",\n \"evenWhenDynamic\"\n]);\n\nconst changeHandler = ({ currentTarget }) => {\n const control = $.data(currentTarget, \"control\");\n\n if (!currentTarget.closest(\".group.selected\")) return;\n\n const controls = control._group.controls;\n\n if (hasMultipleQuestions(controls)) return;\n\n if (!bb.Mode.get(\"a-mouse-user\")) return;\n\n bb.next();\n};\n\nconst isInteractionable = allPass([\n isQuestion,\n isVisible,\n complement(isReadOnly)\n]);\n\n// there is more than one interactionable control?\nconst hasMultipleQuestions = compose(\n x => x > 1,\n length,\n filter(isInteractionable)\n);\n\nconst radios = filter(both(isQuestion, propEq(\"controltype\", \"radio\")));\n\nconst addChangeHandler = when(Boolean, widget =>\n widget.addEventListener(\"change\", changeHandler)\n);\n\nconst makeLastInputDoNext =\n /*\n * Bind click event on last logical switching input elements to\n * go to the next screen automatically\n */\n compose(\n map(control => {\n addChangeHandler(document.getElementById(control.id));\n }),\n radios\n );\n\n$(document).on(\"bb:postHandleData\", function (event, data) {\n if (\n typeof data !== \"undefined\" &&\n data &&\n data.groups &&\n data.groups.length\n ) {\n data.groups.forEach(function (group) {\n if (evenWhenDynamic(bb.conf) || !group.dynamic)\n makeLastInputDoNext(group.controls);\n });\n }\n});\n", "/* bb-xarea:\n *\n * Dynamically grow textareas.\n *\n * Depends on: jquery.xarea.js\n *\n * Copyright 2013 Berkeley Bridge\n *\n */\n\n(function ($) {\n var first = true;\n\n function xarea(event, data, status, req) {\n if (\n typeof data != \"undefined\" &&\n data &&\n data.groups &&\n data.groups.length > 0\n )\n $(\".group textarea\")\n .filter(function () {\n return !$(this).data(\"xarea\");\n })\n .data(\"xarea\", true)\n .on(\"bb:errorOn\", function (ev, text, anchor) {\n var parent = $(this).parents(\".xarea\");\n var errordiv = parent.find(\".errortext\");\n parent.next(\".errortext\").remove();\n errordiv.insertAfter(parent);\n })\n .on(\"bb:errorOff\", function (ev) {\n var parent = $(this).parents(\".xarea\");\n parent.next(\".errortext\").remove();\n })\n .xarea()\n .each(function () {\n this.parentNode.className = \"xarea\";\n });\n }\n\n $(document)\n .on(\"change keydown keyup\", \".group textarea\", function () {\n window.setTimeout(function () {\n $(document).trigger(\"bb:resized\");\n }, 150);\n })\n .on(\"focus\", \".xarea\", function (ev) {\n $(this).addClass(\"focus\");\n return true;\n })\n .on(\"blur\", \".xarea\", function (ev) {\n $(this).removeClass(\"focus\");\n });\n\n $(document).on(\"bb:updated\", function (event, $widget, control, updates) {\n if (\n updates.includes(\"visible\") &&\n control.controltype === \"memo\" &&\n control.visible\n ) {\n $widget.trigger(\"bb:reclone\");\n }\n });\n\n $(document).on(\"bb:postHandleData\", function (event, data, status, req) {\n if (first) {\n window.setTimeout(function () {\n xarea(event, data, status, req);\n }, 150);\n first = false;\n } else {\n xarea(event, data, status, req);\n }\n });\n})(jQuery);\n", "/* dialog:\n *\n * handle plugins the simplest of ways\n *\n * Author: Niels Giesen\n * Copyright 2016 Berkeley Bridge\n *\n */\n(function ($, win, doc) {\n $(doc).on(\"keydown\", function (ev) {\n if (ev.keyCode === 27)\n // ESCAPE\n win.location.hash = \"\";\n });\n\n $(doc).on(\"click touchstart\", \".dialog-mask\", function () {\n win.location.hash = \"\";\n });\n\n $(doc).on(\"click touchstart\", \".dialog-box\", function (ev) {\n ev.stopPropagation();\n return true;\n });\n})(jQuery, window, document);\n", "/* grid-rowspan:\n *\n * - Add rowspan=x to (link-)label cells repeated over subsequent rows\n * - Remove like cells.\n *\n * Author: Niels Giesen\n * Copyright 2015 Berkeley Bridge\n */\n(function ($) {\n $(function () {\n $(document).on(\"bb:preHandleData\", rowspanifyData);\n });\n\n /**\n * @param {Event} event The event that triggered this function.\n * @param {Object} data The JSON-object as defined in our JSON API.\n *\n * NOTE: this function is destructive - it may change the data\n * argument.\n */\n function rowspanifyData(event, data) {\n if (typeof data != \"undefined\" && data && data.groups)\n $.each(data.groups, function (_, group) {\n $.each(group.controls, function (_, control) {\n if (\n control.controltype == \"grid\" &&\n !/norowspan/.test(control[\"font-class\"])\n ) {\n rowspan(control);\n }\n });\n });\n }\n\n /**\n * Set (link-)label cell values to null when coming beneath other\n * cells with same value (and same url in case of linklabels).\n *\n * Give those other cells appropriate _rowspan values.\n *\n * @param {Object} control A control object as defined in our JSON API.\n *\n * NOTE: this function is destructive - it may change the control\n * argument.\n */\n function rowspan(control) {\n $.each(control.columns, function (i, column) {\n if (\n column.controltype === \"label\" ||\n column.controltype === \"linklabel\"\n ) {\n var cur, last, len;\n\n len = control.value.length;\n\n while (len-- > 0) {\n cur = control.value[len][i];\n cur._rowspan = 1;\n\n if (last && last.value === cur.value) {\n if (column.controltype !== \"linklabel\" || last.url === cur.url) {\n cur._rowspan = last._rowspan + 1;\n last.value = null;\n }\n }\n\n last = cur;\n }\n }\n });\n }\n})(jQuery);\n", "/* has-no-next:\n *\n * Set body.hasNoNext when the current screen title matches a\n * predefined regular expression, and unsets it when does not.\n *\n * Author: Niels Giesen\n *\n * Copyright (C) 2011, 2012 by Berkeley Bridge\n *\n */\n\nimport { bb } from \"$json\";\n\n(function ($) {\n // Regular expression to test absolute screentitles against:\n var re = /^(Einde)$/;\n\n $(document).on(\"bb:postHandleData\", function (event, data, status, req) {\n if (data && data.jumplist)\n bb.Mode.toggle(\n \"hasNoNext\",\n data.hasnext == false ||\n $.grep(data.jumplist, function (group) {\n return (\n group.status == \"selected\" && re.test($.trim(group.screentitle))\n );\n }).length > 0\n );\n });\n})(jQuery);\n", "import { bb } from \"$json\";\nimport { canEditEarlier } from \"$json/lib/feature-queries\";\nimport { conf } from \"$json/lib/conf\";\n/* has-required:\n *\n * Note whether there is any required question currently\n *\n * Author: Niels Giesen\n * Copyright 2016 Berkeley Bridge\n *\n */\n(function ($, win, doc) {\n $(function () {\n $(doc).on(\"bb:preHandleData\", function (event, data) {\n if (data && data.groups) {\n var req = data.groups.some(function (group) {\n return (\n (canEditEarlier(conf) || group.current) &&\n group.controls.some(function (control) {\n return control.notnull;\n })\n );\n });\n bb.Mode.toggle(\"hasRequired\", req);\n }\n });\n });\n})(jQuery, window, document);\n", "/* heading2-3:\n *\n * Turn first top label into heading level 2, and any subsequent to level 3.\n *\n * Author: Niels Giesen\n * Copyright 2016 Berkeley Bridge\n *\n */\n(function ($, win, doc) {\n var level = 2;\n\n $(function () {\n $(doc).on(\"bb:preHandleData\", function (event, data) {\n if (data && data.groups && data.groups.length) {\n var topdone = false;\n $.each(data.groups, function (_, group) {\n var ctl;\n if (\n group.controls &&\n ((ctl = group.controls[0]), ctl) &&\n ctl.controltype === \"label\" &&\n ctl[\"font-class\"].toLowerCase().indexOf(\"title\") > -1\n ) {\n ctl._subtype = \"heading\";\n ctl._level = topdone ? level + 1 : level;\n topdone = true;\n }\n });\n }\n });\n });\n})(jQuery, window, document);\n", "import { bb } from \"$json\";\n/* high-on-info-ng:\n *\n * Make an information source from text in questions that matches the\n * description of an informationsource.\n *\n * Author: Niels Giesen\n * Copyright (C) 2011, 2012, 2015, 2016 by Berkeley Bridge\n *\n *\n */\n\n(function ($) {\n function maybeEncodeURI(uri) {\n return uri.indexOf(\"%\") > -1 ? uri : encodeURI(uri);\n }\n\n function replaceMatchWithHTML(n, from, to) {\n if (typeof n == \"undefined\") return false;\n if (n.tagName === \"A\" /*Do not mess with links*/) return false;\n if (n.nodeType == 3 /*Node.TEXT_NODE*/) {\n if (n.data.match(from)) {\n var nn = document.createElement(\"span\");\n $(nn).html(n.data.replace(from, to));\n n.parentNode.replaceChild(nn, n);\n return true;\n }\n return false;\n } else {\n var kids = n.childNodes;\n for (var i = 0, len = kids.length; i < len; i++) {\n if (replaceMatchWithHTML(kids[i], from, to)) return true;\n }\n return false;\n }\n }\n\n function makeLinksInMainText(informationsources) {\n var source,\n from,\n to,\n description,\n content,\n isurl,\n isexternal,\n newtext,\n object = $(\".group.selected\").get(0),\n flags = \"m\";\n for (var i = 0, len = informationsources.length; i < len; i++) {\n source = informationsources[i];\n if (!source.selected) continue;\n description = source.description.replace(/[.?|()*]/gm, function ($0) {\n return \"\\\\\" + $0;\n });\n from = new RegExp(\"((?= )|^|\\\\b)\" + description + \"(\\\\b|$|(?= ))\", flags);\n to = bb.escapeHTML(source.description);\n content = source.content;\n isurl = source.isurl;\n isexternal = source.external;\n if (isurl) {\n replaceMatchWithHTML(\n object,\n from,\n \"' +\n to +\n \"\"\n );\n } else {\n replaceMatchWithHTML(\n object,\n from,\n '' +\n to +\n \"\"\n );\n }\n }\n }\n\n $(document).on(\"bb:postHandleData\", function (event, data) {\n if (data && data.informationsources) {\n var sources = $.grep(data.informationsources, function (source) {\n return (\n $.trim(source.description) != \"\" &&\n $.trim(source.content) != \"\" &&\n $.trim(source.content) != \"http://\"\n );\n });\n makeLinksInMainText(sources);\n }\n });\n})(jQuery);\n", "/* history:\n *\n * Manage history using the html5 history api and sessionStorage\n *\n * Could have support for crunchbang ( #!modelname=thisandthat )\n *\n * Author: Niels Giesen\n * Copyright 2013, 2014, 2015 Berkeley Bridge\n *\n */\nimport { bb, _ } from \"$json\";\nimport { has } from \"$json/lib/functional\";\nimport { setSettled } from \"$json/lib/settled\";\n\n(function ($, win, history, location) {\n var crunchbang = false;\n\n if (history && history.pushState) {\n if (!location.origin) {\n location.origin =\n location.protocol +\n \"//\" +\n location.hostname +\n (location.port ? \":\" + location.port : \"\");\n }\n\n $(function () {\n var apinav,\n storage,\n params = $.parseQuery(location.hash.slice(2)),\n _title_sep = \" \",\n _title = document.title;\n\n try {\n storage = window.sessionStorage;\n } catch (err) {\n storage = null;\n }\n\n function directory(loc) {\n return loc.origin + loc.pathname.replace(/[^/]+$/, \"\");\n }\n\n function restoreState(state) {\n if (state.sessionid) {\n // restore case\n bb.ajax\n .post({\n url: \"action\",\n data: state\n })\n .then(setSettled);\n } else if (bb.getVar(\"sessionid\")) {\n // exit running case and restore model view\n bb.exit(() => bb.menu(state).then(setSettled));\n } else {\n // restore model view\n bb.menu(state).then(setSettled);\n }\n }\n\n function ditchState() {\n storage && storage.removeItem(\"state\");\n history.replaceState(null, null, null);\n setSettled();\n }\n\n if (location.search !== \"\") ditchState();\n\n var initial_state =\n history.state || (storage && JSON.parse(storage.getItem(\"state\")));\n\n if (initial_state) {\n // Detect explicit edit of the crunchbang - this should\n // override the dbname parameter and instead use the modelname\n if (params.modelname && params.modelname !== initial_state.modelname) {\n initial_state.modelname = params.modelname;\n delete initial_state.dbname;\n delete initial_state.sessionid;\n }\n\n if (initial_state.directory === directory(location)) {\n bb.Mode.set(\"isLoggedIn\"); // Yes, just an assumption it will go allright.\n restoreState(initial_state);\n } else {\n ditchState();\n }\n } else if (params.modelname) {\n // Bookmarked with crunchbang, but no state\n bb.Router(params);\n } else {\n setSettled();\n }\n\n $(document).on(\"bb:jsonError\", ditchState);\n\n $(document).on(\"bb:preHandleData\", function (event, data) {\n if (data && data.uniqueid) {\n var title,\n state = {\n fmt: \"json\",\n uniqueid: data.uniqueid,\n // Save the 'directory part'\n directory: directory(location)\n };\n if (has(\"dbname\", data) && data.sessionid) {\n state.dbname = data.dbname;\n state.sessionid = data.sessionid;\n state.modelname = data.modelname; // Needed to get interpret explicit change to location\n\n if (data.modeldescription) {\n title = [_title, data.modeldescription.replace(/_/g, \" \")].join(\n _title_sep\n );\n }\n } else if (data.models) {\n var model = $.grep(data.models, function (m) {\n return m.selected;\n })[0],\n dbname = model ? model.dbname : null;\n if (dbname !== null) {\n state.dbname = dbname;\n title = [_title, model.modelname, \"-\", _(\"overview\")].join(\n _title_sep\n );\n } else {\n title = [_title, _(\"Your models\")].join(_title_sep);\n }\n }\n if (!apinav) {\n try {\n storage && storage.setItem(\"state\", JSON.stringify(state));\n } catch (e) {\n // Guard against QuotaExceededError (which always happens on Safari Private Browsing on iOS)\n }\n if (history.state && history.state.sessionid && state.sessionid) {\n history.replaceState(\n state,\n null,\n location.origin +\n location.pathname +\n ((crunchbang && \"#!modelname=\" + data.modelname) || \"\")\n );\n } else {\n if (data.modelname && crunchbang) {\n history.pushState(\n state,\n null,\n location.origin +\n location.pathname +\n \"#!modelname=\" +\n data.modelname\n );\n } else {\n history.pushState(\n state,\n null,\n location.origin + location.pathname\n );\n }\n }\n }\n if (title && document.title !== title) {\n document.title = title;\n }\n }\n // Something went miserably wrong. Clear history to get out of this mess.\n if (\n data &&\n ((data.error && data.error.summary) ||\n (data.groups && !data.groups.length) ||\n data.status === \"logout successful\")\n ) {\n // Extra check - may be we are but updating\n if (\n data &&\n data.error &&\n data.error.code &&\n data.error.code === 14 && // Error loading case\n data.error.subcode === 1002\n )\n // Updating\n return;\n ditchState();\n }\n apinav = false;\n });\n\n win.addEventListener(\"popstate\", function (e) {\n apinav = true;\n if (e.state) {\n if (e.state.directory === directory(location)) restoreState(e.state);\n else ditchState();\n }\n });\n });\n }\n})(jQuery, window, window.history, window.location);\n", "/*!\n * mustache.js - Logic-less {{mustache}} templates with JavaScript\n * http://github.com/janl/mustache.js\n */\n\n/*global define: false Mustache: true*/\n\nfunction mustacheFactory(mustache) {\n var objectToString = Object.prototype.toString;\n var isArray =\n Array.isArray ||\n function isArrayPolyfill(object) {\n return objectToString.call(object) === \"[object Array]\";\n };\n\n function isFunction(object) {\n return typeof object === \"function\";\n }\n\n /**\n * More correct typeof string handling array\n * which normally returns typeof 'object'\n */\n function typeStr(obj) {\n return isArray(obj) ? \"array\" : typeof obj;\n }\n\n function escapeRegExp(string) {\n return string.replace(/[\\-\\[\\]{}()*+?.,\\\\\\^$|#\\s]/g, \"\\\\$&\");\n }\n\n /**\n * Null safe way of checking whether or not an object,\n * including its prototype, has a given property\n */\n function hasProperty(obj, propName) {\n return obj != null && typeof obj === \"object\" && propName in obj;\n }\n\n // Workaround for https://issues.apache.org/jira/browse/COUCHDB-577\n // See https://github.com/janl/mustache.js/issues/189\n var regExpTest = RegExp.prototype.test;\n function testRegExp(re, string) {\n return regExpTest.call(re, string);\n }\n\n var nonSpaceRe = /\\S/;\n function isWhitespace(string) {\n return !testRegExp(nonSpaceRe, string);\n }\n\n var entityMap = {\n \"&\": \"&\",\n \"<\": \"<\",\n \">\": \">\",\n '\"': \""\",\n \"'\": \"'\",\n \"/\": \"/\",\n \"`\": \"`\",\n \"=\": \"=\"\n };\n\n function escapeHtml(string) {\n return String(string).replace(/[&<>\"'`=\\/]/g, function fromEntityMap(s) {\n return entityMap[s];\n });\n }\n\n var whiteRe = /\\s*/;\n var spaceRe = /\\s+/;\n var equalsRe = /\\s*=/;\n var curlyRe = /\\s*\\}/;\n var tagRe = /#|\\^|\\/|>|\\{|&|=|!/;\n\n /**\n * Breaks up the given `template` string into a tree of tokens. If the `tags`\n * argument is given here it must be an array with two string values: the\n * opening and closing tags used in the template (e.g. [ \"<%\", \"%>\" ]). Of\n * course, the default is to use mustaches (i.e. mustache.tags).\n *\n * A token is an array with at least 4 elements. The first element is the\n * mustache symbol that was used inside the tag, e.g. \"#\" or \"&\". If the tag\n * did not contain a symbol (i.e. {{myValue}}) this element is \"name\". For\n * all text that appears outside a symbol this element is \"text\".\n *\n * The second element of a token is its \"value\". For mustache tags this is\n * whatever else was inside the tag besides the opening symbol. For text tokens\n * this is the text itself.\n *\n * The third and fourth elements of the token are the start and end indices,\n * respectively, of the token in the original template.\n *\n * Tokens that are the root node of a subtree contain two more elements: 1) an\n * array of tokens in the subtree and 2) the index in the original template at\n * which the closing tag for that section begins.\n */\n function parseTemplate(template, tags) {\n if (!template) return [];\n\n var sections = []; // Stack to hold section tokens\n var tokens = []; // Buffer to hold the tokens\n var spaces = []; // Indices of whitespace tokens on the current line\n var hasTag = false; // Is there a {{tag}} on the current line?\n var nonSpace = false; // Is there a non-space char on the current line?\n\n // Strips all whitespace tokens array for the current line\n // if there was a {{#tag}} on it and otherwise only space.\n function stripSpace() {\n if (hasTag && !nonSpace) {\n while (spaces.length) delete tokens[spaces.pop()];\n } else {\n spaces = [];\n }\n\n hasTag = false;\n nonSpace = false;\n }\n\n var openingTagRe, closingTagRe, closingCurlyRe;\n function compileTags(tagsToCompile) {\n if (typeof tagsToCompile === \"string\")\n tagsToCompile = tagsToCompile.split(spaceRe, 2);\n\n if (!isArray(tagsToCompile) || tagsToCompile.length !== 2)\n throw new Error(\"Invalid tags: \" + tagsToCompile);\n\n openingTagRe = new RegExp(escapeRegExp(tagsToCompile[0]) + \"\\\\s*\");\n closingTagRe = new RegExp(\"\\\\s*\" + escapeRegExp(tagsToCompile[1]));\n closingCurlyRe = new RegExp(\n \"\\\\s*\" + escapeRegExp(\"}\" + tagsToCompile[1])\n );\n }\n\n compileTags(tags || mustache.tags);\n\n var scanner = new Scanner(template);\n\n var start, type, value, chr, token, openSection;\n while (!scanner.eos()) {\n start = scanner.pos;\n\n // Match any text between tags.\n value = scanner.scanUntil(openingTagRe);\n\n if (value) {\n for (var i = 0, valueLength = value.length; i < valueLength; ++i) {\n chr = value.charAt(i);\n\n if (isWhitespace(chr)) {\n spaces.push(tokens.length);\n } else {\n nonSpace = true;\n }\n\n tokens.push([\"text\", chr, start, start + 1]);\n start += 1;\n\n // Check for whitespace on the current line.\n if (chr === \"\\n\") stripSpace();\n }\n }\n\n // Match the opening tag.\n if (!scanner.scan(openingTagRe)) break;\n\n hasTag = true;\n\n // Get the tag type.\n type = scanner.scan(tagRe) || \"name\";\n scanner.scan(whiteRe);\n\n // Get the tag value.\n if (type === \"=\") {\n value = scanner.scanUntil(equalsRe);\n scanner.scan(equalsRe);\n scanner.scanUntil(closingTagRe);\n } else if (type === \"{\") {\n value = scanner.scanUntil(closingCurlyRe);\n scanner.scan(curlyRe);\n scanner.scanUntil(closingTagRe);\n type = \"&\";\n } else {\n value = scanner.scanUntil(closingTagRe);\n }\n\n // Match the closing tag.\n if (!scanner.scan(closingTagRe))\n throw new Error(\"Unclosed tag at \" + scanner.pos);\n\n token = [type, value, start, scanner.pos];\n tokens.push(token);\n\n if (type === \"#\" || type === \"^\") {\n sections.push(token);\n } else if (type === \"/\") {\n // Check section nesting.\n openSection = sections.pop();\n\n if (!openSection)\n throw new Error('Unopened section \"' + value + '\" at ' + start);\n\n if (openSection[1] !== value)\n throw new Error(\n 'Unclosed section \"' + openSection[1] + '\" at ' + start\n );\n } else if (type === \"name\" || type === \"{\" || type === \"&\") {\n nonSpace = true;\n } else if (type === \"=\") {\n // Set the tags for the next time around.\n compileTags(value);\n }\n }\n\n // Make sure there are no open sections when we're done.\n openSection = sections.pop();\n\n if (openSection)\n throw new Error(\n 'Unclosed section \"' + openSection[1] + '\" at ' + scanner.pos\n );\n\n return nestTokens(squashTokens(tokens));\n }\n\n /**\n * Combines the values of consecutive text tokens in the given `tokens` array\n * to a single token.\n */\n function squashTokens(tokens) {\n var squashedTokens = [];\n\n var token, lastToken;\n for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {\n token = tokens[i];\n\n if (token) {\n if (token[0] === \"text\" && lastToken && lastToken[0] === \"text\") {\n lastToken[1] += token[1];\n lastToken[3] = token[3];\n } else {\n squashedTokens.push(token);\n lastToken = token;\n }\n }\n }\n\n return squashedTokens;\n }\n\n /**\n * Forms the given array of `tokens` into a nested tree structure where\n * tokens that represent a section have two additional items: 1) an array of\n * all tokens that appear in that section and 2) the index in the original\n * template that represents the end of that section.\n */\n function nestTokens(tokens) {\n var nestedTokens = [];\n var collector = nestedTokens;\n var sections = [];\n\n var token, section;\n for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {\n token = tokens[i];\n\n switch (token[0]) {\n case \"#\":\n case \"^\":\n collector.push(token);\n sections.push(token);\n collector = token[4] = [];\n break;\n case \"/\":\n section = sections.pop();\n section[5] = token[2];\n collector =\n sections.length > 0\n ? sections[sections.length - 1][4]\n : nestedTokens;\n break;\n default:\n collector.push(token);\n }\n }\n\n return nestedTokens;\n }\n\n /**\n * A simple string scanner that is used by the template parser to find\n * tokens in template strings.\n */\n function Scanner(string) {\n this.string = string;\n this.tail = string;\n this.pos = 0;\n }\n\n /**\n * Returns `true` if the tail is empty (end of string).\n */\n Scanner.prototype.eos = function eos() {\n return this.tail === \"\";\n };\n\n /**\n * Tries to match the given regular expression at the current position.\n * Returns the matched text if it can match, the empty string otherwise.\n */\n Scanner.prototype.scan = function scan(re) {\n var match = this.tail.match(re);\n\n if (!match || match.index !== 0) return \"\";\n\n var string = match[0];\n\n this.tail = this.tail.substring(string.length);\n this.pos += string.length;\n\n return string;\n };\n\n /**\n * Skips all text until the given regular expression can be matched. Returns\n * the skipped string, which is the entire tail if no match can be made.\n */\n Scanner.prototype.scanUntil = function scanUntil(re) {\n var index = this.tail.search(re),\n match;\n\n switch (index) {\n case -1:\n match = this.tail;\n this.tail = \"\";\n break;\n case 0:\n match = \"\";\n break;\n default:\n match = this.tail.substring(0, index);\n this.tail = this.tail.substring(index);\n }\n\n this.pos += match.length;\n\n return match;\n };\n\n /**\n * Represents a rendering context by wrapping a view object and\n * maintaining a reference to the parent context.\n */\n function Context(view, parentContext) {\n this.view = view;\n this.cache = { \".\": this.view };\n this.parent = parentContext;\n }\n\n /**\n * Creates a new context using the given view with this context\n * as the parent.\n */\n Context.prototype.push = function push(view) {\n return new Context(view, this);\n };\n\n /**\n * Returns the value of the given name in this context, traversing\n * up the context hierarchy if the value is absent in this context's view.\n */\n Context.prototype.lookup = function lookup(name) {\n var cache = this.cache;\n\n var value;\n if (cache.hasOwnProperty(name)) {\n value = cache[name];\n } else {\n var context = this,\n names,\n index,\n lookupHit = false;\n\n while (context) {\n if (name.indexOf(\".\") > 0) {\n value = context.view;\n names = name.split(\".\");\n index = 0;\n\n /**\n * Using the dot notion path in `name`, we descend through the\n * nested objects.\n *\n * To be certain that the lookup has been successful, we have to\n * check if the last object in the path actually has the property\n * we are looking for. We store the result in `lookupHit`.\n *\n * This is specially necessary for when the value has been set to\n * `undefined` and we want to avoid looking up parent contexts.\n **/\n while (value != null && index < names.length) {\n if (index === names.length - 1)\n lookupHit = hasProperty(value, names[index]);\n\n value = value[names[index++]];\n }\n } else {\n value = context.view[name];\n lookupHit = hasProperty(context.view, name);\n }\n\n if (lookupHit) break;\n\n context = context.parent;\n }\n\n cache[name] = value;\n }\n\n if (isFunction(value)) value = value.call(this.view);\n\n return value;\n };\n\n /**\n * A Writer knows how to take a stream of tokens and render them to a\n * string, given a context. It also maintains a cache of templates to\n * avoid the need to parse the same template twice.\n */\n function Writer() {\n this.cache = {};\n }\n\n /**\n * Clears all cached templates in this writer.\n */\n Writer.prototype.clearCache = function clearCache() {\n this.cache = {};\n };\n\n /**\n * Parses and caches the given `template` and returns the array of tokens\n * that is generated from the parse.\n */\n Writer.prototype.parse = function parse(template, tags) {\n var cache = this.cache;\n var tokens = cache[template];\n\n if (tokens == null)\n tokens = cache[template] = parseTemplate(template, tags);\n\n return tokens;\n };\n\n /**\n * High-level method that is used to render the given `template` with\n * the given `view`.\n *\n * The optional `partials` argument may be an object that contains the\n * names and templates of partials that are used in the template. It may\n * also be a function that is used to load partial templates on the fly\n * that takes a single argument: the name of the partial.\n */\n Writer.prototype.render = function render(template, view, partials) {\n var tokens = this.parse(template);\n var context = view instanceof Context ? view : new Context(view);\n return this.renderTokens(tokens, context, partials, template);\n };\n\n /**\n * Low-level method that renders the given array of `tokens` using\n * the given `context` and `partials`.\n *\n * Note: The `originalTemplate` is only ever used to extract the portion\n * of the original template that was contained in a higher-order section.\n * If the template doesn't use higher-order sections, this argument may\n * be omitted.\n */\n Writer.prototype.renderTokens = function renderTokens(\n tokens,\n context,\n partials,\n originalTemplate\n ) {\n var buffer = \"\";\n\n var token, symbol, value;\n for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {\n value = undefined;\n token = tokens[i];\n symbol = token[0];\n\n if (symbol === \"#\")\n value = this.renderSection(token, context, partials, originalTemplate);\n else if (symbol === \"^\")\n value = this.renderInverted(token, context, partials, originalTemplate);\n else if (symbol === \">\")\n value = this.renderPartial(token, context, partials, originalTemplate);\n else if (symbol === \"&\") value = this.unescapedValue(token, context);\n else if (symbol === \"name\") value = this.escapedValue(token, context);\n else if (symbol === \"text\") value = this.rawValue(token);\n\n if (value !== undefined) buffer += value;\n }\n\n return buffer;\n };\n\n Writer.prototype.renderSection = function renderSection(\n token,\n context,\n partials,\n originalTemplate\n ) {\n var self = this;\n var buffer = \"\";\n var value = context.lookup(token[1]);\n\n // This function is used to render an arbitrary template\n // in the current context by higher-order sections.\n function subRender(template) {\n return self.render(template, context, partials);\n }\n\n if (!value) return;\n\n if (isArray(value)) {\n for (var j = 0, valueLength = value.length; j < valueLength; ++j) {\n buffer += this.renderTokens(\n token[4],\n context.push(value[j]),\n partials,\n originalTemplate\n );\n }\n } else if (\n typeof value === \"object\" ||\n typeof value === \"string\" ||\n typeof value === \"number\"\n ) {\n buffer += this.renderTokens(\n token[4],\n context.push(value),\n partials,\n originalTemplate\n );\n } else if (isFunction(value)) {\n if (typeof originalTemplate !== \"string\")\n throw new Error(\n \"Cannot use higher-order sections without the original template\"\n );\n\n // Extract the portion of the original template that the section contains.\n value = value.call(\n context.view,\n originalTemplate.slice(token[3], token[5]),\n subRender\n );\n\n if (value != null) buffer += value;\n } else {\n buffer += this.renderTokens(\n token[4],\n context,\n partials,\n originalTemplate\n );\n }\n return buffer;\n };\n\n Writer.prototype.renderInverted = function renderInverted(\n token,\n context,\n partials,\n originalTemplate\n ) {\n var value = context.lookup(token[1]);\n\n // Use JavaScript's definition of falsy. Include empty arrays.\n // See https://github.com/janl/mustache.js/issues/186\n if (!value || (isArray(value) && value.length === 0))\n return this.renderTokens(token[4], context, partials, originalTemplate);\n };\n\n Writer.prototype.renderPartial = function renderPartial(\n token,\n context,\n partials\n ) {\n if (!partials) return;\n\n var value = isFunction(partials) ? partials(token[1]) : partials[token[1]];\n if (value != null)\n return this.renderTokens(this.parse(value), context, partials, value);\n };\n\n Writer.prototype.unescapedValue = function unescapedValue(token, context) {\n var value = context.lookup(token[1]);\n if (value != null) return value;\n };\n\n Writer.prototype.escapedValue = function escapedValue(token, context) {\n var value = context.lookup(token[1]);\n if (value != null) return mustache.escape(value);\n };\n\n Writer.prototype.rawValue = function rawValue(token) {\n return token[1];\n };\n\n mustache.name = \"mustache.js\";\n mustache.version = \"2.2.1\";\n mustache.tags = [\"{{\", \"}}\"];\n\n // All high-level mustache.* functions use this writer.\n var defaultWriter = new Writer();\n\n /**\n * Clears all cached templates in the default writer.\n */\n mustache.clearCache = function clearCache() {\n return defaultWriter.clearCache();\n };\n\n /**\n * Parses and caches the given template in the default writer and returns the\n * array of tokens it contains. Doing this ahead of time avoids the need to\n * parse templates on the fly as they are rendered.\n */\n mustache.parse = function parse(template, tags) {\n return defaultWriter.parse(template, tags);\n };\n\n /**\n * Renders the `template` with the given `view` and `partials` using the\n * default writer.\n */\n mustache.render = function render(template, view, partials) {\n if (typeof template !== \"string\") {\n throw new TypeError(\n 'Invalid template! Template should be a \"string\" ' +\n 'but \"' +\n typeStr(template) +\n '\" was given as the first ' +\n \"argument for mustache#render(template, view, partials)\"\n );\n }\n\n return defaultWriter.render(template, view, partials);\n };\n\n // This is here for backwards compatibility with 0.4.x.,\n /*eslint-disable */ // eslint wants camel cased function name\n mustache.to_html = function to_html(template, view, partials, send) {\n /*eslint-enable*/\n\n var result = mustache.render(template, view, partials);\n\n if (isFunction(send)) {\n send(result);\n } else {\n return result;\n }\n };\n\n // Export the escaping function so that the user may override it.\n // See https://github.com/janl/mustache.js/issues/244\n mustache.escape = escapeHtml;\n\n // Export these mainly for testing, but also for advanced usage.\n mustache.Scanner = Scanner;\n mustache.Context = Context;\n mustache.Writer = Writer;\n}\n\nlet Mustache = {};\n\nmustacheFactory(Mustache);\n\nexport default Mustache;\nexport { Mustache };\n", "//\n// showdown.js -- A javascript port of Markdown.\n//\n// Copyright (c) 2007 John Fraser.\n//\n// Original Markdown Copyright (c) 2004-2005 John Gruber\n// \n//\n// Redistributable under a BSD-style open source license.\n// See license.txt for more information.\n//\n// The full source distribution is at:\n//\n//\t\t\t\tA A L\n//\t\t\t\tT C A\n//\t\t\t\tT K B\n//\n// \n//\n\n//\n// Wherever possible, Showdown is a straight, line-by-line port\n// of the Perl version of Markdown.\n//\n// This is not a normal parser design; it's basically just a\n// series of string substitutions. It's hard to read and\n// maintain this way, but keeping Showdown close to the original\n// design makes it easier to port new features.\n//\n// More importantly, Showdown behaves like markdown.pl in most\n// edge cases. So web applications can do client-side preview\n// in Javascript, and then build identical HTML on the server.\n//\n// This port needs the new RegExp functionality of ECMA 262,\n// 3rd Edition (i.e. Javascript 1.5). Most modern web browsers\n// should do fine. Even with the new regular expression features,\n// We do a lot of work to emulate Perl's regex functionality.\n// The tricky changes in this file mostly have the \"attacklab:\"\n// label. Major or self-explanatory changes don't.\n//\n// Smart diff tools like Araxis Merge will be able to match up\n// this file with markdown.pl in a useful way. A little tweaking\n// helps: in a copy of markdown.pl, replace \"#\" with \"//\" and\n// replace \"$text\" with \"text\". Be sure to ignore whitespace\n// and line endings.\n//\n\n//\n// Showdown usage:\n//\n// var text = \"Markdown *rocks*.\";\n//\n// var converter = new Showdown.converter();\n// var html = converter.makeHtml(text);\n//\n// alert(html);\n//\n// Note: move the sample code to the bottom of this\n// file before uncommenting it.\n//\n\n//\n// Showdown namespace\n//\nvar Showdown = {};\n\n//\n// converter\n//\n// Wraps all \"globals\" so that the only thing\n// exposed is makeHtml().\n//\nShowdown.converter = function () {\n //\n // Globals:\n //\n\n // Global hashes, used by various utility routines\n var g_urls;\n var g_titles;\n var g_html_blocks;\n\n // Used to track when we're inside an ordered or unordered list\n // (see _ProcessListItems() for details):\n var g_list_level = 0;\n\n this.makeHtml = function (text, inline_only) {\n //\n // Main function. The order in which other subs are called here is\n // essential. Link and image substitutions need to happen before\n // _EscapeSpecialCharsWithinTagAttributes(), so that any *'s or _'s in the \n // and tags get encoded.\n //\n\n // Clear the global hashes. If we don't clear these, you get conflicts\n // from other articles when generating a page which contains more than\n // one article (e.g. an index page that shows the N most recent\n // articles):\n g_urls = new Array();\n g_titles = new Array();\n g_html_blocks = new Array();\n\n // attacklab: Replace ~ with ~T\n // This lets us use tilde as an escape char to avoid md5 hashes\n // The choice of character is arbitray; anything that isn't\n // magic in Markdown will work.\n text = text.replace(/~/g, \"~T\");\n\n // attacklab: Replace $ with ~D\n // RegExp interprets $ as a special character\n // when it's in a replacement string\n text = text.replace(/\\$/g, \"~D\");\n\n // Standardize line endings\n text = text.replace(/\\r\\n/g, \"\\n\"); // DOS to Unix\n text = text.replace(/\\r/g, \"\\n\"); // Mac to Unix\n\n // Make sure text begins and ends with a couple of newlines:\n text = \"\\n\\n\" + text + \"\\n\\n\";\n\n // Convert all tabs to spaces.\n text = _Detab(text);\n\n // Strip any lines consisting only of spaces and tabs.\n // This makes subsequent regexen easier to write, because we can\n // match consecutive blank lines with /\\n+/ instead of something\n // contorted like /[ \\t]*\\n+/ .\n text = text.replace(/^[ \\t]+$/gm, \"\");\n\n // Turn block-level HTML blocks into hash entries\n text = _HashHTMLBlocks(text);\n\n // Strip link definitions, store in hashes.\n text = _StripLinkDefinitions(text);\n\n if (inline_only) text = _RunSpanGamut(text);\n else text = _RunBlockGamut(text);\n\n text = _UnescapeSpecialChars(text);\n\n // attacklab: Restore dollar signs\n text = text.replace(/~D/g, \"$$\");\n\n // attacklab: Restore tildes\n text = text.replace(/~T/g, \"~\");\n\n return text;\n };\n\n var _StripLinkDefinitions = function (text) {\n //\n // Strips link definitions from text, stores the URLs and titles in\n // hash references.\n //\n\n // Link defs are in the form: ^[id]: url \"optional title\"\n\n /*\n var text = text.replace(/\n ^[ ]{0,3}\\[(.+)\\]: // id = $1 attacklab: g_tab_width - 1\n [ \\t]*\n \\n?\t\t\t\t// maybe *one* newline\n [ \\t]*\n (\\S+?)>?\t\t\t// url = $2\n [ \\t]*\n \\n?\t\t\t\t// maybe one newline\n [ \\t]*\n (?:\n (\\n*)\t\t\t\t// any lines skipped = $3 attacklab: lookbehind removed\n [\"(]\n (.+?)\t\t\t\t// title = $4\n [\")]\n [ \\t]*\n )?\t\t\t\t\t// title is optional\n (?:\\n+|$)\n /gm,\n function(){...});\n */\n var text = text.replace(\n /^[ ]{0,3}\\[(.+)\\]:[ \\t]*\\n?[ \\t]*(\\S+?)>?[ \\t]*\\n?[ \\t]*(?:(\\n*)[\"(](.+?)[\")][ \\t]*)?(?:\\n+|\\Z)/gm,\n function (wholeMatch, m1, m2, m3, m4) {\n m1 = m1.toLowerCase();\n g_urls[m1] = _EncodeAmpsAndAngles(m2); // Link IDs are case-insensitive\n if (m3) {\n // Oops, found blank lines, so it's not a title.\n // Put back the parenthetical statement we stole.\n return m3 + m4;\n } else if (m4) {\n g_titles[m1] = m4.replace(/\"/g, \""\");\n }\n\n // Completely remove the definition from the text\n return \"\";\n }\n );\n\n return text;\n };\n\n var _HashHTMLBlocks = function (text) {\n // attacklab: Double up blank lines to reduce lookaround\n text = text.replace(/\\n/g, \"\\n\\n\");\n\n // Hashify HTML blocks:\n // We only want to do this for block-level HTML tags, such as headers,\n // lists, and tables. That's because we still want to wrap
\");\n }\n );\n\n text = text.replace(\n /^(.+)[ \\t]*\\n-+[ \\t]*\\n+/gm,\n function (matchFound, m1) {\n return hashBlock(\"
\" + _RunSpanGamut(m1) + \"
\");\n }\n );\n\n // atx-style headers:\n // # Header 1\n // ## Header 2\n // ## Header 2 with closing hashes ##\n // ...\n // ###### Header 6\n //\n\n /*\n text = text.replace(/\n ^(\\#{1,6})\t\t\t\t// $1 = string of #'s\n [ \\t]*\n (.+?)\t\t\t\t\t// $2 = Header text\n [ \\t]*\n \\#*\t\t\t\t\t\t// optional closing #'s (not counted)\n \\n+\n /gm, function() {...});\n */\n\n text = text.replace(\n /^(\\#{1,6})[ \\t]*(.+?)[ \\t]*\\#*\\n+/gm,\n function (wholeMatch, m1, m2) {\n var h_level = m1.length;\n return hashBlock(\n \"\" + _RunSpanGamut(m2) + \"\"\n );\n }\n );\n\n return text;\n };\n\n // This declaration keeps Dojo compressor from outputting garbage:\n var _ProcessListItems;\n\n var _DoLists = function (text) {\n //\n // Form HTML ordered (numbered) and unordered (bulleted) lists.\n //\n\n // attacklab: add sentinel to hack around khtml/safari bug:\n // http://bugs.webkit.org/show_bug.cgi?id=11231\n text += \"~0\";\n\n // Re-usable pattern to match any entirel ul or ol list:\n\n /*\n var whole_list = /\n (\t\t\t\t\t\t\t\t\t// $1 = whole list\n (\t\t\t\t\t\t\t\t// $2\n [ ]{0,3}\t\t\t\t\t// attacklab: g_tab_width - 1\n ([*+-]|\\d+[.])\t\t\t\t// $3 = first list item marker\n [ \\t]+\n )\n [^\\r]+?\n (\t\t\t\t\t\t\t\t// $4\n ~0\t\t\t\t\t\t\t// sentinel for workaround; should be $\n |\n \\n{2,}\n (?=\\S)\n (?!\t\t\t\t\t\t\t// Negative lookahead for another list item marker\n [ \\t]*\n (?:[*+-]|\\d+[.])[ \\t]+\n )\n )\n )/g\n */\n var whole_list =\n /^(([ ]{0,3}([*+-]|\\d+[.])[ \\t]+)[^\\r]+?(~0|\\n{2,}(?=\\S)(?![ \\t]*(?:[*+-]|\\d+[.])[ \\t]+)))/gm;\n\n if (g_list_level) {\n text = text.replace(whole_list, function (wholeMatch, m1, m2) {\n var list = m1;\n var list_type = m2.search(/[*+-]/g) > -1 ? \"ul\" : \"ol\";\n\n // Turn double returns into triple returns, so that we can make a\n // paragraph for the last item in a list, if necessary:\n list = list.replace(/\\n{2,}/g, \"\\n\\n\\n\");\n var result = _ProcessListItems(list);\n\n // Trim any trailing whitespace, to put the closing `$list_type>`\n // up on the preceding line, to get it past the current stupid\n // HTML block parser. This is a hack to work around the terrible\n // hack that is the HTML block parser.\n result = result.replace(/\\s+$/, \"\");\n result = \"<\" + list_type + \">\" + result + \"\" + list_type + \">\\n\";\n return result;\n });\n } else {\n whole_list =\n /(\\n\\n|^\\n?)(([ ]{0,3}([*+-]|\\d+[.])[ \\t]+)[^\\r]+?(~0|\\n{2,}(?=\\S)(?![ \\t]*(?:[*+-]|\\d+[.])[ \\t]+)))/g;\n text = text.replace(whole_list, function (wholeMatch, m1, m2, m3) {\n var runup = m1;\n var list = m2;\n\n var list_type = m3.search(/[*+-]/g) > -1 ? \"ul\" : \"ol\";\n // Turn double returns into triple returns, so that we can make a\n // paragraph for the last item in a list, if necessary:\n var list = list.replace(/\\n{2,}/g, \"\\n\\n\\n\");\n var result = _ProcessListItems(list);\n result =\n runup + \"<\" + list_type + \">\\n\" + result + \"\" + list_type + \">\\n\";\n return result;\n });\n }\n\n // attacklab: strip sentinel\n text = text.replace(/~0/, \"\");\n\n return text;\n };\n\n _ProcessListItems = function (list_str) {\n //\n // Process the contents of a single ordered or unordered list, splitting it\n // into individual list items.\n //\n // The $g_list_level global keeps track of when we're inside a list.\n // Each time we enter a list, we increment it; when we leave a list,\n // we decrement. If it's zero, we're not in a list anymore.\n //\n // We do this because when we're not inside a list, we want to treat\n // something like this:\n //\n // I recommend upgrading to version\n // 8. Oops, now this line is treated\n // as a sub-list.\n //\n // As a single paragraph, despite the fact that the second line starts\n // with a digit-period-space sequence.\n //\n // Whereas when we're inside a list (or sub-list), that line will be\n // treated as the start of a sub-list. What a kludge, huh? This is\n // an aspect of Markdown's syntax that's hard to parse perfectly\n // without resorting to mind-reading. Perhaps the solution is to\n // change the syntax rules such that sub-lists must start with a\n // starting cardinal number; e.g. \"1.\" or \"a.\".\n\n g_list_level++;\n\n // trim trailing blank lines:\n list_str = list_str.replace(/\\n{2,}$/, \"\\n\");\n\n // attacklab: add sentinel to emulate \\z\n list_str += \"~0\";\n\n /*\n list_str = list_str.replace(/\n (\\n)?\t\t\t\t\t\t\t// leading line = $1\n (^[ \\t]*)\t\t\t\t\t\t// leading whitespace = $2\n ([*+-]|\\d+[.]) [ \\t]+\t\t\t// list marker = $3\n ([^\\r]+?\t\t\t\t\t\t// list item text = $4\n (\\n{1,2}))\n (?= \\n* (~0 | \\2 ([*+-]|\\d+[.]) [ \\t]+))\n /gm, function(){...});\n */\n list_str = list_str.replace(\n /(\\n)?(^[ \\t]*)([*+-]|\\d+[.])[ \\t]+([^\\r]+?(\\n{1,2}))(?=\\n*(~0|\\2([*+-]|\\d+[.])[ \\t]+))/gm,\n function (wholeMatch, m1, m2, m3, m4) {\n var item = m4;\n var leading_line = m1;\n var leading_space = m2;\n\n if (leading_line || item.search(/\\n{2,}/) > -1) {\n item = _RunBlockGamut(_Outdent(item));\n } else {\n // Recursion for sub-lists:\n item = _DoLists(_Outdent(item));\n item = item.replace(/\\n$/, \"\"); // chomp(item)\n item = _RunSpanGamut(item);\n }\n\n return \"
\" + item + \"
\\n\";\n }\n );\n\n // attacklab: strip sentinel\n list_str = list_str.replace(/~0/g, \"\");\n\n g_list_level--;\n return list_str;\n };\n\n var _DoCodeBlocks = function (text) {\n //\n // Process Markdown `
` blocks.\n //\n\n /*\n text = text.replace(text,\n /(?:\\n\\n|^)\n (\t\t\t\t\t\t\t\t// $1 = the code block -- one or more lines, starting with a space/tab\n (?:\n (?:[ ]{4}|\\t)\t\t\t// Lines must start with a tab or a tab-width of spaces - attacklab: g_tab_width\n .*\\n+\n )+\n )\n (\\n*[ ]{0,3}[^ \\t\\n]|(?=~0))\t// attacklab: g_tab_width\n /g,function(){...});\n */\n\n // attacklab: sentinel workarounds for lack of \\A and \\Z, safari\\khtml bug\n text += \"~0\";\n\n text = text.replace(\n /(?:\\n\\n|^)((?:(?:[ ]{4}|\\t).*\\n+)+)(\\n*[ ]{0,3}[^ \\t\\n]|(?=~0))/g,\n function (wholeMatch, m1, m2) {\n var codeblock = m1;\n var nextChar = m2;\n\n codeblock = _EncodeCode(_Outdent(codeblock));\n codeblock = _Detab(codeblock);\n codeblock = codeblock.replace(/^\\n+/g, \"\"); // trim leading newlines\n codeblock = codeblock.replace(/\\n+$/g, \"\"); // trim trailing whitespace\n\n codeblock = \"
\" + codeblock + \"\\n
\";\n\n return hashBlock(codeblock) + nextChar;\n }\n );\n\n // attacklab: strip sentinel\n text = text.replace(/~0/, \"\");\n\n return text;\n };\n\n var hashBlock = function (text) {\n text = text.replace(/(^\\n+|\\n+$)/g, \"\");\n return \"\\n\\n~K\" + (g_html_blocks.push(text) - 1) + \"K\\n\\n\";\n };\n\n var _DoCodeSpans = function (text) {\n //\n // * Backtick quotes are used for spans.\n //\n // * You can use multiple backticks as the delimiters if you want to\n // include literal backticks in the code span. So, this input:\n //\n // Just type ``foo `bar` baz`` at the prompt.\n //\n // Will translate to:\n //\n //
Just type foo `bar` baz at the prompt.
\n //\n //\tThere's no arbitrary limit to the number of backticks you\n //\tcan use as delimters. If you need three consecutive backticks\n //\tin your code, use four for delimiters, etc.\n //\n // * You can use spaces to get literal backticks at the edges:\n //\n // ... type `` `bar` `` ...\n //\n // Turns to:\n //\n // ... type `bar` ...\n //\n\n /*\n text = text.replace(/\n (^|[^\\\\])\t\t\t\t\t// Character before opening ` can't be a backslash\n (`+)\t\t\t\t\t\t// $2 = Opening run of `\n (\t\t\t\t\t\t\t// $3 = The code block\n [^\\r]*?\n [^`]\t\t\t\t\t// attacklab: work around lack of lookbehind\n )\n \\2\t\t\t\t\t\t\t// Matching closer\n (?!`)\n /gm, function(){...});\n */\n\n text = text.replace(\n /(^|[^\\\\])(`+)([^\\r]*?[^`])\\2(?!`)/gm,\n function (wholeMatch, m1, m2, m3, m4) {\n var c = m3;\n c = c.replace(/^([ \\t]*)/g, \"\"); // leading whitespace\n c = c.replace(/[ \\t]*$/g, \"\"); // trailing whitespace\n c = _EncodeCode(c);\n return m1 + \"\" + c + \"\";\n }\n );\n\n return text;\n };\n\n var _EncodeCode = function (text) {\n //\n // Encode/escape certain characters inside Markdown code runs.\n // The point is that in code, these characters are literals,\n // and lose their special Markdown meanings.\n //\n // Encode all ampersands; HTML entities are not\n // entities within a Markdown code span.\n text = text.replace(/&/g, \"&\");\n\n // Do the angle bracket song and dance:\n text = text.replace(//g, \">\");\n\n // Now, escape characters that are magic in Markdown:\n text = escapeCharacters(text, \"*_{}[]\\\\\", false);\n\n // jj the line above breaks this:\n //---\n\n //* Item\n\n // 1. Subitem\n\n // special char: *\n //---\n\n return text;\n };\n\n var _DoItalicsAndBold = function (text) {\n // must go first:\n text = text.replace(\n /(\\*\\*|__)(?=\\S)([^\\r]*?\\S[*_]*)\\1/g,\n \"$2\"\n );\n\n text = text.replace(/(\\*|_)(?=\\S)([^\\r]*?\\S)\\1/g, \"$2\");\n\n return text;\n };\n\n var _DoBlockQuotes = function (text) {\n /*\n text = text.replace(/\n (\t\t\t\t\t\t\t\t// Wrap whole match in $1\n (\n ^[ \\t]*>[ \\t]?\t\t\t// '>' at the start of a line\n .+\\n\t\t\t\t\t// rest of the first line\n (.+\\n)*\t\t\t\t\t// subsequent consecutive lines\n \\n*\t\t\t\t\t\t// blanks\n )+\n )\n /gm, function(){...});\n */\n\n text = text.replace(\n /((^[ \\t]*>[ \\t]?.+\\n(.+\\n)*\\n*)+)/gm,\n function (wholeMatch, m1) {\n var bq = m1;\n\n // attacklab: hack around Konqueror 3.5.4 bug:\n // \"----------bug\".replace(/^-/g,\"\") == \"bug\"\n\n bq = bq.replace(/^[ \\t]*>[ \\t]?/gm, \"~0\"); // trim one level of quoting\n\n // attacklab: clean up hack\n bq = bq.replace(/~0/g, \"\");\n\n bq = bq.replace(/^[ \\t]+$/gm, \"\"); // trim whitespace-only lines\n bq = _RunBlockGamut(bq); // recurse\n\n bq = bq.replace(/(^|\\n)/g, \"$1 \");\n // These leading spaces screw with
content, so we need to fix that:\n bq = bq.replace(\n /(\\s*
[^\\r]+?<\\/pre>)/gm,\n function (wholeMatch, m1) {\n var pre = m1;\n // attacklab: hack around Konqueror 3.5.4 bug:\n pre = pre.replace(/^ /gm, \"~0\");\n pre = pre.replace(/~0/g, \"\");\n return pre;\n }\n );\n\n return hashBlock(\"
\\n\" + bq + \"\\n
\");\n }\n );\n return text;\n };\n\n var _FormParagraphs = function (text) {\n //\n // Params:\n // $text - string to process with html
tags\n //\n\n // Strip leading and trailing lines:\n text = text.replace(/^\\n+/g, \"\");\n text = text.replace(/\\n+$/g, \"\");\n\n var grafs = text.split(/\\n{2,}/g);\n var grafsOut = new Array();\n\n //\n // Wrap
tags.\n //\n var end = grafs.length;\n for (var i = 0; i < end; i++) {\n var str = grafs[i];\n\n // if this is an HTML marker, copy it\n if (str.search(/~K(\\d+)K/g) >= 0) {\n grafsOut.push(str);\n } else if (str.search(/\\S/) >= 0) {\n str = _RunSpanGamut(str);\n str = str.replace(/^([ \\t]*)/g, \"
\");\n str += \"
\";\n grafsOut.push(str);\n }\n }\n\n //\n // Unhashify HTML blocks\n //\n end = grafsOut.length;\n for (var i = 0; i < end; i++) {\n // if this is a marker for an html block...\n while (grafsOut[i].search(/~K(\\d+)K/) >= 0) {\n var blockText = g_html_blocks[RegExp.$1];\n blockText = blockText.replace(/\\$/g, \"$$$$\"); // Escape any dollar signs\n grafsOut[i] = grafsOut[i].replace(/~K\\d+K/, blockText);\n }\n }\n\n return grafsOut.join(\"\\n\\n\");\n };\n\n var _EncodeAmpsAndAngles = function (text) {\n // Smart processing for ampersands and angle brackets that need to be encoded.\n\n // Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:\n // http://bumppo.net/projects/amputator/\n text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\\w+);)/g, \"&\");\n\n // Encode naked <'s\n text = text.replace(/<(?![a-z\\/?\\$!])/gi, \"<\");\n\n return text;\n };\n\n var _EncodeBackslashEscapes = function (text) {\n //\n // Parameter: String.\n // Returns:\tThe string, with after processing the following backslash\n // escape sequences.\n //\n\n // attacklab: The polite way to do this is with the new\n // escapeCharacters() function:\n //\n // text = escapeCharacters(text,\"\\\\\",true);\n // text = escapeCharacters(text,\"`*_{}[]()>#+-.!\",true);\n //\n // ...but we're sidestepping its use of the (slow) RegExp constructor\n // as an optimization for Firefox. This function gets called a LOT.\n\n text = text.replace(/\\\\(\\\\)/g, escapeCharacters_callback);\n text = text.replace(/\\\\([`*_{}\\[\\]()>#+-.!])/g, escapeCharacters_callback);\n return text;\n };\n\n var _DoAutoLinks = function (text) {\n text = text.replace(\n /<((https?|ftp|dict):[^'\">\\s]+)>/gi,\n '$1'\n );\n\n // Email addresses: \n\n /*\n text = text.replace(/\n <\n (?:mailto:)?\n (\n [-.\\w]+\n \\@\n [-a-z0-9]+(\\.[-a-z0-9]+)*\\.[a-z]+\n )\n >\n /gi, _DoAutoLinks_callback());\n */\n text = text.replace(\n /<(?:mailto:)?([-.\\w]+\\@[-a-z0-9]+(\\.[-a-z0-9]+)*\\.[a-z]+)>/gi,\n function (wholeMatch, m1) {\n return _EncodeEmailAddress(_UnescapeSpecialChars(m1));\n }\n );\n\n return text;\n };\n\n var _EncodeEmailAddress = function (addr) {\n //\n // Input: an email address, e.g. \"foo@example.com\"\n //\n // Output: the email address as a mailto link, with each character\n //\tof the address encoded as either a decimal or hex entity, in\n //\tthe hopes of foiling most address harvesting spam bots. E.g.:\n //\n //\tfoo\n // @example.com\n //\n // Based on a filter by Matthew Wickline, posted to the BBEdit-Talk\n // mailing list: \n //\n\n // attacklab: why can't javascript speak hex?\n function char2hex(ch) {\n var hexDigits = \"0123456789ABCDEF\";\n var dec = ch.charCodeAt(0);\n return hexDigits.charAt(dec >> 4) + hexDigits.charAt(dec & 15);\n }\n\n var encode = [\n function (ch) {\n return \"\" + ch.charCodeAt(0) + \";\";\n },\n function (ch) {\n return \"\" + char2hex(ch) + \";\";\n },\n function (ch) {\n return ch;\n }\n ];\n\n addr = \"mailto:\" + addr;\n\n addr = addr.replace(/./g, function (ch) {\n if (ch == \"@\") {\n // this *must* be encoded. I insist.\n ch = encode[Math.floor(Math.random() * 2)](ch);\n } else if (ch != \":\") {\n // leave ':' alone (to spot mailto: later)\n var r = Math.random();\n // roughly 10% raw, 45% hex, 45% dec\n ch = r > 0.9 ? encode[2](ch) : r > 0.45 ? encode[1](ch) : encode[0](ch);\n }\n return ch;\n });\n\n addr = '' + addr + \"\";\n addr = addr.replace(/\">.+:/g, '\">'); // strip the mailto: from the visible part\n\n return addr;\n };\n\n var _UnescapeSpecialChars = function (text) {\n //\n // Swap back in all the special characters we've hidden.\n //\n text = text.replace(/~E(\\d+)E/g, function (wholeMatch, m1) {\n var charCodeToReplace = parseInt(m1);\n return String.fromCharCode(charCodeToReplace);\n });\n return text;\n };\n\n var _Outdent = function (text) {\n //\n // Remove one level of line-leading tabs or spaces\n //\n\n // attacklab: hack around Konqueror 3.5.4 bug:\n // \"----------bug\".replace(/^-/g,\"\") == \"bug\"\n\n text = text.replace(/^(\\t|[ ]{1,4})/gm, \"~0\"); // attacklab: g_tab_width\n\n // attacklab: clean up hack\n text = text.replace(/~0/g, \"\");\n\n return text;\n };\n\n var _Detab = function (text) {\n // attacklab: Detab's completely rewritten for speed.\n // In perl we could fix it by anchoring the regexp with \\G.\n // In javascript we're less fortunate.\n\n // expand first n-1 tabs\n text = text.replace(/\\t(?=\\t)/g, \" \"); // attacklab: g_tab_width\n\n // replace the nth with two sentinels\n text = text.replace(/\\t/g, \"~A~B\");\n\n // use the sentinel to anchor our regex so it doesn't explode\n text = text.replace(/~B(.+?)~A/g, function (wholeMatch, m1, m2) {\n var leadingText = m1;\n var numSpaces = 4 - (leadingText.length % 4); // attacklab: g_tab_width\n\n // there *must* be a better way to do this:\n for (var i = 0; i < numSpaces; i++) leadingText += \" \";\n\n return leadingText;\n });\n\n // clean up sentinels\n text = text.replace(/~A/g, \" \"); // attacklab: g_tab_width\n text = text.replace(/~B/g, \"\");\n\n return text;\n };\n\n //\n // attacklab: Utility functions\n //\n\n var escapeCharacters = function (text, charsToEscape, afterBackslash) {\n // First we have to escape the escape characters so that\n // we can build a character class out of them\n var regexString =\n \"([\" + charsToEscape.replace(/([\\[\\]\\\\])/g, \"\\\\$1\") + \"])\";\n\n if (afterBackslash) {\n regexString = \"\\\\\\\\\" + regexString;\n }\n\n var regex = new RegExp(regexString, \"g\");\n text = text.replace(regex, escapeCharacters_callback);\n\n return text;\n };\n\n var escapeCharacters_callback = function (wholeMatch, m1) {\n var charCodeToEscape = m1.charCodeAt(0);\n return \"~E\" + charCodeToEscape + \"E\";\n };\n}; // end of Showdown.converter\n\nexport default Showdown;\n", "import { default as Showdown } from \"$showdown\";\nexport { converter };\n\nconst converter = new Showdown.converter();\n\nconst orig = converter.makeHtml.bind(converter);\nconverter.makeHtml = (text, inline) =>\n orig(text, inline).replace(/\n * @author Karol Kuczmarski \"Xion\"\n * @note Contains ideas from http://stackoverflow.com/a/2032642/434799\n */\n\n(function ($) {\n $.fn.extend({\n xarea: function () {\n return this.filter(\"textarea\").each(function () {\n var $this = $(this);\n var markup = setupMarkup($this);\n var autosize = setupAutosize(markup);\n autosize();\n });\n }\n });\n\n let cloneCss = ($textarea, $mimic) => {\n $mimic.css({\n fontFamily: $textarea.css(\"font-family\"),\n fontSize: $textarea.css(\"font-size\"),\n fontWeight: $textarea.css(\"font-weight\"),\n lineHeight: $textarea.css(\"line-height\")\n });\n $mimic.css(\"min-height\", $textarea.outerHeight());\n $mimic.css(\"marginLeft\", $textarea.css(\"marginLeft\"));\n $mimic.css(\"marginRight\", $textarea.css(\"marginRight\"));\n $mimic.css(\"marginTop\", $textarea.css(\"marginTop\"));\n $mimic.css(\"marginBottom\", $textarea.css(\"marginBottom\"));\n $mimic.css(\"paddingLeft\", $textarea.css(\"paddingLeft\"));\n $mimic.css(\"paddingTop\", $textarea.css(\"paddingTop\"));\n $mimic.css(\"paddingRight\", $textarea.css(\"paddingRight\"));\n $mimic.css(\"border\", $textarea.css(\"border\"));\n };\n\n var setupMarkup = function ($textarea) {\n var $container = $(\"\");\n $container.css(\"position\", \"relative\");\n\n // create \"mimic\"