switchgroup.blade.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <style>
  2. table.grid-switch-group tr td {
  3. padding: 3px 0!important;
  4. height:25px!important;
  5. border: 0!important;
  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. var msg = d.data.message || d.message;
  52. if (d.status) {
  53. Dcat.success(msg);
  54. reload && Dcat.reload()
  55. } else {
  56. Dcat.error(msg);
  57. }
  58. }
  59. });
  60. });
  61. </script>