|
| 1 | +/** |
| 2 | + * this should NOT contain any main logic of system |
| 3 | + * only some smaller function passed for example in json configs etc. |
| 4 | + */ |
| 5 | + |
| 6 | +var uploadWidget = { |
| 7 | + |
| 8 | + /** |
| 9 | + * Selecting option corresponding to the category on which im at atm. |
| 10 | + * raw js while jquerry works within webpack scripts only |
| 11 | + */ |
| 12 | + selectCurrentModuleAndUploadDirOptionForQuickUpload: function () { |
| 13 | + |
| 14 | + let moduleSelect = document.querySelector("select#upload_form_upload_module_dir"); |
| 15 | + let directorySelect = document.querySelector("select#upload_form_subdirectory"); |
| 16 | + |
| 17 | + let moduleSelectOptions = document.querySelectorAll("select#upload_form_upload_module_dir option"); |
| 18 | + let directorySelectOptions = document.querySelectorAll("select#upload_form_subdirectory option"); |
| 19 | + |
| 20 | + let getAttrs = JSON.parse(TWIG_GET_ATTRS); |
| 21 | + let directoryPath = unescape(getAttrs.encoded_subdirectory_path) |
| 22 | + let route = TWIG_ROUTE; |
| 23 | + |
| 24 | + let moduleToSelect = ''; |
| 25 | + |
| 26 | + // swap module |
| 27 | + if ( route === 'modules_my_files' ) { |
| 28 | + moduleToSelect = 'files'; |
| 29 | + } else if( route === 'modules_my_images' ){ |
| 30 | + moduleToSelect = 'images'; |
| 31 | + } |
| 32 | + |
| 33 | + moduleSelect.setAttribute("value", moduleToSelect); |
| 34 | + moduleSelectOptions.forEach(function (option, index) { |
| 35 | + if (option.getAttribute("value") == moduleToSelect) { |
| 36 | + option.setAttribute("selected", "true"); |
| 37 | + } |
| 38 | + }); |
| 39 | + |
| 40 | + //swap dir |
| 41 | + let allOptgroups = directorySelect.querySelectorAll("optgroup"); |
| 42 | + allOptgroups.forEach(function (optgroup, index) { |
| 43 | + optgroup.setAttribute('class', 'd-none'); |
| 44 | + }); |
| 45 | + |
| 46 | + let optgroupForModule = directorySelect.querySelectorAll("optgroup[label^='" + moduleToSelect + "']")[0]; |
| 47 | + let options = optgroupForModule.childNodes; |
| 48 | + |
| 49 | + optgroupForModule.setAttribute('class', ''); |
| 50 | + |
| 51 | + if( null === directoryPath ){ // main dir |
| 52 | + // do nothing - main is always selected first |
| 53 | + return; |
| 54 | + } |
| 55 | + |
| 56 | + directorySelect.setAttribute("value", directoryPath); |
| 57 | + options.forEach(function (option, index) { |
| 58 | + option.setAttribute('class',''); |
| 59 | + if (option.getAttribute("value") == directoryPath) { |
| 60 | + option.setAttribute("selected", "true"); |
| 61 | + } |
| 62 | + }); |
| 63 | + |
| 64 | + } |
| 65 | + |
| 66 | +} |
0 commit comments