form-fuel.sql 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. SET ":created" = COALESCE(:created, (SELECT created FROM code WHERE hash = :hash));
  2. SET ":expiry" = COALESCE(:expiry, (SELECT expiry FROM code_detail WHERE hash = :hash));
  3. SET ":value" = COALESCE(:value, (SELECT value FROM code_detail WHERE hash = :hash));
  4. SET ":store" = COALESCE(:store, json_array((SELECT store FROM code_detail WHERE hash = :hash)));
  5. SET ":used" = COALESCE(:used, (SELECT used FROM code_detail WHERE hash = :hash));
  6. SET ":type" = COALESCE(:type, json_array((SELECT type FROM code_detail WHERE hash = :hash)));
  7. SET ":title" = COALESCE(:type->>0, 'New')||' Voucher';
  8. SET ":type" = COALESCE(:type, json_array('Fuel'));
  9. SET ":content" = (SELECT json(content) FROM code WHERE hash = :hash);
  10. SET ":validate" = 'Update';
  11. SET ":action" = (CASE COALESCE(:action, '') WHEN '' THEN NULL ELSE :action END);
  12. SET ":method" = 'post';
  13. SET ":preview" = (SELECT 'data:image/svg+xml;base64,'||svg FROM code WHERE hash = :hash);
  14. SET ":autofill" = TRUE;
  15. SET ":filter_config" = '[
  16. {"name": "store[]", "required": true},
  17. {"name": "value", "required": true},
  18. {"name": "expiry", "required": true},
  19. { "name": "used", "label": "Used",
  20. "type": "radio", "value": "true",
  21. "width": 2
  22. },
  23. { "name": "used", "label": "Not Used",
  24. "type": "radio", "value": "false",
  25. "width": 2
  26. }
  27. ]';
  28. SET ":inner" = CASE COALESCE(:action, '')
  29. WHEN 'Update' THEN 'code/update.sql'
  30. ELSE 'code/form.sql'
  31. END;
  32. SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/theme.sql') AS properties
  33. WHERE COALESCE(:action, '') <> 'Update';
  34. SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/Style.sql') AS properties
  35. WHERE COALESCE(:action, '') <> 'Update';
  36. SELECT 'card' AS component, 1 AS columns
  37. WHERE COALESCE(:action, '') <> 'Update';
  38. SELECT COALESCE(:store->>'0'||' ', '') || COALESCE(:expiry, :created, '') AS title
  39. , '
  40. Type: '||COALESCE(:type->>'0','')||'
  41. Value: '||COALESCE(:value,'')||'
  42. Expires: '||COALESCE(:expiry,'')||'
  43. Submitted: '||COALESCE(:created,'')||'
  44. | Type | Content |
  45. |:-----|:--------|
  46. | ' || COALESCE(:content->>'format', '') || ' | ' || COALESCE(:content->>'content', '') || ' |
  47. ' AS description_md
  48. , :preview AS top_image
  49. , :tabler_color AS color
  50. WHERE COALESCE(:action, '') <> 'Update';
  51. ;
  52. SELECT 'dynamic' AS component, sqlpage.run_sql(:inner) AS properties;
  53. SELECT 'table' AS component;
  54. SELECT * FROM code_detail
  55. WHERE hash = :hash;