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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
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[]}
|
|
|
|
**/
|
|
|
|
let types = {};
|
2018-10-22 15:58:16 +03:00
|
|
|
|
2019-01-23 18:34:56 +03:00
|
|
|
export default {
|
2018-10-22 15:58:16 +03:00
|
|
|
/**
|
|
|
|
*
|
2019-01-23 18:34:56 +03:00
|
|
|
* @param type
|
|
|
|
* @param {TypeDefinition} typeDefinition
|
2018-10-22 15:58:16 +03:00
|
|
|
*/
|
2019-01-23 18:34:56 +03:00
|
|
|
registerType(type, typeDefinition) {
|
|
|
|
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() {
|
|
|
|
return Object.keys(types);
|
2018-10-22 15:58:16 +03:00
|
|
|
},
|
2019-01-23 18:34:56 +03:00
|
|
|
getIcon(type) {
|
2019-01-31 13:22:46 +03:00
|
|
|
return types[type].typeIconClass || '';
|
2018-10-22 15:58:16 +03:00
|
|
|
},
|
2019-01-23 18:34:56 +03:00
|
|
|
getLabel(type) {
|
|
|
|
return t('files_sharing', 'Link to a {label}', { label: types[type].typeString || type }, 1)
|
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 */
|
|
|
|
return typeof types[type] !== 'undefined' ? types[type].link(id) : '';
|
2018-10-22 15:58:16 +03:00
|
|
|
}
|
|
|
|
};
|