cvgen.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. function onReady()
  14. {
  15. construct_reglages();
  16. }
  17. function generate()
  18. {
  19. var reg = get_regs();
  20. reg.leftbar=get_cats();
  21. reg.main=get_conts();
  22. return reg;
  23. }
  24. function test()
  25. {
  26. console.log(JSON.stringify(generate()));
  27. //send_post(generate());
  28. var blob = new Blob([JSON.stringify(generate())], {type: "application/*"});
  29. saveAs(blob, "cv.json");
  30. }
  31. function fill_ui(data)
  32. {
  33. if(typeof data == "string") data=JSON.parse(data);
  34. info_open(data.leftbar);
  35. regs_open(data);
  36. cont_open(data.main);
  37. load_json();
  38. }
  39. function submitForm()
  40. {
  41. console.log("submit event");
  42. var fd = new FormData(document.getElementById("fileinfo"));
  43. //fd.append("label", "WEBUPLOAD");
  44. $.ajax({
  45. url: "server/ping.php",
  46. type: "POST",
  47. data: fd,
  48. processData: false, // tell jQuery not to process the data
  49. contentType: false // tell jQuery not to set contentType
  50. }).done(function( data ) {
  51. fill_ui(data);
  52. });
  53. return false;
  54. }
  55. function submitFormImage()
  56. {
  57. console.log("submit event image");
  58. var obj = generate();
  59. var fd = new FormData(document.getElementById("fileinfoimage"));
  60. fd.append("json", JSON.stringify(obj));
  61. fd.append("img", "cv/"+obj.photo);
  62. $.ajax({
  63. url: "server/archive.php",
  64. type: "POST",
  65. data: fd,
  66. processData: false,
  67. contentType: false,
  68. async: false
  69. }).done(function( data ) {
  70. var a = document.getElementById('a1');
  71. a.href = "data:application/x-tgz;base64,"+data;
  72. a.click();
  73. });
  74. return false;
  75. }
  76. function load_json()
  77. {
  78. if($('#button_open').html()=="Importer")
  79. {
  80. $('#button_open').html("Annuler");
  81. $('#input_open').removeClass('hidden');
  82. }
  83. else
  84. {
  85. $('#button_open').html("Importer");
  86. $('#input_open').addClass('hidden');
  87. }
  88. }
  89. function toggle_distribe()
  90. {
  91. if($('#button_distrib').html()=="Distribuer")
  92. {
  93. $('#button_distrib').html("Annuler");
  94. $('#input_open_image').removeClass('hidden');
  95. }
  96. else
  97. {
  98. $('#button_distrib').html("Distribuer");
  99. $('#input_open_image').addClass('hidden');
  100. }
  101. }
  102. $( document ).ready(onReady);