'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': '', 'top': 0, 'left': 0, 'width': 0, 'height': 0, 'minimised': false, 'maximised': false, '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.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 $scope.PICWindowData.splice(index, 1); if ($('#' + panelid).html() != undefined) { $('#' + panelid).remove(); } $rootScope.resetjsPanelTop(panelid); } } } } $scope.PanelActivity = function () { $("#" + $scope.jsPanelID).resizable({ stop: function (event, ui) { var len = (event.currentTarget.id).split("_").length; var windowviewid = (event.currentTarget.id).split("_")[len - 1]; $scope.SetPICwindowStoreData(windowviewid, 'width', ui.size.width); $scope.SetPICwindowStoreData(windowviewid, 'height', ui.size.height); } }); $("#" + $scope.jsPanelID).draggable({ stop: function (event, ui) { var len = (event.currentTarget.id).split("_").length; var windowviewid = (event.currentTarget.id).split("_")[len - 1]; //var offSets = $(this).offset(); var postions = (this).position(); (this).offsetTop (this).offsetLeft $scope.SetPICwindowStoreData(windowviewid, 'top', ui.position.top); $scope.SetPICwindowStoreData(windowviewid, 'left', ui.position.left); } }); // close panel $(document).on("click", "#" + $scope.jsPanelID + " .jsPanel-hdr .jsPanel-hdr-r .jsPanel-btn-close .jsglyph-remove", function () { 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"); $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; var isMinimize = $scope.picOpenInOtherModules.minimised; $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 = 320; $scope.jsPanelTop = $rootScope.cBModulejsPanelTop(); if($location.url()!= "/curriculum-builder-detail") { $scope.jsPanelLeft = 1; } $scope.jsPanelPIC = $.jsPanel({ id: $scope.jsPanelID, selector: '.picView', theme: 'success', currentController: 'MyPictureController', parentSlug: $scope.GetPICwindowStoreData(windowviewid, 'parentSlugName'), content: '