model-mapping-configuration.js 2.4 KB
Newer Older
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
invoiceModule.directive('modelMappingConfiguration', ['$log', '$document', '$uibModal',
function ($log, $document, $uibModal) {
    'use strict';

    return {
        restrict: 'E',
        templateUrl: '/app/vat/output-invoice/model-mapping-configuration/model-mapping-configuration.html' + '?_=' + Math.random(),
        scope:
        { 
            isOpen: '=',
            parentElement: "@"
        },
        link: function (scope, element) {
            $log.debug('modelMappingConfiguration.ctor()...');

            scope.$watch('isOpen', function (newVal, oldVal) {
                if (newVal) {
                    scope.eventService.open();
                }
            });

            var parentElement = scope.parentElement
                ? $document[0].querySelector(scope.parentElement) : element[0];

            scope.eventService = {
                open: function () {
                    var modalInstance = $uibModal.open({
                        ariaLabelledBy: 'modal-title',
                        ariaDescribedBy: 'modal-body',
                        backdrop: 'static',
                        templateUrl: 'view-mapping-template.html',
                        controller: 'modelMappingConfigurationController',
                        windowClass: 'model-mapping-popup center-popup',
                        appendTo: angular.element(parentElement),
                        scope: scope
                    });
                },
                addOrEdit: function (refreshFunc, model) {
                    var modalInstance = $uibModal.open({
                        ariaLabelledBy: 'modal-title',
                        ariaDescribedBy: 'modal-body',
                        backdrop: 'static',
                        templateUrl: 'add-edit-mapping-template.html',
                        controller: 'modelMappingAddEditController',
                        windowClass: 'add-mapping-popup center-popup',
                        appendTo: angular.element(parentElement),
                        scope: scope,
                        resolve: {
                            refreshFunc: function () {
                                return refreshFunc;
                            },
                            model: function () {
                                return model;
                            }
                        }
                    });
                }
            };
        }
    };
}]);