Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

103 linhas
3.1 KiB

  1. import $ from 'jquery';
  2. import { b64_decode_unicode, b64_encode_unicode, FlexPages } from './finder';
  3. import { isEnabled, getCookie, setCookie } from 'tiny-cookie';
  4. import getFilters from '../utils/get-filters';
  5. const container = document.querySelector('#pages-content-wrapper');
  6. export const getStore = () => {
  7. if (!isEnabled) {
  8. return '';
  9. }
  10. return JSON.parse(b64_decode_unicode(getCookie('grav-admin-flexpages') || 'e30='));
  11. };
  12. export const setStore = (store = {}, options = { expires: '1Y', samesite: 'Lax' }) => {
  13. if (!isEnabled) {
  14. return '';
  15. }
  16. return setCookie('grav-admin-flexpages', b64_encode_unicode(JSON.stringify(store)), options);
  17. };
  18. export const getInitialRoute = () => {
  19. const parsed = getStore();
  20. return parsed.route || '';
  21. };
  22. export const setInitialRoute = ({ route = '', filters = getStore().filters || {}, options = { expires: '1Y' }} = {}) => {
  23. return setStore({ route, filters }, options);
  24. };
  25. export let FlexPagesInstance = null;
  26. export const ReLoad = (fresh = false) => {
  27. const search = document.querySelector('#pages-filters [name="filters[search]"]');
  28. const loader = container.querySelector('.grav-loading');
  29. const content = container.querySelector('#pages-columns');
  30. const gravConfig = typeof global.GravConfig !== 'undefined' ? global.GravConfig : global.GravAdmin.config;
  31. if (fresh && search) {
  32. search.focus();
  33. }
  34. if (loader && content) {
  35. loader.style.display = 'block';
  36. content.innerHTML = '';
  37. const filters = fresh ? getStore().filters || {} : getFilters();
  38. const withFilters = Object.keys(filters).length ? { ...filters, initial: true } : {};
  39. const store = getStore();
  40. store.filters = filters;
  41. setStore(store);
  42. let isSearchFocused = false;
  43. if (search) {
  44. isSearchFocused = search === document.activeElement;
  45. }
  46. const contentWrapper = document.querySelector('.content-wrapper .gm-scroll-view');
  47. const scrollPosition = {
  48. top: contentWrapper ? contentWrapper.scrollTop : 0,
  49. left: contentWrapper ? contentWrapper.scrollLeft : 0
  50. };
  51. $.ajax({
  52. url: `${gravConfig.current_url}`,
  53. method: 'post',
  54. data: Object.assign({}, {
  55. route: b64_encode_unicode(getInitialRoute()),
  56. initial: true,
  57. action: 'listLevel'
  58. }, withFilters),
  59. success(response) {
  60. loader.style.display = 'none';
  61. if (response.status === 'error') {
  62. content.innerHTML = response.message;
  63. return true;
  64. }
  65. FlexPagesInstance = null;
  66. FlexPagesInstance = new FlexPages(content, response.data);
  67. if (search && isSearchFocused) {
  68. search.focus();
  69. }
  70. if (contentWrapper) {
  71. contentWrapper.scrollTo(scrollPosition);
  72. }
  73. return FlexPagesInstance;
  74. }
  75. });
  76. }
  77. };
  78. if (container) {
  79. ReLoad(true);
  80. }