選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

143 行
8.7KB

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

Powered by TurnKey Linux.