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:
parent
2c3cabec61
commit
97e7d5425b
|
@ -207,6 +207,7 @@
|
|||
"description": "Upload d'un journal d'appel au format .xml.",
|
||||
"permissions": ["admin"],
|
||||
"parameters": {
|
||||
"phone_number": { "description": "Numéro de téléphone de l'interrogé.", "type": "number" },
|
||||
"file": { "description": "Fichier du journal d'appel.", "type": "FILE" }
|
||||
}
|
||||
},
|
||||
|
|
|
@ -123,10 +123,10 @@
|
|||
|
||||
/* [4] Gestion de la reponse
|
||||
=========================================================*/
|
||||
$answer = new ModuleResponse($this->error);
|
||||
$answer->appendAll($returned);
|
||||
$response = new ModuleResponse($this->error);
|
||||
$response->appendAll($returned);
|
||||
|
||||
return $answer;
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
public static function unserialize($params){
|
||||
extract($params);
|
||||
|
||||
|
||||
// On formatte le numéro de téléphone
|
||||
$phone_number = Database::formatNumber($phone_number);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
use \manager\Database;
|
||||
use \manager\ResourceDispatcher;
|
||||
use \manager\sessionManager;
|
||||
use \manager\ModuleRequest;
|
||||
use \manager\ManagerError;
|
||||
use \manager\Repo;
|
||||
|
||||
|
@ -110,8 +111,9 @@
|
|||
public static function call_log($params){
|
||||
extract($params);
|
||||
|
||||
return array(
|
||||
'ModuleError' => self::simpleFile(
|
||||
/* [1] Gestion de l'upload du fichier et de la vérification du format
|
||||
=========================================================*/
|
||||
$uploadError = self::simpleFile(
|
||||
'call_log', // nom du dossier d'upload
|
||||
'xml', // format du fichier
|
||||
$file, // Fichier lui-même
|
||||
|
@ -143,7 +145,23 @@
|
|||
/* (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
|
||||
*
|
||||
* @file<FILE> Pointeur vers $_FILES['']
|
||||
|
@ -160,8 +188,9 @@
|
|||
public static function local_data($params){
|
||||
extract($params);
|
||||
|
||||
return array(
|
||||
'ModuleError' => self::simpleFile(
|
||||
/* [1] Upload et vérifiaction du format du fichier
|
||||
=========================================================*/
|
||||
$uploadError = self::simpleFile(
|
||||
'local_data', // nom du dossier d'upload
|
||||
'json', // format du fichier
|
||||
$file, // Fichier lui-même
|
||||
|
@ -258,7 +287,13 @@
|
|||
|
||||
return true;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
/* [2] Renvoi du contenu du fichier
|
||||
=========================================================*/
|
||||
return array(
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,10 +1,9 @@
|
|||
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=
|
||||
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()}
|
||||
function checkRadioValue(a){for(var b=0,c=0;c<a.length;c++)!0===a[c].status&&b++;return 1!=b?!1:!0}
|
||||
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<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 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"]'));
|
||||
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]},
|
||||
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();
|
||||
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){$("#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"),
|
||||
mini:lsi["export"]("mini-fiches"),fiches:lsi["export"]("fiches")};api.send(a,function(a){console.log(a)},!1)},!1)})})})});
|
||||
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]};
|
||||
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",
|
||||
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]};
|
||||
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)})})})});
|
||||
|
|
|
@ -214,47 +214,31 @@ include('/js/includes/input-phone-fiche.js', function(){
|
|||
/* (5) Gestion de l'import du fichier
|
||||
---------------------------------------------------------*/
|
||||
importCallLog.addEventListener('change', function(e){
|
||||
console.log( importCallLog.files[0] );
|
||||
/* (1) On rédige la requête */
|
||||
var uploadRequest = {
|
||||
var request = {
|
||||
path: 'upload/call_log',
|
||||
phone_number: $('#subject_phone_number').value,
|
||||
file: importCallLog.files[0]
|
||||
};
|
||||
|
||||
/* (2) On effectue l'upload (import) */
|
||||
api.send(uploadRequest, function(uploadResponse){
|
||||
console.log(uploadResponse);
|
||||
|
||||
// Si tout est bon, on met l'input en bleu
|
||||
if( uploadResponse.ModuleError == 0 ){
|
||||
importCallLog.addClass('active');
|
||||
|
||||
/* (3) On rédige la requête pour récupérer les données du fichier */
|
||||
var callLogRequest = {
|
||||
path: 'call_log/unserialize',
|
||||
phone_number: $('#subject_phone_number').value
|
||||
};
|
||||
|
||||
/* (4) On effectue la récupération d'informations */
|
||||
api.send(callLogRequest, function(dataResponse){
|
||||
console.log(dataResponse);
|
||||
api.send(request, function(response){
|
||||
console.log(response);
|
||||
|
||||
// Si erreur, on quitte
|
||||
if( dataResponse.ModuleError != 0 )
|
||||
if( response.ModuleError != 0 )
|
||||
return;
|
||||
|
||||
|
||||
|
||||
/* (5) Pour chaque contact de l'annuaire, on ajoute un contact */
|
||||
for( var i = 0 ; i < dataResponse.directory.length ; i++ ){
|
||||
/* (3) Pour chaque contact de l'annuaire, on ajoute un contact */
|
||||
for( var i = 0 ; i < response.directory.length ; i++ ){
|
||||
|
||||
// On découpe le nom par espaces
|
||||
var name = dataResponse.directory[i].name===null ? '' : dataResponse.directory[i].name;
|
||||
var name = response.directory[i].name===null ? '' : response.directory[i].name;
|
||||
var splitted = name.split(' ');
|
||||
|
||||
lsi.set('contacts', i, {
|
||||
uid: i,
|
||||
number: dataResponse.directory[i].number,
|
||||
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
|
||||
|
@ -264,8 +248,6 @@ include('/js/includes/input-phone-fiche.js', function(){
|
|||
/* (6) On met à jour l'affichage */
|
||||
contactManager.storageToFields();
|
||||
dynamicUpdate(true);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue