From ec379f2c93e46b0d32d7036a2a50d29c5a3c435f Mon Sep 17 00:00:00 2001 From: gdetrez Date: Mon, 9 Oct 2006 19:33:29 +0200 Subject: [PATCH] import initial des scripts javascript darcs-hash:20061009173329-f46e9-611debe6ac89ea14f4a855dfceaeec2930ccb1a9.gz --- intranet/static/scripts/crans.js | 193 +++++++++++ intranet/static/scripts/crans_domtab.js | 259 ++++++++++++++ intranet/static/scripts/digicode.js | 161 +++++++++ intranet/static/scripts/impression.js | 334 +++++++++++++++++++ intranet/static/scripts/passwordGenerator.js | 66 ++++ intranet/static/scripts/popup.js | 34 ++ 6 files changed, 1047 insertions(+) create mode 100644 intranet/static/scripts/crans.js create mode 100644 intranet/static/scripts/crans_domtab.js create mode 100644 intranet/static/scripts/digicode.js create mode 100644 intranet/static/scripts/impression.js create mode 100644 intranet/static/scripts/passwordGenerator.js create mode 100644 intranet/static/scripts/popup.js diff --git a/intranet/static/scripts/crans.js b/intranet/static/scripts/crans.js new file mode 100644 index 00000000..c1b45beb --- /dev/null +++ b/intranet/static/scripts/crans.js @@ -0,0 +1,193 @@ +function askForName(oldName) { + var c = ''; + while ( c == '') + c = prompt("Votre nom :",oldName); + if (c == null) + return false; + else + window.location.href= 'changeNomAdherent?nouveauNom=' + c; +} + + +function askForSurname(oldSurname) { + var c = ''; + while ( c == '') + c = prompt("Votre prénom :",oldSurname); + if (c == null) + return false; + else + window.location.href= 'changePrenomAdherent?nouveauPrenom=' + c; +} + +function askForTel(oldTel) { + var c = ''; + while ( c == '') + c = prompt("Votre numéro de téléphone :",oldTel); + if (c == null) + return false; + else + window.location.href= 'changeTelAdherent?nouveauTel=' + c; +} + +function askForMachineMac(oldMac, mid) { + var c = ''; + while ( c == '') + c = prompt("Adresse MAC de la machine :",oldMac); + if (c == null) + return false; + var e = loadJSONDoc('changeMACMachine?nouvelleMAC=' + c + '&mid=' + mid); + e.addCallback(machineModifHandler); + e.addErrback(ajaxErrorHandler); + loading(true); + return false; +} +function askForMachineName(oldName, mid) { + var c = ''; + while ( c == '') + c = prompt("Nom de la machine :",oldName); + if (c == null) + return false; + var e = loadJSONDoc("changeNomMachine?nouveauNom=" + c + "&mid=" + mid); + e.addCallback(machineModifHandler); + e.addErrback(ajaxErrorHandler); + loading(true); + return false; +} + +function askForDeleteMachine(mid, nom) { + if (confirm("Supprimer la machine ?")) { + var e = loadJSONDoc('supprimeMachine?mid=' + mid); + e.addCallback(machineModifHandler); + e.addErrback(ajaxErrorHandler); + loading(true); + return false; + } + return false; +} + +function newAlias() { + var c = ''; + while ( c == '') + c = prompt("Nouvel alias :"); + if (c == null) + return false; + else + window.location.href= 'newAlias?alias=' + c + "#mailTab"; + +} + + + +function newMachineNode(name, shortName, mac, ip, mid, type, ipsec) { + machineName = H3({},shortName); + + var propertiesList = createDOM("DL",{'class':'machineInfos'}); + valuesList = [ + {'label':'Type : ', 'value':type}, + {'label':'Mac : ', 'value':mac}, + {'label':'IP : ', 'value':ip}, + {'label':'ipsec : ', 'value':ipsec}, + ] ; + for (var i=0; i'); +document.write('div.domtab>div{display:none;}<'); +document.write('/s'+'tyle>'); diff --git a/intranet/static/scripts/digicode.js b/intranet/static/scripts/digicode.js new file mode 100644 index 00000000..8565d442 --- /dev/null +++ b/intranet/static/scripts/digicode.js @@ -0,0 +1,161 @@ +/* ************************************************************ + * Digicode + ************************************************************ + * Digicode.init : initialisation de la page + * Digicode.makeCode : creation de codes + * Digicode.codelist : liste des codes + * Digicode.AJAX : ajax + */ +Digicode = {}; + +/***************************** + Digicode.init + *****************************/ +Digicode.init = function() +{ + // afficher le tableau codelist + appendChildNodes("globalDiv", Digicode.codelist.create()) + // recuperer la liste des codes + this.codelist.load(); + // afficher le formulaire de creation de code + appendChildNodes("globalDiv", DIV({"id":"addCodeBox"})); + Digicode.makeCode.displayForm(); +} + +/***************************** + Digicode.makeCode + *****************************/ +Digicode.makeCode = {} + +Digicode.makeCode.displayForm = function() +{ + + var myForm = FORM({'id':'createCodeForm', 'name':'createCodeForm','onsubmit':"Digicode.makeCode.createCode(document.createCodeForm.newCode.value); return false;", 'style':'display: none;'}, + BUTTON({"type":"button","onclick":"Digicode.makeCode.createCode(document.createCodeForm.newCode.value)", "style":"float:right;"},"Créer code"), + INPUT({"name":"newCode", "size":"6", "maxlength":"6", "style":"float:right;"}), + BUTTON({"type":"button","onclick":"Digicode.makeCode.createCode()", "style":"float:right;clear:both;"},"Code aléatoire") + ); + replaceChildNodes("addCodeBox", H1({},"Nouveau code"), myForm ); + appear(myForm); + +} + +Digicode.makeCode.restoreForm = function() +{ + try + { + removeElement("newCodeDisplay"); + removeElement("loading"); + } catch (error){} + appear("createCodeForm"); + +} + +Digicode.makeCode.createCode = function(code) +{ + var image = createDOM("IMG",{'style':'margin-right:2px;float:right;','src':'/static/images/indicator.gif'}); + appendChildNodes("addCodeBox", DIV({'id':"loading",'style':'display:none;max-height:1em;float:left;'},image,"Loading")) + removeElement("createCodeForm"); + appear("loading"); + if (code) + Digicode.AJAX.call("createCode?code="+code, this.handleNewCode); + else + Digicode.AJAX.call("createCode", this.handleNewCode); + +} +Digicode.makeCode.handleNewCode = function(res) +{ + if (res.code) + { + appendChildNodes("addCodeBox", + DIV({'id':"newCodeDisplay", + 'style':'display:none;font-size:2em;maring:1em;font-weight:bold;text-align:center;', + 'onclick':"Digicode.makeCode.displayForm();"},res.code)); + appear("newCodeDisplay"); + removeElement("loading") + Digicode.codelist.addCode(res); + } else if (res.erreur) { + logError("Erreur distante : " + res.erreur); + alert("Erreur sur le serveur, le code est peut-être déjà pris.") + Digicode.makeCode.displayForm(); + } else if (res.formatErreur) { + alert("Ceci n'est pas un code valide"); + Digicode.makeCode.displayForm(); + } + +} +/***************************** + Digicode.codelist + *****************************/ +Digicode.codelist = {}; + +Digicode.codelist.create = function () +{ + var thead = createDOM("thead", {}, + createDOM("th", {'class':'code'}, "Code" ), + createDOM("th", {'class':'age'}, "Age") + ); + var tbody = createDOM("tbody", {"id":"codeList"}); + return TABLE({"id":"codesTable", "cellspacing":"0"}, thead, tbody) +} + + + +Digicode.codelist.load = function() +{ + Digicode.AJAX.call("codeList", Digicode.codelist.displayCodes); +} + +Digicode.codelist.displayCodes = function(result) +{ + if (result.codes) + replaceChildNodes('codeList',map(Digicode.codelist.newCodeTrNodeFromDict,result.codes)); + else if (result.erreur) + logError("Erreur distante : " + result.erreur); +} + +Digicode.codelist.newCodeTrNodeFromDict = function (aDict, style) +{ + if (style) { + var aRow = createDOM("TR", {'id':'code'+aDict.code,"style":style}); + } else + var aRow = createDOM("TR", {'id':'code'+aDict.code}); + appendChildNodes(aRow, createDOM("TD", {'class':'code'}, aDict.code, SPAN({'style':'color:gray;margin-left:2em;'}, aDict.desc ) ) ); + appendChildNodes(aRow, createDOM("TD", {'class':'age'}, aDict.age) ); + return aRow; +} + +Digicode.codelist.addCode = function (aDict) +{ + var newLine = this.newCodeTrNodeFromDict(aDict) + appendChildNodes("codeList", newLine); + pulsate(newLine); +} + + +/***************************** + Digicode.AJAX + *****************************/ +Digicode.AJAX = {} + +Digicode.AJAX.call = function(page, callBack) { + logDebug("calling AJAX : " + page) + var e = loadJSONDoc(page); + e.addCallback(callBack); + e.addErrback(this.errorHandler); +} + +Digicode.AJAX.errorHandler = function(d) { + //Digicode.AJAX..modifPrix("Erreur", false); + logError("AJAX Error: " + d); +} + + + + + + + + + +setInterval(Digicode.codelist.load, 30000); diff --git a/intranet/static/scripts/impression.js b/intranet/static/scripts/impression.js new file mode 100644 index 00000000..84d3dce2 --- /dev/null +++ b/intranet/static/scripts/impression.js @@ -0,0 +1,334 @@ +/* ************************************************************ + * Impression + ************************************************************ + * Impression.settings : panneau de configuration + * Impression.popup : popup + * Impression.AJAX : ajax + */ +Impression = {}; + +/***************************** + Impression.settings + *****************************/ + +Impression.settings = {}; + + // +//// images : images used for previewing +// +Impression.settings.images = [ +"portrait_couleurs_agraphediagonale.png", +"portrait_couleurs_pasdagraphes.png", +"portrait_couleurs_uneagraphe.png", +"portrait_couleurs_Deuxagraphes.png", +"portrait_couleurs_troisAgraphes.png", +"portrait_couleurs_stitching.png", +"portrait_nb_agraphediagonale.png", +"portrait_nb_pasdagraphes.png", +"portrait_nb_uneagraphe.png", +"portrait_nb_Deuxagraphes.png", +"portrait_nb_troisAgraphes.png", +"portrait_nb_stitching.png", +"portrait_transparent_couleurs.png", +"portrait_transparent_nb.png", +]; + +Impression.settings.preloadImage = function(imageName) { + var image = new Image(); + image.src = "/static/images/"+imageName; +} + +Impression.settings.preloadAllImages = function() { + log("Preloading images..."); + map(this.preloadImage,this.images); +} + + // +//// init : parse every field and display preview +// +Impression.settings.init = function () { + log("Init settings..."); + this.theform = document.form_impression; + this.disableForm(false); +} + // +//// reset : reset form and then re-init settings +// +Impression.settings.reset = function () { + log("Reset form"); + this.theform.reset(); + this.init(); +} + +Impression.settings.disableForm = function(bool) +{ + log("Set Disable Form : " + bool); + var fields = this.theform.elements; for( var i=0; i< fields.length; i++) + { + this.setDisableField( fields[i], bool ); + } +} + + // +//// getValue : parse a field and store value in fielld.name +// +Impression.settings.getValue = function(field) +{ + if (field.value) + { + this[field.name] = field.value; + log( field.name + " is now " + this[field.name]); + } + else + { + logError("Can't get fieldValue"); + } +} + // +//// getCopies : parse copies field +// +Impression.settings.getCopies = function(field) { + if ( (!field.value) || (parseInt(field.value)!=field.value-0) || (parseInt(field.value) < 1) ) + { + this.copies = 1; + logError("Can't get copies"); + } + else + { + this.copies = parseInt(field.value); + } + log("copies is now " + this.copies); +} + + // +//// setValue : set field value +// +Impression.settings.setValue = function(afield, avalue) { + afield.value = avalue; + this.getValue(afield) +} + + // +//// setDisableField : set field disabled on/off +// +Impression.settings.setDisableField = function( afield, isdisabled ) { + afield.disabled = isdisabled ; +} + + // +//// disableField : set field disabled on +// +Impression.settings.disableField = function(afield) { + this.setDisableField(afield, true); +} + + // +//// fieldChanges : when a field is changed +// +Impression.settings.update = function (field) { + var orientation = "portrait"; + if (this.theform.type_impression_couleur.checked) + this.getValue(this.theform.type_impression_couleur); + else + this.getValue(this.theform.type_impression_nb); + + if (this.theform.disposition_recto.checked) + this.getValue(this.theform.disposition_recto); + else + this.getValue(this.theform.disposition_recto_verso); + this.getValue(this.theform.papier); + this.getCopies(this.theform.nb_copies); + this.getValue(this.theform.agrafes); + // Contraintes + if ( + ( this.papier != "A4" ) || + ( (this.disposition == "recto") && (this.nb_pages>50) ) || + ( (this.disposition == "rectoverso") && (this.nb_pages>100) ) ) { + this.setValue(this.theform.agrafes, "pasdagraphes"); + this.disableField(this.theform.agrafes); + this.getValue(this.theform.agrafes); + } else { + this.setDisableField(this.theform.agrafes, false); + } + if (this.papier == "A4tr") + { + this.theform.disposition_recto.checked = true; + this.disableField(this.theform.disposition_recto); + this.disableField(this.theform.disposition_recto_verso); + this.getValue(this.theform.disposition_recto); + } + else + { + this.setDisableField(this.theform.disposition_recto, false); + this.setDisableField(this.theform.disposition_recto_verso, false); + } + + logError("eee"); + this.updatePreview(); + logError("eee"); + Impression.AJAX.recalcPrix(); + logError("eee"); +} + + // +//// updatePreview : update preview with new value +// +Impression.settings.updatePreview = function() +{ + var image_name = ""; + if (this.papier == "A4tr") + image_name = "portrait_transparent_" + this.type_impression + ".png"; + else + image_name = "portrait_" + this.type_impression + '_' + this.agrafes + ".png"; + var image = createDOM("IMG",{'src':'/static/images/'+image_name}); + log("Updating preview (new image : " + image_name + ")"); + replaceChildNodes("preview",image) +} + + +/***************************** + Impression.popup + *****************************/ +Impression.popup = {}; + +Impression.popup.popupImpression = function(code) { + Popup.hide(); + Popup.create({}, "Impression en cours...", + DIV( + {"id":"printingPopupContent", "style":"background-image:url(/static/images/dialog-printer.png)"}, + SPAN("code: "+code), + A({"href":"https://wiki.crans.org/VieCrans/ImpressionReseau", "class":"aide", "target":"_blank"}, "Comment récupérer mon impression ? "))); + Popup.display(); +} + +Impression.popup.popupError = function(erreur) { + Popup.hide(); + Popup.create({}, "Erreur", + DIV({"id":"printingPopupContent", "style":"background-image:url(/static/images/dialog-warning.png)"}, + SPAN(erreur), + A({"href":"#", "class":"aide", "target":"_blank"}, "Envoyer un rapport aux nounous"), + Popup.closeLink({"class":"aide", "style":"text-align:right;"}, "Fermer"))); + Popup.display(); +} + +Impression.popup.popupSolde = function(code) { + Popup.hide(); + Popup.create({}, "Solde insuffisant", + DIV( + {"id":"printingPopupContent", "style":"background-image:url(/static/images/dialog-solde.png)"}, + SPAN("pas assez de sous"), + A({"href":"#", "class":"aide", "target":"_blank"}, "Comment recharger mon compte ? "), + Popup.closeLink({"class":"aide", "style":"text-align:right;"}, "Fermer"))); + Popup.display(); +} + + + +/***************************** + Impression.AJAX + *****************************/ + +Impression.AJAX = {}; + + +Impression.AJAX.modifPrix = function( text, wheel ) +{ + if (wheel) + { + var image = createDOM("IMG",{'src':'/static/images/indicator.gif'}); + } + else + { + var image = new DIV({}); + } + var item = new DIV({'onclick':'Impression.AJAX.recalcPrix();'}, image, text); + replaceChildNodes("prix_placeholder",item); +} + +Impression.AJAX.modifNbPages = function( nbpages ) +{ + Impression.settings.nb_pages = nbpages; + replaceChildNodes("fileNbPages",nbpages); +} + +Impression.AJAX.call = function(page, callBack) { + logDebug("calling AJAX : " + page) + var e = loadJSONDoc(page); + e.addCallback(callBack); + e.addErrback(this.errorHandler); +} + +Impression.AJAX.errorHandler = function(d) { + //Impression.AJAX..modifPrix("Erreur", false); + logError("AJAX Error: " + d); + Impression.AJAX.modifPrix("Erreur...", false); +} + + +Impression.AJAX.usefile = function(filename) { + var item = new DIV({}, "Calculs en cours..."); + this.modifPrix("Analyse du fichier...", true); + this.call('useFile?fileName=' + filename,this.analysefini ); +} + +Impression.AJAX.analysefini = function(AJAXResp) +{ + logDebug('AJAX terminated (usefile)'); + if (AJAXResp.erreur) { + Impression.AJAX.modifPrix(AJAXResp.erreur, false); + Impression.popup.popupError(AJAXResp.erreur); + Impression.settings.disableForm(true); + logWarning('Erreur distante : ' + AJAXResp.erreur); + } else { + Impression.AJAX.modifPrix("Analyse terminée", true); + Impression.settings.update(); + Impression.AJAX.modifNbPages(AJAXResp.nbPages); + } +} + +Impression.AJAX.recalcPrix = function() +{ + settings = Impression.settings; + var url = "changeSettings?copies=" + settings.copies + +"&couleurs="+ settings.type_impression + +"&papier="+ settings.papier + +"&recto_verso="+ settings.disposition + +"&agrafes="+ settings.agrafes; + this.modifPrix("Calcul en cours", true); + this.call(url, this.changePrix); +} + +Impression.AJAX.changePrix = function(AJAXResp) +{ + logDebug('AJAX terminated (recalcPrix)'); + if (AJAXResp.erreur) { + Impression.AJAX.modifPrix(AJAXResp.erreur, false); + Impression.popup.popupError(AJAXResp.erreur); + Impression.settings.disableForm(true); + logWarning('Erreur distante : ' + AJAXResp.erreur); + } else { + Impression.AJAX.modifPrix("Coût : " + AJAXResp.nouvPrix + "€", false); + } +} + +Impression.AJAX.lancerImpression = function(AJAXResp) +{ + var url = "lancerImpression"; + Impression.settings.disableForm(true); + this.call(url, this.etatImpression); +} + +Impression.AJAX.etatImpression = function(AJAXResp) +{ + logDebug('AJAX terminated (lancerImpression)'); + if (AJAXResp.erreur) { + Impression.popup.popupError(AJAXResp.erreur); + logWarning('Erreur distante : ' + AJAXResp.erreur); + } else if (AJAXResp.SoldeInsuffisant) { + Impression.popup.popupSolde(); + Impression.settings.disableForm(false); + Impression.settings.update(); + } else { + Impression.popup.popupImpression(AJAXResp.code); + } +} diff --git a/intranet/static/scripts/passwordGenerator.js b/intranet/static/scripts/passwordGenerator.js new file mode 100644 index 00000000..18b6cf90 --- /dev/null +++ b/intranet/static/scripts/passwordGenerator.js @@ -0,0 +1,66 @@ +/************************************************************************ + Password generator + ************************************************************************/ + +function GeneratePassword() { + + if (parseInt(navigator.appVersion) <= 3) { + alert("Sorry this only works in 4.0 browsers"); + return false; + } + + var length=8; + var sPassword = ""; + length = 10;//document.aForm.charLen.options[document.aForm.charLen.selectedIndex].value; + + var noPunction = false;//(document.aForm.punc.checked); + var randomLength = true;//(document.aForm.rLen.checked); + + if (randomLength) { + length = Math.random(); + + length = parseInt(length * 100); + length = (length % 7) + 6 + } + + + for (i=0; i < length; i++) { + + numI = getRandomNum(); + if (noPunction) { while (checkPunc(numI)) { numI = getRandomNum(); } } + + sPassword = sPassword + String.fromCharCode(numI); + } + + //document.aForm.passField.value = sPassword + c = prompt('Mot de passe généré : ', sPassword) + if (c!= null) { + document.changePasswordForm.nouveauPassword1.value = c + document.changePasswordForm.nouveauPassword2.value = c + } + return false; +} + +function getRandomNum() { + + // between 0 - 1 + var rndNum = Math.random() + + // rndNum from 0 - 1000 + rndNum = parseInt(rndNum * 1000); + + // rndNum from 33 - 127 + rndNum = (rndNum % 94) + 33; + + return rndNum; +} + +function checkPunc(num) { + + if ((num >=33) && (num <=47)) { return true; } + if ((num >=58) && (num <=64)) { return true; } + if ((num >=91) && (num <=96)) { return true; } + if ((num >=123) && (num <=126)) { return true; } + + return false; +} diff --git a/intranet/static/scripts/popup.js b/intranet/static/scripts/popup.js new file mode 100644 index 00000000..b970ebdb --- /dev/null +++ b/intranet/static/scripts/popup.js @@ -0,0 +1,34 @@ +Popup = {}; +Popup.popupNode = null; +Popup.visible = false; + +Popup.display = function() { + if (this.popupNode == null) { + logError("Popup not created, cannot be displayed"); + return false; + } + appendChildNodes("pageContent", this.popupNode); + this.visible = true; +// logDebug("popup visible"); +} + +Popup.create = function(options, title_popup, content) { + var inPopup = DIV({"id":"__popupInDivId", "style":"background:white;margin:2px 5px;"}, content); + var outPopup = DIV({"id":"__popupOutDivId","style":"background:#AE0F3E;z-index:500;float:left;padding:0;min-width:300px;position:fixed;top:30%;left:30%;right:30%;"}, H1({"style":"font-size:1em;margin:0;text-align:center;color:white;"}, IMG({"src":"/static/images/WindowTitleLogo.png","alt":"icon", "style":"margin:0 5px;"}), title_popup), inPopup ); + roundElement(outPopup); + logDebug("Popup \""+ title_popup +"\" created"); + this.popupNode = outPopup; +} + +Popup.hide = function() { + if (this.visible) { + removeElement(this.popupNode); + this.visible = false; + } +// logDebug("popup not visible"); +} +Popup.closeLink = function(options, text_link) { + options["href"] = "#"; + options["onclick"] = "Popup.hide()"; + return A(options, text_link); +} \ No newline at end of file