2018-02-03 22:45:53 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
2018-03-26 23:04:00 +03:00
|
|
|
|
2018-02-03 22:45:53 +03:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a new CommentsModifyMenuinstance
|
|
|
|
* @constructs CommentsModifyMenu
|
|
|
|
* @memberof OC.Comments
|
2018-10-24 17:24:16 +03:00
|
|
|
* @private
|
2018-02-03 22:45:53 +03:00
|
|
|
*/
|
2019-11-13 15:05:10 +03:00
|
|
|
const CommentsModifyMenu = OC.Backbone.View.extend({
|
2018-02-03 22:45:53 +03:00
|
|
|
tagName: 'div',
|
|
|
|
className: 'commentsModifyMenu popovermenu bubble menu',
|
|
|
|
_scopes: [
|
|
|
|
{
|
|
|
|
name: 'edit',
|
2019-09-25 19:19:42 +03:00
|
|
|
displayName: t('comments', 'Edit comment'),
|
2019-11-13 15:05:10 +03:00
|
|
|
iconClass: 'icon-rename',
|
2018-02-03 22:45:53 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'delete',
|
|
|
|
displayName: t('comments', 'Delete comment'),
|
2019-11-13 15:05:10 +03:00
|
|
|
iconClass: 'icon-delete',
|
|
|
|
},
|
2018-02-03 22:45:53 +03:00
|
|
|
],
|
2020-07-31 10:26:43 +03:00
|
|
|
initialize() {
|
2018-02-03 22:45:53 +03:00
|
|
|
|
|
|
|
},
|
|
|
|
events: {
|
2019-11-13 15:05:10 +03:00
|
|
|
'click a.action': '_onClickAction',
|
2018-02-03 22:45:53 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler whenever an action has been clicked within the menu
|
|
|
|
*
|
|
|
|
* @param {Object} event event object
|
|
|
|
*/
|
2020-07-31 10:26:43 +03:00
|
|
|
_onClickAction(event) {
|
2019-11-13 15:05:10 +03:00
|
|
|
let $target = $(event.currentTarget)
|
2018-02-03 22:45:53 +03:00
|
|
|
if (!$target.hasClass('menuitem')) {
|
2019-09-25 19:19:42 +03:00
|
|
|
$target = $target.closest('.menuitem')
|
2018-02-03 22:45:53 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
OC.hideMenus()
|
2018-03-26 23:04:00 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
this.trigger('select:menu-item-clicked', event, $target.data('action'))
|
2018-02-03 22:45:53 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the menu with the currently set items
|
|
|
|
*/
|
2020-07-31 10:26:43 +03:00
|
|
|
render() {
|
2020-07-31 10:31:39 +03:00
|
|
|
this.$el.html(OCA.Comments.Templates.commentsmodifymenu({
|
2019-11-13 15:05:10 +03:00
|
|
|
items: this._scopes,
|
2019-09-25 19:19:42 +03:00
|
|
|
}))
|
2018-02-03 22:45:53 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the menu
|
2019-09-25 19:19:42 +03:00
|
|
|
* @param {Event} context the click event
|
2018-02-03 22:45:53 +03:00
|
|
|
*/
|
2020-07-31 10:26:43 +03:00
|
|
|
show(context) {
|
2019-09-25 19:19:42 +03:00
|
|
|
this._context = context
|
2018-02-03 22:45:53 +03:00
|
|
|
|
2019-11-13 15:05:10 +03:00
|
|
|
for (const i in this._scopes) {
|
2019-09-25 19:19:42 +03:00
|
|
|
this._scopes[i].active = false
|
2018-02-03 22:45:53 +03:00
|
|
|
}
|
|
|
|
|
2019-11-13 15:05:10 +03:00
|
|
|
const $el = $(context.target)
|
|
|
|
const offsetIcon = $el.offset()
|
|
|
|
const offsetContainer = $el.closest('.authorRow').offset()
|
2018-02-03 22:45:53 +03:00
|
|
|
|
|
|
|
// adding some extra top offset to push the menu below the button.
|
2019-11-13 15:05:10 +03:00
|
|
|
const position = {
|
2018-02-03 22:45:53 +03:00
|
|
|
top: offsetIcon.top - offsetContainer.top + 48,
|
|
|
|
left: '',
|
2019-11-13 15:05:10 +03:00
|
|
|
right: '',
|
2019-09-25 19:19:42 +03:00
|
|
|
}
|
2018-02-03 22:45:53 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
position.left = offsetIcon.left - offsetContainer.left
|
2018-02-03 22:45:53 +03:00
|
|
|
|
|
|
|
if (position.left > 200) {
|
|
|
|
// we need to position the menu to the right.
|
2019-09-25 19:19:42 +03:00
|
|
|
position.left = ''
|
|
|
|
position.right = this.$el.closest('.comment').find('.date').width()
|
|
|
|
this.$el.removeClass('menu-left').addClass('menu-right')
|
2018-02-03 22:45:53 +03:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
this.$el.removeClass('menu-right').addClass('menu-left')
|
2018-02-03 22:45:53 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
this.$el.css(position)
|
|
|
|
this.render()
|
|
|
|
this.$el.removeClass('hidden')
|
2018-02-03 22:45:53 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
OC.showMenu(null, this.$el)
|
2019-11-13 15:05:10 +03:00
|
|
|
},
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2018-02-03 22:45:53 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
OCA.Comments = OCA.Comments || {}
|
|
|
|
OCA.Comments.CommentsModifyMenu = CommentsModifyMenu
|
|
|
|
})(OC, OCA)
|