switchgroup.blade.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <style>
  2. table.grid-switch-group td {
  3. padding: 3px 0;
  4. height:23px;
  5. border: 0;
  6. }
  7. </style>
  8. <table class="grid-switch-group">
  9. @foreach($columns as $column => $label)
  10. @php($checked = Illuminate\Support\Arr::get($row, $column) ? 'checked' : '')
  11. <tr style="box-shadow: none;background: transparent">
  12. <td>{{ $label }}:&nbsp;&nbsp;&nbsp;</td>
  13. <td><input name="{{ $column }}" data-path="{{ $resource }}" data-key="{{ $key }}" {{ $checked }}
  14. type="checkbox" class="grid-column-switch-group" data-size="small" data-color="{{ $color }}"/></td>
  15. </tr>
  16. @endforeach
  17. </table>
  18. <script require="@switchery">
  19. var swt = $('.grid-column-switch-group'),
  20. reload = '{{ $refresh }}',
  21. that;
  22. function initSwitchery() {
  23. swt.each(function() {
  24. that = $(this);
  25. that.parent().find('.switchery').remove();
  26. new Switchery(that[0], that.data())
  27. })
  28. }
  29. initSwitchery();
  30. swt.off('change').change(function(e) {
  31. var that = $(this),
  32. id = that.data('key'),
  33. url = that.data('path') + '/' + id,
  34. checked = that.is(':checked'),
  35. name = that.attr('name'),
  36. data = {},
  37. value = checked ? 1 : 0;
  38. if (name.indexOf('.') === -1) {
  39. data[name] = value;
  40. } else {
  41. name = name.split('.');
  42. data[name[0]] = {};
  43. data[name[0]][name[1]] = value;
  44. }
  45. Dcat.NP.start();
  46. $.put({
  47. url: url,
  48. data: data,
  49. success: function (d) {
  50. Dcat.NP.done();
  51. if (d.status) {
  52. Dcat.success(d.message);
  53. reload && Dcat.reload()
  54. } else {
  55. Dcat.error(d.message);
  56. }
  57. }
  58. });
  59. });
  60. </script>