2019-09-25 19:19:42 +03:00
|
|
|
/**
|
2018-10-22 15:58:16 +03:00
|
|
|
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
|
|
|
|
*
|
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This 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.
|
|
|
|
*
|
|
|
|
* This program 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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-05 22:11:28 +03:00
|
|
|
import escapeHTML from 'escape-html'
|
|
|
|
|
2019-01-23 18:34:56 +03:00
|
|
|
/**
|
|
|
|
* @typedef TypeDefinition
|
|
|
|
* @method {callback} action This action is executed to let the user select a resource
|
|
|
|
* @param {string} icon Contains the icon css class for the type
|
|
|
|
* @constructor
|
|
|
|
*/
|
2018-10-22 15:58:16 +03:00
|
|
|
|
2019-01-23 18:34:56 +03:00
|
|
|
/**
|
|
|
|
* @type {TypeDefinition[]}
|
|
|
|
**/
|
2019-11-13 15:05:10 +03:00
|
|
|
const types = {}
|
2018-10-22 15:58:16 +03:00
|
|
|
|
2019-03-28 17:30:28 +03:00
|
|
|
/**
|
|
|
|
* Those translations will be used by the vue component but they should be shipped with the server
|
2019-06-07 11:27:09 +03:00
|
|
|
* FIXME: Those translations should be added to the library
|
2019-09-25 19:19:42 +03:00
|
|
|
* @returns {Array}
|
2019-03-28 17:30:28 +03:00
|
|
|
*/
|
2019-09-25 19:19:42 +03:00
|
|
|
export const l10nProjects = () => {
|
2019-06-07 11:27:09 +03:00
|
|
|
return [
|
|
|
|
t('core', 'Add to a project'),
|
|
|
|
t('core', 'Show details'),
|
|
|
|
t('core', 'Hide details'),
|
|
|
|
t('core', 'Rename project'),
|
|
|
|
t('core', 'Failed to rename the project'),
|
|
|
|
t('core', 'Failed to create a project'),
|
|
|
|
t('core', 'Failed to add the item to the project'),
|
|
|
|
t('core', 'Connect items to a project to make them easier to find'),
|
2019-11-13 15:05:10 +03:00
|
|
|
t('core', 'Type to search for existing projects'),
|
2019-09-25 19:19:42 +03:00
|
|
|
]
|
2019-06-07 11:27:09 +03:00
|
|
|
}
|
2019-03-28 17:30:28 +03:00
|
|
|
|
2019-01-23 18:34:56 +03:00
|
|
|
export default {
|
2018-10-22 15:58:16 +03:00
|
|
|
/**
|
|
|
|
*
|
2019-09-25 19:19:42 +03:00
|
|
|
* @param {string} type type
|
|
|
|
* @param {TypeDefinition} typeDefinition typeDefinition
|
2018-10-22 15:58:16 +03:00
|
|
|
*/
|
2019-01-23 18:34:56 +03:00
|
|
|
registerType(type, typeDefinition) {
|
2019-09-25 19:19:42 +03:00
|
|
|
types[type] = typeDefinition
|
2018-10-22 15:58:16 +03:00
|
|
|
},
|
2019-01-23 18:34:56 +03:00
|
|
|
trigger(type) {
|
|
|
|
return types[type].action()
|
2018-10-22 15:58:16 +03:00
|
|
|
},
|
2019-01-23 18:34:56 +03:00
|
|
|
getTypes() {
|
2019-09-25 19:19:42 +03:00
|
|
|
return Object.keys(types)
|
2018-10-22 15:58:16 +03:00
|
|
|
},
|
2019-01-23 18:34:56 +03:00
|
|
|
getIcon(type) {
|
2019-09-25 19:19:42 +03:00
|
|
|
return types[type].typeIconClass || ''
|
2018-10-22 15:58:16 +03:00
|
|
|
},
|
2019-01-23 18:34:56 +03:00
|
|
|
getLabel(type) {
|
2019-04-08 17:01:52 +03:00
|
|
|
return escapeHTML(types[type].typeString || type)
|
2018-10-22 15:58:16 +03:00
|
|
|
},
|
2019-01-23 18:34:56 +03:00
|
|
|
getLink(type, id) {
|
|
|
|
/* TODO: Allow action to be executed instead of href as well */
|
2019-09-25 19:19:42 +03:00
|
|
|
return typeof types[type] !== 'undefined' ? types[type].link(id) : ''
|
2019-11-13 15:05:10 +03:00
|
|
|
},
|
2019-09-25 19:19:42 +03:00
|
|
|
}
|