objectlibs.zentaobiz.html.hook.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php if(!empty($doc) and !$doc->deleted and $doc->version > 1 and common::hasPriv('doc', 'diff')):?>
  2. <?php
  3. $versions = array();
  4. $i = 1;
  5. foreach($actions as $action)
  6. {
  7. if($action->action == 'created' or $action->action == 'deletedfile' or $action->action == 'commented')
  8. {
  9. $versions[$i] = "#$i " . zget($users, $action->actor) . ' ' . substr($action->date, 2, 14);
  10. $i++;
  11. }
  12. elseif($action->action == 'edited')
  13. {
  14. foreach($action->history as $history)
  15. {
  16. if($history->field == 'content')
  17. {
  18. $versions[$i] = "#$i " . zget($users, $action->actor) . ' ' . substr($action->date, 2, 14);
  19. $i++;
  20. break;
  21. }
  22. }
  23. }
  24. }
  25. krsort($versions);
  26. $diffHtml = "<div class='btn-group versions'>";
  27. $diffHtml .= "<button data-toggle='dropdown' class='btn btn-link'>{$lang->doc->diff} <span class='caret'></span></button>";
  28. $diffHtml .= "<ul class='dropdown-menu pull-right'>";
  29. foreach($versions as $i => $versionTitle)
  30. {
  31. $diffHtml .= "<li class='v{$i}'>" . html::a(inlink('diff', "objectType={$objectType}&docID={$doc->id}&newVersion=%currentVersion%&version={$i}"), $versionTitle) . '</li>';
  32. }
  33. $diffHtml .= "</ul>";
  34. $diffHtml .= "</div>";
  35. ?>
  36. <script>
  37. appendDiffLink();
  38. /* Append diff link when change doc version. */
  39. $(document).on('click', '.doc-version-menu a, #mainActions .container a', function(event)
  40. {
  41. var times = 0;
  42. var timer = setInterval(function()
  43. {
  44. times ++;
  45. if($('#mainContent #content .detail-title .actions .versions').length == 0)
  46. {
  47. appendDiffLink();
  48. clearInterval(timer);
  49. }
  50. if(times >= 300) clearInterval(timer);
  51. }, 100);
  52. });
  53. /**
  54. * Append diff link.
  55. *
  56. * @access public
  57. * @return void
  58. */
  59. function appendDiffLink()
  60. {
  61. var currentVersion = $('#mainContent #content .info .version').attr('data-version');
  62. var diffHtml = <?php echo json_encode($diffHtml)?>;
  63. var diffHtml = diffHtml.replace(/%currentVersion%/g, currentVersion);
  64. $('#mainContent #content .detail-title .actions').append(diffHtml);
  65. $('#mainContent #content .detail-title .actions .versions').find('.v' + currentVersion).remove();
  66. }
  67. </script>
  68. <?php endif;?>