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