AIA.controller("AIController", ["$scope", "$window", "$rootScope", "$compile", "$http", "$log", "$location", "$timeout", "pages", "DataService", "AIAConstants", function ($scope, $window, $rootScope, $compile, $http, log, $location, $timeout, pages, DataService, AIAConstants) { // $rootScope.currentActiveModuleTitle = pages[3].name; $scope.showTabButton = true; $scope.IllustrationData; $scope.searchAIListViewData = []; $scope.SelectedAIthumbImage = []; $scope.SelectedAIImage = []; $scope.SelectedAIId = []; $scope.SelectedAITitle = []; $scope.selectedAIListViewData = []; $scope.filterstring = false; $scope.idSelected; $scope.srollListView; $scope.query = { SearchText: '', SearchTextByAlphabet: '', }; $scope.setActiveTab = function (tabToSet) { $scope.activeTab = tabToSet; localStorage.setItem("currentAITabView", $scope.activeTab); }; $scope.$on('$viewContentLoaded', function (event) { if ($rootScope.refreshcheck == null) { $location.path('/'); } // code that will be executed ... // every time this view is loaded //get current path var currentURL = $location.path(); var selectedModuleName = ''; //set module title angular.forEach($rootScope.userModules, function (value, key) { if (value.slug === currentURL.replace('/', '')) { selectedModuleName = value.name; } $rootScope.currentActiveModuleTitle = selectedModuleName; }) $scope.LoadAIJsonData(); $scope.scroll(); //push the details of open module in array $rootScope.openModules $rootScope.openModules.push({ "ModuleId": 13 }); //set the local storage var curtab = $rootScope.getLocalStorageValue("currentAITabView"); if (curtab == 2) { $scope.setActiveTab(2); var curSelectedRowId = $rootScope.getLocalStorageValue("AISelectedRowId"); if (typeof (curSelectedRowId) !== "undefined" && curSelectedRowId !== null && curSelectedRowId !== '') { $scope.reRunSearchOnLoad(); $scope.idSelected = curSelectedRowId; $scope.ReloadListViewImageDiv($scope.idSelected); } else { $scope.reRunSearchOnLoad() $scope.idSelected = ''; } } else { $scope.setActiveTab(1); $scope.reRunSearchOnLoad(); } }); $scope.reRunSearchOnLoad = function () { var searchByText = $rootScope.getLocalStorageValue("SearchText"); var searchTextByAlphabet = $rootScope.getLocalStorageValue("SearchByAlphabet"); if (typeof (searchByText) !== "undefined" && searchByText !== null && searchByText !== '') { $scope.query.SearchText = searchByText; } else if (typeof (searchTextByAlphabet) !== "undefined" && searchTextByAlphabet !== null && searchTextByAlphabet !== '') { $scope.query.SearchTextByAlphabet = searchTextByAlphabet; } else { $scope.query.SearchTextByAlphabet = ""; } if ($scope.query.SearchText == "" && $scope.query.SearchTextByAlphabet == "") { $scope.loadAllAI(); } else if ($scope.query.SearchTextByAlphabet != "" || $scope.query.SearchText == "") { $scope.ApplySearchByAlphabet($scope.query.SearchTextByAlphabet); } else { $scope.ApplySearch($scope.query); } } $scope.LoadAIJsonData = function () { $('ul li a').removeAttr("style"); var promise = DataService.getJson('~/../content/data/json/ai/ai_dat_contentlist.json') promise.then( function (result) { $scope.IllustrationData = result; $scope.selectedAIListViewData = new jinqJs() .from($scope.IllustrationData.root.AIData) .orderBy([{ field: '_Title', sort: 'asc' }]) .select(); }, function (error) { // handle errors here console.log(' $scope.IllustrationData = ' + error.statusText); } ); }; $scope.loadAllAI = function () { $rootScope.isLoading = true; localStorage.setItem("SearchText", ''); localStorage.setItem("SearchByAlphabet", ''); $('ul li a').removeAttr("style"); $('#aiSpinner').css('visibility', 'visible'); $('#aiSpinner').css('zIndex', '20000'); var promise = DataService.getJson('~/../content/data/json/ai/ai_dat_contentlist.json') promise.then( function (result) { $scope.IllustrationData = result; $scope.selectedAIListViewData = new jinqJs() .from($scope.IllustrationData.root.AIData) .orderBy([{ field: '_Title', sort: 'asc' }]) .select(); //console.log($scope.selectedAIListViewData); $('#grid-view').empty(); var $e1 = $('').appendTo('#grid-view'); $compile($e1)($scope); $timeout(function () { $('#' + $rootScope.getLocalStorageValue("currentAIImageId")).find('.thumbnail').addClass('HightLightThumbnail'); if ($rootScope.getLocalStorageValue('AIGridViewScroll') !== null && $location.url() == "/ADAM-images") { $('html, body').animate({ scrollTop: $rootScope.getLocalStorageValue('AIGridViewScroll') }); } }, 100); $rootScope.isLoading = false; $('#aiSpinner').css('visibility', 'hidden'); }, function (error) { // handle errors here console.log(' $scope.IllustrationData = ' + error.statusText); } ); } $scope.IsVisible = function () { $scope.scroll(); } $scope.showItem = function (id) { $scope.idSelected = id; localStorage.setItem("AISelectedRowId", id); //Set the vertical scroll value of the table. var y = $('#ListViewDiv').scrollTop(); localStorage.setItem("AIListViewScroll", y); $scope.hiderow = true; if ($scope.filterstring == false) { var SelectedAIthumbImage = []; SelectedAIthumbImage = new jinqJs() .from($scope.selectedAIListViewData) .where('_id = ' + id) .select('_ThumbnailImage', '_id', '_Title'); $scope.SelectedAIthumbImage = "~/../content/images/ai/thumbnails/" + SelectedAIthumbImage[0]._ThumbnailImage; $scope.SelectedAIId = SelectedAIthumbImage[0]._id; $scope.SelectedAITitle = SelectedAIthumbImage[0]._Title; } else { if ($scope.searchAIListViewData.length > 0) { var SelectedAIthumbImage = []; SelectedAIthumbImage = new jinqJs() .from($scope.searchAIListViewData) .where('_id = ' + id) .select('_ThumbnailImage', '_id', '_Title'); $scope.SelectedAIthumbImage = "~/../content/images/ai/thumbnails/" + SelectedAIthumbImage[0]._ThumbnailImage; $scope.SelectedAIId = SelectedAIthumbImage[0]._id; $scope.SelectedAITitle = SelectedAIthumbImage[0]._Title; } } }; $scope.Reset = function (query) { $('ul li a').removeAttr("style"); query.SearchText = ""; //set localstorage values localStorage.setItem("SearchText", ''); localStorage.setItem("SearchByAlphabet", ''); localStorage.setItem("AIListViewScroll", ''); if ($('.selected').hasClass("selected")) { $('.selected').removeClass("selected"); } $('#ListViewDiv').scrollTop(0); $scope.hideListViewDiv(); $scope.filterstring = false; while ($scope.searchAIListViewData.length) { $scope.searchAIListViewData.pop(); } $scope.loadAllAI(); } $scope.ApplySearch = function (query) { $('ul li a').removeAttr("style"); var currentSearchtext = $rootScope.getLocalStorageValue("SearchText"); localStorage.setItem("SearchText", ''); if (currentSearchtext == "undefined" || (currentSearchtext == null || currentSearchtext == "")) { if (query.SearchText == "undefined" || (query.SearchText == null || query.SearchText == "")) { $rootScope.errorMessage = AIAConstants.PLEASE_ENTER_SEARCH_TEXT; $("#messageModal").modal('show'); // alert("Please enter the text !") return false; } } $rootScope.isLoading = true; $('#spinner').css('visibility', 'visible'); $rootScope.isLoading = true; $('#spinner').css('visibility', 'visible'); $scope.filterstring = true; while ($scope.searchAIListViewData.length) { $scope.searchAIListViewData.pop(); } if (typeof (query.SearchText) !== "undefined" && (query.SearchText !== null && query.SearchText !== "")) { localStorage.setItem("SearchText", query.SearchText); } else { localStorage.setItem("SearchText", ''); } var promise = DataService.getJson('~/../content/data/json/ai/ai_dat_contentlist.json') promise.then( function (result) { $scope.IllustrationData = result; $scope.selectedAIListViewData = new jinqJs() .from($scope.IllustrationData.root.AIData) .orderBy([{ field: '_Title', sort: 'asc' }]) .select(); $('#grid-view').empty(); angular.forEach($scope.selectedAIListViewData, function (value, key) { var selectimg = true; //var count = 0; if (typeof (query.SearchText) !== "undefined" && (query.SearchText !== null && query.SearchText !== "")) { var SearchText = query.SearchText var posbodyregion = value._Title.toLowerCase().indexOf(SearchText.toLowerCase()); if (posbodyregion > -1) { selectimg = true; //count = count + 1; } else { selectimg = false; //count = count - 1; } } if (selectimg === true) { $scope.imagePath = "~/../content/images/ai/thumbnails/" + value._ThumbnailImage; var $el = $('
' + '
' + '' + '

' + value._Title + '

').appendTo('#grid-view'); $compile($el)($scope); $(".sidebar").mCustomScrollbar({ autoHideScrollbar: true, //theme:"rounded" }); $scope.searchAIListViewData.push( { "_id": value._id, //"_ImageId": value._ImageId, "_Title": value._Title, "_contentImage": value._contentImage, "_ThumbnailImage": value._ThumbnailImage, }); } }); $('table > #ListViewDiv > #searchItem').remove(); //Show Error Message in case of gridview if no data is found if ($scope.searchAIListViewData.length == 0) { var $el = $('
No illustration found for the selected search criteria!
').appendTo('#grid-view'); $compile($el)($scope); $('table > #ListViewDiv > #searchItem').remove(); $('#ListViewDiv').append('No illustration found for the selected search criteria!'); } $rootScope.isLoading = false; $('#spinner').css('visibility', 'hidden'); }, function (error) { // handle errors here console.log(' $scope.IllustrationData = ' + error.statusText); } ); } $scope.ApplySearchByAlphabet = function (SearchText) { $rootScope.isLoading = true; $('#spinner').css('visibility', 'visible'); $scope.filterstring = true; while ($scope.searchAIListViewData.length) { $scope.searchAIListViewData.pop(); } if (typeof (SearchText) !== "undefined" && (SearchText !== null && SearchText !== "")) { localStorage.setItem("AIImageId", SearchText); } else { localStorage.setItem("AIImageId", ''); } var promise = DataService.getJson('~/../content/data/json/ai/ai_dat_contentlist.json') promise.then( function (result) { $scope.IllustrationData = result; $scope.selectedAIListViewData = new jinqJs() .from($scope.IllustrationData.root.AIData) .orderBy([{ field: '_Title', sort: 'asc' }]) .select(); $('#grid-view').empty(); angular.forEach($scope.selectedAIListViewData, function (value, key) { var selectimg = true; //var count = 0; if (typeof (SearchText) !== "undefined" && (SearchText !== null && SearchText !== "")) { var firstChar = value._Title[0]; if (firstChar == SearchText) { selectimg = true; //count = count + 1; } else { selectimg = false; //count = count - 1; } } if (selectimg === true) { $scope.imagePath = "~/../content/images/ai/thumbnails/" + value._ThumbnailImage; var $el = $('
' + '
' + '' + '

' + value._Title + '

').appendTo('#grid-view'); $compile($el)($scope); $(".sidebar").mCustomScrollbar({ autoHideScrollbar: true, //theme:"rounded" }); $scope.searchAIListViewData.push( { "_id": value._id, //"_ImageId": value._ImageId, "_Title": value._Title, "_contentImage": value._contentImage, "_ThumbnailImage": value._ThumbnailImage, }); } }); $('table > #ListViewDiv > #searchItem').remove(); //Show Error Message in case of gridview if no data is found if ($scope.searchAIListViewData.length == 0) { var $el = $('
No illustration found for the selected search criteria!
').appendTo('#grid-view'); $compile($el)($scope); $('table > #ListViewDiv > #searchItem').remove(); $('#ListViewDiv').append('No illustration found for the selected search criteria!'); } $rootScope.isLoading = false; $('#spinner').css('visibility', 'hidden'); }, function (error) { // handle errors here console.log(' $scope.IllustrationData = ' + error.statusText); } ); } $scope.ApplySearchByAlphabet = function (SearchTextByAlphabet) { $rootScope.SearchTextByAlphabet = SearchTextByAlphabet $rootScope.isLoading = true; $('ul li a').removeAttr("style"); $('#spinner').css('visibility', 'visible'); $('#' + $rootScope.SearchTextByAlphabet).css({ "color": "white", "background-color": "#1B92D0" }); //color: #0095da; //background-color: #ffffff; $scope.filterstring = true; while ($scope.searchAIListViewData.length) { $scope.searchAIListViewData.pop(); } if (typeof (SearchTextByAlphabet) !== "undefined" && (SearchTextByAlphabet !== null && SearchTextByAlphabet !== "")) { localStorage.setItem("SearchByAlphabet", SearchTextByAlphabet); } else { localStorage.setItem("SearchByAlphabet", ''); } var promise = DataService.getJson('~/../content/data/json/ai/ai_dat_contentlist.json') promise.then( function (result) { $scope.IllustrationData = result; $scope.selectedAIListViewData = new jinqJs() .from($scope.IllustrationData.root.AIData) .orderBy([{ field: '_Title', sort: 'asc' }]) .select(); $('#grid-view').empty(); angular.forEach($scope.selectedAIListViewData, function (value, key) { var selectimg = true; //var count = 0; if (typeof (SearchTextByAlphabet) !== "undefined" && (SearchTextByAlphabet !== null && SearchTextByAlphabet !== "")) { var firstChar = value._Title[0]; if (firstChar == SearchTextByAlphabet) { selectimg = true; } else { selectimg = false; } } if (selectimg === true) { $scope.imagePath = "~/../content/images/ai/thumbnails/" + value._ThumbnailImage; var $el = $('
' + '
' + '' + '

' + value._Title + '

').appendTo('#grid-view'); $compile($el)($scope); $(".sidebar").mCustomScrollbar({ autoHideScrollbar: true, //theme:"rounded" }); $scope.searchAIListViewData.push( { "_id": value._id, //"_ImageId": value._ImageId, "_Title": value._Title, "_contentImage": value._contentImage, "_ThumbnailImage": value._ThumbnailImage, }); } }); $('table > #ListViewDiv > #searchItem').remove(); //Show Error Message in case of gridview if no data is found if ($scope.searchAIListViewData.length == 0) { var $el = $('
No illustration found for the selected search criteria!
').appendTo('#grid-view'); $compile($el)($scope); $('table > #ListViewDiv > #searchItem').remove(); $('#ListViewDiv').append('No illustration found for the selected search criteria!'); } $rootScope.isLoading = false; $('#spinner').css('visibility', 'hidden'); }, function (error) { console.log(' $scope.IllustrationData = ' + error.statusText); } ); } $scope.scroll = function () { $("html,body").scrollTop(0); } $scope.OpenAdamImage = function ($event) { $rootScope.MenuModuleName = "AI"; $rootScope.disableAnnotationTB = false; $rootScope.AIAnotationIdentifyModeOff = true; $rootScope.currentAIImageId = $event.currentTarget.id; if ($event.currentTarget.textContent !== null && typeof ($event.currentTarget.textContent) !== "undefined") { var AITitle = []; AITitle = new jinqJs() .from($scope.selectedAIListViewData) .where('_id = ' + $event.currentTarget.id) .select('_Title'); $rootScope.ViewTitle = AITitle[0]._Title; } else { $rootScope.ViewTitle = $event.currentTarget.textContent; } localStorage.setItem("currentImageTitleFromJson", $rootScope.ViewTitle); localStorage.setItem("currentAIImageId", $event.currentTarget.id); //Set the vertical scroll value of the Grid-View. var y = $($window).scrollTop(); localStorage.setItem("AIGridViewScroll", y); var u = $location.url(); $location.url('/adam-images-detail'); } $scope.OpenAdamImageView = function () { if ($rootScope.refreshcheck == null) { $location.path('/'); } $rootScope.isLoading = true; $('#spinner').css('visibility', 'visible'); $scope.voId = $rootScope.getLocalStorageValue("currentAIImageId"); var counter = 1; var tittle = $rootScope.getLocalStorageValue("currentImageTitleFromJson"); localStorage.setItem("currentViewTitle", tittle); var promise = DataService.getJson('~/../content/data/json/ai/ai_dat_contentlist.json') promise.then( function (result) { $scope.AIllustrationData = result; $scope.AIlistViewData = $scope.AIllustrationData.root.AIData; var clickedAIImage = []; clickedAIImage = new jinqJs() .from($scope.AIlistViewData) .where('_id == ' + $scope.voId) .select('_contentImage'); $scope.clickedAIImage = "~/../content/images/ai/images/" + clickedAIImage[0]._contentImage; if (clickedAIImage.length > 0) { $.jsPanel({ id: 'aiImagePanel', selector: '.aiView', theme: 'success', currentController: 'AIController', parentSlug: 'ADAM-images', content: '
' + '
' + '' + '
' + '
', //ajax: { // url: 'app/views/ci/ci-view-detail.html' //}, title: $rootScope.getLocalStorageValue("currentViewTitle"), position: { top: 70, left: 20, }, size: { width: $(window).outerWidth() - 20, height: $(window).outerHeight() - 110 }, }); $('#canvasDiv img').load(function () { $rootScope.isLoading = false; $('#spinner').css('visibility', 'hidden'); }); $rootScope.currentSlug = 'adam-images-detail'; $rootScope.openViews.push( { "module": $rootScope.currentActiveModuleTitle, "bodyView": tittle, "state": 'max', "BodyViewId": $rootScope.currentAIImageId, "slug": $rootScope.currentSlug }); //$("#aiImagePanel .img-thumbnail").css("height", $("#aiImagePanel .jsPanel-content").height()); $('.jsPanel-content .jsPanel-theme-success').css('overflow-y', 'auto !important') var jspContentHeight = $('.jsPanel-content').height(); } }, function (error) { // handle errors here console.log(' $scope.AIllustrationData = ' + error.statusText); } ); // console.log($rootScope.OpenAdamImages); $('#AIView').css("height", $(window).outerHeight()); $('#AIView').css("width", $(window).outerWidth()); } $scope.$on('annotationToolEvent', function (event, data) { $('#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" }); $("#canvas").css("display", "block"); $("#canvasPaint").css("display", "block"); $rootScope.onDrawingCanvasClick(); $rootScope.FreeStylePaint(); }); $scope.ReloadListViewImageDiv = function (id) { //console.log(id); $scope.idSelected = id; $scope.hiderow = true; var promise = DataService.getJson('~/../content/data/json/ai/ai_dat_contentlist.json') promise.then( function (result) { $scope.IllustrationData = result; var SelectedAIthumbImage = []; SelectedAIthumbImage = new jinqJs() .from($scope.IllustrationData.root.AIData) .where('_id = ' + id) .select('_ThumbnailImage', '_id', '_Title'); $scope.SelectedAIthumbImage = "~/../content/images/ai/thumbnails/" + SelectedAIthumbImage[0]._ThumbnailImage; $scope.SelectedAIId = SelectedAIthumbImage[0]._id; $scope.SelectedAITitle = SelectedAIthumbImage[0]._Title; //Set the scroll position of the tablebody to show selected row. var curAIListViewScroll = $rootScope.getLocalStorageValue("AIListViewScroll"); if (typeof (curAIListViewScroll) !== "undefined" && curAIListViewScroll !== null && curAIListViewScroll !== '') { if (typeof InstallTrigger !== 'undefined') { $('#ListViewDiv').animate({ scrollTop: $rootScope.getLocalStorageValue("AIListViewScroll") }); } else { $('#ListViewDiv').scrollTop($rootScope.getLocalStorageValue("AIListViewScroll")); } } }, function (error) { // handle errors here console.log(' $scope.AnimationData = ' + error.statusText); } ); }; $scope.hideListViewDiv = function () { if ($rootScope.getLocalStorageValue("currentAITabView") == 2) { //localStorage.setItem("AISelectedRowId", ""); if ($('.selected').hasClass("selected")) { $('.selected').removeClass("selected"); } $scope.hiderow = false; } } }] );