From 0ed57c8b50855272a64d05f3533b0a753e409849 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 8 May 2016 23:32:07 +0200 Subject: [PATCH] =?UTF-8?q?`matriceManager`=20version=201=20termin=C3=A9e,?= =?UTF-8?q?=20il=20manque=20notamment=20l'export=20de=20sauvegarde=20local?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/includes/input-phone-matrice-min.js | 12 +- js/includes/input-phone-matrice.js | 305 ++++++------------------- view/js/input-min.js | 4 +- view/js/input.js | 12 +- 4 files changed, 84 insertions(+), 249 deletions(-) diff --git a/js/includes/input-phone-matrice-min.js b/js/includes/input-phone-matrice-min.js index 78b68ef..ef08f7e 100644 --- a/js/includes/input-phone-matrice-min.js +++ b/js/includes/input-phone-matrice-min.js @@ -1,9 +1,5 @@ function inputPhoneMatrice(a){this.container=a}inputPhoneMatrice.prototype={container:this.container}; -inputPhoneMatrice.prototype.fieldsToStorage=function(){console.log("MATRICE: FIELDS TO STORAGE");var a=(new FormDeflater(this.container,["input"],["data-name"])).deflate();crc32(JSON.stringify(a));console.log(a);var b={},c;for(c in a)if(a[c]instanceof Array)for(var d in a[c])!0===a[c][d].status&&(null==b[c]&&(b[c]=[]),b[c].push(parseInt(a[c][d].value)));else!0===a[c].status&&(null==b[c]&&(b[c]=[]),b[c].push(parseInt(a[c].value)));lsi.set("matrice",0,b)}; -inputPhoneMatrice.prototype.add=function(a){console.log("MATRICE: ADD");if(null==a||null==a.uid)return!1;a.age=null!=a.age?a.age:this.defaultData.age;a.sexe=null!=a.sexe?a.sexe:this.defaultData.sexe;a.studies=null!=a.studies?a.studies:this.defaultData.studies;a.reltype=null!=a.reltype?a.reltype:this.defaultData.reltype;a.reltypeSpecial=null!=a.reltypeSpecial?a.reltypeSpecial:this.defaultData.reltypeSpecial;a.loc=null!=a.loc?a.loc:this.defaultData.loc;var b=lsi.get("contacts",a.uid);if(!1===b)return!1; -this.container.innerHTML+=miniFicheBuilder.build({firstname:b.firstname,lastname:b.lastname,username:0==b.username.length?"":"("+b.username+")",countcall:b.countcall,countsms:b.countsms,uid:a.uid,reltypespecial:a.reltypeSpecial});b=$('article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>span>select[data-name="studies"]>option[value="'+a.studies+'"]');null!=b&&b.setAttribute("selected","selected");b=$('article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>span>select[data-name="age"]>option[value="'+ -a.age+'"]');null!=b&&b.setAttribute("selected","selected");for(var c=$$('article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="sexe"]'),b=0;binput[type="radio"][data-name="reltype"]');for(b=0;binput[type="radio"][data-name="loc"]');for(b=0;b span.active"),c=0;c'+(c+1)+""}for(var d in a)b=$('#nav-mini [data-n="'+a[d].uid+'"]'),null!=b&&(!0===a[d].valid?b.addClass("done"):b.remClass("done"));this.nav($('#nav-mini [data-n="'+this.selected+'"]'))}; -inputPhoneMatrice.prototype.check=function(a){return!checkRadioValue(a.sexe)||"."==a.studies||"."==a.age||!checkRadioValue(a.loc)||!checkRadioValue(a.reltype)||a.reltype[8].status&&2>a.reltypeSpecial.length?!1:!0};inputPhoneMatrice.prototype.attach=function(a){console.log("MATRICE: ATTACH");lsi.createDataset("matrice");this.storageToFields();this.handler=a}; +inputPhoneMatrice.prototype.fieldsToStorage=function(){console.log("MATRICE: FIELDS TO STORAGE");var a=(new FormDeflater(this.container,["input"],["data-name"])).deflate();crc32(JSON.stringify(a));var d={},b;for(b in a)if(a[b]instanceof Array)for(var e in a[b])!0===a[b][e].status&&(null==d[b]&&(d[b]=[]),d[b].push(parseInt(a[b][e].value)));else!0===a[b].status&&(null==d[b]&&(d[b]=[]),d[b].push(parseInt(a[b].value)));lsi.set("matrice",0,d)}; +inputPhoneMatrice.prototype.storageToFields=function(){console.log("MATRICE: STORAGE TO FIELDS");var a=lsi["export"]("fiches"),d=lsi.get("matrice",0),b=lsi["export"]("contacts"),e=[],c;for(c in a)-1==e.indexOf(a[c].contact)&&e.push(a[c].contact);a="";for(c=0;c";0',a+=f.firstname+" "+f.lastname,a+=0",a+='',a+=g.firstname+" "+g.lastname,a+=0"):a+=""}a+=""}this.container.innerHTML= +a+"
"};inputPhoneMatrice.prototype.attach=function(){console.log("MATRICE: ATTACH");lsi.createDataset("matrice");this.storageToFields();var a=this;this.container.addEventListener("click",function(d){a.fieldsToStorage();a.storageToFields()},!1)}; diff --git a/js/includes/input-phone-matrice.js b/js/includes/input-phone-matrice.js index d4cdb8d..dc43a15 100644 --- a/js/includes/input-phone-matrice.js +++ b/js/includes/input-phone-matrice.js @@ -26,7 +26,7 @@ inputPhoneMatrice.prototype.fieldsToStorage = function(){ var deflatedHash = crc32(JSON.stringify(deflated)); - console.log(deflated); + // console.log(deflated); /* (3) On crée l'objet et on le remplit avec les relations */ var obj = {}; @@ -70,86 +70,6 @@ inputPhoneMatrice.prototype.fieldsToStorage = function(){ -/* [3] Gestion de l'ajout physique d'un nouveau contact -=========================================================*/ -/* -* -* @objectData Objet contenant les informations nécessaires à l'affichage -* -*/ -inputPhoneMatrice.prototype.add = function(objectData){ - console.log('MATRICE: ADD'); - - // Si pas d'UID, on retourne une erreur - if( objectData == null || objectData.uid == null ) - return false; - - /* (0) Gestion du formattage des valeur */ - objectData.age = (objectData.age != null) ? objectData.age : this.defaultData.age; - objectData.sexe = (objectData.sexe != null) ? objectData.sexe : this.defaultData.sexe; - objectData.studies = (objectData.studies != null) ? objectData.studies : this.defaultData.studies; - objectData.reltype = (objectData.reltype != null) ? objectData.reltype : this.defaultData.reltype; - objectData.reltypeSpecial = (objectData.reltypeSpecial != null) ? objectData.reltypeSpecial : this.defaultData.reltypeSpecial; - objectData.loc = (objectData.loc != null) ? objectData.loc : this.defaultData.loc; - - - // {1} On récupère username/firstname/lastname du contact associé // - var associatedContact = lsi.get('contacts', objectData.uid); - - // Si on ne trouve pas le contact, on ne fais rien - if( associatedContact === false ) - return false; - - - // {2} Création physique // - this.container.innerHTML += miniFicheBuilder.build({ - firstname: associatedContact.firstname, - lastname: associatedContact.lastname, - username: (associatedContact.username.length==0) ? '' : '('+associatedContact.username+')', - countcall: associatedContact.countcall, - countsms: associatedContact.countsms, - uid: objectData.uid, - reltypespecial: objectData.reltypeSpecial - }); - - - /* {3} On sélectionne la valeur dans le select (manuellement) de la PROFESSION */ - var selectedOption = $('article.mini-fiche-relation input[data-name="uid"][value="'+objectData.uid+'"] ~ h5>span>select[data-name="studies"]>option[value="'+objectData.studies+'"]'); - if( selectedOption != null ) - selectedOption.setAttribute('selected', 'selected'); - - /* {4} On sélectionne la valeur dans le select (manuellement) de l'AGE */ - selectedOption = $('article.mini-fiche-relation input[data-name="uid"][value="'+objectData.uid+'"] ~ h5>span>select[data-name="age"]>option[value="'+objectData.age+'"]'); - if( selectedOption != null ) - selectedOption.setAttribute('selected', 'selected'); - - /* {5} On sélectionna la valeur des boutons pour le SEXE */ - var sexeCreated = $$('article.mini-fiche-relation input[data-name="uid"][value="'+objectData.uid+'"] ~ h5>input[type="radio"][data-name="sexe"]'); - for( var i = 0 ; i < sexeCreated.length && i < objectData.sexe.length ; i++ ) - if( objectData.sexe[i].status ) sexeCreated[i].setAttribute('checked', 'checked'); - else sexeCreated[i].removeAttribute('checked'); - - /* {6} On sélectionna la valeur des boutons pour le TYPE DE RELATION */ - var reltypeCreated = $$('article.mini-fiche-relation input[data-name="uid"][value="'+objectData.uid+'"] ~ h5>input[type="radio"][data-name="reltype"]'); - for( var i = 0 ; i < reltypeCreated.length && i < objectData.reltype.length ; i++ ) - if( objectData.reltype[i].status ) reltypeCreated[i].setAttribute('checked', 'checked'); - else reltypeCreated[i].removeAttribute('checked'); - - /* {7} On sélectionna la valeur des boutons pour la LOCATION */ - var locCreated = $$('article.mini-fiche-relation input[data-name="uid"][value="'+objectData.uid+'"] ~ h5>input[type="radio"][data-name="loc"]'); - for( var i = 0 ; i < locCreated.length && i < objectData.loc.length ; i++ ) - if( objectData.loc[i].status ) locCreated[i].setAttribute('checked', 'checked'); - else locCreated[i].removeAttribute('checked'); - -}; - - - - - - - - /* [4] Gestion de l'affichage depuis le 'localStorage' @@ -157,176 +77,88 @@ inputPhoneMatrice.prototype.add = function(objectData){ inputPhoneMatrice.prototype.storageToFields = function(){ console.log('MATRICE: STORAGE TO FIELDS'); - // {1} Pour chaque contact du 'localStorage' // - var miniData = lsi.get('mini-fiches', this.selected); + /* (1) On récupère la liste des contacts à mettre dans la matrice */ + // On récupère les fiches + var ficheData = lsi.export('fiches'); - // On réinitialise le HTML - this.container.innerHTML = ''; + // On récupère les données de la matrice + var matriceData = lsi.get('matrice', 0); - // {2} On affiche la MINI fiche sélectionnée // - this.add(miniData); - - // {3} On met à jour la navigation // - this.updateNavBar(); - -}; - - - - - - - - - - - -/* [5] Synchronisation des CONTACT vers les MINI fiches -=========================================================*/ -inputPhoneMatrice.prototype.sync = function(){ - console.log('MATRICE: SYNC'); - - /* (1) On récupère les clés de tous les CONTACTS */ + // On récupère les contacts pour afficher les noms/prénoms var contactData = lsi.export('contacts'); - /* (2) Pour chaque CONTACT, on met à jour/crée la MINI fiche associée */ - for( var key in contactData ){ + // Contiendra les UID des contacts à mettre dans la matrice + var contacts = []; - /* (3) On récupère les informations de la MINI (si elle existe) */ - var miniData = lsi.get('mini-fiches', key); + // Pour chaque fiche, on ajoute l'uid du contact s'il n'est pas déja ajouté + for( var f in ficheData ) + if( contacts.indexOf( ficheData[f].contact ) == -1 ) + contacts.push( ficheData[f].contact ); - /* (4) Si la MINI fiche n'exise pas, on la crée avec les valeurs par défaut */ - if( miniData == null ){ - miniData = this.defaultData; - miniData.valid = false; - } + /* (2) On construit le HTML de la matrice */ + // Contiendra le HTML + var matrice_html = ""; - /* (5) On met à jour la MINI fiche */ - miniData.uid = contactData[key].uid; + // {1} Pour chaque ligne // + for( var A = 0 ; A < contacts.length ; A++ ){ + var conA = contactData[A]; - /* (6) On enregistre les modification */ - lsi.set('mini-fiches', key, miniData); + matrice_html += ''; + if( A > 0 ){ // Noms sur la première ligne (abscisses) + matrice_html += ''; + }else // Sinon, + matrice_html += ''; + + // {2} Pour chaque case // + for( var B = 0 ; B < contacts.length ; B++ ){ if( B < contacts.length-1 ){ + var conB = contactData[B]; + + // {3} Première colonne -> Intitulé des ordonnées // + if( A == 0 ){ + matrice_html += ''; + }} + + matrice_html += ''; } + matrice_html += '
'; + matrice_html += conA.firstname+' '+conA.lastname + matrice_html += (conA.username.length>0) ? ' ('+conA.username+')' : ''; + matrice_html += ''; + matrice_html += ''; + matrice_html += conB.firstname+' '+conB.lastname; + matrice_html += (conB.username.length>0) ? ' ('+conB.username+')' : ''; + matrice_html += ''; + + // {4} Valeurs des relations (boutons) // + }else if( B < A ){ + matrice_html += ""; + matrice_html += " -1 ) + matrice_html += " checked"; + matrice_html += " >"; + matrice_html += ""; + + // {5} Cases vides (moitié supérieure droite) // + }else + matrice_html += "
'; + + + /* (3) On affiche la matrice */ + this.container.innerHTML = matrice_html; }; - - - - -/* [6] Gestion de la navigation entre les fiches -=========================================================*/ -inputPhoneMatrice.prototype.nav = function(element){ - /* (1) On vérifie que l'élément contient un nombre et existe */ - if( element == null ) - return false; - - if( element.getData('n') === false || isNaN(element.getData('n')) || element.parentNode.id != 'nav-mini' ) - return false; - - /* (2) On désactive tous les éléments actifs */ - var activeElements = $$('#nav-mini > span.active'); - for( var i = 0 ; i < activeElements.length ; i++ ) - activeElements[i].remClass('active'); - - /* (3) On active l'élément courant */ - element.addClass('active'); - this.selected = parseInt(element.getData('n')); -}; - - - - - - - -/* [7] Mise à jour de la navigation -=========================================================*/ -inputPhoneMatrice.prototype.updateNavBar = function(){ - var miniData = lsi.export('mini-fiches'); - var len = Object.keys(miniData).length; - - - /* (1) On vérifie si la barre de navigation est à jour */ - var navBarUpToDate = $$('#nav-mini [data-n]').length == len; - - - /* (2) On vide et remplit la barre de nav, si elle n'est pas à jour */ - if( !navBarUpToDate ){ - this.nav_container.innerHTML = ''; - - for( var i = 0 ; i < len ; i++ ) - this.nav_container.innerHTML += ''+(i+1)+''; - } - - /* (3) On montre les MINI fiches qui sont correctes dans la navbar */ - for( var key in miniData ){ - - var currentElement = $('#nav-mini [data-n="'+miniData[key].uid+'"]'); - - if( currentElement == null ) - continue; - - // On remplit avec le numéro de la MINI fiche - // currentElement.setAttribute('data-n', miniData[key].uid); - // currentElement.innerHTML = miniData[key].uid + 1; - - // Si la MINI fiche est valide - if( miniData[key].valid === true ) currentElement.addClass('done'); - // Si elle est invalide - else currentElement.remClass('done'); - - } - - - - /* (4) On séléctionne par défaut la dernière MINI fiche sélectionnée */ - this.nav( $('#nav-mini [data-n="'+this.selected+'"]') ); -}; - - - - -/* [8] Vérification des données du formulaire -=========================================================*/ -inputPhoneMatrice.prototype.check = function(miniData){ - - // 1. Le sexe est défini - if( !checkRadioValue(miniData.sexe) ) - return false; - // 2. Le métier est défini - if( miniData.studies == '.' ) - return false; - // 3. L'age est définie - if( miniData.age == '.' ) - return false; - // 4. La distance de localisation est définie - if( !checkRadioValue(miniData.loc) ) - return false; - // 5. Le TYPE DE RELATION a un et un seul choix - if( !checkRadioValue(miniData.reltype) ) - return false; - // 6. TYPE DE RELATION si autre est coché (indice 8), reltypeSpecial doit avoir au moins 2 caractère - if( miniData.reltype[8].status && miniData.reltypeSpecial.length < 2 ) - return false; - - - // Si aucune erreur, tout est ok - return true; -}; - - - - - /* [9] Point d'amorçage de la gestion des contacts =========================================================*/ -inputPhoneMatrice.prototype.attach = function(handler){ +inputPhoneMatrice.prototype.attach = function(){ console.log('MATRICE: ATTACH'); /* (1) On initialise le jeu de données */ @@ -335,7 +167,10 @@ inputPhoneMatrice.prototype.attach = function(handler){ /* (2) On charge les mini fiches depuis la mémoire ('localStorage') */ this.storageToFields(); - /* (3) On attache la barre de navigation à une fonction */ - // On enregistre le handler - this.handler = handler; + /* (3) On enregistre la matrice à chaque modification */ + var ptr = this; + this.container.addEventListener('click', function(e){ + ptr.fieldsToStorage(); + ptr.storageToFields(); + }, false); }; diff --git a/view/js/input-min.js b/view/js/input-min.js index 0a806d4..a7baae9 100644 --- a/view/js/input-min.js +++ b/view/js/input-min.js @@ -1,7 +1,7 @@ var subjectManager,contactManager,miniManager,ficheManager,matriceManager,defTrue={status:!0,value:"on"},defFalse={status:!1,value:"on"}; function dynamicUpdate(a){var b=a instanceof Element,e=b&&"SPAN"==a.tagName&&"switch-left"==a.className,f=b&&"SPAN"==a.tagName&&"switch-both"==a.className,c=b&&"INPUT"==a.tagName&&"submit"==a.type,d=b&&"SPAN"==a.tagName&&("nav-mini"==a.parentNode.id||"nav-fiche"==a.parentNode.id),b=b&&"SPAN"==a.tagName&&"nav-contact"==a.parentNode.id;if(!(f||e||c||d||b)&&!0!==a)return!1;if(f)console.log("> switch firstname <-> lastname"),e=a.parentNode,a=e.children[8],e=e.children[10],f=a.value,a.value=e.value,e.value= -f;else if(e){console.log("> switch firstname+lastname -> username");e=a.parentNode;f=e.children[6];a=e.children[8];e=e.children[10];if(0 dynamic update"),miniManager.fieldsToStorage(),ficheManager.fieldsToStorage(),contactManager.fieldsToStorage(),miniManager.sync(),ficheManager.sync(),miniManager.storageToFields(),ficheManager.storageToFields(),(c||b)&&contactManager.storageToFields()} -function checkRadioValue(a){for(var b=0,e=0;e switch firstname+lastname -> username");e=a.parentNode;f=e.children[6];a=e.children[8];e=e.children[10];if(0 dynamic update"),miniManager.fieldsToStorage(),ficheManager.fieldsToStorage(),contactManager.fieldsToStorage(),matriceManager.fieldsToStorage(),miniManager.sync(),ficheManager.sync(),miniManager.storageToFields(),ficheManager.storageToFields(), +matriceManager.storageToFields(),(c||b)&&contactManager.storageToFields()}function checkRadioValue(a){for(var b=0,e=0;ec;c++)f.push(b.calls[c].number);for(c=0;c