From 4d5b58c3787799b14038dbf5e38f657c7a711c20 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 30 Apr 2016 11:33:01 +0200 Subject: [PATCH] =?UTF-8?q?Pr=C3=A9pa=20envoi=20formulaire=20+=20cr=C3=A9a?= =?UTF-8?q?tion=20parseur=20markdown=20(docu)=20=C3=A0=20partir=20de=20/co?= =?UTF-8?q?nfig/modules.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/modules.json | 9 +++- js/includes/charts-sociogram-min.js | 2 +- js/includes/charts-sociogram.js | 2 +- js/includes/input-phone-fiche-min.js | 5 +-- js/includes/input-phone-fiche.js | 2 +- js/includes/input-phone-mini-min.js | 4 +- js/includes/input-phone-mini.js | 2 +- manager/module/{charts.php => chart.php} | 2 +- manager/module/module.php | 55 ++++++++++++++++++++++++ view/charts.php | 4 +- view/input.php | 15 +++++-- view/js/input-min.js | 5 ++- view/js/input.js | 51 +++++++++++++++++++--- 13 files changed, 134 insertions(+), 24 deletions(-) rename manager/module/{charts.php => chart.php} (97%) diff --git a/config/modules.json b/config/modules.json index c2bb684..ebaccbd 100755 --- a/config/modules.json +++ b/config/modules.json @@ -29,6 +29,13 @@ "description": "Méthode utile à phpunit pour le test des permissions.", "permissions": ["a", "b"], "parameters": {} + }, + + + "markdown": { + "description": "Retourne une description en markdown des différents modules de l'API", + "permissions": [], + "parameters": {} } }, @@ -97,7 +104,7 @@ } }, - "charts": { + "chart": { "network_data": { "description": "Renvoie un jeu de donnees fictif pour un graphique de type #network.", diff --git a/js/includes/charts-sociogram-min.js b/js/includes/charts-sociogram-min.js index 388647b..5422cc7 100644 --- a/js/includes/charts-sociogram-min.js +++ b/js/includes/charts-sociogram-min.js @@ -1,5 +1,5 @@ function sociogramClass(a){this.container=a;this.log("sociogram created")} -sociogramClass.prototype={container:this.container,sigma:null,request:{path:"charts/network_data"},response:null,nodes:[],edges:[],rad:500,nodeDistance:100,overloadGraph:function(){},load:function(){},nodeAt:function(a,b){},arrange:function(a,b,d){},extractNodesFromResponse:function(){},extractEdgesFromResponse:function(){},renderNodes:function(){},renderEdges:function(){},overload:{nodeNeighbors:function(a){},nodeDirectNeighbors:function(a){}},bindings:{clickNode:function(a,b){},clickStage:function(a, +sociogramClass.prototype={container:this.container,sigma:null,request:{path:"chart/network_data"},response:null,nodes:[],edges:[],rad:500,nodeDistance:100,overloadGraph:function(){},load:function(){},nodeAt:function(a,b){},arrange:function(a,b,d){},extractNodesFromResponse:function(){},extractEdgesFromResponse:function(){},renderNodes:function(){},renderEdges:function(){},overload:{nodeNeighbors:function(a){},nodeDirectNeighbors:function(a){}},bindings:{clickNode:function(a,b){},clickStage:function(a, b){}},log:function(a){console.log("--[SOCIOGRAM]--");console.warn(a);console.log("--[/SOCIOGRAM]--")}};sociogramClass.prototype.overloadGraph=function(){sigma.classes.graph.addMethod("nodeNeighbors",this.overload.nodeNeighbors);sigma.classes.graph.addMethod("nodeDirectNeighbors",this.overload.nodeDirectNeighbors);this.log("graph overloaded")}; sociogramClass.prototype.load=function(){this.sigma=new sigma({renderer:{container:this.container,type:"canvas"}});var a=this;api.send(this.request,function(b){a.log(b);0==b.ModuleError&&(a.response=b,a.sigma.settings({defaultNodeColor:"#348ed8",defaultLabelSize:14,defaultLabelBGColor:"#ddd",defaultHoverLabelBGColor:"#002147",defaultLabelHoverColor:"#fff",labelThreshold:10,defaultEdgeType:"line"}),a.extractNodesFromResponse(),a.extractEdgesFromResponse(),a.addNodes(),a.addEdges(),a.sigma.bind("clickNode", function(b){a.bindings.clickNode(a,b)}),a.sigma.bind("clickStage",function(b){a.bindings.clickStage(a,b)}),a.sigma.graph.nodes().forEach(function(b){a.arrange(b.id,null,!0)}),a.sigma.camera.ratio=1.2,a.sigma.refresh())})};sociogramClass.prototype.nodeAt=function(a,b){var d=this.sigma.graph.nodes(),c=null,e;for(e in d){var f=Math.sqrt(Math.pow(a-d[e].x,2)+Math.pow(b-d[e].y,2));if(null==c||fspan>select[data-name="job"]>option[value="'+a.job+'"]');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="loc"]');for(b=0;b Description des modules + * + */ + public static function markdown(){ + /* [1] Récupération de la configuration + =========================================================*/ + // On récupère le fichier et on le parse + $modules = json_decode( ResourceDispatcher::getResource('f/json/modules/conf'), true ); + + // Gestion de l'erreur de parsage + if( $modules == null ) + return array( 'ModuleError' => ManagerError::ParsingFailed ); + + /* [2] Mise en forme de la liste des modules + =========================================================*/ + $markdown = "## Module List
"; + + foreach($modules as $moduleName=>$moduleData) + $markdown .= "- $moduleName
"; + + /* [3] Mise en forme des méthodes des modules + =========================================================*/ + $markdown .= '----
## Method List & Description
'; + + $count = 1; + foreach($modules as $moduleName=>$moduleData){ + $markdown .= "### $count - '$moduleName' methods
"; + + foreach($moduleData as $methodName=>$methodData) + $markdown .= "- `$methodName` - ".$methodData['description']."
"; + + $markdown .= '----
'; + + $count++; + } + + + + /* [n] Gestion du retour + =========================================================*/ + return array( + 'ModuleError' => ManagerError::Success, + 'markdown' => $markdown + ); + } } + ?> diff --git a/view/charts.php b/view/charts.php index 087df69..c4e9e24 100755 --- a/view/charts.php +++ b/view/charts.php @@ -13,7 +13,7 @@ /* [1] Gestion du cercle des relations =======================================*/ /* (1) On recupere les donnees */ -$getData = new ModuleRequest('charts/network_data'); +$getData = new ModuleRequest('chart/network_data'); $answer = $getData->dispatch(); // Si pas d'erreur @@ -25,7 +25,7 @@ $data = $answer->get('data'); /* (2) On recupere le rendu */ -$getRender = new ModuleRequest('charts/network_render', array('dataset' => $data)); +$getRender = new ModuleRequest('chart/network_render', array('dataset' => $data)); $answer = $getRender->dispatch(); // Si pas d'erreur diff --git a/view/input.php b/view/input.php index a15763b..ae27fff 100755 --- a/view/input.php +++ b/view/input.php @@ -110,14 +110,23 @@

Remplir les fiches relations complètes des contacts les plus contactés

- - -
+
+ + + +

Envoi des données

+
+

+ +

+ + + diff --git a/view/js/input-min.js b/view/js/input-min.js index 6521bd2..7079552 100644 --- a/view/js/input-min.js +++ b/view/js/input-min.js @@ -1,8 +1,9 @@ -var clearAllButton=$("#clear-all"),importCallLog=$('input#call_log-import[type="file"]'),subjectManager,contactManager,miniManager,ficheManager; +var clearAllButton=$("#clear-all"),submitAllButton=$("#submit-all"),importCallLog=$('input#call_log-import[type="file"]'),subjectManager,contactManager,miniManager,ficheManager; function dynamicUpdate(a){var c=a instanceof Element,b=c&&"SPAN"==a.tagName&&"switch-left"==a.className,d=c&&"SPAN"==a.tagName&&"switch-both"==a.className,e=c&&"INPUT"==a.tagName&&"submit"==a.type,f=c&&"SPAN"==a.tagName&&("nav-mini"==a.parentNode.id||"nav-fiche"==a.parentNode.id),c=c&&"SPAN"==a.tagName&&"nav-contact"==a.parentNode.id;if(!(d||b||e||f||c)&&!0!==a)return!1;if(d)console.log("> switch firstname <-> lastname"),b=a.parentNode,a=b.children[3],b=b.children[5],d=a.value,a.value=b.value,b.value= d;else if(b){console.log("> switch firstname+lastname -> username");b=a.parentNode;d=b.children[1];a=b.children[3];b=b.children[5];if(0 dynamic update"),miniManager.fieldsToStorage(),ficheManager.fieldsToStorage(),contactManager.fieldsToStorage(),miniManager.sync(),ficheManager.sync(),miniManager.storageToFields(),ficheManager.storageToFields(),(e||c)&&contactManager.storageToFields()} function checkRadioValue(a){for(var c=0,b=0;b GATHERING ALL DATA");subjectManager.fieldsToStorage();contactManager.fieldsToStorage();miniManager.fieldsToStorage();ficheManager.fieldsToStorage();a={subject:lsi["export"]("subject"),contact:lsi["export"]("contacts"),mini:lsi["export"]("mini-fiches"),fiche:lsi["export"]("fiches")};console.log(a);api.send({path:"input/phone",data:a},function(a){console.log(a)}, +!1)},!1)})})})}); diff --git a/view/js/input.js b/view/js/input.js index 890ab68..7bfc5bc 100644 --- a/view/js/input.js +++ b/view/js/input.js @@ -7,8 +7,12 @@ /* [1] Initialisation des utilitaires et variables =========================================================*/ -/* (1) Bouton pour effacer toutes les données */ -var clearAllButton = $('#clear-all'); +/* (1) Boutons primaires */ + // {1} pour effacer toutes les données // + var clearAllButton = $('#clear-all'); + // {2} pour envoyer toutes les données // + var submitAllButton = $('#submit-all'); + /* (2) Input de type fichier pour l'import */ var importCallLog = $('input#call_log-import[type="file"]'); @@ -26,11 +30,11 @@ function dynamicUpdate(target){ /* (0) Vérification de la cohérence de la @target ---------------------------------------------------------*/ var isElement = target instanceof Element; - var isSwitchLeft = isElement && target.tagName == 'SPAN' && target.className == 'switch-left'; - var isSwitchBoth = isElement && target.tagName == 'SPAN' && target.className == 'switch-both'; - var isSaveButton = isElement && target.tagName == 'INPUT' && target.type == 'submit'; + var isSwitchLeft = isElement && target.tagName == 'SPAN' && target.className == 'switch-left'; + var isSwitchBoth = isElement && target.tagName == 'SPAN' && target.className == 'switch-both'; + var isSaveButton = isElement && target.tagName == 'INPUT' && target.type == 'submit'; var isNavButton = isElement && target.tagName == 'SPAN' && (target.parentNode.id == 'nav-mini' || target.parentNode.id == 'nav-fiche'); - var isNavContact = isElement && target.tagName == 'SPAN' && target.parentNode.id == 'nav-contact'; + var isNavContact = isElement && target.tagName == 'SPAN' && target.parentNode.id == 'nav-contact'; // Si erreur, on retourne une erreur if( !isSwitchBoth && !isSwitchLeft && !isSaveButton && !isNavButton && !isNavContact && target !== true ) @@ -274,6 +278,41 @@ include('/js/includes/input-phone-fiche.js', function(){ }, false); + /* (7) Gestion de la validation et de l'envoi des données + ---------------------------------------------------------*/ + submitAllButton.addEventListener('click', function(e){ + console.log('> GATHERING ALL DATA') + + /* (1) On met dans la mémoire tout les champs non enregistrés */ + subjectManager.fieldsToStorage(); + contactManager.fieldsToStorage(); + miniManager.fieldsToStorage(); + ficheManager.fieldsToStorage(); + + /* (2) On construit un objet qui contiendra toutes les données */ + var data = { + subject: lsi.export('subject'), + contact: lsi.export('contacts'), + mini: lsi.export('mini-fiches'), + fiche: lsi.export('fiches') + }; + console.log( data ); + + /* (3) On prépare la requête */ + var request = { + path: 'input/phone', + data: data + }; + + /* (4) On envoie la requête et traite la réponse */ + api.send(request, function(response){ + console.log(response); + }, false); + + + }, false); + + }) }) }) });