switch-group.blade.php
1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<tr style="height: 28px;">
<td><strong><small>{{ $label }}:</small></strong> </td>
<td><input type="checkbox" class="{{ $class }}" {{ $checked }} data-key="{{ $key }}" /></td>
</tr>
<script>
$('.{{ $class }}').bootstrapSwitch({
size:'mini',
onText: '{{ $states['on']['text'] }}',
offText: '{{ $states['off']['text'] }}',
onColor: '{{ $states['on']['color'] }}',
offColor: '{{ $states['off']['color'] }}',
onSwitchChange: function(event, state){
$(this).val(state ? 'on' : 'off');
var key = $(this).data('key');
var value = $(this).val();
var _status = true;
$.ajax({
url: "{{ $resource }}/" + key,
type: "POST",
data: {
"{{ $name }}": value,
_token: LA.token,
_method: 'PUT'
},
success: function (data) {
if (data.status)
toastr.success(data.message);
else
toastr.warning(data.message);
},
complete:function(xhr,status) {
if (status == 'success')
_status = xhr.responseJSON.status;
}
});
return _status;
}
});
</script>