Création du 'html-builder' sur le même principe de remplissage des variables que '/api/client.php' mais pour le contenu HTML
This commit is contained in:
parent
91c7acfc0f
commit
e01f20bae8
|
@ -0,0 +1 @@
|
|||
function HTMLBuilder(){}HTMLBuilder.prototype={layout:null,default_params:{},setLayout:function(a){this.layout=a},build:function(a){var b=this.layout,c;for(c in a){var d=new RegExp("@"+c,"g");console.log(d);b=b.replace(d,a[c])}return b}};
|
|
@ -0,0 +1,30 @@
|
|||
function HTMLBuilder(){}
|
||||
|
||||
|
||||
HTMLBuilder.prototype = {
|
||||
layout: null,
|
||||
default_params: {},
|
||||
|
||||
/* [1] Définit le layout (texte HTML à utiliser)
|
||||
=========================================================*/
|
||||
// Les variables sont entrées en '@nomvariable' dans la chaine
|
||||
setLayout: function(layout){ this.layout = layout; },
|
||||
|
||||
/* [2] Construction renvoie le contenu avec les paramètres remplacés
|
||||
=========================================================*/
|
||||
build: function(parameters){
|
||||
// Contiendra le résultat
|
||||
var render = this.layout;
|
||||
|
||||
for( var name in parameters ){
|
||||
// Contiendra l'expression régulière pour remplacer le paramètre
|
||||
var regex = new RegExp('@'+name, 'g');
|
||||
console.log(regex);
|
||||
|
||||
render = render.replace(regex, parameters[name]);
|
||||
}
|
||||
|
||||
return render;
|
||||
}
|
||||
|
||||
};
|
1
view.php
1
view.php
|
@ -26,6 +26,7 @@
|
|||
|
||||
<!-- Dépendences Javascript -->
|
||||
<script type='text/javascript' src='/f/js/local-storage-interface-min/js/lib' ></script> <!-- Interface de gestion du 'localStorage' -->
|
||||
<script type='text/javascript' src='/f/js/html-builder-min/js/lib' ></script> <!-- Gestion de construction de HTML -->
|
||||
<script type='text/javascript' src='/f/js/input-checker-min/js/lib' ></script> <!-- Gestion dynamique des saisies -->
|
||||
<script type='text/javascript' src='/f/js/form-deflater-min/js/lib' ></script> <!-- Gestion des formulaires js-friendly -->
|
||||
<script type='text/javascript' src='/f/js/reset-min/js/lib' ></script> <!-- Corrections Javascript natif (ajouts) -->
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
function newContactHTMLBuilder(a,b,c,d){var e=document.createElement("h4");e.dataset.icon="p";e.className="new-contact";a="<input type='text' data-name='number' placeholder='Num\u00e9ro de t\u00e9l\u00e9phone' value='"+("undefined"!=typeof a?a:"")+"'> ";a+="<input type='text' data-name='username' placeholder='Pseudo' value='";a+="undefined"!=typeof b?b:"";a+="'> ";a+="<input type='text' data-name='firstname' placeholder='Pr\u00e9nom' value='";a+="undefined"!=typeof c?c:"";a+="'> ";a+="<input type='text' data-name='lastname' placeholder='Nom' value='";
|
||||
a+="undefined"!=typeof d?d:"";a+="'> ";a+="<input type='submit' class='primary sub-number' value='Enregistrer'>";e.innerHTML=a;return e}var ficheRelationHTML="";function updateListener(a,b,c,d){a.removeEventListener(b,c);d.addEventListener(b,c);return d}var ic=new inputChecker,FormDeflaterP={tags:["input"],attr:["data-name"]},importCallLog=$('input#call_log-import[type="file"]'),contactDeflaters=[];
|
||||
function contactForms(){var a=$$("h4.new-contact");contactDeflaters=[];for(var b=0;b<a.length;b++)contactDeflaters.push(new FormDeflater(a[b],FormDeflaterP.tags,FormDeflaterP.attr));return a}var addContact=$("h4.add-contact"),contactContainer=$("article.contact-panel");
|
||||
var contactBuilder=new HTMLBuilder,contactBuilderLayout="<input type='text' data-name='number' placeholder='Num\u00e9ro de t\u00e9l\u00e9phone' value='@number'> ",contactBuilderLayout=contactBuilderLayout+"<input type='text' data-name='username' placeholder='Pseudo' value='@username'> ",contactBuilderLayout=contactBuilderLayout+"<input type='text' data-name='firstname' placeholder='Pr\u00e9nom' value='@firstname'> ",contactBuilderLayout=contactBuilderLayout+"<input type='text' data-name='lastname' placeholder='Nom' value='@lastname'> ",
|
||||
contactBuilderLayout=contactBuilderLayout+"<input type='submit' class='primary sub-number' value='Enregistrer'>";contactBuilder.setLayout(contactBuilderLayout);function newContactHTMLBuilder(b,a,c,d){var e=document.createElement("h4");e.dataset.icon="p";e.className="new-contact";e.innerHTML=contactBuilder.build({number:"string"!=typeof b?"":b,username:"string"!=typeof a?"":a,firstname:"string"!=typeof c?"":c,lastname:"string"!=typeof d?"":d});return e}var ficheRelationHTML="";
|
||||
function updateListener(b,a,c,d){b.removeEventListener(a,c);d.addEventListener(a,c);return d}var ic=new inputChecker,FormDeflaterP={tags:["input"],attr:["data-name"]},importCallLog=$('input#call_log-import[type="file"]'),contactDeflaters=[];function contactForms(){var b=$$("h4.new-contact");contactDeflaters=[];for(var a=0;a<b.length;a++)contactDeflaters.push(new FormDeflater(b[a],FormDeflaterP.tags,FormDeflaterP.attr));return b}var addContact=$("h4.add-contact"),contactContainer=$("article.contact-panel");
|
||||
function addNewContact(){console.log("adding New Contact");console.log(contactContainer.children);contactContainer.removeChild(addContact);contactContainer.appendChild(newContactHTMLBuilder());contactContainer.appendChild(addContact)}addContact.addEventListener("click",addNewContact,!1);var relationDeflaters=[];
|
||||
function relationForms(){var a=$$("h4.fiche-relation");relationDeflaters=[];for(var b=0;b<a.length;b++)relationDeflaters.push(new FormDeflater(a[b],FormDeflaterP.tags,FormDeflaterP.attr));return a}importCallLog.addEventListener("change",function(a){api.send({path:"upload/call_log",file:importCallLog.files[0]},function(a){console.log(a);0==a.ModuleError&&importCallLog.addClass("active")})},!1);
|
||||
function relationForms(){var b=$$("h4.fiche-relation");relationDeflaters=[];for(var a=0;a<b.length;a++)relationDeflaters.push(new FormDeflater(b[a],FormDeflaterP.tags,FormDeflaterP.attr));return b}importCallLog.addEventListener("change",function(b){api.send({path:"upload/call_log",file:importCallLog.files[0]},function(a){console.log(a);0==a.ModuleError&&importCallLog.addClass("active")})},!1);
|
||||
|
|
|
@ -21,31 +21,26 @@
|
|||
|
||||
/* [0] Gestion des constantes et fonctions
|
||||
=========================================================*/
|
||||
var contactBuilder = new HTMLBuilder();
|
||||
var contactBuilderLayout = "<input type='text' data-name='number' placeholder='Numéro de téléphone' value='@number'> ";
|
||||
contactBuilderLayout += "<input type='text' data-name='username' placeholder='Pseudo' value='@username'> ";
|
||||
contactBuilderLayout += "<input type='text' data-name='firstname' placeholder='Prénom' value='@firstname'> ";
|
||||
contactBuilderLayout += "<input type='text' data-name='lastname' placeholder='Nom' value='@lastname'> ";
|
||||
contactBuilderLayout += "<input type='submit' class='primary sub-number' value='Enregistrer'>";
|
||||
contactBuilder.setLayout(contactBuilderLayout);
|
||||
|
||||
/* (1) Contiendra le formulaire d'ajout de contact (numéro, pseudo, prénom, nom, submit) */
|
||||
function newContactHTMLBuilder(number, username, firstname, lastname){
|
||||
var root = document.createElement('h4');
|
||||
root.dataset.icon = 'p';
|
||||
root.className = 'new-contact';
|
||||
|
||||
var contentHTML = "<input type='text' data-name='number' placeholder='Numéro de téléphone' value='";
|
||||
contentHTML += (typeof number != 'undefined') ? number : '';
|
||||
contentHTML += "'> ";
|
||||
|
||||
contentHTML += "<input type='text' data-name='username' placeholder='Pseudo' value='";
|
||||
contentHTML += (typeof username != 'undefined') ? username : '';
|
||||
contentHTML += "'> ";
|
||||
|
||||
contentHTML += "<input type='text' data-name='firstname' placeholder='Prénom' value='";
|
||||
contentHTML += (typeof firstname != 'undefined') ? firstname : '';
|
||||
contentHTML += "'> ";
|
||||
|
||||
contentHTML += "<input type='text' data-name='lastname' placeholder='Nom' value='";
|
||||
contentHTML += (typeof lastname != 'undefined') ? lastname : '';
|
||||
contentHTML += "'> ";
|
||||
|
||||
contentHTML += "<input type='submit' class='primary sub-number' value='Enregistrer'>";
|
||||
|
||||
root.innerHTML = contentHTML;
|
||||
root.innerHTML = contactBuilder.build({
|
||||
number: (typeof number != 'string') ? '' : number,
|
||||
username: (typeof username != 'string') ? '' : username,
|
||||
firstname: (typeof firstname != 'string') ? '' : firstname,
|
||||
lastname: (typeof lastname != 'string') ? '' : lastname
|
||||
});
|
||||
|
||||
return root;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue