ext-php_savefile_chamilo.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. /*globals $, svgCanvas, svgEditor*/
  2. /*jslint regexp:true*/
  3. // TODO: Might add support for "exportImage" custom
  4. // handler as in "ext-server_opensave.js" (and in savefile.php)
  5. svgEditor.addExtension("php_savefile_chamilo", {
  6. callback: function() {
  7. 'use strict';
  8. function getFileNameFromTitle () {
  9. var title = svgCanvas.getDocumentTitle();
  10. return $.trim(title);
  11. }
  12. var save_svg_action = svgEditor.curConfig.extPath + 'savefile.php';
  13. svgEditor.setCustomHandlers({
  14. save: function(win, data) {
  15. var svg = '<?xml version="1.0" encoding="UTF-8"?>\n' + data,
  16. filename = getFileNameFromTitle();
  17. $.post(
  18. save_svg_action,
  19. {output_svg: svg, filename: filename}
  20. ).done(function(data) {
  21. var response = jQuery.parseJSON(data);
  22. console.log(response.message);
  23. alert(response.message);
  24. if (response.url != '') {
  25. window.top.location.href = response.url;
  26. }
  27. }
  28. );
  29. }
  30. });
  31. }
  32. });