25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

134 satır
8.2KB

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

Powered by TurnKey Linux.