2016-05-10 06:22:29 +00:00
function inputPhoneFiche ( a , b ) { this . container = a ; this . nav _container = b } inputPhoneFiche . prototype = { container : this . container , nav _container : this . nav _container , selected : 0 , handler : null , defaultData : { sexe : "H" , age : "." , job : "." , famsit : "0" , studies : "." , reltype : "0" , reltypeSpecial : "" , city : "" , loc : "0" , duration : [ "" , "" ] , context : "0" , contextSpecial : [ "" , "" , "" ] , freq : [ "0" , "4" , "8" , "12" , "16" ] , connect : "1 3 5 7 9 11" . split ( " " ) , connectSpecial : [ "" , "" ] , timestamp : 0 , valid : ! 1 } } ;
2016-05-09 18:04:23 +00:00
inputPhoneFiche . prototype . fieldsToStorage = function ( ) { console . log ( "FICHE: FIELDS TO STORAGE" ) ; for ( var a = $$ ( "article.relation-panel .fiche-relation" ) , b = 0 ; b < a . length ; b ++ ) { var c = ( new FormDeflater ( a [ b ] , [ "input" , "select" ] , [ "data-name" ] ) ) . deflate ( ) , f = crc32 ( JSON . stringify ( c ) ) , d = lsi . get ( "fiches" , c . uid ) ; if ( ! 1 !== d ) { if ( null != d . hash && d . hash == f ) break ; c = { contact : parseInt ( c . contact ) , uid : parseInt ( c . uid ) , sexe : c . sexe , age : c . age , job : c . job , famsit : c . famsit , studies : c . studies , reltype : c . reltype , reltypeSpecial : c . reltypeSpecial ,
city : c . city , loc : c . loc , duration : c . duration , context : c . context , contextSpecial : c . contextSpecial , freq : c . freq , connect : c . connect , connectSpecial : c . connectSpecial , hash : f } ; c . valid = this . check ( c ) ; 0 < diff ( d , c , [ "hash" , "valid" , "timestamp" ] ) . length && ( console . log ( diff ( d , c , [ "hash" , "valid" , "timestamp" ] ) ) , console . warn ( "> FICHE UPDATE" ) , c . timestamp = Date . now ( ) ) ; lsi . set ( "fiches" , c . uid , c ) } } } ;
2016-05-08 13:25:20 +00:00
inputPhoneFiche . prototype . add = function ( a ) { console . log ( "FICHE: ADD" ) ; if ( null == a . uid || null == a . contact ) return ! 1 ; a . city = null != a . city ? a . city : this . defaultData . city ; a . duration [ 0 ] = null != a . duration [ 0 ] ? a . duration [ 0 ] : this . defaultData . duration [ 0 ] ; a . duration [ 1 ] = null != a . duration [ 1 ] ? a . duration [ 1 ] : this . defaultData . duration [ 1 ] ; a . reltypeSpecial = null != a . reltypeSpecial ? a . reltypeSpecial : this . defaultData . reltypeSpecial ; a . contextSpecial [ 0 ] = null != a . contextSpecial [ 0 ] ? a . contextSpecial [ 0 ] : this . defaultData . contextSpecial [ 0 ] ;
a . contextSpecial [ 1 ] = null != a . contextSpecial [ 1 ] ? a . contextSpecial [ 1 ] : this . defaultData . contextSpecial [ 1 ] ; a . contextSpecial [ 2 ] = null != a . contextSpecial [ 2 ] ? a . contextSpecial [ 2 ] : this . defaultData . contextSpecial [ 2 ] ; a . connectSpecial [ 0 ] = null != a . connectSpecial [ 0 ] ? a . connectSpecial [ 0 ] : this . defaultData . connectSpecial [ 0 ] ; a . connectSpecial [ 1 ] = null != a . connectSpecial [ 1 ] ? a . connectSpecial [ 1 ] : this . defaultData . connectSpecial [ 1 ] ; a . job = null != a . job ? a . job : this . defaultData . job ; a . studies = null != a . studies ? a . studies : this . defaultData . studies ;
a . age = null != a . age ? a . age : this . defaultData . age ; a . sexe = null != a . sexe ? a . sexe : this . defaultData . sexe ; a . famsit = null != a . famsit ? a . famsit : this . defaultData . famsit ; a . reltype = null != a . reltype ? a . reltype : this . defaultData . reltype ; a . loc = null != a . loc ? a . loc : this . defaultData . loc ; a . context = null != a . context ? a . context : this . defaultData . context ; a . freq = null != a . freq ? a . freq : this . defaultData . freq ; a . connect = null != a . connect ? a . connect : this . defaultData . connect ; var b = lsi . get ( "contacts" , a . contact ) ; if ( ! 1 === b ) return ! 1 ; this . container . innerHTML +=
ficheBuilder . build ( { firstname : b . firstname , lastname : b . lastname , username : 0 == b . username . length ? "" : "(" + b . username + ")" , countcall : b . countcall , countsms : b . countsms , uid : a . uid , contact : a . contact , city : a . city , duration0 : a . duration [ 0 ] , duration1 : a . duration [ 1 ] , reltypespecial : a . reltypeSpecial , contextspecial0 : a . contextSpecial [ 0 ] , contextspecial1 : a . contextSpecial [ 1 ] , contextspecial2 : a . contextSpecial [ 2 ] , connectspecial0 : a . connectSpecial [ 0 ] , connectspecial1 : a . connectSpecial [ 1 ] } ) ; b = $ ( 'article.fiche-relation input[data-name="uid"][value="' +
a . uid + '"] ~ h5>span>select[data-name="job"]>option[value="' + a . job + '"]' ) ; null != b && b . setAttribute ( "selected" , "selected" ) ; b = $ ( 'article.fiche-relation input[data-name="uid"][value="' + a . uid + '"] ~ h5>span>select[data-name="studies"]>option[value="' + a . studies + '"]' ) ; null != b && b . setAttribute ( "selected" , "selected" ) ; b = $ ( 'article.fiche-relation input[data-name="uid"][value="' + a . uid + '"] ~ h5>span>select[data-name="age"]>option[value="' + a . age + '"]' ) ; null != b && b . setAttribute ( "selected" , "selected" ) ; for ( var c = $$ ( 'article.fiche-relation input[data-name="uid"][value="' +
2016-05-09 18:04:23 +00:00
a . uid + '"] ~ h5>input[type="radio"][data-name="sexe"]' ) , b = 0 ; b < c . length ; b ++ ) c [ b ] . value == a . sexe ? c [ b ] . setAttribute ( "checked" , "checked" ) : c [ b ] . removeAttribute ( "checked" ) ; c = $$ ( 'article.fiche-relation input[data-name="uid"][value="' + a . uid + '"] ~ h5>input[type="radio"][data-name="famsit"]' ) ; for ( b = 0 ; b < c . length ; b ++ ) c [ b ] . value == a . famsit ? c [ b ] . setAttribute ( "checked" , "checked" ) : c [ b ] . removeAttribute ( "checked" ) ; c = $$ ( 'article.fiche-relation input[data-name="uid"][value="' + a . uid + '"] ~ h5>input[type="radio"][data-name="reltype"]' ) ;
for ( b = 0 ; b < c . length ; b ++ ) c [ b ] . value == a . reltype ? c [ b ] . setAttribute ( "checked" , "checked" ) : c [ b ] . removeAttribute ( "checked" ) ; c = $$ ( 'article.fiche-relation input[data-name="uid"][value="' + a . uid + '"] ~ h5>input[type="radio"][data-name="loc"]' ) ; for ( b = 0 ; b < c . length ; b ++ ) c [ b ] . value == a . loc ? c [ b ] . setAttribute ( "checked" , "checked" ) : c [ b ] . removeAttribute ( "checked" ) ; c = $$ ( 'article.fiche-relation input[data-name="uid"][value="' + a . uid + '"] ~ h5>input[type="radio"][data-name="context"]' ) ; for ( b = 0 ; b < c . length ; b ++ ) c [ b ] . value == a . context ?
2016-05-10 06:22:29 +00:00
c [ b ] . setAttribute ( "checked" , "checked" ) : c [ b ] . removeAttribute ( "checked" ) ; c = $$ ( 'article.fiche-relation input[data-name="uid"][value="' + a . uid + '"] ~ h5>input[type="radio"][data-name="freq"]' ) ; for ( b = 0 ; b < c . length ; b ++ ) - 1 < a . freq . indexOf ( c [ b ] . value ) ? c [ b ] . setAttribute ( "checked" , "checked" ) : c [ b ] . removeAttribute ( "checked" ) ; c = $$ ( 'article.fiche-relation input[data-name="uid"][value="' + a . uid + '"] ~ h5>input[type="radio"][data-name="connect"]' ) ; for ( b = 0 ; b < c . length ; b ++ ) - 1 < a . connect . indexOf ( c [ b ] . value ) ? c [ b ] . setAttribute ( "checked" ,
"checked" ) : c [ b ] . removeAttribute ( "checked" ) } ; inputPhoneFiche . prototype . storageToFields = function ( ) { console . log ( "FICHE: STORAGE TO FIELDS" ) ; var a = lsi [ "export" ] ( "fiches" ) ; this . container . innerHTML = "" ; for ( var b in a ) a [ b ] . uid == this . selected && this . add ( a [ b ] ) ; this . updateNavBar ( ) } ;
2016-05-09 18:04:23 +00:00
inputPhoneFiche . prototype . sync = function ( ) { console . log ( "FICHE: SYNC" ) ; var a = lsi [ "export" ] ( "contacts" ) , b = [ ] , c ; for ( c in a ) { if ( - 1 < a [ c ] . call ) { var f = a [ c ] . call ; b . push ( f ) ; var d = lsi . get ( "fiches" , f ) ; null == d && ( d = this . defaultData ) ; d . uid = f ; d . contact = parseInt ( c ) ; lsi . set ( "fiches" , f , d ) } - 1 < a [ c ] . sms && ( f = 10 + a [ c ] . sms , b . push ( f ) , d = lsi . get ( "fiches" , f ) , null == d && ( d = this . defaultData ) , d . uid = f , d . contact = parseInt ( c ) , lsi . set ( "fiches" , f , d ) ) } if ( 20 > b . length ) for ( c in a ) { for ( a = 0 ; - 1 < b . indexOf ( a ) && 20 > a ; ) a ++ ; b . push ( a ) ; d = lsi . get ( "fiches" ,
2016-05-10 14:51:09 +00:00
a ) ; null == d && ( d = this . defaultData ) ; d . uid = a ; d . contact = c ; lsi . set ( "fiches" , a , d ) ; if ( 20 <= b . length ) break } var d = lsi [ "export" ] ( "fiches" ) , e ; for ( e in d ) miniData = lsi . get ( "mini-fiches" , d [ e ] . contact ) , null == miniData . timestamp || d [ e ] . timestamp > miniData . timestamp ? ( miniData . sexe = d [ e ] . sexe , miniData . age = d [ e ] . age , miniData . studies = d [ e ] . studies , miniData . loc = d [ e ] . loc , miniData . reltype = d [ e ] . reltype , miniData . reltypeSpecial = d [ e ] . reltypeSpecial ) : ( d [ e ] . sexe = miniData . sexe , d [ e ] . age = miniData . age , d [ e ] . studies = miniData . studies , d [ e ] . loc =
miniData . loc , d [ e ] . reltype = miniData . reltype , d [ e ] . reltypeSpecial = miniData . reltypeSpecial ) , lsi . set ( "mini-fiches" , d [ e ] . contact , miniData ) , lsi . set ( "fiches" , e , d [ e ] ) ; for ( e in d ) b = lsi . get ( "contacts" , d [ e ] . contact ) , null != b && - 1 != b . sms && - 1 != b . call && ( b = 10 > parseInt ( e ) ? 10 + b . sms : b . call , b = d [ b ] , b . timestamp >= d [ e ] . timestamp || ( c = d [ e ] , c . uid = b . uid , lsi . set ( "fiches" , b . uid , c ) ) ) } ;
2016-05-06 12:16:02 +00:00
inputPhoneFiche . prototype . nav = function ( a ) { if ( null == a || ! 1 === a . getData ( "n" ) || isNaN ( a . getData ( "n" ) ) || "nav-fiche" != a . parentNode . id ) return ! 1 ; for ( var b = $$ ( "#nav-fiche > span.active" ) , c = 0 ; c < b . length ; c ++ ) b [ c ] . remClass ( "active" ) ; a . addClass ( "active" ) ; this . selected = parseInt ( a . getData ( "n" ) ) } ;
2016-05-10 14:51:09 +00:00
inputPhoneFiche . prototype . updateNavBar = function ( ) { var a = lsi [ "export" ] ( "fiches" ) , b = lsi . keys ( "fiches" ) . length ; if ( $$ ( "#nav-fiche [data-n]" ) . length != b ) { this . nav _container . innerHTML = "" ; for ( var c = 0 ; c < b ; c ++ ) 0 == c && ( this . nav _container . innerHTML += "<span>APPELS</span>" ) , 9 == c ? this . nav _container . innerHTML += '<span data-n="' + c + '" class="lc">' + ( c % 10 + 1 ) + "</span> " : ( 10 == c && ( this . nav _container . innerHTML += '<span class="fc">SMS</span>' ) , this . nav _container . innerHTML += '<span data-n="' + c + '">' + ( c % 10 + 1 ) + "</span>" ) } for ( var f in a ) b =
$ ( '#nav-fiche [data-n="' + a [ f ] . uid + '"]' ) , null != b && ( ! 0 === a [ f ] . valid ? b . addClass ( "done" ) : b . remClass ( "done" ) ) ; this . nav ( $ ( '#nav-fiche [data-n="' + this . selected + '"]' ) ) } ;
inputPhoneFiche . prototype . check = function ( a ) { if ( 2 > a . city . length || isNaN ( parseInt ( a . duration [ 0 ] ) ) && 0 < a . duration [ 0 ] . length || isNaN ( parseInt ( a . duration [ 1 ] ) ) && 0 < a . duration [ 1 ] . length || 0 == a . duration [ 0 ] . length + a . duration [ 1 ] . length || "." == a . job || "." == a . studies || "." == a . age || "" == a . sexe || "" == a . famsit || "" == a . reltype || "" == a . loc || "" == a . context ) return ! 1 ; for ( var b = 0 ; b < a . freq . length ; b ++ ) if ( "" == a . freq [ b ] ) return ! 1 ; for ( b = 0 ; b < a . connect . length ; b ++ ) if ( "" == a . connect [ b ] ) return ! 1 ; return "8" == a . reltype && 2 > a . reltypeSpecial . length ||
"11" == a . context && 2 > a . contextSpecial [ 0 ] . length || "12" == a . context && 2 > a . contextSpecial [ 1 ] . length || "13" == a . context && 2 > a . contextSpecial [ 2 ] . length ? ! 1 : ! 0 } ; inputPhoneFiche . prototype . attach = function ( a ) { console . log ( "FICHE: ATTACH" ) ; lsi . createDataset ( "fiches" ) ; this . storageToFields ( ) ; this . handler = a ; var b = this , b = this ; this . nav _container . addEventListener ( "click" , function ( a ) { b . nav ( a . target ) ; b . handler ( a . target ) } , ! 1 ) } ;