51 lines
1.9 KiB
JavaScript
51 lines
1.9 KiB
JavaScript
document.addEventListener('DOMContentLoaded', function () {
|
|
let currentKA = null;
|
|
|
|
// Listen for messages from the KB iframe
|
|
window.addEventListener('message', function(event) {
|
|
if (event.origin !== 'https://kb.jv.com') {
|
|
return;
|
|
}
|
|
|
|
if (event.data.type === 'ka-viewed') {
|
|
currentKA = event.data.kaNumber;
|
|
console.log('Current KA:', currentKA);
|
|
}
|
|
});
|
|
|
|
app.initialized()
|
|
.then(function (client) {
|
|
console.log('KB initialized');
|
|
|
|
document.getElementById('insert-ka-btn').addEventListener('click', function() {
|
|
if (!currentKA) {
|
|
client.interface.trigger('showNotify', {
|
|
type: 'warning',
|
|
message: 'No article selected. Please view an article first.'
|
|
});
|
|
return;
|
|
}
|
|
|
|
client.interface.trigger("setValue", {
|
|
id: "cf_ka_number",
|
|
value: currentKA
|
|
})
|
|
.then(function(data) {
|
|
return client.interface.trigger('showNotify', {
|
|
type: 'success',
|
|
message: currentKA + ' attached to ticket'
|
|
});
|
|
})
|
|
.catch(function(error) {
|
|
client.interface.trigger('showNotify', {
|
|
type: 'error',
|
|
message: 'Failed to attach KA#: ' + error.message
|
|
});
|
|
});
|
|
});
|
|
})
|
|
.catch(function(error) {
|
|
console.error('Failed to initialize app:', error);
|
|
document.body.innerHTML = '<p>Failed to load app. Please refresh.</p>';
|
|
});
|
|
}); |