Advertisement
imguru

Angular JS app not building properly on Grunt Compile,(minif

Jun 20th, 2014
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. angular.module( 'tappApp.planManager', [
  2.   'ui.router'
  3. ])
  4. .config(['$stateProvider','$urlRouteProvider',function config( $stateProvider, $urlRouterProvider) {
  5.   $stateProvider["state"]( 'planManager', {
  6.     url: '/planManager/:state',
  7.     views: {
  8.       "main": {
  9.         controller: 'planManagerControl',
  10.         templateUrl: 'planManager/planManager.tpl.html'
  11.       }
  12.     },
  13.    /* params: [{'planType':'new'}],*/
  14.     data:{ pageTitle: 'Plan Manager' },
  15.     resolve:{
  16.          validState: function($stateParams,localStorageService){
  17.           if($stateParams["state"]!="buy" && $stateParams["state"]!="audience" && $stateParams["state"]!="campaign"){
  18.             $stateParams["state"]="buy";
  19.           }
  20.           /*TODO:
  21.           Need to change this to remove the unnknown part of the URL and replace it with planManager/buy... Right now, is the unknown string is abcd, then the
  22.           url still shows planManager/abcd although the right page is loaded*/
  23.           return true;
  24.          },
  25.          pmGetPlan:  function($http,$stateParams){
  26.             var urlConfig='';
  27.             if($stateParams["planType"]=='draft'){
  28.               urlConfig="assets/data/mediaPlan_draft.json";
  29.             }
  30.             else if($stateParams["planType"]=='newClient'){
  31.               urlConfig="assets/data/mediaPlan_new_client.json";
  32.             }
  33.             else {
  34.               urlConfig="assets/data/mediaPlan_new.json";
  35.             }
  36.             var plan = $http({method: 'GET', url: urlConfig})
  37.             .success(function(){
  38.               /*console.log("Fetch successfull"+plan);*/
  39.             })
  40.             .error(function(){
  41.               console.log(error);
  42.             });
  43.             return true;
  44.           }
  45.         }
  46.   }]);
  47.   $urlRouterProvider.when('/planManager/', '/planManager/buy');
  48.   $urlRouterProvider.when('/planManager', '/planManager/buy');
  49.   $urlRouterProvider.otherwise('/planManager/buy');
  50. })
  51. .run(['$rootScope','$state','$stateParams',function run ($rootScope, $state, $stateParams) {
  52.   $rootScope.$state = $state;
  53.   $rootScope.$stateParams = $stateParams;
  54. }])
  55. .directive('onLastRepeatDemo', function() {
  56.         return function(scope, element, attrs) {
  57.             if (scope.$last){
  58.               setTimeout(function(){
  59.                 scope.$emit('onRepeatLastDemo', element, attrs);
  60.             }, 1);
  61.             }
  62.         };
  63.     })
  64. .directive('onLastRepeatBeh', function() {
  65.         return function(scope, element, attrs) {
  66.             if (scope.$last){
  67.               setTimeout(function(){
  68.                 scope.$emit('onRepeatLastBeh', element, attrs);
  69.             }, 1);
  70.             }
  71.         };
  72.     })
  73. /**
  74.  * And of course we define a controller for our route.
  75.  */
  76. .controller( 'planManagerControl', ['$scope','localStorageService','$http','$rootScope','$stateParams', function($scope,localStorageService,$http,$rootScope,$stateParams) {
  77.  /* if($('html').hasClass("defaultBg")){
  78.     $('html').removeClass("defaultBg");
  79.   }*/
  80.   $rootScope["states"]=[{
  81.                       "name": "buy",
  82.                       "active": true,
  83.                       "currentState":false
  84.                     },{
  85.                       "name": "audience",
  86.                       "active": true,
  87.                       "currentState":false
  88.                     },{
  89.                       "name": "campaign",
  90.                       "active": true,
  91.                       "currentState":false
  92.                     }];
  93.   $rootScope["state"] = $stateParams["state"];
  94.   var activeIndex = 2;
  95.   $.each($rootScope["states"], function(i,item){
  96.     if(item["name"]==$rootScope["state"].toLowerCase() || i<activeIndex){
  97.       item["active"]=true;
  98.       if(item["name"]==$rootScope["state"].toLowerCase()){
  99.         activeIndex = i;
  100.         item["currentState"]=true;
  101.       }
  102.     }
  103.     else
  104.       {
  105.         item["active"]=false;
  106.       }
  107.   });
  108.     var pmTabs = $('.pmTab');
  109.     $.each(pmTabs, function(i, item){
  110.       if($(item).attr("id")!==$rootScope["state"]){
  111.         $(item).css("visibility","hidden");
  112.       }
  113.     });
  114.     $('#'+$rootScope["state"]).css("visibility","visible");  
  115.     angular.element(document).ready(function (){
  116.       $.each(pmTabs, function(i, item){
  117.       if($(item).attr("id")!==$rootScope["state"]){
  118.         $(item).hide();
  119.       }
  120.     });
  121.      $('.'+$rootScope["state"]).show();
  122.     $('#'+$rootScope["state"]).show();
  123.     });
  124.  
  125.     /*Buy code starts*/
  126.      $scope["planObject"] = $.parseJSON(JSON.stringify(localStorageService.get("plan")));
  127.      /*var buy = JSON.parse();*/
  128.   $scope.updateBuyParam = function(event){
  129.  
  130.     if(event.target.attributes["name"]["value"]=="bbBiz"){
  131.       $scope["planObject"]["buy"]["sBusinessType"] = (event.target.nextSibling.nextElementSibling.innerText).replace(/\n/g,'');
  132.       }
  133.     else if (event.target.attributes["name"]["value"]=="bbBuyType"){
  134.       $scope["planObject"]["buy"]["sMediaBuy"]=event.target.nextSibling.nextElementSibling.innerText.replace(/\n/g,'');
  135.     }
  136.     else if (event.target.attributes["name"]["value"]=="bbMediaType"){
  137.       $scope["planObject"]["buy"]["sMediaDelivery"]=event.target.nextSibling.nextElementSibling.innerText.replace(/\n/g,'');
  138.     }
  139.     else if (event.target.attributes["name"]["value"]=="bbMediaType"){
  140.       $scope["planObject"]["buy"]["sMediaMethod"]=event.target.nextSibling.nextElementSibling.innerText.replace(/\n/g,'');
  141.     }
  142.     else{
  143.       console.log('Invalid Buy Parameter Selection');
  144.     }
  145.     localStorageService.remove("plan");
  146.     localStorageService.set("plan",$scope.planObject);
  147.     };
  148.   $scope["bBoxProps"] =   [{
  149.                       "bbId":"bbBiz",
  150.                       "bbClass":[
  151.                         "disabledBb"
  152.                       ],
  153.                       "bbTitle":"BUSINESS",
  154.                       "bbOptIds":{
  155.                         "id1":"bbBiz1",
  156.                         "id2":"bbBiz2"
  157.                         },
  158.                         "bbName":"bbBiz",
  159.                         "bbLabelText":{
  160.                         "label1":"NYI",
  161.                         "label2":"Local"
  162.                         }
  163.                       },
  164.                       {
  165.                       "bbId":"bbBuyType",
  166.                       "bbClass":[
  167.                         "disabledBb"
  168.                       ],
  169.                       "bbTitle":"BUY TYPE",
  170.                       "bbOptIds":{
  171.                         "id1":"bbBuyType1",
  172.                         "id2":"bbBuyType2"
  173.                         },
  174.                         "bbName":"bbBuyType",
  175.                       "bbLabelText":{
  176.                         "label1":"Audience",
  177.                         "label2":"Spot"
  178.                         }
  179.                       },
  180.                       {
  181.                       "bbId":"bbMediaType",
  182.                       "bbClass":[
  183.                         "disabledBb"
  184.                         ],
  185.                       "bbTitle":"MEDIA TYPE",
  186.                      "bbOptIds":{
  187.                         "id1":"bbMediaType1",
  188.                         "id2":"bbMediaType2"
  189.                         },
  190.                         "bbName":"bbMediaType",
  191.                       "bbLabelText":{
  192.                         "label1":"Optimized Linear",
  193.                         "label2":"Addressable"
  194.                         }
  195.                       },
  196.                       {
  197.                       "bbId":"bbDelType",
  198.                       "bbClass":[
  199.                         "disabledBb"
  200.                         ],
  201.                       "bbTitle":"DELIVERY TYPE",
  202.                       "bbOptIds":{
  203.                         "id1":"bbDelType1",
  204.                         "id2":"bbDelType2"
  205.                         },
  206.                         "bbName":"bbDelType",
  207.                       "bbLabelText":{
  208.                         "label1":"Impressions",
  209.                         "label2":"GRP"
  210.                         }
  211.                       }];
  212.   angular.element(document).ready(function (){
  213.  
  214.     $("#bbBiz").removeClass("disabledBb");
  215.      var activeIndex = 0;
  216.         var activeIndexFlag = false;
  217.         var buyBoxArray = $(".buyBox");
  218.     $("a#buy").on('click', this, function(){
  219.       $("div#buyPBox").css('left','0%').css('display','inline-block');
  220.     });
  221.     $("a#audience").on('click', this, function(){
  222.       $("div#audPBox").css('left','0%').css('display','inline-block');
  223.     });
  224.     $("a#campaign").on('click', this, function(){
  225.       $("div#camPBox").css('left','0%').css('display','inline-block');
  226.     });
  227.     $("div.buyBox.disabledBb input").attr('disabled','disabled');
  228.     $("a#buy").trigger('click');
  229.    
  230.     $("div.bbSelectOpt").on('change','input', function(){
  231.         $.each(buyBoxArray,function(i,item){
  232.            if($(item).hasClass('activeBb')){
  233.             $(item).removeClass('activeBb');
  234.            }
  235.         });
  236.         $(this).parents(".buyBox").addClass("activeBb");
  237.         $.each($(this).parents('.bbSelect').children('.bbSelectOpt'), function(){
  238.             $(this).removeClass('bbSelected');
  239.             if($(this).children('input.css-checkbox').is(':checked')){
  240.               $(this).addClass('bbSelected');
  241.             }
  242.         });
  243.         $.each(buyBoxArray,function(i,item){
  244.             if($(buyBoxArray[i]).hasClass("activeBb")){
  245.               activeIndex = i;
  246.               activeIndexFlag = true;
  247.             }
  248.             else if((i==(activeIndex+1)) && (activeIndexFlag===true) && ($(item).length>0)){
  249.               $(item).removeClass('disabledBb');
  250.               $(item).find('input').removeAttr('disabled').removeAttr('checked');
  251.               $(item).find('.bbSelectOpt').removeClass('bbSelected');
  252.             }
  253.         });
  254.          $.each(buyBoxArray,function(i,item){
  255.               if(i>(activeIndex+1)){
  256.                 $(item).addClass("disabledBb");
  257.                 $(item).find('input').attr("disabled","disabled").removeAttr('checked');
  258.                 $(item).find('.bbSelectOpt').removeClass('bbSelected');
  259.             }
  260.         });
  261.        
  262.        
  263.     });
  264.     $("span#clearBuySelections").on('click',this,function(){
  265.       $.each(buyBoxArray,function(i, item){
  266.         if(i!==0){
  267.           $(item).addClass('disabledBb');
  268.           $(item).find('input').removeAttr('checked').attr("disabled","disabled");
  269.           $(item).find('.bbSelected').removeClass('bbSelected');
  270.        }
  271.        else if(i===0){
  272.         $(item).find('input').removeAttr('checked');
  273.         $(item).find('.bbSelected').removeClass('bbSelected');
  274.        }
  275.       });
  276.     });
  277.     $("div#buy").removeClass("tappLoader");
  278.   });
  279. /*Buy code ends*/
  280. /*Audience code starts*/
  281.  $scope.planObject = $.parseJSON(JSON.stringify(localStorageService.get("plan")));
  282.   $scope["custSelList"] = [];
  283.   $scope["audienceBehavioral"]=[];
  284.   $scope["audienceDemographics"] = [];
  285.   $scope["demoFlag"]="";
  286.   $scope["behFlag"]="";
  287.   $scope["universeHousehold"] = "";
  288.   $scope["segmentAudience"] = "";
  289.   $scope["sSegmentHousehold"] = "";
  290.   $scope.pmStateValidator = function(state){
  291.       return true;
  292.     };
  293.   $scope.custNav = function(tabName, event){
  294.     if(!($(event.target.parentElement).hasClass("active"))){
  295.       if(tabName=="demo"){
  296.         $('.demoContainer').toggleClass('active').addClass('tappLoader');
  297.         $('.behContainer').toggleClass('active');
  298.         $(event.target.parentElement.parentElement.children).removeClass('active');
  299.         $(event.target.parentElement).toggleClass('active');
  300.         gridCtrl.resizeGrid($(".demoContainer .gridContainer"));
  301.         $('.demoContainer').removeClass('tappLoader');
  302.        /* $scope.resizeGridSiblings();*/
  303.       }
  304.       else if(tabName=="beh"){
  305.         $('.demoContainer').toggleClass('active');
  306.         $('.behContainer').toggleClass('active').addClass('tappLoader');
  307.         $(event.target.parentElement.parentElement.children).removeClass('active');
  308.          $(event.target.parentElement).toggleClass('active');
  309.          gridCtrl.resizeGrid($(".behContainer .gridContainer"));
  310.          $('.behContainer').removeClass('tappLoader');
  311.          // $scope.resizeGridSiblings();
  312.       }
  313.     }
  314.  
  315. };
  316. $scope.resizeGridSiblings = function(){
  317.   var gridHeight = $('.custTabContainer').height();
  318.   $('.selListContainer').height(gridHeight);
  319. };
  320. $scope.audNav = function(tabName, event){
  321.   if(!($(event.target.parentElement).hasClass("active"))){
  322.     if(tabName=="pre"){
  323.       $('.preContainer').toggleClass('active');
  324.       $('.custContainer').toggleClass('active');
  325.       $(event.target.parentElement.parentElement.children).removeClass('active');
  326.       $(event.target.parentElement).toggleClass('active');
  327.     }
  328.     else if(tabName=="cust"){
  329.     $('.custContainer').toggleClass('active');
  330.     $('.preContainer').toggleClass('active');
  331.     $(event.target.parentElement.parentElement.children).removeClass('active');
  332.      $(event.target.parentElement).toggleClass('active');
  333.   }
  334. }
  335. };
  336.  
  337.   angular.element(document).ready(function (){
  338.     $scope.$on('onRepeatLastDemo', function(scope, element, attrs){
  339.           var columns= 4;
  340.           gridCtrl.createGrid("#demoGridContainer",3,true);
  341.           $("div#audience").removeClass("tappLoader");
  342.           /*$scope.resizeGridSiblings(); */
  343.       });
  344.     $scope.$on('onRepeatLastBeh', function(scope, element, attrs){
  345.           var columns= 4;
  346.           gridCtrl.createGrid("#behGridContainer",3,true);
  347.           $("div#audience").removeClass("tappLoader");  
  348.       });
  349.       $http.get('assets/data/audienceDemographics.json').
  350.         success(function(data, status, headers, config) {
  351.           $scope.audienceDemographics = data;
  352.           $scope.demoFlag="demographic";
  353.           }).
  354.         error(function(data, status, headers, config) {
  355.             console.log("Error fetching demographic distribution");
  356.           });
  357.       $http.get('assets/data/audienceBehavioral.json').
  358.         success(function(data, status, headers, config) {
  359.           $scope.audienceBehavioral = data;
  360.           $scope.behFlag="behavioral";
  361.           }).
  362.         error(function(data, status, headers, config) {
  363.           console.log("Error fetching behavioral distribution");
  364.         });  
  365.     });
  366.    $scope.updatePlan = function(custCategory,name,value){
  367.     $scope.planObject.audience[custCategory][name].push(value);
  368.     localStorageService.remove("plan");
  369.     localStorageService.set("plan",$scope.planObject);
  370.     /*To do - update only the audience part of the plan object OR
  371.     Do only one transaction with all changes together. This will save time*/
  372.   };
  373.   $scope.itemClick = function(custCategory,obj, $event){
  374.       $event.stopPropagation();
  375.       obj[custCategory]["isSelected"] = "true";
  376.       gridCtrl.cellClicked($($event.currentTarget));
  377.     };/*End of itemClick event*/
  378.  
  379.   $scope.subItemClick = function(custCategory,obj,$event){
  380.     //alert("subitemClcik");
  381.     $event.stopPropagation();
  382.     gridCtrl.subSectionItemClick($($event.currentTarget));
  383.     if(obj["subItemValue"]["isSelected"] == "true"){
  384.           obj["subItemValue"]["isSelected"] = "false";
  385.  
  386.         }
  387.         else if(obj["subItemValue"]["isSelected"] == "false") {
  388.           if(obj[custCategory]["isMultiSelect"] == "false")
  389.           {
  390.            $(obj[custCategory]["values"]).each(function(index, val){
  391.             val["isSelected"] = "false";
  392.            });
  393.           }
  394.           obj["subItemValue"]["isSelected"] = "true";
  395.        }
  396.     //alert("1");
  397.     var values = obj[custCategory]["values"];
  398.     var name = obj[custCategory]["name"];
  399.     //alert("2");
  400.     var selEval = $scope.selEval(obj, custCategory, obj[custCategory]["keyid"]);
  401.     if(selEval){
  402.       $scope.planObject.audience[custCategory][name] = [];
  403.       $.each(values, function(i, item){
  404.  
  405.       if(item.isSelected==="true"){
  406.         var key = item["subkeyid"];
  407.         var value = item["value"];
  408.         $scope.updatePlan(custCategory,name,value);
  409.         }
  410.       });
  411.     }
  412.     //$event.stopPropagation();
  413.     //alert("calling stopPropagation");
  414.    
  415.     //$event.
  416.   };/*End of subitemClick event*/
  417.  
  418.   $scope.clearSubItems = function(custCategory,obj,event){
  419.     event.stopPropagation();
  420.     $(obj[custCategory]["values"]).each(function(index, item){
  421.       item["isSelected"]="false";
  422.     });
  423.     gridCtrl.clearSubOptions($(event.currentTarget));
  424.     var values = obj[custCategory]["values"];
  425.     var name = obj[custCategory]["name"];
  426.     var selEval = $scope.selEval(obj, custCategory, obj[custCategory]["keyid"]);
  427.     if(selEval){
  428.       $scope["planObject"]["audience"][custCategory][name] = [];
  429.       $.each(values, function(i, item){
  430.       if(item["isSelected"]==="true"){
  431.         var key = item["subkeyid"];
  432.         var value = item["value"];
  433.         $scope.updatePlan(custCategory,name,value);
  434.         }
  435.       });
  436.     }
  437.   };/*End of clearSubItems function*/
  438.   $scope.doneWithSubItem = function(custCategory,obj,event){
  439.     event.stopPropagation();
  440.     gridCtrl.doneSubOptionClick($(event.currentTarget));
  441.   };/*End of doneWithSubItem Function*/
  442.  
  443.   $scope.selEval = function(obj,custCategory, id){
  444.     var returnVal = false;
  445.     /*At time of evaluation, the item is active: sub items may or may not be checked*/
  446.     if(obj[custCategory]["isSelected"] === "true"){
  447.       var values = obj[custCategory]["values"];
  448.       var subItemSelected = false;/*Sub items exist*/
  449.       var dupe = false;/*Item already exist in custSelList*/
  450.       $.each(values, function(i, item){
  451.         if(item["isSelected"]==="true"){
  452.           subItemSelected=true;
  453.           return false;
  454.         }
  455.       });
  456.       if(!subItemSelected){
  457.         $scope["custRemoveItem"](id,true);
  458.         returnVal = true;
  459.       }
  460.       else{
  461.         $.each($scope["custSelList"], function(i, item){
  462.           if(item["keyid"]==id){
  463.             dupe=true;
  464.           }
  465.         });
  466.         if(!(dupe)){
  467.             $scope["custSelList"].push(obj[custCategory]);
  468.             returnVal = true;
  469.           }
  470.       }
  471.     }
  472.     else{
  473.       returnVal = false;
  474.     }
  475.     return returnVal;
  476.   };
  477. $scope.custRemoveItem = function(key, dontChangeCellStatus){
  478.     var index = -1;
  479.     var custSelList = $scope["custSelList"];
  480.     $.each(custSelList, function(i, item){
  481.       if(item["keyid"]==key){
  482.           index=i;
  483.           return false;
  484.         }
  485.       });
  486.     if(index>=0){
  487.       $scope["custSelList"].splice(index,1);
  488.       }
  489.       if($scope["audienceDemographics"].length > 0 && !dontChangeCellStatus){
  490.         index = -1;
  491.         $.each($scope["audienceDemographics"], function(i, item){
  492.         if(item["keyid"]==key){
  493.           index=i;
  494.           return false;
  495.         }
  496.       });
  497.         if(index>=0)
  498.         {
  499.           $scope["audienceDemographics"][index].isSelected = "false";
  500.           $.each($scope["audienceDemographics"][index]["values"], function(i, item){
  501.             item.isSelected = "false";
  502.           });
  503.         }
  504.      
  505.       /*$scope.updatePlan($scope.demoFlag,$scope.audienceDemographics[index].name,value); STUB TO DO*/
  506.        }
  507.       if($scope["audienceBehavioral"].length > 0 && !dontChangeCellStatus){
  508.         index =-1;
  509.           $.each($scope["audienceBehavioral"], function(i, item){
  510.             if(item["keyid"]==key){
  511.               index=i;
  512.               return false;
  513.             }
  514.           });
  515.           if(index>=0)
  516.           {
  517.             $scope["audienceBehavioral"][index]["isSelected"] = "false";
  518.             $.each($scope["audienceBehavioral"][index]["values"], function(i, item){
  519.             item["isSelected"] = "false";
  520.             });
  521.           }
  522.      
  523.           /*$scope.updatePlan($scope.demoFlag,$scope.audienceDemographics[index].name,value); STUB TO DO*/
  524.         }
  525.     if(!dontChangeCellStatus){
  526.       gridCtrl.changeCellStatusByDataKeyId(key,false);
  527.     }
  528.   };
  529.  
  530.        $scope.clearAllSelections= function(){
  531.        while($scope["custSelList"].length>0)
  532.       {
  533.         gridCtrl.changeCellStatusByDataKeyId($scope["custSelList"][0]["keyid"], false);
  534.         $scope["custRemoveItem"]($scope["custSelList"][0]["keyid"]);
  535.       }
  536.     };
  537.  
  538.    $scope["tempMediaPlan"] = '';
  539.    $scope["closeHH"] = function(){
  540.     $(".hhCountDisplay").hide();
  541.    };
  542.    $scope["updateCanvas"] = function(canvasObj){
  543.     var canvas = canvasObj;
  544.     canvas.parent().show();
  545.    
  546.       var set = [];
  547.       var total = parseFloat($scope["universeHousehold"]);
  548.       var segmentAudience = parseFloat($scope["segmentAudience"]);
  549.       var segAudInPercent = parseFloat(((100*segmentAudience)/total).toFixed(1));
  550.       var remainPercent = 100 - segAudInPercent;
  551.       var r = 80;
  552.       var cx = 0;
  553.       var cy = 0;
  554.       var x1=0;
  555.       var y1 =0;
  556.       var tempAngle = 0;
  557.      
  558.       var w = parseInt(canvas.css('width'),10);
  559.       var h = parseInt(canvas.css('height'),10);
  560.       var p = canvas.parent();
  561.       p.css("top",$(".audFooter").offset().top-h-12);
  562.       p.css("left",$("#hhCanvasTrigger").offset().left-35);
  563.       var ctx = canvas[0].getContext('2d');
  564.       ctx.save();
  565.  
  566.       ctx.font = "normal 14px sans-serif";
  567.       ctx.translate(w/2,h/2);
  568.       //ctx.fillStyle = "#585E6B";
  569.       ctx.rect(-w/2,-h/2,w,h);
  570.       ctx.fillStyle = "#585E6B";
  571.       ctx.fill();
  572.       ctx.strokeStyle="#585E6B";
  573.       ctx.beginPath();
  574.       ctx.arc(cx,cy,r,0,2*Math.PI);
  575.       ctx.fillStyle = "#31dbd2";
  576.       ctx.fill();
  577.       if(segAudInPercent>0)
  578.       {
  579.         ctx.beginPath();
  580.         var startAngle = 1.75 *Math.PI;
  581.         var endAngle = startAngle + (2 * Math.PI * segAudInPercent/100);
  582.         ctx.arc(cx,cy,r,startAngle,endAngle);
  583.         ctx.fillStyle = "#f27b57";
  584.         ctx.lineTo(cx,cy);
  585.         x1 = r * Math.cos(startAngle);
  586.         y1 = r * Math.sin(startAngle);
  587.         ctx.lineTo(x1,y1);
  588.        
  589.         ctx.fill();
  590.         ctx.stroke();
  591.  
  592.         tempAngle = startAngle + (endAngle-startAngle)/2;
  593.         x1 = (r-50) * Math.cos(tempAngle);
  594.         y1 = (r-50) * Math.sin(tempAngle);
  595.         ctx.fillStyle = "white";
  596.         //ctx.strokeStyle = "white"
  597.         ctx.fillText(segAudInPercent+" %",x1,y1);
  598.       }
  599.      
  600.       ctx.fillText("Household Count: "+$scope.segmentHousehold,cx-70,cy+r+25);
  601.       //data[0].sSegmentAudience;
  602.       ctx.restore();
  603.    };
  604.     $scope.sendHhCount = function(canvasId){
  605.       var canvas = $(canvasId);
  606.       if(canvas.parent().css("display") !="none")
  607.       {
  608.         canvas.parent().hide();return;
  609.       }
  610.       $http.get('assets/data/hhRequest.json').
  611.       success(function(response){
  612.         $scope["tempMediaPlan"] = JSON.parse(JSON.stringify(response));
  613.         $.ajax({
  614.           url:'/TAPP2_MDP1/cablevision/MediaPlan/householdAudience',
  615.           data: JSON.stringify($scope["tempMediaPlan"]),
  616.           type:"POST",
  617.           contentType: "application/json",
  618.           success: function(response){
  619.             var hhData = JSON.parse(JSON.stringify(data));
  620.             $scope["universeHousehold"] = hhData[0]["sUniverseHousehold"];
  621.             $scope["segmentAudience"] = hhData[0]["sSegmentAudience"];
  622.             $scope["segmentHousehold"] = hhData[0]["sSegmentHousehold"];
  623.  
  624.             $('.hhCountDisplay').show().fadeIn('slow');
  625.             $scope.updateCanvas(canvas);
  626.           },
  627.           error:function(){
  628.             $http.get('assets/data/hhResponse.json').
  629.             success(function(data, status, headers, config) {
  630.             var hhData = JSON.parse(JSON.stringify(data));
  631.             $scope["universeHousehold"]=hhData[0]["sUniverseHousehold"];
  632.             $scope["segmentAudience"]=hhData[0]["sSegmentAudience"];
  633.             $scope["segmentHousehold"]=hhData[0]["sSegmentHousehold"];
  634.             $scope["updateCanvas"](canvas);
  635.             });
  636.           }
  637.         });//end of inner AJAX
  638.  
  639.       }).
  640.       error(function(data, status, headers, config) {
  641.         console.log("Error fetching HH request from LS");
  642.       });
  643.      
  644.    };
  645.        /*Audience code ends*/
  646. }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement