2016-05-09 18:04:23 +00:00
var subjectManager , contactManager , miniManager , ficheManager , matriceManager ;
2016-05-10 14:51:09 +00:00
function dynamicUpdate ( a ) { var e = a instanceof Element , c = e && "SPAN" == a . tagName && "switch-left" == a . className , f = e && "SPAN" == a . tagName && "switch-both" == a . className , b = e && "INPUT" == a . tagName && "submit" == a . type , d = e && "SPAN" == a . tagName && ( "nav-mini" == a . parentNode . id || "nav-fiche" == a . parentNode . id ) , e = e && "SPAN" == a . tagName && "nav-contact" == a . parentNode . id ; if ( ! ( f || c || b || d || e ) && ! 0 !== a ) return ! 1 ; if ( f ) console . log ( "> switch firstname <-> lastname" ) , c = a . parentNode , a = c . children [ 8 ] , c = c . children [ 10 ] , f = a . value , a . value = c . value , c . value =
f ; else if ( c ) { console . log ( "> switch firstname+lastname -> username" ) ; c = a . parentNode ; f = c . children [ 6 ] ; a = c . children [ 8 ] ; c = c . children [ 10 ] ; if ( 0 < f . value . length || 0 == a . value . length && 0 == c . value . length ) return ! 1 ; f . value = a . value + " " + c . value ; a . value = "" ; c . value = "" } else console . log ( "> dynamic update" ) , miniManager . fieldsToStorage ( ) , ficheManager . fieldsToStorage ( ) , contactManager . fieldsToStorage ( ) , matriceManager . fieldsToStorage ( ) , miniManager . sync ( ) , ficheManager . sync ( ) , miniManager . storageToFields ( ) , ficheManager . storageToFields ( ) ,
matriceManager . storageToFields ( ) , ( b || e ) && contactManager . storageToFields ( ) }
2016-05-08 16:31:58 +00:00
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 ( ) { include ( "/js/includes/input-phone-matrice.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"]' ) ,
2016-05-08 17:11:03 +00:00
$ ( '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 ) ; matriceManager = new inputPhoneMatrice ( $ ( "article.matrice-panel" ) ) ; matriceManager . attach ( dynamicUpdate ) ;
2016-05-10 14:51:09 +00:00
$ ( 'input#call_log-import[type="file"]' ) . addEventListener ( "click" , function ( a ) { a . target . value = null } , ! 1 ) ; $ ( 'input#call_log-import[type="file"]' ) . addEventListener ( "change" , function ( a ) { a = { path : "upload/call_log" , phone _number : $ ( "#subject_phone_number" ) . value , file : a . target . files [ 0 ] } ; api . send ( a , function ( a ) { console . log ( a ) ; if ( 0 == a . ModuleError ) { for ( var c = 0 , f = [ ] , b = 0 ; b < a . calls . length && 10 > b ; b ++ ) f . push ( a . calls [ b ] . number ) ; for ( b = 0 ; b < f . length ; b ++ ) { var d = a . directory [ f [ b ] ] . name . split ( " " ) ; lsi . set ( "contacts" , c , { uid : c ,
number : f [ b ] , username : 1 == d . length ? d [ 0 ] : "" , firstname : 1 < d . length ? d [ 0 ] : "" , lastname : 1 < d . length ? d . splice ( 1 ) . join ( " " ) : "" , countsms : a . directory [ f [ b ] ] . sms , countcall : a . directory [ f [ b ] ] . calls , call : b , sms : - 1 } ) ; c ++ } for ( var g = [ ] , b = 0 ; b < a . sms . length && 10 > b ; b ++ ) g . push ( a . sms [ b ] . number ) ; for ( b = 0 ; b < g . length ; b ++ ) if ( d = f . indexOf ( g [ b ] ) , - 1 < d ) { var k = lsi . get ( "contacts" , d ) ; k . sms = b ; lsi . set ( "contacts" , d , k ) } else d = a . directory [ g [ b ] ] . name . split ( " " ) , lsi . set ( "contacts" , c , { uid : c , number : g [ b ] , username : 1 == d . length ? d [ 0 ] : "" , firstname : 1 < d . length ?
d [ 0 ] : "" , lastname : 1 < d . length ? d . splice ( 1 ) . join ( " " ) : "" , countsms : a . directory [ g [ b ] ] . sms , countcall : a . directory [ g [ b ] ] . calls , call : - 1 , sms : b } ) , c ++ ; for ( var h in a . directory ) - 1 < f . indexOf ( h ) || - 1 < g . indexOf ( h ) || ( d = ( null === a . directory [ h ] . name ? "" : a . directory [ h ] . name ) . split ( " " ) , lsi . set ( "contacts" , c , { uid : c , number : h , username : 1 == d . length ? d [ 0 ] : "" , firstname : 1 < d . length ? d [ 0 ] : "" , lastname : 1 < d . length ? d . splice ( 1 ) . join ( " " ) : "" , countsms : a . directory [ h ] . sms , countcall : a . directory [ h ] . calls , call : - 1 , sms : - 1 } ) , c ++ ) ; contactManager . storageToFields ( ) ;
2016-05-09 07:34:17 +00:00
dynamicUpdate ( ! 0 ) } } ) } , ! 1 ) ; $ ( "#clear-all" ) . addEventListener ( "click" , function ( a ) { lsi . clear ( "subject" ) ; lsi . clear ( "contacts" ) ; lsi . clear ( "mini-fiches" ) ; lsi . clear ( "fiches" ) ; lsi . clear ( "matrice" ) ; subjectManager . storageToFields ( ) ; contactManager . storageToFields ( ) ; miniManager . storageToFields ( ) ; ficheManager . storageToFields ( ) ; matriceManager . storageToFields ( ) } , ! 1 ) ; $ ( "#export-all" ) . addEventListener ( "click" , function ( a ) { a = { subject : lsi [ "export" ] ( "subject" ) [ 0 ] , contacts : lsi [ "export" ] ( "contacts" ) , mini : lsi [ "export" ] ( "mini-fiches" ) ,
2016-05-10 14:51:09 +00:00
fiches : lsi [ "export" ] ( "fiches" ) , matrice : lsi [ "export" ] ( "matrice" ) [ 0 ] } ; var e = $ ( "#download-target" ) ; e . download = "local-data.json" ; e . href = "data:application/octet-stream," + encodeURIComponent ( JSON . stringify ( a ) ) ; e . click ( ) } , ! 1 ) ; $ ( "#import-all" ) . addEventListener ( "click" , function ( a ) { $ ( "#local-upload" ) . click ( ) } , ! 1 ) ; $ ( "#local-upload" ) . addEventListener ( "click" , function ( a ) { a . target . value = null } , ! 1 ) ; $ ( "#local-upload" ) . addEventListener ( "change" , function ( a ) { a = { path : "upload/local_data" , file : $ ( "#local-upload" ) . files [ 0 ] } ;
2016-05-09 07:34:17 +00:00
api . send ( a , function ( a ) { console . log ( a ) ; if ( 0 != a . ModuleError ) return ! 1 ; console . log ( a . local _data . matrice ) ; lsi . set ( "subject" , 0 , a . local _data . subject ) ; lsi [ "import" ] ( "contacts" , a . local _data . contacts ) ; lsi [ "import" ] ( "mini-fiches" , a . local _data . mini ) ; lsi [ "import" ] ( "fiches" , a . local _data . fiches ) ; lsi . set ( "matrice" , 0 , a . local _data . matrice ) ; subjectManager . storageToFields ( ) ; contactManager . storageToFields ( ) ; matriceManager . storageToFields ( ) ; dynamicUpdate ( ! 0 ) } ) } , ! 1 ) ; $ ( "#submit-all" ) . addEventListener ( "click" , function ( a ) { console . log ( "> GATHERING ALL DATA" ) ;
2016-05-10 14:51:09 +00:00
subjectManager . fieldsToStorage ( ) ; contactManager . fieldsToStorage ( ) ; miniManager . fieldsToStorage ( ) ; ficheManager . fieldsToStorage ( ) ; if ( ! subjectManager . check ( ) ) return ! 1 ; a = lsi [ "export" ] ( "mini-fiches" ) ; for ( var e in a ) if ( ! a [ e ] . valid ) return ! 1 ; a = lsi [ "export" ] ( "fiches" ) ; for ( e in a ) if ( ! a [ e ] . valid ) return ! 1 ; e = { path : "input/phone" , subject : lsi [ "export" ] ( "subject" ) [ 0 ] , contacts : lsi [ "export" ] ( "contacts" ) , mini : lsi [ "export" ] ( "mini-fiches" ) , fiches : lsi [ "export" ] ( "fiches" ) , matrice : lsi [ "export" ] ( "matrice" ) [ 0 ] } ; api . send ( e , function ( a ) { console . log ( a ) } ,
! 1 ) } , ! 1 ) } ) } ) } ) } ) } ) ;