- 1 :
/**
- 2 :
* Action à faire lorsque l'on a tapé un texte dans la recherche.
- 3 :
* @param {*} e Input recherche
- 4 :
*/
- 5 :
function mm_s_Action(e)
- 6 :
{
- 7 :
const replaced = rcmail.env.REPLACED_SEARCH;
- 8 :
let val = e.value;
- 9 :
let config = rcmail.env.mm_search_config;
- 10 :
$(".search-container").html("");
- 11 :
- 12 :
if (val === "")
- 13 :
{
- 14 :
$("#barup-search").addClass("hidden");
- 15 :
$("#barup-search-background").addClass("hidden");
- 16 :
$("body").unbind("click");
- 17 :
return;
- 18 :
}
- 19 :
- 20 :
let search_icon = $("#barup-search-col .icofont-search").removeClass("icofont-search").html('<span class="spinner-grow spinner-grow-sm" role="status"><span class="sr-only">Chargement des informations...</span></span>');
- 21 :
- 22 :
- 23 :
rcmail.env.mel_metapage_search = {
- 24 :
size:config.length,
- 25 :
finished:[],
- 26 :
timeout: function () {
- 27 :
- 28 :
if (rcmail.env.mel_metapage_search.size === rcmail.env.mel_metapage_search.finished.length)
- 29 :
{
- 30 :
rcmail.env.mel_metapage_search = null;
- 31 :
delete rcmail.env.mel_metapage_search
- 32 :
- 33 :
rcmail.clear_messages();
- 34 :
- 35 :
if (search_icon.children().hasClass("text-success"))
- 36 :
{
- 37 :
rcmail.display_message("Recherche effectué avec succès !", "confirmation");
- 38 :
- 39 :
if ($("#barup-search").hasClass("hidden"))
- 40 :
{
- 41 :
$("#barup-search").removeClass("hidden");
- 42 :
$("#barup-search-background").removeClass("hidden");
- 43 :
}
- 44 :
}
- 45 :
else
- 46 :
rcmail.display_message("Aucun résultat lié à la recherche...");
- 47 :
- 48 :
search_icon.addClass("icofont-search").html("");
- 49 :
- 50 :
- 51 :
- 52 :
}
- 53 :
else
- 54 :
setTimeout(() => {
- 55 :
rcmail.env.mel_metapage_search.timeout();
- 56 :
}, 100);
- 57 :
}
- 58 :
};
- 59 :
- 60 :
setTimeout(rcmail.env.mel_metapage_search.timeout, 100);
- 61 :
//rcmail.display_message("Recherche en cours....", "loading")
- 62 :
- 63 :
rcmail.display_message(`Recherche de contenus lié au mot clé "${val}"`, "loading");
- 64 :
- 65 :
for (let index = 0; index < config.length; ++index) {
- 66 :
const element = config[index];
- 67 :
// mm_s_array.push({index:index,ajax:
- 68 :
$.ajax({ // fonction permettant de faire de l'ajax
- 69 :
type: "GET", // methode de transmission des données au fichier php
- 70 :
url: element.replace(replaced, val), // url du fichier php
- 71 :
dataType: 'json',
- 72 :
success: async function (data) {
- 73 :
try {
- 74 :
rcmail.env.mel_metapage_search.finished.push(null);
- 75 :
- 76 :
if (Array.isArray(data) && data.length > 0 && data[0].calendar !== undefined)
- 77 :
{
- 78 :
data = await SearchResultCalendar.from_array(data);
- 79 :
}
- 80 :
- 81 :
- 82 :
if (data.datas !== undefined && data.datas.length > 0)
- 83 :
{
- 84 :
mm_s_AfficheResults(data, val);
- 85 :
search_icon.children().addClass("text-success");
- 86 :
}
- 87 :
- 88 :
} catch (error) {
- 89 :
- 90 :
}
- 91 :
},
- 92 :
error: function (xhr, ajaxOptions, thrownError) { // Add these parameters to display the required response
- 93 :
- 94 :
},
- 95 :
});//});
- 96 :
- 97 :
}
- 98 :
- 99 :
if (!Enumerable.from(jQuery._data($("body")[0], 'events')["click"]).where(x => x.handler + "" === mm_s_bodyClick + "").any())//jQuery._data($("body")[0], 'events')["click"] === undefined)
- 100 :
$("body").click(mm_s_bodyClick);
- 101 :
}
- 102 :
- 103 :
/**
- 104 :
* Affiche ou non les résultats de recherche si il y en a.
- 105 :
* @param {*} event
- 106 :
*/
- 107 :
function mm_s_bodyClick(event)
- 108 :
{
- 109 :
let querry = $("#barup-search");
- 110 :
- 111 :
if (querry.hasClass("hidden"))
- 112 :
return;
- 113 :
- 114 :
let target = event.target;
- 115 :
- 116 :
while (target.id !== "layout") {
- 117 :
//console.log("target",target.id, target,target.id === "barup-search",target.id === "barup" );
- 118 :
if (target.id === "barup-search" || target.id === "barup-search-input")
- 119 :
return;
- 120 :
else
- 121 :
target = target.parentElement;
- 122 :
}
- 123 :
if (!querry.hasClass("hidden"))
- 124 :
{
- 125 :
querry.addClass("hidden");
- 126 :
$("#barup-search-background").addClass("hidden");
- 127 :
}
- 128 :
- 129 :
- 130 :
- 131 :
}
- 132 :
- 133 :
/**
- 134 :
* Cache la recherche en cours.
- 135 :
*/
- 136 :
function mm_s_OnClick()
- 137 :
{
- 138 :
//console.log($(".search-container").html() !== "");
- 139 :
if ($(".search-container").html() !== "")
- 140 :
{
- 141 :
let querry = $("#barup-search");
- 142 :
if (querry.hasClass("hidden"))
- 143 :
{
- 144 :
querry.removeClass("hidden");
- 145 :
$("#barup-search-background").removeClass("hidden");
- 146 :
}
- 147 :
}
- 148 :
}
- 149 :
- 150 :
/**
- 151 :
* Affiche les résultats de la recherche.
- 152 :
* @param {*} datas Résultats de la recherche.
- 153 :
*/
- 154 :
function mm_s_AfficheResults(datas, searchVal)
- 155 :
{
- 156 :
const max = 5
- 157 :
- 158 :
let querry = $("#barup-search");
- 159 :
- 160 :
html = '<div class=search-parent><div class=search-label onclick="mm_s_extend(this)"><span class="icofont-rounded-down"></span><span class=result-label>' + datas.label + '</span></div><div>';
- 161 :
html += '<table class="table table-striped">'
- 162 :
let isa;
- 163 :
- 164 :
for (let index = 0; index < datas.datas.length; index++) {
- 165 :
- 166 :
if (index >= max)
- 167 :
break;
- 168 :
- 169 :
const element = datas.datas[index];
- 170 :
- 171 :
isa = element.link === "" ? "span" : "a";
- 172 :
html += '<tr><td><' + isa + ' href="'+ element.link + '"' + (element.onclick !== undefined ? (' onclick="' + element.onclick + '" ') : "") +' class="result-link"><div class="result-header">' + element.header + '</div><div class="result-desc">' + element.sub_header + '</div></' + isa + '></td></tr>'
- 173 :
}
- 174 :
- 175 :
let action = "";
- 176 :
- 177 :
switch (datas.label) {
- 178 :
case rcmail.gettext("mails", "mel_metapage"):
- 179 :
action = `mm_st_OpenOrCreateFrame('mail', true, {}, [{action:'search', args:['${searchVal}']}])`;
- 180 :
break;
- 181 :
case rcmail.gettext('agenda', 'mel_portal'):
- 182 :
action = `mm_st_OpenOrCreateFrame('calendar', true, {}, [{action:'search', args:['${searchVal}']}])`;
- 183 :
break;
- 184 :
case rcmail.gettext('contacts', "mel_metapage"):
- 185 :
action = `mm_st_OpenOrCreateFrame('contacts', true, {}, [{action:'search', args:['${searchVal}']}])`;
- 186 :
break;
- 187 :
default:
- 188 :
break;
- 189 :
}
- 190 :
- 191 :
if (action !== "")
- 192 :
{
- 193 :
html += "<tr>";
- 194 :
html += "<td>";
- 195 :
html += `<a href=# onclick="mm_s_HideSearch();${action};"><span class="icon-mel-plus"></span> Voir plus </a>`;
- 196 :
html += "</td></tr>";
- 197 :
}
- 198 :
- 199 :
html += "</table></div></div>";
- 200 :
$(".search-container").append(html);
- 201 :
}
- 202 :
- 203 :
/**
- 204 :
* Affiche ou cache une catégorie.
- 205 :
* @param {*} e Catégorie à afficher ou fermer.
- 206 :
*/
- 207 :
function mm_s_extend(e)
- 208 :
{
- 209 :
window.temp1 = e;
- 210 :
if (e.children[0].classList.contains("icofont-rounded-down"))
- 211 :
{
- 212 :
e.children[0].classList.remove("icofont-rounded-down");
- 213 :
e.children[0].classList.add("icofont-rounded-right");
- 214 :
e.parentElement.children[1].classList.add("hidden")
- 215 :
}
- 216 :
else {
- 217 :
e.children[0].classList.add("icofont-rounded-down");
- 218 :
e.children[0].classList.remove("icofont-rounded-right");
- 219 :
e.parentElement.children[1].classList.remove("hidden")
- 220 :
}
- 221 :
}
- 222 :
- 223 :
function mm_s_Calendar(cal)
- 224 :
{
- 225 :
try {
- 226 :
cal = SearchResult.parse(cal);
- 227 :
} catch (error) {
- 228 :
cal = JSON.parse(cal.replace(/£¤£/g, '"'));
- 229 :
}
- 230 :
- 231 :
rcmail.local_storage_set_item("calendar_redirect", cal);
- 232 :
window.location.href = rcmail.get_task_url("calendar&source=" + cal.calendar + "&date="+(new Date(cal.start)).getTime()/1000.0);
- 233 :
}
- 234 :
- 235 :
function mm_s_HideSearch()
- 236 :
{
- 237 :
$("#barup-search").addClass("hidden");
- 238 :
$("#barup-search-background").addClass("hidden");
- 239 :
}
- 240 :
- 241 :
/**
- 242 :
* Ouvre ou créer une frame.
- 243 :
* @param {string} action Frame à ouvrir.
- 244 :
* @param {string} url Url de la frame.
- 245 :
*/
- 246 :
function mm_s_CreateOrUpdateFrame(action, args)
- 247 :
{
- 248 :
event.preventDefault();
- 249 :
$("#barup-search").addClass("hidden");
- 250 :
$("#barup-search-background").addClass("hidden");
- 251 :
- 252 :
switch (action) {
- 253 :
case "mail":
- 254 :
if ($(".mail-frame").length > 0)
- 255 :
$(".mail-frame").remove();
- 256 :
break;
- 257 :
case "contacts":
- 258 :
if ($(".addressbook-frame").length > 0)
- 259 :
$(".addressbook-frame").remove();
- 260 :
break;
- 261 :
default:
- 262 :
break;
- 263 :
}
- 264 :
- 265 :
- 266 :
//console.log("url", url, action);
- 267 :
mm_st_OpenOrCreateFrame(action, true, args);
- 268 :
- 269 :
// rcmail.set_busy(true, "loading");
- 270 :
// let querry = $("." + action + "-frame");
- 271 :
// let changePage;
- 272 :
// if (querry.length > 0)
- 273 :
// {
- 274 :
// querry[0].src = url;
- 275 :
// if (!rcmail.busy)
- 276 :
// rcmail.set_busy(true, "loading");
- 277 :
// rcmail.env.frame_created = false;
- 278 :
// mm_st_CreateOrOpenModal(action, true);
- 279 :
// new Promise(async (a, b) => {
- 280 :
// while (rcmail.env.frame_created === false) {
- 281 :
// await delay(1000);
- 282 :
// if (!rcmail.busy)
- 283 :
// rcmail.set_busy(true, "loading");
- 284 :
// }
- 285 :
// rcmail.set_busy(false);
- 286 :
// rcmail.clear_messages();}
- 287 :
// );
- 288 :
// }
- 289 :
// else {
- 290 :
// rcmail.set_busy(false);
- 291 :
// return
- 292 :
// let id = mm_st_CreateOrOpenModal(action, false);
- 293 :
// if (!rcmail.busy)
- 294 :
// rcmail.set_busy(true, "loading");
- 295 :
// console.log("id", id, action);
- 296 :
// querry = $("#" + id);
- 297 :
// new Promise(async (a, b) => {
- 298 :
// while (rcmail.env.frame_created === false) {
- 299 :
// await delay(100);
- 300 :
// if (!rcmail.busy)
- 301 :
// rcmail.set_busy(true, "loading");
- 302 :
// }
- 303 :
// rcmail.env.frame_created = false;
- 304 :
// if (!rcmail.busy)
- 305 :
// rcmail.set_busy(true, "loading");
- 306 :
// querry[0].src = url;
- 307 :
// while (rcmail.env.frame_created === false) {
- 308 :
// await delay(1000);
- 309 :
// }
- 310 :
// mm_st_CreateOrOpenModal(action);
- 311 :
// rcmail.set_busy(false);
- 312 :
// rcmail.clear_messages();
- 313 :
// });
- 314 :
//}
- 315 :
}
- 316 :
- 317 :
/*
- 318 :
rcmail.display_message("test", "error") / rcmail.display_message("test", "confirmation") / loading
- 319 :
- 320 :
- 321 :
- 322 :
- 323 :
- 324 :
- 325 :
*/