(function () { 'use strict'; var app = angular.module('showboards'); var templatePath = modulesSharedResourcesUrl + 'Modules/MyShowboards/Views/'; app.directive('myShowboards', function () { return { restrict: 'E', templateUrl: templatePath + 'myshowboards.html', } }); app.directive('showboardsList', ['showboardsDataContext', 'showboardsService', '$filter', 'common', '$location', '$modal', '$rootScope', function (showboardsDataContext, showboardsService, $filter, common, $location, $modal, $rootScope) { return { restrict: 'E', templateUrl: templatePath + 'showboardslist.html', scope: { selectOnly: '=' }, link: link }; function link($scope, elem, attrs) { var getLogFn = common.logger.getLogFn; var logSuccess = getLogFn("showboards", "success"); var logError = getLogFn("showboards", "error"); function getShowboards() { showboardsDataContext.getAllMyShowboards().then(function (data) { $scope.showboards = data; $scope.showboardsOriginal = angular.copy(data); $scope.showboardsLoaded = true; }); } $scope.getShowboardUser = function (showboard) { showboardsService.getShowboardUserDetails(showboard); } $scope.pinShowboard = function (showboard) { showboard.isPinned = !showboard.isPinned; showboard.isTrue = showboard.isPinned; showboardsDataContext.pinShowboard(showboard).then(function (data) { if (showboard.isTrue) { logSuccess("Pinned " + showboard.name); } else { logSuccess("Upinned " + showboard.name); } }); } $scope.searchShowboards = function (val) { $scope.showboards = $scope.showboardsOriginal; $scope.showboards = $filter('filter')($scope.showboards, { name: val, description: val }); if ($scope.showboards.length == 0) { $scope.noResults = true; } else { $scope.noResults = false; } } $scope.likeShowboard = function (showboard) { if (!$scope.likingShowboard) { $scope.likingShowboard = true; showboard.isLiked = !showboard.isLiked; if (showboard.isLiked) { showboard.numLikes = showboard.numLikes + 1 } else { showboard.numLikes = showboard.numLikes - 1 } showboard.isTrue = showboard.isLiked; showboardsDataContext.likeShowboard(showboard).then(function (data) { if (showboard.isTrue) { logSuccess("Liked " + showboard.name); } else { logSuccess("Unliked " + showboard.name); } $scope.likingShowboard = false; }); } } $scope.viewShowboard = function (showboard) { showboardsService.setCurrentShowboard(showboard); $location.path('/showboards/view'); } $scope.favouriteShowboard = function (showboard) { showboard.isFavourite = !showboard.isFavourite; showboard.isTrue = showboard.isFavourite; showboardsDataContext.favouriteShowboard(showboard).then(function (data) { if (showboard.isTrue) { logSuccess("Added " + showboard.name + " To favourites"); } else { logSuccess("Removed " + showboard.name + " From favourites"); } }); } $scope.shareShowboard = function (showboard) { $modal.open({ templateUrl: templatePath + 'share.html', controller: shareShowboardController, size: 'sm', background: 'static', resolve: { showboard: function () { return showboard; }, } }); } var shareShowboardController = function (common, $scope, $modalInstance, showboard) { $scope.showboard = showboard; $scope.showboardUrl = showboardsUrl; //close the modal $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; } $scope.canManageShowboards = function () { if ($rootScope.currentRole && $rootScope.currentRole.functions.find(item => item === 'myshowboards_manage')) { return true; } return false } getShowboards(); } }]); app.directive('viewShowboard', ['$window', 'user', '$filter', 'showboardsDataContext', 'showboardsService', 'virusScanModalService', 'common', '$location', '$modal', '$rootScope', function ($window, user, $filter, showboardsDataContext, showboardsService, virusScanModalService, common, $location, $modal, $rootScope) { return { restrict: 'E', templateUrl: templatePath + 'viewshowboard.html', link: link }; function link($scope, elem, attrs) { var getLogFn = common.logger.getLogFn; var logSuccess = getLogFn("showboards", "success"); var logError = getLogFn("showboards", "error"); $scope.showboard = showboardsService.getCurrentShowboard(); $scope.showboardItem = showboardsService.getCurrentShowboardItem(); showboardsService.setCurrentShowboardItem(null); if (!$scope.showboard) { $location.path('/showboards'); } // figure how much space we have to play with if ($window.innerWidth > 1366) { $scope.fourColumnLayout = true; } else if ($window.innerWidth > 1024) { $scope.threeColumnLayout = true; } else if ($window.innerWidth > 768) { $scope.twoColumnLayout = true; } else { $scope.singleColumnLayout = true; } // This is a maybe as it slows the page but it may be needed if we need the colums to adjust when the window is resized $(window).on("resize.doResize", function (){ $scope.$apply(function() { // figure how much space we have to play with if ($window.innerWidth > 1366) { $scope.fourColumnLayout = true; $scope.threeColumnLayout = false; $scope.singleColumnLayout = false; $scope.twoColumnLayout = false; } else if ($window.innerWidth >= 1024) { $scope.threeColumnLayout = true; $scope.fourColumnLayout = false; $scope.singleColumnLayout = false; $scope.twoColumnLayout = false; } else if ($window.innerWidth > 768) { $scope.twoColumnLayout = true; $scope.fourColumnLayout = false; $scope.threeColumnLayout = false; $scope.singleColumnLayout = false; } else { $scope.singleColumnLayout = true; $scope.threeColumnLayout = false; $scope.fourColumnLayout = false; $scope.twoColumnLayout = false; } }); }); $scope.$on("$destroy",function (){ $(window).off("resize.doResize"); //remove the handler added earlier }); $rootScope.$on("updateItems", function (event, args) { if ($scope.showboardItemsOriginal) { $scope.showboardItemsOriginal.push(args); } }); $scope.searchShowboard = function (val, reverse, type) { $scope.showboard.showBoardItems = $scope.showboardItemsOriginal; if (type == 'tag') { $scope.showboard.showBoardItems = $filter('selectedTags')($scope.showboard.showBoardItems, val); $scope.showboard.search = val; if ($scope.showboard.showBoardItems.length == 0) { $scope.noResults = true; } else { $scope.noResults = false; } } else { if (typeof val !== 'object') { $scope.showboard.search = val; $scope.showboard.showBoardItems = $filter('filter')($scope.showboard.showBoardItems, val); if ($scope.showboard.showBoardItems.length == 0) { $scope.noResults = true; } else { $scope.noResults = false; } } if (!reverse) { $scope.showboard.showBoardItems = $filter('filter')($scope.showboard.showBoardItems, val); } else { $scope.showboard.showBoardItems = $filter('filter')($scope.showboard.showBoardItems, ''); } } $scope.orderByPredicate('-dateCreated', true); } $scope.inView = function (showboardItem, inView) { if (inView) { showboardItem.show = true } else { showboardItem.show = false } } $scope.orderByPredicate = function (val, reverse) { if (!reverse) { val = '-' + val; } $scope.showboard.showBoardItems = $filter('orderBy')($scope.showboard.showBoardItems, val); } if ($scope.showboard) { $scope.showboardItemsOriginal = angular.copy($scope.showboard.showBoardItems); showboardsDataContext.updateShowboardView($scope.showboard); $scope.showboard.numTimesViewed = $scope.showboard.numTimesViewed + 1; user.getProfile().then(function (theUser) { $scope.user = theUser; // If we have a showboardItem at this point then we are creating if ($scope.showboardItem) { //$modalInstance.dismiss('cancel'); $scope.addShowboardItem($scope.showboardItem); } }); $scope.orderByPredicate('-dateCreated', true) } $scope.getShowboardUser = function (showboard) { showboardsService.getShowboardUserDetails(showboard); } $scope.getReportReason = function (reason) { return showboardsService.getReportReason(reason); } $scope.canUserComment = function (element) { if (element) { if (element.commenting == 0) { return false; } if (element.commenting == 1) { if (!$scope.showboard.isAdmin) { return false; } else { return true; } } if (element.commenting == 2) { if ($scope.user) { if (element.createdBy == $scope.user.userId) { return true; } else if ($scope.showboard.isAdmin) { return true; } else { return false; } } } if (element.commenting == 3) { return true; } } } $scope.favouriteShowboardItem = function (showboardItem) { showboardItem.isFavourite = !showboardItem.isFavourite; showboardItem.isTrue = showboardItem.isFavourite; showboardsDataContext.favouriteShowboardItem(showboardItem).then(function (data) { if (showboardItem.isTrue) { logSuccess("Set " + showboardItem.name + " as a favourite"); } else { logSuccess("Removed " + showboardItem.name + " as favourite"); } }); } $scope.likeShowboardItem = function (showboardItem) { if (!$scope.likingShowboardItem) { $scope.likingShowboardItem = true; showboardItem.isLiked = !showboardItem.isLiked; if (showboardItem.isLiked) { showboardItem.numLikes = showboardItem.numLikes + 1 } else { showboardItem.numLikes = showboardItem.numLikes - 1 } showboardItem.isTrue = showboardItem.isLiked; showboardsDataContext.likeShowboardItem(showboardItem).then(function (data) { if (showboardItem.isTrue) { logSuccess("Liked " + showboardItem.name); } else { logSuccess("Unliked " + showboardItem.name); } $scope.likingShowboardItem = false; }); } } $scope.favouriteShowboard = function (showboard) { showboard.isFavourite = !showboard.isFavourite; showboard.isTrue = showboard.isFavourite; showboardsDataContext.favouriteShowboard(showboard).then(function (data) { if (showboard.isTrue) { logSuccess("Added " + showboard.name + " To favourites"); } else { logSuccess("Removed " + showboard.name + " From favourites"); } }); } $scope.updateReportItem = function (report, status, showboardItem) { report.status = status showboardsDataContext.updateShowboardItemReport(report).then(function (data) { logSuccess("Showboard item report updated"); for (i in showboardItem.issueReportsClassed.new) { if (showboardItem.issueReportsClassed.new[i].id == report.id) { showboardItem.issueReportsClassed.new.splice(i, 1); if (status == 2) { showboardItem.issueReportsClassed.resolved.push(report); } if (status == 1) { showboardItem.issueReportsClassed.inProgress.push(report); } } } }); } $scope.reportItem = function (reportedItem, type) { $modal.open({ templateUrl: templatePath + 'report.html', controller: reportItemController, size: 'sm', background: 'static', resolve: { reportedItem: function () { return reportedItem; }, type: function () { return type; } } }); } var reportItemController = function (common, $scope, $modalInstance, reportedItem, type) { $scope.reportedItem = reportedItem; $scope.reportItem = function (reason) { if (type == 'showboard') { showboardsDataContext.reportShowboard($scope.reportedItem, reason).then(function (data) { logSuccess("Showboard reported"); $scope.reportSubmitted = true; $scope.reportedItem.hasOpenReport = true; }); } if (type == 'showboardItem') { showboardsDataContext.reportShowboardItem($scope.reportedItem, reason).then(function (data) { logSuccess("Showboard item reported"); $scope.reportSubmitted = true; $scope.reportedItem.hasOpenReport = true; }); } } //close the modal $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; } $scope.removeItem = function (showboardItem) { $modal.open({ templateUrl: templatePath + 'remove.html', controller: removeItemController, size: 'sm', background: 'static', resolve: { showboardItem: function () { return showboardItem; } } }); } var removeItemController = function (common, $scope, $modalInstance, showboardItem) { $scope.showboardItem = showboardItem; $scope.removeItem = function (reason) { $scope.showboardItem.status = 2; showboardsDataContext.withdrawShowboardItem($scope.showboardItem).then(function (data) { logSuccess("Showboard item removed"); $modalInstance.dismiss('cancel'); }); } //close the modal $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; } $scope.viewShowboardItem = function (showboardItem) { $modal.open({ templateUrl: templatePath + 'viewshowboarditem.html', controller: viewShowboardItemController, size: 'lg', background: 'static', windowClass: 'clean-full-modal', resolve: { showboard: function () { return $scope.showboard; }, showboardItem: function () { return showboardItem; }, user: function () { return $scope.user; }, canUserComment: function () { return $scope.canUserComment; } } }); } $scope.goBack = function(path) { showboardsService.goBack(path); } var viewShowboardItemController = function (common, $scope, $modalInstance, showboardItem, user, showboard, canUserComment) { $scope.canUserComment = canUserComment; $scope.user = user; $scope.showboardItem = showboardItem; $scope.showboard = showboard; $scope.showcaseUrl = myShowcaseSiteUrl + 'showcase/' + $scope.showboardItem.externalId; showboardsDataContext.updateShowboardItemView($scope.showboardItem); $scope.showboardItem.numTimesViewed = $scope.showboardItem.numTimesViewed + 1; $scope.canManageShowboards = function () { if ($rootScope.currentRole && $rootScope.currentRole.functions.find(item => item === 'myshowboards_manage')) { return true; } return false } //close the modal $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; } $scope.addShowboardItem = function (showboardItem) { $modal.open({ templateUrl: templatePath + 'addshowboarditem.html', controller: addShowboardItemController, size: 'lg', background: 'static', resolve: { showboardItem: function () { return showboardItem; }, showboard: function () { return $scope.showboard; } } }); } var addShowboardItemController = function (common, $scope, $modalInstance, showboardItem, showboard) { $scope.showboard = showboard; $scope.showboardItem = showboardItem; $scope.showcases = []; //get showcases for this user function getShowcases() { showboardsDataContext.getShowcases().then(function (result) { for (var i = 0; i < result.length; i++) { if (result[i].showcaseState == "Published") { $scope.showcases.push(result[i]); } } if ($scope.showcases.length == 0) { $scope.noShowcases = true; } }); } getShowcases(); if (!$scope.showboardItem) { $scope.showboardItem = showboardsService.createBlankShowboardItem(); $scope.showboardItem.commenting = $scope.showboard.commenting; user.getProfile().then(function (theUser) { $scope.showboardItem.user = theUser; if (theUser.avatarDetails) { $scope.showboardItem.user.avatarUrlFull = theUser.avatarDetails.url; } }); $scope.showboardItem.showBoardItemTypeId = $scope.showboard.allowedItemTypes[0].showBoardItemTypeId; } else if (!$scope.showboardItem.createdBy) { user.getProfile().then(function (theUser) { $scope.showboardItem.user = theUser; if (theUser.avatarDetails) { $scope.showboardItem.user.avatarUrlFull = theUser.avatarDetails.url; } }); $scope.showboardItem.showBoardItemTypeId = $scope.showboard.allowedItemTypes[0].showBoardItemTypeId; } $scope.showboardItem.showBoardId = $scope.showboard.id; $scope.saveShowboardItem = function () { if (!$scope.showboardItem.id) { $scope.showboardItem.status = 1; showboardsDataContext.createShowboardItem($scope.showboardItem).then(function (data) { $scope.showboard.showBoardItems.unshift(data); $rootScope.$broadcast('updateItems', data); logSuccess("Showboard item created successfully"); $modalInstance.dismiss('cancel'); $scope.saving = false; }).catch(function (errorData) { if (errorData === "Virus scan positive.") { virusScanModalService.virusModal(); } else { logError("An error occured saving the item."); } $scope.saving = false; $modalInstance.dismiss('cancel'); }); } else { $scope.showboardItem.status = 1; showboardsDataContext.updateShowboardItem($scope.showboardItem).then(function (data) { $scope.showboardItem.showBoardItemStyle = data.showBoardItemStyle; logSuccess("Showboard item updated successfully"); $modalInstance.dismiss('cancel'); $scope.saving = false; }).catch(function (errorData) { if (errorData === "Virus scan positive.") { virusScanModalService.virusModal(); } else { logError("An error occured saving the item."); } $scope.saving = false; $modalInstance.dismiss('cancel'); }); } } $scope.withdrawShowboardItem = function () { $scope.showboardItem.status = 2; showboardsDataContext.updateShowboardItem($scope.showboardItem).then(function (data) { logSuccess("Showboard item updated successfully"); $modalInstance.dismiss('cancel'); $scope.saving = false; }); } $scope.getShowboardUser = function (showboardItem) { if (showboardItem.createdBy) { showboardsService.getShowboardUserDetails(showboard); } } // Called when image file has been selected $scope.onFileSelect = function (files) { if (files) { $scope.errorMessage = null; $scope.file = files[0]; $scope.file.fileName = $scope.file.name; if ($scope.file.size > 20000000) { $scope.errorMessage = 'File size is too large, max 20MB'; return; } var reader = new FileReader(); reader.onload = function (e) { $scope.$apply(function () { // get loaded data and render preview. var image = new Image(); image.src = e.target.result; $scope.imagePreview = e.target.result; image.onload = function () { var height = this.height; var width = this.width; $scope.showboardItem.showBoardItemStyle.imageWidth = width + 'px'; if (this.width > 450) { $scope.$apply(function () { $scope.showboardItem.showBoardItemStyle.imageHeight = height / (width / 450) + 'px'; }); } else { $scope.$apply(function () { $scope.showboardItem.showBoardItemStyle.imageHeight = height + 'px'; }); } } }); $scope.showboardItem.fileAsBase64 = reader.result; }; // Generate base 64 image for preview reader.readAsDataURL($scope.file); } } $scope.resetHeader = function (color) { $scope.file = null; $scope.showboardItem.showBoardItemStyle.imageHeight = '300px'; $scope.showboardItem.showBoardItemStyle.headerColour = color; $scope.showboardItem.showBoardItemStyle.headerImageUrl = null; $scope.imagePreview = null; } //close the modal $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; } $scope.canManageShowboards = function () { if ($rootScope.currentRole && $rootScope.currentRole.functions.find(item => item === 'myshowboards_manage')) { return true; } return false } } }]); app.directive('discoverShowboards', ['showboardsDataContext', 'showboardsService', 'common', '$location', '$modal', '$filter', function (showboardsDataContext, showboardsService, common, $location, $modal, $filter) { return { restrict: 'E', templateUrl: templatePath + 'discovershowboards.html', link: link }; function link($scope, elem, attrs) { var getLogFn = common.logger.getLogFn; var logSuccess = getLogFn("showboardsAdmin", "success"); var logError = getLogFn("showboardsAdmin", "error"); function getShowboards() { showboardsDataContext.discoverShowboards().then(function (data) { $scope.showboards = data; $scope.showboardsOriginal = angular.copy(data); $scope.showboardsLoaded = true; }); } $scope.getShowboardUser = function (showboard) { showboardsService.getShowboardUserDetails(showboard); } $scope.viewShowboard = function (showboard) { showboardsService.setCurrentShowboard(showboard); $location.path('/showboards/view'); } $scope.favouriteShowboard = function (showboard) { showboard.isFavourite = !showboard.isFavourite; showboard.isTrue = showboard.isFavourite; showboardsDataContext.favouriteShowboard(showboard).then(function (data) { if (showboard.isTrue) { logSuccess("Added " + showboard.name + " To favourites"); } else { logSuccess("Removed " + showboard.name + " From favourites"); } }); } $scope.likeShowboard = function (showboard) { if (!$scope.likingShowboard) { $scope.likingShowboard = true; showboard.isLiked = !showboard.isLiked; if (showboard.isLiked) { showboard.numLikes = showboard.numLikes + 1 } else { showboard.numLikes = showboard.numLikes - 1 } showboard.isTrue = showboard.isLiked; showboardsDataContext.likeShowboard(showboard).then(function (data) { if (showboard.isTrue) { logSuccess("Liked " + showboard.name); } else { logSuccess("Unliked " + showboard.name); } $scope.likingShowboard = false; }); } } $scope.searchShowboards = function (val) { $scope.showboards = $scope.showboardsOriginal; $scope.showboards = $filter('filter')($scope.showboards, { name: val, description: val }); if ($scope.showboards.length == 0) { $scope.noResults = true; } else { $scope.noResults = false; } } getShowboards(); } }]); angular.module('showboards').filter('selectedTags', function () { return function (items, tag) { return items.filter(function (item) { for (var i in item.tags) { if (tag.toLowerCase() == item.tags[i].text.toLowerCase()) { return true; } } return false; }); }; }); })();