v1.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace zin;
  3. require_once dirname(__DIR__) . DS . 'label' . DS . 'v1.php';
  4. require_once dirname(__DIR__) . DS . 'statuslabel' . DS . 'v1.php';
  5. require_once dirname(__DIR__) . DS . 'branchlabel' . DS . 'v1.php';
  6. require_once dirname(__DIR__) . DS . 'storylist' . DS . 'v1.php';
  7. class twinsStoryList extends storyList
  8. {
  9. /**
  10. * @var mixed[]
  11. */
  12. protected static $defineProps = array
  13. (
  14. 'story' => '?object', // 被关联的需求。
  15. 'relievedBtn' => '?array|bool', // 取消关联按钮。
  16. 'relievedTip' => '?string', // 取消关联提示信息。
  17. 'branches' => '?array' // 分支数据。
  18. );
  19. /**
  20. * @var mixed[]
  21. */
  22. protected static $defaultProps = array
  23. (
  24. 'name' => 'twins-story-list'
  25. );
  26. public static function getPageJS()
  27. {
  28. return <<<'JS'
  29. window.unlinkTwins = function(e)
  30. {
  31. const $this = $(e.target).closest('li').find('.relievedTwins');
  32. const $ul = $this.closest('ul');
  33. const postData = new FormData();
  34. postData.append('twinID', $this.data('id'));
  35. zui.Modal.confirm({message: window.relievedTip || $ul.data('relievedTip'), icon:'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x'}).then((res) =>
  36. {
  37. if(!res) return;
  38. $.post($.createLink('story', 'ajaxRelieveTwins'), postData, function()
  39. {
  40. $this.closest('li').remove();
  41. if($ul.find('li').length == 0) $ul.closest('.section').remove();
  42. });
  43. });
  44. };
  45. JS;
  46. }
  47. /**
  48. * @var object|null
  49. */
  50. protected $story;
  51. /**
  52. * @var null|mixed[]|bool
  53. */
  54. protected $relievedBtn = null;
  55. /**
  56. * @var mixed[]|null
  57. */
  58. protected $branches;
  59. protected function beforeBuild()
  60. {
  61. parent::beforeBuild();
  62. $story = $this->prop('story');
  63. if(!$story) $story = data('story');
  64. $branches = $this->prop('branches');
  65. if(!$branches) $branches = data('branches');
  66. $relievedBtn = $this->prop('relievedBtn');
  67. if($relievedBtn === null) $relievedBtn = hasPriv('story', 'relieved');
  68. $this->story = $story;
  69. $this->branches = $branches;
  70. $this->relievedBtn = $relievedBtn;
  71. }
  72. /**
  73. * @param object $story
  74. */
  75. protected function getItem($story)
  76. {
  77. global $lang;
  78. $item = parent::getItem($story);
  79. $relievedBtn = $this->relievedBtn;
  80. if(!isset($item['leading'])) $item['leading'] = array();
  81. if(isset($this->branches[$story->branch]))
  82. {
  83. if(!is_array($item['leading'])) $item['leading'] = array($item['leading']);
  84. $item['leading'] = array_merge(array(branchLabel::create($story->branch, $this->branches[$story->branch]), $item['leading']));
  85. }
  86. $item['content'] = statusLabel::create($story->status, $lang->story->statusList[$story->status], setClass('flex-none'));
  87. $item['titleClass'] = 'gap-2 items-center min-w-0 text-clip';
  88. if($relievedBtn)
  89. {
  90. $btn = array
  91. (
  92. 'class' => ($this->compact ? 'relievedTwins text-primary opacity-0 group-hover:opacity-100' : 'relievedTwins primary-pale'),
  93. 'icon' => 'unlink',
  94. 'data-id' => $story->id,
  95. 'data-on' => 'click',
  96. 'data-params' => 'event',
  97. 'data-call' => 'unlinkTwins',
  98. 'hint' => $lang->story->relievedTwins
  99. );
  100. if(is_array($relievedBtn)) $btn = array_merge($btn, $relievedBtn);
  101. if(!isset($item['actions'])) $item['actions'] = array();
  102. $item['actions'][] = $btn;
  103. }
  104. return $item;
  105. }
  106. protected function build()
  107. {
  108. $list = parent::build();
  109. if($this->relievedBtn)
  110. {
  111. global $lang;
  112. $relievedTip = $this->prop('relievedTip');
  113. if($relievedTip === null) $relievedTip = $lang->story->relievedTip;
  114. $list->add(setData('relievedTip', $relievedTip));
  115. }
  116. return $list;
  117. }
  118. }