AIA.controller("3dAController", ["$scope", "$rootScope", "pages", "$log", '$http', 'DataService', '$filter', '$location', '$document', '$sce', "$compile", "$timeout", "ModuleService", "$interval",
function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location, $document, $sce, $compile, $timeout, ModuleService, $interval) {
$scope.ObjectAttribute=function(windowviewid)
{
var windata={
'multiwinid': windowviewid,
'threeDAnatomyData': [],
'ImagePath': '',
'moduleName': '',
'currentViewTitle': '',
'parentSlugName': '',
'currentSlug': '',
'imageId': '',
'y': 0,
'x': 0,
'width': 0,
'height': 0,
'minimised': false,
'maximised': true,
'minmaxAutoEvent':true,
};
return windata;
}
$scope.initialize3DWindowData = function (windowviewid, isOpenWithExistsModule, openPanelNo) {
if (isOpenWithExistsModule || openPanelNo == 0) {
if ($rootScope.TheeDWindowData != undefined) {
$rootScope.TheeDWindowData.length = 0;
}
else {
$rootScope.TheeDWindowData = [];
}
$rootScope.TheeDWindowData.push($scope.ObjectAttribute(windowviewid));
}
else {
var isNewWindow = true;
for (var k = 0; k < $rootScope.TheeDWindowData.length; k++) {
if ($rootScope.TheeDWindowData[k].multiwinid == windowviewid) {
isNewWindow = false;
break;
}
}
if (isNewWindow) {
$rootScope.TheeDWindowData.push($scope.ObjectAttribute(windowviewid));
}
}
}
$scope.Get3DwindowStoreData = function (windowviewid, keyname) {
for (var x = 0 ; x < $rootScope.TheeDWindowData.length; x++) {
if ($rootScope.TheeDWindowData[x].multiwinid == windowviewid) {
return $rootScope.TheeDWindowData[x][keyname];
}
}
}
$scope.Set3DwindowStoreData = function (windowviewid, keyname, value) {
for (var x = 0 ; x < $rootScope.TheeDWindowData.length; x++) {
if ($rootScope.TheeDWindowData[x].multiwinid == windowviewid) {
$rootScope.TheeDWindowData[x][keyname] = value;
}
}
}
// access from home controller
$rootScope.Set3DwindowData=function(windowviewid,keyname,data) {
for(var x=0 ;x < $rootScope.TheeDWindowData.length;x++){
if($rootScope.TheeDWindowData[x].multiwinid==windowviewid)
{
$rootScope.TheeDWindowData[x][keyname]=data;
}
}
}
$scope.DisableUI = function () {
var caImagePanelConetent = document.getElementsByClassName("jsPanel-content");
for (var i = 0; i < caImagePanelConetent.length; i++) {
caImagePanelConetent[i].style.pointerEvents = "none";
caImagePanelConetent[i].style.opacity = "0.7";
}
$rootScope.isLoading = true;
$('#spinner').css('visibility', 'visible');
// CB module disable all
$('#HomeContainerDiv').css('pointer-events', 'none');
$('#HomeContainerDiv').css('opacity', '0.7');
}
$scope.EnableUI = function () {
var caImagePanelConetent = document.getElementsByClassName("jsPanel-content");
for (var i = 0; i < caImagePanelConetent.length; i++) {
caImagePanelConetent[i].style.pointerEvents = "auto";
caImagePanelConetent[i].style.opacity = "1";
}
$rootScope.isLoading = false;
$('#spinner').css('visibility', 'hidden');
// CB module enable all
$('#HomeContainerDiv').css('pointer-events', 'auto');
$('#HomeContainerDiv').css('opacity', '1');
}
$scope.loadAIModuleById = function (moduleId) {
$rootScope.isCallFromOtherModule = undefined;
$rootScope.MULTI_VIEW_ID += 1
// store exist module in module service
var ExistData = ModuleService.getModuleData("THREE_D_ANATOMY");
if (ExistData != undefined && ExistData.length > 0) {
// clear all module data before open new module in cb
ModuleService.ClearWinDataByModule(ExistData.mType);
}
var newWindowData = {
"mType": 'THREE_D_ANATOMY',
};
ModuleService.setModuleData(newWindowData, 0);
// close/remove prev panel when in minimised mode
if($rootScope.TheeDWindowData!=undefined)
{
if($rootScope.TheeDWindowData.length>0)
{
for(var x=0 ;x < $rootScope.TheeDWindowData.length;x++){
var winid=$rootScope.TheeDWindowData[x].multiwinid;
if ($('#ThreeDImagePanel_' + winid).html() != undefined) {
$('#ThreeDImagePanel_' + winid).remove();
}
}
$rootScope.TheeDWindowData=[];
}
}
$scope.initialize3DWindowData($rootScope.MULTI_VIEW_ID, true, undefined);
$scope.DisableUI();
if ($rootScope.refreshcheck == null) {
$location.path('/');
}
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;
})
$scope.Set3DwindowStoreData($rootScope.MULTI_VIEW_ID, 'moduleName', "3D Anatomy");
$scope.Load3DJsonData($rootScope.MULTI_VIEW_ID);
$scope.scroll();
};
$scope.scroll = function () {
$("html,body").scrollTop(0);
}
$scope.Load3DJsonData = function (windowviewid) {
var promise = DataService.getJson('~/../content/data/json/3da/3da_dat_contentlist.json')
promise.then(
function (result) {
var threeDAnatomyData = new jinqJs()
.from(result.root.ThreeDAData)
.orderBy([{ field: '_Title', sort: 'asc' }])
.select();
$scope.Set3DwindowStoreData(windowviewid, 'threeDAnatomyData', threeDAnatomyData);
// console.log($scope.selectedCIListViewData);
$('#grid-view').empty();
angular.forEach(threeDAnatomyData, function (value, key) {
$scope.imagePath = "~/../content/images/3da/thumbnails/" + value._ThumbnailImage;
var $el = $('
'
+ '
'
+ '
![]()
'
+ '
').appendTo('#grid-view');
$compile($el)($scope);
$(".sidebar").mCustomScrollbar({
autoHideScrollbar: true,
//theme:"rounded"
});
});
$timeout(function () { $scope.EnableUI(); }, 200);
},
function (error) {
$scope.EnableUI();
// handle errors here
console.log(' $scope.threeDAnatomyData = ' + error.statusText);
}
);
};
$scope.Open3DModel = function ($event) {
// open module bu openresource
var isopenResourceRequest = sessionStorage.getItem('isModuleOpenByOpenResource');
if (isopenResourceRequest == "true") {
//set default module data
var ThreeDopenData = {
"id": $event.currentTarget.id,
"mType": 'THREE_D_ANATOMY',
"windowTitle": $event.currentTarget.textContent,
"size": { height: 600, width: 900 },
"position": { x: 10, y: 30 }
};
window.parent.AIAModuleOpenResourceInfo(ThreeDopenData);
}
else
{
$rootScope.currentBodyViewId = $event.currentTarget.id;
var windowviewid = $rootScope.MULTI_VIEW_ID;
var selectedThreeDAdata = $scope.Get3DwindowStoreData(windowviewid, 'threeDAnatomyData');
if ($event.currentTarget.textContent !== null && typeof ($event.currentTarget.textContent) !== "undefined") {
var ThreeDTitle = [];
ThreeDTitle = new jinqJs()
.from(selectedThreeDAdata)
.where('_id = ' + $event.currentTarget.id)
.select('_Title', '_3dimagepath');
$rootScope.ViewTitle = ThreeDTitle[0]._Title;
}
else {
$rootScope.ViewTitle = $event.currentTarget.textContent;
}
localStorage.setItem("currentViewTitleFromJson", $rootScope.ViewTitle);
localStorage.setItem("currentBodyViewId", $event.currentTarget.id);
var ImagePath = ThreeDTitle[0]._3dimagepath;
$scope.Set3DwindowStoreData(windowviewid, 'currentViewTitle', $rootScope.ViewTitle);
$scope.Set3DwindowStoreData(windowviewid, 'imageId', $event.currentTarget.id);
$scope.Set3DwindowStoreData(windowviewid, 'ImagePath', ImagePath);
var u = $location.url();
$location.url('/3d-anatomy-details');
}
}
$rootScope.Open3DModelBodyMain = function () {
if ($rootScope.isCallFromOtherModule) {
$scope.ThreeDModuleData = ModuleService.getModuleData("THREE_D_ANATOMY");
if($scope.ThreeDModuleData.length<1) return;
$scope.DisableUI();
$scope.readyToLoad = true;
$rootScope.ThreeDWindowLoadComplete = false;
$scope.wincount = 1;
var winlen = $scope.ThreeDModuleData.length;
var timeint = null;
timeint = $interval(function () {
if ($scope.readyToLoad == true) {
var windata = $scope.ThreeDModuleData[$scope.wincount - 1];
$scope.Open3DModelBody(windata);
}
$scope.readyToLoad = false;
if ($scope.wincount < winlen && $rootScope.ThreeDWindowLoadComplete == true) {
$scope.wincount = $scope.wincount + 1;
$rootScope.ThreeDWindowLoadComplete = false;
$scope.readyToLoad = true;
}
if ($scope.wincount == winlen && $rootScope.ThreeDWindowLoadComplete == true) {
$scope.stopInterval();
$scope.$emit("LoadModuleComplete", "THREE_D_ANATOMY");
}
}, 100);
$scope.stopInterval = function () {
if (angular.isDefined(timeint)) {
$interval.cancel(timeint);
timeint = undefined;
}
};
}
else {
$scope.DisableUI();
$scope.Open3DModelBody(null);
}
}
$scope.Open3DModelBody = function (ThreeDModuleData) {
$scope.DisableUI();
if ($rootScope.isCallFromOtherModule == true) {
$scope.ThreeDOpenInOtherModules = ThreeDModuleData;
$rootScope.MULTI_VIEW_ID += 1;
var windowviewid = $rootScope.MULTI_VIEW_ID;
$scope.initialize3DWindowData(windowviewid, false, $scope.ThreeDOpenInOtherModules.currentWindowId);
var moduleName = $scope.ThreeDOpenInOtherModules.mType;
$scope.Set3DwindowStoreData(windowviewid, 'moduleName', moduleName);
var promise = DataService.getJson('~/../content/data/json/3da/3da_dat_contentlist.json');
promise.then(
function (result) {
var imageId = $scope.ThreeDOpenInOtherModules.id;
var clicked3DViewData = [];
clicked3DViewData = new jinqJs().from(result.root.ThreeDAData)
.where('_id == ' + imageId)
.select('_Title', '_3dimagepath');
if (clicked3DViewData.length == 0) {
$rootScope.ThreeDWindowLoadComplete = true
return;
}
$scope.Set3DwindowStoreData(windowviewid, 'imageId', imageId);
var ImagePath = clicked3DViewData[0]._3dimagepath;
$scope.Set3DwindowStoreData(windowviewid, 'ImagePath', ImagePath);
var ThreeDTitle = $scope.ThreeDOpenInOtherModules.anatomyTitle;
$scope.Set3DwindowStoreData(windowviewid, 'currentViewTitle', ThreeDTitle);
localStorage.setItem("currentViewTitle", ThreeDTitle);
var isMaximize = $scope.ThreeDOpenInOtherModules.maximised!=undefined?$scope.ThreeDOpenInOtherModules.maximised:false;
var isMinimize = $scope.ThreeDOpenInOtherModules.minimised!=undefined?$scope.ThreeDOpenInOtherModules.minimised:false;
$scope.Set3DwindowStoreData(windowviewid, 'maximised', isMaximize);
$scope.Set3DwindowStoreData(windowviewid, 'minimised', isMinimize);
if($location.url()== "/curriculum-builder-detail") {
$scope.Set3DwindowStoreData(windowviewid,'parentSlugName',($location.url()).replace('/', ''));
}
else
{
$scope.Set3DwindowStoreData(windowviewid,'parentSlugName','3d-anatomy-list');
}
$scope.load3DAnimation(windowviewid);
},
function (error) {
// handle errors here
console.log(' $scope.CAllustrationData = ' + error.statusText);
}
);
}
else {
$scope.Set3DwindowStoreData($rootScope.MULTI_VIEW_ID, 'parentSlugName', '3d-anatomy-list');
$scope.load3DAnimation($rootScope.MULTI_VIEW_ID);
}
}
$scope.load3DAnimation = function (windowviewid) {
if ($rootScope.refreshcheck == null) {
$location.path('/');
}
$scope.jsPanelID = 'ThreeDImagePanel' + '_' + windowviewid;
var Selected3DImagePath = $scope.Get3DwindowStoreData(windowviewid, 'ImagePath');
var tittle = $scope.Get3DwindowStoreData(windowviewid, 'currentViewTitle');
if ($rootScope.isCallFromOtherModule) {
// open JS panel for curriculum with define cornonate in CB jason
$scope.jsPanelWidth = $scope.ThreeDOpenInOtherModules.size.width;//1000;
if ($scope.ThreeDOpenInOtherModules.size.width < 900)
$scope.jsPanelWidth = 900;
$scope.jsPanelHeight = $scope.ThreeDOpenInOtherModules.size.height;
if ($scope.ThreeDOpenInOtherModules.size.height < 560)
$scope.jsPanelHeight = 560;
$scope.jsPanelLeft = $scope.ThreeDOpenInOtherModules.position.x;
if ($scope.ThreeDOpenInOtherModules.position.x < 20)
$scope.jsPanelLeft = 20;
$scope.jsPanelTop = $scope.ThreeDOpenInOtherModules.position.y;
if ($scope.ThreeDOpenInOtherModules.position.y < 35)
$scope.jsPanelTop = 35;
if($location.url()!= "/curriculum-builder-detail") {
$scope.jsPanelLeft = 20;
$scope.jsPanelTop = 100;
}
}
else {
$scope.jsPanelWidth = $(window).outerWidth() - 20;
$scope.jsPanelHeight = $(window).outerHeight() - 90;
$scope.jsPanelLeft = 1;
$scope.jsPanelTop = 70;
}
if (Selected3DImagePath.length > 0) {
$scope.jsPanel3D =
$.jsPanel({
id: $scope.jsPanelID,
selector: '.threeDView',
theme: 'success',
currentController: '3dAController',
parentSlug: $scope.Get3DwindowStoreData(windowviewid, 'parentSlugName'),
content: '' +
'' +
'
',
title: tittle,
position: {
top: $scope.jsPanelTop,
left: $scope.jsPanelLeft
},
size: {
width: $scope.jsPanelWidth,
height: $scope.jsPanelHeight
},
onminimized:function (panel) {
var pnlName=panel[0].id;
var len = (pnlName).split("_").length;
var windowviewid = (pnlName).split("_")[len - 1];
var isAutoCalled = $scope.Get3DwindowStoreData(windowviewid, 'minmaxAutoEvent');
if(!isAutoCalled)
{
$rootScope.UnsaveCurriculum = true;
}
$scope.Set3DwindowStoreData(windowviewid, 'minimised',true);
$scope.Set3DwindowStoreData(windowviewid, 'maximised',false);
},
onmaximized:function (panel) {
var pnlName=panel[0].id;
var len = (pnlName).split("_").length;
var windowviewid = (pnlName).split("_")[len - 1];
var isAutoCalled = $scope.Get3DwindowStoreData(windowviewid, 'minmaxAutoEvent');
if(!isAutoCalled)
{
$rootScope.UnsaveCurriculum = true;
}
$scope.Set3DwindowStoreData(windowviewid, 'maximised',true);
$scope.Set3DwindowStoreData(windowviewid, 'minimised',false);
},
onnormalized:function (panel) {
var pnlName=panel[0].id;
var len = (pnlName).split("_").length;
var windowviewid = (pnlName).split("_")[len - 1];
var isAutoCalled = $scope.Get3DwindowStoreData(windowviewid, 'minmaxAutoEvent');
if(!isAutoCalled)
{
$rootScope.UnsaveCurriculum = true;
}
$scope.Set3DwindowStoreData(windowviewid, 'minimised',false);
$scope.Set3DwindowStoreData(windowviewid, 'maximised',false);
$rootScope.resetMenuOptionOnClick(pnlName);
},
resizable: {
stop: function (event, ui) {
var pnlName=event.currentTarget.id;
var len = (pnlName).split("_").length;
var windowviewid = (pnlName).split("_")[len - 1];
$scope.Set3DwindowStoreData(windowviewid, 'width', ui.size.width);
$scope.Set3DwindowStoreData(windowviewid, 'height', ui.size.height);
$scope.Set3DwindowStoreData(windowviewid, 'y', ui.position.top);
$scope.Set3DwindowStoreData(windowviewid, 'x', ui.position.left);
$rootScope.UnsaveCurriculum = true;
$rootScope.resetMenuOptionOnClick(pnlName);
}
},
draggable: {
stop: function( event, ui ) {
var pnlName=event.currentTarget.id;
var len = (pnlName).split("_").length;
var windowviewid = (pnlName).split("_")[len - 1];
$scope.Set3DwindowStoreData(windowviewid, 'y', ui.position.top);
$scope.Set3DwindowStoreData(windowviewid, 'x', ui.position.left);
$rootScope.UnsaveCurriculum = true;
$rootScope.resetMenuOptionOnClick(pnlName);
}
},
});
var isMaximize = $scope.Get3DwindowStoreData(windowviewid, 'maximised');
var isMinimize = $scope.Get3DwindowStoreData(windowviewid, 'minimised');
if (isMaximize) {
$scope.jsPanel3D.maximize();
}
else if (isMinimize) {
$scope.jsPanel3D.minimize();
}
else {
$scope.jsPanel3D.normalize();
}
// set false after initial call of min,max or normal
$scope.Set3DwindowStoreData(windowviewid, 'minmaxAutoEvent', false);
$scope.Set3DwindowStoreData(windowviewid, 'y', $scope.jsPanelTop);
$scope.Set3DwindowStoreData(windowviewid, 'x', $scope.jsPanelLeft);
$scope.Set3DwindowStoreData(windowviewid, 'width', $scope.jsPanelWidth);
$scope.Set3DwindowStoreData(windowviewid, 'height', $scope.jsPanelHeight);
$rootScope.currentSlug = '3d-anatomy-details';
$scope.Set3DwindowStoreData(windowviewid, 'currentSlug', '3d-anatomy-details');
$rootScope.openViews.push(
{
"module": $rootScope.currentActiveModuleTitle, "bodyView": tittle, "state": 'max', "BodyViewId": $rootScope.currentBodyViewId,
"slug": $scope.Get3DwindowStoreData(windowviewid, 'currentSlug')
});
}
if (!$rootScope.isCallFromOtherModule) {
$('#ThreeDView').css("height", $(window).outerHeight()-10);
$('#ThreeDView').css("width", $(window).outerWidth()-20);
}
//Calling methode for save Js Panel Activity for SaveCB
$scope.PanelActivity();
$("#threedImage_" + windowviewid).css('background-color', 'aliceblue');
}
$scope.AnimationOnLoad = function (windowviewid) {
$scope.EnableUI();
if ($rootScope.isCallFromOtherModule) {
$rootScope.ThreeDWindowLoadComplete = true;
}
$scope.JsPanelMouseEnter(windowviewid);
}
$scope.JsPanelMouseEnter = function (windowviewid) {
//reset option list manager and annotation
//call when module loaded
$rootScope.resetMenuOption();
var timeintval = null;
timeintval = $interval(PointerEventEnableDisable, 5000);
function PointerEventEnableDisable() {
var pointevents = $("#threedImage_" + windowviewid).css('pointer-events');
if (pointevents=='auto') {
$scope.stop3drefresh(timeintval);
timeintval = $interval(PointerEventEnableDisable, 500);
$("#threedImage_" + windowviewid).css('pointer-events', 'none');
}
else if(pointevents=='none')
{
$("#threedImage_" + windowviewid).css('pointer-events', 'auto');
$scope.stop3drefresh(timeintval);
timeintval = $interval(PointerEventEnableDisable, 10000);
}
else
{
//auto clode interval when panel close
$scope.stop3drefresh(timeintval);
}
}
$scope.stop3drefresh = function (timeintval) {
if (angular.isDefined(timeintval)) {
$interval.cancel(timeintval);
timeintval = undefined;
}
};
// call from while open module in CB
//click event not work on object-tag document
//so then add mouseenter
//remove pre event
$("#ThreeDImagePanel_" + windowviewid).off("mouseenter mouseout");
$("#ThreeDImagePanel_" + windowviewid).on('mouseenter mouseout', function (event) {
//after drawing annotation click not work on iPad/Android device
var pnlName = event.currentTarget.id;
$rootScope.resetMenuOptionOnClick(pnlName);
});
}
$scope.RemoveJSPanel = function (panelid) {
var len = (panelid).split("_").length;
var windowviewid = (panelid).split("_")[len - 1];
// remove old stored data after close panel
for (var index = 0 ; index < $rootScope.TheeDWindowData.length; index++) {
if ($rootScope.TheeDWindowData[index].multiwinid == windowviewid) {
if (index != -1) {
// remove module which one is loaded
$rootScope.TheeDWindowData.splice(index, 1);
if ($('#' + panelid).html() != undefined) {
$('#' + panelid).remove();
}
// $rootScope.resetjsPanelTop(panelid);
}
}
}
}
//Created method by Sandeep for Save JSPanel Activity on the CB module
$scope.PanelActivity = function () {
$(document).on("click", "#" + $scope.jsPanelID + " .jsPanel-hdr .jsPanel-hdr-r .jsPanel-btn-close .jsglyph-remove", function (event) {
var panelid = $(event.target).parent().parent().parent().parent().attr('id');
$scope.RemoveJSPanel(panelid);
});
}
}]);
function AnimationOnLoad(event) {
console.log('animation loaded')
var scope = angular.element(document.getElementById("ThreeDView")).scope();
// var len = (event.target.id).split("_").length;
var windowviewid = (event.target.id).split("_")[1];
scope.$apply(function () {
scope.AnimationOnLoad(windowviewid);
});
}