2016-04-22 17:35:05 +00:00
function updateListener ( a , b , c ) { a . removeEventListener ( b , c ) ; a . addEventListener ( b , c ) }
2016-04-25 14:18:50 +00:00
var ic = new inputChecker , FormDeflaterP = { tags : [ "input" ] , attr : [ "data-name" ] } , importCallLog = $ ( 'input#call_log-import[type="file"]' ) , addContact = $ ( "h4.add-contact" ) , contactContainer = $ ( "article.contact-panel" ) , addFiche = $ ( "h4.add-mini-fiche" ) , miniFicheContainer = $ ( "article.mini-relation-panel" ) , addFiche = $ ( "h4.add-fiche" ) , ficheContainer = $ ( "article.relation-panel" ) , subjectInput = { number : $ ( 'article.subject-panel [data-name="number"]' ) , username : $ ( 'article.subject-panel [data-name="username"]' ) , firstname : $ ( 'article.subject-panel [data-name="firstname"]' ) ,
lastname : $ ( 'article.subject-panel [data-name="lastname"]' ) , store : $ ( 'article.subject-panel [data-name="submit"]' ) } ; lsi . createDataset ( "subject" ) ;
2016-04-22 17:35:05 +00:00
function storeSubject ( ) { console . log ( "storing subject" ) ; var a = 0 < subjectInput . number . value . length , a = a && 0 < subjectInput . username . value . length + subjectInput . firstname . value . length + subjectInput . lastname . value . length ; if ( ! a ) return ! 1 ; lsi . set ( "subject" , "form" , { number : subjectInput . number . value , username : subjectInput . username . value , firstname : subjectInput . firstname . value , lastname : subjectInput . lastname . value } ) }
2016-04-25 14:18:50 +00:00
function restoreSubject ( ) { var a = lsi . get ( "subject" , "form" ) ; console . log ( a ) ; null != a && ( subjectInput . number . value = a . number , subjectInput . username . value = a . username , subjectInput . firstname . value = a . firstname , subjectInput . lastname . value = a . lastname ) } restoreSubject ( ) ; subjectInput . store . addEventListener ( "click" , storeSubject , ! 1 ) ; lsi . createDataset ( "contacts" ) ;
2016-04-22 17:35:05 +00:00
function storeContacts ( ) { console . log ( "storing all forms" ) ; for ( var a = $$ ( "article.contact-panel .new-contact" ) , b = 0 ; b < a . length ; b ++ ) { var c = a [ b ] . parentNode . children . indexOf ( a [ b ] ) , d = ( new FormDeflater ( a [ b ] , [ "input" ] , [ "data-name" ] ) ) . deflate ( ) , e = 0 < d . number . value . length ; ( e = e && 0 < d . username . value . length + d . firstname . value . length + d . lastname . value . length ) && lsi . set ( "contacts" , "form" + c , { number : d . number . value , username : d . username . value , firstname : d . firstname . value , lastname : d . lastname . value } ) } restoreContacts ( ) }
function addNewContact ( a , b , c , d ) { contactContainer . innerHTML += contactBuilder . build ( { number : "string" != typeof a ? "" : a , username : "string" != typeof b ? "" : b , firstname : "string" != typeof c ? "" : c , lastname : "string" != typeof d ? "" : d } ) ; a = $$ ( 'article.contact-panel .new-contact input[type="submit"]' ) ; for ( b = 0 ; b < a . length ; b ++ ) updateListener ( a [ b ] , "click" , storeContacts ) }
2016-04-25 14:18:50 +00:00
function restoreContacts ( ) { var a = lsi . keys ( "contacts" ) ; contactContainer . innerHTML = "" ; for ( var b = 0 ; b < a . length ; b ++ ) { var c = lsi . get ( "contacts" , a [ b ] ) ; addNewContact ( c . number , c . username , c . firstname , c . lastname ) } addNewContact ( ) ; a = $$ ( 'article.contact-panel .new-contact input[type="submit"]' ) ; for ( b = 0 ; b < a . length ; b ++ ) updateListener ( a [ b ] , "click" , storeContacts ) } restoreContacts ( ) ; addContact . addEventListener ( "click" , storeContacts , ! 1 ) ; var miniFicheUID = 0 ;
function addNewMiniFiche ( a , b , c ) { miniFicheContainer . innerHTML += miniFicheBuilder . build ( { firstname : "string" != typeof a ? "" : a , lastname : "string" != typeof b ? "" : b , username : "string" != typeof c ? "" : c , uid : miniFicheUID } ) ; miniFicheUID ++ } importCallLog . addEventListener ( "change" , function ( a ) { api . send ( { path : "upload/call_log" , file : importCallLog . files [ 0 ] } , function ( a ) { console . log ( a ) ; 0 == a . ModuleError && importCallLog . addClass ( "active" ) } ) } , ! 1 ) ;