summaryrefslogtreecommitdiffstats
path: root/lib/redmine/wiki_formatting/textile/helper.rb
blob: b4fe7f089e29d5d941411e0124a880f0c008c306 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# frozen_string_literal: true

# Redmine - project management software
# Copyright (C) 2006-  Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

module Redmine
  module WikiFormatting
    module Textile
      module Helper
        def wikitoolbar_for(field_id, preview_url = preview_text_path)
          heads_for_wiki_formatter
          # Is there a simple way to link to a public resource?
          url = "#{Redmine::Utils.relative_url_root}/help/#{current_language.to_s.downcase}/wiki_syntax_textile.html"
          javascript_tag(
            "var wikiToolbar = new jsToolBar(document.getElementById('#{field_id}')); " \
              "wikiToolbar.setHelpLink('#{escape_javascript url}'); " \
              "wikiToolbar.setPreviewUrl('#{escape_javascript preview_url}'); wikiToolbar.draw();"
          )
        end

        def initial_page_content(page)
          "h1. #{@page.pretty_title}"
        end

        def heads_for_wiki_formatter
          unless @heads_for_wiki_formatter_included
            toolbar_language_options = User.current && User.current.pref.toolbar_language_options
            lang =
              if toolbar_language_options.nil?
                UserPreference::DEFAULT_TOOLBAR_LANGUAGE_OPTIONS
              else
                toolbar_language_options.split(',')
              end
            content_for :header_tags do
              javascript_include_tag('jstoolbar/jstoolbar') +
              javascript_include_tag('jstoolbar/textile') +
              javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
              javascript_tag(
                "var wikiImageMimeTypes = #{Redmine::MimeType.by_type('image').to_json};" \
                  "var userHlLanguages = #{lang.to_json};") +
              stylesheet_link_tag('jstoolbar')
            end
            @heads_for_wiki_formatter_included = true
          end
        end
      end
    end
  end
end
option value='backport/46307/stable29'>backport/46307/stable29 Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/apps/comments/src/filesplugin.js
blob: 45d7372dfc7e14756c44f6687fc2d7d5fafca8fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
 * Copyright (c) 2016 Vincent Petry <pvince81@owncloud.com>
 *
 * @author Joas Schilling <coding@schilljs.com>
 * @author John Molakvoæ <skjnldsv@protonmail.com>
 * @author Michael Jobst <mjobst+github@tecratech.de>
 * @author Roeland Jago Douma <roeland@famdouma.nl>
 * @author Vincent Petry <vincent@nextcloud.com>
 *
 * @license AGPL-3.0-or-later
 *
 * 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/>.
 *
 */

(function() {

	_.extend(OC.Files.Client, {
		PROPERTY_COMMENTS_UNREAD: '{' + OC.Files.Client.NS_OWNCLOUD + '}comments-unread',
	})

	OCA.Comments = _.extend({}, OCA.Comments)
	if (!OCA.Comments) {
		/**
		 * @namespace
		 */
		OCA.Comments = {}
	}

	/**
	 * @namespace
	 */
	OCA.Comments.FilesPlugin = {
		ignoreLists: [
			'trashbin',
			'files.public',
		],

		_formatCommentCount(count) {
			return OCA.Comments.Templates.filesplugin({
				count,
				countMessage: n('comments', '%n unread comment', '%n unread comments', count),
				iconUrl: OC.imagePath('core', 'actions/comment'),
			})
		},

		attach(fileList) {
			const self = this
			if (this.ignoreLists.indexOf(fileList.id) >= 0) {
				return
			}

			const oldGetWebdavProperties = fileList._getWebdavProperties
			fileList._getWebdavProperties = function() {
				const props = oldGetWebdavProperties.apply(this, arguments)
				props.push(OC.Files.Client.PROPERTY_COMMENTS_UNREAD)
				return props
			}

			fileList.filesClient.addFileInfoParser(function(response) {
				const data = {}
				const props = response.propStat[0].properties
				const commentsUnread = props[OC.Files.Client.PROPERTY_COMMENTS_UNREAD]
				if (!_.isUndefined(commentsUnread) && commentsUnread !== '') {
					data.commentsUnread = parseInt(commentsUnread, 10)
				}
				return data
			})

			fileList.$el.addClass('has-comments')
			const oldCreateRow = fileList._createRow
			fileList._createRow = function(fileData) {
				const $tr = oldCreateRow.apply(this, arguments)
				if (fileData.commentsUnread) {
					$tr.attr('data-comments-unread', fileData.commentsUnread)
				}
				return $tr
			}

			// register "comment" action for reading comments
			fileList.fileActions.registerAction({
				name: 'Comment',
				displayName(context) {
					if (context && context.$file) {
						const unread = parseInt(context.$file.data('comments-unread'), 10)
						if (unread >= 0) {
							return n('comments', '1 new comment', '{unread} new comments', unread, { unread })
						}
					}
					return t('comments', 'Comment')
				},
				mime: 'all',
				order: -140,
				iconClass: 'icon-comment',
				permissions: OC.PERMISSION_READ,
				type: OCA.Files.FileActions.TYPE_INLINE,
				render(actionSpec, isDefault, context) {
					const $file = context.$file
					const unreadComments = $file.data('comments-unread')
					if (unreadComments) {
						const $actionLink = $(self._formatCommentCount(unreadComments))
						context.$file.find('a.name>span.fileactions').append($actionLink)
						return $actionLink
					}
					return ''
				},
				actionHandler(fileName, context) {
					context.$file.find('.action-comment').tooltip('hide')
					// open sidebar in comments section
					OCA.Files.Sidebar.setActiveTab('comments')
					OCA.Files.Sidebar.open(context.dir + '/' + fileName)
				},
			})

			// add attribute to "elementToFile"
			const oldElementToFile = fileList.elementToFile
			fileList.elementToFile = function($el) {
				const fileInfo = oldElementToFile.apply(this, arguments)
				const commentsUnread = $el.data('comments-unread')
				if (commentsUnread) {
					fileInfo.commentsUnread = commentsUnread
				}
				return fileInfo
			}
		},
	}

})()

OC.Plugins.register('OCA.Files.FileList', OCA.Comments.FilesPlugin)