issue.js 785 B

12345678910111213141516171819202122232425262728293031323334353637
  1. ready(function(){
  2. dom.get('#form-issue')
  3. .on('submit',function(e){
  4. var form = this,
  5. id = dom.get(form).get('[name=id]').value;
  6. global.settings.fetch.native = true;
  7. fetch(id===null?'./issue/complete':BASE_URL+'/issue/'+id+'/update',{
  8. method: 'post',
  9. body: new FormData(form),
  10. mode: 'cors',
  11. credentials: 'include'
  12. })
  13. .then(function(res){
  14. return res.json();
  15. })
  16. .then(function(data){
  17. if(data.error){
  18. if(data.error.message){
  19. alert(data.error.message);
  20. }else{
  21. alert(data.error);
  22. }
  23. }else{
  24. form.reset();
  25. location.assign(BASE_URL+'/!'+data.id);
  26. }
  27. })
  28. .catch(function(e){
  29. alert(e);
  30. });
  31. e.stopPropagation();
  32. if(e.cancelable){
  33. e.preventDefault();
  34. }
  35. return false;
  36. });
  37. });