all files / app/main/apps/scrumboard/views/calendar/dialogs/event/ event-dialog.controller.js

23.08% Statements 6/26
100% Branches 0/0
16.67% Functions 1/6
23.08% Lines 6/26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90                                                                                                                                                                        
(function ()
{
    'use strict';
 
    angular
        .module('app.scrumboard')
        .controller('ScrumboardCalendarEventDialogController', ScrumboardCalendarEventDialogController);
 
    /** @ngInject */
    function ScrumboardCalendarEventDialogController($mdDialog, dueDate, BoardService, msUtils)
    {
        var vm = this;
 
        // Data
        vm.board = BoardService.data;
        vm.dueDate = dueDate;
        vm.newCard = {
            name  : '',
            listId: ''
        };
        vm.selectedCards = [];
 
        // Methods
        vm.exists = msUtils.exists;
        vm.toggleInArray = msUtils.toggleInArray;
        vm.closeDialog = closeDialog;
        vm.addNewCard = addNewCard;
        vm.assignDueDate = assignDueDate;
 
        //////////
 
        /**
         * Close Dialog
         */
        function closeDialog()
        {
            $mdDialog.hide();
        }
 
        /**
         * Add New Card
         */
        function addNewCard()
        {
            var newCardId = msUtils.guidGenerator();
 
            vm.board.cards.push({
                'id'               : newCardId,
                'name'             : vm.newCard.name,
                'description'      : '',
                'idAttachmentCover': '',
                'idMembers'        : [],
                'idLabels'         : [],
                'attachments'      : [],
                'subscribed'       : false,
                'checklists'       : [],
                'checkItems'       : 0,
                'checkItemsChecked': 0,
                'comments'         : [],
                'activities'       : [],
                'due'              : vm.dueDate
            });
 
            vm.board.lists.getById(vm.newCard.listId).idCards.push(newCardId);
 
            // Reset the newCard object
            vm.newCard = {
                name: '',
                listId: ''
            };
 
            closeDialog();
        }
 
        /**
         * Assign Due Date
         */
        function assignDueDate()
        {
            angular.forEach(vm.selectedCards, function (cardId)
            {
                vm.board.cards.getById(cardId).due = vm.dueDate;
            });
 
            vm.selectedCards = [];
 
            closeDialog();
        }
    }
})();