hasmanytable.blade.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <style>
  2. .table-has-many .input-group{flex-wrap: nowrap!important}
  3. </style>
  4. <div class="row form-group">
  5. <div class="{{$viewClass['label']}} "><label class="control-label pull-right">{!! $label !!}</label></div>
  6. <div class="{{$viewClass['field']}}">
  7. @include('admin::form.error')
  8. <span name="{{$column}}"></span> {{-- 用于显示错误信息 --}}
  9. <div class="has-many-table-{{$columnClass}}" >
  10. <table class="table table-has-many has-many-table-{{$columnClass}}">
  11. <thead>
  12. <tr>
  13. @foreach($headers as $header)
  14. <th>{{ $header }}</th>
  15. @endforeach
  16. <th class="hidden"></th>
  17. @if($options['allowDelete'])
  18. <th></th>
  19. @endif
  20. </tr>
  21. </thead>
  22. <tbody class="has-many-table-{{$columnClass}}-forms">
  23. @foreach($forms as $pk => $form)
  24. <tr class="has-many-table-{{$columnClass}}-form fields-group">
  25. <?php $hidden = ''; ?>
  26. @foreach($form->fields() as $field)
  27. @if (is_a($field, Dcat\Admin\Form\Field\Hidden::class))
  28. <?php $hidden .= $field->render(); ?>
  29. @continue
  30. @endif
  31. <td>{!! $field->setLabelClass(['hidden'])->width(12, 0)->render() !!}</td>
  32. @endforeach
  33. <td class="hidden">{!! $hidden !!}</td>
  34. @if($options['allowDelete'])
  35. <td class="form-group">
  36. <div>
  37. <div class="remove btn btn-white btn-sm pull-right"><i class="feather icon-trash"></i></div>
  38. </div>
  39. </td>
  40. @endif
  41. </tr>
  42. @endforeach
  43. </tbody>
  44. </table>
  45. <template class="{{$columnClass}}-tpl">
  46. <tr class="has-many-table-{{$columnClass}}-form fields-group">
  47. {!! $template !!}
  48. <td class="form-group">
  49. <div>
  50. <div class="remove btn btn-white btn-sm pull-right"><i class="feather icon-trash"></i></div>
  51. </div>
  52. </td>
  53. </tr>
  54. </template>
  55. @if($options['allowCreate'])
  56. <div class="form-group row m-t-10">
  57. <div class="{{$viewClass['field']}}" style="margin-top: 8px">
  58. <div class="add btn btn-primary btn-outline btn-sm"><i class="feather icon-plus"></i>&nbsp;{{ trans('admin.new') }}</div>
  59. </div>
  60. </div>
  61. @endif
  62. </div>
  63. </div>
  64. </div>
  65. {{--<hr style="margin-top: 0px;">--}}
  66. <script>
  67. (function () {
  68. var nestedIndex = {!! $count !!},
  69. container = '.has-many-table-{{ $columnClass }}';
  70. function replaceNestedFormIndex(value) {
  71. return String(value).replace(/{{ $parentKey ?: Dcat\Admin\Form\NestedForm::DEFAULT_KEY_NAME }}/g, nestedIndex);
  72. }
  73. $(document).off('click', container+' .add').on('click', container+' .add', function (e) {
  74. var $con = $(this).closest(container);
  75. var tpl = $con.find('template.{{ $columnClass }}-tpl');
  76. nestedIndex++;
  77. $con.find('.has-many-table-{{ $columnClass }}-forms').append(replaceNestedFormIndex(tpl.html()));
  78. e.preventDefault();
  79. return false
  80. });
  81. $(document).off('click', container+' .remove').on('click', container+' .remove', function () {
  82. var $form = $(this).closest('.has-many-table-{{ $columnClass }}-form');
  83. $form.hide();
  84. $form.find('[required]').prop('required', false);
  85. $form.find('.{{ Dcat\Admin\Form\NestedForm::REMOVE_FLAG_CLASS }}').val(1);
  86. });
  87. })();
  88. </script>