projects.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. function manageProject(id){
  2. window.location.href = "/projects/edit.php?p=" + id;
  3. }
  4. function deleteProject(id, title){
  5. dialog("confirm", "Delete project", "Do you really want to delete the project '" + title + "'?<br/><br/>There is no way to undo this action. You can also unpublish the project instead of deleting it.", function (confirmed) {
  6. if (confirmed) {
  7. var xmlhttp;
  8. if (window.XMLHttpRequest){
  9. xmlhttp = new XMLHttpRequest();
  10. }
  11. xmlhttp.onreadystatechange=function(){
  12. if (xmlhttp.readyState == 4){
  13. if (xmlhttp.status == 200){
  14. location.reload();
  15. }
  16. else{
  17. dialog("alert", "ERROR", "Error deleting the project '" + title + "'.", null);
  18. }
  19. }
  20. }
  21. xmlhttp.open("GET","/projects/delete.php?p=" + id, true);
  22. xmlhttp.send();
  23. }
  24. });
  25. }
  26. function deleteVersion(id, title){
  27. dialog("confirm", "Delete version", "Do you really want to delete the version '" + title + "'?<br/><br/>There is no way to undo this action. You can also unpublish the version instead of deleting it.", function (confirmed) {
  28. if (confirmed) {
  29. var xmlhttp;
  30. if (window.XMLHttpRequest){
  31. xmlhttp = new XMLHttpRequest();
  32. }
  33. xmlhttp.onreadystatechange=function(){
  34. if (xmlhttp.readyState == 4){
  35. if (xmlhttp.status == 200){
  36. location.reload();
  37. }
  38. else{
  39. dialog("alert", "ERROR", "Error deleting the version '" + title + "'.", null);
  40. }
  41. }
  42. }
  43. xmlhttp.open("GET","/projects/deleteversion.php?v=" + id, true);
  44. xmlhttp.send();
  45. }
  46. });
  47. }
  48. function deleteComment(id){
  49. dialog("confirm", "Delete version", "Do you really want to delete this comment?<br/><br/>There is no way to undo this action. You can also disapprove the comment instead of deleting it.", function (confirmed) {
  50. if (confirmed) {
  51. var xmlhttp;
  52. if (window.XMLHttpRequest){
  53. xmlhttp = new XMLHttpRequest();
  54. }
  55. xmlhttp.onreadystatechange=function(){
  56. if (xmlhttp.readyState == 4){
  57. if (xmlhttp.status == 200){
  58. location.reload();
  59. }
  60. else{
  61. dialog("alert", "ERROR", "Error deleting the comment.", null);
  62. }
  63. }
  64. }
  65. xmlhttp.open("GET","/projects/deletecomment.php?i=" + id, true);
  66. xmlhttp.send();
  67. }
  68. });
  69. }
  70. function visibleProject(id, title, visible){
  71. var xmlhttp;
  72. if (window.XMLHttpRequest){
  73. xmlhttp = new XMLHttpRequest();
  74. }
  75. xmlhttp.onreadystatechange=function(){
  76. if (xmlhttp.readyState == 4){
  77. if (xmlhttp.status == 200){
  78. location.reload();
  79. }
  80. else{
  81. dialog("alert", "ERROR", "Error changing visibility of the project '" + title + "'.", null);
  82. }
  83. }
  84. }
  85. xmlhttp.open("GET","/projects/visible.php?p=" + id + "&v=" + visible, true);
  86. xmlhttp.send();
  87. }
  88. function selectIcon(){
  89. document.getElementById("icon_file").click();
  90. }
  91. function changeIcon(event, title){
  92. console.log("changeIcon 1");
  93. var frame = document.getElementById("icon");
  94. var file = event.target.files[0];
  95. var reader = new FileReader();
  96. var httpPost = new XMLHttpRequest();
  97. console.log("changeIcon 2");
  98. reader.onloadend = function() {
  99. console.log("changeIcon LOADEND 1");
  100. console.log('RESULT', reader.result);
  101. var data = "image=IVV" + reader.result;
  102. var path = "/projects/uploadimage.php?name=" + title + "-icon.png";
  103. console.log("changeIcon LOADEND 2");
  104. httpPost.open("POST", path, true);
  105. console.log("changeIcon LOADEND 3");
  106. httpPost.setRequestHeader('Content-Type', 'x-www-form-urlencoded');
  107. httpPost.setRequestHeader("Content-length", data.length);
  108. console.log("changeIcon LOADEND 4");
  109. httpPost.send(data);
  110. console.log("changeIcon LOADEND 5 - END");
  111. }
  112. console.log("changeIcon 3");
  113. var b64 = reader.readAsDataURL(file);
  114. //var b64 = reader.result;
  115. console.log("changeIcon 4");
  116. httpPost.onreadystatechange = function(err) {
  117. console.log("changeIcon REQCHANGE");
  118. if (httpPost.readyState == 4 && httpPost.status == 200){
  119. console.log("changeIcon REQOK");
  120. frame.src = window.URL.createObjectURL(event.target.files[0]);
  121. console.log(httpPost.responseText);
  122. }
  123. else {
  124. console.log("changeIcon REQ-ERROR");
  125. console.log(err);
  126. }
  127. };
  128. console.log("changeIcon 5 - END");
  129. }