2019-01-29 16:50:05 +03:00
|
|
|
/**
|
|
|
|
* @copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
*
|
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later. See the COPYING file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import _ from 'underscore'
|
|
|
|
import $ from 'jquery'
|
|
|
|
|
|
|
|
import OC from '../OC/index'
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
export function query(options) {
|
|
|
|
options = options || {}
|
2019-11-13 15:05:10 +03:00
|
|
|
const dismissOptions = options.dismiss || {}
|
2019-01-29 16:50:05 +03:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: options.url || OC.linkToOCS('core', 2) + 'whatsnew?format=json',
|
2019-09-25 19:19:42 +03:00
|
|
|
success: options.success || function(data, statusText, xhr) {
|
|
|
|
onQuerySuccess(data, statusText, xhr, dismissOptions)
|
2019-01-29 16:50:05 +03:00
|
|
|
},
|
2019-11-13 15:05:10 +03:00
|
|
|
error: options.error || onQueryError,
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2019-01-29 16:50:05 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
export function dismiss(version, options) {
|
|
|
|
options = options || {}
|
2019-01-29 16:50:05 +03:00
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: options.url || OC.linkToOCS('core', 2) + 'whatsnew',
|
2019-09-25 19:19:42 +03:00
|
|
|
data: { version: encodeURIComponent(version) },
|
2019-01-29 16:50:05 +03:00
|
|
|
success: options.success || onDismissSuccess,
|
2019-11-13 15:05:10 +03:00
|
|
|
error: options.error || onDismissError,
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2019-01-29 16:50:05 +03:00
|
|
|
// remove element immediately
|
2019-09-25 19:19:42 +03:00
|
|
|
$('.whatsNewPopover').remove()
|
2019-01-29 16:50:05 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
function onQuerySuccess(data, statusText, xhr, dismissOptions) {
|
|
|
|
console.debug('querying Whats New data was successful: ' + statusText)
|
|
|
|
console.debug(data)
|
2019-01-29 16:50:05 +03:00
|
|
|
|
|
|
|
if (xhr.status !== 200) {
|
2019-09-25 19:19:42 +03:00
|
|
|
return
|
2019-01-29 16:50:05 +03:00
|
|
|
}
|
|
|
|
|
2019-11-13 15:05:10 +03:00
|
|
|
let item, menuItem, text, icon
|
2019-01-29 16:50:05 +03:00
|
|
|
|
2019-11-13 15:05:10 +03:00
|
|
|
const div = document.createElement('div')
|
2019-09-25 19:19:42 +03:00
|
|
|
div.classList.add('popovermenu', 'open', 'whatsNewPopover', 'menu-left')
|
2019-01-29 16:50:05 +03:00
|
|
|
|
2019-11-13 15:05:10 +03:00
|
|
|
const list = document.createElement('ul')
|
2019-01-29 16:50:05 +03:00
|
|
|
|
|
|
|
// header
|
2019-09-25 19:19:42 +03:00
|
|
|
item = document.createElement('li')
|
|
|
|
menuItem = document.createElement('span')
|
|
|
|
menuItem.className = 'menuitem'
|
|
|
|
|
|
|
|
text = document.createElement('span')
|
2020-07-31 10:31:39 +03:00
|
|
|
text.innerText = t('core', 'New in') + ' ' + data.ocs.data.product
|
2019-09-25 19:19:42 +03:00
|
|
|
text.className = 'caption'
|
|
|
|
menuItem.appendChild(text)
|
|
|
|
|
|
|
|
icon = document.createElement('span')
|
|
|
|
icon.className = 'icon-close'
|
|
|
|
icon.onclick = function() {
|
2020-07-31 10:31:39 +03:00
|
|
|
dismiss(data.ocs.data.version, dismissOptions)
|
2019-09-25 19:19:42 +03:00
|
|
|
}
|
|
|
|
menuItem.appendChild(icon)
|
2019-01-29 16:50:05 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
item.appendChild(menuItem)
|
|
|
|
list.appendChild(item)
|
2019-01-29 16:50:05 +03:00
|
|
|
|
|
|
|
// Highlights
|
2020-07-31 10:31:39 +03:00
|
|
|
for (const i in data.ocs.data.whatsNew.regular) {
|
|
|
|
const whatsNewTextItem = data.ocs.data.whatsNew.regular[i]
|
2019-09-25 19:19:42 +03:00
|
|
|
item = document.createElement('li')
|
2019-01-29 16:50:05 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
menuItem = document.createElement('span')
|
|
|
|
menuItem.className = 'menuitem'
|
2019-01-29 16:50:05 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
icon = document.createElement('span')
|
|
|
|
icon.className = 'icon-checkmark'
|
|
|
|
menuItem.appendChild(icon)
|
2019-01-29 16:50:05 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
text = document.createElement('p')
|
|
|
|
text.innerHTML = _.escape(whatsNewTextItem)
|
|
|
|
menuItem.appendChild(text)
|
2019-01-29 16:50:05 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
item.appendChild(menuItem)
|
|
|
|
list.appendChild(item)
|
2019-01-29 16:50:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Changelog URL
|
2020-07-31 10:31:39 +03:00
|
|
|
if (!_.isUndefined(data.ocs.data.changelogURL)) {
|
2019-09-25 19:19:42 +03:00
|
|
|
item = document.createElement('li')
|
2019-01-29 16:50:05 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
menuItem = document.createElement('a')
|
2020-07-31 10:31:39 +03:00
|
|
|
menuItem.href = data.ocs.data.changelogURL
|
2019-09-25 19:19:42 +03:00
|
|
|
menuItem.rel = 'noreferrer noopener'
|
|
|
|
menuItem.target = '_blank'
|
2019-01-29 16:50:05 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
icon = document.createElement('span')
|
|
|
|
icon.className = 'icon-link'
|
|
|
|
menuItem.appendChild(icon)
|
2019-01-29 16:50:05 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
text = document.createElement('span')
|
|
|
|
text.innerText = t('core', 'View changelog')
|
|
|
|
menuItem.appendChild(text)
|
2019-01-29 16:50:05 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
item.appendChild(menuItem)
|
|
|
|
list.appendChild(item)
|
2019-01-29 16:50:05 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
div.appendChild(list)
|
|
|
|
document.body.appendChild(div)
|
2019-01-29 16:50:05 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
function onQueryError(x, t, e) {
|
|
|
|
console.debug('querying Whats New Data resulted in an error: ' + t + e)
|
|
|
|
console.debug(x)
|
2019-01-29 16:50:05 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
function onDismissSuccess(data) {
|
|
|
|
// noop
|
2019-01-29 16:50:05 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
function onDismissError(data) {
|
|
|
|
console.debug('dismissing Whats New data resulted in an error: ' + data)
|
|
|
|
}
|