@natlibfi/melinda-merge-ui-commons
Version:
Common modules for Melinda Merge UI application
231 lines (200 loc) • 21.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SubrecordActionButton = undefined;
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 _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _constants = require('../../constants');
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
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; } /**
*
* @licstart The following is the entire license notice for the JavaScript code in this file.
*
* UI for merging MARC records
*
* Copyright (C) 2015-2019 University Of Helsinki (The National Library Of Finland)
*
* This file is part of marc-merge-ui
*
* marc-merge-ui program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* marc-merge-ui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @licend The above is the entire license notice
* for the JavaScript code in this file.
*
*/
var SubrecordActionButton = exports.SubrecordActionButton = function (_React$Component) {
_inherits(SubrecordActionButton, _React$Component);
function SubrecordActionButton() {
_classCallCheck(this, SubrecordActionButton);
return _possibleConstructorReturn(this, (SubrecordActionButton.__proto__ || Object.getPrototypeOf(SubrecordActionButton)).apply(this, arguments));
}
_createClass(SubrecordActionButton, [{
key: 'componentDidUpdate',
value: function componentDidUpdate() {
window.$ && window.$(this._button).closeFAB();
}
}, {
key: 'selectAction',
value: function selectAction(type) {
var _this2 = this;
var _props = this.props,
rowId = _props.rowId,
onChangeAction = _props.onChangeAction;
return function () {
if (_this2.props.actionsEnabled) {
onChangeAction(rowId, type);
}
};
}
}, {
key: 'getIcon',
value: function getIcon(actionType) {
if (actionType === _constants.SubrecordActionTypes.BLOCK) return 'block';
if (actionType === _constants.SubrecordActionTypes.MERGE) return 'queue';
if (actionType === _constants.SubrecordActionTypes.COPY) return 'forward';
return 'more_vert';
}
}, {
key: 'getColor',
value: function getColor(actionType) {
if (actionType === _constants.SubrecordActionTypes.BLOCK) return 'red';
if (actionType === _constants.SubrecordActionTypes.MERGE) return 'green';
if (actionType === _constants.SubrecordActionTypes.COPY) return 'blue';
return 'yellow';
}
}, {
key: 'renderButton',
value: function renderButton(color, icon, onClickFn) {
var buttonClasses = (0, _classnames2.default)('btn-floating', color);
return _react2.default.createElement(
'a',
{ className: buttonClasses,
onClick: onClickFn },
_react2.default.createElement(
'i',
{ className: 'material-icons' },
icon
)
);
}
}, {
key: 'renderActionButton',
value: function renderActionButton(actionType) {
var color = this.getColor(actionType);
var icon = this.getIcon(actionType);
return this.renderButton(color, icon, this.selectAction(actionType));
}
}, {
key: 'renderUnsetButton',
value: function renderUnsetButton() {
return this.renderButton('yellow', 'more_vert', this.selectAction(_constants.SubrecordActionTypes.UNSET));
}
}, {
key: 'renderBlockButton',
value: function renderBlockButton() {
return this.renderButton('red', 'block', this.selectAction(_constants.SubrecordActionTypes.BLOCK));
}
}, {
key: 'renderMergeButton',
value: function renderMergeButton() {
return this.renderButton('green', 'queue', this.selectAction(_constants.SubrecordActionTypes.MERGE));
}
}, {
key: 'renderCopyButton',
value: function renderCopyButton() {
return this.renderButton('blue', 'forward', this.selectAction(_constants.SubrecordActionTypes.COPY));
}
}, {
key: 'isActionAvailable',
value: function isActionAvailable(actionType) {
var _props2 = this.props,
isMergeActionAvailable = _props2.isMergeActionAvailable,
isCopyActionAvailable = _props2.isCopyActionAvailable;
if (actionType === _constants.SubrecordActionTypes.COPY) return isCopyActionAvailable;
if (actionType === _constants.SubrecordActionTypes.MERGE) return isMergeActionAvailable;
return true;
}
}, {
key: 'render',
value: function render() {
var _this3 = this;
var _props3 = this.props,
selectedAction = _props3.selectedAction,
actionsEnabled = _props3.actionsEnabled;
var UNSET = _constants.SubrecordActionTypes.UNSET,
BLOCK = _constants.SubrecordActionTypes.BLOCK,
MERGE = _constants.SubrecordActionTypes.MERGE,
COPY = _constants.SubrecordActionTypes.COPY;
var buttons = [BLOCK, MERGE, COPY].filter(function (actionType) {
return _this3.isActionAvailable(actionType);
}).map(function (actionType) {
return actionType === selectedAction ? UNSET : actionType;
}).map(function (actionType) {
return _react2.default.createElement(
'li',
{ key: actionType },
_this3.renderActionButton(actionType)
);
});
var color = this.getColor(selectedAction);
var selectedIconClasses = (0, _classnames2.default)('btn-floating', 'btn-small', 'waves-light', 'subrecord-action-button', color, {
'disabled': !actionsEnabled,
'waves-effect': actionsEnabled
});
var containerClasses = (0, _classnames2.default)('subrecord-action-button-container', {
'fixed-action-btn': actionsEnabled,
'click-to-toggle': actionsEnabled,
'horizontal': actionsEnabled
});
return _react2.default.createElement(
'div',
{ className: containerClasses, ref: function ref(c) {
return _this3._button = c;
} },
_react2.default.createElement(
'a',
{ className: selectedIconClasses },
_react2.default.createElement(
'i',
{ className: 'large material-icons' },
this.getIcon(selectedAction)
)
),
actionsEnabled ? _react2.default.createElement(
'ul',
{ className: 'open-left' },
buttons
) : null
);
}
}]);
return SubrecordActionButton;
}(_react2.default.Component);
SubrecordActionButton.propTypes = {
rowId: _propTypes2.default.string.isRequired,
onChangeAction: _propTypes2.default.func.isRequired,
selectedAction: _propTypes2.default.string,
isMergeActionAvailable: _propTypes2.default.bool,
isCopyActionAvailable: _propTypes2.default.bool,
actionsEnabled: _propTypes2.default.bool
};
//# sourceMappingURL=subrecord-action-button.js.map