Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

147 lines
8.8KB

  1. <?php $customerId = (int) ($model->customer['id'] ?? 0); ?>
  2. <script>
  3. window.__customerTypes = <?= json_encode($model->customerTypes, JSON_HEX_TAG | JSON_THROW_ON_ERROR) ?>;
  4. window.__initialCtId = <?= json_encode($model->form['customer_type_id'], JSON_HEX_TAG | JSON_THROW_ON_ERROR) ?>;
  5. window.__initialCtVals = <?= json_encode($model->form['attribute_values'], JSON_HEX_TAG | JSON_THROW_ON_ERROR) ?>;
  6. </script>
  7. <section class="content-stack">
  8. <div class="page-toolbar">
  9. <div class="section-heading">
  10. <h1><?= e($model->title) ?></h1>
  11. <p>Update the customer type or attribute values for this customer.</p>
  12. </div>
  13. <a class="button button-secondary" href="/customers">&larr; Back to list</a>
  14. </div>
  15. <?php if ($model->saved): ?>
  16. <div class="alert alert-success" x-data="{ open: true }" x-show="open" x-transition.opacity x-init="setTimeout(() => open = false, 3500)">
  17. Customer updated successfully.
  18. </div>
  19. <?php endif; ?>
  20. <section class="section-panel" x-data="customerForm(window.__customerTypes, window.__initialCtId, window.__initialCtVals)">
  21. <?php if (isset($model->errors['_token'])): ?>
  22. <div class="alert alert-error"><?= e($model->errors['_token'][0]) ?></div>
  23. <?php endif; ?>
  24. <?php if (isset($model->errors['_duplicate'])): ?>
  25. <div class="alert alert-error"><?= $model->errors['_duplicate'][0] ?></div>
  26. <?php endif; ?>
  27. <form method="post" action="/customers/<?= e((string) $customerId) ?>/update" class="ct-form" novalidate>
  28. <?= csrf_field() ?>
  29. <div class="form-section">
  30. <label class="field field-full">
  31. <span>Customer type <span class="required-mark">*</span></span>
  32. <select class="input<?= isset($model->errors['customer_type_id']) ? ' input-error' : '' ?>"
  33. name="customer_type_id" x-model="selectedTypeId" x-on:change="onTypeChange()" required>
  34. <option value="0">— Select a customer type —</option>
  35. <?php foreach ($model->customerTypes as $ct): ?>
  36. <option value="<?= e((string) $ct['id']) ?>"
  37. <?= (int) $model->form['customer_type_id'] === $ct['id'] ? 'selected' : '' ?>>
  38. <?= e($ct['name']) ?>
  39. </option>
  40. <?php endforeach; ?>
  41. </select>
  42. <?php if (isset($model->errors['customer_type_id'])): ?>
  43. <small class="field-error"><?= e($model->errors['customer_type_id'][0]) ?></small>
  44. <?php endif; ?>
  45. </label>
  46. </div>
  47. <div class="form-section" x-show="currentAttributes.length > 0">
  48. <div class="attributes-header">
  49. <h3>Attribute values</h3>
  50. <p class="attributes-hint">Fields defined by the selected customer type.</p>
  51. </div>
  52. <div class="form-grid">
  53. <template x-for="attr in currentAttributes" :key="attr.name">
  54. <label class="field" :class="{ 'api-lookup-label': attr.type === 'api_lookup' }">
  55. <span x-text="attr.name"></span>
  56. <template x-if="attr.type === 'boolean'">
  57. <select class="input"
  58. :name="`attribute_values[${attr.name}]`"
  59. x-on:change="attributeValues[attr.name] = $event.target.value">
  60. <option value="" :selected="!attributeValues[attr.name]">— Select —</option>
  61. <option value="true" :selected="attributeValues[attr.name] === 'true'">True</option>
  62. <option value="false" :selected="attributeValues[attr.name] === 'false'">False</option>
  63. </select>
  64. </template>
  65. <template x-if="attr.type === 'api_lookup'">
  66. <div class="api-lookup-field">
  67. <input class="input" type="text"
  68. :name="`attribute_values[${attr.name}]`"
  69. x-model="attributeValues[attr.name]"
  70. placeholder="Type to search…"
  71. autocomplete="off"
  72. x-on:focus="openApiLookup(attr.name)"
  73. x-on:blur="closeApiLookup(attr.name)"
  74. x-on:keydown.escape.prevent="closeApiLookup(attr.name)">
  75. <div class="api-lookup-dropdown"
  76. x-show="apiLookupOpen[attr.name]"
  77. x-on:mousedown.prevent>
  78. <p class="api-lookup-loading" x-show="apiLookupState[attr.name] === 'loading'">Loading…</p>
  79. <div class="api-lookup-table" x-show="apiLookupState[attr.name] !== 'loading' && apiLookupState[attr.name] !== 'error'">
  80. <div class="api-lookup-thead"
  81. :style="`grid-template-columns: repeat(${getApiOptions(attr.name).fields.length || 1}, 1fr)`">
  82. <template x-for="f in getApiOptions(attr.name).fields" :key="f">
  83. <span x-text="f"></span>
  84. </template>
  85. </div>
  86. <div class="api-lookup-tbody">
  87. <template x-for="rec in getFilteredRecords(attr.name, attributeValues[attr.name])" :key="rec._primary">
  88. <div class="api-lookup-tr"
  89. :class="{ 'is-selected': attributeValues[attr.name] === rec._primary }"
  90. :style="`grid-template-columns: repeat(${getApiOptions(attr.name).fields.length || 1}, 1fr)`"
  91. x-on:click="selectApiOption(attr, rec)">
  92. <template x-for="(v, i) in rec._display" :key="i">
  93. <span x-text="v"></span>
  94. </template>
  95. </div>
  96. </template>
  97. <div class="api-lookup-empty" x-show="!getFilteredRecords(attr.name, attributeValues[attr.name]).length">No results.</div>
  98. </div>
  99. </div>
  100. <small class="field-error" x-show="apiLookupState[attr.name] === 'error'" x-text="apiLookupError[attr.name] || 'Fetch failed.'"></small>
  101. </div>
  102. </div>
  103. </template>
  104. <template x-if="attr.type !== 'boolean' && attr.type !== 'api_lookup'">
  105. <input class="input" :type="inputType(attr.type)"
  106. :name="`attribute_values[${attr.name}]`"
  107. :value="attributeValues[attr.name] ?? ''"
  108. x-on:input="attributeValues[attr.name] = $event.target.value">
  109. </template>
  110. </label>
  111. </template>
  112. </div>
  113. </div>
  114. <p class="attributes-hint" x-show="selectedTypeId && currentAttributes.length === 0">
  115. This customer type has no attributes defined.
  116. </p>
  117. <div class="form-actions">
  118. <button class="button button-primary" type="submit">Update Customer</button>
  119. <a class="button button-secondary" href="/customers">Cancel</a>
  120. </div>
  121. </form>
  122. <div class="delete-zone">
  123. <h4>Delete this customer</h4>
  124. <p>This cannot be undone.</p>
  125. <form method="post" action="/customers/<?= e((string) $customerId) ?>/delete"
  126. x-on:submit.prevent="confirmDelete($event)">
  127. <?= csrf_field() ?>
  128. <button type="submit" class="button button-danger">Delete Customer</button>
  129. </form>
  130. </div>
  131. </section>
  132. </section>

Powered by TurnKey Linux.