Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $scope.etatBloc =  {};
  2.  
  3.        
  4.         setupEtatBloc();
  5.  
  6.         function setupEtatBloc(){
  7.             // read cookie
  8.            // For each bloc
  9.            for(var i = 0; i < $scope.etatBloc.length; i++) {
  10.                id = $scope.etatBloc[i];
  11.                // IF we have the id block element in the cookie
  12.                if (getCookie(id) === "true" || getCookie(id) === "" ) {
  13.                    $scope.etatBloc[i] = true
  14.                } else {
  15.                    $scope.etatBloc[i] = false
  16.                }
  17.            }
  18.             //build var
  19.             $scope.etatBloc = {
  20.                 "partInfoContent" : false,
  21.                 "blocInfoUsager" : true,
  22.                 "preconisationBloc" : true,
  23.                 "partEvalAjust" : true,
  24.                 "finalRelBloc" : true,
  25.                 "blocNds" : false,
  26.                 "partReferentiel" : false,
  27.                 "partEvaluation" : false,
  28.                 "listPointDot" : false,
  29.                 "blocInfoContact" : false
  30.             };
  31.         }
  32.  
  33.         $scope.onBlocDisplayClick = function(nomBloc){
  34.             $scope.etatBloc[nomBloc] = !$scope.etatBloc[nomBloc];
  35.             // save in cookie
  36.             setCookie($scope.etatBloc[nomBloc], $scope.etatBloc[nomBloc] === true ? "true" : "false", 365);
  37.             // TODO
  38.         };
  39.  
  40.          // Set the cookie
  41.             function setCookie(cname, cvalue, exdays) {
  42.                 var d = new Date();
  43.                 d.setTime(d.getTime() + (exdays*24*60*60*1000));
  44.                 var expires = "expires="+ d.toUTCString();
  45.                 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  46.             }
  47.             // get / read the cookie
  48.             function getCookie(cname) {
  49.                 var name = cname + "=";
  50.                 var decodedCookie = decodeURIComponent(document.cookie);
  51.                 var ca = decodedCookie.split(';');
  52.                 for(var i = 0; i <ca.length; i++) {
  53.                     var c = ca[i];
  54.                     while (c.charAt(0) == ' ') {
  55.                         c = c.substring(1);
  56.                     }
  57.                     if (c.indexOf(name) == 0) {
  58.                         return c.substring(name.length, c.length);
  59.                     }
  60.                 }
  61.                 return "";
  62.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement