AIA.controller("CurrBuildController", ["$scope", "$rootScope", "pages", "$log", "Modules", "$http", "$compile", "$location", "$timeout", "ModuleService", "$interval",
function ($scope, $rootScope, pages, log, Modules, $http, $compile, $location, $timeout, ModuleService, $interval) {
// $rootScope.currentActiveModuleTitle = pages[6].name;
$scope.showTabButton = false;
$scope.listCurriculumBuilder = null;
$scope.dataPopup = null;
$scope.countLeftlist;
$scope.countRightlist;
$rootScope.selectedNodeSingle = [];
$scope.selectedNodeSingleObj = [];
$scope.IsVisible = function () {
$scope.scroll();
}
$scope.scroll = function () {
// $window.scrollTo(0, 0);
$("html,body").scrollTop(0);
//alert("scroll");
}
angular.element(document).ready(function (e) {
$("#sidebar-wrapper").on('click', function (event) {
//4. on click disable menu option
$scope.$emit("cBEnableDisableMenuOption","");
});
// close all selected open panel in CB
$(document).on("click", " .jsPanel-hdr .jsPanel-hdr-r .jsPanel-btn-close .jsglyph-remove", function () {
// close in case of Curriculum Builder
var id = $(event.target).parent().parent().parent().parent().attr('id');
if (id == "CBTinyMCEPanel") {
tinymce.execCommand('mceRemoveControl', true, 'CBTextArea');
tinymce.execCommand('mceFocus', true, 'CBTextArea');
tinymce.execCommand('mceRemoveEditor', true, 'CBTextArea');
tinymce.execCommand('mceAddEditor', true, 'CBTextArea');
}
if ($('#' + id).html() != undefined) {
$('#' + id).remove();
// remove panel name from dropdown
$('#viwerSelect option[value="' + id + '"]').remove();
}
//Added code by sandeep for fixed Bug-58066
var ddlViewerLen = $("#viwerSelect option").length;
if (ddlViewerLen == 0) {
$('#viwerSelect').hide();
}
});
$scope.CBDisableUI = function () {
$rootScope.isLoading = true;
$('#spinner').css('visibility', 'visible');
$('#spinner').css('z-index', '1000000001');
// CB module disable all
$('#HomeContainerDiv').css('pointer-events', 'none');
$('#HomeContainerDiv').css('opacity', '0.7');
$timeout(function () {
// in case failed default time out 40 second
var opcity = $("#HomeContainerDiv").css("opacity")
if (opcity != 1)
{
$scope.CBEnableUI();
}
}, 40000);
}
$scope.CBEnableUI = function () {
$rootScope.isLoading = false;
$('#spinner').css('visibility', 'hidden');
// CB module enable all
$('#HomeContainerDiv').css('pointer-events', 'auto');
$('#HomeContainerDiv').css('opacity', '1');
}
});
$rootScope.firstSelectedNodeId = null;
//load json data
$scope.loadCurriculumBuiderData = function () {
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;
})
//get current path
var currentURL = $location.path();
$http({ method: 'GET', url: 'content/data/json/cb/cb_list_content.json' }).success(function (data) {
$scope.listCurriculumBuilder = data;
//load default body view list
$scope.getCBViewList();
})
.error(function (data, status, headers, config) {
console.log(data);
});
}
//get CB body view list
$scope.getCBViewList = function ($event) {
$('#leftBodyViewList').empty();
$scope.countLeftlist = Object.keys($scope.listCurriculumBuilder.slideshows.slideshow).length / 2;
$scope.loadleftBodyViewList = new jinqJs()
.from($scope.listCurriculumBuilder.slideshows.slideshow)
.select();
for (var i = 0; i < $scope.countLeftlist; i++) {
console.log($scope.listCurriculumBuilder.slideshows.slideshow[i]._label);
//alert($scope.listCurriculumBuilder.slideshows.slideshow[i]._label);
console.log($scope.listCurriculumBuilder.slideshows.slideshow[i]._filename);
var $el = $('
' + $scope.listCurriculumBuilder.slideshows.slideshow[i]._label + '').appendTo('#leftBodyViewList');
$compile($el)($scope);
}
$scope.countRightlist = Object.keys($scope.listCurriculumBuilder.slideshows.slideshow).length;
for (var i = $scope.countLeftlist; i < $scope.countRightlist; i++) {
console.log($scope.listCurriculumBuilder.slideshows.slideshow[i]._label);
var $el1 = $('' + $scope.listCurriculumBuilder.slideshows.slideshow[i]._label + '').appendTo('#rightBodyViewList');
$compile($el1)($scope);
}
}
$scope.loadSlideShowXmldata = function (e) {
$scope.CBDisableUI();
$rootScope.AutherName="";
$rootScope.summary="";
$rootScope.FileTitle=e.target.text;
$scope.fileName = e.target.id.split('.');
$('#modal-CurBuilder').css("display", "block");
$("#CurBuilderbackground").css("display", "block");
$http({ method: 'GET', url: 'content/data/json/cb/SlideShow/json/' + $scope.fileName[0] + '.json' }).success(function (data) {
localStorage.setItem("cbJsonDataObject", JSON.stringify(data));
$rootScope.cbJsonData = JSON.parse(localStorage.getItem("cbJsonDataObject"));
$rootScope.cbDynamicJsonData = data;
$rootScope.getCBsummary();
$scope.CBEnableUI();
})
.error(function (data, status, headers, config) {
console.log(data);
$scope.CBEnableUI();
});
}
$rootScope.OpenExistingCurriculum = function (file_Name) {
$("#opencbview").trigger("click");
var fileupload = document.getElementById("opencbview");
fileupload.onchange = function () {
var fileName = fileupload.value;
alert(fileName);
//switch ($location.url()) {
// case '/curriculum-builder-detail':
// $location.url('/curriculum-builder');
// break;
//}
// $scope.fileName = file_Name;
$('#modal-CurBuilder').css("display", "block");
$("#CurBuilderbackground").css("display", "block");
$http({ method: 'GET', url: fileName }).success(function (data) {
localStorage.setItem("cbJsonDataObject", JSON.stringify(data));
$rootScope.cbJsonData = JSON.parse(localStorage.getItem("cbJsonDataObject"));
$rootScope.cbDynamicJsonData = data;
$rootScope.getCBsummary();
$scope.openCurriculumDetail();
})
.error(function (data, status, headers, config) {
console.log(data);
});
};
}
$rootScope.exportToFile = function () {
$rootScope.selectedNodeSingle.push(
{
"slideshow": {
"presentation": {
"structure": {
"structure": [
{
"_label": "Untitled Slide",
"_id": "-1507902782",
"_isRoot": "false",
"_isBranch": "false",
"_isLocked": "false"
}
],
"_label": "Untitled Curriculum",
"_id": "-225638207",
"_isRoot": "true",
"_isBranch": "true",
"_isLocked": "false"
},
"_anchor": "true",
"_window_position": "6,10",
"_window_size": "828,453"
},
"content": {
"element": [
{
"notes": "
",
"windows": {
"window": "{\"windowTitle\":\"Hand (Post/Ant)\",\"selectedCallouts\":[],\"annotationData\":\"\",\"minimised\":false,\"scrollPosition\":{\"vertical\":78,\"horizontal\":120},\"selectedStructureID\":7446,\"maximised\":false,\"size\":{\"width\":800,\"height\":753},\"id\":\"424\",\"showSelectedPins\":true,\"scaleIndex\":0,\"bodySystemId\":11,\"windowListId\":\"0\",\"imageId\":\"424\",\"position\":{\"x\":840,\"y\":10},\"mType\":\"ATLAS_ANATOMY\",\"hideCallOuts\":true,\"containsCapturedContent\":true,\"selectedPins\":[\"32783\"],\"contextMenu\":{\"hideLeftBar\":false,\"hideTitleBar\":false,\"hideTopToolBar\":false,\"lockResize\":false}}"
},
"_id": "-1507902782"
}
]
}
}
});
$scope.filename = "filename.json";
var filename = $scope.filename;
var blob = new Blob([angular.toJson($rootScope.selectedNodeSingle, true)], { type: 'text/text' });
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob, filename);
} else {
var e = document.createEvent('MouseEvents'),
a = document.createElement('a');
a.download = filename;
a.href = window.URL.createObjectURL(blob);
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':');
e.initEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
a.dispatchEvent(e);
// window.URL.revokeObjectURL(url); // clean the url.createObjectURL resource
}
$http({ method: 'Post', url: $scope.fileName }).success(function (data) {
localStorage.setItem("cbJsonDataObject", JSON.stringify(data));
$rootScope.cbJsonData = JSON.parse(localStorage.getItem("cbJsonDataObject"));
$rootScope.cbDynamicJsonData = data;
//$scope.getCBsummary();
$rootScope.cbJsonData.slideshow.content.element = "Eement data";
$rootScope.cbDynamicJsonData.slideshow.content.element = "slideshow element data";
$rootScope.note = "save data"
//$scope.openCurriculumDetail();
})
.error(function (data, status, headers, config) {
console.log(data);
});
};
//$rootScope.saveCurricullam = function (file_Name) {
// $scope.selectedNodeSingleObj.push(
// {
// "slideshow": {
// "presentation": {
// "structure": {
// "structure": [
// {
// "_label": "Untitled Slide",
// "_id": "-1507902782",
// "_isRoot": "false",
// "_isBranch": "false",
// "_isLocked": "false"
// }
// ],
// "_label": "Untitled Curriculum",
// "_id": "-225638207",
// "_isRoot": "true",
// "_isBranch": "true",
// "_isLocked": "false"
// },
// "_anchor": "true",
// "_window_position": "6,10",
// "_window_size": "828,453"
// },
// "content": {
// "element": [
// {
// "notes": "
",
// "windows": {
// "window": "{\"windowTitle\":\"Hand (Post/Ant)\",\"selectedCallouts\":[],\"annotationData\":\"\",\"minimised\":false,\"scrollPosition\":{\"vertical\":78,\"horizontal\":120},\"selectedStructureID\":7446,\"maximised\":false,\"size\":{\"width\":800,\"height\":753},\"id\":\"424\",\"showSelectedPins\":true,\"scaleIndex\":0,\"bodySystemId\":11,\"windowListId\":\"0\",\"imageId\":\"424\",\"position\":{\"x\":840,\"y\":10},\"mType\":\"ATLAS_ANATOMY\",\"hideCallOuts\":true,\"containsCapturedContent\":true,\"selectedPins\":[\"32783\"],\"contextMenu\":{\"hideLeftBar\":false,\"hideTitleBar\":false,\"hideTopToolBar\":false,\"lockResize\":false}}"
// },
// "_id": "-1507902782"
// }
// ]
// }
// }
// });
// console.log($scope.selectedNodeSingle);
// $scope.exportToFile();
// $http({ method: 'Post', url: 'content/data/json/cb/SlideShow/json/' + $scope.fileName + '.json' }).success(function (data) {
// localStorage.setItem("cbJsonDataObject", JSON.stringify(data));
// $rootScope.cbJsonData = JSON.parse(localStorage.getItem("cbJsonDataObject"));
// $rootScope.cbDynamicJsonData = data;
// //$scope.getCBsummary();
// $rootScope.cbJsonData.slideshow.content.element="Eement data";
// $rootScope.cbDynamicJsonData.slideshow.content.element="slideshow element data";
// $rootScope.note = "save data"
// //$scope.openCurriculumDetail();
// })
// .error(function (data, status, headers, config) {
// console.log(data);
// });
//}
//$rootScope.NewCurricullumData = function (file_Name) {
// //$rootScope.fileNames = e.target.id;
// alert('test');
// switch ($location.url()) {
// case '/curriculum-builder-detail':
// $location.url('/curriculum-builder');
// break;
// }
// $scope.fileName = file_Name;
// $('#modal-CurBuilder').css("display", "block");
// $("#CurBuilderbackground").css("display", "block");
// $http({ method: 'GET', url: 'content/data/json/cb/SlideShow/json/' + $scope.fileName + '.json' }).success(function (data) {
// localStorage.setItem("cbJsonDataObject", JSON.stringify(data));
// $rootScope.cbJsonData = JSON.parse(localStorage.getItem("cbJsonDataObject"));
// $rootScope.cbDynamicJsonData = data;
// //$scope.getCBsummary();
// //$rootScope.note = $rootScope.cbJsonData.slideshow.content.element;
// //$rootScope.Auther = $rootScope.cbDynamicJsonData.slideshow.content.element;
// $rootScope.note = $rootScope.cbJsonData.slideshow.content.element;
// $scope.openCurriculumDetail();
// })
// .error(function (data, status, headers, config) {
// console.log(data);
// });
//}
$scope.openImagePanel = function () {
var jsImageURL = 'app/views/CBuild/curriculum-builder-image.html';
$.jsPanel({
id: 'CBSourceImagePanel',
selector: '.CBBodyView',
theme: 'success',
currentController: 'CurrBuildController',
parentSlug: 'curriculum-builder-detail',
ajax: {
url: jsImageURL
},
title: $rootScope.windowstitle,
position: {
top: 600,
left: 10,
},
controls: { buttons: 'closeonly' },
size: { width: 850, height: 503 },
});
setTimeout(function () {
$scope.ImagePanelclick();
var imfgEle = document.getElementById("imgtag");
if (imfgEle!=null)
imfgEle.src = "data:image/png;base64," + $rootScope.windowsimageSource;
setTimeout(function () {
var cleintht=imfgEle.clientHeight;
if(cleintht>0)
$('#CBSourceImagePanel .jsPanel-content').css('height', cleintht);
$scope.CBEnableUI();
}, 200)
}, 200)
}
$scope.ImagePanelclick = function () {
$("#CBSourceImagePanel").on('click', function (event) {
var pnlName=event.currentTarget.id;
$scope.$emit("cBEnableDisableMenuOption",pnlName);
});
}
$rootScope.getCBsummary = function () {
$rootScope.summary = $rootScope.cbJsonData.slideshow.content.element[0].summary;
$rootScope.AutherName = $rootScope.cbJsonData.slideshow.content.element[0].author;
$rootScope.note = $rootScope.cbJsonData.slideshow.content.element;
$rootScope.Auther = $rootScope.cbDynamicJsonData.slideshow.content.element;
}
$scope.closeCurBulderModal = function () {
$('#modal-CurBuilder').css("display", "none");
$("#CurBuilderbackground").css("display", "none");
}
$scope.openCurriculumDetail = function () {
$rootScope.structure = $rootScope.cbJsonData.slideshow.presentation.structure.structure;
$rootScope.stru = $rootScope.cbDynamicJsonData.slideshow.presentation;
$rootScope.cbTreeFirstLabel = $rootScope.cbJsonData.slideshow.presentation.structure._label;
$rootScope.cbTreeFirstID = $rootScope.cbJsonData.slideshow.presentation.structure._id;
$location.url("/curriculum-builder-detail");
}
$rootScope.newCurriculumDetail = function () {
$rootScope.selectedNodeSingle.push(
{
"structure": {
"structure": [
{
"_label": "Untitled Slide",
"_id": "51516C76",
"_isRoot": "false",
"_isBranch": "false",
"_isLocked": "false"
}
],
},
"_label": "Untitled Curriculum",
"_id": "111112",
"_isRoot": "true",
"_isBranch": "true",
"_isLocked": "false"
});
$rootScope.stru = $scope.selectedNodeSingle[0];
//$scope.nodeid = $scope.selectedNodeSingle[0].structure.structure[0]._label;
//traverseTreeSelectedSingleObj($rootScope.stru, $scope.nodeid);
//$scope.structure = $scope.selectedNodeSingle[0].structure.structure[0]._label;
$rootScope.cbTreeFirstLabel = $scope.selectedNodeSingle[0]._label;
$rootScope.structure = $scope.selectedNodeSingle[0].structure.structure;
$rootScope.cbTreeFirstID = $scope.selectedNodeSingle[0]._id;
$location.url("/curriculum-builder-detail");
}
$scope.openCBJsPanel = function () {
$scope.CBDisableUI();
var jsContentURL = 'app/views/CBuild/curriculum-builder-TinyMCEjspanel.html';
var jsImageContentURL = 'app/views/CBuild/curriculum-builder-image-jspanel.html';
$.jsPanel({
id: 'CBTinyMCEPanel',
selector: '.CBBodyView',
theme: 'success',
currentController: 'CurrBuildController',
parentSlug: 'curriculum-builder',
ajax: {
url: jsContentURL
},
title: $rootScope.cbTreeFirstLabel,
position: {
top: 20,
left: 20,
},
controls: { buttons: 'closeonly' },
size: { width: 850, height: 512 },
});
$timeout(function () {
$scope.TinyMCEPanelclick();
},1000);
if ($rootScope.isOpenResourceBtnClicked == true) {
switch ($rootScope.MenuModuleName) {
case 'DA':
$e = $('#resourceModuleDiv').append("");
$compile($e)($scope);
break;
}
//$compile($e)($scope);
}
}
$scope.TinyMCEPanelclick = function () {
$("#CBTinyMCEPanel").on('click', function (event) {
//3. on click disable menu option
$scope.$emit("cBEnableDisableMenuOption","");
});
}
$scope.myeditorclick=function() {
//1. disable menu options
$scope.$emit("cBEnableDisableMenuOption","");
}
function traverseTreeForSetIcons(o, current_id) {
for (var i in o) {
if (o[i] !== null && typeof (o[i]) == "object") {
if (o[i]._isBranch == "false") {
$("#jstree").jstree(true).set_icon(o[i]._id, "../../../content/images/CB/file.png");
//$("#AddSlide").addClass("cbAddSection");
//$("#AddSection").addClass("cbAddSection");
}
if (o[i]._isBranch == "true") {
//$("#AddSlide").removeClass("cbAddSection");
// $("#AddSection").removeClass("cbAddSection");
}
traverseTreeForSetIcons(o[i], current_id);
}
}
}
function getLoadNodeId(o) {
for (var i in o) {
if (o[i] !== null && typeof (o[i]) == "object") {
if (o[i]._isBranch == "false") {
$rootScope.firstSelectedNodeId = o[i]._id;
}
getLoadNodeId(o[i]);
}
}
}
$scope.loadNotesById = function () {
traverseForLoadDropDown($rootScope.stru);
setTimeout(function () {
var nodeid = document.getElementById('cbSelect').value;
$('#jstree').jstree('select_node', nodeid);
traverseTreeForSetIcons($rootScope.stru, nodeid);
}, 200);
}
$scope.openTinyMCE = function (nodeid) {
$scope.CBDisableUI();
if ($scope.Currentselectednodeid == undefined || $scope.Currentselectednodeid != nodeid) {
console.log("instance create for id : " + nodeid);
$scope.Currentselectednodeid = nodeid;
traverseTreeSelectedSingleObj($rootScope.stru, nodeid);
if ($scope.selectedNodeSingleObj._isBranch == "false") {
$("#Deletesection").addClass("DeletesectionClass");
$("#DeleteSlide").removeClass("DeleteslideClass");
$("#AddSlide").addClass("cbAddSection");
$("#AddSection").addClass("cbAddSection");
}
if ($scope.selectedNodeSingleObj._isBranch == "true") {
$("#Deletesection").removeClass("DeletesectionClass");
$("#DeleteSlide").addClass("DeleteslideClass");
$("#AddSlide").removeClass("cbAddSection");
$("#AddSection").removeClass("cbAddSection");
}
$scope.DropDownSelectNodeClick(nodeid);
$scope.SelectedNotes = "";
traverseTreeSelectedSingleObj($rootScope.note, nodeid);
$scope.SelectedNotes = $scope.selectedNodeSingleObj.notes;
// clear module data
ModuleService.ClearWinData();
$('#CBSourceImagePanel').remove();
$("#viwerSelect").empty();
$("#viwerSelect").hide();
if ($('#parentcustomDiv').html() != "") {
$('#parentcustomDiv').empty();
}
if ($scope.SelectedNotes != "" && $scope.SelectedNotes != undefined) {
tinymce.get("CBTextArea").setContent($scope.SelectedNotes);
setTimeout(function () {
if ($scope.selectedNodeSingleObj.windows != "") {
$scope.loadContentOfSelectedSlide($scope.selectedNodeSingleObj._id)
}
else
{
$scope.CBEnableUI();
}
},200);
}
else
{
tinymce.get("CBTextArea").setContent("");
$scope.CBEnableUI();
}
}
else
{
$scope.CBEnableUI();
}
}
$rootScope.cbSelectOnChange = function (obj) {
$('#jstree').jstree(true).deselect_all();
$('#jstree').jstree('select_node', obj.value);
}
//Start Code by Sandeep for TicketNo: 49226(3)
$scope.DropDownSelectNodeClick = function (nodeid) {
//var current_id = document.getElementById('cbSelect').value;
traverseTreeSelectedSingleObj($rootScope.stru, nodeid);
traverse($rootScope.stru, nodeid);
$('#cbEditorRightSideBar').css('pointer-events', 'auto');
$('#cbEditorRightSideBar').css('opacity', '1');
if ($scope.selectedNodeSingleObj._isBranch == "true") {
$("#cbSelect").empty();
$('#cbEditorRightSideBar').css('pointer-events', 'none');
$('#cbEditorRightSideBar').css('opacity', '0.7');
localStorage.setItem("cbSelectId", nodeid);
if ($scope.selectedNodeSingleObj._id == nodeid) {
$scope.currentSlideNumber += 1;
$('#cbSelect').append('');
}
else {
$('#cbSelect').append('');
}
if ($scope.selectedNodeSingleObj._isRoot == "true") {
document.getElementById("slideNumber").innerHTML = "Slide " + 1 + " of " + 1;
}
else if ($scope.selectedNodeSingleObj._isBranch == "true") {
document.getElementById("slideNumber").innerHTML = "Slide " + $scope.currentSlideNumber + " of " + Object.keys($scope.selectedNodeSingleObj).length;
}
else
{
document.getElementById("slideNumber").innerHTML = "Slide " + $scope.currentSlideNumber + " of " + Object.keys($scope.selectedNodeSingleObj).length;
}
}
else {
traverse($rootScope.stru, nodeid);
$("#cbSelect").empty();
for (i = 0; i < $scope.selectedNodeSiblingObjs.length; i++) {
localStorage.setItem("cbSelectId", nodeid);
if ($scope.selectedNodeSiblingObjs[i]._id == nodeid) {
$scope.currentSlideNumber = i + 1;
$('#cbSelect').append('');
}
else {
$('#cbSelect').append('');
}
}
document.getElementById("slideNumber").innerHTML = "Slide " + $scope.currentSlideNumber + " of " + Object.keys($scope.selectedNodeSiblingObjs).length;
}
}
$rootScope.cbNext = function () {
var cbCurrentId = document.getElementById('cbSelect').value;
var counter = 0;
$("#jstree").jstree("open_all");
$('.jstree-container-ul li a span').each(function () {
var span_Id = $(this).attr("id");
if (span_Id == cbCurrentId) {
counter++;
}
if (counter == 2) {
$scope.nextCurrentId = span_Id;
if ($scope.nextCurrentId != undefined) {
$('#jstree').jstree(true).deselect_all();
$('#jstree').jstree('select_node', $scope.nextCurrentId);
}
return false;
}
if (counter == 1) {
counter += 1;
}
});
}
$rootScope.cbBack = function () {
var cbCurrentId = document.getElementById('cbSelect').value;
var counter = 0;
$("#jstree").jstree("open_all");
$($(".jstree-container-ul li a span").get().reverse()).each(function () {
var span_Id = $(this).attr("id");
if (span_Id == cbCurrentId) {
counter++;
}
if (counter == 2) {
$scope.backCurrentId = span_Id;
if ($scope.backCurrentId != undefined) {
$('#jstree').jstree(true).deselect_all();
$('#jstree').jstree('select_node', $scope.backCurrentId);
}
return false;
}
if (counter == 1) {
counter += 1;
}
});
}
//End Code by Sandeep for TicketNo: 49226(3)
function traverse(o, current_id) {
for (var i in o) {
if (o[i] !== null && typeof (o[i]) == "object") {
if (o[i]._id == current_id) {
$scope.selectedNodeSiblingObjs = o;
}
traverse(o[i], current_id);
}
}
}
$rootScope.cbRenameModelShow = function () {
var current_id = document.getElementById('cbSelect').value;
document.getElementById('renameInputBoxId').value = "";
traverseTreeSelectedSingleObj($rootScope.stru, current_id);
if ($scope.selectedNodeSingleObj._isBranch == "true") {
traverseTreeSelectedSingleObj($rootScope.Auther, current_id);
document.getElementById('cbRenameDate').value = $scope.selectedNodeSingleObj.modified;
document.getElementById('cbModelRenameBackground').style.display = "block";
document.getElementById('cbModelSectionRenameId').style.display = "block";
}
else {
document.getElementById('cbModelRenameBackground').style.display = "block";
document.getElementById('cbModelRenameId').style.display = "block";
}
}
$rootScope.cbPasswordModelShow = function () {
//var current_id = document.getElementById('cbSelect').value;
//traverseTreeSelectedSingleObj($rootScope.stru, current_id);
//if ($scope.selectedNodeSingleObj._isBranch == "true") {
//traverseTreeSelectedSingleObj($rootScope.Auther, current_id);
//document.getElementById('cbRenameDate').value = $scope.selectedNodeSingleObj.modified;
document.getElementById('cbModelRenameBackground').style.display = "block";
document.getElementById('cbModelUserPassWord').style.display = "block";
//}
//else {
//document.getElementById('cbModelRenameBackground').style.display = "block";
//document.getElementById('cbModelRenameId').style.display = "block";
// }
}
$rootScope.cbRenameSlide = function () {
var current_id
if (($rootScope.getLocalStorageValue("cbSelectId")) != '') {
current_id = $rootScope.getLocalStorageValue("cbSelectId");
}
else {
current_id = document.getElementById('cbSelect').value;
}
//var current_id = document.getElementById('cbSelect').value;
var newSlideText = document.getElementById('renameInputBoxId').value;
var newSlideName = ("" + newSlideText + "");
$("#jstree").jstree('set_text', current_id, newSlideName);
traverseTreeSelectedSingleObj($rootScope.stru, current_id);
$scope.selectedNodeSingleObj._label = newSlideText;
$scope.DropDownSelectNodeClick(current_id);
console.log(JSON.stringify($rootScope.stru));
$rootScope.closeRenameModel();
}
$rootScope.closeRenameModel = function () {
document.getElementById('cbModelRenameBackground').style.display = "none";
if (document.getElementById("cbModelRenameId").style.display == 'block') {
document.getElementById('cbModelRenameId').style.display = "none";
}
if (document.getElementById("cbModelUserPassWord").style.display == 'block') {
document.getElementById('cbModelUserPassWord').style.display = "none";
}
if (document.getElementById("cbModelSectionRenameId").style.display == 'block') {
document.getElementById('cbModelSectionRenameId').style.display = "none";
}
}
$rootScope.cbRenameSection = function () {
var nodeid
if (($rootScope.getLocalStorageValue("cbSelectId")) != '') {
nodeid = $rootScope.getLocalStorageValue("cbSelectId");
}
else {
nodeid = document.getElementById('cbSelect').value;
}
//var nodeid = document.getElementById('cbSelect').value;
$scope.cbRenameDate();
//var newSlideName = document.getElementById('cbRenameSectionTitle').value;
var newAuthorName = document.getElementById('cbRenameAuthor').value;
var newSummary = document.getElementById('cbRenameSummary').value;
var newversion = document.getElementById('cbRenameVersionNo').value;
var newSectionText = document.getElementById('cbRenameSectionTitle').value;
var newSlideName = ("" + newSectionText + "");
$("#jstree").jstree('set_text', nodeid, newSlideName);
traverseTreeSelectedSingleObj($rootScope.stru, nodeid);
$scope.selectedNodeSingleObj._label = newSectionText;
$scope.selectedNodeSingleObj = "";
traverseTreeSelectedSingleObj($rootScope.Auther, nodeid);
setTimeout(function () {
$scope.selectedNodeSingleObj.summary = newSummary;
$scope.selectedNodeSingleObj.author = newAuthorName;
$scope.selectedNodeSingleObj.version = newversion;
$scope.selectedNodeSingleObj.modified = $scope.dateTime;
$scope.DropDownSelectNodeClick(nodeid);
console.log("summary" + JSON.stringify($rootScope.cbDynamicJsonData));
}, 100);
$rootScope.closeRenameModel();
}
$scope.cbRenameDate = function () {
var currentdate = new Date();
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1;
var day = now.getDate();
var hours = now.getHours();
var minute = now.getMinutes();
var ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
if (month.toString().length == 1) {
month = '0' + month;
}
if (day.toString().length == 1) {
day = '0' + day;
}
if (hours.toString().length == 1) {
hours = '0' + hours;
}
if (minute.toString().length == 1) {
minute = '0' + minute;
}
$scope.dateTime = month + '/' + day + '/' + year + ',' + hours + ':' + minute + ' ' + ampm;
}
$rootScope.showDeleteSlideModel = function () {
document.getElementById('cbModelDeleteBackground').style.display = "block";
document.getElementById('cbModelDeleteConfirmBoxId').style.display = "block";
}
$rootScope.DeleteSlideSection = function () {
var cbCurrentSelectedId = document.getElementById('cbSelect').value;
var CurrentSelectedLiId = $('#' + cbCurrentSelectedId).closest('li').attr('id');
var CurrentSelectedParentSpanId = $('#' + cbCurrentSelectedId).parent().parent().parent().parent().find('span').attr('id');
var parentNodeObj = $('#' + cbCurrentSelectedId).parent().parent().parent();
var indexOfCurrentSelectedId = $(parentNodeObj).children('li').index($("#" + CurrentSelectedLiId));
$('#jstree').jstree().delete_node([$("#jstree").jstree().get_selected(true)[0].id]);
var lengthOfCurrentSelectedSlideSiblings = $(parentNodeObj).children('li').length;
if (indexOfCurrentSelectedId <= 0) {
if (lengthOfCurrentSelectedSlideSiblings > 1) {
$rootScope.cbNext();
}
else {
$('#jstree').jstree(true).deselect_all();
$('#jstree').jstree('select_node', CurrentSelectedParentSpanId);
}
}
else {
$rootScope.cbBack();
}
$scope.DeleteSlide(cbCurrentSelectedId);
var CurrentId = document.getElementById('cbSelect').value;
$scope.DropDownSelectNodeClick(CurrentId);
$rootScope.closeDeleteModel();
}
$rootScope.closeDeleteModel = function () {
document.getElementById('cbModelDeleteBackground').style.display = "none";
document.getElementById('cbModelDeleteConfirmBoxId').style.display = "none";
}
$rootScope.CBAddSlide = function () {
var current_id
if (($rootScope.getLocalStorageValue("cbSelectId")) != '') {
current_id = $rootScope.getLocalStorageValue("cbSelectId");
}
else {
current_id = document.getElementById('cbSelect').value;
}
traverseTreeSelectedSingleObj($rootScope.stru, current_id);
var parentid = $('#' + current_id).parent().parent().parent().parent().find('span').attr('id');
var createNodeId;
if ($scope.selectedNodeSingleObj._isBranch == "true") {
createNodeId = current_id;
}
else {
createNodeId = parentid;
//open other modules
// $scope.loadContentOfSelectedSlide(current_id);
}
var AddSlideId = "";
var AddSlideLiId = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 5; i++) {
AddSlideId += possible.charAt(Math.floor(Math.random() * possible.length));
AddSlideLiId += possible.charAt(Math.floor(Math.random() * (possible.length) + 1));
}
// var AddSlideId = 'abcd';
//var AddSlideId = Math.random().toString();
$('#jstree').jstree().create_node(createNodeId, {
li_attr: { "name": "isBranchFalse" },
"id": AddSlideLiId,
"text": 'New Slide'
}, "last", function () {
// //$scope.addCBSlide(current_id, AddSlideId);
$scope.addSlide(createNodeId, AddSlideId);
// $scope.DropDownSelectNodeClick(current_id);
$('#jstree').jstree(true).deselect_all();
$('#jstree').jstree('select_node', AddSlideLiId);
//$('#jstree').jstree('select_node', AddSlideId);
//$scope.openTinyMCE(AddSlideId);
});
}
$rootScope.CBAddSection = function () {
var current_id
if (($rootScope.getLocalStorageValue("cbSelectId")) != '') {
current_id = $rootScope.getLocalStorageValue("cbSelectId");
}
else {
current_id = document.getElementById('cbSelect').value;
}
traverseTreeSelectedSingleObj($rootScope.stru, current_id);
var parentid = $('#' + current_id).parent().parent().parent().parent().find('span').attr('id');
var createNodeId;
if ($scope.selectedNodeSingleObj._isBranch == "true") {
createNodeId = current_id;
}
else {
createNodeId = parentid;
}
var AddSectionId = "";
var AddSectionLiId = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 5; i++) {
AddSectionId += possible.charAt(Math.floor(Math.random() * possible.length));
AddSectionLiId += possible.charAt(Math.floor(Math.random() * (possible.length) + 1));
}
// var AddSlideId = 'abcd';
//var AddSlideId = Math.random().toString();
$('#jstree').jstree().create_node(createNodeId, {
li_attr: { "name": "isBranchFalse" },
"id": AddSectionLiId,
"text": 'New Section'
}, "last", function () {
//$scope.addCBSlide(current_id, AddSlideId);
$scope.addSection(createNodeId, AddSectionId);
// $scope.DropDownSelectNodeClick(current_id);
$('#jstree').jstree(true).deselect_all();
//$('#jstree').jstree('select_node', AddSectionId);
$('#jstree').jstree('select_node', AddSectionLiId);
});
}
function traverseForLoadDropDown(o) {
for (i = 0; i < o.structure.structure.length; i++) {
$('#cbSelect').append('');
}
}
$scope.moveUP = function (currentid) {
traverse($rootScope.stru, currentid);
console.log("cbJsonData Before" + JSON.stringify($rootScope.stru));
console.log("upDateJsonObj Before" + JSON.stringify($scope.selectedNodeSiblingObjs));
for (var j = 0; j < $scope.selectedNodeSiblingObjs.length; j++) {
if (($scope.selectedNodeSiblingObjs[j]._id == currentid) && ($scope.selectedNodeSiblingObjs[j - 1] != undefined)) {
var key = $scope.selectedNodeSiblingObjs[j];
$scope.selectedNodeSiblingObjs[j] = $scope.selectedNodeSiblingObjs[j - 1];
$scope.selectedNodeSiblingObjs[j - 1] = key;
}
}
console.log("upDateJsonObjenew after" + JSON.stringify($scope.selectedNodeSiblingObjs));
console.log("stru after" + JSON.stringify($rootScope.stru));
console.log("structure after" + JSON.stringify($rootScope.structure));
}
$scope.DeleteSlide = function (currentid) {
traverse($rootScope.stru, currentid);
for (var j = 0; j < $scope.selectedNodeSiblingObjs.length; j++) {
if (($scope.selectedNodeSiblingObjs[j]._id == currentid)) {
$scope.selectedNodeSiblingObjs.splice(j, 1);
}
}
// prune($rootScope.stru, currentid);
// alert("After" + JSON.stringify($rootScope.stru));
}
$scope.addSection = function (currentid, AddSecionId) {
traverseTreeSelectedSingleObj($rootScope.stru, currentid);
traverse($rootScope.stru, currentid);
if (currentid == "-225638207") {
$rootScope.selectedNodeSingle.push(
{
"structure": {
"structure": [
//{
// "_label": "NEW ",
// "_id": AddSlideId,
// "_isRoot": "false",
// "_isBranch": "false",
// "_isLocked": "false"
//}
],
"_label": "New Section",
"_id": AddSecionId,
"_isRoot": "false",
"_isBranch": "true",
"_isLocked": "false"
}
});
}
else {
$scope.selectedNodeSingleObj['structure'].push(
{
"structure": [
//{
// "_label": "M",
// "_id": "51516C76-78F4-0D67-6B43-394B4168CF7C",
// "_isRoot": "false",
// "_isBranch": "false",
// "_isLocked": "false"
//}
],
"_label": "New Section",
"_id": AddSecionId,
"_isRoot": "false",
"_isBranch": "true",
"_isLocked": "false"
});
}
// setTimeout(function () { traverseTreeForSetIcons($rootScope.stru, currentid); }, 1500);
}
$scope.addSlide = function (currentid, AddSlideId) {
traverseTreeSelectedSingleObj($rootScope.stru, currentid);
// traverse($rootScope.stru, currentid);
//console.log(JSON.stringify($scope.upDateJsonObj))
if (currentid == "-225638207") {
$rootScope.selectedNodeSingle.push(
{
"_label": "NEW Slide1",
"_id": AddSlideId,
"_isRoot": "false",
"_isBranch": "false",
"_isLocked": "false"
});
}
else {
$scope.selectedNodeSingleObj['structure'].push({
"_label": "New Slide",
"_id": AddSlideId,
"_isRoot": "false",
"_isBranch": "false",
"_isLocked": "false"
});
}
// setTimeout(function () { traverseTreeForSetIcons($rootScope.stru, currentid); }, 3000);
setTimeout(function () { $("#jstree").jstree(true).set_icon(AddSlideId, "../../../content/images/CB/file.png"); }, 100);
}
$scope.moveDown = function (currentid) {
traverse($rootScope.stru, currentid);
for (var j = 0; j < $scope.selectedNodeSiblingObjs.length; j++) {
if (($scope.selectedNodeSiblingObjs[j]._id == currentid) && ($scope.selectedNodeSiblingObjs[j + 1] != undefined)) {
var key1 = $scope.selectedNodeSiblingObjs[j];
$scope.selectedNodeSiblingObjs[j] = $scope.selectedNodeSiblingObjs[j + 1];
$scope.selectedNodeSiblingObjs[j + 1] = key1;
break;
}
}
}
function traverseTreeSelectedSingleObj(o, current_id) {
for (var i in o) {
if (o[i] !== null && typeof (o[i]) == "object") {
if (o[i]._id == current_id) {
$scope.selectedNodeSingleObj = o[i];
}
traverseTreeSelectedSingleObj(o[i], current_id);
}
}
}
$(function () {
$("#modal-CurBuilder").draggable();
});
$scope.loadContentOfSelectedSlide = function (id) {
// alert("Id" + id);
console.log("id= " + id)
var content = $rootScope.cbJsonData.slideshow.content.element;
var contenctForSelectedSlide = new jinqJs()
.from(content)
.where("_id == " + id)
.select();
// console.log('contenctForSelectedSlide' + contenctForSelectedSlide[0].notes)
var windowsInSelectedSlide = contenctForSelectedSlide[0].windows;
var allwindowData = windowsInSelectedSlide.window;
var windowData;
var imageSourc;
var DawindowId = 0;
var AtlasWindowId = 0;
var CIWindowId = 0;
var CAWindowId = 0;
var ThreeDWindowId = 0;
$scope.LoadModuleName = [];
$scope.Slidenumber = id;
//check for multiple windows, if Array.isArray==true
if (allwindowData != undefined && Array.isArray(allwindowData)) {
for (var i = 0; i < allwindowData.length; i++) {
if (allwindowData[i].indexOf('imageSource') != -1) {
// var subS = allwindowData[i].substring(allwindowData.indexOf('imageSource'), allwindowData[i].length - 1);
// var subS1 = allwindowData[i].split('imageSource');
// windowData = JSON.parse(subS1[0]);
// imageSourc = subS1[1];
windowData = JSON.parse(allwindowData[i])
if (windowData.mType == "MY_PICTURES") {
$rootScope.windowsimageSource = windowData.imageSource;
$rootScope.windowstitle = windowData.windowTitle;
$scope.openImagePanel();
}
}
else {
windowData = JSON.parse(allwindowData[i])
// **** Use this code when all module complted
// var isFound = jQuery.inArray(windowData.mType, $scope.LoadModuleName)
// if (isFound == -1) {
// $scope.LoadModuleName.push(windowData.mType);
// }
if (windowData.mType == "DISSECTIBLE_ANATOMY") {
ModuleService.setModuleData(windowData, DawindowId, $scope.Slidenumber);
DawindowId = DawindowId + 1;
var isFound = jQuery.inArray(windowData.mType, $scope.LoadModuleName)
if (isFound == -1) {
$scope.LoadModuleName.push(windowData.mType);
}
}
else if (windowData.mType == "ATLAS_ANATOMY") {
ModuleService.setModuleData(windowData, AtlasWindowId, $scope.Slidenumber);
AtlasWindowId = AtlasWindowId + 1;
var isFound = jQuery.inArray(windowData.mType, $scope.LoadModuleName)
if (isFound == -1) {
$scope.LoadModuleName.push(windowData.mType);
}
}
else if (windowData.mType == "CLINICAL_ILLUSTRATIONS") {
ModuleService.setModuleData(windowData, CIWindowId, $scope.Slidenumber);
CIWindowId = CIWindowId + 1;
var isFound = jQuery.inArray(windowData.mType, $scope.LoadModuleName)
if (isFound == -1) {
$scope.LoadModuleName.push(windowData.mType);
}
}
else if (windowData.mType == "CLINICAL_ANIMATIONS") {
ModuleService.setModuleData(windowData, CAWindowId, $scope.Slidenumber);
CAWindowId = CAWindowId + 1;
var isFound = jQuery.inArray(windowData.mType, $scope.LoadModuleName)
if (isFound == -1) {
$scope.LoadModuleName.push(windowData.mType);
}
}
else if (windowData.mType == "THREE_D_ANATOMY") {
ModuleService.setModuleData(windowData, ThreeDWindowId, $scope.Slidenumber);
ThreeDWindowId = ThreeDWindowId + 1;
var isFound = jQuery.inArray(windowData.mType, $scope.LoadModuleName)
if (isFound == -1) {
$scope.LoadModuleName.push(windowData.mType);
}
}
}
}
}
else {
// single window
windowData = JSON.parse(allwindowData);
if (windowData.mType == "MY_PICTURES") {
$rootScope.windowsimageSource = windowData.imageSource;
$rootScope.windowstitle = windowData.windowTitle;
$scope.openImagePanel();
}
else if (windowData.mType == "DISSECTIBLE_ANATOMY") {
var isFound = jQuery.inArray(windowData.mType, $scope.LoadModuleName)
if (isFound == -1) {
$scope.LoadModuleName.push(windowData.mType);
}
ModuleService.setModuleData(windowData, DawindowId, $scope.Slidenumber);
}
else if (windowData.mType == "ATLAS_ANATOMY") {
var isFound = jQuery.inArray(windowData.mType, $scope.LoadModuleName)
if (isFound == -1) {
$scope.LoadModuleName.push(windowData.mType);
}
ModuleService.setModuleData(windowData, AtlasWindowId, $scope.Slidenumber);
}
else if (windowData.mType == "CLINICAL_ILLUSTRATIONS") {
var isFound = jQuery.inArray(windowData.mType, $scope.LoadModuleName)
if (isFound == -1) {
$scope.LoadModuleName.push(windowData.mType);
}
ModuleService.setModuleData(windowData, CIWindowId, $scope.Slidenumber);
}
else if (windowData.mType == "CLINICAL_ANIMATIONS") {
var isFound = jQuery.inArray(windowData.mType, $scope.LoadModuleName)
if (isFound == -1) {
$scope.LoadModuleName.push(windowData.mType);
}
ModuleService.setModuleData(windowData, CAWindowId, $scope.Slidenumber);
}
else if (windowData.mType == "THREE_D_ANATOMY") {
var isFound = jQuery.inArray(windowData.mType, $scope.LoadModuleName)
if (isFound == -1) {
$scope.LoadModuleName.push(windowData.mType);
}
ModuleService.setModuleData(windowData, ThreeDWindowId, $scope.Slidenumber);
}
}
// intially call module at index 0
$scope.$emit("LoadModuleComplete", "", $scope.Slidenumber);
}
$scope.$on("LoadModuleComplete", function (evt, name, slideno) {
if ($scope.LoadModuleName != undefined) {
if (slideno == $scope.Slidenumber) {
var index = $scope.LoadModuleName.indexOf(name);
if (index != -1) {
// remove module which one is loaded
$scope.LoadModuleName.splice(index, 1);
}
if ($scope.LoadModuleName.length > 0) {
var nextmodulename = $scope.LoadModuleName[0];
$scope.loadModuleWithCB(nextmodulename);
}
else { //Added Code by sandeep for user story-52696
var modulePanel = $("#HomeContainerDiv").find("div[id*='ImagePanel']");
if (modulePanel != undefined && modulePanel != null) {
// $('#viwerSelect').append('');
//Added code by sandeep for fixed Bug-58066
if (modulePanel.length > 0) {
$('#viwerSelect').show();
}
}
else {
$('#viwerSelect').hide();
}
for (var i = 0 ; i < modulePanel.length; i++) {
var paneld = modulePanel[i].id;
var panelTitle = document.getElementById(paneld).childNodes[0].innerText;
$('#viwerSelect').append('');
}
$scope.CBEnableUI();
// scroll down to first panel
var lastpanel = modulePanel[0].id;
$('body,html').animate({ scrollTop: $('#' + lastpanel).position().top }, 1000);
}
}
}
});
$scope.loadModuleWithCB = function (moduleName) {
if (moduleName == "DISSECTIBLE_ANATOMY") {
var DAData = ModuleService.getModuleData(moduleName);
if (DAData != undefined && DAData.length > 0) {
$scope.loadDissectibleAnatomyModule();
}
}
else if (moduleName == "ATLAS_ANATOMY") {
var AAData = ModuleService.getModuleData(moduleName);
if (AAData != undefined && AAData.length > 0) {
$scope.loadAtlasAnatomyModule();
}
}
else if (moduleName == "CLINICAL_ILLUSTRATIONS") {
var CIData = ModuleService.getModuleData(moduleName);
if (CIData != undefined && CIData.length > 0) {
$scope.loadClinicalIllustrationModule();
}
}
else if (moduleName == "CLINICAL_ANIMATIONS") {
var CAData = ModuleService.getModuleData(moduleName);
if (CAData != undefined && CAData.length > 0) {
$scope.loadClinicalAnimationModule();
}
}
else if (moduleName == "THREE_D_ANATOMY") {
var ThreeDData = ModuleService.getModuleData(moduleName);
if (ThreeDData != undefined && ThreeDData.length > 0) {
$scope.load3DAnatomyModule();
}
}
}
$scope.load3DAnatomyModule = function () {
$rootScope.isCallFromOtherModule = true;
$('#parentcustomDiv').append($(''));
$e = $('#theeDCustomModuleDiv' + $scope.Slidenumber).append("");
$compile($e)($scope);
}
$scope.loadClinicalAnimationModule = function () {
$rootScope.isCallFromOtherModule = true;
$('#parentcustomDiv').append($(''));
$e = $('#caCustomModuleDiv' + $scope.Slidenumber).append("");
$compile($e)($scope);
}
$scope.loadClinicalIllustrationModule = function () {
$rootScope.isCallFromOtherModule = true;
//slide number to terminate last load module on prev slide
// aaCustomModuleDiv new div create for new slide load
$('#parentcustomDiv').append($(''));
$e = $('#ciCustomModuleDiv' + $scope.Slidenumber).append("");
$compile($e)($scope);
}
$scope.loadAtlasAnatomyModule = function () {
$rootScope.isCallFromOtherModule = true;
//slide number to terminate last load module on prev slide
// aaCustomModuleDiv new div create for new slide load
$('#parentcustomDiv').append($(''));
$e = $('#aaCustomModuleDiv' + $scope.Slidenumber).append("");
$compile($e)($scope);
}
$scope.loadDissectibleAnatomyModule = function () {
$rootScope.isCallFromOtherModule = true;
//slide number to terminate last load module on prev slide
// daCustomModuleDiv new div create for new slide load
$('#parentcustomDiv').append($(''));
$e = $('#daCustomModuleDiv' + $scope.Slidenumber).append("");
$compile($e)($scope);
}
//Added code by sandeep for user story-52696
$rootScope.viwerSelectOnChange = function (obj) {
//var selectedText = $("#viwerSelect option:selected").text();
var selected_Id = $("#viwerSelect option:selected").val();
if (selected_Id != "0") {
$('body,html').animate({ scrollTop: $('#' + selected_Id).position().top }, 500);
}
}
}]
);