CIController.js 14.5 KB
AIA.controller("CIController", ["$scope", "$window", "$rootScope", "$compile", "$http", "$log", "$location", "pages", "BodyRegions", "BodySystems", "ViewOrientations", "ImageTypes", "MedicalSpecialties", "DataService",
function ($scope, $window, $rootScope, $compile, $http, log,$location, pages, BodyRegions, BodySystems, ViewOrientations, ImageTypes, MedicalSpecialties, DataService) {
    $rootScope.currentActiveModuleTitle = pages[3].name;
    $scope.showme = true;
    $scope.IllustrationData;
    $scope.CIAllBodyRegion = [];
    $scope.CIAllBodySystem = [];
    $scope.CIAllOrientation = [];
    $scope.CIAllImageType = [];
    $scope.CIAllSpeciality = [];
    $scope.searchCIlistViewData = [];
    $scope.SelectedCIthumbImage = [];
    $scope.SelectedCIImage = [];
    $scope.SelectedCISummary=[];
    $scope.filterstring = false;

    $scope.$on('$viewContentLoaded', function (event) {
        // code that will be executed ... 
        // every time this view is loaded

        $scope.CIAllBodyRegion = BodyRegions;
        $scope.CIAllBodySystem = BodySystems;
        $scope.CIAllOrientation = ViewOrientations;
        $scope.CIAllImageType = ImageTypes;
        $scope.CIAllSpeciality = MedicalSpecialties;
        $scope.scroll();

    });

    var promise = DataService.getJson('~/../content/data/json/ci/ci_dat_contentlist.json')
    promise.then(
              function (result) {
                  $scope.IllustrationData = result;
                  $scope.selectedCIlistViewData = $scope.IllustrationData.root.CIData;

                  $('#grid-view').empty();

                  angular.forEach($scope.selectedCIlistViewData, function (value, key) {
                      $scope.imagePath = "~/../content/images/ci/thumbnails/" + value._ThumbnailImage;

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


                      $compile($el)($scope);

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

                  });

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

    $scope.IsVisible = function () {
        $scope.scroll();

    }

    $scope.showItem = function (id) {
        console.log(id);
        $scope.hiderow = true;
        if ($scope.filterstring == false) {

            var SelectedCIthumbImage = [];
            SelectedCIthumbImage = new jinqJs()
                          .from($scope.selectedCIlistViewData)
                          .where('_id = ' + id)
                          .select('_ThumbnailImage');

            $scope.SelectedCIthumbImage = "~/../content/images/ci/thumbnails/" + SelectedCIthumbImage[0]._ThumbnailImage;

            var SelectedCISummary = [];
            SelectedCISummary = new jinqJs()
                          .from($scope.selectedCIlistViewData)
                          .where('_id = '+id)
                          .select('_Summary');

            $scope.SelectedCISummary = SelectedCISummary[0]._Summary
           // alert($scope.SelectedCIImage + "\n" + $scope.SelectedCISummary);
        }
        else {
            if ($scope.searchCIlistViewData.length > 0) {

                var SelectedCIthumbImage = [];
                SelectedCIthumbImage = new jinqJs()
                              .from($scope.searchCIlistViewData)
                              .where('_id = ' + id)
                              .select('_ThumbnailImage');

                $scope.SelectedCIthumbImage = "~/../content/images/ci/thumbnails/" + SelectedCIthumbImage[0]._ThumbnailImage;

                var SelectedCISummary = [];
                SelectedCISummary = new jinqJs()
                              .from($scope.searchCIlistViewData)
                              .where('_id = ' + id)
                              .select('_Summary');

                $scope.SelectedCISummary = SelectedCISummary[0]._Summary
              //  alert($scope.SelectedCIImage + "\n" + $scope.SelectedCISummary);
            }
        }
    };

    $scope.Reset = function (query) {

        query.selectedbodyregion = "";
        query.selectedbodysystem = "";
        query.selectedorientation = "";
        query.selectedimagetype = "";
        query.selectedspecialty = "";
        $scope.filterstring = false;
        while ($scope.searchCIlistViewData.length) {
            $scope.searchCIlistViewData.pop();
        }
        $('#grid-view').empty();

        angular.forEach($scope.selectedCIlistViewData, function (value, key) {
            $scope.imagePath = "~/../content/images/ci/thumbnails/" + value._ThumbnailImage;

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


            $compile($el)($scope);

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

        });

    }

    $scope.ApplySearch = function (query) {

        $scope.filterstring = true;

        while ($scope.searchCIlistViewData.length) {
            $scope.searchCIlistViewData.pop();
        }

        $('#grid-view').empty();

        filtercount = 0;
        if (typeof (query.selectedbodyregion) !== "undefined" && query.selectedbodyregion !== null) {
            filtercount = filtercount + 1;
        }
        if (typeof (query.selectedbodysystem) !== "undefined" && query.selectedbodysystem !== null) {
            filtercount = filtercount + 1;
        }
        if (typeof (query.selectedorientation) !== "undefined" && query.selectedorientation !== null) {
            filtercount = filtercount + 1;
        }
        if (typeof (query.selectedimagetype) !== "undefined" && query.selectedimagetype !== null) {
            filtercount = filtercount + 1;
        }
        if (typeof (query.selectedspecialty) !== "undefined" && query.selectedspecialty !== null) {
            filtercount = filtercount + 1;
        }

        angular.forEach($scope.selectedCIlistViewData, function (value, key) {

            var selectimg = true;
            var count = 0;


            if (typeof (query.selectedbodyregion) !== "undefined" && query.selectedbodyregion !== null)
            {
                var posbodyregion = value._BodyRegion.indexOf((query.selectedbodyregion.trim()));
                if (posbodyregion > -1)
                {
                    selectimg = true;
                    count = count + 1;
                    
                }
                else {
                    selectimg = false;
                    count = count - 1;
                }

            }

            if (typeof (query.selectedbodysystem) !== "undefined" && query.selectedbodysystem !== null)
            {
                var posbodysystem = value._BodySystem.indexOf(query.selectedbodysystem);
                if (posbodysystem > -1) {
                    count = count + 1;
                    selectimg = true;
                } else {
                    selectimg = false;
                    count = count - 1;
                }
            }

            if (typeof (query.selectedorientation) !== "undefined" && query.selectedorientation !== null)
            {
                var posorientation = value._ViewOrientation.indexOf(query.selectedorientation);
                if (posorientation > -1) {
                    count = count + 1;
                    selectimg = true;
                   
                } else {
                    selectimg = false;
                    count = count - 1;
                }

            }

            if (typeof (query.selectedimagetype) !== "undefined" && query.selectedimagetype !== null)
            {
                var posimagetype = value._ImageType.indexOf(query.selectedimagetype);
                if (posimagetype > -1) {
                    count = count + 1;
                    selectimg = true;
                   
                } else {
                    selectimg = false;
                    count = count - 1;
                }

            }

            if (typeof (query.selectedspecialty) !== "undefined" && query.selectedspecialty !== null)
            {
                var posspeciality = value._MedicalSpecialty.indexOf(query.selectedspecialty);
                if (posspeciality > -1)
                {
                    count = count + 1;
                    selectimg = true;
                } else {
                    selectimg = false;
                    count = count - 1;
                }

            }

            if (selectimg === true && count >= filtercount) {


                                    $scope.imagePath = "~/../content/images/ci/thumbnails/" + value._ThumbnailImage;

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


                                    $compile($el)($scope);

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


                                $scope.searchCIlistViewData.push(
                                {
                                    "_id": value._id,
                                    "_ImageId": value._ImageId,
                                    "_Title": value._Title,
                                    "_contentImage": value._contentImage,
                                    "_ThumbnailImage": value._ThumbnailImage,
                                    "_BodySystem": value._BodySystem,
                                    "_BodyRegion": value._BodyRegion,
                                    "_ViewOrientation": value._ViewOrientation,
                                    "_MedicalSpecialty": value._MedicalSpecialty,
                                    "_ImageType": value._ImageType,
                                    "_Summary": value._Summary

                                });

            }

           
        });
    }




    $scope.scroll = function () {
        $("html,body").scrollTop(0);
    }



    $scope.openView = function ($event) {

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


        if ($scope.filterstring == false) {

            var SelectedCIImage = [];
            SelectedCIImage = new jinqJs()
                          .from($scope.selectedCIlistViewData)
                          .where('_id = ' + $event.currentTarget.id)
                          .select('_contentImage');

            $scope.SelectedCIImage = "~/../content/images/ci/images/" + SelectedCIImage[0]._contentImage;

            var SelectedCISummary = [];
            SelectedCISummary = new jinqJs()
                          .from($scope.selectedCIlistViewData)
                          .where('_id = ' + $event.currentTarget.id)
                          .select('_Summary');

            $scope.SelectedCISummary = SelectedCISummary[0]._Summary
          //  alert($scope.SelectedCIImage + "\n" + $scope.SelectedCISummary);
        }
        else {
            if ($scope.searchCIlistViewData.length > 0) {

                var SelectedCIImage = [];
                SelectedCIImage = new jinqJs()
                              .from($scope.searchCIlistViewData)
                              .where('_id = ' + $event.currentTarget.id)
                              .select('_contentImage');

                $scope.SelectedCIImage = "~/../content/images/ci/images/" + SelectedCIImage[0]._contentImage;

                var SelectedCISummary = [];
                SelectedCISummary = new jinqJs()
                              .from($scope.searchCIlistViewData)
                              .where('_id = ' + $event.currentTarget.id)
                              .select('_Summary');

                $scope.SelectedCISummary = SelectedCISummary[0]._Summary
               // alert($scope.SelectedCIImage + "\n" + $scope.SelectedCISummary);
            }
        }


        $.jsPanel({
            position: {
                top: 100,
                left: 1,
            },
            size: { width: $(window).outerWidth() - 40, height: $(window).outerHeight() - 130 },
            title: $event.currentTarget.textContent,
            theme: 'success',
            content: '<div class="row"><div class="col-sm-12 img-thumbnail" align="center">' +
                '<img src="' + $scope.SelectedCIImage + '" alt="" title="" class="img-responsive "></div><div class="col-sm-12 well">'+
                '<div id="sid"><p>' + $scope.SelectedCISummary + '</p></div><button class="btn btn-primary pull-right">Text Off</button><script>$(document).ready(function(){$("button").click(function(){$("#sid").toggle();});});</script></div>' +
                '</div>',
        });

        //var u = $location.url();
        //  $location.url('/ci-detail');

        //$.jsPanel({
        //    id: 'ciImagePanel',
        //    selector: '.ciBodyView',
        //    theme: 'success',
        //    ajax: {
        //        url: 'app/views/ci/ci-detail.html'
        //    },
        //    //title: localStorage.getItem("currentViewTitleFromJson"),
        //    title: "currentViewTitle",
        //    position: {
        //        top: 70,
        //        left: 1,
        //    },

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

        //});


    }


}]


);