zentaobiz.ui.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. function getDropdown()
  2. {
  3. return zui.Dropdown.get('#versionDropdown-toggle');
  4. }
  5. window.afterRenderMenu = function(firstRender)
  6. {
  7. if(!firstRender) return;
  8. const $exchangeBtn = $('#exchangeDiffBtn');
  9. if(!$exchangeBtn.length) return;
  10. const newVersion = $exchangeBtn.prev().find('.text').text().replace('#', '');
  11. const oldVersion = $exchangeBtn.next().find('.text').text().replace('#', '');
  12. const checked = {};
  13. checked[newVersion] = true;
  14. checked[oldVersion] = true;
  15. this.setState({showCheckbox: true, checked: checked});
  16. };
  17. window.getVersionHeader = function()
  18. {
  19. if(this.props.items.length < 2) return;
  20. const dropdown = getDropdown();
  21. const actions =
  22. [
  23. {icon: 'exchange', text: dropdown.options.diffLang, className: this.state.showCheckbox ? 'invisible pointer-events-none' : 'text-primary', onClick: () => this.setState({showCheckbox: true})},
  24. ];
  25. return {
  26. component: 'Listitem',
  27. style: {marginBottom: -6},
  28. className: 'not-hide-menu',
  29. props:
  30. {
  31. text: dropdown.options.allVersion,
  32. titleClass: 'text-gray',
  33. actions: actions,
  34. },
  35. };
  36. }
  37. window.getVersionFooter = function()
  38. {
  39. if(this.props.items.length < 2) return;
  40. const dropdown = getDropdown();
  41. return {
  42. component: 'Toolbar',
  43. props: {
  44. gap: 4,
  45. className: `p-1 pt-0${this.state.showCheckbox ? '' : ' hidden'}`,
  46. items: [
  47. {text: dropdown.options.confirmLang, size: 'sm', disabled: this.getChecks().length < 2, type: 'primary', onClick: () =>
  48. {
  49. const versions = this.getChecks();
  50. const oldVersion = Math.min(...versions);
  51. const newVersion = Math.max(...versions);
  52. reloadView(newVersion, oldVersion);
  53. const $toggle = $('#versionDropdown-toggle').removeClass('gray-pale').addClass('primary-pale rounded-r-none');
  54. $('#docHeader .is-extra-version').remove();
  55. $toggle.find('.text').text('#' + newVersion);
  56. $toggle.after(
  57. [
  58. '<button class="rounded-none size-xs gap-1 btn primary-pale is-extra-version" id="exchangeDiffBtn" onClick="flipVersion(this)" style="margin-left:-6px"><span class="icon icon-exchange"></span></button>',
  59. `<button class='rounded-full rounded-l-none size-xs gap-1 btn primary-pale is-extra-version pointer-events-none' style="margin-left:-6px;min-width:${$toggle.outerWidth()}px"><span class='text'>#${oldVersion}</span></button>`
  60. ].join(''));
  61. this.setState({showCheckbox: true});
  62. }
  63. },
  64. {text: dropdown.options.cancelDiff, size: 'sm', className: 'not-hide-menu', type: 'default', onClick: () => {this.setState({showCheckbox: false});}},
  65. ],
  66. },
  67. };
  68. }
  69. window.getDropdownItem = function(item)
  70. {
  71. if (!this.state.showCheckbox) return item;
  72. const checked = !!this.state.checked[item.key];
  73. item = $.extend({checked: checked}, item, {active: false, selected: item.checked});
  74. if (!item.checked && item.disabled === undefined) {
  75. const disabled = this.getChecks().length >= 2;
  76. item = $.extend({disabled: disabled}, item);
  77. }
  78. return item;
  79. }
  80. window.onClickDropdownItem = function(info)
  81. {
  82. if(!this.state.showCheckbox) return;
  83. info.event.stopPropagation();
  84. info.event.preventDefault();
  85. }
  86. window.reloadView = function(newV, oldV)
  87. {
  88. const dropdown = getDropdown();
  89. const param = 'objectType=' + dropdown.options.objectType + '&docID=' + dropdown.options.docID + '&newVersion=' + newV + '&oldVersion=' + oldV;
  90. loadTarget($.createLink('doc', 'diff', param), '#docEditor');
  91. }
  92. window.flipVersion = function()
  93. {
  94. const $exchangeBtn = $('#exchangeDiffBtn');
  95. $exchangeBtn.toggleClass('primary').toggleClass('primary-pale');
  96. const newVersion = $exchangeBtn.prev().find('.text').text().replace('#', '');
  97. const oldVersion = $exchangeBtn.next().find('.text').text().replace('#', '');
  98. $exchangeBtn.prev().find('.text').text('#' + oldVersion);
  99. $exchangeBtn.next().find('.text').text('#' + newVersion);
  100. reloadView(oldVersion, newVersion);
  101. }