AIA.controller("AIController", ["$scope", "$window", "$rootScope", "$compile", "$http", "$log", "$location", "$timeout", "pages", "DataService", "AIAConstants","ModuleService", "$interval",
function ($scope, $window, $rootScope, $compile, $http, log, $location, $timeout, pages, DataService, AIAConstants, ModuleService, $interval) {
$scope.showTabButton = true;
$scope.SelectedAIthumbImage = [];
$scope.SelectedAIImage = [];
$scope.SelectedAIId = [];
$scope.SelectedAITitle = [];
$scope.selectedAIListViewData = [];
$scope.filterstring = false;
$scope.idSelected;
$scope.srollListView;
$scope.query = {
SearchText: '',
SearchTextByAlphabet: '',
SelectedDiv: ''
};
$scope.numPerImage = 100;
$scope.maxSize = 5;
$scope.totalimage =0;
$scope.numPages = function () {
return Math.ceil($scope.totalimage / $scope.numPerImage);
};
$scope.$watch('currentPage + numPerPage', function () {
var begin = (($scope.currentPage - 1) * $scope.numPerImage)
, end = begin + $scope.numPerImage;
if ($scope.filterstring)
{
if ($scope.AllsearchAIViewData != undefined) {
localStorage.setItem("currentpage", $scope.currentPage);
if ($scope.activeTab == 1) {
$scope.searchAIImageViewData = $scope.AllsearchAIViewData.slice(begin, end);
}
else {
$scope.searchAIListViewData = $scope.AllsearchAIViewData.slice(begin, end);
}
}
}
else
{
if ($scope.AllAIListViewData != undefined) {
localStorage.setItem("currentpage", $scope.currentPage);
$scope.selectedAIListViewData = $scope.AllAIListViewData.slice(begin, end);
}
}
});
var searchByText = $rootScope.getLocalStorageValue("SearchText");
var searchTextByAlphabet = $rootScope.getLocalStorageValue("SearchByAlphabet");
var SelectCurrTab = $rootScope.getLocalStorageValue("currentAITabView");
$scope.initializeAIWindowData = function (windowviewid, isOpenWithExistsModule, openPanelNo) {
if (isOpenWithExistsModule || openPanelNo == 0) {
if ($rootScope.AIWindowData != undefined) {
$rootScope.AIWindowData.length = 0;
}
else {
$rootScope.AIWindowData = [];
}
$rootScope.AIWindowData.push(
{
'multiwinid': windowviewid,
'IllustrationData': [],
'searchAIListViewData': [],
'ImageCount':200,
'AIImagePath': '',
'moduleName': '',
'currentViewTitle': '',
'parentSlugName': '',
'currentSlug': '',
'imageId': '',
'imageName': '',
});
}
else {
var isNewWindow = true;
for (var k = 0; k < $rootScope.AIWindowData.length; k++) {
if ($rootScope.AIWindowData[k].multiwinid == windowviewid) {
isNewWindow = false;
break;
}
}
if (isNewWindow) {
$rootScope.AIWindowData.push(
{
'multiwinid': windowviewid,
'IllustrationData': [],
'searchAIListViewData': [],
'ImageCount': 200,
'AIImagePath': '',
'moduleName': '',
'currentViewTitle': '',
'parentSlugName': '',
'currentSlug': '',
'imageId': '',
'imageName': '',
});
}
}
}
$scope.GetAIwindowStoreData = function (windowviewid, keyname) {
for (var x = 0 ; x < $rootScope.AIWindowData.length; x++) {
if ($rootScope.AIWindowData[x].multiwinid == windowviewid) {
return $rootScope.AIWindowData[x][keyname];
}
}
}
$scope.SetAIwindowStoreData = function (windowviewid, keyname, value) {
for (var x = 0 ; x < $rootScope.AIWindowData.length; x++) {
if ($rootScope.AIWindowData[x].multiwinid == windowviewid) {
$rootScope.AIWindowData[x][keyname] = value;
}
}
}
$rootScope.GetAIWindowId = function () {
// handle for single window
if ($rootScope.AIWindowData.length > 0) {
for (var x = 0 ; x < $rootScope.AIWindowData.length; x++) {
return $rootScope.AIWindowData[x].multiwinid;
}
}
else return 0;
}
$scope.DisableUI = function () {
var aiImagePanelConetent = document.getElementsByClassName("jsPanel-content");
for (var i = 0; i < aiImagePanelConetent.length; i++) {
aiImagePanelConetent[i].style.pointerEvents = "none";
aiImagePanelConetent[i].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');
//$('#imgParent').css('z-index', '1');
//document.getElementById("imgParent").style.pointerEvents = "none";
//document.getElementById("imgParent").style.opacity = "0.5";
}
$scope.EnableUI = function () {
var aiImagePanelConetent = document.getElementsByClassName("jsPanel-content");
for (var i = 0; i < aiImagePanelConetent.length; i++) {
aiImagePanelConetent[i].style.pointerEvents = "auto";
aiImagePanelConetent[i].style.opacity = "1";
}
$rootScope.isLoading = false;
$('#spinner').css('visibility', 'hidden');
// CB module enable all
$('#CBDetailPageDiv').css('pointer-events', 'auto');
$('#CBDetailPageDiv').css('opacity', '1');
//document.getElementById("imgParent").style.pointerEvents = "auto";
//document.getElementById("imgParent").style.opacity = "1.0";
}
$scope.PanelActivity = function () {
$("#" + $scope.jsPanelID).resize(function (event) {
//work on it
// alert('test');
});
// close panel
$(document).on("click", "#" + $scope.jsPanelID + " .jsPanel-hdr .jsPanel-hdr-r .jsPanel-btn-close .jsglyph-remove", function () {
var panelid = $(event.target).parent().parent().parent().parent().attr('id');
var len = (panelid).split("_").length;
var windowviewid = (panelid).split("_")[len - 1];
// remove old stored data after close panel
for (var index = 0 ; index < $rootScope.AIWindowData.length; index++) {
if ($rootScope.AIWindowData[index].multiwinid == windowviewid) {
if (index != -1) {
// remove module which one is loaded
$scope.AIWindowData.splice(index, 1);
if ($('#' + panelid).html() != undefined) {
$('#' + panelid).remove();
}
$rootScope.resetjsPanelTop();
}
}
}
});
}
//Modified code by sandeep for fixed Bugs of ADAM Images
$scope.setActiveTab = function (tabToSet, inderectCall, windowviewid) {
if (windowviewid == undefined)
windowviewid = $rootScope.MULTI_VIEW_ID;
$scope.DisableUI();
$scope.activeTab = tabToSet;
var pretab = $rootScope.getLocalStorageValue("currentAITabView");
if (pretab != tabToSet) {
$scope.currentPage = 1;
localStorage.setItem("currentpage", $scope.currentPage);
}
else {
$scope.currentPage = parseInt($rootScope.getLocalStorageValue("currentpage"));
}
localStorage.setItem("currentAITabView", $scope.activeTab);
var ImageCount = $scope.GetAIwindowStoreData(windowviewid, 'ImageCount');
var searchText = $rootScope.getLocalStorageValue("SearchText");
var SearchByAlphabet = $rootScope.getLocalStorageValue("SearchByAlphabet");
$scope.hiderow = false;
if (tabToSet == 2) {
var curSelectedRowId = $rootScope.getLocalStorageValue("AISelectedRowId");
$('#' + $rootScope.getLocalStorageValue("currentAIImageId")).addClass("selected");
$scope.idSelected = $rootScope.getLocalStorageValue("currentAIImageId");
var selectedImageId = $rootScope.getLocalStorageValue("currentAIImageId");
if (searchText != '' && searchText != null && searchText != undefined) {
$scope.ApplySearch(searchText, windowviewid);
if (inderectCall == true) {
if (curSelectedRowId != "") {
$scope.showItem(curSelectedRowId, windowviewid);
}
} else {
if (selectedImageId != "") {
$scope.filterstring = false;
$scope.showItem(selectedImageId, windowviewid);
$scope.filterstring = true;
}
}
}
else if (SearchByAlphabet != "" && SearchByAlphabet != null && SearchByAlphabet != undefined) {
$scope.ApplySearchByAlphabet(SearchByAlphabet, windowviewid);
if (inderectCall == true) {
if (curSelectedRowId != "") {
$scope.showItem(curSelectedRowId, windowviewid);
}
} else {
if (selectedImageId != "") {
$scope.filterstring = false;
$scope.showItem(selectedImageId, windowviewid);
$scope.filterstring = true;
}
}
}
else {
$scope.loadAllAI(ImageCount, windowviewid);
if (inderectCall == true) {
if (curSelectedRowId != "") {
$scope.filterstring = true;
$scope.showItem(curSelectedRowId, windowviewid);
$scope.filterstring = false;
}
} else {
if (selectedImageId != "") {
$scope.filterstring = false;
$scope.showItem(selectedImageId, windowviewid);
}
}
}
$scope.query.SelectedDiv = tabToSet;
//Method call for set position for selected title Bug-57978
$('#grid-view').css("display", "none");
$('#list-view').css("display", "block");
}
else {
$('#' + $rootScope.getLocalStorageValue("currentAIImageId")).find('.thumbnail').addClass('HightLightThumbnail');
$('#' + $rootScope.getLocalStorageValue("currentAIImageId")).removeClass('selected');
$scope.query.SelectedDiv = tabToSet;
//Modified Code by sandeep for fixed bug-45300
if (searchText != '' && searchText != null && searchText != undefined) {
$scope.ApplySearch(searchText, windowviewid);
}
else if (SearchByAlphabet != "" && SearchByAlphabet != null && SearchByAlphabet != undefined) {
$scope.ApplySearchByAlphabet(SearchByAlphabet, windowviewid);
}
else {
$scope.loadAllAI(ImageCount, windowviewid);
}
$('#grid-view').css("display", "block");
$('#list-view').css("display", "none");
}
setTimeout(function () {
$scope.setImgPosition();
}, 500);
};
$scope.loadAIModuleById = function (moduleId) {
$rootScope.isCallFromOtherModule = undefined;
$rootScope.MULTI_VIEW_ID += 1;
$scope.DisableUI();
// store exist module in module service
var ExistData = ModuleService.getModuleData("ADAM_IMAGES");
if (ExistData != undefined && ExistData.length > 0) {
// clear all module data before open new module in cb
ModuleService.ClearWinDataByModule(ExistData.mType);
}
var newWindowData = {
"mType": 'ADAM_IMAGES',
};
ModuleService.setModuleData(newWindowData, 0);
$scope.initializeAIWindowData($rootScope.MULTI_VIEW_ID, true, undefined);
if ($rootScope.checkRefreshButtonClick == 1) {
var query = $scope.query;
$scope.ResetCurrentModule(query, $rootScope.MULTI_VIEW_ID);
$rootScope.checkRefreshButtonClick = 0;
}
var ImageCount = $scope.GetAIwindowStoreData($rootScope.MULTI_VIEW_ID, 'ImageCount');
if ($rootScope.refreshcheck == null) {
$location.path('/');
}
//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.SetAIwindowStoreData($rootScope.MULTI_VIEW_ID, 'moduleName', "Adam Images");
$scope.LoadAIJsonData(ImageCount, $rootScope.MULTI_VIEW_ID);
$scope.scroll();
//push the details of open module in array $rootScope.openModules
$rootScope.openModules.push({ "ModuleId": 13 });
//set the local storage
setTimeout(function () {
var curtab = $rootScope.getLocalStorageValue("currentAITabView");
var inderectCall = true;
if (curtab == 2) {
$scope.setActiveTab(2, inderectCall);
var curSelectedRowId = $rootScope.getLocalStorageValue("AISelectedRowId");
if (typeof (curSelectedRowId) !== "undefined" && curSelectedRowId !== null && curSelectedRowId !== '') {
$scope.reRunSearchOnLoad($rootScope.MULTI_VIEW_ID);
$scope.idSelected = curSelectedRowId;
$scope.ReloadListViewImageDiv($scope.idSelected, ImageCount, $rootScope.MULTI_VIEW_ID);
}
else {
$scope.reRunSearchOnLoad($rootScope.MULTI_VIEW_ID)
$scope.idSelected = '';
}
}
else {
$scope.setActiveTab(1, inderectCall);
$scope.reRunSearchOnLoad($rootScope.MULTI_VIEW_ID);
}
}, 500);
}
$scope.reRunSearchOnLoad = function (windowviewid) {
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 = "";
}
}
$scope.LoadAIJsonData = function (ImageCount, windowviewid) {
$('ul li span').removeAttr("style");
var promise = DataService.getJson('~/../content/data/json/ai/ai_dat_contentlist.json')
promise.then(
function (result) {
var IllustrationData = new jinqJs()
.from(result.root.AIData)
.orderBy([{ field: '_Title', sort: 'asc' }])
//.select().slice(0, ImageCount);
.select();
$scope.AllAIListViewData = IllustrationData;
$scope.totalimage = IllustrationData.length;
// $scope.currentPage = 1;
$scope.SetAIwindowStoreData(windowviewid, 'IllustrationData', IllustrationData);
},
function (error) {
$scope.EnableUI();
// handle errors here
console.log(' $scope.IllustrationData = ' + error.statusText);
}
);
};
$scope.loadAllAI = function (ImageCount, windowviewid) {
$rootScope.isLoading = true;
localStorage.setItem("SearchText", '');
localStorage.setItem("SearchByAlphabet", '');
$('ul li span').removeAttr("style");
var IllustrationData = $scope.GetAIwindowStoreData(windowviewid, 'IllustrationData');
// $scope.selectedAIListViewData = $scope.GetAIwindowStoreData(windowviewid, 'IllustrationData');
$scope.AllAIListViewData = IllustrationData;
$scope.totalimage = IllustrationData.length;
$scope.selectedAIListViewData = new jinqJs()
.from(IllustrationData)
.orderBy([{ field: '_Title', sort: 'asc' }])
.select().slice(0, $scope.numPerImage);
$('#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" && $scope.query.SelectedDiv == 1) {
$('html, body').animate({ scrollTop: $rootScope.getLocalStorageValue('AIGridViewScroll') });
}
}, 100);
$timeout(function () { $scope.EnableUI(); }, 500);
}
$scope.IsVisible = function () {
$scope.scroll();
}
$scope.showItem = function (id, windowviewid) {
if (windowviewid == undefined)
windowviewid = $rootScope.MULTI_VIEW_ID;
//Modified code by sandeep for fixed issue of ADAM Images
$scope.idSelected = id;
localStorage.setItem("AISelectedRowId", id);
//Set the vertical scroll value of the table.
var y = $('#ListViewDiv').scrollTop();
localStorage.setItem("AIListViewScroll", y);
//$('#' + id).find('.thumbnail').addClass('HightLightThumbnail');
localStorage.setItem("currentAIImageId", id);
if ($scope.filterstring == false) {
var SelectedAIthumbImage = [];
SelectedAIthumbImage = new jinqJs()
.from($scope.selectedAIListViewData)
.where('_id = ' + id)
.select('_ThumbnailImage', '_id', '_Title');
if (SelectedAIthumbImage.length > 0) {
$scope.SelectedAIthumbImage = "~/../content/images/ai/thumbnails/" + SelectedAIthumbImage[0]._ThumbnailImage;
$scope.SelectedAIId = SelectedAIthumbImage[0]._id;
$scope.SelectedAITitle = SelectedAIthumbImage[0]._Title;
$scope.hiderow = true;
}
else
{ $scope.hiderow = false; }
}
else {
var searchAIListViewData = $scope.GetAIwindowStoreData(windowviewid, 'searchAIListViewData');
if (searchAIListViewData.length > 0) {
var SelectedAIthumbImage = [];
SelectedAIthumbImage = new jinqJs()
.from(searchAIListViewData)
.where('_id = ' + id)
.select('_ThumbnailImage', '_id', '_Title');
if (SelectedAIthumbImage.length > 0) {
$scope.SelectedAIthumbImage = "~/../content/images/ai/thumbnails/" + SelectedAIthumbImage[0]._ThumbnailImage;
$scope.SelectedAIId = SelectedAIthumbImage[0]._id;
$scope.SelectedAITitle = SelectedAIthumbImage[0]._Title;
$scope.hiderow = true;
} else { $scope.hiderow = false; }
}
}
};
$scope.ResetCurrentModule = function (query) {
$('ul li span').removeAttr("style");
query.SearchText = "";
$scope.idSelected = '';
$scope.hideListViewDiv();
//set localstorage values
localStorage.setItem("SearchText", '');
localStorage.setItem("SearchByAlphabet", '');
localStorage.setItem("AIListViewScroll", '');
localStorage.setItem("AIGridViewScroll", '');
localStorage.setItem("currentAITabView", '');
localStorage.setItem("AIListViewScrollPosition", '');
localStorage.setItem("AISelectedRowId", '');
localStorage.setItem("currentAIImageId", '');
localStorage.setItem("listViewSelectedID", '');
localStorage.setItem("AIGridViewHighlightThumbnail", '');
localStorage.setItem("currentViewTitle", '');
if ($('.selected').hasClass("selected")) {
$('.selected').removeClass("selected");
}
$('#ListViewDiv').scrollTop(0);
$scope.currentPage = 1;
}
//Code changes by Sandeep for fixed bug-57854
$scope.Reset = function (query, windowviewid) {
if (windowviewid == undefined)
windowviewid = $rootScope.MULTI_VIEW_ID;
$('ul li span').removeAttr("style");
query.SearchText = "";
$scope.idSelected = '';
$scope.hideListViewDiv();
//set localstorage values
localStorage.setItem("SearchText", '');
localStorage.setItem("SearchByAlphabet", '');
localStorage.setItem("AIListViewScroll", '');
localStorage.setItem("AIGridViewScroll", '');
localStorage.setItem("currentAITabView", '');
localStorage.setItem("AIListViewScrollPosition", '');
localStorage.setItem("AISelectedRowId", '');
localStorage.setItem("currentAIImageId", '');
localStorage.setItem("listViewSelectedID", '');
localStorage.setItem("AIGridViewHighlightThumbnail", '');
localStorage.setItem("currentViewTitle", '');
var ImageCount = $scope.GetAIwindowStoreData(windowviewid, 'ImageCount');
if ($('.selected').hasClass("selected")) {
$('.selected').removeClass("selected");
}
$('#ListViewDiv').scrollTop(0);
$scope.SetAIwindowStoreData(windowviewid, 'searchAIListViewData', []);
$scope.filterstring = false;
$scope.currentPage = 1;
$scope.DisableUI();
$scope.loadAllAI(ImageCount, windowviewid);
}
$scope.ApplySearch = function (query, windowviewid) {
if (windowviewid == undefined)
{
$scope.currentPage = 1;
windowviewid = $rootScope.MULTI_VIEW_ID;
}
$scope.DisableUI();
var currentSearchtext = $rootScope.getLocalStorageValue("SearchText");
//localStorage.setItem("SearchText", '');
localStorage.setItem("SearchByAlphabet", '');
if (typeof (query) !== "undefined" && (query !== null && query !== "")) {
currentSearchtext = query.SearchText;
$scope.query.SearchText = query.SearchText;
if (currentSearchtext == undefined || $scope.query.SearchText == undefined) {
currentSearchtext = query;
$scope.query.SearchText = query;
}
}
localStorage.setItem("SearchText", currentSearchtext);
if (currentSearchtext == "undefined" || (currentSearchtext == null || currentSearchtext == "")) {
if ($scope.query.SearchText == "undefined" || ($scope.query.SearchText == null || $scope.query.SearchText == "")) {
$rootScope.errorMessage = AIAConstants.PLEASE_ENTER_SEARCH_TEXT;
$("#messageModal").modal('show');
$scope.EnableUI();
return false;
}
}
//Modified code by sandeep for fixed issue of ADAM Images
$('ul li span').removeAttr("style");
$scope.idSelected = '';
$scope.hiderow = false;
$scope.SetAIwindowStoreData(windowviewid, 'searchAIListViewData', []);
$scope.filterstring = true;
if (typeof ($scope.query.SearchText) !== "undefined" && ($scope.query.SearchText !== null && $scope.query.SearchText !== "")) {
//localStorage.setItem("SearchText", query.SearchText);
localStorage.setItem("SearchText", $scope.query.SearchText);
}
else {
localStorage.setItem("SearchText", '');
}
var selectedAIListViewData = $scope.GetAIwindowStoreData(windowviewid, 'IllustrationData');
//$scope.selectedAIListViewData = $scope.GetAIwindowStoreData(windowviewid, 'IllustrationData');
var ailistviewdata = [];
$('#grid-view').empty();
angular.forEach(selectedAIListViewData, function (value, key) {
var selectimg = true;
//var count = 0;
if (typeof ($scope.query.SearchText) !== "undefined" && ($scope.query.SearchText !== null && $scope.query.SearchText !== "")) {
var SearchText = $scope.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 = $('').appendTo('#grid-view');
//$compile($el)($scope);
ailistviewdata.push(
{
"_id": value._id,
//"_ImageId": value._ImageId,
"_Title": value._Title,
"_contentImage": value._contentImage,
"_ThumbnailImage": value._ThumbnailImage,
});
}
});
$('table > #ListViewDiv > #searchItem').remove();
$scope.SetAIwindowStoreData(windowviewid, 'searchAIListViewData', ailistviewdata);
$scope.totalimage = ailistviewdata.length;
$scope.AllsearchAIViewData = ailistviewdata;
if ($scope.activeTab == 1) {
//for image view
$scope.searchAIImageViewData = new jinqJs()
.from(ailistviewdata)
.orderBy([{ field: '_Title', sort: 'asc' }])
.select().slice(0, $scope.numPerImage);
var $e1 = $('').appendTo('#grid-view');
$compile($e1)($scope);
}
else {
// for list view
$scope.searchAIListViewData = new jinqJs()
.from(ailistviewdata)
.orderBy([{ field: '_Title', sort: 'asc' }])
.select().slice(0, $scope.numPerImage);
}
//Show Error Message in case of gridview if no data is found
if ($scope.AllsearchAIViewData.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! |
');
localStorage.setItem("SearchText", '');
}
$timeout(function () { $scope.EnableUI(); }, 500);
}
//Added method by sandeep for fixed Bug-57978 to selected Image
$scope.setImgPosition = function () {
var _currentImgId = $rootScope.getLocalStorageValue("currentAIImageId");
var aISelectedRowId = $rootScope.getLocalStorageValue("AISelectedRowId");
if (_currentImgId != "null" && _currentImgId != null) {
var dd = $('#' + _currentImgId).find('.thumbnail');
$('#' + _currentImgId).find('.thumbnail').addClass('HightLightThumbnail');
// $scope.hiderow = true;
}
if ($('#grid-view').css("display") == "block") {
var aiGridViewScroll = $rootScope.getLocalStorageValue('AIGridViewScroll');
if (aiGridViewScroll !== null && $location.url() == "/ADAM-images" && aiGridViewScroll != "0") {
$('html, body').animate({ scrollTop: $rootScope.getLocalStorageValue('AIGridViewScroll') }, 'slow');
}
else if (_currentImgId != "null" && _currentImgId != null) {
$('html, body').animate({ scrollTop: $('#' + _currentImgId).position().top }, 100);
}
}
if ($('#list-view').css("display") == "block") {
var AIListViewScroll = $rootScope.getLocalStorageValue("AIListViewScrollPosition");
if (AIListViewScroll !== null && $location.url() == "/ADAM-images" && AIListViewScroll != "0") {
$('#ListViewDiv').animate({ scrollTop: $rootScope.getLocalStorageValue('AIListViewScrollPosition') }, 'slow');
}
//if (_currentImgId != "null" && _currentImgId != null) {
// $('html, body').animate({ scrollTop: _currentImgId }, 'slow');
//}
else if (aISelectedRowId != "null" && aISelectedRowId != null) {
$('html, body').animate({ scrollTop: $('#' + aISelectedRowId).position().top }, 100);
}
}
}
$scope.ApplySearchByAlphabet = function (SearchTextByAlphabet, windowviewid) {
if (windowviewid == undefined) {
$scope.currentPage = 1;
windowviewid = $rootScope.MULTI_VIEW_ID;
}
//Modified code by sandeep for fixed issue of ADAM Images
$rootScope.SearchTextByAlphabet = SearchTextByAlphabet;
localStorage.setItem("SearchText", '');
$('#txtSerachInput').val("");
$scope.idSelected = '';
$scope.hiderow = false;
$scope.DisableUI();
$('ul li span').removeAttr("style");
$('#' + $rootScope.SearchTextByAlphabet).css({ "color": "white", "background-color": "#1B92D0" });
$scope.filterstring = true;
$scope.SetAIwindowStoreData(windowviewid, 'searchAIListViewData', []);
if (typeof (SearchTextByAlphabet) !== "undefined" && (SearchTextByAlphabet !== null && SearchTextByAlphabet !== "")) {
localStorage.setItem("SearchByAlphabet", SearchTextByAlphabet);
}
else {
localStorage.setItem("SearchByAlphabet", '');
}
var selectedAIListViewData = $scope.GetAIwindowStoreData(windowviewid, 'IllustrationData');
//$scope.selectedAIListViewData = $scope.GetAIwindowStoreData(windowviewid, 'IllustrationData');
var ailistviewdata = [];
$('#grid-view').empty();
angular.forEach(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 = $('').appendTo('#grid-view');
//$compile($el)($scope);
ailistviewdata.push(
{
"_id": value._id,
//"_ImageId": value._ImageId,
"_Title": value._Title,
"_contentImage": value._contentImage,
"_ThumbnailImage": value._ThumbnailImage,
});
}
});
$('table > #ListViewDiv > #searchItem').remove();
$scope.SetAIwindowStoreData(windowviewid, 'searchAIListViewData', ailistviewdata);
$scope.totalimage = ailistviewdata.length;
$scope.AllsearchAIViewData = ailistviewdata;
if ($scope.activeTab == 1)
{
//for image view
$scope.searchAIImageViewData = new jinqJs()
.from(ailistviewdata)
.orderBy([{ field: '_Title', sort: 'asc' }])
.select().slice(0, $scope.numPerImage);
var $e1 = $('').appendTo('#grid-view');
$compile($e1)($scope);
}
else
{
// for list view
$scope.searchAIListViewData = new jinqJs()
.from(ailistviewdata)
.orderBy([{ field: '_Title', sort: 'asc' }])
.select().slice(0, $scope.numPerImage);
}
//Show Error Message in case of gridview if no data is found
if ($scope.AllsearchAIViewData.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! |
');
}
$timeout(function () { $scope.EnableUI(); }, 500);
}
$scope.scroll = function () {
//$("html,body").scrollTop(0);
}
$scope.OpenAdamImage = function ($event) {
var windowviewid = $rootScope.MULTI_VIEW_ID;
$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.AllAIListViewData)
.where('_id = ' + $event.currentTarget.id)
.select();
$rootScope.ViewTitle = AITitle[0]._Title;
}
else {
$rootScope.ViewTitle = $event.currentTarget.textContent;
}
// open module bu openresource
var isopenResourceRequest = sessionStorage.getItem('isModuleOpenByOpenResource');
if (isopenResourceRequest == "true") {
//set default module data
var AIDopenData = {
"id": $event.currentTarget.id,
"mType": 'ADAM_IMAGES',
"windowTitle": $rootScope.ViewTitle,
"size": { height: 600, width: 900 }
};
window.parent.AIAModuleOpenResourceInfo(AIDopenData);
}
else {
localStorage.setItem("currentViewTitle", $rootScope.ViewTitle);
localStorage.setItem("currentAIImageId", $event.currentTarget.id);
$scope.SetAIwindowStoreData(windowviewid, 'currentViewTitle', $rootScope.ViewTitle);
$scope.SetAIwindowStoreData(windowviewid, 'imageId', $event.currentTarget.id);
var imageName = AITitle[0]._contentImage;
$scope.SetAIwindowStoreData(windowviewid, 'imageName', imageName);
var imagePath = "~/../content/images/ai/images/" + imageName;
$scope.SetAIwindowStoreData(windowviewid, 'AIImagePath', imagePath);
// store image for export
var tittle = $rootScope.getLocalStorageValue("currentViewTitle");
$rootScope.StoreTitleName(tittle);
$rootScope.StoreOrgImageName(imageName);
var moduleItemDataToBeSavedID = $event.currentTarget.id;
$("#list-view table tbody tr").removeClass("active");
localStorage.setItem("listViewSelectedID", moduleItemDataToBeSavedID);
$("#list-view table tbody #" + moduleItemDataToBeSavedID).addClass("active");
localStorage.setItem("AIListViewScrollPosition", $("#list-view table tbody").scrollTop());
//Set the vertical scroll value of the Grid-View.
var y = $($window).scrollTop();
localStorage.setItem("AIGridViewScroll", y);
localStorage.setItem("AIGridViewHighlightThumbnail", $(event.target).parent().parent().parent().attr('id'));
var u = $location.url();
$location.url('/adam-images-detail');
}
}
$rootScope.OpenAdamImageViewMain = function () {
if ($rootScope.isCallFromOtherModule) {
$scope.AIModuleData = ModuleService.getModuleData("ADAM_IMAGES");
$scope.readyToLoad = true;
$rootScope.AIWindowLoadComplete = false;
$scope.wincount = 1;
var winlen = $scope.AIModuleData.length;
var timeint = null;
timeint = $interval(function () {
if ($scope.readyToLoad == true) {
var windata = $scope.AIModuleData[$scope.wincount - 1];
$scope.OpenAdamImageView(windata);
}
$scope.readyToLoad = false;
if ($scope.wincount < winlen && $rootScope.AIWindowLoadComplete == true) {
$scope.wincount = $scope.wincount + 1;
$rootScope.AIWindowLoadComplete = false;
$scope.readyToLoad = true;
}
if ($scope.wincount == winlen && $rootScope.AIWindowLoadComplete == true) {
$scope.stopInterval();
$scope.$emit("LoadModuleComplete", "ADAM_IMAGES");
}
}, 100);
$scope.stopInterval = function () {
if (angular.isDefined(timeint)) {
$interval.cancel(timeint);
timeint = undefined;
}
};
}
else {
$scope.OpenAdamImageView(null);
}
}
$scope.OpenAdamImageView = function (aiModuleData) {
if ($rootScope.isCallFromOtherModule == true) {
$scope.aiOpenInOtherModules = aiModuleData;
$rootScope.MULTI_VIEW_ID += 1;
var windowviewid = $rootScope.MULTI_VIEW_ID;
$scope.initializeAIWindowData(windowviewid, false, $scope.aiOpenInOtherModules.currentWindowId);
var moduleName = $scope.aiOpenInOtherModules.mType;
$scope.SetAIwindowStoreData(windowviewid, 'moduleName', moduleName);
var promise = DataService.getJson('~/../content/data/json/ai/ai_dat_contentlist.json');
promise.then(
function (result) {
var IllustrationData = new jinqJs()
.from(result.root.AIData)
.orderBy([{ field: '_Title', sort: 'asc' }])
.select();
// serial no of imageid
var imageId = $scope.aiOpenInOtherModules.id;
$scope.SetAIwindowStoreData(windowviewid, 'imageId', imageId);
var selectedTileData = [];
selectedTileData = new jinqJs()
.from(IllustrationData)
.where('_id == ' + imageId)
.select();
var imageName = selectedTileData[0]._contentImage;
$scope.SetAIwindowStoreData(windowviewid, 'imageName', imageName);
var imagePath = "~/../content/images/ai/images/" + imageName;
$scope.SetAIwindowStoreData(windowviewid, 'AIImagePath', imagePath);
var aiTitle = $scope.aiOpenInOtherModules.anatomyTitle;
$scope.SetAIwindowStoreData(windowviewid, 'currentViewTitle', aiTitle);
localStorage.setItem("currentViewTitle", aiTitle);
// store image for export
$rootScope.StoreTitleName(aiTitle);
$rootScope.StoreOrgImageName(selectedTileData[0]._contentImage);
$scope.SetAIwindowStoreData(windowviewid, 'parentSlugName', ($location.url()).replace('/', ''));
$scope.loadAIllustration(windowviewid);
},
function (error) {
// handle errors here
console.log(' $scope.AIllustrationData = ' + error.statusText);
}
);
}
else {
$scope.SetAIwindowStoreData($rootScope.MULTI_VIEW_ID, 'parentSlugName', 'ADAM-images');
$scope.loadAIllustration($rootScope.MULTI_VIEW_ID);
}
}
$scope.loadAIllustration = function (windowviewid) {
if ($rootScope.refreshcheck == null) {
$location.path('/');
}
$scope.jsPanelID = 'aiImagePanel' + '_' + windowviewid;
var selectedCIImage = $scope.GetAIwindowStoreData(windowviewid, 'AIImagePath');
var tittle = $scope.GetAIwindowStoreData(windowviewid, 'currentViewTitle');
var imageId = $scope.GetAIwindowStoreData(windowviewid, 'imageId');
if ($rootScope.isCallFromOtherModule) {
// open JS panel for curriculum with define cornonate in CB jason
$scope.jsPanelWidth = $scope.aiOpenInOtherModules.size.width;//1000;
$scope.jsPanelHeight = $scope.aiOpenInOtherModules.size.height;
if ($scope.aiOpenInOtherModules.size.height > 540)
$scope.jsPanelHeight = 540;
$scope.jsPanelLeft = 320;
$scope.jsPanelTop = $rootScope.cBModulejsPanelTop();
}
else {
$scope.jsPanelWidth = $(window).outerWidth() - 30;
$scope.jsPanelHeight = $(window).outerHeight() - 125;
$scope.jsPanelLeft = 15;
$scope.jsPanelTop = 70;
}
if (selectedCIImage.length > 0) {
$.jsPanel({
id: $scope.jsPanelID,
selector: '.aiView',
theme: 'success',
currentController: 'AIController',
parentSlug: $scope.GetAIwindowStoreData(windowviewid, 'parentSlugName'),
content: '
' +
'
' +
'

' +
'
',
title: tittle,
position: {
top: $scope.jsPanelTop,
left: $scope.jsPanelLeft
},
size: {
width: $scope.jsPanelWidth,
height: $scope.jsPanelHeight
},
});
$('#canvasDivAI_' + windowviewid + ' img').load(function () {
$scope.JsPanelclick(windowviewid);
$rootScope.AIWindowLoadComplete = true;
var canvas = document.getElementById("canvasAI_" + windowviewid);
var canvasPaint = document.getElementById("canvasPaintAI_" + windowviewid);
canvas.height = $("#" + $scope.jsPanelID + " .jsPanel-content").height();
canvasPaint.height = $("#" + $scope.jsPanelID + " .jsPanel-content").height();
});
$scope.SetAIwindowStoreData(windowviewid, 'currentSlug', 'adam-images-detail');
$rootScope.openViews.push(
{
"module": $rootScope.currentActiveModuleTitle, "bodyView": tittle, "state": 'max', "BodyViewId": imageId,
"slug": $scope.GetAIwindowStoreData(windowviewid, 'currentSlug')
});
$("#" + $scope.jsPanelID + " .img-thumbnail").css("min-height", $("#" + $scope.jsPanelID + " .jsPanel-content").height());
$('.jsPanel-content .jsPanel-theme-success').css('overflow-y', 'auto !important')
var jspContentHeight = $('.jsPanel-content').height();
// console.log($rootScope.OpenAdamImages);
$('#AIView').css("height", $(window).outerHeight() - 65);
$('#AIView').css("width", $(window).outerWidth() - 15);
//var canvasDIvHeight = parseInt($('#aiImagePanel').outerHeight()) - 30;
var canvasDIvHeight = $("#" + $scope.jsPanelID + " .jsPanel-content").height();
$('#canvasDivCI_' + windowviewid).css('height', canvasDIvHeight);
}
$scope.PanelActivity();
}
$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" });
$('#canvasAI_' + $rootScope.MULTI_VIEW_ID).css("display", "block");
$('#canvasPaintAI_' + $rootScope.MULTI_VIEW_ID).css("display", "block");
$rootScope.onDrawingCanvasClick();
});
$scope.ReloadListViewImageDiv = function (id, imgCount, windowviewid) {
$scope.idSelected = id;
var IllustrationData = $scope.GetAIwindowStoreData(windowviewid, 'IllustrationData');
var SelectedAIthumbImage = [];
SelectedAIthumbImage = new jinqJs()
.from(IllustrationData)
.where('_id = ' + id)
.select('_ThumbnailImage', '_id', '_Title').slice(0, imgCount);
if (SelectedAIthumbImage.length > 0) {
$scope.SelectedAIthumbImage = "~/../content/images/ai/thumbnails/" + SelectedAIthumbImage[0]._ThumbnailImage;
$scope.SelectedAIId = SelectedAIthumbImage[0]._id;
$scope.SelectedAITitle = SelectedAIthumbImage[0]._Title;
$scope.hiderow = true;
} else { $scope.hiderow = false; }
};
$scope.hideListViewDiv = function () {
if ($rootScope.getLocalStorageValue("currentAITabView") == 2) {
//localStorage.setItem("AISelectedRowId", "");
if ($('.selected').hasClass("selected")) { $('.selected').removeClass("selected"); }
$scope.hiderow = false;
}
}
$scope.JsPanelclick = function (windowviewid) {
// call from while open module in CB
$("#aiImagePanel_" + windowviewid).on('click', function (event) {
var pnlName = event.currentTarget.id;
$scope.$emit("cBEnableDisableMenuOption", pnlName);
// store image for export while click on panel
var currentViewTitle = $scope.GetAIwindowStoreData(windowviewid, 'currentViewTitle');
var imageName = $scope.GetAIwindowStoreData(windowviewid, 'imageName');
$rootScope.StoreTitleName(currentViewTitle);
$rootScope.StoreOrgImageName(imageName);
});
}
}]
);