page-template.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <!DOCTYPE html>
  2. <html lang="se">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>[Page-Number] [Page Name] - [Project Name]</title>
  7. <!-- Tailwind CSS via CDN -->
  8. <script src="https://cdn.tailwindcss.com"></script>
  9. <!-- Tailwind Config (Design Tokens) -->
  10. <script>
  11. tailwind.config = {
  12. theme: {
  13. extend: {
  14. colors: {
  15. '[project-name]': {
  16. 50: '#eff6ff',
  17. 100: '#dbeafe',
  18. 500: '#2563eb',
  19. 600: '#1d4ed8',
  20. 700: '#1e40af',
  21. }
  22. },
  23. fontFamily: {
  24. sans: ['Inter', 'system-ui', 'sans-serif'],
  25. }
  26. }
  27. }
  28. }
  29. </script>
  30. <!-- Google Fonts -->
  31. <link rel="preconnect" href="https://fonts.googleapis.com">
  32. <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  33. <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
  34. <!-- Dev Mode Styles (feedback/testing tool) -->
  35. <link rel="stylesheet" href="components/dev-mode.css">
  36. <!-- Custom Styles (minimal - only what Tailwind can't do) -->
  37. <style>
  38. /* Custom styles that can't be done with Tailwind */
  39. /* Example: Complex animations, special overlays, etc. */
  40. </style>
  41. </head>
  42. <body class="min-h-screen bg-gray-50 font-sans">
  43. <!-- ========================================================================
  44. DEV MODE TOGGLE (for easy feedback - copy Object IDs)
  45. ======================================================================== -->
  46. <button id="dev-mode-toggle" class="dev-mode-toggle" title="Toggle Dev Mode (Ctrl+E)">
  47. <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  48. <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path>
  49. <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path>
  50. </svg>
  51. <span>Dev Mode: OFF</span>
  52. </button>
  53. <div id="dev-mode-tooltip" class="dev-mode-tooltip" style="display: none;"></div>
  54. <!-- ========================================================================
  55. HEADER
  56. ======================================================================== -->
  57. <header class="bg-white border-b border-gray-200 px-4 py-3 flex items-center justify-between">
  58. <!-- Back Button -->
  59. <button
  60. id="[page]-header-back"
  61. data-object-id="[page]-header-back"
  62. onclick="history.back()"
  63. class="text-gray-600 hover:text-gray-900 font-medium text-sm transition-colors"
  64. >
  65. ← [Back Text]
  66. </button>
  67. <!-- Page Title -->
  68. <h1
  69. id="[page]-header-title"
  70. data-object-id="[page]-header-title"
  71. class="text-lg font-semibold text-gray-900"
  72. >
  73. [Page Title]
  74. </h1>
  75. <!-- Spacer (for alignment) -->
  76. <div class="w-20"></div>
  77. <!-- Optional: Language Selector or Action Button -->
  78. <!-- <button class="text-[project-name]-600">Action</button> -->
  79. </header>
  80. <!-- ========================================================================
  81. MAIN CONTENT
  82. ======================================================================== -->
  83. <main class="max-w-md mx-auto p-4">
  84. <form id="[page]Form" class="space-y-4" onsubmit="handleSubmit(event)">
  85. <!-- ============================================================
  86. SECTION 1: Example - Picture Upload
  87. ============================================================ -->
  88. <div class="flex items-center gap-4 mb-6">
  89. <button
  90. type="button"
  91. id="[page]-picture-upload"
  92. data-object-id="[page]-picture-upload"
  93. onclick="handlePictureUpload()"
  94. class="w-24 h-24 rounded-full bg-gray-100 border-2 border-dashed border-gray-300 flex items-center justify-center hover:border-[project-name]-500 hover:bg-gray-50 transition-all cursor-pointer"
  95. >
  96. <img id="picturePreview" class="hidden w-full h-full rounded-full object-cover" alt="Preview" />
  97. <svg class="w-10 h-10 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  98. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"></path>
  99. </svg>
  100. </button>
  101. <input type="file" id="pictureInput" accept="image/*" class="hidden">
  102. <div class="flex-1">
  103. <label class="text-sm text-gray-700 font-medium">
  104. [Upload Label]
  105. </label>
  106. <p class="text-xs text-red-600 hidden" id="pictureError"></p>
  107. </div>
  108. </div>
  109. <!-- ============================================================
  110. SECTION 2: Example - Text Input
  111. ============================================================ -->
  112. <div>
  113. <input
  114. type="text"
  115. id="[page]-input-[field]"
  116. data-object-id="[page]-input-[field]"
  117. name="[fieldName]"
  118. placeholder="[Placeholder] *"
  119. class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-[project-name]-500 focus:border-transparent transition-all"
  120. required
  121. />
  122. <p class="text-sm text-red-600 hidden mt-1" id="[field]Error"></p>
  123. </div>
  124. <!-- ============================================================
  125. SECTION 3: Example - Split Button (Binary Choice)
  126. ============================================================ -->
  127. <div
  128. id="[page]-split-[choice]"
  129. data-object-id="[page]-split-[choice]"
  130. class="grid grid-cols-2 gap-0 border border-gray-300 rounded-lg overflow-hidden"
  131. >
  132. <button
  133. type="button"
  134. id="choice1"
  135. onclick="selectChoice('option1')"
  136. class="py-2 text-center font-medium text-gray-700 hover:bg-gray-50 transition-colors"
  137. >
  138. [Option 1]
  139. </button>
  140. <button
  141. type="button"
  142. id="choice2"
  143. onclick="selectChoice('option2')"
  144. class="py-2 text-center font-medium text-gray-700 hover:bg-gray-50 transition-colors border-l border-gray-300"
  145. >
  146. [Option 2]
  147. </button>
  148. </div>
  149. <!-- ============================================================
  150. SECTION 4: Example - Textarea
  151. ============================================================ -->
  152. <div>
  153. <textarea
  154. id="[page]-textarea-[field]"
  155. data-object-id="[page]-textarea-[field]"
  156. name="[fieldName]"
  157. placeholder="[Placeholder]"
  158. maxlength="500"
  159. rows="3"
  160. oninput="updateCharCounter()"
  161. class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-[project-name]-500 focus:border-transparent resize-none"
  162. ></textarea>
  163. <p class="text-xs text-gray-500 text-right hidden" id="charCounter"></p>
  164. </div>
  165. <!-- ============================================================
  166. SUBMIT BUTTON
  167. ============================================================ -->
  168. <button
  169. type="submit"
  170. id="[page]-button-submit"
  171. data-object-id="[page]-button-submit"
  172. class="w-full py-3 bg-[project-name]-600 text-white rounded-lg font-semibold hover:bg-[project-name]-700 focus:outline-none focus:ring-2 focus:ring-[project-name]-500 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed transition-all flex items-center justify-center gap-2"
  173. >
  174. <span id="submitButtonText">[Submit Text]</span>
  175. <svg id="submitButtonSpinner" class="hidden animate-spin w-5 h-5" fill="none" viewBox="0 0 24 24">
  176. <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
  177. <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
  178. </svg>
  179. </button>
  180. </form>
  181. </main>
  182. <!-- ========================================================================
  183. SUCCESS TOAST
  184. ======================================================================== -->
  185. <div id="successToast" class="hidden fixed bottom-6 left-1/2 -translate-x-1/2 bg-gray-900 text-white px-6 py-3 rounded-lg shadow-lg flex items-center gap-2 z-50 animate-slide-up">
  186. <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
  187. <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"></path>
  188. </svg>
  189. <span id="toastMessage">[Success Message]</span>
  190. </div>
  191. <!-- ========================================================================
  192. ERROR BANNER (optional)
  193. ======================================================================== -->
  194. <div id="errorBanner" class="hidden fixed top-20 left-1/2 -translate-x-1/2 max-w-md w-full mx-4 bg-red-50 border border-red-200 rounded-lg p-4 flex items-start gap-3 z-50">
  195. <svg class="w-5 h-5 text-red-600 flex-shrink-0 mt-0.5" fill="currentColor" viewBox="0 0 20 20">
  196. <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"></path>
  197. </svg>
  198. <div class="flex-1">
  199. <p class="font-medium text-red-900">Error</p>
  200. <p class="text-sm text-red-700" id="errorMessage">[Error message]</p>
  201. </div>
  202. <button onclick="hideErrorBanner()" class="text-red-600 hover:text-red-900">
  203. <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
  204. <path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path>
  205. </svg>
  206. </button>
  207. </div>
  208. <!-- ========================================================================
  209. MODALS (add as needed - example: image crop modal)
  210. ======================================================================== -->
  211. <!-- Image Crop Modal Template (uncomment if using image upload) -->
  212. <!--
  213. <div id="cropModal" class="hidden fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4">
  214. <div class="bg-white rounded-lg max-w-md w-full overflow-hidden">
  215. <div class="flex items-center justify-between px-4 py-3 border-b border-gray-200">
  216. <button onclick="cancelCrop()" class="text-[project-name]-600 font-medium">Cancel</button>
  217. <h2 class="font-semibold text-gray-900">Crop Image</h2>
  218. <button onclick="replaceImage()" class="text-[project-name]-600 font-medium">Replace</button>
  219. </div>
  220. <div class="p-4">
  221. <div class="relative bg-gray-100 rounded-lg overflow-hidden" style="height: 300px;">
  222. <img id="cropImage" src="" alt="Crop" class="w-full h-full object-contain">
  223. </div>
  224. <input type="range" id="zoomSlider" min="10" max="200" value="100"
  225. class="w-full mt-4 accent-[project-name]-600">
  226. </div>
  227. <div class="p-4">
  228. <button onclick="confirmCrop()"
  229. class="w-full py-3 bg-[project-name]-600 text-white rounded-lg font-semibold hover:bg-[project-name]-700">
  230. Use Image
  231. </button>
  232. </div>
  233. </div>
  234. </div>
  235. -->
  236. <!-- ========================================================================
  237. JAVASCRIPT - Shared Scripts
  238. ======================================================================== -->
  239. <script src="shared/prototype-api.js"></script>
  240. <script src="shared/init.js"></script>
  241. <script src="shared/utils.js"></script>
  242. <!-- ========================================================================
  243. JAVASCRIPT - Dev Mode (feedback tool)
  244. ======================================================================== -->
  245. <script src="components/dev-mode.js"></script>
  246. <!-- ========================================================================
  247. JAVASCRIPT - Component Scripts (load as needed)
  248. ======================================================================== -->
  249. <!-- <script src="components/image-crop.js"></script> -->
  250. <!-- <script src="components/toast.js"></script> -->
  251. <!-- <script src="components/modal.js"></script> -->
  252. <!-- <script src="components/form-validation.js"></script> -->
  253. <!-- ========================================================================
  254. JAVASCRIPT - Page-Specific Script (if complex logic)
  255. ======================================================================== -->
  256. <!-- Option 1: External file (if >150 lines) -->
  257. <!-- <script src="pages/[page-number]-[page-name].js"></script> -->
  258. <!-- Option 2: Inline script (preferred for <150 lines) -->
  259. <script>
  260. /**
  261. * Page: [Page Number] [Page Name]
  262. * Purpose: [Brief description]
  263. */
  264. // ================================================================
  265. // STATE MANAGEMENT
  266. // ================================================================
  267. let formData = {
  268. // Initialize form state
  269. };
  270. // ================================================================
  271. // INITIALIZATION
  272. // ================================================================
  273. window.initPage = function() {
  274. console.log('📄 [Page Name] loaded');
  275. // Page-specific initialization
  276. loadPageData();
  277. };
  278. async function loadPageData() {
  279. try {
  280. // Load any required data
  281. const user = await window.PrototypeAPI.getUser();
  282. console.log('👤 Current user:', user);
  283. // Pre-fill form if needed
  284. } catch (error) {
  285. console.error('❌ Error loading data:', error);
  286. }
  287. }
  288. // ================================================================
  289. // FORM HANDLING
  290. // ================================================================
  291. async function handleSubmit(event) {
  292. event.preventDefault();
  293. // Validate
  294. if (!validateForm()) {
  295. return;
  296. }
  297. // Show loading
  298. setLoadingState(true);
  299. try {
  300. // Collect form data
  301. const data = {
  302. // Extract form values
  303. };
  304. // API call
  305. console.log('📤 Submitting:', data);
  306. const result = await window.PrototypeAPI.[method](data);
  307. console.log('✅ Success:', result);
  308. // Show success
  309. showToast('[Success message]', 'success');
  310. // Navigate (after delay)
  311. setTimeout(() => {
  312. window.location.href = '[next-page].html';
  313. }, 1500);
  314. } catch (error) {
  315. console.error('❌ Error:', error);
  316. showErrorBanner(error.message);
  317. } finally {
  318. setLoadingState(false);
  319. }
  320. }
  321. function validateForm() {
  322. let isValid = true;
  323. // Validate each field
  324. // Example:
  325. // const name = document.getElementById('[field]').value;
  326. // if (!name) {
  327. // showFieldError('[field]', 'This field is required');
  328. // isValid = false;
  329. // }
  330. return isValid;
  331. }
  332. // ================================================================
  333. // UI INTERACTIONS
  334. // ================================================================
  335. function handlePictureUpload() {
  336. document.getElementById('pictureInput').click();
  337. }
  338. function selectChoice(choice) {
  339. // Handle choice selection
  340. console.log('Choice selected:', choice);
  341. }
  342. function updateCharCounter() {
  343. const textarea = document.getElementById('[page]-textarea-[field]');
  344. const counter = document.getElementById('charCounter');
  345. const current = textarea.value.length;
  346. const max = textarea.maxLength;
  347. counter.textContent = `${current}/${max}`;
  348. counter.classList.remove('hidden');
  349. }
  350. // ================================================================
  351. // FEEDBACK
  352. // ================================================================
  353. function setLoadingState(isLoading) {
  354. const btn = document.getElementById('[page]-button-submit');
  355. const text = document.getElementById('submitButtonText');
  356. const spinner = document.getElementById('submitButtonSpinner');
  357. btn.disabled = isLoading;
  358. text.classList.toggle('hidden', isLoading);
  359. spinner.classList.toggle('hidden', !isLoading);
  360. }
  361. function showToast(message, type = 'success') {
  362. const toast = document.getElementById('successToast');
  363. const messageEl = document.getElementById('toastMessage');
  364. messageEl.textContent = message;
  365. toast.classList.remove('hidden');
  366. setTimeout(() => {
  367. toast.classList.add('hidden');
  368. }, 3000);
  369. }
  370. function showErrorBanner(message) {
  371. const banner = document.getElementById('errorBanner');
  372. const messageEl = document.getElementById('errorMessage');
  373. messageEl.textContent = message;
  374. banner.classList.remove('hidden');
  375. setTimeout(() => {
  376. banner.classList.add('hidden');
  377. }, 5000);
  378. }
  379. function hideErrorBanner() {
  380. document.getElementById('errorBanner').classList.add('hidden');
  381. }
  382. function showFieldError(fieldId, message) {
  383. const errorEl = document.getElementById(`${fieldId}Error`);
  384. const inputEl = document.getElementById(fieldId);
  385. if (errorEl) {
  386. errorEl.textContent = message;
  387. errorEl.classList.remove('hidden');
  388. }
  389. if (inputEl) {
  390. inputEl.classList.add('border-red-500');
  391. }
  392. }
  393. function clearFieldError(fieldId) {
  394. const errorEl = document.getElementById(`${fieldId}Error`);
  395. const inputEl = document.getElementById(fieldId);
  396. if (errorEl) {
  397. errorEl.classList.add('hidden');
  398. }
  399. if (inputEl) {
  400. inputEl.classList.remove('border-red-500');
  401. }
  402. }
  403. </script>
  404. </body>
  405. </html>