DRY up bootstrapSwitches with default values

This commit is contained in:
James Mason 2018-06-18 17:44:06 -07:00
parent d703dad496
commit 1e9765c163
12 changed files with 33 additions and 66 deletions

View file

@ -5,7 +5,7 @@ function checkboxSwitch(selector){
$(selector).on('switchChange.bootstrapSwitch', function(event, state) {
var url = $(this).attr('url') + state;
var method = $(this).attr('method');
var method = $(this).attr('method') || 'patch';
$.ajax({
url: url,
@ -16,13 +16,20 @@ function checkboxSwitch(selector){
}
$(function () {
$.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';
checkboxSwitch("[class='switch-checkbox']");
$("[class='switch-checkbox-schedule']").bootstrapSwitch();
$('input[class="switch-checkbox-schedule"]').on('switchChange.bootstrapSwitch', function(event, state) {
var url = $(this).attr('url');
var method = $(this).attr('method');
var method = $(this).attr('method') || 'patch';
if(state){
url += $(this).attr('value');