all files / src/modal/ modalDialog.ui.tsx

54.79% Statements 40/73
27.59% Branches 8/29
37.04% Functions 10/27
56.52% Lines 39/69
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143                                                                                        10×                                                                                                                        
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var React = require('react');
var react_redux_1 = require('react-redux');
var Modal = require('./modalDialog.js');
var ModalDialog = (function (_super) {
    __extends(ModalDialog, _super);
    function ModalDialog(props) {
        _super.call(this, props);
        this.state = { screen: this.screenSize() };
    }
    ModalDialog.prototype.componentDidMount = function () {
        var _this = this;
        var $modal = $('.ui.modal.' + this.props.id);
        $modal.modal({
            detachable: false,
            closable: false,
            observeChanges: true,
            onApprove: function ($element) { return false; },
            onDeny: function ($element) { return false; },
            transition: "fade",
            onVisible: function () {
                // This is to update the Browser Scrollbar, at least needed in WebKit
                if (typeof document !== 'undefined') {
                    var n_1 = document.createTextNode(' ');
                    $modal.append(n_1);
                    setTimeout(function () {
                        n_1.parentNode.removeChild(n_1);
                    }, 0);
                }
            }
        });
        $(window).resize(function () {
            _this.setState({ screen: _this.screenSize() });
        });
    };
    ModalDialog.prototype.screenSize = function () {
        Eif (typeof window === 'undefined') {
            console.log("Running on nodeJS!");
            return {
                height: 500,
                width: 500
            };
        }
        return {
            height: window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight,
            width: window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth
        };
    };
    ModalDialog.prototype.onClick = function (e, action) {
        if (action.onClick(e)) {
            // Closing is done externally (by redux)
            this.props.closeDialog();
        }
    };
    ModalDialog.prototype.render = function () {
        var _this = this;
        var key = 0;
        var actions = this.props.actions.map(function (action) {
            return React.createElement("div", {key: key++, className: action.className, onClick: function (e) { return _this.onClick(e, action); }}, 
                action.label, 
                action.iconClass ? React.createElement("i", {className: action.iconClass}) : null);
        });
        var props = this.props;
        // TODO: realize Modals with React, then isOpen gets handy:
        //const isOpen = props.dialogState.dialogId == props.id && props.dialogState.isVisible;
        var height = this.state.screen.height;
        var width = this.state.screen.width;
        return React.createElement("div", {id: this.props.id, className: 'ui modal ' + this.props.id, style: { width: width - 80, top: 40, left: 40, margin: 1, minHeight: "500px" }}, 
            React.createElement("div", {className: "header"}, props.title), 
            this.props.dialogState.isVisible ?
                React.createElement("div", {className: "content", style: { overflowY: 'scroll', height: height - 300, minHeight: "500px" }}, 
                    this.props.dialogState.errors ?
                        this.props.dialogState.errors.map(function (message, i) {
                            return React.createElement(ModalUserMessageComponent, {key: i, userMessage: message});
                        })
                        : null, 
                    props.children)
                : null, 
            React.createElement("div", {className: "actions"}, actions));
    };
    return ModalDialog;
}(React.Component));
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = react_redux_1.connect(function (state, ownProps) {
    return {
        dialogState: state.modalDialog
    };
}, function (dispatch) {
    return {
        closeDialog: function () { return dispatch(Modal.closeModal()); }
    };
})(ModalDialog);
var ModalUserMessage = (function (_super) {
    __extends(ModalUserMessage, _super);
    function ModalUserMessage() {
        _super.apply(this, arguments);
    }
    ModalUserMessage.prototype.close = function () {
        this.props.close(this.props.userMessage);
    };
    ModalUserMessage.prototype.render = function () {
        var _this = this;
        var theme = "error";
        if (this.props.userMessage.kind === "info") {
            theme = "success";
        }
        if (this.props.userMessage.kind === "error") {
            theme = "error";
        }
        return React.createElement("div", {className: "slds-notify_container slds-is-relative slds-m-bottom--x-small"}, 
            React.createElement("div", {className: "slds-notify slds-notify--alert slds-theme--alert-texture slds-theme--" + theme, role: "alert"}, 
                React.createElement("button", {className: "slds-button slds-notify__close slds-button--icon-inverse", onClick: function () { return _this.close(); }}, 
                    React.createElement("svg", {"aria-hidden": "true", className: "slds-button__icon"}, 
                        React.createElement("use", {xlinkHref: "assets/icons/utility-sprite/svg/symbols.svg#close"})
                    ), 
                    React.createElement("span", {className: "slds-assistive-text"}, "Close")), 
                React.createElement("span", {className: "slds-assistive-text"}, this.props.userMessage.kind), 
                React.createElement("h2", null, this.props.userMessage.text))
        );
    };
    return ModalUserMessage;
}(React.Component));
var ModalUserMessageComponent = react_redux_1.connect(function (state, ownProps) {
    return {
        userMessage: ownProps.userMessage
    };
}, function (dispatch) {
    return {
        close: function (message) {
            dispatch(Modal.deleteUserMessage(message));
        }
    };
})(ModalUserMessage);