Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Add an "Email" form destination, sending a customized email when a form is submitted

### Changed

- Make the plugin compatible with the Content Security Policy

### Fixed

- Fix hidden question not available in anonymous forms
Expand Down
61 changes: 61 additions & 0 deletions public/js/email_addresses_field.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* -------------------------------------------------------------------------
* advancedforms plugin for GLPI
* -------------------------------------------------------------------------
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2025 by the advancedforms plugin team.
* @license MIT https://opensource.org/licenses/mit-license.php
* @link https://github.com/pluginsGLPI/advancedforms
* -------------------------------------------------------------------------
*/

/**
* Loaded right after the email addresses select (templates/destination/email_addresses_field.html.twig).
* Same tags dropdown as the actors fields of the ITIL objects.
*/
(function () {
const ready_attr = 'data-af-email-addresses-ready';

const template = (option) => option.id
? $('<span>').append('<i class="ti ti-mail mx-1"></i>', document.createTextNode(option.text))
: option.text;

document.querySelectorAll('[data-af-email-addresses]:not([' + ready_attr + '])').forEach((el) => {
el.setAttribute(ready_attr, '');
const email_regex = new RegExp(el.dataset.emailPattern, 'u');

$(el).select2({
tags: true,
width: '100%',
tokenSeparators: [',', ';', ' '],
templateSelection: template,
templateResult: template,
createTag: (params) => {
const term = $.trim(params.term);

// Return null to disable tag creation when it is not an email
return email_regex.test(term) ? {id: term, text: term} : null;
},
});
});
})();
56 changes: 56 additions & 0 deletions public/js/reservation_question.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* -------------------------------------------------------------------------
* advancedforms plugin for GLPI
* -------------------------------------------------------------------------
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2025 by the advancedforms plugin team.
* @license MIT https://opensource.org/licenses/mit-license.php
* @link https://github.com/pluginsGLPI/advancedforms
* -------------------------------------------------------------------------
*/

/**
* Loaded right after the reservation question markup (templates/reservation_question.html.twig).
* Waits for DOM ready on full pages, like the former inline module did.
*/
(function () {
const ready_attr = 'data-reservation-question-widget-ready';

const init = () => {
const els = [...document.querySelectorAll('[data-reservation-question-widget]:not([' + ready_attr + '])')];
if (els.length === 0) {
return;
}
els.forEach((el) => el.setAttribute(ready_attr, ''));

import('/plugins/advancedforms/js/modules/ReservationQuestionWidget.js').then(({ ReservationQuestionWidget }) => {
els.forEach((el) => new ReservationQuestionWidget(el));
});
};

if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init, { once: true });
} else {
init();
}
})();
56 changes: 56 additions & 0 deletions public/js/reservation_request_timeline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* -------------------------------------------------------------------------
* advancedforms plugin for GLPI
* -------------------------------------------------------------------------
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2025 by the advancedforms plugin team.
* @license MIT https://opensource.org/licenses/mit-license.php
* @link https://github.com/pluginsGLPI/advancedforms
* -------------------------------------------------------------------------
*/

/**
* Loaded after each reservation request timeline card, on full pages and on AJAX-reloaded timelines.
* Idempotent: each card is initialised once.
*/
(function () {
const ready_attr = 'data-af-reservation-request-timeline-ready';

const init = () => {
const els = [...document.querySelectorAll('[data-af-reservation-request-timeline]:not([' + ready_attr + '])')];
if (els.length === 0) {
return;
}
els.forEach((el) => el.setAttribute(ready_attr, ''));

import('/plugins/advancedforms/js/modules/ReservationRequestTimelineActions.js').then(({ ReservationRequestTimelineActions }) => {
els.forEach((el) => new ReservationRequestTimelineActions(el));
});
};

if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init, { once: true });
} else {
init();
}
})();
72 changes: 72 additions & 0 deletions public/js/table_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* -------------------------------------------------------------------------
* advancedforms plugin for GLPI
* -------------------------------------------------------------------------
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2025 by the advancedforms plugin team.
* @license MIT https://opensource.org/licenses/mit-license.php
* @link https://github.com/pluginsGLPI/advancedforms
* -------------------------------------------------------------------------
*/

/**
* Loaded right after the table question config markup (templates/editor/question_types/table_config.html.twig).
* Idempotent: each markup block is initialised once, even when rendered again.
*/
(function () {
const ready_attr = 'data-af-table-config-ready';
const els = [...document.querySelectorAll('[data-af-table-config]:not([' + ready_attr + '])')];
if (els.length === 0) {
return;
}
els.forEach((el) => el.setAttribute(ready_attr, ''));

window.select2_configs = window.select2_configs || {};
els.forEach((el) => {
const icons = JSON.parse(el.dataset.afTableConfigIcons);
window.afTableColumnTypeTemplate = window.afTableColumnTypeTemplate || function (item) {
if (!item.id || !icons[item.id]) {
return item.text;
}
return $('<span>', { 'class': 'd-flex align-items-center gap-1' })
.append($('<i>', { 'class': icons[item.id] }))
.append(document.createTextNode(' ' + item.text));
};

const field_id = 'af-table-type-template-' + el.dataset.afTableConfig;
window.select2_configs[field_id] = {
type: 'adapt',
field_id: field_id,
width: '200px',
dropdown_css_class: '',
placeholder: '',
ajax_limit_count: Number(el.dataset.afTableConfigAjaxLimit),
templateresult: window.afTableColumnTypeTemplate,
templateselection: window.afTableColumnTypeTemplate,
};
});

import('/plugins/advancedforms/js/modules/AfTableQuestionConfig.js').then(({ AfTableQuestionConfig }) => {
new AfTableQuestionConfig();
});
})();
56 changes: 56 additions & 0 deletions public/js/table_end_user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* -------------------------------------------------------------------------
* advancedforms plugin for GLPI
* -------------------------------------------------------------------------
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2025 by the advancedforms plugin team.
* @license MIT https://opensource.org/licenses/mit-license.php
* @link https://github.com/pluginsGLPI/advancedforms
* -------------------------------------------------------------------------
*/

/**
* Loaded right after the end user table question markup (templates/table_end_user.html.twig).
* Waits for DOM ready on full pages, like the former inline module did.
*/
(function () {
const ready_attr = 'data-af-table-question-ready';

const init = () => {
const els = [...document.querySelectorAll('[data-af-table-question]:not([' + ready_attr + '])')];
if (els.length === 0) {
return;
}
els.forEach((el) => el.setAttribute(ready_attr, ''));

import('/plugins/advancedforms/js/modules/AfTableQuestion.js').then(({ AfTableQuestion }) => {
els.forEach((el) => new AfTableQuestion(el));
});
};

if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init, { once: true });
} else {
init();
}
})();
64 changes: 64 additions & 0 deletions public/js/tree_cascade_dropdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* -------------------------------------------------------------------------
* advancedforms plugin for GLPI
* -------------------------------------------------------------------------
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2025 by the advancedforms plugin team.
* @license MIT https://opensource.org/licenses/mit-license.php
* @link https://github.com/pluginsGLPI/advancedforms
* -------------------------------------------------------------------------
*/

/**
* Loaded after the tree cascade dropdown markup (templates/tree_cascade_dropdown.html.twig).
* Each select carries its own config in data attributes.
* Waits for DOM ready on full pages, like the former inline modules did.
*/
(function () {
const ready_attr = 'data-af-tree-cascade-ready';

const init = () => {
const els = [...document.querySelectorAll('select[data-af-tree-cascade]:not([' + ready_attr + '])')];
if (els.length === 0) {
return;
}
els.forEach((el) => el.setAttribute(ready_attr, ''));

import('/plugins/advancedforms/js/modules/AfTreeCascadeDropdown.js').then(({ AfTreeCascadeDropdown }) => {
els.forEach((el) => new AfTreeCascadeDropdown({
selector_id: el.id,
questions_id: Number(el.dataset.afTreeQuestionsId),
ajax_limit_count: Number(el.dataset.afTreeAjaxLimit),
level: Number(el.dataset.afTreeLevel || 1),
next_container_id: el.dataset.afTreeNextContainer,
auto_load_parent_id: Number(el.dataset.afTreeAutoLoadParent || 0),
}));
});
};

if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init, { once: true });
} else {
init();
}
})();
Loading