all files / src/dashboard/ importExportDialog.ui.js

60.78% Statements 31/51
44.44% Branches 4/9
43.75% Functions 7/16
62.5% Lines 30/48
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                                                                                                                                                     
/* 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 Import = require('./import');
var modalDialog_ui_1 = require('../modal/modalDialog.ui');
var react_1 = require("react");
var ImportExportDialog = (function (_super) {
    __extends(ImportExportDialog, _super);
    function ImportExportDialog(props) {
        _super.call(this, props);
        this.state = { state: null };
    }
    ImportExportDialog.prototype.componentWillReceiveProps = function (nextProps) {
        //this.refs.data.value = Import.serialize(nextProps.state);
    };
    ImportExportDialog.prototype.componentDidMount = function () {
    };
    ImportExportDialog.prototype._loadData = function () {
        this.refs.data.value = Import.serialize(this.props.state);
        this.refs.data.focus();
        this.refs.data.select();
    };
    ImportExportDialog.prototype._clearData = function () {
        this.refs.data.value = "";
        this.refs.data.focus();
        this.refs.data.select();
    };
    ImportExportDialog.prototype._exportToClipboard = function () {
        this.refs.data.focus();
        this.refs.data.select();
        try {
            var successful = document.execCommand('copy');
            var msg = successful ? 'successful' : 'unsuccessful';
            console.log('Copying text command was ' + msg);
        }
        catch (err) {
            alert('Oops, unable to copy');
        }
    };
    ImportExportDialog.prototype.render = function () {
        var _this = this;
        var props = this.props;
        var actions = [
            {
                className: "ui right black button",
                label: "Close",
                onClick: function () { return true; }
            },
            {
                className: "ui right labeled icon positive button",
                iconClass: "folder open icon",
                label: "Import",
                onClick: function () {
                    props.doImport(_this.refs.data.value);
                    return true;
                }
            }
        ];
        return React.createElement(modalDialog_ui_1.default, {id: "dashboard-import-export-dialog", title: "Import / Export Dashboard", actions: actions}, 
            React.createElement("div", {className: "ui one column grid"}, 
                React.createElement("div", {className: "column"}, 
                    React.createElement("button", {className: "ui compact labeled icon button", onClick: this._loadData.bind(this)}, 
                        React.createElement("i", {className: "refresh icon"}), 
                        "Load Data"), 
                    React.createElement("button", {className: "ui compact labeled icon button", onClick: this._exportToClipboard.bind(this)}, 
                        React.createElement("i", {className: "upload icon"}), 
                        "Copy to Clipboard"), 
                    React.createElement("button", {className: "ui compact labeled icon button", onClick: this._clearData.bind(this)}, 
                        React.createElement("i", {className: "erase icon"}), 
                        "Clear Data")), 
                React.createElement("div", {className: "column"}, 
                    React.createElement("form", {className: "ui form"}, 
                        React.createElement("div", {className: "field"}, 
                            React.createElement("label", null, "Data"), 
                            React.createElement("textarea", {className: "monospace", ref: "data", rows: "10", onFocus: function (e) { return e.target.select(); }, placeholder: 'Click "Load Data" to get data for export or paste your data here ...'}))
                    )
                ))
        );
    };
    return ImportExportDialog;
}(React.Component));
ImportExportDialog.propTypes = {
    state: react_1.PropTypes.object,
    doImport: react_1.PropTypes.func.isRequired
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = react_redux_1.connect(function (state) {
    return {
        state: state
    };
}, function (dispatch) {
    return {
        doImport: function (state) { return dispatch(Import.doImport(state)); }
    };
})(ImportExportDialog);