DAController.js 3.67 KB
'use strict';

AIA.controller("DAController", ["$scope", "$compile", "$http", "$log", "$location", "$timeout","DA",
    function ($scope, $compile,$http, $log, $location, $timeout,DA ) {

        $scope.genderId = "";
        $scope.BodyViewData = null;
        $scope.selectedGenderBodyViewData = null;
        $scope.imagePath = "";



        //get the DA body view list based on selected gender
        $scope.getDAViewList = function ($event) {

          
            $("#bodyViewList").empty();
            //for default load
            if ($event == null) {
                $scope.genderId = "Male";
            }
            else {
                $scope.genderId = $event.currentTarget.id;
            }
                $scope.selectedGenderBodyViewData = new jinqJs()
               .from($scope.BodyViewData.BodyViews.view)
               .where('_gender == ' + $scope.genderId)
               .select();
           

                angular.forEach($scope.selectedGenderBodyViewData, function (value, key) {
                    
                     var userEthnicity = DA[0].ethnicity;
                     var userModestysettings = DA[0].modesty;
                    var userSelectedSkintone = 'W';
                    $scope.userModestySetting = 'Y'
                    var thumbnailImage = ((value._thumbnailImage).replace('.jpg', '_' + userEthnicity + userModestysettings)) + '.jpg';
                    $scope.imagePath = "http://localhost/AIA/content/images/DA/BodyViews/" + value._id + '/skintone/' + userEthnicity + '/' + thumbnailImage;
                  
                    $scope.isImageExists = $scope.checkImgExistance($scope.imagePath);
                    //debugger
                 
                    if ($scope.isImageExists == false) {
                        $scope.imagePath = ($scope.imagePath).replace($scope.userModestySetting, "");
                    }
                       
                    //debugger
                    var $el = $('<div id=' + value._id + ' class="col-sm-3 col-lg-2" data-ng-click="openView($event)"><div class="thumbnail" >'
                                              + '<img class= "daImg" id="' + value._title + '" src="' + $scope.imagePath + '" alt="" title="" >'
                                              + '<div class="caption"><p>' + value._title + '</p></div></a></div></div>').appendTo('#bodyViewList');
                    $compile($el)($scope);
                   

                });
           
        };
       
        $scope.checkImgExistance = function (imagePath) {
            var result = "";
            $.ajax({
                url: imagePath,
                success: function (data) {

                    result = true;

                },
                error: function (data) {

                    result = false;

                },
            })
           debugger
            return result;
        }

       
      
        $scope.openView = function ($event) {
            alert('clicked: ' + $event.currentTarget.id)
        }


        //load json data for body view
        $scope.loadBodyViewData = function () {
            $http({ method: 'GET', url: 'http://localhost/AIA/content/data/json/da_dat_contentlist.json' }).success(function (data) {

                $scope.BodyViewData = data;
                //load default body view list for male
                $scope.getDAViewList();
                
            })
           .error(function (data, status, headers, config) {
               console.log(data);
           });
        }


        angular.element(document).ready(function () {


       
        })

    }]



);