ajaxgetbugs.html.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <?php include $app->getModuleRoot() . 'common/view/header.lite.html.php';?>
  2. <?php js::set('repoLang', $lang->repo);?>
  3. <?php js::set('bugIDList', $bugIDList);?>
  4. <?php js::set('reviewComments', $comments);?>
  5. <?php js::set('contentError', $lang->repo->error->commentText);?>
  6. <?php js::import($jsRoot . '/zui/tabs/tabs.min.js');?>
  7. <div id='reviewBugs'>
  8. <div class="modal-header detail-title tabs-navbar">
  9. <div class="btn btn-left pull-left"><i class="icon icon-chevron-left"></i></div>
  10. <div class="btn close close-bugs pull-right"><i class="icon icon-close"></i></div>
  11. <div class="btn btn-right pull-right"><i class="icon icon-chevron-right"></i></div>
  12. <ul class="nav nav-tabs bug-tabs">
  13. <?php $index = 0;?>
  14. <?php foreach($bugs as $bug):?>
  15. <li <?php if($index ==0) echo 'class="active"';?>>
  16. <a href="###" data-target="#repoViewBug<?php echo $bug->id;?>" data-toggle="tab"><?php echo $bug->title;?></a>
  17. </li>
  18. <?php $index++;?>
  19. <?php endforeach;?>
  20. </ul>
  21. </div>
  22. <div class='review-bug-list'>
  23. <div id="bugAccordion" class="tab-content">
  24. <?php $index = 0;?>
  25. <?php foreach($bugs as $bug):?>
  26. <div class="tab-pane fade bug-view <?php echo $index == 0 ? 'active in' : '';?>" id="repoViewBug<?php echo $bug->id;?>">
  27. <div class="with-padding nobr bug-user">
  28. <span><?php echo html::smallAvatar(zget($users, $bug->openedBy));?></span>
  29. <span class='strong'><?php echo isset($users[$bug->openedBy]) ? $users[$bug->openedBy]->realname : $bug->openedBy;?></span>
  30. <div class="text-muted"><?php echo sprintf($lang->repo->dateTmpl, $bug->openedDate);?></div>
  31. </div>
  32. <div class="with-padding">
  33. <span><?php echo $lang->repo->issueTitle;?></span>
  34. <span class='strong'><?php echo $bug->title;?></span>
  35. </div>
  36. <?php if($bug->steps):?>
  37. <div class="with-padding">
  38. <span><?php echo $lang->repo->issueDesc;?></span>
  39. <div class='strong bug-detail'><?php echo $bug->steps;?></div>
  40. <div class='detail-unfold text-center'><?php echo $lang->repo->expand . ' ';?><i class='icon icon-caret-down'></i></div>
  41. </div>
  42. <?php endif;?>
  43. <div class="with-padding">
  44. <div class='tabs'>
  45. <ul class='nav nav-tabs'>
  46. <li class='active'><a href='#legendComment<?php echo $bug->id;?>' data-toggle='tab' class='bug-comment<?php echo $bug->id;?>'><?php echo $lang->repo->comment;?>(<span>0</span>)</a></li>
  47. </ul>
  48. <?php if(common::hasPriv('repo', 'addComment')):?>
  49. <div class='tab-content'>
  50. <div class='tab-pane active' id='legendComment<?php echo $bug->id;?>'>
  51. <p>
  52. <form class='commentForm not-watch' data-bugID="<?php echo $bug->id;?>" method='post' action='<?php echo $commentUrl?>' id='commentForm'>
  53. <textarea name='comment' class='commentText form-control mgb-10' spellcheck='false' placeholder='<?php echo $lang->repo->notice->commentContent?>'></textarea>
  54. <input class='commentSubmit btn btn-sm btn-primary pull-right' type='submit' value='<?php echo $lang->repo->submit?>'>
  55. <input type='hidden' name='objectID' value='<?php echo $bug->id;?>'>
  56. <div class='optional'></div>
  57. </form>
  58. </p>
  59. </div>
  60. </div>
  61. <?php endif;?>
  62. </div>
  63. </div>
  64. <div class="with-padding hidden comment-list">
  65. <p class='detail-title bug-comment<?php echo $bug->id;?>'><span>0</span><?php echo $lang->repo->commentNum;?></p>
  66. <div id="reviewComment<?php echo $bug->id;?>"></div>
  67. </div>
  68. </div>
  69. <?php $index++;?>
  70. <?php endforeach;?>
  71. </div>
  72. </div>
  73. </div>
  74. <div id="commentTemp" class="hidden">
  75. <div class='comment-block'>
  76. <div class='comment-user'>
  77. <span class="avatar %imgClass% avatar-circle avatar-sm pull-left">%avatar%</span>
  78. <strong class="realname">%realname%</strong>
  79. </div>
  80. <div class='comment-desc' id="comment-%commentID%">
  81. <div class='comment-content' title="%comment%">%comment%</div>
  82. <div class="comment-form-div hidden">
  83. <form method="post" class="comment-edit-form not-watch" action="<?php echo $this->createLink('repo', 'editComment', 'commentID=%commentID%');?>">
  84. <textarea name="commentText" class="commentInput form-control mgb-10">%comment%</textarea>
  85. <button type="submit" class="btn btn-sm btn-primary commentEditSubmit"><?php echo $lang->repo->submit;?></button>
  86. <button type="button" class="btn btn-sm commentEditCancel"><?php echo $lang->cancel;?></button>
  87. </form>
  88. </div>
  89. </div>
  90. <div>
  91. <span class='text-muted comment-date'>
  92. <span class='date'>%date%</span>
  93. </span>
  94. <?php if(common::hasPriv('repo', 'editComment')):?>
  95. <a href='javascript:;' class='edit commentEdit pull-right text-muted' data-id="%commentID%">
  96. <i class='icon icon-edit'></i>
  97. </a>
  98. <?php endif;?>
  99. </div>
  100. </div>
  101. </div>
  102. <script>
  103. /**
  104. * Set comment block.
  105. *
  106. * @param int bugID
  107. * @param object comment
  108. * @param object user
  109. * @access public
  110. * @return void
  111. */
  112. function setCommentBlock(bugID, comment, user)
  113. {
  114. var $commentBlock = $('#commentTemp').html();
  115. var commentBlock = $commentBlock.replace(/%realname%/g, comment.realname).replace(/%date%/g, comment.date).replace(/%comment%/g, comment.comment).replace(/%commentID%/g, comment.id);
  116. var imgClass = 'has-img';
  117. var userAvatar = user ? '<img src="' + user.avatar + '"/>' : '';
  118. if(!user || !user.avatar)
  119. {
  120. var name = user.name ? user.name : (user.realname ? user.realname : comment.actor);
  121. imgClass = 'has-text';
  122. userAvatar = '<span class="text text-len-' + name.replace(/[^\x00-\xff]/g, "00").length + '">' + name + '</span>';
  123. }
  124. commentBlock = commentBlock.replace(/%imgClass%/g, imgClass).replace(/%avatar%/g, userAvatar);
  125. $('#reviewComment' + bugID).append(commentBlock);
  126. $('#reviewComment' + bugID).parent().removeClass('hidden');
  127. var commentNum = parseInt($('.bug-comment' + bugID + ':first span').text());
  128. $('.bug-comment' + bugID + ' span').text(commentNum + 1);
  129. $('#reviewComment' + bugID + ' .commentEdit:not(:last)').addClass('hidden');
  130. }
  131. $(function()
  132. {
  133. $.each(bugIDList, function(i, bugID)
  134. {
  135. if(reviewComments[bugID])
  136. {
  137. var comments = Object.values(reviewComments[bugID]);
  138. $.each(comments, function(i, comment)
  139. {
  140. setCommentBlock(bugID, comment, comment.user);
  141. });
  142. }
  143. });
  144. arrowTabs('reviewBugs', 1);
  145. $('#bugAccordion').on('hide.zui.collapse', function () {
  146. $('#bugAccordion .fold').removeClass('icon-caret-up').addClass('icon-caret-down');
  147. })
  148. $('#bugAccordion').on('show.zui.collapse', function () {
  149. $('#bugAccordion .fold').removeClass('icon-caret-up').addClass('icon-caret-down');
  150. $(this).find('.fold').addClass('icon-caret-up');
  151. })
  152. $('#reviewBugs .close').on('click', function()
  153. {
  154. parent.removeReviewBug();
  155. });
  156. $("#reviewBugs").on('click', '.btn-left', function()
  157. {
  158. arrowTabs('reviewBugs', 1);
  159. }).on('click', '.btn-right', function()
  160. {
  161. arrowTabs('reviewBugs', -2);
  162. }).on('click', '.commentEdit', function()
  163. {
  164. var $id = '#comment-' + $(this).data('id');
  165. $($id).find('.comment-content').addClass('hidden');
  166. $($id).find('.comment-form-div').removeClass('hidden');
  167. }).on('click', '.commentEditCancel', function()
  168. {
  169. $(this).closest('.comment-desc').find('.comment-content').removeClass('hidden');
  170. $(this).closest('.comment-desc').find('.comment-form-div').addClass('hidden');
  171. }).on('click', '.detail-unfold', function()
  172. {
  173. var fold = $(this).find('i').hasClass('icon-caret-down');
  174. $(this).html(fold ? repoLang.collapse + "<i class='icon icon-caret-up'></i>" : repoLang.expand + " <i class='icon icon-caret-down'></i>");
  175. var height = fold ? 'auto' : '75px';
  176. $(this).parent().find('.bug-detail').css('height', height);
  177. }).on('click', '.histories-list .switch-btn', function()
  178. {
  179. $(this).closest('li').toggleClass('show-changes');
  180. $(this).closest('li').find('.btn-mini').eq(2).remove();
  181. }).on('submit', '.commentForm', function()
  182. {
  183. var $form = $(this);
  184. $form.ajaxSubmit(
  185. {
  186. success:function(json)
  187. {
  188. $form.find('textarea').val('');
  189. var comment = $.parseJSON(json);
  190. setCommentBlock(comment.bugID, comment, comment.user);
  191. },
  192. beforeSubmit:function(formData, jqForm)
  193. {
  194. var form = jqForm[0];
  195. if(!form.comment.value)
  196. {
  197. alert(contentError);
  198. return false;
  199. }
  200. }
  201. });
  202. return false;
  203. }).on('submit', '.comment-edit-form', function()
  204. {
  205. var $form = $(this);
  206. $form.ajaxSubmit(
  207. {
  208. success:function(html)
  209. {
  210. var $comment = $form.closest('.comment-desc');
  211. $comment.find('.comment-content').html(html);
  212. $comment.find('.comment-content').removeClass('hidden');
  213. $comment.find('.comment-form-div').addClass('hidden');
  214. },
  215. beforeSubmit:function(formData, jqForm)
  216. {
  217. var form = jqForm[0];
  218. if(!form.commentText.value)
  219. {
  220. alert(contentError);
  221. return false;
  222. }
  223. }
  224. });
  225. return false;
  226. });
  227. });
  228. var distance = 0;
  229. /**
  230. * Aarrow tabs area.
  231. *
  232. * @param string domID
  233. * @param number shift 1|-1
  234. * @param bool hideRightBtn
  235. * @access public
  236. * @return void
  237. */
  238. function arrowTabs(domID, shift, hideRightBtn)
  239. {
  240. if($('#' + domID).html() == '') return;
  241. var hasParent = $('#' + domID + ' .btn-left').length;
  242. var $leftBtn = hasParent ? $('#' + domID + ' .btn-left') : $('.btn-left');
  243. var $rightBtn = hasParent ? $('#' + domID + ' .btn-right') : $('.btn-right');
  244. $leftBtn.show();
  245. $rightBtn.show();
  246. if(hideRightBtn) $rightBtn.hide();
  247. var tabItemWidth = $('#' + domID + ' > .tabs-navbar > .nav-tabs')[0].clientWidth;
  248. var tabsWidth = $('#' + domID)[0].clientWidth;
  249. if($('#' + domID + ' .close-bugs').length) tabsWidth = tabsWidth * 0.7;
  250. if(tabItemWidth < tabsWidth)
  251. {
  252. $leftBtn.hide();
  253. $rightBtn.hide();
  254. return;
  255. }
  256. distance += tabsWidth * shift * 0.2;
  257. if(distance > 0) distance = 0;
  258. if(distance == 0)
  259. {
  260. $leftBtn.hide();
  261. }
  262. if((tabItemWidth + distance) < tabsWidth * 0.75)
  263. {
  264. $rightBtn.hide();
  265. return arrowTabs(domID, 1, true);
  266. }
  267. $('#' + domID + ' > .tabs-navbar > .nav-tabs')[0].style.transform = 'translateX('+ distance +'px)';
  268. }
  269. </script>