all files / src/components/modal/services/ osModal.ts

100% Statements 49/49
96.43% Branches 27/28
100% Functions 12/12
100% Lines 47/47
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  14× 14×   13× 13× 13× 13× 13× 13× 13×   54× 40×                       60× 14×          
"use strict";
var OsModalService = (function () {
    function OsModalService($mdDialog, $mdMedia) {
        this.$mdDialog = $mdDialog;
        this.$mdMedia = $mdMedia;
    }
    OsModalService.prototype.getDefaultOptions = function (options) {
        options.title = options.hasOwnProperty('title') ? options.title : '';
        options.textContent = options.hasOwnProperty('textContent') ? options.textContent : '';
        options.template = options.hasOwnProperty('template') ? options.template : require('html!../templates/default.html');
        options.ok = options.hasOwnProperty('ok') ? options.ok : 'OK';
        options.cancel = options.hasOwnProperty('cancel') ? options.cancel : 'Cancel';
        options.fullscreen = options.hasOwnProperty('fullscreen') ? options.fullscreen : true;
        return options;
    };
    OsModalService.prototype.prepareModalOptions = function (dialog, options) {
        angular.forEach(options, function (value, key) {
            if (angular.isFunction(dialog[key])) {
                dialog[key](value);
            }
        });
    };
    OsModalService.prototype.alert = function (options, display) {
        if (display === void 0) { display = true; }
        var params = this.getDefaultOptions(options);
        var modal = this.$mdDialog.alert();
        this.prepareModalOptions(modal, params);
        return display ? this.$mdDialog.show(modal) : modal;
    };
    OsModalService.prototype.confirm = function (options, display) {
        if (display === void 0) { display = true; }
        var params = this.getDefaultOptions(options);
        var modal = this.$mdDialog.confirm();
        this.prepareModalOptions(modal, params);
        return display ? this.$mdDialog.show(modal) : modal;
    };
    OsModalService.prototype.html = function (options) {
        var params = this.getDefaultOptions(options);
        if (options.controller) {
            params.controller = options.controller;
        }
        if (options.templateUrl) {
            params.templateUrl = options.templateUrl;
        }
        else Eif (options.template) {
            params.template = options.template;
        }
        return this.$mdDialog.show(params);
    };
    OsModalService.prototype.show = function (dialog) {
        return this.$mdDialog.show(dialog);
    };
    return OsModalService;
}());
exports.OsModalService = OsModalService;
var OsModal = (function () {
    function OsModal() {
        this.$get = ['$mdDialog', '$mdMedia', function ($mdDialog, $mdMedia) {
                return new OsModalService($mdDialog, $mdMedia);
            }];
    }
    return OsModal;
}());
exports.OsModal = OsModal;