v1.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * 处理保存文档的操作请求,向服务器发送请求并返回保存的文档对象。
  3. * Handle the save doc operation request, send a request to the server and return the saved doc object.
  4. */
  5. function handleSaveDoc(doc)
  6. {
  7. const docApp = getDocApp();
  8. if(docApp.isSavingDoc) return;
  9. docApp.isSavingDoc = true;
  10. const url = $.createLink('weekly', 'edit', `reportID=${doc.id}`);
  11. const docData = {
  12. rawContent : doc.content,
  13. status : doc.status || 'normal',
  14. contentType: doc.contentType,
  15. type : 'text',
  16. title : doc.title,
  17. keywords : doc.keywords,
  18. content : doc.html,
  19. uid : (doc.uid || `doc${doc.id}`),
  20. };
  21. if(doc.fromVersion) docData.fromVersion = doc.fromVersion;
  22. return new Promise((resolve, reject) => {
  23. $.ajaxSubmit({'url': url, 'data': docData, 'load': false, 'onComplete': function(result)
  24. {
  25. docApp.isSavingDoc = false;
  26. resolve(result.newDoc);
  27. docApp.cancelEditDoc();
  28. }});
  29. });
  30. }
  31. window._setDocViwerOptions = window.setDocAppOptions;
  32. window.setDocAppOptions = function(_, options)
  33. {
  34. options = window._setDocViwerOptions(_, options);
  35. return $.extend(options,
  36. {
  37. onSaveDoc: handleSaveDoc
  38. });
  39. };