'use strict'; AIA.controller("HomeController", ["$rootScope", "Modules", "$log", "$location", "$timeout", function ($rootScope, Modules, $log, $location, $timeout) { //$scope.pageToOpen = { // name: 'MainMenu' //}; $rootScope.pageToOpen = 'app/widget/MainMenu.html'; $rootScope.currentBodyViewId; $rootScope.currentActiveModuleTitle = 'Welcome to A.D.A.M. Interactive Anatomy';//Modules[0].Name; $rootScope.currentActiveViewTitle; $rootScope.cuurentActiveModuleId; $rootScope.openModules = []; $rootScope.openViews = []; $rootScope.currentSlug; $rootScope.jsPanelTitle; $rootScope.ViewTitle; $rootScope.isLoading = false; $rootScope.isAnnotationWindowOpen = false; $rootScope.isDrawingToolSelected = false; $rootScope.isIdetifyClicked = true; $rootScope.paint = false; $rootScope.clickX = new Array(); $rootScope.clickY = new Array(); $rootScope.clickDrag = new Array(); $rootScope.isLineDrawSelecyed = false; $rootScope.isAnnotationWindowClose = false; $rootScope.setListManagerZindex = false; $rootScope.lastX; $rootScope.lastY; $rootScope.CommonData; $rootScope.shapeType; $rootScope.globalSetting = { ethnicity: 'W', modesty: 'Y', }; $rootScope.formsetting = { ethnicity: null, modesty: null }; $rootScope.isModestyOn; $rootScope.isModestyOff; $rootScope.SetSettingActiveTab; //jspanel functionality.. $rootScope.openParent = function (slug) { // debugger; var openViews = $rootScope.openViews; if (openViews.length > 0) { $rootScope.openViews.splice(openViews.length - 1); } if (openViews.length > 0) { var lastOpenMoudle = $rootScope.openViews[openViews.length - 1]; } $('#daImagePanel').remove(); $location.url('/' + slug); $rootScope.$broadcast('jsPanelCloseEvent', true); } //called on jsanel minimize $rootScope.setState = function (state, title) { var alreadyOpenThisView = new jinqJs() .from($rootScope.openViews) .where("body-views == " + title) .select(); var k = 0; if (alreadyOpenThisView != null) { for (var i = 0; i < $rootScope.openViews.length; i++) { k++; if ($rootScope.openViews[i].body - views == title) { $rootScope.openViews.splice((k - 1), 1); $rootScope.openViews.push( { "module": $rootScope.currentActiveModuleTitle, "bodyView": title, "state": state, "BodyViewId": $rootScope.currentBodyViewId, "slug": $rootScope.currentSlug } ); } } } if (state == 'max') { $('#daBodyview').css('width', '100%') } } // $rootScope.DrawLine = function () { //$rootScope.isIdetifyClicked = false; //$rootScope.isDrawingToolSelected = true; //$rootScope.isLineDrawSelecyed = true; // $rootScope.shapeType = "Line"; // alert($rootScope.shapeType); // } $rootScope.ClearIframe = function () { if ($('#daImagePanel') != null) $('#daImagePanel').remove(); $rootScope.hideScrollbar(); } //ends $rootScope.hideScrollbar = function () { $(".sidebar").mCustomScrollbar({ autoHideScrollbar: true, //theme:"rounded" }); } //annotation tool custom events $rootScope.ShowAnnotationWindow = function () { //7904 $("#OnIdentify").addClass("annotationtoolbartab"); $("#annotationToolBarOptions").addClass("active"); $("#annotationButton").addClass("active"); $rootScope.isAnnotationWindowOpen = true; $(".annotationTollbar").css("display", "block"); $rootScope.$broadcast('annotationToolEvent', true); $("#canvasPaint").css("display", "none"); $("#canvas").css("display", "none"); } $rootScope.CloseAnnotationTool = function () { console.log('close'); $("#OnIdentify").removeClass("annotationtoolbartab"); $("#DrawMode").removeClass("annotationtoolbartab"); $('.btnCursor').removeClass('activebtncolor'); $("#annotationButton").removeClass("active"); $("#annotationToolBarOptions").removeClass("active"); $(".annotationTollbar").css("display", "none"); $rootScope.isAnnotationWindowClose = true; $("#canvasPaint").css("display", "none"); $("#canvas").css("display", "none"); } $rootScope.OnIdentifyClick = function () { $("#OnIdentify").addClass("annotationtoolbartab"); $("#DrawMode").removeClass("annotationtoolbartab"); // $rootScope.isIdetifyClicked = true; // $rootScope.isDrawingToolSelected = false; $("#canvasPaint").css("display", "none"); $("#canvas").css("display", "none"); // $("#canvasPaint").css("z-index", "0"); // $("#canvas").css("z-index", "0"); $('.btnCursor').removeClass('activebtncolor'); } $rootScope.DrawingMode = function () { $("#OnIdentify").removeClass("annotationtoolbartab"); $("#DrawMode").addClass("annotationtoolbartab"); $('.btnCursor').addClass('activebtncolor'); $rootScope.switchCanvas(); $("#canvasPaint").css("display", "block"); $("#canvas").css("display", "block"); } // Dissectible Anatomy > Settings should be disable if Annotation is Open. $rootScope.ShowSettingWindow = function () { if ($(".annotationTollbar").css("display") == "block") { // alert("already open"); } else { $('#modal-settings').modal('toggle'); } } //----Annotation Toolbar: Jcanvas----- $rootScope.DrLine = function (e) { $rootScope.setListManagerZindex = true; $("#canvasPaint").css("display", "block"); $("#canvas").css("display", "block"); $rootScope.switchCanvas(); $rootScope.shapeType = "Line"; $('.btnCursor').removeClass('activebtncolor'); $(".btn-annotation").removeClass("activebtncolor"); $(".btn-annotation-line").addClass("activebtncolor"); } $rootScope.DrPin = function (e) { $("#canvasPaint").css("display", "block"); $("#canvas").css("display", "block"); $rootScope.switchCanvas(); $rootScope.switchCanvas(); $rootScope.setListManagerZindex = true; $rootScope.shapeType = "Pin"; $('.btnCursor').removeClass('activebtncolor'); $(".btn-annotation").removeClass("activebtncolor"); $(".btn-annotation-pin").addClass("activebtncolor"); } $rootScope.Cursor = function () { $rootScope.switchCanvas(); $rootScope.shapeType = "cursor"; $(".btn-annotation").removeClass("activebtncolor"); // $("#" + e.currentTarget.id).removeClass("activebtncolor"); $('.btnCursor').addClass('activebtncolor'); } $rootScope.DrawRectangle = function (e) { $rootScope.setListManagerZindex = true; $("#canvasPaint").css("display", "block"); $("#canvas").css("display", "block"); $rootScope.switchCanvas(); $rootScope.shapeType = "Rectangle"; $('.btnCursor').removeClass('activebtncolor'); $(".btn-annotation").removeClass("activebtncolor"); $(".btn-annotation-rectangle").addClass("activebtncolor"); } $rootScope.paintBrush = function () { // debugger; // $('.btnCursor').addClass('activebtncolor'); $rootScope.setListManagerZindex = true; $("#canvasPaint").css("display", "block"); $("#canvas").css("display", "block"); $rootScope.switchCanvasToPaintCanvas(); $rootScope.shapeType = "FreeStylePaint"; var a = $("#amount-2").val(); $rootScope.shapeSize = parseInt(a); if ($rootScope.shapeSize == '') { $('#canvasPaint').sketch({ defaultSize: 1 }); } else { $('#canvasPaint').sketch({ defaultSize: $rootScope.shapeSize }); } // $('#canvasPaint').sketch(); } $rootScope.switchCanvasToPaintCanvas = function (e) { var canvasPaint_zIndex = $('#canvasPaint').css("z-index"); var canvas_zIndex = $('#canvas').css("z-index"); if (canvas_zIndex > canvasPaint_zIndex) { canvasPaint_zIndex = parseInt(canvas_zIndex) + 1; } else { canvasPaint_zIndex = parseInt(canvasPaint_zIndex) + 1; } $('#canvasPaint').css("z-index", canvasPaint_zIndex); } $rootScope.DrawCircle = function (e) { $rootScope.setListManagerZindex = true; $("#canvasPaint").css("display", "block"); $("#canvas").css("display", "block"); $rootScope.switchCanvas(); $rootScope.shapeType = "Circle"; $('.btnCursor').removeClass('activebtncolor'); $(".btn-annotation").removeClass("activebtncolor"); $(".btn-annotation-circle").addClass("activebtncolor"); } $rootScope.DrawArrow = function (e) { $rootScope.setListManagerZindex = true; $("#canvasPaint").css("display", "block"); $("#canvas").css("display", "block"); $rootScope.switchCanvas(); $rootScope.shapeType = "Arrow"; $('.btnCursor').removeClass('activebtncolor'); $(".btn-annotation").removeClass("activebtncolor"); $(".btn-annotation-arrow").addClass("activebtncolor"); } $rootScope.DrawText = function () { $rootScope.setListManagerZindex = true; $("#canvasPaint").css("display", "block"); $("#canvas").css("display", "block"); $rootScope.switchCanvas(); $rootScope.shapeType = "TextArea"; $('.btnCursor').removeClass('activebtncolor'); $(".btn-annotation").removeClass("activebtncolor"); $(".btn-annotation-Text").addClass("activebtncolor"); // $("#text_area").val(''); // $("#text_area").css({ " font-family": 'Verdana, sans-serif', "font-size": "14px", "font-weight": "normal", "font-style": "normal", "color": "#000", "text-align": "left", "text-decoration": "none" }); } $rootScope.DrawPolygon = function () { $rootScope.setListManagerZindex = true; $("#canvasPaint").css("display", "block"); $("#canvas").css("display", "block"); $rootScope.shapeType = "DrawPolygon"; } $rootScope.OpacityModal = function () { } $rootScope.switchCanvas = function () { var x = $('#canvasPaint').css("z-index"); var y = $('#canvas').css("z-index"); if (x > y) { y = parseInt(x) + 1; } else { y = parseInt(y) + 1; } $('#canvas').css("z-index", y); } $rootScope.EraseDrawing = function () { $rootScope.switchCanvasToPaintCanvas(); // $('#canvasPaint').sketch({ defaultColor: "yellow", defaultSize: 1 }); var sktch = $('#canvasPaint').sketch(); $('#canvasPaint').sketch().actions = []; // this line empties the actions. var myCanvas = document.getElementById("canvasPaint"); var ctx = myCanvas.getContext('2d'); ctx.clearRect(0, 0, myCanvas.width, myCanvas.height); $rootScope.switchCanvas(); } //opacity code $rootScope.shapestyleOpacity = 1; $rootScope.shapestyleFillColor = "#fff"; $rootScope.shapestyleFillBorderColor = "black"; $rootScope.shapestyleborderWidth = 2; $rootScope.shapestyleborderStyles = "solid"; $rootScope.shapestyle = function (id) { document.getElementById('modelbackground').style.display = "none"; document.getElementById('modeleditstyle').style.display = "none"; $rootScope.shapestyleOpacity = $("#" + id).css('opacity'); $rootScope.shapestyleFillColor = $("#" + id).parent().css('background-color'); $rootScope.shapestyleborderColor = $("#" + id).parent().css("border-top-color"); $rootScope.shapestyleborderWidthSeparatingPixel = $("#" + id).parent().css("border-top-width"); var pixelSeparation = $rootScope.shapestyleborderWidthSeparatingPixel; var intPart = pixelSeparation.split("p"); $rootScope.shapestyleborderWidth = intPart[0]; $rootScope.shapestyleborderStyles = "solid"; $('#editshapestyle').modal('hide'); // name: 'Circle_' + $rootScope.resetCircle, // $("#canvas").removeLayer("TextRect_" + $rootScope.resetTextRect).drawLayers(); //Edit Shape Style popup should open at it's default position $("#modeleditstyle").css({ "left": "40%", "right": "0", "top":"70px"}); } $rootScope.enableAnnotationToolBar = function () { document.getElementById('modelbackground').style.display = "block"; //$("#editshapestyle").modal('show'); document.getElementById('modeleditstyle').style.display = "block"; if ($('#modeleditstyle').css("display") == "block") { //Check if the modal is already showing var previewOpacity = $('#imgOpacity').css("opacity"); $('#slider-range-min-4 div.ui-slider-range-min').css("width", (previewOpacity*100) + "%"); $('#slider-range-min-4 span.ui-slider-handle').css("left", (previewOpacity * 100) + "%"); }; } $rootScope.enableEditShapeTooltip = function () { $("#edit-block").addClass("custom-tooltip-annotation"); $(".custom-tooltip-annotation").css('display', 'block'); } $rootScope.disableEditShapeTooltip = function () { $(".custom-tooltip-annotation").css('display', 'none'); $("#edit-block").removeClass("custom-tooltip-annotation"); } $rootScope.disableAnnotationToolBar = function () { document.getElementById('modelbackground').style.display = "none"; document.getElementById('modeleditstyle').style.display = "none"; //Edit Shape Style popup should open at it's default position $("#modeleditstyle").css({"left":"40%", "right":"0", "top":"70px"}); } //----End------------- $rootScope.AddClick = function (x, y, dragging) { $rootScope.clickX.push(x); $rootScope.clickY.push(y); $rootScope.clickDrag.push(dragging); } $rootScope.Redraw = function () { var context = document.getElementById('paintCanvas').getContext('2d'); context.clearRect(0, 0, context.canvas.width, context.canvas.height); // Clears the canvas context.strokeStyle = "#FFFFFF"; context.lineJoin = "round"; context.lineWidth = 5; for (var i = 0; i < $rootScope.clickX.length; i++) { context.beginPath(); if ($rootScope.clickDrag[i] && i) { context.moveTo($rootScope.clickX[i - 1], $rootScope.clickY[i - 1]); } else { context.moveTo($rootScope.clickX[i] - 1, $rootScope.clickY[i]); } context.lineTo($rootScope.clickX[i], $rootScope.clickY[i]); context.closePath(); context.stroke(); } } $rootScope.PaintCanvasMousedownListener = function (canvasContext, x, y) { if ($rootScope.isLineDrawSelecyed == true) { canvasContext.lineWidth = 0.1; //$scope.paintCanvasContext.lineJoin = 'round'; //$scope.paintCanvasContext.lineCap = 'round'; canvasContext.strokeStyle = 'red'; canvasContext.beginPath(); //var canvasOffset = $("#myCanvas").offset(); //var offsetX = canvasOffset.left; //var offsetY = canvasOffset.top; canvasContext.moveTo(x, y); } } $rootScope.PaintCanvasMouseupListener = function (canvasContext) { if ($scope.isLineDrawSelecyed == true) { } } $rootScope.PaintCanvasMousemoveListener = function (canvasContext, x, y) { if ($rootScope.isLineDrawSelecyed == true) { console.log('hm moving') canvasContext.lineTo(x, y); canvasContext.stroke(); } } $rootScope.Draw = function (x, y, isDown, context) { if (isDown) { context.beginPath(); context.strokeStyle = '#000000'; context.lineWidth = 1//$('#selWidth').val(); context.lineJoin = "round"; context.moveTo($rootScope.lastX, $rootScope.lastY); context.lineTo(x, y); context.closePath(); context.stroke(); } $rootScope.lastX = x; $rootScope.lastY = y; } //list manager function //list manager function $rootScope.disableAnnotationtoolOnListManager = false; $rootScope.ShowListManager = function () { console.log('ShowListManager') $rootScope.disableAnnotationtoolOnListManager = true; $rootScope.isLoading = true; $('#spinner').css('visibility', 'visible'); $('#listManager').css('display', 'block'); $("#listManager").css("visibility", "visible"); $('#listManager').draggable(); $rootScope.islistManagerEventAlredayDispachted = true; $rootScope.$broadcast('listManagerEvent', true); } $rootScope.CloseListManager = function () { console.log('close') $rootScope.disableAnnotationtoolOnListManager = false; if ($rootScope.disableAnnotationtoolOnListManager == false) { $('#AnnotaionPopupDiv').find('input, textarea, button, select,img,div').removeAttr('disabled', 'disabled'); $('#slider-range-min-2').slider('enable'); } //$rootScope.isListManagerSelected = false; $('#listManager').css('display', 'none'); $("#listManager").css("visibility", "hidden"); $rootScope.isLoading = false; $('#spinner').css('visibility', 'hidden'); //$('#spinner').css('display', 'none'); // $rootScope.isAnnotationWindowClose = true; // if('#termList') if ($('#termList option').length > 0) { //$('#termList option') = null; //$('#termList').innerHTML=''; $('#termList') .find('option') .remove() .end() if ($('#termList option').length > 0) { } } } function fillListManagerTerms() { var len = $rootScope.openModules.length; var openViewLen = $rootScope.openViews.length; var currentOpenModuleId = $rootScope.openModules[len - 1].ModuleId; var currentOpenViewId = $rootScope.openViews[openViewLen - 1].BodyViewId; if (currentOpenModuleId == 1) { } } //setrtings $rootScope.SetSettingActiveTab = function (tabToSet) { $rootScope.SettingsTab = tabToSet; }; $rootScope.loadsettings = function () { //1. For now we are by default opening DA settings tab $rootScope.SettingsTab = 3; //2. var curentEthnicity = localStorage.getItem("globalEthnicity"); if (typeof (curentEthnicity) !== "undefined" && curentEthnicity !== null) { $rootScope.globalSetting.ethnicity = curentEthnicity; } else { localStorage.setItem("globalEthnicity", $rootScope.globalSetting.ethnicity); } var curentmodesty = localStorage.getItem("globalModesty"); if (typeof (curentmodesty) !== "undefined" && curentmodesty !== null) { $rootScope.globalSetting.modesty = curentmodesty } else { localStorage.setItem("globalModesty", $rootScope.globalSetting.modesty); } //3. $rootScope.setModestySettings($rootScope.globalSetting.modesty); //4. $rootScope.setEthncitySettings($rootScope.globalSetting.ethnicity); }; $rootScope.setModestySettings = function (currentmodsetting) { if (currentmodsetting == 'Y') { $rootScope.isModestyOn = true; $rootScope.isModestyOff = false; } else { $rootScope.isModestyOn = false; $rootScope.isModestyOff = true; } } $rootScope.setEthncitySettings = function (currentEthncitysetting) { // this code is used for maintaing the currently selected Ethencity. if (currentEthncitysetting == 'L') { $("#btnEthnicA").addClass("skindefault"); if ($("#btnEthnicB").hasClass("skindefault")) { $("#btnEthnicB").removeClass("skindefault"); } if ($("#btnEthnicL").hasClass("skindefault")) { $("#btnEthnicL").removeClass("skindefault"); } if ($("#btnEthnicW").hasClass("skindefault")) { $("#btnEthnicW").removeClass("skindefault"); } } if (currentEthncitysetting == 'B') { $("#btnEthnicB").addClass("skindefault"); if ($("#btnEthnicL").hasClass("skindefault")) { $("#btnEthnicL").removeClass("skindefault"); } if ($("#btnEthnicW").hasClass("skindefault")) { $("#btnEthnicW").removeClass("skindefault"); } if ($("#btnEthnicA").hasClass("skindefault")) { $("#btnEthnicA").removeClass("skindefault"); } } if (currentEthncitysetting == 'A') { $("#btnEthnicL").addClass("skindefault"); if ($("#btnEthnicB").hasClass("skindefault")) { $("#btnEthnicB").removeClass("skindefault"); } if ($("#btnEthnicW").hasClass("skindefault")) { $("#btnEthnicW").removeClass("skindefault"); } if ($("#btnEthnicA").hasClass("skindefault")) { $("#btnEthnicA").removeClass("skindefault"); } } if (currentEthncitysetting == 'W') { $("#btnEthnicW").addClass("skindefault"); if ($("#btnEthnicB").hasClass("skindefault")) { $("#btnEthnicB").removeClass("skindefault"); } if ($("#btnEthnicL").hasClass("skindefault")) { $("#btnEthnicL").removeClass("skindefault"); } if ($("#btnEthnicA").hasClass("skindefault")) { $("#btnEthnicA").removeClass("skindefault"); } } } $rootScope.ChangeEthnicity = function (formsetting, skintone) { formsetting.ethnicity = skintone; $rootScope.setEthncitySettings(formsetting.ethnicity); } $rootScope.ChangeModesty = function (formsetting, modestyValue) { formsetting.modesty = modestyValue; $rootScope.setModestySettings(formsetting.modesty); } $rootScope.CloseSetting = function () { $rootScope.setEthncitySettings($rootScope.globalSetting.ethnicity); $rootScope.setModestySettings($rootScope.globalSetting.modesty); $('#modal-settings').modal('hide'); } $rootScope.UpdateAndCloseSetting = function (setting) { $rootScope.UpdateSetting(setting); $('#modal-settings').modal('hide'); }; $rootScope.UpdateSetting = function (setting) { //1. if (typeof (setting.ethnicity) !== "undefined" && setting.ethnicity !== null) { $rootScope.ChangeEthnicity(setting, setting.ethnicity); $rootScope.globalSetting.ethnicity = setting.ethnicity; localStorage.setItem("globalEthnicity", $rootScope.globalSetting.ethnicity); $rootScope.setEthncitySettings($rootScope.globalSetting.ethnicity); } if (typeof (setting.modesty) !== "undefined" && setting.modesty !== null) { $rootScope.ChangeModesty(setting, setting.modesty); $rootScope.globalSetting.modesty = setting.modesty; localStorage.setItem("globalModesty", $rootScope.globalSetting.modesty); $rootScope.setModestySettings($rootScope.globalSetting.modesty); } //2. //localStorage.setItem("globalEthnicity", $rootScope.globalSetting.ethnicity); //3. //localStorage.setItem("globalModesty", $rootScope.globalSetting.modesty); //4. //$rootScope.reloadChildController(); var len = $rootScope.openModules.length; if (len > 0) { $rootScope.reloadChildController(); } else { $('#modal-settings').modal('hide'); } }; $rootScope.reloadChildController = function () { var len = $rootScope.openModules.length; var currentOpenModuleId = $rootScope.openModules[len - 1].ModuleId; //checking is DA module is opend. if (currentOpenModuleId == 1) { //Check that what current bodyview is open if ($rootScope.openViews.length > 0) { var openViewLen = $rootScope.openViews.length; var currentOpenViewId = $rootScope.openViews[openViewLen - 1].BodyViewId; //$rootScope.isSettingEventAlredayDispachted = true; $rootScope.$broadcast('reloadDABodyViewEvent', { reloadDABodyViewId: currentOpenViewId }, true); } else { $rootScope.$broadcast('reloadDAControllerEvent', true); } } }; }] );