3dAController.js 8.57 KB
AIA.controller("3dAController", ["$scope", "$rootScope", "pages", "$log", '$http', 'DataService', '$filter', '$location', '$document', '$sce', "$compile",
function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location, $document, $sce, $compile) {

  
    $scope.showTabButton = false;
    $scope.threeDAnatomyData;
    $scope.Id;
    $scope.$on('$viewContentLoaded', function (event) {
        var currentURL = $location.path();
        var selectedModuleName = '';
        //set module title
        angular.forEach($rootScope.userModules, function (value, key) {
          //  if (value.slug === currentURL.replace('/', '')) {
            if (value.slug === "3d-anatomy-list") {
            selectedModuleName = value.name;
            }
            $rootScope.currentActiveModuleTitle = selectedModuleName;
        })
        if ($rootScope.refreshcheck == null) {
            $location.path('/');
        }
        $scope.scroll();
        var promise = DataService.getJson('~/../content/data/json/3da/3da_dat_contentlist.json')
        promise.then(
                  function (result) {
                      $scope.threeDAnatomyData = result;

                      // $scope.selectedThreeDAdata = $scope.threeDAnatomyData.root.ThreeDAData;

                      $scope.selectedThreeDAdata = new jinqJs()
                                                      .from($scope.threeDAnatomyData.root.ThreeDAData)
                                                      .orderBy([{ field: '_Title', sort: 'asc' }])
                                                      .select();

                      // console.log($scope.selectedCIListViewData);
                      $('#grid-view').empty();
                      angular.forEach($scope.selectedThreeDAdata, function (value, key) {
                          $scope.imagePath = "~/../content/images/3da/thumbnails/" + value._ThumbnailImage;

                          var $el = $('<div id="3dView' + value._id + '" class="col-sm-3 col-md-2" title = "' + value._Title + '">'
                              + '<div class="thumbnail">'
                                         + '<img id="' + value._id + '"ng-src="' + $scope.imagePath + '" alt="" title="' + value._Title + '"  data-ng-click="Open3DModel($event)" >'
                                         + '<div class="caption"><p>' + value._Title + '</p></div></div></div>').appendTo('#grid-view');


                          $compile($el)($scope);

                          $(".sidebar").mCustomScrollbar({
                              autoHideScrollbar: true,
                              //theme:"rounded"
                          });

                      });

                  },
                  function (error) {
                      // handle errors here
                      console.log(' $scope.threeDAnatomyData = ' + error.statusText);
                  }
               );

    });
    $scope.scroll = function () {
        // $window.scrollTo(0, 0);
        $("html,body").scrollTop(0);
        //alert("scroll");
    }
    $scope.IsVisible = function () {
        //$scope.scroll();
     
        $location.url("/3dAnatomy");

    }


    $scope.Open3DModel = function ($event) {
        $rootScope.currentBodyViewId = $event.currentTarget.id;
        if ($event.currentTarget.textContent !== null && typeof ($event.currentTarget.textContent) !== "undefined") {
            var ThreeDTitle = [];
            ThreeDTitle = new jinqJs()
                          .from($scope.selectedThreeDAdata)
                          .where('_id = ' + $event.currentTarget.id)
                          .select('_Title');

            $rootScope.ViewTitle = ThreeDTitle[0]._Title;
        }
        else {
            $rootScope.ViewTitle = $event.currentTarget.textContent;

        }


        localStorage.setItem("currentViewTitleFromJson", $rootScope.ViewTitle);
        localStorage.setItem("currentBodyViewId", $event.currentTarget.id);

        var u = $location.url();
        $location.url('/3d-anatomy-details');

    }

    $scope.Open3DModelBody = function () {

        if ($rootScope.refreshcheck == null) {
            $location.path('/');

        }
        $rootScope.isLoading = true;
        $('#spinner').css('visibility', 'visible');
        //alert($rootScope.getLocalStorageValue("currentBodyViewId"));
        $scope.voId3D = $rootScope.getLocalStorageValue("currentBodyViewId");

        //alert($scope.voId3D);


        //once you get id in scope push detail in jspanel content

        var openViews;
        //if ($rootScope.openViews.length > 0) {
        //    openViews = new jinqJs()
        //       .from($rootScope.openViews)
        //       .where("BodyViewId==" + $scope.voId3D)
        //       .select();
        //}
        //var counter = 1;
        var tittle = $rootScope.getLocalStorageValue("currentViewTitleFromJson");
        $rootScope.currentActiveViewTitle = tittle;
        localStorage.setItem("currentViewTitle", tittle);
        //if (openViews != null && openViews.length > 0) {
        //    angular.forEach(openViews, function (value, key) {

        //        if (value.body - views == tittle) {
        //            tittle = $rootScope.getLocalStorageValue("currentViewTitleFromJson") + counter++;
        //            $rootScope.currentActiveViewTitle = tittle;
        //            localStorage.setItem("currentViewTitle", tittle);
        //        }

        //    });
        //}
        //else {
        //    localStorage.setItem("currentViewTitle", tittle);

        //}

        // alert($rootScope.getLocalStorageValue("currentViewTitle"));

        var promise = DataService.getJson('~/../content/data/json/3da/3da_dat_contentlist.json')
        promise.then(
                  function (result) {
                      $scope.threeDAnatomyData = result;

                      var clicked3dAview = [];
                      clicked3dAview = new jinqJs().from($scope.threeDAnatomyData.root.ThreeDAData)
                                                     .where('_id == ' + $scope.voId3D)
                                                     .select('_Title', '_3dimagepath');
                      $scope.Selected3DImagePath = clicked3dAview[0]._3dimagepath;
                      $scope.threeDBodySystemTitle = clicked3dAview[0]._Title;

                      if (clicked3dAview.length > 0) {

                          $rootScope.isLoading = false;
                          $('#spinner').css('visibility', 'hidden');

                          $.jsPanel({
                              id: '3DImagePanel',
                              selector: '.threeDView',
                              theme: 'success',
                              currentController: '3dAController',
                              parentSlug: '3d-anatomy-list',
                              content: '<div class="col-sm-12">' +
                                      '<object data="' + $scope.Selected3DImagePath + '" width="100%" height="800px" type="image/svg+xml"></object>' +
                                      '</div><script>$(document).ready(function(){var $ua = navigator.userAgent; if (($ua.match(/(iPod|iPhone|iPad|android)/i))) {var threeDivWidth = $("#ThreeDView").css("width");$("#ThreeDView").css({"left":"0px","width":"100%","min-idth": threeDivWidth}); var jspanelContainerWidth = $(".jsPanel-content").css("width"); $(".jsPanel-content").css({ "width": "100%", "min-width": jspanelContainerWidth}); $("#3DImagePanel").css("width", "100%"); }});</script>',
                              title: $rootScope.getLocalStorageValue("currentViewTitle"),
                              position: {
                                  top: 70,
                                  left: 1,
                              },

                              size: { width: $(window).outerWidth() - 20, height: $(window).outerHeight() - 10 },

                          });

                          $rootScope.currentSlug = '3d-anatomy-details';

                          $rootScope.openViews.push(
                         {
                             "module": $rootScope.currentActiveModuleTitle, "bodyView": tittle, "state": 'max', "BodyViewId": $rootScope.currentBodyViewId,
                             "slug": $rootScope.currentSlug
                         });


                      }


                  },
                  function (error) {
                      // handle errors here
                      console.log(' $scope.CIllustrationData = ' + error.statusText);
                  }

               );
        $('#ThreeDView').css("height", $(window).outerHeight());

        $('#ThreeDView').css("width", $(window).outerWidth());

    }

          

}]



);