2016-07-13 14:58:39 +00:00
var section = { view : { text : '#CONTAINER > section[data-sublink="view"] ' , element : document . querySelector ( '#CONTAINER > section[data-sublink="view"]' ) , searchbar : document . querySelector ( '#CONTAINER > section[data-sublink="view"] > .searchbar' ) } , create : { text : '#CONTAINER > section[data-sublink="create"] ' , element : document . querySelector ( '#CONTAINER > section[data-sublink="create"]' ) } , remove : { text : '#CONTAINER > section[data-sublink="remove"] ' , element : document . querySelector ( '#CONTAINER > section[data-sublink="remove"]' ) } ,
2016-07-20 14:50:41 +00:00
edit : { text : '#CONTAINER > section[data-sublink="edit"] ' , element : document . querySelector ( '#CONTAINER > section[data-sublink="edit"]' ) } , members : { text : '#CONTAINER > section[data-sublink="members"] ' , element : document . querySelector ( '#CONTAINER > section[data-sublink="members"]' ) , chooser : { text : '#CONTAINER > section[data-sublink="members"] form#choose-cluster ' , element : document . querySelector ( '#CONTAINER > section[data-sublink="members"] form#choose-cluster' ) } } , permissions : { text : '#CONTAINER > section[data-sublink="permissions"] ' ,
2016-07-16 10:41:21 +00:00
element : document . querySelector ( '#CONTAINER > section[data-sublink="permissions"]' ) } } ;
2016-07-20 16:41:24 +00:00
if ( null != section . view . element ) { 1 < pageManager . vars . length && /^(u|m)\d+$/ . test ( pageManager . vars [ 1 ] ) && ( document . location = "#" + pageManager . vars [ 1 ] , document . getElementById ( pageManager . vars [ 1 ] ) . addClass ( "selected" ) ) ; section . view . link = { edit : document . querySelectorAll ( section . view . text + ".link_edit[data-cluster]" ) , remove : document . querySelectorAll ( section . view . text + ".link_remove[data-cluster]" ) } ; section . view . group = { rem : document . querySelectorAll ( section . view . text + ".rem-member[data-cluster][data-member]" ) , add : document . querySelectorAll ( section . view . text +
2016-07-20 15:33:38 +00:00
".add-member[data-cluster]" ) } ; section . view . searchbar . addEventListener ( "keyup" , function ( a ) { api . send ( { path : "clusterDefault/search" , keywords : section . view . searchbar . value } , function ( a ) { if ( 0 == a . ModuleError ) { for ( var d = [ ] , c = 0 ; c < a . clusters . length ; c ++ ) d . push ( a . clusters [ c ] . id _cluster ) ; a = document . querySelectorAll ( section . view . text + "> article.inline-box[id]" ) ; for ( c = 0 ; c < a . length ; c ++ ) - 1 < d . indexOf ( a [ c ] . id ) ? a [ c ] . remClass ( "hidden" ) : a [ c ] . addClass ( "hidden" ) } } ) } , ! 1 ) ; var i ; for ( i = 0 ; i < section . view . link . edit . length ; i ++ ) section . view . link . edit [ i ] . addEventListener ( "click" ,
2016-07-20 17:41:43 +00:00
function ( a ) { pageManager . vars [ 1 ] = a . target . getData ( "cluster" ) ; autofill _edit ( ) ; navSubMenu ( "edit" ) ; document . location = "" } , ! 1 ) ; for ( i = 0 ; i < section . view . link . remove . length ; i ++ ) section . view . link . remove [ i ] . addEventListener ( "click" , function ( a ) { pageManager . vars [ 1 ] = a . target . getData ( "cluster" ) ; autofill _remove ( ) ; navSubMenu ( "remove" ) ; document . location = "" } , ! 1 ) ; for ( i = 0 ; i < section . view . group . rem . length ; i ++ ) section . view . group . rem [ i ] . addEventListener ( "click" , function ( a ) { var b = a . target . getData ( "cluster" ) [ 0 ] , d = a . target . getData ( "cluster" ) . slice ( 1 ) ;
console . log ( a . target ) ; var c = { } ; c . path = "u" == b ? "userDefault/unlink" : "machineDefault/unlink" ; c . id _cluster = d ; "u" == b ? c . id _user = a . target . getData ( "member" ) : c . id _machine = a . target . getData ( "member" ) ; api . send ( c , function ( b ) { if ( 0 != b . ModuleError ) return ! 1 ; a . target . parentNode . parentNode . removeChild ( a . target . parentNode ) } ) } , ! 1 ) ; for ( i = 0 ; i < section . view . group . add . length ; i ++ ) section . view . group . add [ i ] . addEventListener ( "click" , function ( a ) { pageManager . vars [ 1 ] = a . target . getData ( "cluster" ) ; navSubMenu ( "members" ) ; document . location =
"" } , ! 1 ) }
2016-07-20 17:46:57 +00:00
null != section . create . element && ( section . create . input = { name : document . querySelector ( section . create . text + "#create_name" ) , "class" : document . querySelector ( section . create . text + "#create_class" ) , submit : document . querySelector ( section . create . text + "#create_submit" ) } , section . create . input . submit . addEventListener ( "click" , function ( a ) { a . preventDefault ( ) ; var b = { path : "clusterDefault/create" , name : section . create . input . name . value , "class" : section . create . input [ "class" ] . value } ; api . send ( b , function ( a ) { 0 == a . ModuleError && ( console . log ( "Groupe cree!" ) ,
pageManager . vars [ 1 ] = ( 0 == b [ "class" ] ? "u" : "m" ) + a . id _cluster , navSubMenu ( "view" ) , document . location = "" , section . create . input . submit . anim ( "active" , 1500 ) ) } ) } , ! 1 ) ) ;
2016-07-20 16:16:36 +00:00
if ( null != section . remove . element ) { var autofill _remove = function ( ) { var a = { id _cluster : "" , "class" : "" , name : "" , disable _input : ! 0 } ; if ( null == found _remove [ searchindex _remove ] ) searchindex _remove = section . remove . input . search . num . innerHTML = 0 ; else { var b ; found _remove [ searchindex _remove ] . hasOwnProperty ( "id_user_cluster" ) ? ( a = found _remove [ searchindex _remove ] . id _user _cluster , b = 0 ) : ( a = found _remove [ searchindex _remove ] . id _machine _cluster , b = 1 ) ; a = { id _cluster : a , "class" : b , name : found _remove [ searchindex _remove ] . name , disable _input : ! 1 } ;
section . remove . input . search . num . innerHTML = searchindex _remove + 1 } section . remove . input . search . id . value = a . id _cluster ; section . remove . input . name . value = a . name ; section . remove . input [ "class" ] . value = 0 == a [ "class" ] ? "utilisateur" : "machine" ; console . log ( a ) ; section . remove . input . submit . disabled = a . disable _input } ; section . remove . input = { search : { view : document . querySelector ( section . remove . text + ".remove_search_view" ) , num : document . querySelector ( section . remove . text + ".remove_search_num" ) , sum : document . querySelector ( section . remove . text +
".remove_search_sum" ) , keyword : document . querySelector ( section . remove . text + "#remove_search_keyword" ) , id : document . querySelector ( section . remove . text + "#remove_search_id" ) , submit : document . querySelector ( section . remove . text + "#remove_search_submit" ) } , name : document . querySelector ( section . remove . text + "#remove_name" ) , "class" : document . querySelector ( section . remove . text + "#remove_class" ) , submit : document . querySelector ( section . remove . text + "#remove_submit" ) } ; var lastkeywords _remove = "" , found _remove = [ ] , searchindex _remove =
2016-07-20 16:41:24 +00:00
0 ; if ( 2 <= pageManager . vars . length && /^(u|m)\d+$/ . test ( pageManager . vars [ 1 ] ) ) { var prefix = pageManager . vars [ 1 ] [ 0 ] , cluster = pageManager . vars [ 1 ] . slice ( 1 ) , request = { path : "clusterDefault/getById" , id _cluster : cluster , "class" : "u" == prefix ? 0 : 1 } ; api . send ( request , function ( a ) { 0 == a . ModuleError && ( found _remove = [ a . cluster ] , searchindex _remove = 0 , autofill _remove ( ) ) } ) } section . remove . input . search . submit . addEventListener ( "click" , function ( a ) { a . preventDefault ( ) ; if ( "" != section . remove . input . search . keyword . value ) if ( section . remove . input . search . keyword . value ==
2016-07-20 16:16:36 +00:00
lastkeywords _remove ) searchindex _remove = ( searchindex _remove + 1 ) % found _remove . length , autofill _remove ( ) ; else { var b = { path : "clusterDefault/search" , keywords : section . remove . input . search . keyword . value } ; api . send ( b , function ( a ) { 0 == a . ModuleError && ( section . remove . input . search . submit . anim ( "active" , 1E3 ) , searchindex _remove = 0 , found _remove = a . clusters , section . remove . input . search . sum . innerHTML = found _remove . length , autofill _remove ( ) ) ; lastkeywords _remove = b . keywords } ) } } , ! 1 ) ; section . remove . input . submit . addEventListener ( "click" ,
2016-07-20 17:46:57 +00:00
function ( a ) { a . preventDefault ( ) ; "" != section . remove . input . search . id . value && ( a = found _remove [ searchindex _remove ] . hasOwnProperty ( "id_user_cluster" ) ? 0 : 1 , api . send ( { path : "clusterDefault/delete" , id _cluster : section . remove . input . search . id . value , "class" : a } , function ( a ) { 0 == a . ModuleError && 1 == a . status ? ( console . log ( "Groupe supprimee!" ) , section . remove . input . submit . anim ( "active" , 1500 ) , pageManager . vars [ 1 ] = "" , navSubMenu ( "view" ) , document . location = "" ) : console . error ( "ModuleError::" + a . ModuleError ) } ) ) } , ! 1 ) }
2016-07-20 17:41:43 +00:00
if ( null != section . edit . element ) { var autofill _edit = function ( ) { var a = "" , b = "" , d = ! 0 ; if ( null == found _edit [ searchindex _edit ] ) searchindex _edit = section . edit . input . search . num . innerHTML = 0 ; else { var c ; found _edit [ searchindex _remove ] . hasOwnProperty ( "id_user_cluster" ) ? ( a = found _edit [ searchindex _remove ] . id _user _cluster , c = 0 ) : ( a = found _edit [ searchindex _remove ] . id _machine _cluster , c = 1 ) ; b = found _edit [ searchindex _remove ] . name ; d = ! 1 ; section . edit . input . search . num . innerHTML = searchindex _edit + 1 } section . edit . input . search . id . value =
a ; section . edit . input . name . value = b ; section . edit . input [ "class" ] . value = 0 == c ? "utilisateur" : "machine" ; section . edit . input . submit . disabled = d } ; section . edit . input = { search : { view : document . querySelector ( section . edit . text + ".edit_search_view" ) , num : document . querySelector ( section . edit . text + ".edit_search_num" ) , sum : document . querySelector ( section . edit . text + ".edit_search_sum" ) , keyword : document . querySelector ( section . edit . text + "#edit_search_keyword" ) , id : document . querySelector ( section . edit . text + "#edit_search_id" ) , submit : document . querySelector ( section . edit . text +
"#edit_search_submit" ) } , name : document . querySelector ( section . edit . text + "#edit_name" ) , "class" : document . querySelector ( section . edit . text + "#edit_class" ) , submit : document . querySelector ( section . edit . text + "#edit_submit" ) } ; var lastkeywords _edit = "" , found _edit = [ ] , searchindex _edit = 0 ; 2 <= pageManager . vars . length && /^(u|m)\d+$/ . test ( pageManager . vars [ 1 ] ) && ( console . log ( "bla" ) , prefix = pageManager . vars [ 1 ] [ 0 ] , cluster = pageManager . vars [ 1 ] . slice ( 1 ) , request = { path : "clusterDefault/getById" , id _cluster : cluster , "class" : "u" == prefix ?
0 : 1 } , api . send ( request , function ( a ) { 0 == a . ModuleError && ( found _edit = [ a . cluster ] , searchindex _edit = 0 , autofill _edit ( ) ) } ) ) ; section . edit . input . search . submit . addEventListener ( "click" , function ( a ) { a . preventDefault ( ) ; if ( "" != section . edit . input . search . keyword . value ) if ( section . edit . input . search . keyword . value == lastkeywords _edit ) searchindex _edit = ( searchindex _edit + 1 ) % found _edit . length , autofill _edit ( ) ; else { var b = { path : "clusterDefault/search" , keywords : section . edit . input . search . keyword . value } ; api . send ( b , function ( a ) { 0 ==
a . ModuleError && ( section . edit . input . search . submit . anim ( "active" , 1E3 ) , searchindex _edit = 0 , found _edit = a . clusters , section . edit . input . search . sum . innerHTML = found _edit . length , autofill _edit ( ) ) ; lastkeywords _edit = b . keywords } ) } } , ! 1 ) ; section . edit . input . submit . addEventListener ( "click" , function ( a ) { a . preventDefault ( ) ; if ( "" != section . edit . input . search . id . value ) { var b = found _edit [ searchindex _edit ] . hasOwnProperty ( "id_user_cluster" ) ? 0 : 1 , d = { path : "clusterDefault/edit" , id _cluster : section . edit . input . search . id . value , name : section . edit . input . name . value ,
"class" : b } ; api . send ( d , function ( a ) { 0 == a . ModuleError && 1 == a . status ? ( console . log ( "Groupe modifiee!" ) , section . edit . input . submit . anim ( "active" , 1500 ) , pageManager . vars [ 1 ] = ( 0 == b ? "u" : "m" ) + d . id _cluster , navSubMenu ( "view" ) , document . location = "" ) : console . error ( "ModuleError::" + a . ModuleError ) } ) } } , ! 1 ) }
2016-07-20 16:41:24 +00:00
null != section . members . element && null != section . members . chooser . element && ( section . members . chooser . deflater = new FormDeflater ( section . members . chooser . element , [ "select" ] , [ "data-name" ] ) , section . members . chooser . submit = document . querySelector ( section . members . chooser . text + "#choose-cluster" ) , section . members . chooser . submit . addEventListener ( "click" , function ( a ) { a . preventDefault ( ) ; a = section . members . chooser . deflater . deflate ( ) . cluster ; /^(u|m)\d+$/ . test ( a ) && ( pageManager . vars [ 1 ] = a , pageManager . refresh ( ) , document . location =
"" ) } , ! 1 ) ) ;
null != section . members . element && null == section . members . chooser . element && ( section . members . deflater = new FormDeflater ( section . members . element , [ "input" ] , [ "data-name" ] ) , section . members . baseData = section . members . deflater . deflate ( ) . members , section . members [ "class" ] = document . querySelector ( "#members-member-class" ) . value , section . members . idcluster = document . querySelector ( "#members-member-idcluster" ) . value , section . members . element . addEventListener ( "click" , function ( a ) { var b = [ ] , d = [ ] , c = section . members . deflater . deflate ( ) . members ; c instanceof
Array || ( c = [ c ] ) ; for ( a = 0 ; a < c . length ; a ++ ) - 1 == section . members . baseData . indexOf ( c [ a ] ) && b . push ( c [ a ] ) ; for ( a = 0 ; a < section . members . baseData . length ; a ++ ) - 1 == c . indexOf ( section . members . baseData [ a ] ) && d . push ( section . members . baseData [ a ] ) ; for ( a = 0 ; a < b . length ; a ++ ) { var e = { } ; e . path = 0 == section . members [ "class" ] ? "userDefault/link" : "machineDefault/link" ; e . id _cluster = section . members . idcluster ; 0 == section . members [ "class" ] ? e . id _user = b [ a ] : e . id _machine = b [ a ] ; api . send ( e , function ( a ) { 0 != a . ModuleError && console . error ( "Erreur d'ajout de membre" ) } ) } for ( a =
2016-07-20 15:33:38 +00:00
0 ; a < d . length ; a ++ ) b = { } , b . path = 0 == section . members [ "class" ] ? "userDefault/unlink" : "machineDefault/unlink" , b . id _cluster = section . members . idcluster , 0 == section . members [ "class" ] ? b . id _user = d [ a ] : b . id _machine = d [ a ] , api . send ( b , function ( a ) { 0 != a . ModuleError && console . error ( "Erreur d'ajout de membre" ) } ) ; section . members . baseData = c } , ! 1 ) ) ;