').html(t(OCA.Onlyoffice.AppName, 'Provide advanced document permissions using ONLYOFFICE Docs')).prependTo($el)
+ }
+
+ if (templateItem) {
+ callback()
+ return
+ }
+
+ $.get(OC.filePath(OCA.Onlyoffice.AppName, 'templates', 'share.html'),
+ function(tmpl) {
+ templateItem = $(tmpl)
+
+ callback()
+ })
+ }
+
+ const render = function() {
+ getTemplate(() => {
+ collection.forEach(extra => {
+ const itemNode = templateItem.clone()
+ const descNode = itemNode.find('span')
+ const avatar = itemNode.find('img')
+ const actionButton = itemNode.find('#onlyoffice-share-action')
+
+ let avatarSrc = '/index.php/avatar/' + extra.shareWith + '/32?v=0'
+ let label = extra.shareWithName
+ if (extra.type === OC.Share.SHARE_TYPE_GROUP
+ || extra.type === OC.Share.SHARE_TYPE_ROOM) {
+ avatarSrc = '/index.php/avatar/guest/' + extra.shareWith + '/32?v=0'
+ label = extra.shareWith + ' (' + t(OCA.Onlyoffice.AppName, 'group') + ')'
+ }
+
+ if (extra.type === OC.Share.SHARE_TYPE_ROOM) {
+ label = extra.shareWith + ' (' + t(OCA.Onlyoffice.AppName, 'conversation') + ')'
+ }
+
+ if (extra.type === OC.Share.SHARE_TYPE_LINK) {
+ label = t(OCA.Onlyoffice.AppName, 'Share link')
+
+ const avatarWrapper = itemNode.find('.avatardiv')
+ avatarWrapper.addClass('onlyoffice-share-link-avatar')
+
+ avatarSrc = '/core/img/actions/public.svg'
+ }
+
+ actionButton.click(onClickPermissionMenu)
+
+ avatar[0].src = avatarSrc
+ descNode[0].innerText = label
+
+ itemNode[0].id = extra.share_id
+
+ getContainer().append(itemNode)
+ })
+ })
+ }
+
+ const onClickSetPermissions = function(e) {
+ const permissionValues = permissionsMenu.getValues()
+ const shareId = permissionsMenu.getTargetId()
+ const fileId = fileInfo.id
+ const extra = collection.find(item => item.share_id === shareId)
+
+ let permissions = OCA.Onlyoffice.Permissions.None
+ if (permissionValues[OCA.Onlyoffice.Permissions.Review]) {
+ permissions |= OCA.Onlyoffice.Permissions.Review
+ }
+ if (permissionValues[OCA.Onlyoffice.Permissions.Comment]
+ && (permissions & OCA.Onlyoffice.Permissions.Review) !== OCA.Onlyoffice.Permissions.Review
+ && (permissions & OCA.Onlyoffice.Permissions.ModifyFilter) !== OCA.Onlyoffice.Permissions.ModifyFilter) {
+ permissions |= OCA.Onlyoffice.Permissions.Comment
+ }
+ if (permissionValues[OCA.Onlyoffice.Permissions.FillForms]
+ && (permissions & OCA.Onlyoffice.Permissions.Review) !== OCA.Onlyoffice.Permissions.Review) {
+ permissions |= OCA.Onlyoffice.Permissions.FillForms
+ }
+ if (permissionValues[OCA.Onlyoffice.Permissions.ModifyFilter]
+ && (permissions & OCA.Onlyoffice.Permissions.Comment) !== OCA.Onlyoffice.Permissions.Comment) {
+ permissions |= OCA.Onlyoffice.Permissions.ModifyFilter
+ }
+
+ permissionsMenu.block(true)
+ OCA.Onlyoffice.SetShares(extra.id, shareId, fileId, permissions, (extra) => {
+ collection.forEach(item => {
+ if (item.share_id === extra.share_id) {
+ item.id = extra.id
+ item.permissions = extra.permissions
+ item.available = extra.available
+ }
+ })
+
+ const attributes = getPermissionAttributes(extra)
+
+ permissionsMenu.refresh(attributes)
+ permissionsMenu.block(false)
+ })
+ }
+
+ const listenOuterClicks = function(event) {
+ if (event.target.id === 'onlyoffice-share-action') {
+ return
+ }
+ const target = document.querySelector('#onlyoffice-share-popup-menu')
+ if (target) {
+ const eventPath = event.composedPath().includes(target)
+ if (!eventPath && typeof (permissionsMenu) !== 'undefined' && permissionsMenu.isOpen()) {
+ permissionsMenu.close()
+ }
+ }
+ }
+
+ const onClickPermissionMenu = function(e) {
+ if (!permissionsMenu) {
+ permissionsMenu = getPermissionMenu()
+ }
+ window.addEventListener('click', listenOuterClicks)
+
+ const shareNode = $(e.target).closest('.onlyoffice-share-item')[0]
+ const shareId = shareNode.id
+
+ if (permissionsMenu.isOpen()) {
+ const previousId = permissionsMenu.getTargetId()
+ permissionsMenu.close()
+
+ if (previousId === shareId) return
+ }
+
+ const extra = collection.find(item => item.share_id === shareId)
+
+ const attributes = getPermissionAttributes(extra)
+
+ permissionsMenu.open(extra.share_id, attributes, $(e.target).position())
+ }
+
+ const getCustomEvents = function() {
+ let init = false
+
+ return {
+ on() {
+ if (!init) {
+ $('#content').on('click', function(e) {
+ const target = $(e.target)[0]
+ if (!permissionsMenu
+ || !permissionsMenu.isOpen()
+ || target.id === 'onlyoffice-share-action'
+ || target.className === 'onlyoffice-share-label'
+ || target.closest('.onlyoffice-share-action')) {
+ return
+ }
+
+ permissionsMenu.close()
+ })
+
+ init = true
+ }
+ },
+ }
+ }
+
+ const getPermissionAttributes = function(extra) {
+ const attributes = []
+
+ if (format.review
+ && (OCA.Onlyoffice.Permissions.Review & extra.available) === OCA.Onlyoffice.Permissions.Review) {
+ const review = (OCA.Onlyoffice.Permissions.Review & extra.permissions) === OCA.Onlyoffice.Permissions.Review
+ attributes.push({
+ checked: review,
+ extra: OCA.Onlyoffice.Permissions.Review,
+ label: t(OCA.Onlyoffice.AppName, 'Review only'),
+ })
+ }
+ if (format.comment
+ && (OCA.Onlyoffice.Permissions.Comment & extra.available) === OCA.Onlyoffice.Permissions.Comment) {
+ const comment = (OCA.Onlyoffice.Permissions.Comment & extra.permissions) === OCA.Onlyoffice.Permissions.Comment
+ attributes.push({
+ checked: comment,
+ extra: OCA.Onlyoffice.Permissions.Comment,
+ label: t(OCA.Onlyoffice.AppName, 'Comment only'),
+ })
+ }
+ if (format.fillForms
+ && (OCA.Onlyoffice.Permissions.FillForms & extra.available) === OCA.Onlyoffice.Permissions.FillForms) {
+ const fillForms = (OCA.Onlyoffice.Permissions.FillForms & extra.permissions) === OCA.Onlyoffice.Permissions.FillForms
+ attributes.push({
+ checked: fillForms,
+ extra: OCA.Onlyoffice.Permissions.FillForms,
+ label: t(OCA.Onlyoffice.AppName, 'Form filling'),
+ })
+ }
+
+ if (format.modifyFilter
+ && (OCA.Onlyoffice.Permissions.ModifyFilter & extra.available) === OCA.Onlyoffice.Permissions.ModifyFilter) {
+ const modifyFilter = (OCA.Onlyoffice.Permissions.ModifyFilter & extra.permissions) === OCA.Onlyoffice.Permissions.ModifyFilter
+ attributes.push({
+ checked: modifyFilter,
+ extra: OCA.Onlyoffice.Permissions.ModifyFilter,
+ label: t(OCA.Onlyoffice.AppName, 'Global filter'),
+ })
+ }
+
+ return attributes
+ }
+
+ const getPermissionMenu = function() {
+ const popup = $('
', {
+ class: 'popovermenu onlyoffice-share-popup',
+ id: 'onlyoffice-share-popup-menu',
+ }).append($('
'), {
+ id: -1,
+ })
+
+ const appendItem = function(checked, extra, name) {
+ const item = $('- ').append($('', {
+ class: 'onlyoffice-share-action',
+ }).append($('', {
+ id: 'extra-' + extra,
+ type: 'checkbox',
+ class: 'checkbox action-checkbox__checkbox focusable',
+ checked,
+ })).append($('
-