'use strict'; AIA.controller("MyPictureController", ["$scope", "$window", "$rootScope", "$compile", "$http", "$log", "$location", "$timeout","ModuleService", "$interval", function ($scope, $window, $rootScope, $compile, $http, log, $location, $timeout, ModuleService, $interval) { $scope.ObjectAttribute=function(windowviewid) { var windata={ 'multiwinid': windowviewid, 'imageSource': [], 'moduleName': '', 'currentViewTitle': '', 'parentSlugName': '', 'currentSlug': '', 'imageId': '', 'y': 0, 'x': 0, 'width': 0, 'height': 0, 'minimised': false, 'maximised': false, 'minmaxAutoEvent':true, 'annotationData':{shapeStates:[],paintCanvasState:[]}, }; return windata; } $scope.initializePICWindowData = function (windowviewid, isOpenWithExistsModule, openPanelNo) { if (isOpenWithExistsModule || openPanelNo == 0) { if ($rootScope.PICWindowData != undefined) { $rootScope.PICWindowData.length = 0; } else { $rootScope.PICWindowData = []; } $rootScope.PICWindowData.push($scope.ObjectAttribute(windowviewid)); } else { var isNewWindow = true; for (var k = 0; k < $rootScope.PICWindowData.length; k++) { if ($rootScope.PICWindowData[k].multiwinid == windowviewid) { isNewWindow = false; break; } } if (isNewWindow) { $rootScope.PICWindowData.push($scope.ObjectAttribute(windowviewid)); } } } $scope.GetPICwindowStoreData = function (windowviewid, keyname) { for (var x = 0 ; x < $rootScope.PICWindowData.length; x++) { if ($rootScope.PICWindowData[x].multiwinid == windowviewid) { return $rootScope.PICWindowData[x][keyname]; } } } $scope.SetPICwindowStoreData = function (windowviewid, keyname, value) { for (var x = 0 ; x < $rootScope.PICWindowData.length; x++) { if ($rootScope.PICWindowData[x].multiwinid == windowviewid) { $rootScope.PICWindowData[x][keyname] = value; } } } // access from home controller $rootScope.GetPICwindowData=function(windowviewid,keyname) { for(var x=0 ;x < $rootScope.PICWindowData.length;x++){ if($rootScope.PICWindowData[x].multiwinid==windowviewid) { return $rootScope.PICWindowData[x][keyname]; } } } // access from home controller $rootScope.SetPICwindowData=function(windowviewid,keyname,data) { for(var x=0 ;x < $rootScope.PICWindowData.length;x++){ if($rootScope.PICWindowData[x].multiwinid==windowviewid) { $rootScope.PICWindowData[x][keyname]=data; } } } $scope.DisableUI = function () { var myImagePanelConetent = document.getElementsByClassName("jsPanel-content"); for (var i = 0; i < myImagePanelConetent.length; i++) { myImagePanelConetent[i].style.pointerEvents = "none"; myImagePanelConetent[i].style.opacity = "0.7"; } $rootScope.isLoading = true; $('#spinner').css('visibility', 'visible'); // CB module disable all $('#CBDetailPageDiv').css('pointer-events', 'none'); $('#CBDetailPageDiv').css('opacity', '0.7'); } $scope.EnableUI = function () { var myImagePanelConetent = document.getElementsByClassName("jsPanel-content"); for (var i = 0; i < myImagePanelConetent.length; i++) { myImagePanelConetent[i].style.pointerEvents = "auto"; myImagePanelConetent[i].style.opacity = "1"; } $rootScope.isLoading = false; $('#spinner').css('visibility', 'hidden'); // CB module enable all $('#CBDetailPageDiv').css('pointer-events', 'auto'); $('#CBDetailPageDiv').css('opacity', '1'); } $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.PICWindowData.length; index++) { if ($rootScope.PICWindowData[index].multiwinid == windowviewid) { if (index != -1) { // remove module which one is loaded $rootScope.PICWindowData.splice(index, 1); if ($('#' + panelid).html() != undefined) { $('#' + panelid).remove(); } // $rootScope.resetjsPanelTop(panelid); } } } } $scope.PanelActivity = function () { // close panel $(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); }); } $rootScope.OpenMyPictureViewMain = function () { if ($rootScope.isCallFromOtherModule) { $scope.PicModuleData = ModuleService.getModuleData("MY_PICTURES"); if($scope.PicModuleData.length<1) return; $scope.DisableUI(); $scope.readyToLoad = true; $rootScope.PicLoadComplete = false; $scope.wincount = 1; var winlen = $scope.PicModuleData.length; var timeint = null; timeint = $interval(function () { if ($scope.readyToLoad == true) { var windata = $scope.PicModuleData[$scope.wincount - 1]; $scope.OpenPictureView(windata); } $scope.readyToLoad = false; if ($scope.wincount < winlen && $rootScope.PicLoadComplete == true) { $scope.wincount = $scope.wincount + 1; $rootScope.PicLoadComplete = false; $scope.readyToLoad = true; } if ($scope.wincount == winlen && $rootScope.PicLoadComplete == true) { $scope.stopInterval(); $scope.$emit("LoadModuleComplete", "MY_PICTURES"); } }, 100); $scope.stopInterval = function () { if (angular.isDefined(timeint)) { $interval.cancel(timeint); timeint = undefined; } }; } } $scope.OpenPictureView = function (picModuleData) { $scope.picOpenInOtherModules = picModuleData; $rootScope.MULTI_VIEW_ID += 1; var windowviewid = $rootScope.MULTI_VIEW_ID; $scope.initializePICWindowData(windowviewid, false, $scope.picOpenInOtherModules.currentWindowId); var moduleName = $scope.picOpenInOtherModules.mType; $scope.SetPICwindowStoreData(windowviewid, 'moduleName', moduleName); // serial no of imageid var imageId = $scope.picOpenInOtherModules.id; $scope.SetPICwindowStoreData(windowviewid, 'imageId', imageId); var imageSource=$scope.picOpenInOtherModules.imageSource; $scope.SetPICwindowStoreData(windowviewid, 'imageSource', imageSource); var aiTitle = $scope.picOpenInOtherModules.anatomyTitle; $scope.SetPICwindowStoreData(windowviewid, 'currentViewTitle', aiTitle); localStorage.setItem("currentViewTitle", aiTitle); var isMaximize = $scope.picOpenInOtherModules.maximised!=undefined?$scope.picOpenInOtherModules.maximised:false; var isMinimize = $scope.picOpenInOtherModules.minimised!=undefined?$scope.picOpenInOtherModules.minimised:false; $scope.SetPICwindowStoreData(windowviewid, 'maximised', isMaximize); $scope.SetPICwindowStoreData(windowviewid, 'minimised', isMinimize); // store image for export $rootScope.StoreTitleName(aiTitle); $rootScope.StoreOrgImageName(aiTitle); if($location.url()== "/curriculum-builder-detail") { $scope.SetPICwindowStoreData(windowviewid,'parentSlugName',($location.url()).replace('/', '')); } else { $scope.SetPICwindowStoreData(windowviewid,'parentSlugName','');//back to home screen } $scope.loadMyPicture(windowviewid); } $scope.loadMyPicture = function (windowviewid) { $scope.jsPanelID = 'picImagePanel' + '_' + windowviewid; var selectedpicture = $scope.GetPICwindowStoreData(windowviewid, 'imageSource'); if (selectedpicture.indexOf('base64') == -1) { selectedpicture="data:image/png;base64,"+selectedpicture; } var tittle = $scope.GetPICwindowStoreData(windowviewid, 'currentViewTitle'); // open JS panel for curriculum with define cornonate in CB jason $scope.jsPanelWidth = $scope.picOpenInOtherModules.size.width;//1000; $scope.jsPanelHeight = $scope.picOpenInOtherModules.size.height; if ($scope.picOpenInOtherModules.size.height < 540) $scope.jsPanelHeight = 540; $scope.jsPanelLeft = $scope.picOpenInOtherModules.position.x; if ($scope.picOpenInOtherModules.position.x <= 1) $scope.jsPanelLeft = 0; $scope.jsPanelTop = $scope.picOpenInOtherModules.position.y; if ($scope.picOpenInOtherModules.position.y < 30) $scope.jsPanelTop = 30; if($location.url()!= "/curriculum-builder-detail") { $scope.jsPanelLeft = 1; $scope.jsPanelTop = 85; } $scope.jsPanelPIC = $.jsPanel({ id: $scope.jsPanelID, selector: '.picView', theme: 'success', currentController: 'MyPictureController', parentSlug: $scope.GetPICwindowStoreData(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.GetPICwindowStoreData(windowviewid, 'minmaxAutoEvent'); if(!isAutoCalled) { $rootScope.UnsaveCurriculum = true; } $scope.SetPICwindowStoreData(windowviewid, 'minimised',true); $scope.SetPICwindowStoreData(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.GetPICwindowStoreData(windowviewid, 'minmaxAutoEvent'); if(!isAutoCalled) { $rootScope.UnsaveCurriculum = true; } $scope.SetPICwindowStoreData(windowviewid, 'maximised',true); $scope.SetPICwindowStoreData(windowviewid, 'minimised',false); var canvasDIvHeight = $('#picImagePanel_' + windowviewid+ " .jsPanel-content").height(); $('#canvasDivPIC_' + windowviewid).css('height', canvasDIvHeight-5); $rootScope.resetMenuOptionOnClick(pnlName); }, onnormalized:function (panel) { var pnlName=panel[0].id; var len = (pnlName).split("_").length; var windowviewid = (pnlName).split("_")[len - 1]; var isAutoCalled = $scope.GetPICwindowStoreData(windowviewid, 'minmaxAutoEvent'); if(!isAutoCalled) { $rootScope.UnsaveCurriculum = true; } $scope.SetPICwindowStoreData(windowviewid, 'minimised',false); $scope.SetPICwindowStoreData(windowviewid, 'maximised',false); var canvasDIvHeight = $('#picImagePanel_' + windowviewid+ " .jsPanel-content").height(); $('#canvasDivPIC_' + windowviewid).css('height', canvasDIvHeight-5); $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.SetPICwindowStoreData(windowviewid, 'width', ui.size.width); $scope.SetPICwindowStoreData(windowviewid, 'height', ui.size.height); $scope.SetPICwindowStoreData(windowviewid, 'y', ui.position.top); $scope.SetPICwindowStoreData(windowviewid, 'x', ui.position.left); $rootScope.UnsaveCurriculum = true; var canvasDIvHeight = $('#picImagePanel_' + windowviewid+ " .jsPanel-content").height(); $('#canvasDivPIC_' + windowviewid).css('height', canvasDIvHeight-5); $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.SetPICwindowStoreData(windowviewid, 'y', ui.position.top); $scope.SetPICwindowStoreData(windowviewid, 'x', ui.position.left); $rootScope.UnsaveCurriculum = true; $rootScope.resetMenuOptionOnClick(pnlName); } }, }); var isMaximize = $scope.GetPICwindowStoreData(windowviewid, 'maximised'); var isMinimize = $scope.GetPICwindowStoreData(windowviewid, 'minimised'); if (isMaximize) { $scope.jsPanelPIC.maximize(); } else if (isMinimize) { $scope.jsPanelPIC.minimize(); } else { $scope.jsPanelPIC.normalize(); } $rootScope.AllPanelObject(windowviewid,$scope.jsPanelPIC); $("#picImagePanel_"+windowviewid).css('overflow','hidden'); // set false after initial call of min,max or normal $scope.SetPICwindowStoreData(windowviewid, 'minmaxAutoEvent', false); $scope.SetPICwindowStoreData(windowviewid, 'y', $scope.jsPanelTop); $scope.SetPICwindowStoreData(windowviewid, 'x', $scope.jsPanelLeft); $scope.SetPICwindowStoreData(windowviewid, 'width', $scope.jsPanelWidth); $scope.SetPICwindowStoreData(windowviewid, 'height', $scope.jsPanelHeight); $timeout(function () { $scope.SetPICwindowStoreData(windowviewid, 'currentSlug', 'my-picture'); $('.jsPanel-content .jsPanel-theme-success').css('overflow-y', 'auto !important') var canvasDIvHeight = $('#picImagePanel_' + windowviewid+ " .jsPanel-content").height(); $('#canvasDivPIC_' + windowviewid).css('height', canvasDIvHeight-5); var canvas = document.getElementById("canvasPIC_" + windowviewid); var canvasPaint = document.getElementById("canvasPaintPIC_" + windowviewid); var $ua = navigator.userAgent; if (($ua.match(/(iPod|iPhone|iPad|android)/i))) { canvas.width = screen.width-20; canvasPaint.width = screen.width-20; canvas.height = screen.height-130; canvasPaint.height = screen.height-130; } else { canvas.height = screen.height-280; canvasPaint.height = screen.height-280; canvas.width = screen.width-40; canvasPaint.width = screen.width-40; } var openedImage = document.getElementById('mypic_' + windowviewid ); openedImage.src = selectedpicture; openedImage.onload = function () { $scope.JsPanelclick(windowviewid); //some time get big size image if(this.height>780) { canvas.height = this.height; canvasPaint.height = this.height; } var annotationData= $scope.picOpenInOtherModules.annotationData; // load annotation if(annotationData!="" && annotationData!=undefined) { if(annotationData.shapeStates.length>0||annotationData.paintCanvasState.length>0) { //first draw shape and then store in object $rootScope.LoadCBSavedAnnotation("canvasPIC_"+windowviewid,"canvasPaintPIC_"+windowviewid,annotationData); } } $scope.EnableUI(); $rootScope.PicLoadComplete = true; } $scope.PanelActivity(); },300) } $rootScope.picAnnotationToolEvent = function (windowviewid) { $('#editstylebackgroundcolor .minicolors >.minicolors-swatch > .minicolors-swatch-color').css("background-color", "rgb(255,255,255)") $('#editstylebackgroundcolor .minicolors >.minicolors-panel > .minicolors-grid >.minicolors-picker').css({ "top": "145px", "left": "4px" }); $('#outlineColor .minicolors >.minicolors-swatch > .minicolors-swatch-color').css("background-color", "rgb(0,0,0)") $('#outlineColor .minicolors >.minicolors-panel > .minicolors-grid >.minicolors-picker').css({ "top": "145px", "left": "4px" }); $('#canvasPIC_'+windowviewid).css("display", "block"); $('#canvasPaintPIC_'+windowviewid).css("display", "block"); } $scope.JsPanelclick = function (windowviewid) { //reset option list manager and annotation //call when module loaded $rootScope.resetMenuOption(); //remove pre event // $("#picImagePanel_" + windowviewid).off("click"); $("#picImagePanel_" + windowviewid).on('click', function (event) { //after drawing annotation click not work on iPad/Android device var pnlName = event.currentTarget.id; $rootScope.resetMenuOptionOnClick(pnlName); // store image for export while click on panel var currentViewTitle = $scope.GetPICwindowStoreData(windowviewid, 'currentViewTitle'); $rootScope.StoreTitleName(currentViewTitle); $rootScope.StoreOrgImageName(currentViewTitle); }); } }])