2016-10-12 16:43:51 +00:00
function inputFacebookFiche ( a , c ) { this . container = a ; this . nav _container = c ; this . top _size = 10 } inputFacebookFiche . prototype = { container : this . container , nav _container : this . nav _container , selected : 0 , handler : null , defaultData : { sexe : "2" , age : "." , job : "." , famsit : "0" , studies : "0" , reltype : "0" , reltypeSpecial : "" , city : "" , quartier : "" , cp : "" , loc : "0" , duration : [ "" , "" ] , context : "0" , contextSpecial : [ "" , "" , "" ] , freq : [ "4" , "9" , "14" , "19" , "24" ] , connect : "1 3 5 7 9 11" . split ( " " ) , connectSpecial : [ "" , "" ] , timestamp : 0 , valid : ! 1 } } ;
2016-10-17 09:45:25 +00:00
inputFacebookFiche . prototype . fieldsToStorage = function ( ) { console . group ( "[facebook.fiche] fields to storage" ) ; for ( var a = $$ ( '[data-sublink="facebook"] article.relation-panel .fiche-relation' ) , c = 0 ; c < a . length ; c ++ ) { var b = ( new FormDeflater ( a [ c ] , [ "input" , "select" ] , [ "data-name" ] ) ) . deflate ( ) , e = crc32 ( JSON . stringify ( b ) ) , d = lsi . get ( "f_fiches" , b . uid ) ; if ( ! 1 !== d ) { if ( null != d . hash && d . hash == e ) return ; b = { contact : parseInt ( b . contact ) , uid : parseInt ( b . uid ) , sexe : b . sexe , age : b . age , job : b . job , famsit : b . famsit , studies : b . studies , reltype : b . reltype ,
reltypeSpecial : b . reltypeSpecial , city : b . city , quartier : b . quartier , cp : b . cp , loc : b . loc , duration : b . duration , context : b . context , contextSpecial : b . contextSpecial , freq : b . freq , connect : b . connect , connectSpecial : b . connectSpecial , hash : e } ; b . valid = this . check ( b ) ; 0 < diff ( d , b , [ "hash" , "valid" , "timestamp" ] ) . length ? ( console . log ( diff ( d , b , [ "hash" , "valid" , "timestamp" ] ) ) , console . warn ( "> FICHE UPDATE" ) , b . timestamp = Date . now ( ) ) : void 0 == d . timestamp && ( b . timestamp = this . defaultData . timestamp ) ; lsi . set ( "f_fiches" , b . uid , b ) } } console . groupEnd ( ) } ;
2016-10-12 14:20:46 +00:00
inputFacebookFiche . prototype . add = function ( a ) { if ( null == a . uid || isNaN ( a . uid ) || null == a . contact || isNaN ( a . contact ) ) return ! 1 ; a . city = null != a . city ? a . city : this . defaultData . city ; a . quartier = null != a . quartier ? a . quartier : this . defaultData . quartier ; a . cp = null != a . cp ? a . cp : this . defaultData . cp ; 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 :
2016-10-17 08:14:50 +00:00
this . defaultData . connect ; var c = lsi . get ( "f_contacts" , a . contact ) ; if ( ! 1 === c ) return ! 1 ; var b = "" ; isNaN ( c . existing ) || ( b = lsi . get ( "f_friends" , c . existing ) , c . username = b . name , a . age = b . age , a . sexe = b . sexe , a . loc = b . dist , isNaN ( b . reltype ) ? ( a . reltype = 10 , a . reltypeSpecial = b . reltype ) : ( a . reltype = b . reltype , a . reltypeSpecial = "" ) , null != b . studies2 ? ( a . studies = b . studies2 , a . job = b . job , a . famsit = b . famsit , a . city = b . city , a . cp = b . cp , a . quartier = b . quartier , a . duration [ 0 ] = b . duration [ 0 ] , a . duration [ 1 ] = b . duration [ 1 ] , a . context = b . context , a . contextSpecial =
b . contextExtra , a . connect = b . connect , a . connectSpecial = b . connectExtra , a . freq = b . freq , b = "Contact import\u00e9: non modifiable!" ) : b = "Contact import\u00e9 (incomplet): modifiable partiellement!" ) ; this . container . innerHTML += fFicheBuilder . build ( { importedfiche : b , name : c . username , countcall : c . countcall , countsms : c . countsms , uid : a . uid , contact : a . contact , city : a . city , quartier : a . quartier , cp : a . cp , 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 ] } ) ; c = $ ( '[data-sublink="facebook"] article.fiche-relation input[data-name="uid"][value="' + a . uid + '"] ~ h5>span>select[data-name="job"]>option[value="' + a . job + '"]' ) ; null != c && c . setAttribute ( "selected" , "selected" ) ; c = $ ( '[data-sublink="facebook"] article.fiche-relation input[data-name="uid"][value="' + a . uid + '"] ~ h5>span>select[data-name="studies"]>option[value="' + a . studies + '"]' ) ; null != c && c . setAttribute ( "selected" ,
"selected" ) ; c = $ ( '[data-sublink="facebook"] article.fiche-relation input[data-name="uid"][value="' + a . uid + '"] ~ h5>span>select[data-name="age"]>option[value="' + a . age + '"]' ) ; null != c && c . setAttribute ( "selected" , "selected" ) ; b = $$ ( '[data-sublink="facebook"] article.fiche-relation input[data-name="uid"][value="' + a . uid + '"] ~ h5>input[type="radio"][data-name="sexe"]' ) ; for ( c = 0 ; c < b . length ; c ++ ) b [ c ] . value == a . sexe ? b [ c ] . setAttribute ( "checked" , "checked" ) : b [ c ] . removeAttribute ( "checked" ) ; b = $$ ( '[data-sublink="facebook"] article.fiche-relation input[data-name="uid"][value="' +
a . uid + '"] ~ h5>input[type="radio"][data-name="famsit"]' ) ; for ( c = 0 ; c < b . length ; c ++ ) b [ c ] . value == a . famsit ? b [ c ] . setAttribute ( "checked" , "checked" ) : b [ c ] . removeAttribute ( "checked" ) ; b = $$ ( '[data-sublink="facebook"] article.fiche-relation input[data-name="uid"][value="' + a . uid + '"] ~ h5>input[type="radio"][data-name="reltype"]' ) ; for ( c = 0 ; c < b . length ; c ++ ) b [ c ] . value == a . reltype ? b [ c ] . setAttribute ( "checked" , "checked" ) : b [ c ] . removeAttribute ( "checked" ) ; b = $$ ( '[data-sublink="facebook"] article.fiche-relation input[data-name="uid"][value="' +
a . uid + '"] ~ h5>input[type="radio"][data-name="loc"]' ) ; for ( c = 0 ; c < b . length ; c ++ ) b [ c ] . value == a . loc ? b [ c ] . setAttribute ( "checked" , "checked" ) : b [ c ] . removeAttribute ( "checked" ) ; b = $$ ( '[data-sublink="facebook"] article.fiche-relation input[data-name="uid"][value="' + a . uid + '"] ~ h5>input[type="radio"][data-name="context"]' ) ; for ( c = 0 ; c < b . length ; c ++ ) b [ c ] . value == a . context ? b [ c ] . setAttribute ( "checked" , "checked" ) : b [ c ] . removeAttribute ( "checked" ) ; b = $$ ( '[data-sublink="facebook"] article.fiche-relation input[data-name="uid"][value="' +
a . uid + '"] ~ h5>input[type="radio"][data-name="freq"]' ) ; for ( c = 0 ; c < b . length ; c ++ ) - 1 < a . freq . indexOf ( b [ c ] . value ) ? b [ c ] . setAttribute ( "checked" , "checked" ) : b [ c ] . removeAttribute ( "checked" ) ; b = $$ ( '[data-sublink="facebook"] article.fiche-relation input[data-name="uid"][value="' + a . uid + '"] ~ h5>input[type="radio"][data-name="connect"]' ) ; for ( c = 0 ; c < b . length ; c ++ ) - 1 < a . connect . indexOf ( b [ c ] . value ) ? b [ c ] . setAttribute ( "checked" , "checked" ) : b [ c ] . removeAttribute ( "checked" ) } ;
2016-10-12 16:43:51 +00:00
inputFacebookFiche . prototype . storageToFields = function ( ) { console . group ( "[facebook.fiche] storage to fields" ) ; var a = lsi [ "export" ] ( "f_fiches" ) ; this . container . innerHTML = "" ; for ( var c in a ) a [ c ] . uid == this . selected && this . add ( a [ c ] ) ; this . updateNavBar ( ) ; console . groupEnd ( ) } ;
2016-10-17 09:45:25 +00:00
inputFacebookFiche . prototype . sync = function ( ) { console . group ( "[facebook.fiche] synchronisation" ) ; var a = lsi [ "export" ] ( "f_contacts" ) , c = [ ] , b , e ; e = lsi . keys ( "f_contacts" ) . length < 2 * this . top _size ? lsi . keys ( "f_contacts" ) . length : 2 * this . top _size ; for ( var d in a ) { for ( ficheUid = 0 ; - 1 < c . indexOf ( ficheUid ) && ficheUid < e ; ) ficheUid ++ ; c . push ( ficheUid ) ; a = lsi . get ( "f_fiches" , ficheUid ) ; ! a && ( a = this . defaultData ) ; a . uid = ficheUid ; a . contact = parseInt ( d ) ; lsi . set ( "f_fiches" , ficheUid , a ) ; if ( c . length >= e ) break } a = lsi [ "export" ] ( "f_fiches" ) ; e =
lsi [ "export" ] ( "f_mini-fiches" ) ; for ( var f in a ) { var g = lsi . get ( "f_contacts" , a [ f ] . contact ) ; if ( g ) { var c = null , h ; for ( h in e ) if ( b = lsi . get ( "f_contacts" , e [ h ] . contact ) ) if ( d = 0 < b . username . length && g . username === b . username , b = ! isNaN ( b . existing ) && g . existing === b . existing , ( d || b ) && ( c = e [ h ] ) , null !== c ) break ; d = a [ f ] . hasOwnProperty ( "timestamp" ) ? a [ f ] . timestamp : 0 ; g = c instanceof Object && c . hasOwnProperty ( "timestamp" ) ? c . timestamp : 0 ; null !== c && ( g > d ? ( d = a [ f ] , d . age = c . age , d . sexe = c . sexe , d . loc = c . loc , d . reltype = c . reltype , d . reltypeSpecial =
c . reltypeSpecial , d . timestamp = Date . now ( ) , lsi . set ( "f_fiches" , d . uid , d ) ) : d > g && ( d = c , d . age = a [ f ] . age , d . sexe = a [ f ] . sexe , d . loc = a [ f ] . loc , d . reltype = a [ f ] . reltype , d . reltypeSpecial = a [ f ] . reltypeSpecial , d . timestamp = Date . now ( ) , lsi . set ( "f_mini-fiches" , d . uid , d ) ) ) } } a = lsi [ "export" ] ( "f_fiches" ) ; for ( f in a ) if ( g = lsi . get ( "f_contacts" , a [ f ] . contact ) ) { c = null ; e = parseInt ( a [ f ] . uid ) < this . top _size ; for ( h in a ) if ( ! ( e && h < this . top _size || ! e && h >= this . top _size ) && ( b = lsi . get ( "f_contacts" , a [ h ] . contact ) , h != f && b && ( d = 0 < b . username . length && g . username ===
b . username , b = ! isNaN ( b . existing ) && g . existing === b . existing , ( d || b ) && ( c = a [ h ] ) , null !== c ) ) ) break ; d = a [ f ] . hasOwnProperty ( "timestamp" ) ? a [ f ] . timestamp : 0 ; e = c instanceof Object && c . hasOwnProperty ( "timestamp" ) ? c . timestamp : 0 ; null === c || e > d || ( d = a [ f ] , d . uid = c . uid , lsi . set ( "f_fiches" , d . uid , d ) ) } console . groupEnd ( ) } ;
inputFacebookFiche . prototype . nav = function ( a ) { if ( ! ( a instanceof Element && a . getData ( "n" ) ) || isNaN ( a . getData ( "n" ) ) || "f_nav-fiche" != a . parentNode . id ) return ! 1 ; for ( var c = $$ ( '[data-sublink="facebook"] #f_nav-fiche > span.active' ) , b = 0 ; b < c . length ; b ++ ) c [ b ] . remClass ( "active" ) ; a . addClass ( "active" ) ; this . selected = parseInt ( a . getData ( "n" ) ) } ;
inputFacebookFiche . prototype . updateNavBar = function ( ) { var a = lsi [ "export" ] ( "f_fiches" ) ; this . nav _container . innerHTML = "" ; for ( var c = Object . keys ( a ) , b = 0 ; b < c . length ; b ++ ) { var e = parseInt ( c [ b ] ) ; 0 == e && ( this . nav _container . innerHTML += "<span>HISTORIQUE</span>" ) ; 20 > e && b < c . length - 1 && 20 <= c [ b + 1 ] ? this . nav _container . innerHTML += '<span data-n="' + e + '" class="lc">' + ( e % 20 + 1 ) + "</span> " : ( 20 == e && ( this . nav _container . innerHTML += '<br><span class="fc">MESSENGER </span>' ) , this . nav _container . innerHTML += '<span data-n="' +
e + '">' + ( e % 20 + 1 ) + "</span>" ) } for ( var d in a ) c = $ ( '[data-sublink="facebook"] #f_nav-fiche [data-n="' + a [ d ] . uid + '"]' ) , null != c && ( ! 0 === a [ d ] . valid ? c . addClass ( "done" ) : c . remClass ( "done" ) ) ; this . nav ( $ ( '[data-sublink="facebook"] #f_nav-fiche [data-n="' + this . selected + '"]' ) ) } ;
2016-10-12 16:43:51 +00:00
inputFacebookFiche . 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 c = 0 ; c < a . freq . length ; c ++ ) if ( "" == a . freq [ c ] ) return ! 1 ; for ( c = 0 ; c < a . connect . length ; c ++ ) if ( "" == a . connect [ c ] ) return ! 1 ; return "10" == 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 } ; inputFacebookFiche . prototype . attach = function ( a ) { console . group ( "[facebook.fiche] attaching events" ) ; lsi . createDataset ( "f_fiches" ) ; this . storageToFields ( ) ; this . handler = a ; var c = this , c = this ; this . nav _container . addEventListener ( "click" , function ( a ) { c . nav ( a . target ) ; c . handler ( a . target ) } , ! 1 ) ; console . groupEnd ( ) } ;