Gestion de la réponse de `call_log/unserialize` directement dans la réponse de `upload/call_log` pour économiser une requête.

This commit is contained in:
xdrm-brackets 2016-05-03 11:47:05 +02:00
parent 2c3cabec61
commit 97e7d5425b
8 changed files with 1201 additions and 182 deletions

View File

@ -81,7 +81,7 @@
// $request = new ModuleRequest('upload/local_data', array() ); // $request = new ModuleRequest('upload/local_data', array() );
// $response = $request->dispatch(); // $response = $request->dispatch();
// var_dump( ManagerError::explicit($response->error) ); // var_dump( ManagerError::explicit($response->error) );
// //
// } // }

View File

@ -207,7 +207,8 @@
"description": "Upload d'un journal d'appel au format .xml.", "description": "Upload d'un journal d'appel au format .xml.",
"permissions": ["admin"], "permissions": ["admin"],
"parameters": { "parameters": {
"file": { "description": "Fichier du journal d'appel.", "type": "FILE" } "phone_number": { "description": "Numéro de téléphone de l'interrogé.", "type": "number" },
"file": { "description": "Fichier du journal d'appel.", "type": "FILE" }
} }
}, },

View File

@ -123,10 +123,10 @@
/* [4] Gestion de la reponse /* [4] Gestion de la reponse
=========================================================*/ =========================================================*/
$answer = new ModuleResponse($this->error); $response = new ModuleResponse($this->error);
$answer->appendAll($returned); $response->appendAll($returned);
return $answer; return $response;
} }

View File

@ -21,6 +21,7 @@
public static function unserialize($params){ public static function unserialize($params){
extract($params); extract($params);
// On formatte le numéro de téléphone // On formatte le numéro de téléphone
$phone_number = Database::formatNumber($phone_number); $phone_number = Database::formatNumber($phone_number);

View File

@ -4,6 +4,7 @@
use \manager\Database; use \manager\Database;
use \manager\ResourceDispatcher; use \manager\ResourceDispatcher;
use \manager\sessionManager; use \manager\sessionManager;
use \manager\ModuleRequest;
use \manager\ManagerError; use \manager\ManagerError;
use \manager\Repo; use \manager\Repo;
@ -110,41 +111,58 @@
public static function call_log($params){ public static function call_log($params){
extract($params); extract($params);
return array( /* [1] Gestion de l'upload du fichier et de la vžérification du format
'ModuleError' => self::simpleFile( =========================================================*/
'call_log', // nom du dossier d'upload $uploadError = self::simpleFile(
'xml', // format du fichier 'call_log', // nom du dossier d'upload
$file, // Fichier lui-même 'xml', // format du fichier
function($content){ // Vérification du format du fichier $file, // Fichier lui-même
/* (1) Vérification du format XML */ function($content){ // Vérification du format du fichier
$xml = simplexml_load_string($content); /* (1) Vérification du format XML */
if( $xml === false ) return false; // Si erreur de parsage, on retourne une erreur $xml = simplexml_load_string($content);
if( $xml === false ) return false; // Si erreur de parsage, on retourne une erreur
/* (2) Vérification du contenu (balises) */ /* (2) Vérification du contenu (balises) */
// Doit avoir des Item(s) // Doit avoir des Item(s)
if( !isset($xml->Item) ) if( !isset($xml->Item) )
return false;
// Vérification de tous les champs
foreach($xml->Item as $log){
$checkAttributes = isset($log['Id']);
$checkAttributes = $checkAttributes && isset($log['Number']);
$checkAttributes = $checkAttributes && isset($log['Name']);
$checkAttributes = $checkAttributes && isset($log['Date']);
$checkAttributes = $checkAttributes && isset($log['Duration']);
$checkAttributes = $checkAttributes && isset($log['Direction']);
$checkAttributes = $checkAttributes && isset($log['Type']);
// Si on a pas tout les champs, on retourne une erreur
if( !$checkAttributes )
return false; return false;
// Vérification de tous les champs
foreach($xml->Item as $log){
$checkAttributes = isset($log['Id']);
$checkAttributes = $checkAttributes && isset($log['Number']);
$checkAttributes = $checkAttributes && isset($log['Name']);
$checkAttributes = $checkAttributes && isset($log['Date']);
$checkAttributes = $checkAttributes && isset($log['Duration']);
$checkAttributes = $checkAttributes && isset($log['Direction']);
$checkAttributes = $checkAttributes && isset($log['Type']);
// Si on a pas tout les champs, on retourne une erreur
if( !$checkAttributes )
return false;
}
/* (3) Si tout s'est bien passé, le format est bon */
return true;
} }
)
); /* (3) Si tout s'est bien passé, le format est bon */
return true;
}
);
/* [2] Gestion du retour (unserialize)
=========================================================*/
/* (1) Si erreur d'upload, on la renvoie */
if( $uploadError != ManagerError::Success )
return array( 'ModuleError' => $uploadError );
/* (2) Gestion du parsage (unserialize) du journal d'appel */
$request = new ModuleRequest('call_log/unserialize', array( 'phone_number' => $phone_number ) );
$response = $request->dispatch();
/* (3) Restitution du retour de `unserialize` */
return array_merge(
array( 'ModuleError' => $response->error ),
$response->getAll()
);
} }
@ -152,6 +170,16 @@
/* IMPORT D'UNE SAUVEGARDE DE FORMULAIRE LOCAL /* IMPORT D'UNE SAUVEGARDE DE FORMULAIRE LOCAL
* *
* @file<FILE> Pointeur vers $_FILES[''] * @file<FILE> Pointeur vers $_FILES['']
@ -160,106 +188,113 @@
public static function local_data($params){ public static function local_data($params){
extract($params); extract($params);
return array( /* [1] Upload et vérifiaction du format du fichier
'ModuleError' => self::simpleFile( =========================================================*/
'local_data', // nom du dossier d'upload $uploadError = self::simpleFile(
'json', // format du fichier 'local_data', // nom du dossier d'upload
$file, // Fichier lui-même 'json', // format du fichier
function($content){ // Vérification du format du fichier $file, // Fichier lui-même
/* (1) Vérification du format JSON */ function($content){ // Vérification du format du fichier
$json = json_decode($content, true); /* (1) Vérification du format JSON */
if( $json == null ) $json = json_decode($content, true);
return false; // Si erreur de parsage, on retourne une erreur if( $json == null )
return false; // Si erreur de parsage, on retourne une erreur
/* (2) Vérification du contenu de premier niveau */ /* (2) Vérification du contenu de premier niveau */
$checkLevel0 = isset($json['subject']) && is_array($json['subject']); $checkLevel0 = isset($json['subject']) && is_array($json['subject']);
$checkLevel0 = $checkLevel0 && isset($json['contacts']) && is_array($json['contacts']); $checkLevel0 = $checkLevel0 && isset($json['contacts']) && is_array($json['contacts']);
$checkLevel0 = $checkLevel0 && isset($json['mini']) && is_array($json['mini']); $checkLevel0 = $checkLevel0 && isset($json['mini']) && is_array($json['mini']);
$checkLevel0 = $checkLevel0 && isset($json['fiches']) && is_array($json['fiches']); $checkLevel0 = $checkLevel0 && isset($json['fiches']) && is_array($json['fiches']);
// Erreur si level 0 incorrect // Erreur si level 0 incorrect
if( !$checkLevel0 ) if( !$checkLevel0 )
return false;
/* (3) Vérification du sujet */
$checkSubject = isset($json['subject']['username']) && is_string($json['subject']['username']);
$checkSubject = $checkSubject && isset($json['subject']['firstname']) && is_string($json['subject']['firstname']);
$checkSubject = $checkSubject && isset($json['subject']['lastname']) && is_string($json['subject']['lastname']);
$checkSubject = $checkSubject && isset($json['subject']['number']) && is_string($json['subject']['number']);
// Erreur des attributs du sujet incorrects ou manquants
if( !$checkSubject )
return false;
/* (4) Vérification des contacts */
foreach($json['contacts'] as $contact){
$checkContact = isset($contact['username']) && is_string($contact['username']);
$checkContact = $checkContact && isset($contact['firstname']) && is_string($contact['firstname']);
$checkContact = $checkContact && isset($contact['lastname']) && is_string($contact['lastname']);
$checkContact = $checkContact && isset($contact['number']) && ( is_numeric($contact['number']) || is_string($contact['number']) );
// Si erreur des attributs du contact incorrects ou manquants
if( !$checkContact )
return false; return false;
/* (3) Vérification du sujet */
$checkSubject = isset($json['subject']['username']) && is_string($json['subject']['username']);
$checkSubject = $checkSubject && isset($json['subject']['firstname']) && is_string($json['subject']['firstname']);
$checkSubject = $checkSubject && isset($json['subject']['lastname']) && is_string($json['subject']['lastname']);
$checkSubject = $checkSubject && isset($json['subject']['number']) && is_string($json['subject']['number']);
// Erreur des attributs du sujet incorrects ou manquants
if( !$checkSubject )
return false;
/* (4) Vérification des contacts */
foreach($json['contacts'] as $contact){
$checkContact = isset($contact['username']) && is_string($contact['username']);
$checkContact = $checkContact && isset($contact['firstname']) && is_string($contact['firstname']);
$checkContact = $checkContact && isset($contact['lastname']) && is_string($contact['lastname']);
$checkContact = $checkContact && isset($contact['number']) && ( is_numeric($contact['number']) || is_string($contact['number']) );
// Si erreur des attributs du contact incorrects ou manquants
if( !$checkContact )
return false;
}
/* (5) Vérification des mini-fiches */
foreach($json['mini'] as $mini){
$checkMini = isset($mini['uid']) && is_numeric($mini['uid']);
$checkMini = $checkMini && isset($mini['username']) && is_string($mini['username']);
$checkMini = $checkMini && isset($mini['firstname']) && is_string($mini['firstname']);
$checkMini = $checkMini && isset($mini['lastname']) && is_string($mini['lastname']);
$checkMini = $checkMini && isset($mini['sexe']) && is_array($mini['sexe']);
$checkMini = $checkMini && isset($mini['age']) && is_string($mini['age']);
$checkMini = $checkMini && isset($mini['job']) && is_string($mini['job']);
$checkMini = $checkMini && isset($mini['loc']) && is_array($mini['loc']);
// Si erreur des attributs des mini-fiches incorrects ou manquants
if( !$checkMini )
return false;
}
/* (6) Vérification des fiches */
foreach($json['fiches'] as $fiches){
$checkFiche = isset($fiches['uid']) && is_numeric($fiches['uid']);
$checkFiche = $checkFiche && isset($fiches['username']) && is_string($fiches['username']);
$checkFiche = $checkFiche && isset($fiches['firstname']) && is_string($fiches['firstname']);
$checkFiche = $checkFiche && isset($fiches['lastname']) && is_string($fiches['lastname']);
$checkFiche = $checkFiche && isset($fiches['sexe']) && is_array($fiches['sexe']);
$checkFiche = $checkFiche && isset($fiches['age']) && is_string($fiches['age']);
$checkFiche = $checkFiche && isset($fiches['job']) && is_string($fiches['job']);
$checkFiche = $checkFiche && isset($fiches['loc']) && is_array($fiches['loc']);
$checkFiche = $checkFiche && isset($fiches['loc2']) && is_array($fiches['loc2']);
$checkFiche = $checkFiche && isset($fiches['studies']) && is_string($fiches['studies']);
$checkFiche = $checkFiche && isset($fiches['famsit']) && is_array($fiches['famsit']);
$checkFiche = $checkFiche && isset($fiches['reltype']) && is_array($fiches['reltype']);
$checkFiche = $checkFiche && isset($fiches['reltypeSpecial']) && is_string($fiches['reltypeSpecial']);
$checkFiche = $checkFiche && isset($fiches['city']) && is_string($fiches['city']);
$checkFiche = $checkFiche && isset($fiches['duration']) && is_array($fiches['duration']);
$checkFiche = $checkFiche && isset($fiches['context']) && is_array($fiches['context']);
$checkFiche = $checkFiche && isset($fiches['contextSpecial']) && is_array($fiches['contextSpecial']);
$checkFiche = $checkFiche && isset($fiches['freq']) && is_array($fiches['freq']);
$checkFiche = $checkFiche && isset($fiches['connect']) && is_array($fiches['connect']);
$checkFiche = $checkFiche && isset($fiches['connectSpecial']) && is_array($fiches['connectSpecial']);
// Si erreur des attributs des fiches incorrects ou manquants
if( !$checkFiche )
return false;
}
return true;
} }
)
);
/* (5) Vérification des mini-fiches */
foreach($json['mini'] as $mini){
$checkMini = isset($mini['uid']) && is_numeric($mini['uid']);
$checkMini = $checkMini && isset($mini['username']) && is_string($mini['username']);
$checkMini = $checkMini && isset($mini['firstname']) && is_string($mini['firstname']);
$checkMini = $checkMini && isset($mini['lastname']) && is_string($mini['lastname']);
$checkMini = $checkMini && isset($mini['sexe']) && is_array($mini['sexe']);
$checkMini = $checkMini && isset($mini['age']) && is_string($mini['age']);
$checkMini = $checkMini && isset($mini['job']) && is_string($mini['job']);
$checkMini = $checkMini && isset($mini['loc']) && is_array($mini['loc']);
// Si erreur des attributs des mini-fiches incorrects ou manquants
if( !$checkMini )
return false;
}
/* (6) Vérification des fiches */
foreach($json['fiches'] as $fiches){
$checkFiche = isset($fiches['uid']) && is_numeric($fiches['uid']);
$checkFiche = $checkFiche && isset($fiches['username']) && is_string($fiches['username']);
$checkFiche = $checkFiche && isset($fiches['firstname']) && is_string($fiches['firstname']);
$checkFiche = $checkFiche && isset($fiches['lastname']) && is_string($fiches['lastname']);
$checkFiche = $checkFiche && isset($fiches['sexe']) && is_array($fiches['sexe']);
$checkFiche = $checkFiche && isset($fiches['age']) && is_string($fiches['age']);
$checkFiche = $checkFiche && isset($fiches['job']) && is_string($fiches['job']);
$checkFiche = $checkFiche && isset($fiches['loc']) && is_array($fiches['loc']);
$checkFiche = $checkFiche && isset($fiches['loc2']) && is_array($fiches['loc2']);
$checkFiche = $checkFiche && isset($fiches['studies']) && is_string($fiches['studies']);
$checkFiche = $checkFiche && isset($fiches['famsit']) && is_array($fiches['famsit']);
$checkFiche = $checkFiche && isset($fiches['reltype']) && is_array($fiches['reltype']);
$checkFiche = $checkFiche && isset($fiches['reltypeSpecial']) && is_string($fiches['reltypeSpecial']);
$checkFiche = $checkFiche && isset($fiches['city']) && is_string($fiches['city']);
$checkFiche = $checkFiche && isset($fiches['duration']) && is_array($fiches['duration']);
$checkFiche = $checkFiche && isset($fiches['context']) && is_array($fiches['context']);
$checkFiche = $checkFiche && isset($fiches['contextSpecial']) && is_array($fiches['contextSpecial']);
$checkFiche = $checkFiche && isset($fiches['freq']) && is_array($fiches['freq']);
$checkFiche = $checkFiche && isset($fiches['connect']) && is_array($fiches['connect']);
$checkFiche = $checkFiche && isset($fiches['connectSpecial']) && is_array($fiches['connectSpecial']);
// Si erreur des attributs des fiches incorrects ou manquants
if( !$checkFiche )
return false;
}
return true;
}
);
/* [2] Renvoi du contenu du fichier
=========================================================*/
return array(
);
} }

1001
src/upload/call_log/xdrm.xml Executable file

File diff suppressed because it is too large Load Diff

15
view/js/input-min.js vendored
View File

@ -1,10 +1,9 @@
var clearAllButton=$("#clear-all"),submitAllButton=$("#submit-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 b=a instanceof Element,c=b&&"SPAN"==a.tagName&&"switch-left"==a.className,e=b&&"SPAN"==a.tagName&&"switch-both"==a.className,d=b&&"INPUT"==a.tagName&&"submit"==a.type,f=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(!(e||c||d||f||b)&&!0!==a)return!1;if(e)console.log("> switch firstname <-> lastname"),c=a.parentNode,a=c.children[3],c=c.children[5],e=a.value,a.value=c.value,c.value= 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=
e;else if(c){console.log("> switch firstname+lastname -> username");c=a.parentNode;e=c.children[1];a=c.children[3];c=c.children[5];if(0<e.value.length||0==a.value.length&&0==c.value.length)return!1;e.value=a.value+" "+c.value;a.value="";c.value=""}else console.log("> dynamic update"),miniManager.fieldsToStorage(),ficheManager.fieldsToStorage(),contactManager.fieldsToStorage(),miniManager.sync(),ficheManager.sync(),miniManager.storageToFields(),ficheManager.storageToFields(),(d||b)&&contactManager.storageToFields()} 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<d.value.length||0==a.value.length&&0==b.value.length)return!1;d.value=a.value+" "+b.value;a.value="";b.value=""}else console.log("> 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 b=0,c=0;c<a.length;c++)!0===a[c].status&&b++;return 1!=b?!1:!0} function checkRadioValue(a){for(var c=0,b=0;b<a.length;b++)!0===a[b].status&&c++;return 1!=c?!1:!0}
include("/js/includes/input-phone-subject.js",function(){include("/js/includes/input-phone-contact.js",function(){include("/js/includes/input-phone-mini.js",function(){include("/js/includes/input-phone-fiche.js",function(){subjectManager=new inputPhoneSubject($('article.subject-panel [data-name="number"]'),$('article.subject-panel [data-name="username"]'),$('article.subject-panel [data-name="firstname"]'),$('article.subject-panel [data-name="lastname"]'),$('article.subject-panel [data-name="submit"]')); include("/js/includes/input-phone-subject.js",function(){include("/js/includes/input-phone-contact.js",function(){include("/js/includes/input-phone-mini.js",function(){include("/js/includes/input-phone-fiche.js",function(){subjectManager=new inputPhoneSubject($('article.subject-panel [data-name="number"]'),$('article.subject-panel [data-name="username"]'),$('article.subject-panel [data-name="firstname"]'),$('article.subject-panel [data-name="lastname"]'),$('article.subject-panel [data-name="submit"]'));
subjectManager.attach();contactManager=new inputPhoneContact($("article.contact-panel"),$("#nav-contact"));contactManager.attach(dynamicUpdate);miniManager=new inputPhoneMini($("article.mini-relation-panel"),$("#nav-mini"));miniManager.attach(dynamicUpdate);ficheManager=new inputPhoneFiche($("article.relation-panel"),$("#nav-fiche"));ficheManager.attach(dynamicUpdate);importCallLog.addEventListener("change",function(a){console.log(importCallLog.files[0]);api.send({path:"upload/call_log",file:importCallLog.files[0]}, subjectManager.attach();contactManager=new inputPhoneContact($("article.contact-panel"),$("#nav-contact"));contactManager.attach(dynamicUpdate);miniManager=new inputPhoneMini($("article.mini-relation-panel"),$("#nav-mini"));miniManager.attach(dynamicUpdate);ficheManager=new inputPhoneFiche($("article.relation-panel"),$("#nav-fiche"));ficheManager.attach(dynamicUpdate);importCallLog.addEventListener("change",function(a){a={path:"upload/call_log",phone_number:$("#subject_phone_number").value,file:importCallLog.files[0]};
function(a){console.log(a);0==a.ModuleError&&(importCallLog.addClass("active"),a={path:"call_log/unserialize",phone_number:$("#subject_phone_number").value},api.send(a,function(a){console.log(a);if(0==a.ModuleError){for(var b=0;b<a.directory.length;b++){var d=(null===a.directory[b].name?"":a.directory[b].name).split(" ");lsi.set("contacts",b,{uid:b,number:a.directory[b].number,username:1==d.length?d[0]:"",firstname:1<d.length?d[0]:"",lastname:1<d.length?d.splice(1).join(" "):""})}contactManager.storageToFields(); api.send(a,function(a){console.log(a);if(0==a.ModuleError){for(var b=0;b<a.directory.length;b++){var d=(null===a.directory[b].name?"":a.directory[b].name).split(" ");lsi.set("contacts",b,{uid:b,number:a.directory[b].number,username:1==d.length?d[0]:"",firstname:1<d.length?d[0]:"",lastname:1<d.length?d.splice(1).join(" "):""})}contactManager.storageToFields();dynamicUpdate(!0)}})},!1);clearAllButton.addEventListener("click",function(a){localStorage.clear();reload()},!1);$("#export-all").addEventListener("click",
dynamicUpdate(!0)}}))})},!1);clearAllButton.addEventListener("click",function(a){localStorage.clear();reload()},!1);$("#export-all").addEventListener("click",function(a){a={subject:lsi["export"]("subject")[0],contacts:lsi["export"]("contacts"),mini:lsi["export"]("mini-fiches"),fiches:lsi["export"]("fiches")};var b=$("#download-target");b.download="local-data.json";b.href="data:application/octet-stream,"+encodeURIComponent(JSON.stringify(a));b.click()},!1);$("#import-all").addEventListener("click", function(a){a={subject:lsi["export"]("subject")[0],contacts:lsi["export"]("contacts"),mini:lsi["export"]("mini-fiches"),fiches:lsi["export"]("fiches")};var c=$("#download-target");c.download="local-data.json";c.href="data:application/octet-stream,"+encodeURIComponent(JSON.stringify(a));c.click()},!1);$("#import-all").addEventListener("click",function(a){$("#local-upload").click()},!1);$("#local-upload").addEventListener("change",function(a){a={path:"upload/local_data",file:$("#local-upload").files[0]};
function(a){$("#local-upload").click()},!1);$("#local-upload").addEventListener("change",function(a){a={path:"upload/local_data",file:$("#local-upload").files[0]};api.send(a,function(a){console.log(a)})},!1);submitAllButton.addEventListener("click",function(a){console.log("> GATHERING ALL DATA");subjectManager.fieldsToStorage();contactManager.fieldsToStorage();miniManager.fieldsToStorage();ficheManager.fieldsToStorage();a={path:"input/phone",subject:lsi["export"]("subject")[0],contacts:lsi["export"]("contacts"), api.send(a,function(a){console.log(a)})},!1);submitAllButton.addEventListener("click",function(a){console.log("> GATHERING ALL DATA");subjectManager.fieldsToStorage();contactManager.fieldsToStorage();miniManager.fieldsToStorage();ficheManager.fieldsToStorage();a={path:"input/phone",subject:lsi["export"]("subject")[0],contacts:lsi["export"]("contacts"),mini:lsi["export"]("mini-fiches"),fiches:lsi["export"]("fiches")};api.send(a,function(a){console.log(a)},!1)},!1)})})})});
mini:lsi["export"]("mini-fiches"),fiches:lsi["export"]("fiches")};api.send(a,function(a){console.log(a)},!1)},!1)})})})});

View File

@ -214,59 +214,41 @@ include('/js/includes/input-phone-fiche.js', function(){
/* (5) Gestion de l'import du fichier /* (5) Gestion de l'import du fichier
---------------------------------------------------------*/ ---------------------------------------------------------*/
importCallLog.addEventListener('change', function(e){ importCallLog.addEventListener('change', function(e){
console.log( importCallLog.files[0] );
/* (1) On rédige la requête */ /* (1) On rédige la requête */
var uploadRequest = { var request = {
path: 'upload/call_log', path: 'upload/call_log',
file: importCallLog.files[0] phone_number: $('#subject_phone_number').value,
file: importCallLog.files[0]
}; };
/* (2) On effectue l'upload (import) */ /* (2) On effectue l'upload (import) */
api.send(uploadRequest, function(uploadResponse){ api.send(request, function(response){
console.log(uploadResponse); console.log(response);
// Si tout est bon, on met l'input en bleu // Si erreur, on quitte
if( uploadResponse.ModuleError == 0 ){ if( response.ModuleError != 0 )
importCallLog.addClass('active'); return;
/* (3) On rédige la requête pour récupérer les données du fichier */ /* (3) Pour chaque contact de l'annuaire, on ajoute un contact */
var callLogRequest = { for( var i = 0 ; i < response.directory.length ; i++ ){
path: 'call_log/unserialize',
phone_number: $('#subject_phone_number').value
};
/* (4) On effectue la récupération d'informations */ // On découpe le nom par espaces
api.send(callLogRequest, function(dataResponse){ var name = response.directory[i].name===null ? '' : response.directory[i].name;
console.log(dataResponse); var splitted = name.split(' ');
// Si erreur, on quitte lsi.set('contacts', i, {
if( dataResponse.ModuleError != 0 ) uid: i,
return; number: response.directory[i].number,
username: splitted.length == 1 ? splitted[0] : '', // Si un seul mot -> pseudo
firstname: splitted.length > 1 ? splitted[0] : '', // Si plusieurs mots -> le 1er est le prénom
lastname: splitted.length > 1 ? splitted.splice(1).join(' ') : '' // et les autres sont le nom
/* (5) Pour chaque contact de l'annuaire, on ajoute un contact */
for( var i = 0 ; i < dataResponse.directory.length ; i++ ){
// On découpe le nom par espaces
var name = dataResponse.directory[i].name===null ? '' : dataResponse.directory[i].name;
var splitted = name.split(' ');
lsi.set('contacts', i, {
uid: i,
number: dataResponse.directory[i].number,
username: splitted.length == 1 ? splitted[0] : '', // Si un seul mot -> pseudo
firstname: splitted.length > 1 ? splitted[0] : '', // Si plusieurs mots -> le 1er est le prénom
lastname: splitted.length > 1 ? splitted.splice(1).join(' ') : '' // et les autres sont le nom
});
}
/* (6) On met à jour l'affichage */
contactManager.storageToFields();
dynamicUpdate(true);
}); });
} }
/* (6) On met à jour l'affichage */
contactManager.storageToFields();
dynamicUpdate(true);
}); });
}, false); }, false);