checkbox.blade.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <form class="form-group {{ $class }}" style="text-align:left;" data-key="{{ $key }}">
  2. @foreach($options as $v => $label)
  3. @php($checked = \Dcat\Admin\Support\Helper::inArray($v, $value) ? 'checked' : '')
  4. <div class="vs-checkbox-con vs-checkbox-primary" style="margin-bottom: 4px">
  5. <input type="checkbox" name="grid-checkbox-{{ $column }}[]" value="{{ $v }}" {{ $checked }}>
  6. <span class="vs-checkbox vs-checkbox-sm"><span class="vs-checkbox--check"><i class="vs-icon feather icon-check"></i></span></span>
  7. <span class="">{{ $label }}</span>
  8. </div>
  9. @endforeach
  10. <button type="submit" class="btn btn-primary btn-sm pull-left">
  11. <i class="feather icon-save"></i>&nbsp;{{ trans('admin.save') }}
  12. </button>
  13. <button type="reset" class="btn btn-white btn-sm pull-left" style="margin-left:5px;">
  14. <i class="feather icon-trash"></i>&nbsp;{{ trans('admin.reset') }}
  15. </button>
  16. </form>
  17. <script>
  18. $(document).off('submit', 'form.{{ $class }}').on('submit', 'form.{{ $class }}', function () {
  19. var values = $(this).find('input:checkbox:checked').map(function (_, el) {
  20. return $(el).val();
  21. }).get(),
  22. btn = $(this).find('[type="submit"]'),
  23. reload = '{{ $refresh }}';
  24. if (btn.attr('loading')) {
  25. return;
  26. }
  27. btn.attr('loading', 1);
  28. btn.buttonLoading();
  29. $.put({
  30. url: "{{ $resource }}/" + $(this).data('key'),
  31. data: {
  32. '{{ $column }}': values,
  33. },
  34. success: function (d) {
  35. btn.buttonLoading(false);
  36. btn.removeAttr('loading');
  37. Dcat.success(d.data.message || d.message);
  38. reload && Dcat.reload();
  39. },
  40. error: function (a, b, c) {
  41. btn.buttonLoading(false);
  42. btn.removeAttr('loading');
  43. Dcat.handleAjaxError(a, b, c);
  44. },
  45. });
  46. return false;
  47. });
  48. </script>