effortcalendar.ui.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. async function handleSwitchCalendarDate(date)
  2. {
  3. const displayDate = date.getFullYear();
  4. if(displayDate === this.displayDate) return;
  5. this.displayDate = displayDate;
  6. toggleLoading('#mainContent', true);
  7. try
  8. {
  9. const data = await $.getJSON(this.props.ajaxGetEffortsUrl.replace('{year}', displayDate));
  10. const events = data.map(effort => ({id: effort.id, start: effort.start, end: effort.end, title: effort.title, allDay: true, effort: effort}));
  11. this.modifyEvents(events);
  12. }
  13. catch
  14. {
  15. zui.Messager.fail(this.props.textNetworkError);
  16. }
  17. toggleLoading('#mainContent', false);
  18. }
  19. function renderEvent(event)
  20. {
  21. const effort = event.effort;
  22. return {
  23. icon : null,
  24. hint : effort.divTitle || effort.title,
  25. url : effort.url,
  26. text : {html: effort.title, className: 'flex items-center gap-1'},
  27. trailing : zui.jsx`<div class="text-xs muted">${Number(effort.consumed).toFixed(2)}h</div>`,
  28. 'data-toggle': 'modal',
  29. 'data-size' : '70%',
  30. };
  31. }
  32. window.setCalendarOptions = function(_, options)
  33. {
  34. return $.extend({
  35. onSwitchDate: handleSwitchCalendarDate,
  36. eventRender: renderEvent,
  37. }, options);
  38. };
  39. window.changeUser = function(executionID, userID)
  40. {
  41. const url = $.createLink('execution', 'effortcalendar', 'executionID=' + executionID + '&userID=' + userID);
  42. openUrl(url);
  43. };
  44. window.exportCalendar = function(href)
  45. {
  46. const calendar = $('#calendar').zui('calendar');
  47. const thisDate = new Date(calendar.$.date);
  48. const year = thisDate.getFullYear();
  49. const month = thisDate.getMonth() + 1;
  50. href = href.replace('_date_', year + '_' + month + '_01');
  51. zui.Modal.open({url: href, size: 600});
  52. };