2021-03-31 13:15:40 +03:00
|
|
|
/**
|
2019-01-29 12:15:46 +03:00
|
|
|
* @copyright 2018 Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
|
|
*
|
2021-03-31 13:15:40 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
|
|
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2019-01-29 12:15:46 +03:00
|
|
|
*
|
|
|
|
* @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
|
2021-03-31 13:15:40 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
2019-01-29 12:15:46 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
import $ from 'jquery'
|
|
|
|
|
|
|
|
import OC from '../OC'
|
|
|
|
|
|
|
|
const LIST = ''
|
|
|
|
+ '<div class="menu popovermenu menu-left hidden contactsmenu-popover">'
|
|
|
|
+ ' <ul>'
|
|
|
|
+ ' <li>'
|
|
|
|
+ ' <a>'
|
|
|
|
+ ' <span class="icon-loading-small"></span>'
|
|
|
|
+ ' </a>'
|
|
|
|
+ ' </li>'
|
|
|
|
+ ' </ul>'
|
2019-09-25 19:19:42 +03:00
|
|
|
+ '</div>'
|
2019-01-29 12:15:46 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
const entryTemplate = require('./contactsmenu/jquery_entry.handlebars')
|
2019-02-04 00:29:00 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
$.fn.contactsMenu = function(shareWith, shareType, appendTo) {
|
2019-01-29 12:15:46 +03:00
|
|
|
// 0 - user, 4 - email, 6 - remote
|
2019-11-13 15:05:10 +03:00
|
|
|
const allowedTypes = [0, 4, 6]
|
2019-01-29 12:15:46 +03:00
|
|
|
if (allowedTypes.indexOf(shareType) === -1) {
|
2019-09-25 19:19:42 +03:00
|
|
|
return
|
2019-01-29 12:15:46 +03:00
|
|
|
}
|
|
|
|
|
2019-11-13 15:05:10 +03:00
|
|
|
const $div = this
|
2019-09-25 19:19:42 +03:00
|
|
|
appendTo.append(LIST)
|
2019-11-13 15:05:10 +03:00
|
|
|
const $list = appendTo.find('div.contactsmenu-popover')
|
2019-01-29 12:15:46 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
$div.click(function() {
|
2019-01-29 12:15:46 +03:00
|
|
|
if (!$list.hasClass('hidden')) {
|
2019-09-25 19:19:42 +03:00
|
|
|
$list.addClass('hidden')
|
|
|
|
$list.hide()
|
|
|
|
return
|
2019-01-29 12:15:46 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
$list.removeClass('hidden')
|
|
|
|
$list.show()
|
2019-01-29 12:15:46 +03:00
|
|
|
|
|
|
|
if ($list.hasClass('loaded')) {
|
2019-09-25 19:19:42 +03:00
|
|
|
return
|
2019-01-29 12:15:46 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
$list.addClass('loaded')
|
2019-01-29 12:15:46 +03:00
|
|
|
$.ajax(OC.generateUrl('/contactsmenu/findOne'), {
|
|
|
|
method: 'POST',
|
|
|
|
data: {
|
2020-07-31 10:26:43 +03:00
|
|
|
shareType,
|
|
|
|
shareWith,
|
2019-11-13 15:05:10 +03:00
|
|
|
},
|
2019-09-25 19:19:42 +03:00
|
|
|
}).then(function(data) {
|
|
|
|
$list.find('ul').find('li').addClass('hidden')
|
2019-01-29 12:15:46 +03:00
|
|
|
|
2019-11-13 15:05:10 +03:00
|
|
|
let actions
|
2019-01-29 12:15:46 +03:00
|
|
|
if (!data.topAction) {
|
|
|
|
actions = [{
|
|
|
|
hyperlink: '#',
|
2019-11-13 15:05:10 +03:00
|
|
|
title: t('core', 'No action available'),
|
2019-09-25 19:19:42 +03:00
|
|
|
}]
|
2019-01-29 12:15:46 +03:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
actions = [data.topAction].concat(data.actions)
|
2019-01-29 12:15:46 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
actions.forEach(function(action) {
|
2020-11-10 11:50:46 +03:00
|
|
|
$list.find('ul').append(entryTemplate(action))
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2020-11-10 11:50:46 +03:00
|
|
|
|
|
|
|
$div.trigger('load')
|
2019-09-25 19:19:42 +03:00
|
|
|
}, function(jqXHR) {
|
|
|
|
$list.find('ul').find('li').addClass('hidden')
|
2019-01-29 12:15:46 +03:00
|
|
|
|
2019-11-13 15:05:10 +03:00
|
|
|
let title
|
2019-01-29 12:15:46 +03:00
|
|
|
if (jqXHR.status === 404) {
|
2019-09-25 19:19:42 +03:00
|
|
|
title = t('core', 'No action available')
|
2019-01-29 12:15:46 +03:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
title = t('core', 'Error fetching contact actions')
|
2019-01-29 12:15:46 +03:00
|
|
|
}
|
|
|
|
|
2020-11-10 11:50:46 +03:00
|
|
|
$list.find('ul').append(entryTemplate({
|
2019-01-29 12:15:46 +03:00
|
|
|
hyperlink: '#',
|
2020-07-31 10:26:43 +03:00
|
|
|
title,
|
2019-09-25 19:19:42 +03:00
|
|
|
}))
|
2020-11-10 11:50:46 +03:00
|
|
|
|
|
|
|
$div.trigger('loaderror', jqXHR)
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
|
|
|
})
|
2019-01-29 12:15:46 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
$(document).click(function(event) {
|
2019-11-13 15:05:10 +03:00
|
|
|
const clickedList = ($list.has(event.target).length > 0)
|
|
|
|
let clickedTarget = ($div.has(event.target).length > 0)
|
2019-01-29 12:15:46 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
$div.each(function() {
|
2019-01-29 12:15:46 +03:00
|
|
|
if ($(this).is(event.target)) {
|
2019-09-25 19:19:42 +03:00
|
|
|
clickedTarget = true
|
2019-01-29 12:15:46 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2019-01-29 12:15:46 +03:00
|
|
|
|
|
|
|
if (clickedList || clickedTarget) {
|
2019-09-25 19:19:42 +03:00
|
|
|
return
|
2019-01-29 12:15:46 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
$list.addClass('hidden')
|
|
|
|
$list.hide()
|
|
|
|
})
|
|
|
|
}
|