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
142
143
144
145
146
|
/**
* @copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @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/>.
*
*/
import _ from 'underscore'
import $ from 'jquery'
import OC from '../OC/index'
export function query(options) {
options = options || {}
const dismissOptions = options.dismiss || {}
$.ajax({
type: 'GET',
url: options.url || OC.linkToOCS('core', 2) + 'whatsnew?format=json',
success: options.success || function(data, statusText, xhr) {
onQuerySuccess(data, statusText, xhr, dismissOptions)
},
error: options.error || onQueryError,
})
}
export function dismiss(version, options) {
options = options || {}
$.ajax({
type: 'POST',
url: options.url || OC.linkToOCS('core', 2) + 'whatsnew',
data: { version: encodeURIComponent(version) },
success: options.success || onDismissSuccess,
error: options.error || onDismissError,
})
// remove element immediately
$('.whatsNewPopover').remove()
}
function onQuerySuccess(data, statusText, xhr, dismissOptions) {
console.debug('querying Whats New data was successful: ' + statusText)
console.debug(data)
if (xhr.status !== 200) {
return
}
let item, menuItem, text, icon
const div = document.createElement('div')
div.classList.add('popovermenu', 'open', 'whatsNewPopover', 'menu-left')
const list = document.createElement('ul')
// header
item = document.createElement('li')
menuItem = document.createElement('span')
menuItem.className = 'menuitem'
text = document.createElement('span')
text.innerText = t('core', 'New in') + ' ' + data.ocs.data.product
text.className = 'caption'
menuItem.appendChild(text)
icon = document.createElement('span')
icon.className = 'icon-close'
icon.onclick = function() {
dismiss(data.ocs.data.version, dismissOptions)
}
menuItem.appendChild(icon)
item.appendChild(menuItem)
list.appendChild(item)
// Highlights
for (const i in data.ocs.data.whatsNew.regular) {
const whatsNewTextItem = data.ocs.data.whatsNew.regular[i]
item = document.createElement('li')
menuItem = document.createElement('span')
menuItem.className = 'menuitem'
icon = document.createElement('span')
icon.className = 'icon-checkmark'
menuItem.appendChild(icon)
text = document.createElement('p')
text.innerHTML = _.escape(whatsNewTextItem)
menuItem.appendChild(text)
item.appendChild(menuItem)
list.appendChild(item)
}
// Changelog URL
if (!_.isUndefined(data.ocs.data.changelogURL)) {
item = document.createElement('li')
menuItem = document.createElement('a')
menuItem.href = data.ocs.data.changelogURL
menuItem.rel = 'noreferrer noopener'
menuItem.target = '_blank'
icon = document.createElement('span')
icon.className = 'icon-link'
menuItem.appendChild(icon)
text = document.createElement('span')
text.innerText = t('core', 'View changelog')
menuItem.appendChild(text)
item.appendChild(menuItem)
list.appendChild(item)
}
div.appendChild(list)
document.body.appendChild(div)
}
function onQueryError(x, t, e) {
console.debug('querying Whats New Data resulted in an error: ' + t + e)
console.debug(x)
}
function onDismissSuccess(data) {
// noop
}
function onDismissError(data) {
console.debug('dismissing Whats New data resulted in an error: ' + data)
}
|