Sindbad~EG File Manager
/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2022 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/
var GLPI=GLPI||{};GLPI.RichText=GLPI.RichText||{};GLPI.RichText.ContentTemplatesParameters=class{constructor(e,t){this.editor=e;this.values=this.parseParameters(t)}register(){const e=this;this.editor.ui.registry.addAutocompleter("content_templates",{ch:"{",minChars:0,fetch:function(t){return e.fetchItems(t)},onAction:function(t,r,n){e.insertTwigContent(t,r,n)}})}fetchItems(e){const t=this;return new Promise((function(r){const n=t.values.filter((function(r){e=e.trim();if(e.length===0){return true}const n=e.charAt(0);if(["{","%"].includes(n)&&n!==r.opening.charAt(1)){return false}var s=0;var i=null;tinymce.dom.TextSeeker(t.editor.dom,(()=>false)).backwards(t.editor.selection.getNode(),0,(function(e,t,r){if(/\{%\s*endfor\s*%\}/.test(r)){s++}var n=r.match(/\{%\s*for\s+\w+\s+in\s+([\w.]+)\s*%\}/);if(n!==null){if(s==0){i=n[1];return t}s--}return-1}));if(i!==null&&r.parent_key!==i){return false}else if(i===null&&r.parent_key!==undefined){return false}const a=e.replace(/^(\{|%)\s*/,"").toLowerCase();let o=r.key.toLowerCase().includes(a)||r.text.toLowerCase().includes(a);if(!o){return false}return true}));r(n)}))}parseParameters(e,t="",r=""){const n=[];const s=this;e.forEach((e=>{if(t.length>0){e.key=t+"."+e.key}if(r.length>0){e.label=r+" > "+e.label}switch(e.type){case"AttributeParameter":{let t="{{ "+e.key;if(e.filter&&e.filter.length){t+=" | "+e.filter}t+=" }}";n.push({type:"autocompleteitem",opening:"{{",key:e.key,value:t,text:t+" - "+e.label});break}case"ObjectParameter":{n.push(...s.parseParameters(e.properties,e.key,e.label));break}case"ArrayParameter":{let t="{% for "+e.items_key+" in "+e.key+" %}";n.push({type:"autocompleteitem",opening:"{%",key:e.key,value:t,text:t+" - "+e.label});const r=s.parseParameters([e.content]);n.push(...r.map((function(t){t.opening="{{";t.parent_key=e.key;return t})));break}}}));return n}insertTwigContent(e,t,r){this.editor.selection.setRng(t);if(r.indexOf("{% for ")==0){r=r+"<br><br>{% endfor %}"}this.editor.insertContent(r);e.hide()}};
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists