AIA.controller("CurrBuildController", ["$scope", "$rootScope", "pages", "$log", "Modules", "$http", "$compile", "$location", "$timeout", "ModuleService",
function ($scope, $rootScope, pages, log, Modules, $http, $compile, $location, $timeout, ModuleService) {
// $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");
}
$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) {
//$rootScope.fileNames = e.target.id;
$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();
})
.error(function (data, status, headers, config) {
console.log(data);
});
}
$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: 'CBImageSourcePanel',
selector: '.CBBodyView',
theme: 'success',
currentController: 'CurrBuildController',
parentSlug: 'curriculum-builder',
ajax: {
url: jsImageURL
},
title: $rootScope.windowstitle,
position: {
top: 600,
left: 10,
},
controls: { buttons: 'closeonly' },
size: { width: 850, height: 503 },
});
setTimeout(function () {
var imfgEle = document.getElementById("imgtag");
imfgEle.src = "data:image/png;base64," + $rootScope.windowsimageSource;
}, 200)
}
$rootScope.getCBsummary = function () {
$rootScope.summary = $rootScope.cbJsonData.slideshow.content.element[0].summary;
$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 () {
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: 40,
left: 20,
},
controls: { buttons: 'closeonly' },
size: { width: 850, height: 503 },
});
if ($rootScope.isOpenResourceBtnClicked == true) {
switch ($rootScope.MenuModuleName) {
case 'DA':
$e = $('#resourceModuleDiv').append("");
$compile($e)($scope);
break;
}
//$compile($e)($scope);
}
}
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 () {
//getLoadNodeId($rootScope.stru);
// var nodeid = $rootScope.firstSelectedNodeId;
traverseForLoadDropDown($rootScope.stru);
var nodeid = document.getElementById('cbSelect').value;
$('#jstree').jstree('select_node', nodeid);
// $rootScope.title= $("#"+nodeid).text();
traverseTreeForSetIcons($rootScope.stru, nodeid);
// traverseTreeForNotes($rootScope.note, nodeid);
//traverseForLoadDropDown($rootScope.structure);
//document.getElementById("slideNumber").innerHTML = "Slide" + 1 + " of " + $rootScope.structure.length;
// setTimeout(function () {
// tinymce.get("CBTextArea").setContent($scope.SelectedNotes);
// }, 1000);
}
$scope.openTinyMCE = function (nodeid) {
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);
setTimeout(function () {
$scope.SelectedNotes = $scope.selectedNodeSingleObj.notes;
// $scope.SelectedNotes = 'Visit our HTML tutorial';
$('#CBImageSourcePanel').remove();
if ($('#customModuleDiv').html() != "") {
$('#customModuleDiv').empty();
}
$rootScope.CBWindowLoadComplete = false;
// clear DA data
ModuleService.ClearDAData();
var DAData = ModuleService.getModuleData("DISSECTIBLE_ANATOMY");
if ($scope.SelectedNotes != "" && $scope.SelectedNotes != undefined) {
//sandeep
if ($scope.selectedNodeSingleObj.windows != "") {
// $scope.selectedwindows = $scope.selectedNodeSingleObj.windows.window;
// $scope.tmp = angular.fromJson($scope.selectedNodeSingleObj.windows.window);
$scope.loadContentOfSelectedSlide($scope.selectedNodeSingleObj._id)
}
tinymce.get("CBTextArea").setContent($scope.SelectedNotes);
}
else {
tinymce.get("CBTextArea").setContent("");
}
}, 200);
// setTimeout(function () {
// // handle twice click to load module
// $scope.Currentselectednodeid=undefined;
// },2000);
}
}
$(document).on('click', '#CBTinyMCEPanel .jsglyph-remove', function () {
tinymce.remove();
});
$scope.DropDownSelectNodeClick = function (nodeid) {
//var current_id = document.getElementById('cbSelect').value;
//traverseTreeSelectedSingleObj($rootScope.stru, nodeid);
if ($scope.selectedNodeSingleObj._isBranch == "true") {
traverseTreeSelectedSingleObj($rootScope.stru, nodeid);
$("#cbSelect").empty();
//for (i = 0; i < $scope.selectedNodeSingleObj.length; i++) {
localStorage.setItem("cbSelectId", nodeid);
if ($scope.selectedNodeSingleObj._id == nodeid) {
$scope.currentSlideNumber = i + 1;
$('#cbSelect').append('');
}
else {
$('#cbSelect').append('');
}
//}
document.getElementById("slideNumber").innerHTML = "Slide" + $scope.currentSlideNumber + " of " + $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 " + $scope.selectedNodeSiblingObjs.length;
}
}
//$("CBBodyView").on("change", "#cbSelect", function () {
// var datavalue = document.getElementById('cbSelect').value;
// $('#jstree').jstree(true).deselect_all();
// $('#jstree').jstree('select_node', datavalue);
//});
$rootScope.cbSelectOnChange = function (obj) {
$('#jstree').jstree(true).deselect_all();
$('#jstree').jstree('select_node', obj.value);
}
$rootScope.cbNext = function () {
var cbCurrentId = document.getElementById('cbSelect').value;
traverse($rootScope.stru, cbCurrentId);
for (var k = 0; k < $scope.selectedNodeSiblingObjs.length; k++) {
if ($scope.selectedNodeSiblingObjs[k]._id == cbCurrentId) {
$scope.nextCurrentId = $scope.selectedNodeSiblingObjs[k + 1]._id;
}
}
$('#jstree').jstree(true).deselect_all();
$('#jstree').jstree('select_node', $scope.nextCurrentId);
}
$rootScope.cbBack = function () {
var cbCurrentId = document.getElementById('cbSelect').value;
traverse($rootScope.stru, cbCurrentId);
for (var k = 0; k < $scope.selectedNodeSiblingObjs.length; k++) {
if ($scope.selectedNodeSiblingObjs[k]._id == cbCurrentId) {
$scope.backCurrentId = $scope.selectedNodeSiblingObjs[k - 1]._id;
}
}
$('#jstree').jstree(true).deselect_all();
$('#jstree').jstree('select_node', $scope.backCurrentId);
}
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;
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;
//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])
if (windowData.mType == "DISSECTIBLE_ANATOMY") {
ModuleService.setModuleData(JSON.parse(allwindowData[i]), DawindowId);
DawindowId = DawindowId + 1;
}
else if (windowData.mType == "ATLAS_ANATOMY") {
ModuleService.setModuleData(JSON.parse(allwindowData[i]), AtlasWindowId);
AtlasWindowId = AtlasWindowId + 1;
}
}
}
}
else {
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") {
ModuleService.setModuleData(JSON.parse(allwindowData), DawindowId);
}
else if (windowData.mType == "ATLAS_ANATOMY") {
ModuleService.setModuleData(JSON.parse(allwindowData), AtlasWindowId);
}
}
// load DA
var DAData = ModuleService.getModuleData("DISSECTIBLE_ANATOMY");
if (DAData != undefined && DAData.length > 0) {
$scope.loadDissectibleAnatomyModule();
//for (var j = 0; j < DAData.length; j++) {
// $rootScope.isCallFromOtherModule = true;
//localStorage.setItem("currentBodyViewId", DAData[j].currentBodyViewId)
// $rootScope.DaWindowData = DAData[j];
// $scope.loadDissectibleAnatomyModule();
// }
}
//load available modules in slide
//var AAData = ModuleService.getModuleData("ATLAS_ANATOMY");
//if (AAData != undefined && AAData.length > 0) {
// for (var j = 0; j < AAData.length; i++) {
// $rootScope.isCallFromOtherModule = true;
// $scope.loadAtlasAnatomyModule();
// }
//}
}
$scope.loadAtlasAnatomyModule = function () {
debugger;
$rootScope.isCallFromOtherModule = true;
if ($('#customModuleDiv').html() != "") {
$('#customModuleDiv').empty();
}
//$e = $('#customDAModuleDiv').append("");
//$e = $('#customModuleDiv').append("");
//$compile($e)($scope);
}
$scope.loadDissectibleAnatomyModule = function () {
$rootScope.isCallFromOtherModule = true;
//if ($('#customModuleDiv').html() != "") {
// $('#customModuleDiv').empty();
//}
$e = $('#customModuleDiv').append("");
$compile($e)($scope);
}
}]
);