"use strict"; angular.module("vocabulary") .component("yourLessonListing", { templateUrl: "/js/redesign-angular/yourLessons/your-lesson-listing.html", controller: "YourLessonListing", bindings: { listingData: "<", isCopied: "<", onCopyLesson: "&", onDeleteLesson: "&", onMoveLesson: "&", onSelectLesson: "&", showPopover: "<" } }) .controller("YourLessonListing", ["orderByFilter", "scrollService", "drawerService","partsOfSpeechService", "accessRestriction", "FeatureCheck", function YourLessonListingController(orderByFilter, scrollService, drawerService, partsOfSpeechService, accessRestriction, FeatureCheck) { var ctrl = this; this.$onInit = init; function init() { ctrl.lessonWords = ctrl.listingData.words; ctrl.lessonName = ctrl.listingData.lessonName; ctrl.lessonDate = ctrl.listingData.formattedDate; ctrl.lessonId = ctrl.listingData.lessonId; } ctrl.getWords = function(){ if(FeatureCheck.isFeatureEnabled('VAZ_REDESIGN_LESSON_WORD_ORDER')) { switch(ctrl.listingData.lessonWordOrder) { case 'As Entered': return orderByFilter(ctrl.lessonWords, 'lessonEntryOrder'); case 'Alphabetical': return orderByFilter(ctrl.lessonWords, 'wordName'); default: return orderByFilter(ctrl.lessonWords, 'lessonEntryOrder'); } } else { return orderByFilter(ctrl.lessonWords, 'wordName'); } }; ctrl.abbreviatePartOfSpeech = partsOfSpeechService.abbreviate; ctrl.toggleLessonCard = function() { drawerService.closeOpenDrawers("js-lesson-drawer", 300, "linear") .then(function() { return accessRestriction.enforceRestriction({lid: ctrl.lessonId}); }) .then(lessonSelectionAction) .catch(function(e) {}); }; function lessonSelectionAction() { ctrl.onSelectLesson({ $event: { lessonId: ctrl.lessonId } }); } ctrl.copyLesson = function($event){ ctrl.onCopyLesson({ $event: { lessonId: $event.lessonId } }); }; ctrl.deleteLesson = function(){ ctrl.toggleLessonCard(); ctrl.onDeleteLesson(); }; ctrl.moveLesson = function(){ ctrl.toggleLessonCard(); ctrl.onMoveLesson(); }; ctrl.closeLesson = function(){ ctrl.onSelectLesson({ $event: { lessonId: ctrl.lessonId } }); }; ctrl.onDataRetrieved = function(){ scrollService.scrollToTopOfElement("your_lesson_listing_" + ctrl.lessonId, 300, "linear").then(openThisDrawer); }; function openThisDrawer() { drawerService.openSingleDrawer("drawer_" + ctrl.lessonId, 300, "linear"); } }]);