form.blade.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <thead>
  2. <tr class="{{ $elementClass }} quick-create" style="cursor: pointer">
  3. <td colspan="{{ $columnCount }}" style="background: {{ Dcat\Admin\Admin::color()->darken('#ededed', 1) }}">
  4. <span class="create cursor-pointer" style="display: block;">
  5. <i class="feather icon-plus"></i>&nbsp;{{ __('admin.quick_create') }}
  6. </span>
  7. <form class="form-inline create-form" style="display: none;" method="post">
  8. @foreach($fields as $field)
  9. &nbsp;{!! $field->render() !!}
  10. @endforeach
  11. &nbsp;
  12. &nbsp;
  13. <button type="submit" class="btn btn-primary btn-sm">{{ __('admin.submit') }}</button>&nbsp;
  14. &nbsp;
  15. <a href="javascript:void(0);" class="cancel">{{ __('admin.cancel') }}</a>
  16. </form>
  17. </td>
  18. </tr>
  19. </thead>
  20. <script>
  21. var ctr = $('.{!! $elementClass !!}'),
  22. btn = $('.quick-create-button-{!! $uniqueName !!}');
  23. btn.on('click', function () {
  24. ctr.toggle().click();
  25. });
  26. ctr.on('click', function () {
  27. ctr.find('.create-form').show();
  28. ctr.find('.create').hide();
  29. });
  30. ctr.find('.cancel').on('click', function () {
  31. if (btn.length) {
  32. ctr.hide();
  33. return;
  34. }
  35. ctr.find('.create-form').hide();
  36. ctr.find('.create').show();
  37. return false;
  38. });
  39. ctr.find('.create-form').submit(function (e) {
  40. e.preventDefault();
  41. if (ctr.attr('submitting')) {
  42. return;
  43. }
  44. var btn = $(this).find(':submit').buttonLoading();
  45. ctr.attr('submitting', 1);
  46. $.ajax({
  47. url: '{!! $url !!}',
  48. type: '{!! $method !!}',
  49. data: $(this).serialize(),
  50. success: function(data) {
  51. ctr.attr('submitting', '');
  52. btn.buttonLoading(false);
  53. Dcat.handleJsonResponse(data);
  54. },
  55. error:function(xhq){
  56. btn.buttonLoading(false);
  57. ctr.attr('submitting', '');
  58. var json = xhq.responseJSON;
  59. if (typeof json === 'object') {
  60. if (json.message) {
  61. Dcat.error(json.message);
  62. } else if (json.errors) {
  63. var i, errors = [];
  64. for (i in json.errors) {
  65. errors.push(json.errors[i].join("<br>"));
  66. }
  67. Dcat.error(errors.join("<br>"));
  68. }
  69. }
  70. }
  71. });
  72. return false;
  73. });
  74. </script>