Skip to content

Commit 2fcd6ae

Browse files
committed
Clean up JS formatting with Prettier
1 parent 06c8bfb commit 2fcd6ae

22 files changed

+386
-277
lines changed

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"trailingComma": "es5",
33
"semi": true,
4-
"singleQuote": true
4+
"singleQuote": true,
5+
"printWidth": 100
56
}

app/assets/javascripts/bus_lists.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
document.addEventListener("turbolinks:load", function() {
2-
1+
document.addEventListener('turbolinks:load', function() {
32
$checkboxes = $('[data-boarded-bus]');
43

54
function updateCount() {
6-
var count = $checkboxes.filter(':checked').length
7-
$('#boarded-bus-count').text(count + ' boarded')
5+
var count = $checkboxes.filter(':checked').length;
6+
$('#boarded-bus-count').text(count + ' boarded');
87
}
98

109
if ($checkboxes.length < 1) {
@@ -22,15 +21,18 @@ document.addEventListener("turbolinks:load", function() {
2221
questionnaire: {
2322
boarded_bus: checked,
2423
id: $checkbox.data('id'),
25-
}
26-
}
27-
}).done(function() {
28-
$checkbox.prop('checked', checked);
29-
}).fail(function() {
30-
alert("Request failed, please refresh the page or try again later.");
31-
}).always(function() {
32-
$('[type=submit][data-bulk-row-edit]').prop('disabled', false);
33-
updateCount()
34-
});
24+
},
25+
},
26+
})
27+
.done(function() {
28+
$checkbox.prop('checked', checked);
29+
})
30+
.fail(function() {
31+
alert('Request failed, please refresh the page or try again later.');
32+
})
33+
.always(function() {
34+
$('[type=submit][data-bulk-row-edit]').prop('disabled', false);
35+
updateCount();
36+
});
3537
});
3638
});

app/assets/javascripts/cable.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@
99
this.App || (this.App = {});
1010

1111
App.cable = ActionCable.createConsumer();
12-
13-
}).call(this);
12+
}.call(this));

app/assets/javascripts/forms.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
document.addEventListener("turbolinks:load", function() {
1+
document.addEventListener('turbolinks:load', function() {
22
$('[name="questionnaire[travel_not_from_school]"]').on('change', function() {
33
var $location = $('[name="questionnaire[travel_location]"]');
4-
if (this.value === "true") {
4+
if (this.value === 'true') {
55
$location.parent().show();
66
$location.prop('disabled', false);
7-
}
8-
else {
7+
} else {
98
$location.parent().hide();
109
$location.prop('disabled', true);
1110
}
@@ -15,8 +14,7 @@ document.addEventListener("turbolinks:load", function() {
1514
var $content = $('.hide-if-not-attending');
1615
if ($(this).val() == 'rsvp_denied') {
1716
$content.hide();
18-
}
19-
else {
17+
} else {
2018
$content.show();
2119
}
2220
});

app/assets/javascripts/manage/lib/datatables.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
// Global settings and initializer
22

3-
$.extend( $.fn.dataTable.defaults, {
4-
processing : true,
5-
serverSide : true,
6-
scrollX : false,
7-
ajax : {
8-
url : $(this).data('source'),
9-
type : "POST"
3+
$.extend($.fn.dataTable.defaults, {
4+
processing: true,
5+
serverSide: true,
6+
scrollX: false,
7+
ajax: {
8+
url: $(this).data('source'),
9+
type: 'POST',
1010
},
1111
initComplete: function(settings, json) {
1212
var table = settings.oInstance.api();
13-
table.buttons().container().appendTo( $('.col-md-6', table.table().container()).first() );
13+
table
14+
.buttons()
15+
.container()
16+
.appendTo($('.col-md-6', table.table().container()).first());
1417
},
15-
pagingType : 'full_numbers',
18+
pagingType: 'full_numbers',
1619
lengthChange: false,
17-
lengthMenu: [
18-
[ 10, 25, 50, 100, -1 ],
19-
[ '10', '25', '50', '100', 'all' ]
20-
],
20+
lengthMenu: [[10, 25, 50, 100, -1], ['10', '25', '50', '100', 'all']],
2121
buttons: [
2222
{
2323
extend: 'pageLength',
@@ -35,40 +35,38 @@ $.extend( $.fn.dataTable.defaults, {
3535
{
3636
extend: 'csv',
3737
exportOptions: {
38-
columns: ':visible'
39-
}
38+
columns: ':visible',
39+
},
4040
},
4141
{
4242
extend: 'pdfHtml5',
4343
exportOptions: {
44-
columns: ':visible'
45-
}
44+
columns: ':visible',
45+
},
4646
},
47-
]
48-
}
49-
]
47+
],
48+
},
49+
],
5050
//dom:
5151
// "<'row'<'col-sm-4 text-left'f><'right-action col-sm-8 text-right'<'buttons'B> <'select-info'> >>" +
5252
// "<'row'<'dttb col-12 px-0'tr>>" +
5353
// "<'row'<'col-sm-12 table-footer'lip>>"
5454
});
5555

56-
5756
$(document).on('preInit.dt', function(e, settings) {
5857
var api, table_id, url;
5958
api = new $.fn.dataTable.Api(settings);
60-
table_id = "#" + api.table().node().id;
59+
table_id = '#' + api.table().node().id;
6160
url = $(table_id).data('source');
6261
if (url) {
6362
return api.ajax.url(url);
6463
}
6564
});
6665

67-
6866
// init on turbolinks load
6967
$(document).on('turbolinks:load', function() {
70-
if (!$.fn.DataTable.isDataTable("table[id^=dttb-]")) {
71-
$("table[id^=dttb-]").DataTable();
68+
if (!$.fn.DataTable.isDataTable('table[id^=dttb-]')) {
69+
$('table[id^=dttb-]').DataTable();
7270
}
7371
});
7472

app/assets/javascripts/manage/lib/debounce.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
function debounce(func, wait, immediate) {
77
var timeout;
88
return function() {
9-
var context = this, args = arguments;
9+
var context = this,
10+
args = arguments;
1011
var later = function() {
1112
timeout = null;
1213
if (!immediate) func.apply(context, args);
@@ -16,4 +17,4 @@ function debounce(func, wait, immediate) {
1617
timeout = setTimeout(later, wait);
1718
if (callNow) func.apply(context, args);
1819
};
19-
};
20+
}

app/assets/javascripts/manage/lib/emailEvents.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,20 @@ var setupEmailEvents = function() {
2222
};
2323
const groupedEvents = json.reduce(reducer, {});
2424

25-
const innerHtml = Object.keys(groupedEvents).map(function(key) {
26-
const group = groupedEvents[key];
27-
const groupHtml = group.map(function(event) {
28-
const timestamp = new Date(event.timestamp);
29-
return '<br /><small>' + event.type + ' at ' + timestamp.toLocaleString() + '</small>';
30-
}).join('');
31-
return '<li><p><strong>' + group[0].subject + '</strong>' + groupHtml + '</li>';
32-
}).join('');
25+
const innerHtml = Object.keys(groupedEvents)
26+
.map(function(key) {
27+
const group = groupedEvents[key];
28+
const groupHtml = group
29+
.map(function(event) {
30+
const timestamp = new Date(event.timestamp);
31+
return (
32+
'<br /><small>' + event.type + ' at ' + timestamp.toLocaleString() + '</small>'
33+
);
34+
})
35+
.join('');
36+
return '<li><p><strong>' + group[0].subject + '</strong>' + groupHtml + '</li>';
37+
})
38+
.join('');
3339
const newHtml = '<ul>' + innerHtml + '</ul>';
3440

3541
$(events_container).html(newHtml);
@@ -38,4 +44,4 @@ var setupEmailEvents = function() {
3844
$(events_container).html('<em>An error ocurred. Please try again later.</em>');
3945
});
4046
});
41-
}
47+
};

app/assets/javascripts/manage/lib/forms.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var setupManageForms = function() {
1818
$trigger = $('.message_trigger');
1919

2020
var type = $type.val();
21-
if (type === "automated") {
21+
if (type === 'automated') {
2222
disable($recipients);
2323
enable($trigger);
2424
} else {
@@ -31,4 +31,4 @@ var setupManageForms = function() {
3131
$('[name="message[type]"]').on('change', function() {
3232
updateMessageForm();
3333
});
34-
}
34+
};
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
$.fn.bulkRowSelect = function() {
2-
32
var applyAction = function() {
43
var checkState = $('[data-bulk-row-select]').prop('checked');
54
$('input[type=checkbox][data-bulk-row-edit]').prop('checked', checkState);
@@ -9,5 +8,4 @@ $.fn.bulkRowSelect = function() {
98
$('[data-bulk-row-select]').on('click', function(e) {
109
return applyAction();
1110
});
12-
1311
};

app/assets/javascripts/manage/lib/jquery.bulkRowedit.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
$.fn.bulkRowEdit = function() {
2-
32
var applyAction = function() {
43
$('[type=submit][data-bulk-row-edit]').prop('disabled', true);
54

@@ -19,7 +18,14 @@ $.fn.bulkRowEdit = function() {
1918
var number = ids.length;
2019
var questionnaires = number === 1 ? 'questionnaire' : 'questionnaires';
2120
var status = $('select[data-bulk-row-edit] option[value=' + action + ']').text();
22-
var message = 'Are you sure? This will set ' + number + ' ' + questionnaires + ' to "' + status + '".\n\nThis may trigger an automatic email to each applicant depending on your automated messages.';
21+
var message =
22+
'Are you sure? This will set ' +
23+
number +
24+
' ' +
25+
questionnaires +
26+
' to "' +
27+
status +
28+
'".\n\nThis may trigger an automatic email to each applicant depending on your automated messages.';
2329

2430
if (!confirm(message)) {
2531
$('[type=submit][data-bulk-row-edit]').prop('disabled', false);
@@ -31,15 +37,18 @@ $.fn.bulkRowEdit = function() {
3137
type: 'PATCH',
3238
data: {
3339
bulk_action: action,
34-
bulk_ids: ids
35-
}
36-
}).done(function() {
37-
window.questionnairesDataTable.draw(false);
38-
}).fail(function() {
39-
alert("Request failed, please refresh the page or try again later.");
40-
}).always(function() {
41-
$('[type=submit][data-bulk-row-edit]').prop('disabled', false);
42-
});
40+
bulk_ids: ids,
41+
},
42+
})
43+
.done(function() {
44+
window.questionnairesDataTable.draw(false);
45+
})
46+
.fail(function() {
47+
alert('Request failed, please refresh the page or try again later.');
48+
})
49+
.always(function() {
50+
$('[type=submit][data-bulk-row-edit]').prop('disabled', false);
51+
});
4352

4453
return true;
4554
};
@@ -48,5 +57,4 @@ $.fn.bulkRowEdit = function() {
4857
e.preventDefault();
4958
return applyAction();
5059
});
51-
5260
};

0 commit comments

Comments
 (0)