170 lines
8.2 KiB
JavaScript
170 lines
8.2 KiB
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
|
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
|
|
var _react = require('react');
|
|
|
|
var _react2 = _interopRequireDefault(_react);
|
|
|
|
var _reactstrap = require('reactstrap');
|
|
|
|
require('./animate.css');
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
|
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
|
|
var NotificationAlert = function (_React$Component) {
|
|
_inherits(NotificationAlert, _React$Component);
|
|
|
|
function NotificationAlert(props) {
|
|
_classCallCheck(this, NotificationAlert);
|
|
|
|
var _this = _possibleConstructorReturn(this, (NotificationAlert.__proto__ || Object.getPrototypeOf(NotificationAlert)).call(this, props));
|
|
|
|
_this.state = {
|
|
notifyTL: [],
|
|
notifyTC: [],
|
|
notifyTR: [],
|
|
notifyBL: [],
|
|
notifyBC: [],
|
|
notifyBR: []
|
|
};
|
|
_this.onDismiss = _this.onDismiss.bind(_this);
|
|
_this.notificationAlert = _this.notificationAlert.bind(_this);
|
|
return _this;
|
|
}
|
|
|
|
_createClass(NotificationAlert, [{
|
|
key: 'onDismiss',
|
|
value: function onDismiss(nNumber, place, noAnimate) {
|
|
|
|
var notify = [];
|
|
var sNotify = this.state["notify" + place.toUpperCase()];
|
|
var dNotify;
|
|
for (var i = 0; i < sNotify.length; i++) {
|
|
if (sNotify[i].key !== nNumber + "") {
|
|
if (sNotify[i].props.className.indexOf("fadeOutUp") !== -1) {
|
|
dNotify = _react2.default.cloneElement(sNotify[i]);
|
|
} else {
|
|
if (noAnimate === undefined) {
|
|
var animation;
|
|
if (place.indexOf("b") !== -1) {
|
|
animation = sNotify[i].key > nNumber + "" ? " animated moveDown" : "";
|
|
} else {
|
|
animation = sNotify[i].key > nNumber + "" ? " animated moveUp" : "";
|
|
}
|
|
dNotify = _react2.default.cloneElement(sNotify[i], { className: "alert-with-icon" + animation });
|
|
} else {
|
|
dNotify = _react2.default.cloneElement(sNotify[i], { className: "alert-with-icon" });
|
|
}
|
|
}
|
|
notify.push(dNotify);
|
|
} else {
|
|
if (noAnimate === undefined) {
|
|
dNotify = _react2.default.cloneElement(sNotify[i], { className: "alert-with-icon animated fadeOutUp" });
|
|
notify.push(dNotify);
|
|
}
|
|
}
|
|
}
|
|
if (noAnimate === undefined) {
|
|
setTimeout(function () {
|
|
this.onDismiss(nNumber, place, "noAnimate");
|
|
}.bind(this), 800);
|
|
}
|
|
sNotify = {};
|
|
sNotify["notify" + place.toUpperCase()] = notify;
|
|
this.setState(sNotify);
|
|
}
|
|
}, {
|
|
key: 'notificationAlert',
|
|
value: function notificationAlert(options) {
|
|
var _this2 = this;
|
|
|
|
var notify = this.state["notify" + options.place.toUpperCase()];
|
|
var nNumber = notify.length;
|
|
if (notify.length > 0) {
|
|
if (options.place.indexOf("b") !== -1) {
|
|
nNumber = parseInt(notify[0].key, 10) + 1;
|
|
} else {
|
|
nNumber = parseInt(notify[notify.length - 1].key, 10) + 1;
|
|
}
|
|
}
|
|
var notification = _react2.default.createElement(_reactstrap.Alert, { color: options.type, className: 'alert-with-icon animated fadeInDown', toggle: function toggle() {
|
|
return _this2.onDismiss(nNumber, options.place);
|
|
}, key: nNumber }, options.icon !== undefined ? _react2.default.createElement('span', { 'data-notify': 'icon', className: options.icon }) : null, _react2.default.createElement('span', { 'data-notify': 'message' }, options.message));
|
|
if (options.place.indexOf("b") !== -1) {
|
|
notify.unshift(notification);
|
|
} else {
|
|
notify.push(notification);
|
|
}
|
|
var sNotify = {};
|
|
sNotify["notify" + options.place.toUpperCase()] = notify;
|
|
// aici pui notify[notify.length-1].key
|
|
if (options.autoDismiss > 0) setTimeout(function () {
|
|
this.onDismiss(nNumber, options.place);
|
|
}.bind(this), options.autoDismiss * 1000 + (notify.length - 1) * 1000);
|
|
this.setState(sNotify);
|
|
}
|
|
}, {
|
|
key: 'showAllNotifications',
|
|
value: function showAllNotifications(place) {
|
|
if (this.state["notify" + place.toUpperCase()].length > 0) {
|
|
var style = { display: "inline-block", margin: "0px auto", position: "fixed", transition: "all 0.5s ease-in-out", zIndex: "1031" };
|
|
if (place.indexOf("t") !== -1) {
|
|
style["top"] = "20px";
|
|
switch (place) {
|
|
case "tl":
|
|
style["left"] = "20px";
|
|
break;
|
|
case "tc":
|
|
style["left"] = "0px";
|
|
style["right"] = "0px";
|
|
break;
|
|
case "tr":
|
|
style["right"] = "20px";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
} else {
|
|
style["bottom"] = "20px";
|
|
switch (place) {
|
|
case "bl":
|
|
style["left"] = "20px";
|
|
break;
|
|
case "bc":
|
|
style["left"] = "0px";
|
|
style["right"] = "0px";
|
|
break;
|
|
case "br":
|
|
style["right"] = "20px";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
return _react2.default.createElement(_reactstrap.Col, { xs: 11, sm: 4, style: style }, this.state["notify" + place.toUpperCase()].map(function (prop, key) {
|
|
return prop;
|
|
}));
|
|
}
|
|
}
|
|
}, {
|
|
key: 'render',
|
|
value: function render() {
|
|
return _react2.default.createElement('div', { ref: 'notifications' }, this.showAllNotifications("tl"), this.showAllNotifications("tc"), this.showAllNotifications("tr"), this.showAllNotifications("bl"), this.showAllNotifications("bc"), this.showAllNotifications("br"));
|
|
}
|
|
}]);
|
|
|
|
return NotificationAlert;
|
|
}(_react2.default.Component);
|
|
|
|
exports.default = NotificationAlert;
|