'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.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, "body-views": 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 () { $rootScope.isAnnotationWindowOpen = true; $(".annotationTollbar").css("display", "block"); $rootScope.$broadcast('annotationToolEvent', true); } $rootScope.CloseAnnotationTool = function () { console.log('close') $(".annotationTollbar").css("visibility", "hidden"); $rootScope.isAnnotationWindowClose = true; } $rootScope.OnIdentifyClick = function () { $rootScope.isIdetifyClicked = true; $rootScope.isDrawingToolSelected = false; } //----Annotation Toolbar: Jcanvas----- $rootScope.DrawLine = function (e) { $rootScope.shapeType = "Line"; $("#" + e.currentTarget.id).addClass("activebtncolor"); $('.btnCursor').removeClass('activebtncolor'); // $(".btn-annotation").removeClass("activebtncolor"); } $rootScope.DrawPin = function (e) { $rootScope.shapeType = "Pin"; $('.btnCursor').removeClass('activebtncolor'); $(".btn-annotation").removeClass("activebtncolor"); $("#" + e.currentTarget.id).addClass("activebtncolor"); } $rootScope.Cursor = function () { $rootScope.shapeType = "cursor"; $(".btn-annotation").removeClass("activebtncolor"); // $("#" + e.currentTarget.id).removeClass("activebtncolor"); $('.btnCursor').addClass('activebtncolor'); } $rootScope.DrawRectangle = function (e) { $rootScope.shapeType = "Rectangle"; $('.btnCursor').removeClass('activebtncolor'); $(".btn-annotation").removeClass("activebtncolor"); $("#" + e.currentTarget.id).addClass("activebtncolor"); } $rootScope.paintBrush = function () { $rootScope.shapeType = "brush"; //$('.btnCursor').removeClass('activebtncolor'); //$(".btn-annotation").removeClass("activebtncolor"); //$("#" + e.currentTarget.id).addClass("activebtncolor"); } $rootScope.DrawCircle = function (e) { $rootScope.shapeType = "Circle"; $('.btnCursor').removeClass('activebtncolor'); $(".btn-annotation").removeClass("activebtncolor"); $("#" + e.currentTarget.id).addClass("activebtncolor"); } $rootScope.DrawArrow = function (e) { $rootScope.shapeType = "Arrow"; $('.btnCursor').removeClass('activebtncolor'); $(".btn-annotation").removeClass("activebtncolor"); $("#" + e.currentTarget.id).addClass("activebtncolor"); } $rootScope.DrawText = function () { // $("#myModal").modal("toggle"); $rootScope.shapeType = "TextArea"; //$('.btnCursor').removeClass('activebtncolor'); //$(".btn-annotation").removeClass("activebtncolor"); //$("#" + e.currentTarget.id).addClass("activebtncolor"); $rootScope.DrawPolygon = function () { $rootScope.shapeType = "DrawPolygon"; //$('.btnCursor').removeClass('activebtncolor'); //$(".btn-annotation").removeClass("activebtncolor"); //$("#" + e.currentTarget.id).addClass("activebtncolor"); } //----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; } $rootScope.EraseDrawing = function () { document.getElementById('paintCanvas').getContext('2d').setTransform(1, 0, 0, 1, 0, 0); document.getElementById('paintCanvas').getContext('2d').clearRect(0, 0, document.getElementById('paintCanvas').getContext('2d').canvas.width, document.getElementById('paintCanvas').getContext('2d').canvas.height); } //list manager function //list manager function $rootScope.ShowListManager = function () { console.log('ShowListManager') $('#listManager').css('display', 'block'); $("#listManager").css("visibility", "visible"); $('#listManager').draggable(); $rootScope.isLoading = true; $('#spinner').css('visibility', 'visible'); $rootScope.islistManagerEventAlredayDispachted = true; $rootScope.$broadcast('listManagerEvent', true); } $rootScope.CloseListManager = function () { console.log('close') $rootScope.isListManagerSelected = false; $('#listManager').css('display', 'none'); $("#listManager").css("visibility", "hidden"); // $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.UpdateAndCloseSetting = function (setting) { $rootScope.UpdateSetting(setting); $('#modal-settings').modal('hide'); }; $rootScope.UpdateSetting = function (setting) { //1. if (typeof (setting.ethnicity) !== "undefined" && setting.ethnicity !== null) { $rootScope.globalSetting.ethnicity = setting.ethnicity; $rootScope.setEthncitySettings($rootScope.globalSetting.ethnicity); } if (typeof (setting.modesty) !== "undefined" && setting.modesty !== null) { $rootScope.globalSetting.modesty = setting.modesty; $rootScope.setModestySettings($rootScope.globalSetting.modesty); } //2. localStorage.setItem("globalEthnicity", $rootScope.globalSetting.ethnicity); //3. localStorage.setItem("globalmodesty", $rootScope.globalSetting.modesty); //4. $rootScope.reloadChildController(); }; $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.$broadcast('reloadDABodyViewEvent', { reloadDABodyViewId: currentOpenViewId }); } else { $rootScope.$broadcast('reloadDAControllerEvent', true); } } } }; }] );