2018-06-18 17:35:56 -07:00
|
|
|
function checkboxSwitch(selector){
|
|
|
|
|
$(selector).bootstrapSwitch(
|
|
|
|
|
|
|
|
|
|
);
|
2015-01-21 20:12:57 +02:00
|
|
|
|
2018-06-18 17:35:56 -07:00
|
|
|
$(selector).on('switchChange.bootstrapSwitch', function(event, state) {
|
2015-06-14 22:28:33 +03:00
|
|
|
var url = $(this).attr('url') + state;
|
2018-06-18 17:44:06 -07:00
|
|
|
var method = $(this).attr('method') || 'patch';
|
2015-01-21 20:12:57 +02:00
|
|
|
|
2015-06-14 22:28:33 +03:00
|
|
|
$.ajax({
|
|
|
|
|
url: url,
|
|
|
|
|
type: method,
|
|
|
|
|
dataType: 'script'
|
2015-01-21 20:12:57 +02:00
|
|
|
});
|
|
|
|
|
});
|
2018-06-18 17:35:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(function () {
|
2018-06-18 17:44:06 -07:00
|
|
|
$.fn.bootstrapSwitch.defaults.onColor = 'success';
|
|
|
|
|
$.fn.bootstrapSwitch.defaults.offColor = 'warning';
|
|
|
|
|
$.fn.bootstrapSwitch.defaults.onText = 'Yes';
|
|
|
|
|
$.fn.bootstrapSwitch.defaults.offText = 'No';
|
|
|
|
|
$.fn.bootstrapSwitch.defaults.size = 'small';
|
|
|
|
|
|
|
|
|
|
|
2018-06-18 17:35:56 -07:00
|
|
|
checkboxSwitch("[class='switch-checkbox']");
|
2016-08-04 19:20:11 +02:00
|
|
|
|
|
|
|
|
$("[class='switch-checkbox-schedule']").bootstrapSwitch();
|
|
|
|
|
|
|
|
|
|
$('input[class="switch-checkbox-schedule"]').on('switchChange.bootstrapSwitch', function(event, state) {
|
|
|
|
|
var url = $(this).attr('url');
|
2018-06-18 17:44:06 -07:00
|
|
|
var method = $(this).attr('method') || 'patch';
|
2016-08-04 19:20:11 +02:00
|
|
|
|
|
|
|
|
if(state){
|
|
|
|
|
url += $(this).attr('value');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var callback = function(data) {
|
2016-08-09 14:55:39 +02:00
|
|
|
showError($.parseJSON(data.responseText).errors);
|
2016-08-04 19:20:11 +02:00
|
|
|
}
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: url,
|
|
|
|
|
type: method,
|
2016-08-09 14:55:39 +02:00
|
|
|
error: callback,
|
2016-08-04 19:20:11 +02:00
|
|
|
dataType: 'json'
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-01-21 20:12:57 +02:00
|
|
|
});
|