v1.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace zin;
  3. require_once dirname(__DIR__) . DS . 'section' . DS . 'v1.php';
  4. /**
  5. * 历史记录部件类。
  6. * The history widget class.
  7. *
  8. * @author Hao Sun
  9. */
  10. class history extends wg
  11. {
  12. /**
  13. * @var mixed[]
  14. */
  15. protected static $defineProps = array
  16. (
  17. 'panel?: bool=true', // 是否渲染为面板。
  18. 'objectType?: string', // 操作对象类型。
  19. 'objectID?: int', // 操作对象 ID。
  20. 'actions?: array', // 操作列表数据。
  21. 'users?: array', // 用户 Map 数据。
  22. 'commentUrl?: string', // 备注对话框 URL。
  23. 'editCommentUrl?: string', // 修改备注对话框 URL。
  24. 'title?: string|array', // 标题。
  25. 'commentBtn?: string|array' // 是否允许添加备注。
  26. );
  27. public static function getPageCSS()
  28. {
  29. return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css');
  30. }
  31. public static function getPageJS()
  32. {
  33. return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js');
  34. }
  35. protected function onCheckErrors()
  36. {
  37. if(empty($this->prop('objectID'))) return array('The property "objectID" of widget "history" is undefined.');
  38. return null;
  39. }
  40. protected function created()
  41. {
  42. global $app, $lang;
  43. if(!$this->hasProp('title')) $this->setProp('title', $lang->history);
  44. if(!$this->hasProp('commentBtn'))
  45. {
  46. if(!isset($lang->action->create)) $app->loadLang('action');
  47. $this->setProp('commentBtn', $lang->action->create);
  48. }
  49. $objectType = $this->prop('objectType');
  50. $objectID = $this->prop('objectID');
  51. $users = $this->prop('users');
  52. $actions = $this->prop('actions');
  53. if(empty($objectType))
  54. {
  55. $objectType = data('objectType');
  56. if(empty($objectType)) $objectType = $app->rawModule;
  57. if($objectType == 'requirement' || $objectType == 'epic') $objectType = 'story';
  58. if($objectType == 'researchtask') $objectType = 'task';
  59. $this->setProp('objectType', $objectType);
  60. }
  61. if(empty($objectID))
  62. {
  63. $objectID = data($objectType . 'ID');
  64. if(empty($objectID))
  65. {
  66. $object = data($objectType);
  67. if(is_object($object) && isset($object->id)) $objectID = $object->id;
  68. elseif(is_array($object) && isset($object['id'])) $objectID = $object['id'];
  69. }
  70. $this->setProp('objectID', $objectID);
  71. }
  72. if(empty($users))
  73. {
  74. $users = data('users');
  75. $this->setProp('users', $users);
  76. }
  77. if(empty($actions))
  78. {
  79. static $actions;
  80. if(empty($actions))
  81. {
  82. $actions = data('actions');
  83. if(empty($actions) && !empty($objectID)) $actions = $app->loadTarget('action')->getList($objectType, (int)$objectID);
  84. if(!empty($actions)) $actions = $app->loadTarget('action')->buildActionList($actions, $users, (bool)$this->prop('commentBtn'));
  85. }
  86. $this->setProp('actions', $actions);
  87. }
  88. }
  89. protected function build()
  90. {
  91. list($panel, $objectID, $objectType, $title, $actions, $commentUrl, $editCommentUrl, $commentBtn) = $this->prop(array('panel', 'objectID', 'objectType', 'title', 'actions', 'commentUrl', 'editCommentUrl', 'commentBtn'));
  92. $canComment = hasPriv('action', 'comment', null);
  93. $canEditComment = hasPriv('action', 'editComment', null);
  94. $className = $this->props->class->toStr();
  95. if($panel && empty($className)) $className = 'canvas py-1 px-2 overflow-visible';
  96. $className .= ' break-all';
  97. global $lang, $app, $config;
  98. $app->control->loadModel('file');
  99. $previewLink = $downloadLink = '';
  100. $canDownload = common::hasPriv('file', 'download');
  101. $fileListProps = array();
  102. if($canDownload)
  103. {
  104. $previewLink = helper::createLink('file', 'download', "fileID={id}&mouse=left");
  105. $downloadLink = helper::createLink('file', 'download', "fileID={id}");
  106. $downloadLink .= strpos($downloadLink, '?') === false ? '?' : '&';
  107. $downloadLink .= session_name() . '=' . session_id();
  108. jsVar('previewLang', $lang->file->preview);
  109. jsVar('downloadLang', $lang->file->download);
  110. jsVar('previewLink', $previewLink);
  111. jsVar('downloadLink', $downloadLink);
  112. jsVar('libreOfficeTurnon', isset($config->file->libreOfficeTurnon) && $config->file->libreOfficeTurnon == 1);
  113. $fileListProps['fileUrl'] = $downloadLink;
  114. $fileListProps['hoverItemActions'] = true;
  115. $fileListProps['itemProps'] = array('target' => '_blank');
  116. $fileListProps['fileActions'] = jsCallback('file')->do('return getFileActions(file)');
  117. }
  118. return zui::historyPanel
  119. (
  120. set::className($className),
  121. set::objectID((int)$objectID),
  122. set::objectType($objectType),
  123. set::actions($actions),
  124. set::title($title),
  125. set::fileListProps($fileListProps),
  126. $canEditComment ? set::editCommentUrl($editCommentUrl) : null,
  127. $canComment ? set::commentUrl($commentUrl) : null,
  128. set::commentBtn($canComment && !common::isTutorialMode() ? $commentBtn : false),
  129. set($this->getRestProps())
  130. );
  131. }
  132. }