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 = 108;
$scope.maxSize = 10;
$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.ObjectAttribute=function(windowviewid)
{
var windata={
'multiwinid': windowviewid,
'IllustrationData': [],
'searchAIListViewData': [],
'ImageCount':200,
'AIImagePath': '',
'moduleName': '',
'currentViewTitle': '',
'parentSlugName': '',
'currentSlug': '',
'imageId': '',
'imageName': '',
'y': 0,
'x': 0,
'width': 0,
'height': 0,
'minimised': false,
'maximised': true,
'minmaxAutoEvent':true,
'annotationData':{shapeStates:[],paintCanvasState:[]},
};
return windata;
}
$scope.initializeAIWindowData = function (windowviewid, isOpenWithExistsModule, openPanelNo) {
if (isOpenWithExistsModule || openPanelNo == 0) {
if ($rootScope.AIWindowData != undefined) {
$rootScope.AIWindowData.length = 0;
}
else {
$rootScope.AIWindowData = [];
}
$rootScope.AIWindowData.push($scope.ObjectAttribute(windowviewid));
}
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($scope.ObjectAttribute(windowviewid));
}
}
}
$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;
}
}
}
// access from home controller
$rootScope.GetAIwindowData=function(windowviewid,keyname)
{
for(var x=0 ;x < $rootScope.AIWindowData.length;x++){
if($rootScope.AIWindowData[x].multiwinid==windowviewid)
{
return $rootScope.AIWindowData[x][keyname];
}
}
}
// access from home controller
$rootScope.SetAIwindowData=function(windowviewid,keyname,data) {
for(var x=0 ;x < $rootScope.AIWindowData.length;x++){
if($rootScope.AIWindowData[x].multiwinid==windowviewid)
{
$rootScope.AIWindowData[x][keyname]=data;
}
}
}
$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
$('#HomeContainerDiv').css('pointer-events', 'none');
$('#HomeContainerDiv').css('opacity', '0.7');
}
$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
$('#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.AIWindowData.length; index++) {
if ($rootScope.AIWindowData[index].multiwinid == windowviewid) {
if (index != -1) {
// remove module which one is loaded
$rootScope.AIWindowData.splice(index, 1);
if ($('#' + panelid).html() != undefined) {
$('#' + panelid).remove();
}
// $rootScope.resetjsPanelTop(panelid);
}
}
}
}
$scope.PanelActivity = function () {
$(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);
});
}
//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();
if(tabToSet=="" ||tabToSet==undefined)
{
$scope.activeTab=1;
}
else
{
$scope.activeTab = tabToSet;
}
var pretab = $rootScope.getLocalStorageValue("currentAITabView");
if (pretab != $scope.activeTab) {
$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 ($scope.activeTab == 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);
// close/remove prev panel when in minimised mode
if($rootScope.AIWindowData!=undefined)
{
if($rootScope.AIWindowData.length>0)
{
for(var x=0 ;x < $rootScope.AIWindowData.length;x++){
var winid=$rootScope.AIWindowData[x].multiwinid;
if ($('#aiImagePanel_' + winid).html() != undefined) {
$('#aiImagePanel_' + winid).remove();
}
}
$rootScope.AIWindowData=[];
}
}
$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;
//call time interval function until load Illustration data
var timeintval = null;
timeintval = $interval(function () {
var IllustrationData = $scope.GetAIwindowStoreData($rootScope.MULTI_VIEW_ID, 'IllustrationData');
if (IllustrationData.length>0) {
$scope.stopIntervalAI();
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);
}
}
else
{
console.log("waiting for Illustration Data");
}
}, 100);
$scope.stopIntervalAI = function () {
if (angular.isDefined(timeintval)) {
$interval.cancel(timeintval);
timeintval = undefined;
}
};
}, 100);
}
$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;
console.log("Illustration Data loaded");
$scope.SetAIwindowStoreData(windowviewid, 'IllustrationData', IllustrationData);
},
function (error) {
$scope.EnableUI();
// handle errors here
console.log(' $scope.IllustrationData = ' + error.statusText);
}
);
};
$scope.loadAllAI = function (ImageCount, windowviewid) {
localStorage.setItem("SearchText", '');
localStorage.setItem("SearchByAlphabet", '');
$('ul li span').removeAttr("style");
console.log("loadAllAI method called");
var IllustrationData = $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();
$rootScope.ResetGridListLength();
}, 500);
}
$rootScope.ResetGridListLength=function()
{
var $ua = navigator.userAgent;
if (($ua.match(/(iPod|iPhone|iPad|android)/i))) {
var srchHeight=$('.breadcrumb').height();
var gridheight=screen.height-srchHeight-132;
var listheight=screen.height-srchHeight-356;
$('#grid-view').css({"height":gridheight,"overflow":"auto"});
$('#ListViewDiv').css({"height":listheight,"overflow":"auto"});
}
else
{
var srchHeight=$('.breadcrumb').height();
var gridheight=screen.height-srchHeight-281;
var listheight=screen.height-srchHeight-504;
$('#grid-view').css({"height":gridheight,"overflow":"auto"});
$('#ListViewDiv').css({"height":listheight,"overflow":"auto"});
}
}
$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 == "")) {
$('#errorMessage').text(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) {
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();
$rootScope.ResetGridListLength();
}, 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) {
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();
$rootScope.ResetGridListLength();
}, 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 },
"position": { x: 1, y: 30 }
};
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");
if($scope.AIModuleData.length<1) return;
$scope.DisableUI();
$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.DisableUI();
$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);
var isMaximize = $scope.aiOpenInOtherModules.maximised!=undefined?$scope.aiOpenInOtherModules.maximised:false;
var isMinimize = $scope.aiOpenInOtherModules.minimised!=undefined?$scope.aiOpenInOtherModules.minimised:false;
$scope.SetAIwindowStoreData(windowviewid, 'maximised', isMaximize);
$scope.SetAIwindowStoreData(windowviewid, 'minimised', isMinimize);
// store image for export
$rootScope.StoreTitleName(aiTitle);
$rootScope.StoreOrgImageName(selectedTileData[0]._contentImage);
if($location.url()== "/curriculum-builder-detail") {
$scope.SetAIwindowStoreData(windowviewid,'parentSlugName',($location.url()).replace('/', ''));
}
else
{
$scope.SetAIwindowStoreData(windowviewid,'parentSlugName','ADAM-images');
}
$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 selectedAIImage = $scope.GetAIwindowStoreData(windowviewid, 'AIImagePath');
var tittle = $scope.GetAIwindowStoreData(windowviewid, 'currentViewTitle');
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 = $scope.aiOpenInOtherModules.position.x;
if ($scope.aiOpenInOtherModules.position.x <= 1)
$scope.jsPanelLeft =0;
$scope.jsPanelTop = $scope.aiOpenInOtherModules.position.y;
if ($scope.aiOpenInOtherModules.position.y < 30)
$scope.jsPanelTop = 30;
if($location.url()!= "/curriculum-builder-detail") {
$scope.jsPanelLeft = 1;
$scope.jsPanelTop = 85;
}
}
else {
$scope.jsPanelWidth = $(window).innerWidth() - 30;
$scope.jsPanelHeight =$(window).innerHeight() - 150;
$scope.jsPanelLeft = 1;
$scope.jsPanelTop = 55;
}
if (selectedAIImage.length > 0) {
$scope.jsPanelAI = $.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
},
onminimized:function (panel) {
var pnlName=panel[0].id;
var len = (pnlName).split("_").length;
var windowviewid = (pnlName).split("_")[len - 1];
var isAutoCalled = $scope.GetAIwindowStoreData(windowviewid, 'minmaxAutoEvent');
if(!isAutoCalled)
{
$rootScope.UnsaveCurriculum = true;
}
$scope.SetAIwindowStoreData(windowviewid, 'minimised',true);
$scope.SetAIwindowStoreData(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.GetAIwindowStoreData(windowviewid, 'minmaxAutoEvent');
if(!isAutoCalled)
{
$rootScope.UnsaveCurriculum = true;
}
$scope.SetAIwindowStoreData(windowviewid, 'maximised',true);
$scope.SetAIwindowStoreData(windowviewid, 'minimised',false);
var canvasDIvHeight = $('#aiImagePanel_' + windowviewid+ " .jsPanel-content").height();
$('#canvasDivAI_' + windowviewid).css('height', canvasDIvHeight-5);
$rootScope.resetMenuOptionOnClick(pnlName);
},
onnormalized:function (panel) {
var pnlName=panel[0].id;
var len = (pnlName).split("_").length;
var windowviewid = (pnlName).split("_")[len - 1];
var isAutoCalled = $scope.GetAIwindowStoreData(windowviewid, 'minmaxAutoEvent');
if(!isAutoCalled)
{
$rootScope.UnsaveCurriculum = true;
}
$scope.SetAIwindowStoreData(windowviewid, 'minimised',false);
$scope.SetAIwindowStoreData(windowviewid, 'maximised',false);
var canvasDIvHeight = $('#aiImagePanel_' + windowviewid+ " .jsPanel-content").height();
$('#canvasDivAI_' + windowviewid).css('height', canvasDIvHeight-5);
$rootScope.resetMenuOptionOnClick(pnlName);
},
resizable: {
stop: function (event, ui) {
var pnlName=event.currentTarget.id;
var len = (pnlName).split("_").length;
var windowviewid = (pnlName).split("_")[len - 1];
$scope.SetAIwindowStoreData(windowviewid, 'width', ui.size.width);
$scope.SetAIwindowStoreData(windowviewid, 'height', ui.size.height);
$scope.SetAIwindowStoreData(windowviewid, 'y', ui.position.top);
$scope.SetAIwindowStoreData(windowviewid, 'x', ui.position.left);
$rootScope.UnsaveCurriculum = true;
var canvasDIvHeight = $('#aiImagePanel_' + windowviewid+ " .jsPanel-content").height();
$('#canvasDivAI_' + windowviewid).css('height', canvasDIvHeight-5);
$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.SetAIwindowStoreData(windowviewid, 'y', ui.position.top);
$scope.SetAIwindowStoreData(windowviewid, 'x', ui.position.left);
$rootScope.UnsaveCurriculum = true;
$rootScope.resetMenuOptionOnClick(pnlName);
}
},
});
var isMaximize = $scope.GetAIwindowStoreData(windowviewid, 'maximised');
var isMinimize = $scope.GetAIwindowStoreData(windowviewid, 'minimised');
if (isMaximize) {
$scope.jsPanelAI.maximize();
}
else if (isMinimize) {
$scope.jsPanelAI.minimize();
}
else {
$scope.jsPanelAI.normalize();
}
$rootScope.AllPanelObject(windowviewid,$scope.jsPanelAI);
$("#aiImagePanel_"+windowviewid).css('overflow','hidden');
// set false after initial call of min,max or normal
$scope.SetAIwindowStoreData(windowviewid, 'minmaxAutoEvent', false);
$scope.SetAIwindowStoreData(windowviewid, 'y', $scope.jsPanelTop);
$scope.SetAIwindowStoreData(windowviewid, 'x', $scope.jsPanelLeft);
$scope.SetAIwindowStoreData(windowviewid, 'width', $scope.jsPanelWidth);
$scope.SetAIwindowStoreData(windowviewid, 'height', $scope.jsPanelHeight);
$timeout(function () {
$('.jsPanel-content .jsPanel-theme-success').css('overflow-y', 'auto !important')
var canvasDIvHeight = $('#aiImagePanel_' + windowviewid+ " .jsPanel-content").height();
$('#canvasDivAI_' + windowviewid).css('height', canvasDIvHeight-5);
var canvas = document.getElementById("canvasAI_" + windowviewid);
var canvasPaint = document.getElementById("canvasPaintAI_" + windowviewid);
var $ua = navigator.userAgent;
if (($ua.match(/(iPod|iPhone|iPad|android)/i))) {
canvas.width = screen.width-20;
canvasPaint.width = screen.width-20;
canvas.height = screen.height-130;
canvasPaint.height = screen.height-130;
}
else
{
canvas.height = screen.height-280;
canvasPaint.height = screen.height-280;
canvas.width = screen.width-40;
canvasPaint.width = screen.width-40;
}
$scope.SetAIwindowStoreData(windowviewid, 'currentSlug', 'adam-images-detail');
var openedImage = document.getElementById('aimage_' + windowviewid );
openedImage.src = selectedAIImage;
openedImage.onload = function () {
if (!$rootScope.isCallFromOtherModule) {
$("#aimage_"+windowviewid).css("left", (screen.width-this.width-70)/2 + "px");
}
$("#aimage_"+windowviewid).css("visibility","visible");
$scope.JsPanelclick(windowviewid);
if ($rootScope.isCallFromOtherModule) {
var annotationData= $scope.aiOpenInOtherModules.annotationData;
// load annotation
if(annotationData!="" && annotationData!=undefined)
{
if(annotationData.shapeStates.length>0||annotationData.paintCanvasState.length>0)
{
//first draw shape and then store in object
$rootScope.LoadCBSavedAnnotation("canvasAI_"+windowviewid,"canvasPaintAI_"+windowviewid,annotationData);
}
}
}
$scope.EnableUI();
$rootScope.AIWindowLoadComplete = true;
};
$scope.PanelActivity();
},300)
}
}
$rootScope.aiAnnotationToolEvent = function (windowviewid) {
$('#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_'+windowviewid).css("display", "block");
$('#canvasPaintAI_'+windowviewid).css("display", "block");
}
$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) {
//reset option list manager and annotation
//call when module loaded
$rootScope.resetMenuOption();
//remove pre event
// $("#aiImagePanel_" + windowviewid).off("click");
$("#aiImagePanel_" + windowviewid).on('click', function (event) {
//after drawing annotation click not work on iPad/Android device
var pnlName = event.currentTarget.id;
$rootScope.resetMenuOptionOnClick(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);
});
}
}]
);