{"version":3,"sources":["https:\/\/digital.tueftellab.de\/local\/edwiserreports\/amd\/src\/install.js"],"names":["_toConsumableArray","arr","_arrayWithoutHoles","_iterableToArray","_unsupportedIterableToArray","_nonIterableSpread","TypeError","o","minLen","_arrayLikeToArray","n","Object","prototype","toString","call","slice","constructor","name","Array","from","test","iter","Symbol","iterator","isArray","len","length","i","arr2","define","$","ajax","findDuplicates","list","filter","item","index","indexOf","findMissings","dummyPositions","fixDuplicatePosition","duplicate","missing","skippedFirst","fixer","forEach","initializePositionsHandler","positionSelector","currentPositions","each","idx","val","push","parseInt","keys","duplicates","missings","position","fixDuplicatePositions","on","_this","this","posChangedIdx","prevSelectVal","currSelectVal","updater","init","methodname","args","pluginname","configname","done","response","success","document","ready","event","preventDefault","submit"],"mappings":"AAAA,aAEA,SAASA,mBAAmBC,GAAO,OAAOC,mBAAmBD,IAAQE,iBAAiBF,IAAQG,4BAA4BH,IAAQI,qBAClI,SAASA,qBAAuB,MAAM,IAAIC,UAAU,wIACpD,SAASF,4BAA4BG,EAAGC,GAAU,GAAKD,EAAL,CAAgB,GAAiB,iBAANA,EAAgB,OAAOE,kBAAkBF,EAAGC,GAAS,IAAIE,EAAIC,OAAOC,UAAUC,SAASC,KAAKP,GAAGQ,MAAM,GAAI,GAAiE,MAAnD,WAANL,GAAkBH,EAAES,cAAaN,EAAIH,EAAES,YAAYC,MAAgB,QAANP,GAAqB,QAANA,EAAoBQ,MAAMC,KAAKZ,GAAc,cAANG,GAAqB,2CAA2CU,KAAKV,GAAWD,kBAAkBF,EAAGC,QAAzG,GAC7S,SAASL,iBAAiBkB,GAAQ,GAAsB,oBAAXC,QAAmD,MAAzBD,EAAKC,OAAOC,WAA2C,MAAtBF,EAAK,cAAuB,OAAOH,MAAMC,KAAKE,GACtJ,SAASnB,mBAAmBD,GAAO,GAAIiB,MAAMM,QAAQvB,GAAM,OAAOQ,kBAAkBR,GACpF,SAASQ,kBAAkBR,EAAKwB,IAAkB,MAAPA,GAAeA,EAAM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is part of Moodle - http:\/\/moodle.org\/\n\/\/\n\/\/ Moodle is free software: you can redistribute it and\/or modify\n\/\/ it under the terms of the GNU General Public License as published by\n\/\/ the Free Software Foundation, either version 3 of the License, or\n\/\/ (at your option) any later version.\n\/\/\n\/\/ Moodle is distributed in the hope that it will be useful,\n\/\/ but WITHOUT ANY WARRANTY; without even the implied warranty of\n\/\/ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\/\/ GNU General Public License for more details.\n\/\/\n\/\/ You should have received a copy of the GNU General Public License\n\/\/ along with Moodle. If not, see .\n\/**\n * Plugin administration pages are defined here.\n *\n * @copyright 2021 wisdmlabs \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\/* eslint-disable no-console *\/\ndefine(['jquery', 'core\/ajax'], function($, ajax) {\n\n \/**\n * Find duplicate positions in list\n * @param {Array} list Position list\n * @returns {Array}\n *\/\n function findDuplicates(list) {\n return list.filter((item, index) => list.indexOf(item) !== index);\n }\n\n \/**\n * Find missing positions in list.\n * @param {Array} list Position list\n * @param {Array} dummyPositions Dummy positions to search\n * @returns {Array}\n *\/\n function findMissings(list, dummyPositions) {\n return dummyPositions.filter(item => list.indexOf(item) === -1);\n }\n\n \/**\n * Fix duplicate position from list.\n * @param {Array} list Position list\n * @param {Integer} duplicate Duplicate position\n * @param {Integer} missing Missing position\n *\/\n function fixDuplicatePosition(list, duplicate, missing) {\n let skippedFirst = false;\n let fixer = duplicate > missing ? -1 : 1;\n list.forEach(function(item, index) {\n \/\/ Skip first duplicate item.\n if (item == duplicate && skippedFirst == false) {\n skippedFirst = true;\n return;\n }\n\n \/\/ Fixed duplicate item.\n if (item == duplicate) {\n list[index] = item + fixer;\n return;\n }\n\n \/\/ Decrease item position.\n if (duplicate > missing && item > missing && item < duplicate) {\n list[index] = item + fixer;\n return;\n }\n\n \/\/ Increase item position.\n if (duplicate < missing && item < missing && item > duplicate) {\n list[index] = item + fixer;\n return;\n }\n });\n }\n\n \/**\n * Fix duplicate positions in list.\n * @param {Array} list Position list\n * @param {String} positionSelector Position select\n *\/\n function fixDuplicatePositions(list, positionSelector) {\n \/\/ Create dummy positions.\n let dummyPositions = [...Array(list.length).keys()];\n\n \/\/ Find duplicate positions.\n let duplicates = findDuplicates(list);\n\n \/\/ Find missing positions.\n let missings = findMissings(list, dummyPositions);\n while (duplicates.length > 0) {\n for (let i = 0; i < duplicates.length; i++) {\n let duplicate = duplicates[i];\n let missing = missings[i];\n fixDuplicatePosition(list, duplicate, missing);\n }\n duplicates = findDuplicates(list);\n missings = findMissings(list, dummyPositions);\n }\n\n \/\/ Apply fixed positions.\n $(positionSelector).each(function(index, position) {\n $(position).val(list[index]);\n });\n }\n\n \/**\n * Initialize position handler.\n *\/\n function initializePositionsHandler() {\n var positionSelector = 'select[id ^=id_s_local_edwiserreports][id $=position]';\n\n var currentPositions = [];\n $(positionSelector).each(function(idx, val) {\n currentPositions.push(parseInt($(val).val()));\n });\n\n \/\/ Fix duplicate positions.\n fixDuplicatePositions(currentPositions, positionSelector);\n\n $(positionSelector).on('change', function() {\n var _this = this;\n var posChangedIdx = false;\n $(positionSelector).each(function(idx, val) {\n if (_this.name == val.name) {\n posChangedIdx = idx;\n return;\n }\n });\n\n var prevSelectVal = parseInt(currentPositions[posChangedIdx]);\n var currSelectVal = parseInt($(this).val());\n var updater = prevSelectVal > currSelectVal ? 1 : -1;\n\n \/\/ Rearrange other positions.\n currentPositions.forEach((position, index) => {\n if (prevSelectVal == position) {\n position = currSelectVal;\n } else if (prevSelectVal > currSelectVal) {\n if (position < prevSelectVal && position >= currSelectVal) {\n position += updater;\n }\n } else if (prevSelectVal < currSelectVal) {\n if (position > prevSelectVal && position <= currSelectVal) {\n position += updater;\n }\n }\n currentPositions[index] = position;\n });\n\n $(positionSelector).each(function(index, position) {\n $(position).val(currentPositions[index]);\n });\n\n });\n }\n\n var init = function() {\n var getConfig = 'local_edwiserreports_get_plugin_config';\n var getPluginConfig = ajax.call([{\n methodname: getConfig,\n args: {\n pluginname: 'local_edwiserreports',\n configname: 'edwiserreportsinstallation'\n }\n }]);\n\n getPluginConfig[0].done(function(response) {\n if (response.success) {\n var completeInstallation = 'local_edwiserreports_complete_edwiserreports_installation';\n var completePluginInstallation = ajax.call([{\n methodname: completeInstallation,\n args: {}\n }]);\n\n completePluginInstallation[0].done();\n }\n });\n\n $(document).ready(function() {\n $('#page-admin-setting-manageedwiserreports #adminsettings [type=\"submit\"]').on('click', function(event) {\n event.preventDefault();\n var setConfig = 'local_edwiserreports_set_plugin_config';\n var setPluginConfig = ajax.call([{\n methodname: setConfig,\n args: {\n pluginname: 'local_edwiserreports',\n configname: 'edwiserreportsinstallation'\n }\n }]);\n\n setPluginConfig[0].done(function() {\n $('#adminsettings').submit();\n });\n });\n\n initializePositionsHandler();\n });\n };\n\n return {\n init: init\n };\n});\n"],"file":"install.min.js"}