-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathseat.js
More file actions
189 lines (161 loc) · 5.83 KB
/
seat.js
File metadata and controls
189 lines (161 loc) · 5.83 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Add the X-CSRF Token header to ajax requests
// Ref: http://laravel.com/docs/5.1/routing#csrf-x-csrf-token
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
// Generic 'confirm' dialog code for forms.
// Make your submit button part of class confirmform, and viola
// Optional: You can describe the action by adding a "data-seat-action" attribute.
var currentForm;
$(document).on("click", ".confirmform", function (e) {
if ($(this).attr('form') === undefined) {
currentForm = $(this).closest("form");
} else {
currentForm = $('#'.concat($(this).attr('form')))
}
e.preventDefault();
var action = $(this).data('seat-action');
var message = 'Are you sure you want to continue?';
if (typeof action !== 'undefined') {
message = `Are you sure you want to ${action}?`;
}
bootbox.confirm(message, function (confirmed) {
if (confirmed) {
currentForm.get(0).requestSubmit(); // requestSubmit is not supported by jquery, so access the rwa DOM element
}
});
});
// Deletion 'confirm' dialog.
// Make your submit button part of class confirmdelete, and viola.
// You can add an entity name by adding a "data-seat-entity" attribute.
var currentForm;
$(document).on("click", ".confirmdelete", function (e) {
if ($(this).attr('form') === undefined) {
currentForm = $(this).closest("form");
} else {
currentForm = $('#'.concat($(this).attr('form')))
}
e.preventDefault();
entity = $(this).data('seat-entity');
var message = 'Are you sure you want to delete this?';
if (typeof entity !== 'undefined') {
message = `Are you sure you want to delete this ${entity}?`;
}
bootbox.confirm(message, function (confirmed) {
if (confirmed) {
currentForm.get(0).requestSubmit(); // requestSubmit is not supported by jquery, so access the rwa DOM element
}
});
});
// Generic 'confirm' dialog code for links.
// Make your link button part of class confirmlink, and viola
$(document).on("click", "a.confirmlink", function (event) {
event.preventDefault();
var url = $(this).attr("href");
bootbox.confirm("Are you sure you want to continue?", function (confirmed) {
if (confirmed) {
window.location = url;
}
});
});
// Init the jQuery unveil plugin. If the
// viewport come into 100px, start loading
// the image
//
// http://luis-almeida.github.io/unveil/
$(document).ready(function () {
$("img").unveil(100);
});
// Enable bootstrap popovers
$("[data-toggle=popover]").popover();
// Enable bootstrap tooltips
$("[data-toggle=tooltip]").tooltip();
// Initialize DataTables on <table> tags
// with the 'datatable' class.
//
// https://www.datatables.net/
$(document).ready(function () {
$("table.datatable").DataTable({
paging: false,
order: []
});
});
$.extend(true, $.fn.dataTable.defaults, {
responsive: true,
autoWidth: false,
order: [[0, 'desc']],
// External javascript variable defined in `app.blade.php`.
pageLength: typeof pageLength !== 'undefined' ? pageLength : 10,
// Improved `lengthMenu` options to include showing all table rows.
lengthMenu: [
[10, 25, 50, 100, -1],
[10, 25, 50, 100, "All"]
]
});
// put some animation on the caret neat to the user dropdown
$(document).ready(function () {
$('#user-dropdown').on('show.bs.dropdown', function () {
$('#user-dropdown').find('i.fa-caret-left').addClass('fa-rotate-270');
}).on('hide.bs.dropdown', function () {
$('#user-dropdown').find('i.fa-caret-left').removeClass('fa-rotate-270');
});
$('button[data-widget="esi-update"]').on('click', function() {
var button = $(this);
button.find('i').addClass('fa-spin');
$.ajax({
url: button.data('url'),
method: 'POST',
data: {
type: button.data('type'),
entity_id: button.data('entity'),
job_name: button.data('job')
},
success: function() {
button.find('i').removeClass('fa-spin');
},
error: function(e) {
button.addClass('btn-danger');
button.removeClass('btn-light');
console.error(e);
}
});
});
});
// Helper function to mimic the PHP human_readable method
function human_readable(data, type, row) {
if (type == 'display') {
var date = moment.utc(data, "YYYY-MM-DD hh:mm:ss").fromNow();
return '<span data-toggle="tooltip" data-placement="top" title="' + data + '">' + date + "</span>";
}
return data;
}
// Helper function to abbreviate numbers to their SI suffix
var SI_SYMBOL = ["", "k", "M", "G", "T", "P", "E"];
function abbreviateNumber(number){
// what tier? (determines SI symbol)
var tier = Math.log10(number) / 3 | 0;
// if zero, we don't need a suffix
if(tier == 0) return number.toFixed(1);
// get suffix and determine scale
var suffix = SI_SYMBOL[tier];
var scale = Math.pow(10, tier * 3);
// scale the number
var scaled = number / scale;
// format number and add suffix
return scaled.toFixed(1) + suffix;
}
// Helper function to wrap long strings in multiple lines separated
// str: The string to be wrapped.
// width: The column width (a number, default: 75)
// brk: The character(s) to be inserted at every break. (default: ‘n’)
// cut: The cut: a Boolean value (false by default). See PHP docs for more info. (http://us3.php.net/manual/en/function.wordwrap.php)
function wordwrap( str, width, brk, cut ) {
brk = brk || 'n';
width = width || 75;
cut = cut || false;
if (!str) { return str; }
var regex = '.{1,' +width+ '}(\s|$)' + (cut ? '|.{' +width+ '}|.+$' : '|\S+?(\s|$)');
return str.match( RegExp(regex, 'g') ).join( brk );
}