'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:[]},
'imgLeft': 0,
};
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.DisablePicUI = function (windowviewid) {
var modulePanel = $("#picImagePanel_"+windowviewid).find(" .jsPanel-content");
if(modulePanel.length>0)
{
modulePanel[0].style.pointerEvents="none";
modulePanel[0].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.EnablePicUI = function (windowviewid) {
var modulePanel = $("#picImagePanel_"+windowviewid).find(" .jsPanel-content");
if(modulePanel.length>0)
{
modulePanel[0].style.pointerEvents="auto";
modulePanel[0].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.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.DisablePicUI(windowviewid);
$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 imgLeft = $scope.picOpenInOtherModules.imgLeft!=undefined?$scope.picOpenInOtherModules.imgLeft:0;
$scope.SetPICwindowStoreData(windowviewid, 'imgLeft', imgLeft);
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];
$scope.SetPICwindowStoreData(windowviewid, 'maximised',true);
$scope.SetPICwindowStoreData(windowviewid, 'minimised',false);
var canvasDIvHeight = $('#picImagePanel_' + windowviewid+ " .jsPanel-content").height()-5;
var canvasDIvWidth = $('#picImagePanel_' + windowviewid+ " .jsPanel-content").width();
var canvasDiv='canvasDivPIC_' + windowviewid;
var canvasDraw='canvasPIC_' + windowviewid;
var canvasPaint='canvasPaintPIC_' + windowviewid;
var imgName='mypic_' + windowviewid;
var isAutoCalled = $scope.GetPICwindowStoreData(windowviewid, 'minmaxAutoEvent');
if(!isAutoCalled)
{
$rootScope.UnsaveCurriculum = true;
var oldleft= $rootScope.GetPICwindowData(windowviewid, 'imgLeft');
var annotationData=$rootScope.GetPICwindowData(windowviewid,'annotationData');
$rootScope.setIMGPanelCordinate(windowviewid,pnlName,canvasDiv,canvasDraw,canvasPaint,imgName,oldleft,canvasDIvHeight,canvasDIvWidth,annotationData);
var img = document.getElementById(imgName);
$rootScope.SetPICwindowData(windowviewid, 'imgLeft',img.offsetLeft);
}
},
onnormalized:function (panel) {
var pnlName=panel[0].id;
var len = (pnlName).split("_").length;
var windowviewid = (pnlName).split("_")[len - 1];
$scope.SetPICwindowStoreData(windowviewid, 'minimised',false);
$scope.SetPICwindowStoreData(windowviewid, 'maximised',false);
var canvasDIvHeight = $('#picImagePanel_' + windowviewid+ " .jsPanel-content").height()-5;
var canvasDIvWidth = $('#picImagePanel_' + windowviewid+ " .jsPanel-content").width();
var canvasDiv='canvasDivPIC_' + windowviewid;
var canvasDraw='canvasPIC_' + windowviewid;
var canvasPaint='canvasPaintPIC_' + windowviewid;
var imgName='mypic_' + windowviewid;
var isAutoCalled = $scope.GetPICwindowStoreData(windowviewid, 'minmaxAutoEvent');
if(!isAutoCalled)
{
$rootScope.UnsaveCurriculum = true;
var oldleft= $rootScope.GetPICwindowData(windowviewid, 'imgLeft');
var annotationData=$rootScope.GetPICwindowData(windowviewid,'annotationData');
$rootScope.setIMGPanelCordinate(windowviewid,pnlName,canvasDiv,canvasDraw,canvasPaint,imgName,oldleft,canvasDIvHeight,canvasDIvWidth,annotationData);
var img = document.getElementById(imgName);
$rootScope.SetPICwindowData(windowviewid, 'imgLeft',img.offsetLeft);
}
},
resizable: {
minWidth: 600,
minHeight: 500,
stop: function (event, ui) {
var pnlName=event.currentTarget.id;
var len = (pnlName).split("_").length;
var windowviewid = (pnlName).split("_")[len - 1];
$rootScope.UnsaveCurriculum = true;
var canvasDIvHeight = $('#picImagePanel_' + windowviewid+ " .jsPanel-content").height();
var canvasDIvWidth = $('#picImagePanel_' + windowviewid+ " .jsPanel-content").width();
$scope.SetPICwindowStoreData(windowviewid, 'width', ui.size.width);
$scope.SetPICwindowStoreData(windowviewid, 'height',canvasDIvHeight);
$scope.SetPICwindowStoreData(windowviewid, 'y', ui.position.top);
$scope.SetPICwindowStoreData(windowviewid, 'x', ui.position.left);
var canvasDiv='canvasDivPIC_' + windowviewid;
var canvasDraw='canvasPIC_' + windowviewid;
var canvasPaint='canvasPaintPIC_' + windowviewid;
var imgName='mypic_' + windowviewid;
var oldleft= $rootScope.GetPICwindowData(windowviewid, 'imgLeft');
var annotationData=$rootScope.GetPICwindowData(windowviewid,'annotationData');
$rootScope.setIMGPanelCordinate(windowviewid,pnlName,canvasDiv,canvasDraw,canvasPaint,imgName,oldleft,canvasDIvHeight-5,canvasDIvWidth,annotationData);
var img = document.getElementById(imgName);
$rootScope.SetPICwindowData(windowviewid, 'imgLeft',img.offsetLeft);
}
},
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()-5;
var canvasDIvWidth = $('#picImagePanel_' + windowviewid+ " .jsPanel-content").width();
var openedImage = document.getElementById('mypic_' + windowviewid );
openedImage.src = selectedpicture;
openedImage.onload = function () {
var pnlName='picImagePanel_' + windowviewid;
var canvasDiv='canvasDivPIC_' + windowviewid;
var canvasDraw='canvasPIC_' + windowviewid;
var canvasPaint='canvasPaintPIC_' + windowviewid;
var imgName='mypic_' + windowviewid;
var demoData= {shapeStates:[],paintCanvasState:""};
var oldleft= $rootScope.GetPICwindowData(windowviewid, 'imgLeft');
$rootScope.setIMGPanelCordinate(windowviewid,pnlName,canvasDiv,canvasDraw,canvasPaint,imgName,oldleft,canvasDIvHeight,canvasDIvWidth,demoData);
var img = document.getElementById(imgName);
$rootScope.SetPICwindowData(windowviewid, 'imgLeft',img.offsetLeft);
$scope.JsPanelclick(windowviewid);
var annotationData= $scope.picOpenInOtherModules.annotationData;
// load annotation
if(annotationData!="" && annotationData!=undefined)
{
if(annotationData.shapeStates.length>0||annotationData.paintCanvasState.length>0)
{
var modifiedData=$rootScope.resetAnnotationData(imgName,oldleft,annotationData);
if(modifiedData!="" && modifiedData!=undefined)
{
if(modifiedData.shapeStates.length>0||modifiedData.paintCanvasState.length>0)
{
annotationData=modifiedData;
}
}
//first draw shape and then store in object
$rootScope.LoadCBSavedAnnotation(canvasDraw,canvasPaint,annotationData);
}
}
$scope.EnablePicUI(windowviewid);
$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);
});
}
}])