(function () { 'use strict'; var app = angular.module('items'); var templatePath = modulesSharedResourcesUrl + 'Modules/MyItems/Views/'; // A directive for users to view their items and edit their showcases app.directive('myStuff', function () { return { restrict: 'E', controller: 'myStuffController', templateUrl: templatePath + 'mystuff.html' } }); // A directive for users to view their items app.directive('myItems', ['$rootScope', function ($rootScope) { return { restrict: 'E', scope: { showcaseSummary: '=', currentShowcase: '=', myStuffFns: '=' }, controller: 'myItemsController', templateUrl: templatePath + 'myitems.html', link: link }; function link(scope) { scope.goToRootFolder = function() { $rootScope.$broadcast('UpdateItems'); }, scope.goToTransferRootFolder = function() { $rootScope.$broadcast('UpdateTransferItems'); } } }]); // A directive for users to control how their items are viewed app.directive('myItemsToolbar', ['terminology','$rootScope', function (terminology, $rootScope) { return { restrict: 'E', scope: { options: '=', selectedShowcase: '=', showcaseSummary: '=', myItemsFns: '=', myStuffFns: '=', selectedFolder: '=', availableFolders: '=', isTransferEnabled: '=' }, templateUrl: templatePath + 'myitems-toolbar.html', link: link }; function link(scope) { scope.sidebarToggleButtonActiveTitle = 'Open the sidebar to filter your items by tags, type and ' + terminology.frameworkPlural; scope.sidebarToggleButtonInactiveTitle = 'Close the sidebar and view all items'; // Toggle the sidebar scope.toggleSidebar = function () { scope.myItemsFns.toggleSidebar(); }; // Create a new showcase for items scope.createShowcase = scope.myStuffFns.createShowcase; // Set the current showcase that is being edited scope.setCurrentShowcase = scope.myStuffFns.setCurrentShowcase; scope.selectedFolder = scope.selectedFolder; scope.availableFolders = scope.availableFolders; // Set focus to the showcase editor when the user changes the current showcase scope.jumpToShowcaseEditor = function () { $('#showcase-editor .panel-title button:first').focus(); } // Toggle the focus of the jump button scope.setJumpButtonFocus = function (value) { scope.jumpButtonFocused = value; } scope.goToRootFolder = function() { $rootScope.$broadcast('UpdateItems'); } scope.goToTransferRootFolder = function() { $rootScope.$broadcast('UpdateTransferItems'); } } }]); // A directive for users to control how their items are filtered app.directive('myItemsSidebar', ['terminology', 'itemService', function (terminology, itemService) { return { restrict: 'E', scope: { data: '=', filters: '=', setFilter: '=', categorizedItems: '=' }, templateUrl: templatePath + 'myitems-sidebar.html', link: link }; function link(scope) { scope.frameworkPlural = terminology.frameworkPlural; // Get the icon for a given time scope.getIconForItemType = function (type) { return itemService.getItemIcon({ displayType: type }); }; // Filter the items by a tag scope.selectTag = function (tag) { scope.setFilter('selectedTag', tag); }; // Filter the items by a type scope.selectType = function (type) { scope.setFilter('selectedType', type); }; // Hide the tags tab if there are no items with tags scope.noTags = function () { return scope.categorizedItems.tags && ( Object.keys(scope.categorizedItems.tags).length == 1 && scope.categorizedItems.tags["No Tags"] == 0 ); } // Hide the type tab if there are no items with tags scope.noTypes = function () { return scope.categorizedItems.type && Object.keys(scope.categorizedItems.type.length == 0); } } }]); // A directive for users to filter their items by competency app.directive('myItemsCompetencyFilter', function () { return { restrict: 'E', scope: { filters: '=', setFilter: '=', filteredIds: '=' }, controller: 'competencyTreeController', templateUrl: templatePath + 'myitems-competency-filter.html', link: function (scope, _e, _a, ctrl) { // Set the framework scope.setFramework = function (id) { ctrl.setFrameworkAndGetCompetencies(id); } // Filter the items by a competency scope.selectCompetency = function (competency) { var currentFilter = scope.filters.selectedCompetency; scope.setFilter('selectedCompetency', currentFilter && currentFilter.id == competency.id ? null : competency ); } scope.filterCompetencies = function (simpleEvidence) { return simpleEvidence.filter(function (evidence) { return scope.filteredIds.indexOf(evidence.sourceId) > -1; }); }; } } }); // A directive to show which filters are currently active app.directive('myItemsBrowse', function () { return { restrict: 'E', scope: { filters: '=', clearFilter: '=', toggleSidebar: '=', clearAllFilters: '=' }, templateUrl: templatePath + 'myitems-browse.html', link: function (scope) { scope.filterSet = function () { return scope.browseList.some(function (item) { return scope.filters[item.filter]; }); } scope.browseList = [ { icon: 'fa fa-tag', filter: 'selectedTag', type: 'Tag' }, { icon: 'fa fa-sitemap', filter: 'selectedCompetency', type: 'Competency' }, { icon: 'fa fa-th-large', filter: 'selectedType', type: 'Type' }, { icon: 'fa fa-search', filter: 'query', type: 'Search query' } ]; scope.$watch("filters", function () { var filtersToMessage = scope.browseList.filter(function (item) { return scope.filters[item.filter]; }).map(function (item) { return "the " + item.type + " " + (scope.filters[item.filter].name || scope.filters[item.filter]); }); if (filtersToMessage.length > 0) { if (filtersToMessage.length > 1) { var lastMessage = filtersToMessage.splice(filtersToMessage.length - 1, 1); } scope.statusMessage = "You are browsing items with: " + filtersToMessage.join(", ") + (lastMessage ? " and " + lastMessage : ""); } else { scope.statusMessage = ""; } }, true); } }; }); // A directive for the items in the grid that can be dragged to a showcase app.directive('myItemsList', ['$rootScope', function ($rootScope) { return { restrict: 'E', scope: { items: '=', options: '=', filters: '=', order: '=', canDrag: '=', myStuffFns: '=', currentShowcase: '=', loadItemsOnScroll: '=', itemsDisplayedInList: '=', itemsDragOptions: '=dragOptions', myItemsFns: '=', transferItems: '=', isTransferEnabled: '=', currentFolder: '=', showItemsForTransfer: '=' }, templateUrl: templatePath + 'myitems-list.html', link: function (scope) { scope.goToRootFolder = function () { $rootScope.$broadcast('UpdateItems'); }, // Toggle the size of the items scope.toggleItemSize = function () { scope.myItemsFns.toggleItemSize(); }; // Filter the items by a search query scope.search = function (query) { scope.myItemsFns.search(query); } scope.filterEnabled = function (filters) { if (filters.query) { return true; } if (filters.selectedTag) { return true; } if (filters.selectedType) { return true; } if (filters.selectedCompetency) { return true; } return false; } // Create a new folder scope.createFolder = scope.myStuffFns.createFolder; } }; }]); // A directive for users to control how their items are viewed app.directive('myTransferItems', ['terminology','$rootScope', function (terminology, $rootScope) { return { restrict: 'E', scope: { data: '=', transferfns: '=', }, templateUrl: templatePath + 'mytransferitems.html', controller: 'myTransferItemsController', link: link }; function link(scope) { // Filter the items by a search query scope.search = function (query) { scope.transferfns.search(query); } scope.goToRootFolder = function () { $rootScope.$broadcast('UpdateItems'); } scope.setItemTypeFilter = function (itemType) { scope.transferfns.setFilter('selectedType', itemType.value); } scope.goToTransferRootFolder = function () { $rootScope.$broadcast('UpdateTransferItems'); } } }]); })();