(function () { 'use strict'; var app = angular.module('showcases'); // A controller to create a showcase app.controller('showcaseCreateModalController', ['$rootScope', '$scope', '$modalInstance', 'common', 'showcasesService', 'showcasesDataContext', function ($rootScope, $scope, $modalInstance, common, showcasesService, showcasesDataContext) { var getLogFn = common.logger.getLogFn; var logSuccess = getLogFn("itemSummary", "success"); $scope.showcase = {}; $scope.currentShowcases = []; $scope.isNameUnique = false; showcasesDataContext.getShowcases().then(function (showcases) { $scope.currentShowcases = showcases; }) // Check that the name of the showcase is unique $scope.checkShowcaseNameUnique = function (name) { $scope.isNameUnique = showcasesService.checkShowcaseNameUnique($scope.currentShowcases, name); } // Save the new showcase $scope.ok = function () { showcasesDataContext.createShowcase($scope.showcase).then(function (result) { showcasesService.setCurrentShowcaseId(result.showcaseId); logSuccess("Showcase created!"); $modalInstance.close(); // Broadcast the event so the showcases list refreshes $rootScope.$broadcast('UpdateShowcases'); }); }; // Cancel without saving $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; }]); // A controller to share a showcase app.controller('showcaseShareModalController', ['$scope', '$modalInstance', 'showcase', 'common', 'config', 'userDataContext', 'showcasesDataContext', 'showboardsService', function ($scope, $modalInstance, showcase, common, config, userDataContext, showcasesDataContext, showboardsService) { var logSuccess = common.logger.getLogFn("editItem", "success"); $scope.siteUrl = config.siteUrl; $scope.tabs = [{ active: !showcase.preview }, { active: showcase.preview }, { active: showcase.preview }]; $scope.minDate = new Date(); $scope.dateOptions = { formatYear: 'yy', startingDay: 1 }; // List of reviewers for this user and showcase getShowcase(); getReviewersList(); $scope.allReviewers = []; // The currently selected tab $scope.selectedTab = null; // Select a tab $scope.selectTab = function (name) { $scope.selectedTab = name; } // Clear the selected tab $scope.back = function () { $scope.selectedTab = null; }; // Get the showcase function getShowcase() { return showcasesDataContext.getShowcase(showcase.showcaseId).then(function (data) { $scope.showcase = data; $scope.showcase.newReviewers = []; // Default review invite message if (!$scope.showcase.reviewInviteText) { $scope.showcase.reviewInviteText = "Dear [ReviewerName],\n\nI have created a showcase called [ShowcaseName] that I would love for you to take a look at.\n\nYou can find my showcase by clicking the link below.\n\nThank you for your help."; } $scope.showcaseLoaded = true; }) } // Get the list of all reviewers for this user function getReviewersList() { return userDataContext.getReviewers().then(function (data) { $scope.allReviewers = data; }) } // Get a list of reviewers that match a value entered by the user function getReviewersForQuery(type, val) { return $scope.allReviewers.reduce(function (filtered, reviewer) { if (reviewer[type].indexOf(val) !== -1) { filtered.push(reviewer[type]); } return filtered; }, []); } // Get reviewer emails that match the value entered by the user $scope.getReviewerEmails = function (val) { return getReviewersForQuery('email', val); } // Get reviewer names that match the value entered by the user $scope.getReviewerNames = function (val) { return getReviewersForQuery('name', val); } // Add a reviewer to a published showcase $scope.addReviewer = function () { $scope.showcase.newReviewers.push({ name: $scope.showcase.newReviewerName, email: $scope.showcase.newReviewerEmail }); $scope.showcase.newReviewerName = ''; $scope.showcase.newReviewerEmail = ''; } $scope.addGroupReviewer = function () { var split = $scope.newReviewerNameForGroup.split('-'); $scope.showcase.newReviewers.push({ name: split[0].trim(), email: split[1].trim() }); $scope.newReviewerNameForGroup = ''; } // Remove a reviewer from a published showcse $scope.removeReviewer = function (reviewer) { var index = $scope.showcase.newReviewers.indexOf(reviewer); if (index > -1) $scope.showcase.newReviewers.splice(index, 1); } // Open the calendar (for showcase end date) $scope.openCalendar = function ($event) { $event.preventDefault(); $event.stopPropagation(); $scope.isCalendarOpened = true; } $scope.sendReviewMessage = function () { var updatedShowcase = angular.copy($scope.showcase); updatedShowcase.reviewers = $scope.showcase.newReviewers; showcasesDataContext.sendShowcaseReviewMessage(updatedShowcase, $scope.showcase.shortcode).then(function () { getShowcase(); $scope.showcase.newReviewers = []; logSuccess("Email sent"); }); } $scope.shareToShowboard = function () { $scope.selectedTab = 'showboard'; $scope.showboardItem = showboardsService.createBlankShowboardItem(); $scope.showboardItem.externalId = $scope.showcase.shortcode; $scope.showboardItem.name = $scope.showcase.name; $scope.showboardItem.description = $scope.showcase.description; showboardsService.setCurrentShowboardItem($scope.showboardItem); } // this will listen for route changes and call the callback $scope.$on('$routeChangeStart', function () { $modalInstance.dismiss('cancel'); }); //close the modal $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; }]); // A controller to publish a showcase app.controller('showcasePublishModalController', ['$rootScope', '$scope', '$modalInstance', 'showcase', 'showcasesDataContext', 'showcaseModals', function ($rootScope, $scope, $modalInstance, showcase, showcasesDataContext, showcaseModals) { $scope.publishInProgress = false; // Publish the showcase $scope.publish = function () { $scope.publishInProgress = true; showcase.showcaseId = showcase.showcaseId || showcase.id; showcasesDataContext.publishShowcase(showcase.showcaseId).then(function (data) { $rootScope.$broadcast('UpdateShowcases'); $modalInstance.dismiss('cancel'); if (data.shortcode == "Showcase contains no items") { var message = { title: "Showcase cannot be published yet", summary: "This showcase contains no items and so it cannot be published yet.", full: "First, add some items to the showcase and then try to publish it again." } showMessage(message); } else { showcase.shortcode = data.shortcode; showcase.isPrivate = true; showcaseModals.share(showcase); } }); }; function showMessage (message) { $scope.publishInProgress = false; showcaseModals.showMessage(message); // Close the modal $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; } // Close the modal $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; }]); // A controller to show a showcase action message app.controller('showcaseShowMessageModalController', ['$rootScope', '$scope', '$modalInstance', 'showcaseModals', 'message', function ($rootScope, $scope, $modalInstance, showcaseModals, message) { $scope.message = message; // Close the modal $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; console.log($scope.message.title); console.log($scope.message.summary); console.log($scope.message.full); }]); // A controller to view the summary for a showcase app.controller('showcaseSummaryModalController', ['$scope', '$rootScope', '$modalInstance', 'common', 'showcase', 'showcasesDataContext', function ($scope, $rootScope, $modalInstance, common, showcase, showcasesDataContext) { var getLogFn = common.logger.getLogFn; var logSuccess = getLogFn("itemSummary", "success"); $scope.showcase = showcase; $scope.showHistoryId = showcase.showcaseId; $scope.privacyConfirmText = "Are you sure you want to change the privacy setting for this showcase version? Making a showcase a 'Public' showcase means that anyone who has a copy of the link to the showcase will be able to view all its contents. To better control access to your showcase, make the showcase 'Private' (by unchecking the public checkbox) and only invite the people you would like to share it with."; // Get the version history for the selected showcase showcasesDataContext.getShowcaseVersions(showcase.showcaseId).then(function (data) { $scope.showcaseHistoryData = data; }); $scope.toggleVersionPrivacy = function (showcaseVersion) { showcaseVersion.isPrivate = !showcaseVersion.isPrivate; showcasesDataContext.toggleShowcaseVersionPrivacy($scope.showHistoryId, showcaseVersion).then(function () { logSuccess("Showcase version privacy updated"); }); } // Toggle the privacy setting for the showcase $scope.toggleShowcasePrivacy = function () { var showcase = $scope.showcase; showcase.isPrivate = !showcase.isPrivate; showcasesDataContext.toggleShowcasePrivacy(showcase.showcaseId).then(function () { logSuccess("Showcase privacy updated"); }); } // Close the modal $scope.close = function () { $modalInstance.dismiss('cancel'); $rootScope.$broadcast('UpdateShowcases'); }; }]); // A controller to show a notice when users exit the showcase builder app.controller('builderGoBackConfirmController', ['$scope', '$modalInstance', 'confirmed', function ($scope, $modalInstance, confirmed) { $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; $scope.ok = function () { confirmed(); $modalInstance.close(); } }]); })();