https://www.institutlustiger.fr/modules/webportal/templates/include/question.js?timestamp=1741346176
1/** 2 * Fonction à lancer à l'ouverture d'un dialog coté prod 3 */ 4function InitialiseQuestion() 5{ 6 InitialiseQuestionSelect2($("form.sddlg")); 7} 8function InitialiseQuestionSelect2(jForm) 9{ 10 if( !$.fn.select2 ) return; 11 12 // Les SELECT2 génériques 13 jForm.find("INPUT.select2").each(BindSelect2); 14} 15/** 16 * Fonction à lancer pour initialiser un select2 générique 17 * data-xselect2 est un attribut HTML5 data* contenant un object javascript 18 * Cet object comporte : 19 * - soit une clé "data" qui contient l'ensemble des valeurs à proposer au select2 20 * - soit les clés "init" et "load". Dans ce cas la clé "init" contient les valeurs à initialiser 21 * la clé "load" la fonction à appeler pour charger les valeurs sur PHP 22 */ 23function BindSelect2() 24{ 25 var jThis = $(this); 26 var xSelect2 = jThis.data("xselect2"); 27 28 var xMap = {}; 29 $.each(xSelect2.data || xSelect2.init, function(i,xKv) { 30 xMap[xKv.id] = xKv.text; 31 }); 32 xSelect2.separator = "\xA6"; 33 xSelect2.initSelection = function( eltHidden, fnCallback ) { 34 var xInitSelection = [] 35 if(xSelect2.multiple){ 36 $(eltHidden.val().split(xSelect2.separator)).each(function () { 37 xInitSelection.push({"id":this, "text":(xMap[this] || this+"?")}); 38 }); 39 } 40 else{ 41 xInitSelection = {"id":eltHidden.val(), "text":(xMap[eltHidden.val()] || eltHidden.val()+"?")}; 42 } 43 if( !bSortable ) { 44 xInitSelection.sort(function(a,b) { 45 if(a.text.toLowerCase() > b.text.toLowerCase()) return 1; 46 if(a.text.toLowerCase() < b.text.toLowerCase()) return -1; 47 return 0; 48 }); 49 } 50 fnCallback( xInitSelection ); 51 }; 52 xSelect2.formatResult = function(item,container) { 53 // Les lignes qui contiennent une image sont mis en gras 54 if( item.bHtml ) return $("<span/>").append($("<img/>").attr("src",item.img)).append(item.text); 55 return item.text; 56 } 57 58 if( typeof(xSelect2.data)=="undefined" ) { 59 var hSelect2 = new Select2Handle(xSelect2.op,xSelect2.prop); 60 xSelect2["query"] = function(query) { hSelect2.Query(query); }; 61 if( hSelect2.bNife ) xSelect2["minimumInputLength"] = 1; 62 } 63 var bSortable = Boolean(xSelect2.sortable); 64 jThis.select2(xSelect2); 65 66 if( bSortable ) jThis.select2("container").find("ul.select2-choices").sortable({ 67 containment: "parent", 68 start: function() { jThis.select2("onSortStart"); }, 69 update: function() { jThis.select2("onSortEnd"); } 70 }); 71} 72 73function Select2Handle(sOp,xProperties) 74{ 75 if( typeof(sOp)!="string" || sOp.length==0 ) throw new Error("arg sOp required"); 76 this.sOp = sOp; 77 this.iPageSize = typeof(xProperties.iPageSize)=="number" ?xProperties.iPageSize :100; 78 this.iDelay = typeof(xProperties.iDelay )=="number" ?xProperties.iDelay :300; 79 this.bNife = typeof(xProperties.bNife )=="boolean" ?xProperties.bNife :false; 80 this.sDecoPage = typeof(xProperties.sDecoPage)=="string" ?xProperties.sDecoPage :""; 81 this.sDecoLast = typeof(xProperties.sDecoLast)=="string" ?xProperties.sDecoLast :""; 82 this.sDecoSize = typeof(xProperties.sDecoSize)=="string" ?xProperties.sDecoSize :""; 83 this.sDecoImag = typeof(xProperties.sDecoImag)=="string" ?xProperties.sDecoImag :""; 84 this.sUrl = typeof(xProperties.sUrl)=="string" ?xProperties.sUrl :backend(); 85 this.hTimeout = false; 86} 87Select2Handle.prototype.Query = function(query) 88{ 89 if( query.page>1 ) { 90 this.Ajax(query); 91 } 92 else if( query.term=="" ) { 93 if( this.bNife ) this.Results(query,[]); 94 else if( query.page==1 && this.xPage1 ) this.Results(query,this.xPage1); 95 else this.Ajax(query); 96 } 97 else { 98 var iDelay = (query.page>1) ?0 :this.iDelay; 99 if( this.hTimeout ) window.clearTimeout(this.hTimeout); 100 var ceci = this; 101 this.hTimeout = window.setTimeout(function() { ceci.Ajax(query); }, this.iDelay ); 102 } 103} 104Select2Handle.prototype.Ajax = function(query) 105{ 106 $.ajax({ 107 "url" : this.sUrl, 108 "data" : { 109 "op" : this.sOp, 110 "term" : query.term, 111 "limit" : this.iPageSize, 112 "offset" : (query.page-1)*this.iPageSize 113 }, 114 "context": this, 115 "type" : "POST", 116 "success": function(xRecords,sTextStatus,jqXHR) 117 { 118 if( typeof(xRecords)=="string" ) { 119 query.callback({"results":[],"more":false}); 120 alert(xRecords);
121 } 122 else { 123 this.Results(query,xRecords); 124 if( query.term=="" && !this.bNife && query.page==1 ) this.xPage1 = xRecords; 125 } 126 }, 127 "error" :function(jqXHR, sTextStatus, errorThrown) 128 { 129 // La liste est inaccessible, on ne fait rien 130 alert("Select2Handle.prototype.Ajax: error"); 131 } 132 }); 133} 134Select2Handle.prototype.Results = function(query,xRecords) 135{ 136 var xResults = []; 137 var bMore = xRecords.length==this.iPageSize; 138 if( !bMore && xRecords.length>0 && (xChildren=xRecords[xRecords.length-1].children) && xChildren.length==this.iPageSize ) bMore = true; 139 var sPage = " (page "+query.page+")"; 140 141 // Cet appel complète un appel précédent, on ajoute uniquement les utilisateurs 142 if( query.page>1 ) { 143 if( xRecords.length>0 ) { 144 if( this.sDecoPage ) { 145 var sText = this.sDecoPage.replace("{page}",query.page); 146 var xDeco = {"bHtml": true, "text": sText, "children":[] }; 147 if( this.sDecoImag ) xDeco["img"] = this.sDecoImag; 148 xResults.push(xDeco); 149 } 150 xResults = xResults.concat(xRecords); 151 } 152 if( !bMore && this.sDecoLast ) { 153 var sText = this.sDecoLast; 154 var xDeco = {"bHtml": true, "text": sText, "children":[] }; 155 if( this.sDecoImag ) xDeco["img"] = this.sDecoImag; 156 xResults.push(xDeco); 157 } 158 } 159 else { 160 if( xRecords.length>0 ) { 161 if( bMore && this.sDecoPage ) { 162 var sText = this.sDecoPage.replace("{page}",query.page); 163 var xDeco = {"bHtml": true, "text": sText, "children":[] }; 164 if( this.sDecoImag ) xDeco["img"] = this.sDecoImag; 165 xResults.push(xDeco); 166 } 167 else if( !bMore && this.sDecoSize ) { 168 var sText = pluriel(xRecords.length,this.sDecoSize); 169 var xDeco = {"bHtml": true, "text": sText, "children":[] }; 170 if( this.sDecoImag ) xDeco["img"] = this.sDecoImag; 171 xResults.push(xDeco); 172 } 173 xResults = xResults.concat(xRecords); 174 } 175 } 176 query.callback({ 177 "results" : xResults, 178 "more" : bMore 179 }); 180} 181function Select2Ajax() 182{ 183 this.hTimeout = false; 184 this.iPageSize = 100; 185 this.iDelay = 300; 186 this.bNife = false; 187 this.sIconPath = "../images/admin/question/"; 188} 189function BindUsr() 190{ 191 var jThis = $(this); 192 var xSelect2 = { 193 "multiple" :true, 194 "initSelection" : function( eltHidden, fnCallback ) { 195 fnCallback( $(eltHidden).data("init-selection") ); 196 $(eltHidden).data("init-selection",undefined).removeAttr("data-init-selection"); 197 } 198 }; 199 var xUsers = jThis.closest("form").data("users"); 200 if( typeof(xUsers)=="undefined" ) { 201 xSelect2["query"] = BindUsr_query; 202 xSelect2["minimumInputLength"] = 1; 203 } 204 else { 205 xSelect2["data"] = xUsers; 206 } 207 xSelect2.formatResult = xSelect2.formatSelection = function(object, container){ 208 return object.text; 209 } 210 jThis.select2(xSelect2); 211} 212var xBindUsr = new Select2Ajax(); 213function BindUsr_query(query) 214{ 215 if( query.page>1 ) { 216 BindUsr_ajax(query); 217 } 218 else if( query.term=="" ) { 219 if( xBindUsr.bNife ) this.BindUsr_results(query,[]); 220 else if( query.page==1 && xBindUsr.xPage1 ) this.BindUsr_results(query,xBindUsr.xPage1); 221 else BindUsr_ajax(query); 222 } 223 else { 224 var iDelay = (query.page>1) ?0 :xBindUsr.iDelay; 225 if( xBindUsr.hTimeout ) window.clearTimeout(xBindUsr.hTimeout); 226 xBindUsr.hTimeout = window.setTimeout(function() { BindUsr_ajax(query); }, iDelay ); 227 } 228} 229function BindUsr_ajax(query) 230{ 231 $.ajax({ 232 "url" : gXoopsUrl+'/modules/webportal/abonnement_backend.php', 233 "data" : { 234 "op" : "users_by_name", 235 "term" : query.term, 236 "limit" : xBindUsr.iPageSize, 237 "offset" : (query.page-1)*xBindUsr.iPageSize, 238 "needUid" : 'on' 239 }, 240 "type" : "POST", 241 "success": function(xUsers,sTextStatus,jqXHR) 242 { 243 BindUsr_results(query,xUsers); 244 if( query.term=="" && !xbBindUsr.bNife && query.page==1 ) xBindUsr.xPage1 = xUsers; 245 }, 246 "error" :function(jqXHR, sTextStatus, errorThrown) 247 { 248 // La liste des users est inaccessible, on ne fait rien 249 alert("question.BindUsr_ajax: error"); 250 } 251 }); 252} 253function BindUsr_results(query,xUsers) 254{ 255 var xResults = []; 256 var bMore = xUsers.length==xBindUsr.iPageSize; 257 var sPage = " <small>(page "+query.page+")</small>"; 258 259 // Cet appel complète un appel précédent, on ajoute uniquement les utilisateurs 260 if( query.page>1 ) { 261 if( xUsers.length>0 ) { 262 xResults.push({"text":"Utilisateurs"+sPage,"children":[], "img":"user.png"}) 263 xResults = xResults.concat(xUsers); 264 } 265 if( !bMore ) xResults.push({"text":"Utilisateurs <small>(fin)</small>","children":[], "img":"user.png"}); 266 } 267 else { 268 if( xUsers.length>0 ) { 269 xResults.push({"text":"Utilisateurs"+(bMore ?sPage :pluriel(xUsers.length," <small>({n} r\xe9ponse{s})</small>")),"children":[], "img":"user.png"}); 270 xResults = xResults.concat(xUsers); 271 } 272 } 273 query.callback({ 274 "results" : xResults, 275 "more" : bMore 276 }); 277}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.