From 48099c7910d4fc174bf26be4b7f00a7701ce5087 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Fri, 27 May 2016 16:52:20 +0200 Subject: [PATCH] =?UTF-8?q?R=C3=A9tablissement=20des=20donn=C3=A9es=20(non?= =?UTF-8?q?=20modifiables)=20pour=20les=20'mini'=20=C3=A0=20partir=20des?= =?UTF-8?q?=20'contacts=20d=C3=A9ja=20utilis=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/includes/input-phone-contact-min.js | 2 +- js/includes/input-phone-contact.js | 1 - js/includes/input-phone-mini-min.js | 9 ++++---- js/includes/input-phone-mini.js | 28 +++++++++++++++++++++++ view/js/input-min.js | 5 +++-- view/js/input.js | 31 ++++++++++++++++++-------- 6 files changed, 59 insertions(+), 17 deletions(-) diff --git a/js/includes/input-phone-contact-min.js b/js/includes/input-phone-contact-min.js index 412cca5..2ee9ff0 100644 --- a/js/includes/input-phone-contact-min.js +++ b/js/includes/input-phone-contact-min.js @@ -1,5 +1,5 @@ function inputPhoneContact(a,c){this.container=a;this.nav_container=c}inputPhoneContact.prototype={container:this.container,nav_container:this.nav_container,selected:0,handler:null};inputPhoneContact.prototype.check=function(a){return"."!=a.existing||0"+c[b].name+"\n"; this.container.innerHTML+=pContactBuilder.build(a);b=$('[data-sublink="phone"] article.contact-panel .new-contact input[data-name="uid"][value="'+a.uid+'"] ~ span select[data-name="existing"]>option[value="'+a.existing+'"]');null!=b&&b.setAttribute("selected","selected");a=$$('[data-sublink="phone"] article.contact-panel .new-contact');var d=this;for(b=0;b MINI UPDATE");c={uid:parseInt(c.uid),sexe:c.sexe,age:c.age,studies:c.studies,reltype:c.reltype, reltypeSpecial:c.reltypeSpecial,loc:c.loc,unknown:null!=c.unknown,hash:d};c.valid=this.check(c);0 FICHE UPDATE"),c.timestamp=Date.now());lsi.set("p_mini-fiches",c.uid,c)}}}; inputPhoneMini.prototype.add=function(a){console.log("MINI FICHE: 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;a.unknown=null!=a.unknown?a.unknown:this.defaultData.unknown; -var b=lsi.get("p_contacts",a.uid);if(!1===b)return!1;this.container.innerHTML+=pMiniFicheBuilder.build({name:b.username,countcall:b.countcall,countsms:b.countsms,uid:a.uid,reltypespecial:a.reltypeSpecial});b=$('[data-sublink="phone"] 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=$('[data-sublink="phone"] 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=$$('[data-sublink="phone"] 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;binput[type="checkbox"][data-name="unknown"]'); -null!=b&&a.unknown&&b.setAttribute("checked","checked")};inputPhoneMini.prototype.storageToFields=function(){console.log("MINI FICHE: STORAGE TO FIELDS");var a=lsi.get("p_mini-fiches",this.selected);if(null==a)return this.updateNavBar(),!1;this.container.innerHTML="";this.add(a);this.updateNavBar()}; +var b=lsi.get("p_contacts",a.uid);if(!1===b)return!1;if(!isNaN(b.existing)){var c=lsi.get("p_friends",b.existing);b.username=c.name;a.age=c.age;a.sexe=c.sexe;a.loc=c.dist;isNaN(c.reltype)?(a.reltype=10,a.reltypeSpecial=c.reltype):(a.reltype=c.reltype,a.reltypeSpecial="");null!=c.studies1&&(a.studies=c.studies1)}this.container.innerHTML+=pMiniFicheBuilder.build({name:b.username,countcall:b.countcall,countsms:b.countsms,uid:a.uid,reltypespecial:a.reltypeSpecial});b=$('[data-sublink="phone"] 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=$('[data-sublink="phone"] 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");c=$$('[data-sublink="phone"] article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="sexe"]');for(b=0;binput[type="radio"][data-name="reltype"]');for(b=0;binput[type="radio"][data-name="loc"]');for(b=0;binput[type="checkbox"][data-name="unknown"]');null!=b&&a.unknown&&b.setAttribute("checked","checked")}; +inputPhoneMini.prototype.storageToFields=function(){console.log("MINI FICHE: STORAGE TO FIELDS");var a=lsi.get("p_mini-fiches",this.selected);if(null==a)return this.updateNavBar(),!1;this.container.innerHTML="";this.add(a);this.updateNavBar()}; inputPhoneMini.prototype.sync=function(){console.log("MINI FICHE: SYNC");var a=lsi["export"]("p_contacts"),b=lsi["export"]("p_fiches"),c=[],d;for(d in b)-1==c.indexOf(b[d].contact)&&c.push(b[d].contact);for(var e in a)-1 span.active'),c=0;c'+ ++b+"");for(c in a)isNaN(c)||(b=$('[data-sublink="phone"] #p_nav-mini [data-n="'+a[c].uid+'"]'),null!=b&&(!0===a[c].valid?b.addClass("done"):b.remClass("done")));this.nav($('[data-sublink="phone"] #p_nav-mini [data-n="'+this.selected+'"]'))}; diff --git a/js/includes/input-phone-mini.js b/js/includes/input-phone-mini.js index c2548f2..d63a3c6 100644 --- a/js/includes/input-phone-mini.js +++ b/js/includes/input-phone-mini.js @@ -130,6 +130,34 @@ inputPhoneMini.prototype.add = function(objectData){ if( associatedContact === false ) return false; + // {2} Si lié à un contact d'une autre étude, on utilise ses informations // + if( !isNaN(associatedContact.existing) ){ + var existingData = lsi.get('p_friends', associatedContact.existing); + + // On récupère les données communes + associatedContact.username = existingData.name; + objectData.age = existingData.age; + objectData.sexe = existingData.sexe; + objectData.loc = existingData.dist; + + // Si valeur + if( !isNaN(existingData.reltype) ){ + objectData.reltype = existingData.reltype; + objectData.reltypeSpecial = ''; + + // Si extra + }else{ + objectData.reltype = 10; + objectData.reltypeSpecial = existingData.reltype; + } + + // Si données de mini // + if( existingData.studies1 != null ) + objectData.studies = existingData.studies1; + + } + + // {2} Création physique // this.container.innerHTML += pMiniFicheBuilder.build({ diff --git a/view/js/input-min.js b/view/js/input-min.js index a4ea49d..5f7e1e0 100644 --- a/view/js/input-min.js +++ b/view/js/input-min.js @@ -2,8 +2,9 @@ var sField=$("#search-field"),sSubmit=$("#search-subject"),sList=$('section[data sSubmit.addEventListener("click",function(b){api.send({path:"subject/search",name:sField.value},function(a){if(0!=a.ModuleError)return Notification.error("Erreur","La recherche a \u00e9chou\u00e9."),!1;console.log(a);var e="",b;for(b in a.results)e+="
  • ",e+="
    SUJET
    ",e+="
    ",e+="
    "+ a.results[b].name+"
    ",e+="
    "+a.results[b].creation+"
    ",e+="
    ",e+="
    ",e+="
    ",e+="
    ",e+="
  • ";sList.innerHTML=e})},!1); var pSubjectManager,pContactManager,pMiniManager,pFicheManager,pMatriceManager; -function pDynamicUpdate(b){var a=b instanceof Element,e=a&&"INPUT"==b.tagName&&"submit"==b.type,g=a&&"SPAN"==b.tagName&&("p_nav-mini"==b.parentNode.id||"p_nav-fiche"==b.parentNode.id),c=a&&"SPAN"==b.tagName&&"p_nav-contact"==b.parentNode.id;if(!e&&!g&&!c&&!0!==b)return!1;console.log("> dynamic update");pMiniManager.fieldsToStorage();pFicheManager.fieldsToStorage();pContactManager.fieldsToStorage();pMatriceManager.fieldsToStorage();pFicheManager.sync();pMiniManager.sync();api.send({path:"subject/getFriends", -subject_id:pSubjectManager.subject_id.value},function(a){if(0!=a.ModuleError)return!1;console.warn("> existing contacts loaded");lsi["import"]("p_friends",a.subjects);pMiniManager.storageToFields();pFicheManager.storageToFields();pMatriceManager.storageToFields();(e||c)&&pContactManager.storageToFields()})}var fSubjectManager,fContactManager,fMiniManager,fFicheManager,fMatriceManager; +function pDynamicUpdate(b){var a=b instanceof Element,e=a&&"INPUT"==b.tagName&&"submit"==b.type,g=a&&"SPAN"==b.tagName&&("p_nav-mini"==b.parentNode.id||"p_nav-fiche"==b.parentNode.id),c=a&&"SPAN"==b.tagName&&"p_nav-contact"==b.parentNode.id;if(!e&&!g&&!c&&!0!==b)return!1;console.log("> dynamic update");pMiniManager.fieldsToStorage();pFicheManager.fieldsToStorage();pContactManager.fieldsToStorage();pMatriceManager.fieldsToStorage();pFicheManager.sync();pMiniManager.sync();!0===b?api.send({path:"subject/getFriends", +subject_id:pSubjectManager.subject_id.value},function(a){if(0!=a.ModuleError)return!1;console.warn("> existing contacts loaded");lsi["import"]("p_friends",a.subjects);pMiniManager.storageToFields();pFicheManager.storageToFields();pMatriceManager.storageToFields();(e||c)&&pContactManager.storageToFields()}):(pMiniManager.storageToFields(),pFicheManager.storageToFields(),pMatriceManager.storageToFields(),(e||c)&&pContactManager.storageToFields())} +var fSubjectManager,fContactManager,fMiniManager,fFicheManager,fMatriceManager; function fDynamicUpdate(b){var a=b instanceof Element,e=a&&"INPUT"==b.tagName&&"submit"==b.type,g=a&&"SPAN"==b.tagName&&("f_nav-mini"==b.parentNode.id||"f_nav-fiche"==b.parentNode.id),a=a&&"SPAN"==b.tagName&&"f_nav-contact"==b.parentNode.id;if(!e&&!g&&!a&&!0!==b)return!1;console.log("> dynamic update");fMiniManager.fieldsToStorage();fFicheManager.fieldsToStorage();fContactManager.fieldsToStorage();fMatriceManager.fieldsToStorage();fFicheManager.sync();fMiniManager.sync();fMiniManager.storageToFields(); fFicheManager.storageToFields();fMatriceManager.storageToFields();(e||a)&&fContactManager.storageToFields()} include("/js/includes/input-phone-subject-min.js",function(){include("/js/includes/input-phone-contact.js",function(){include("/js/includes/input-phone-mini.js",function(){include("/js/includes/input-phone-fiche-min.js",function(){include("/js/includes/input-phone-matrice-min.js",function(){pSubjectManager=new inputPhoneSubject($('[data-sublink="phone"] article.subject-panel [data-name="tmp_id"]'),$('[data-sublink="phone"] article.subject-panel [data-name="subject_id"]'),$('[data-sublink="phone"] article.subject-panel [data-name="submit"]')); diff --git a/view/js/input.js b/view/js/input.js index 02ac5ce..c7eae45 100644 --- a/view/js/input.js +++ b/view/js/input.js @@ -114,15 +114,29 @@ function pDynamicUpdate(target){ pMiniManager.sync(); /* (7) On récupère tous les amis du sujet */ - api.send({ path: 'subject/getFriends', subject_id: pSubjectManager.subject_id.value }, function(response){ - // Si erreur, on quitte - if( response.ModuleError != 0 ) - return false; + if( target === true ){ + api.send({ path: 'subject/getFriends', subject_id: pSubjectManager.subject_id.value }, function(response){ + // Si erreur, on quitte + if( response.ModuleError != 0 ) + return false; - // On enregistre les contacts existants - console.warn('> existing contacts loaded'); - lsi.import('p_friends', response.subjects); + // On enregistre les contacts existants + console.warn('> existing contacts loaded'); + lsi.import('p_friends', response.subjects); + /* (8) On affiche le tout */ + pMiniManager.storageToFields(); + pFicheManager.storageToFields(); + pMatriceManager.storageToFields(); + + /* (8) On met à jour les contacts si on les a modifié on si on navigue dans les contacts */ + if( isSaveButton || isNavContact ) + pContactManager.storageToFields(); + + }); + + + }else{ /* (8) On affiche le tout */ pMiniManager.storageToFields(); pFicheManager.storageToFields(); @@ -131,8 +145,7 @@ function pDynamicUpdate(target){ /* (8) On met à jour les contacts si on les a modifié on si on navigue dans les contacts */ if( isSaveButton || isNavContact ) pContactManager.storageToFields(); - - }); + } }