Open ebergu78 opened 4 weeks ago
Hi @ebergu78
It does not appear to be possible to add a Watcher by editing the issue. Adding a Watcher is a separate interface.
The REST API may be used to add the Watcher itself.
However, it is going to be complicated.
Thanks.
Hi @onozaty
I have modified my code .. shows the fail message and adds the watcher (?) any idea to fix it? thank you for your support
// Path pattern: /issues/ // Head of all pages
$(function() {
$('#issue-form input[type="submit"]') .on('click', function(event) {
var trackerId = $('#issue_tracker_id').val(); var issueId = ViewCustomize.context.issue.id;
switch(trackerId) { case '26': case '28':
$.ajax({
type: 'POST',
url: '/issues/' + issueId + '/watchers.json',
headers: {
'X-Redmine-API-Key': ViewCustomize.context.user.apiKey
},
dataType: 'text',
contentType: 'application/json',
data: JSON.stringify(
{'user_id': 27}
)
})
.done(function(data) {
location.reload();
})
.fail(function(data) {
alert('Verificar Seguidores');
});
break;
} }); });
Hi @ebergu78
Is REST web service enabled?
hi @onozaty :)
The REST web service is enabled In fact, the code adds the watcher to the issue after displaying the fail alert.
1- I edit the issue 2- I click on “submit”. 3- This code runs and shows the fail alert. 4- Successful update 5- The watcher was added to the issue
Thanks for your time
I am concerned about the content of the dataType
specification.
Try changing dataType: 'text',
to dataType: 'json',
.
Thanks.
If I change the type, the code still shows the alert :( (on Redmine version 5.0.2.stable)
this code works:
$(function() { $('#issue-form').on('submit', function(event) { var trackerId = $('#issue_tracker_id').val(); var issueId = ViewCustomize.context.issue.id;
// Ejecutar AJAX después del envío del formulario
setTimeout(function() {
switch(trackerId) {
case '26':
case '28':
$.ajax({
type: 'POST',
url: '/issues/' + issueId + '/watchers.json',
headers: {
'X-Redmine-API-Key': ViewCustomize.context.user.apiKey
},
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({
'user_id': 27
})
})
.done(function(data) {
// Watcher agregado correctamente, recargar la página
location.reload(); // Recargar la página para reflejar los cambios
})
.fail(function(jqXHR, textStatus, errorThrown) {
// Si hay error en agregar el watcher
alert('Agregar a "xxxx" como Seguidor: ' + textStatus + ' - ' + errorThrown);
console.log(jqXHR.responseText);
});
break;
}
}, 1); // Tiempo de espera para asegurarse de que el formulario se haya enviado completamente
}); });
What is the nature of the error? I would like to know the information in the alert and console.log.
jqXHR.responseText -> undefined
What does the alert dialog show?
alert('Agregar a xxxxx como Seguidor: ' + textStatus + ' -errorThrown: [' + errorThrown + '] -jqXHR: [' + jqXHR.responseText + ']');
the alert dialog shows:
Thank you very much. I tried a similar code and did not encounter any errors.
I am a little concerned about the error at the end of the console log. Since it seems to be occurring on line 366, could you please confirm what the process is in the relevant section?
Thanks.
I disabled another js code that was running and I set the default "theme" It still shows the alert but does not show errors or warnings in the console :( Thank you for your concern and help
Can you tell me the entire code again? Also, can you tell me the Insert Position?
Path pattern /issues/
Project pattern
Insertion position Head of all pages
Type JavaScript
Code
$(function() {
$('#issue-form').on('submit', function(event) {
var trackerId = $('#issue_tracker_id').val();
var issueId = ViewCustomize.context.issue.id;
// setTimeout(function() {
switch(trackerId) {
case '26':
case '28':
$.ajax({
type: 'POST',
url: '/issues/' + issueId + '/watchers.json',
headers: {
'X-Redmine-API-Key': ViewCustomize.context.user.apiKey
},
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({
'user_id': 27
})
})
.done(function(data) {
// Watcher agregado correctamente, recargar la página
location.reload(); // Recargar la página para reflejar los cambios
})
.fail(function(jqXHR, textStatus, errorThrown) {
// Si hay error en agregar el watcher
alert('Agregar a xxxxx como Seguidor: ' + textStatus + ' -errorThrown: [' + errorThrown + '] -jqXHR: [' + jqXHR.responseText + ']');
console.log('LOG: ' + jqXHR.responseText);
});
break;
}
// }, 1); //con setTimeout, funciona!!!
});
});
No errors occurred, but I was concerned that it was reloading at the same time it was submitting. What would happen if I do the following?
$(function() {
$('#issue-form').on('submit', async function(event) {
var trackerId = $('#issue_tracker_id').val();
var issueId = ViewCustomize.context.issue.id;
// setTimeout(function() {
switch(trackerId) {
case '26':
case '28':
await new Promise((resolve, reject) => {
$.ajax({
type: 'POST',
url: '/issues/' + issueId + '/watchers.json',
headers: {
'X-Redmine-API-Key': ViewCustomize.context.user.apiKey
},
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({
'user_id': 15
})
})
.done(function(data) {
// Watcher agregado correctamente, recargar la página
resolve();
})
.fail(function(jqXHR, textStatus, errorThrown) {
// Si hay error en agregar el watcher
reject('Agregar a xxxxx como Seguidor: ' + textStatus + ' -errorThrown: [' + errorThrown + '] -jqXHR: [' + jqXHR.responseText + ']');
});
}).catch(err => alert(err));
break;
}
// }, 1); //con setTimeout, funciona!!!
});
});
1) after updating the code ...
2) watcher added - ok! ... I'm forced to show the alert or use the timeout thanks for your help If there is nothing else to try, you can close the issue, thanks
Hi @onozaty :)
I need add a group as a watcher when editing a issue and when the tracker is changed $('#issue_watcher_user_ids_15 input').prop('checked', true); -> doesn't work when editing a issue :(
the HTML structure is different ...
Can you help me? thank you
I need ->