v1.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * 获取附件的操作按钮。
  3. * Get file actions.
  4. */
  5. window.getDeliverableFileActions = function(file, deliverable)
  6. {
  7. let actions = [];
  8. /* 可以预览的文件。 */
  9. if(['txt', 'jpg', 'jpeg', 'gif', 'png', 'bmp', 'mp4'].includes(file.extension) && canDownload && typeof file.id != 'undefined')
  10. {
  11. actions[0] = {icon: 'eye', key: 'view', url: $.createLink('file', 'download', `fileID=${file.id}&mouse=left`), 'data-toggle' : 'modal', 'data-size' : 'lg'};
  12. }
  13. if(canDownload && typeof file.id != 'undefined') actions[1] = {icon: 'download', key: 'download', url: $.createLink('file', 'download', 'id=' + file.id), target: '_blank'};
  14. if(!onlyShow)
  15. {
  16. actions[2] = {icon: 'edit', key: 'rename'};
  17. if(!isTemplate) actions[3] = {icon: 'trash', key: 'delete'};
  18. }
  19. return actions;
  20. }
  21. /**
  22. * 获取文档的操作按钮。
  23. * Get file actions.
  24. */
  25. window.getDocActions = function(doc, deliverable)
  26. {
  27. let actions = [];
  28. const url = $.createLink('doc', 'view', `docID=${doc.id}`);
  29. if(isTemplate)
  30. {
  31. if(doc.canView) actions[0] = {icon: 'eye', key: 'view', url, target: '_blank'};
  32. }
  33. else
  34. {
  35. actions[0] = {icon: 'eye', key: 'view', url, target: '_blank'};
  36. if(doc.editable) actions[1] = {icon: 'edit', key: 'rename'};
  37. if(deliverable?.status == 'draft' && deliverable?.review == 0) actions[2] = {icon: 'trash', key: 'delete'};
  38. }
  39. return actions;
  40. }
  41. /**
  42. * 获取交付物的操作按钮。
  43. * Get deliverable actions.
  44. */
  45. window.getDeliverableActions = function(deliverable, category)
  46. {
  47. let actions = [];
  48. if(isTemplate)
  49. {
  50. actions[0] = {text: addFile, icon: 'file', key: 'selectFile'}; // 后台交付物只有上传文件操作。
  51. }
  52. else
  53. {
  54. if(canCreateDoc) actions[0] = {text: createDoc, icon: 'doc', key: 'createDoc', 'onClick' : () => showBtnModal(deliverable, category)}; // 前台交付物有三个创建文档的操作。
  55. }
  56. return actions;
  57. }
  58. window.showBtnModal = function(deliverable, category)
  59. {
  60. const actions = [];
  61. const btnClass = config.clientLang == 'en' ? 'btn btn-sm btn-primary w-36' : 'btn btn-sm btn-primary w-28';
  62. actions.push(`<div class="flex flex-row gap-4 justify-center items-center h-20">`);
  63. actions.push(`<a class="${btnClass}" target='_blank' href="${createDocUrl}"><i class="icon icon-doc"></i>${createDoc}</a>`);
  64. actions.push(`<a class="${btnClass}" data-toggle="modal" href="${uploadDocUrl}"><i class="icon icon-file"></i>${uploadFile}</a>`);
  65. if(typeof category.template != 'undefined' && category.template.length > 0)
  66. {
  67. actions.push(`<button class="${btnClass}" data-toggle="dropdown"><i class="icon icon-plus"></i>${createByTemplate} <span class="caret"></span></button>`);
  68. actions.push(`<menu class="dropdown-menu menu">`);
  69. for(const template of category.template)
  70. {
  71. actions.push(`<li class="menu-item"><a href="${template.url}" target="_blank">${template.text}</a></li>`);
  72. }
  73. actions.push(`</menu>`);
  74. }
  75. actions.push(`</div>`);
  76. zui.Modal.open({
  77. id: 'createDoc',
  78. title: createDoc,
  79. type: 'custom',
  80. size: 'sm',
  81. content: {html: actions.join('')},
  82. });
  83. }