'use strict'; AIA.controller("MyAnimationController", ["$scope", "$window", "$rootScope", "$compile", "$http", "$log", "$location", "$timeout", "ModuleService", "$interval", "AIAConstants", function ($scope, $window, $rootScope, $compile, $http, log, $location, $timeout, ModuleService, $interval, AIAConstants) { $scope.ObjectAttribute=function(windowviewid) { var windata={ 'multiwinid': windowviewid, 'videoSource': "", 'moduleName': '', 'currentViewTitle': '', 'parentSlugName': '', 'currentSlug': '', 'imageId': '', 'y': 0, 'x': 0, 'width': 0, 'height': 0, 'minimised': false, 'maximised': false, 'minmaxAutoEvent':true, 'isSourceExist':true }; return windata; } $scope.initializeVideoWindowData = function (windowviewid, isOpenWithExistsModule, openPanelNo) { if (isOpenWithExistsModule || openPanelNo == 0) { if ($rootScope.VideoWindowData != undefined) { $rootScope.VideoWindowData.length = 0; } else { $rootScope.VideoWindowData = []; } $rootScope.VideoWindowData.push($scope.ObjectAttribute(windowviewid)); } else { var isNewWindow = true; for (var k = 0; k < $rootScope.VideoWindowData.length; k++) { if ($rootScope.VideoWindowData[k].multiwinid == windowviewid) { isNewWindow = false; break; } } if (isNewWindow) { $rootScope.VideoWindowData.push($scope.ObjectAttribute(windowviewid)); } } } $scope.GetVideowindowStoreData = function (windowviewid, keyname) { for (var x = 0 ; x < $rootScope.VideoWindowData.length; x++) { if ($rootScope.VideoWindowData[x].multiwinid == windowviewid) { return $rootScope.VideoWindowData[x][keyname]; } } } $scope.SetVideowindowStoreData = function (windowviewid, keyname, value) { for (var x = 0 ; x < $rootScope.VideoWindowData.length; x++) { if ($rootScope.VideoWindowData[x].multiwinid == windowviewid) { $rootScope.VideoWindowData[x][keyname] = value; } } } // access from home controller $rootScope.SetVideowindowData=function(windowviewid,keyname,data) { for(var x=0 ;x < $rootScope.VideoWindowData.length;x++){ if($rootScope.VideoWindowData[x].multiwinid==windowviewid) { $rootScope.VideoWindowData[x][keyname]=data; } } } $scope.DisableVideoUI = function (windowviewid) { var modulePanel = $("#vidImagePanel_"+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 $('#HomeContainerDiv').css('pointer-events', 'none'); $('#HomeContainerDiv').css('opacity', '0.7'); } $scope.EnableVideoUI = function (windowviewid) { var modulePanel = $("#vidImagePanel_"+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 $('#HomeContainerDiv').css('pointer-events', 'auto'); $('#HomeContainerDiv').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.VideoWindowData.length; index++) { if ($rootScope.VideoWindowData[index].multiwinid == windowviewid) { if (index != -1) { // remove module which one is loaded var reffid=$rootScope.VideoWindowData[index].imageId; $rootScope.VideoWindowData.splice(index, 1); //remove also stream/source video from close panel from cb if($rootScope.collectAnimationSource !=undefined) { for (var vdx = 0 ; vdx < $rootScope.collectAnimationSource.length; vdx++) { if(reffid==$rootScope.collectAnimationSource[vdx].imageId) $rootScope.collectAnimationSource.splice(vdx, 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.OpenMyAnimationViewMain = function () { if ($rootScope.isCallFromOtherModule) { $scope.VideoModuleData = ModuleService.getModuleData("MY_ANIMATIONS"); if($scope.VideoModuleData.length<1) return; $scope.readyToLoad = true; $rootScope.VideoLoadComplete = false; $scope.wincount = 1; var winlen = $scope.VideoModuleData.length; var timeint = null; timeint = $interval(function () { if ($scope.readyToLoad == true) { var windata = $scope.VideoModuleData[$scope.wincount - 1]; $scope.OpenAnimationView(windata); } $scope.readyToLoad = false; if ($scope.wincount < winlen && $rootScope.VideoLoadComplete == true) { $scope.wincount = $scope.wincount + 1; $rootScope.VideoLoadComplete = false; $scope.readyToLoad = true; } if ($scope.wincount == winlen && $rootScope.VideoLoadComplete == true) { $scope.stopInterval(); $scope.$emit("LoadModuleComplete", "MY_ANIMATIONS"); } }, 100); $scope.stopInterval = function () { if (angular.isDefined(timeint)) { $interval.cancel(timeint); timeint = undefined; } }; } } $scope.OpenAnimationView = function (vidModuleData) { $scope.VidOpenInOtherModules = vidModuleData; $rootScope.MULTI_VIEW_ID += 1; var windowviewid = $rootScope.MULTI_VIEW_ID; $scope.DisableVideoUI(windowviewid); $scope.initializeVideoWindowData(windowviewid, false, $scope.VidOpenInOtherModules.currentWindowId); var moduleName = $scope.VidOpenInOtherModules.mType; $scope.SetVideowindowStoreData(windowviewid, 'moduleName', moduleName); // serial no of imageid var imageId = $scope.VidOpenInOtherModules.id; $scope.SetVideowindowStoreData(windowviewid, 'imageId', imageId); var videoSource=$scope.VidOpenInOtherModules.videoSource; $scope.SetVideowindowStoreData(windowviewid, 'videoSource', videoSource); if(videoSource=="" ||videoSource==undefined) { $scope.SetVideowindowStoreData(windowviewid, 'isSourceExist', false); } var aiTitle = $scope.VidOpenInOtherModules.anatomyTitle; $scope.SetVideowindowStoreData(windowviewid, 'currentViewTitle', aiTitle); localStorage.setItem("currentViewTitle", aiTitle); var isMaximize = $scope.VidOpenInOtherModules.maximised!=undefined?$scope.VidOpenInOtherModules.maximised:false; var isMinimize = $scope.VidOpenInOtherModules.minimised!=undefined?$scope.VidOpenInOtherModules.minimised:false; $scope.SetVideowindowStoreData(windowviewid, 'maximised', isMaximize); $scope.SetVideowindowStoreData(windowviewid, 'minimised', isMinimize); if($location.url()== "/curriculum-builder-detail") { $scope.SetVideowindowStoreData(windowviewid,'parentSlugName',($location.url()).replace('/', '')); } else { $scope.SetVideowindowStoreData(windowviewid,'parentSlugName','');//back to home screen } $scope.loadMyAnimation(windowviewid); } $scope.loadMyAnimation = function (windowviewid) { $scope.jsPanelID = 'vidImagePanel' + '_' + windowviewid; var tittle = $scope.GetVideowindowStoreData(windowviewid, 'currentViewTitle'); var animationSource = $scope.GetVideowindowStoreData(windowviewid, 'videoSource'); var isSourceExist = $scope.GetVideowindowStoreData(windowviewid, 'isSourceExist'); if(isSourceExist==true) { // get animation from uploaded stream if (animationSource.indexOf('base64') == -1) { animationSource="data:video/mp4;base64,"+animationSource; } } else { // get animation from server animationSource=$scope.aiaAnimationPath+ tittle + ".mp4"; } var playerScript = "~/../libs/video_4_12_11/video_4_12_11.js"; // open JS panel for curriculum with define cornonate in CB jason $scope.jsPanelWidth = $scope.VidOpenInOtherModules.size.width;//1000; if ($scope.VidOpenInOtherModules.size.width < 500) $scope.jsPanelWidth = 500; $scope.jsPanelHeight = $scope.VidOpenInOtherModules.size.height; if ($scope.VidOpenInOtherModules.size.height < 400) $scope.jsPanelHeight = 400; $scope.jsPanelLeft = $scope.VidOpenInOtherModules.position.x; if ($scope.VidOpenInOtherModules.position.x <= 1) $scope.jsPanelLeft = 0; $scope.jsPanelTop = $scope.VidOpenInOtherModules.position.y; if ($scope.VidOpenInOtherModules.position.y < 30) $scope.jsPanelTop = 30; if($location.url()!= "/curriculum-builder-detail") { $scope.jsPanelLeft = 1; $scope.jsPanelTop = 85; } if (animationSource.length > 0 ) { $scope.jsPanelVideo = $.jsPanel({ id: $scope.jsPanelID, selector: '.videoView', theme: 'success', currentController: 'MyAnimationController', parentSlug: $scope.GetVideowindowStoreData(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.GetVideowindowStoreData(windowviewid, 'minmaxAutoEvent'); if(!isAutoCalled) { $rootScope.UnsaveCurriculum = true; } $scope.SetVideowindowStoreData(windowviewid, 'minimised',true); $scope.SetVideowindowStoreData(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.GetVideowindowStoreData(windowviewid, 'minmaxAutoEvent'); if(!isAutoCalled) { $rootScope.UnsaveCurriculum = true; } $scope.SetVideowindowStoreData(windowviewid, 'maximised',true); $scope.SetVideowindowStoreData(windowviewid, 'minimised',false); var canvasDIvHeight = $('#vidImagePanel_' + windowviewid+ " .jsPanel-content").height(); $('#playerinlineVideo_'+ windowviewid ).css("height",canvasDIvHeight); $rootScope.resetMenuOptionOnClick(pnlName); var $ua = navigator.userAgent; if (($ua.match(/(iPod|iPhone|iPad|android)/i))) { var aodheight = screen.height; if(aodheight>=1024) { $("#vidImagePanel_"+windowviewid).css('height',canvasDIvHeight+30-150); $('#vidImagePanel_' + windowviewid+ " .jsPanel-content").css('height',canvasDIvHeight-150); $('#playerinlineVideo_'+ windowviewid ).css("height",canvasDIvHeight-150 ); } else if(aodheight<1024) { $('#playerinlineVideo_'+ windowviewid ).css("height",canvasDIvHeight); } } }, onnormalized:function (panel) { var pnlName=panel[0].id; var len = (pnlName).split("_").length; var windowviewid = (pnlName).split("_")[len - 1]; var isAutoCalled = $scope.GetVideowindowStoreData(windowviewid, 'minmaxAutoEvent'); if(!isAutoCalled) { $rootScope.UnsaveCurriculum = true; } $scope.SetVideowindowStoreData(windowviewid, 'minimised',false); $scope.SetVideowindowStoreData(windowviewid, 'maximised',false); var canvasDIvHeight = $('#vidImagePanel_' + windowviewid+ " .jsPanel-content").height(); $('#playerinlineVideo_'+ windowviewid ).css("height",canvasDIvHeight); $rootScope.resetMenuOptionOnClick(pnlName); }, 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]; var canvasDIvHeight = $('#vidImagePanel_' + windowviewid+ " .jsPanel-content").height(); $scope.SetVideowindowStoreData(windowviewid, 'width', ui.size.width); $scope.SetVideowindowStoreData(windowviewid, 'height', canvasDIvHeight); $scope.SetVideowindowStoreData(windowviewid, 'y', ui.position.top); $scope.SetVideowindowStoreData(windowviewid, 'x', ui.position.left); $rootScope.UnsaveCurriculum = true; $('#playerinlineVideo_'+ windowviewid ).css("height",canvasDIvHeight); $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.SetVideowindowStoreData(windowviewid, 'y', ui.position.top); $scope.SetVideowindowStoreData(windowviewid, 'x', ui.position.left); $rootScope.UnsaveCurriculum = true; $rootScope.resetMenuOptionOnClick(pnlName); } }, }); var isMaximize = $scope.GetVideowindowStoreData(windowviewid, 'maximised'); var isMinimize = $scope.GetVideowindowStoreData(windowviewid, 'minimised'); if (isMaximize) { $scope.jsPanelVideo.maximize(); } else if (isMinimize) { $scope.jsPanelVideo.minimize(); } else { $scope.jsPanelVideo.normalize(); } $rootScope.AllPanelObject(windowviewid,$scope.jsPanelVideo); $("#vidImagePanel_"+windowviewid).css('overflow','hidden'); // set false after initial call of min,max or normal $scope.SetVideowindowStoreData(windowviewid, 'minmaxAutoEvent', false); $scope.SetVideowindowStoreData(windowviewid, 'y', $scope.jsPanelTop); $scope.SetVideowindowStoreData(windowviewid, 'x', $scope.jsPanelLeft); $scope.SetVideowindowStoreData(windowviewid, 'width', $scope.jsPanelWidth); $scope.SetVideowindowStoreData(windowviewid, 'height', $scope.jsPanelHeight); $scope.SetVideowindowStoreData(windowviewid, 'currentSlug', 'clinical-animations-detail'); $('html, body').animate({ scrollTop: 0 }); $rootScope.openViews.push( { "module": $rootScope.currentActiveModuleTitle, "bodyView": tittle, "state": 'max', "BodyViewId": $rootScope.currentBodyViewId, "slug": $scope.GetVideowindowStoreData(windowviewid, 'currentSlug') }); var canvasDIvHeight = $('#vidImagePanel_' + windowviewid+ " .jsPanel-content").height(); $('#playerinlineVideo_'+ windowviewid ).css("height",canvasDIvHeight); } //Calling methode for save Js Panel Activity for SaveCB $scope.PanelActivity(); } $scope.MyvideoOnLoad = function (windowviewid) { if ($rootScope.isCallFromOtherModule) { $rootScope.VideoLoadComplete = true; } $scope.JsPanelclick(windowviewid); $scope.EnableVideoUI(windowviewid); } $scope.JsPanelclick = function (windowviewid) { //reset option list manager and annotation //call when module loaded $rootScope.resetMenuOption(); // call from while open module in CB //remove pre event // $("#vidImagePanel_" + windowviewid).off("click"); $("#vidImagePanel_" + windowviewid).on('click', function (event) { //after drawing annotation click not work on iPad/Android device var pnlName = event.currentTarget.id; $rootScope.resetMenuOptionOnClick(pnlName); }); } }]); function MyvideoOnLoad(event) { console.log('video loaded') var scope = angular.element(document.getElementById("VideoView")).scope(); // var len = (event.target.id).split("_").length; var windowviewid = (event.target.id).split("_")[1]; setTimeout(function() { scope.$apply(function () { scope.MyvideoOnLoad(windowviewid); }); }, 500); }