[ Index ] |
PHP Cross Reference of Project Glazy import |
[Summary view] [Print] [Text view]
1 2 function convert(){ 3 // get all the selected recettes in the box 4 const recettes = document.getElementById('reclist'); 5 var selected = []; 6 for (var option of recettes.options) 7 { 8 if (option.selected) { 9 selected.push(option.value); 10 } 11 } 12 // now call the recettes.php and display it in the right box. 13 url = "./convert.php?fname="+document.getElementById('fname').value; 14 15 url += "&filtre="+document.getElementById('filtre').value; 16 17 for (let i in selected) { 18 url+="&recettes[]="+selected[i]; 19 } 20 21 var exports = document.getElementById('exports'); 22 23 fetch(url) 24 .then(response => response.text()) 25 .then(html => { 26 exports.innerHTML = html; 27 }) 28 .catch(error => { 29 console.log(error); 30 }); 31 32 document.getElementById('cadre').style.display = "none"; 33 document.getElementById('exports').style.display = "block"; 34 //alert('converting '+url); 35 36 } 37 38 39 40 function displayswap(what) { 41 /* 42 swap display of cadre et exports boxes 43 */ 44 45 if (what == 'swap') { 46 if (document.getElementById('exports').style.display == "block") { 47 document.getElementById('exports').style.display = "none"; 48 document.getElementById('cadre').style.display = "block"; 49 } else { 50 document.getElementById('exports').style.display = "block"; 51 document.getElementById('cadre').style.display = "none"; 52 }; 53 } else if (what =='recettes') { 54 document.getElementById('exports').style.display = "none"; 55 document.getElementById('cadre').style.display = "block"; 56 } else { 57 document.getElementById('exports').style.display = "block"; 58 document.getElementById('cadre').style.display = "none"; 59 } 60 } 61 62 function home(){window.location.assign("index.php");} 63 64 function load_recettes() { 65 fname = document.getElementById("fichier").value; 66 url = "recettes.php?fname="+fname; 67 sessionStorage.setItem('filename',fname); 68 const box = document.getElementById('cadre'); 69 70 fetch(url) 71 .then(response => response.text()) 72 .then(html => { 73 box.innerHTML = html; 74 }) 75 .catch(error => { 76 console.log(error); 77 }); 78 } 79 80 function filtre() { 81 const reclist = document.getElementById('reclist'); 82 const textes = [...reclist] 83 .map(el => el.text); 84 const valeurs = [...reclist] 85 .map(el => el.value); 86 87 const keys = valeurs.keys(); 88 //console.log(valeurs); 89 let text = ""; 90 for (let x of keys) { 91 text += x + "\n"; 92 } 93 //console.log(text); 94 95 //console.log(textes) 96 //alert('filtration'); 97 } 98 99 function filtrage() { 100 var keyword = document.getElementById("filtre").value; 101 //console.log(keyword); 102 var select = document.getElementById("reclist"); 103 for (var i = 0; i < select.length; i++) { 104 var txt = select.options[i].text; 105 if (!txt.match(keyword)) { 106 select.options[i].setAttribute('disabled', 'disabled'); 107 select.options[i].style.display = 'none'; 108 } else { 109 //console.log(txt); 110 select.options[i].removeAttribute('disabled'); 111 select.options[i].style.display = 'block'; 112 } 113 114 } 115 } 116 117 118 function checkname(files,fname) { 119 /* 120 checkname: in array of filenames, filename 121 check if filename is in array and if so display a prompt box to change the name until fname is null or not in array 122 */ 123 //console.log('check if '+fname+' is in '+files.toString()); 124 //console.log(files.indexOf(fname)); 125 if (files.indexOf(fname) >= 0) { 126 fname = prompt('le nom de fichier est déjà utilisé, changez le',fname); 127 if ( fname != null) { 128 fname=checkname(files,fname); 129 } else { 130 console.log('prompt canceled'); 131 } 132 } 133 134 //console.log('return fname checkname '+fname) 135 return (fname); 136 } 137 138 function uploadfile() { 139 var xmlhttp = new XMLHttpRequest(); 140 var url = "readdir.php"; 141 const fileInput = document.getElementById('fileToUpload'); 142 143 xmlhttp.onreadystatechange = function() { 144 if (this.readyState == 4 && this.status == 200) { 145 var files = JSON.parse(this.responseText); 146 var newfile = fileInput.files[0].name; 147 // let newfile = prompt('new file name',fname); 148 //console.log(newfile); 149 const fileform = document.getElementById('upload'); 150 if ( (newfile=checkname(files,newfile)) != null) { 151 const output = document.getElementById("id01"); 152 output.innerHTML = newfile; 153 // new file name accepted, we can trigger the upload 154 fileInput.files[0].name = newfile; 155 mysubmit = document.getElementById("mysubmit"); 156 mysubmit.disabled = false; 157 mysubmit.value = 'upload to '+newfile 158 mysubmit.style.background = 'green'; 159 fileform.addEventListener( 160 "submit", 161 (event) => { 162 const output = document.getElementById("id01"); 163 const formData = new FormData(fileform); 164 const file = fileInput.files[0]; 165 formData.delete("fileToUpload"); 166 formData.append("fileToUpload", file, newfile); 167 formData.append("submit","coucou"); 168 169 const request = new XMLHttpRequest(); 170 request.open("POST", "bangit.php", true); 171 request.onload = (progress) => { 172 output.innerHTML = 173 request.status === 200 174 ? "Uploaded!" 175 : `Error $request.status} occurred when trying to upload your file.<br />`; 176 /* mysubmit = document.getElementById("mysubmit"); 177 mysubmit.disabled = true; 178 mysubmit.value = 'Envoyer'; 179 mysubmit.style.background = 'red'; */ 180 location.reload(); 181 }; 182 183 request.send(formData); 184 event.preventDefault(); 185 }, 186 false, 187 ); 188 } else { 189 // operation cancelled 190 console.log('cancelled'); 191 } 192 } 193 }; 194 195 xmlhttp.open("GET", url, true); 196 xmlhttp.send(); 197 198 } 199 200 201 202 async function copyPage(text) { 203 if (window.isSecureContext) { 204 // Page is a secure context so service workers are now available 205 alert('navigator in secure contect') 206 navigator.serviceWorker.register("/offline-worker.js").then(() => { 207 // … 208 }); 209 } 210 try { 211 await navigator.clipboard.writeText(location.href); 212 //console.log('Page URL copied to clipboard'); 213 } catch (err) { 214 console.error('Failed to copy: ', err); 215 } 216 } 217 function copy2clipboard() { 218 // Get the text field 219 var copyText = document.getElementById("glazchem"); 220 221 // Select the text field 222 copyText.select(); 223 copyText.setSelectionRange(0, 99999); // For mobile devices 224 225 // Copy the text inside the text field 226 navigator.clipboard.writeText(copyText.value).then(function(x) { 227 alert("Texte copié dans le presse papier: " + copyText.value); 228 }); 229 //copyPage(copyText.value); 230 // Alert the copied text 231 } 232 233 234 function rename() { 235 var fname = document.getElementById("fichier").value; 236 fname = prompt('Renommez le fichier',fname); 237 fetch('readdir.php') 238 .then ( x => x.json() ) 239 .then ( y => checkname(y,fname) ) 240 .then ( z => { if ( z!= null) { 241 console.log('here mv to new name '+z); 242 fetch ('rename.php?old='+document.getElementById("fichier").value+'&new='+z) 243 .then ( x => x.text()) 244 .then ( y => { console.log(y); location.reload();}) 245 } 246 }) 247 } 248 249 function remove() { 250 var fname = document.getElementById("fichier").value; 251 if (confirm('Effacer le fichier '+fname+ ' ATTENTION pas récupérable !')) { 252 253 fetch('delete.php?fname='+document.getElementById("fichier").value) 254 .then ( x => x.text() ) 255 .then ( y => { console.log(y); location.reload();} ) 256 257 } 258 } 259
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Sep 14 11:31:49 2023 | Cross-referenced by PHPXref 0.7.1 |