|
1
|
(function($) { |
|
2
|
'use strict'; |
|
3
|
|
|
4
|
$(function() { |
|
5
|
|
|
6
|
$('#content-main').on('click', '.reset-link', function(e) { |
|
7
|
e.preventDefault(); |
|
8
|
|
|
9
|
const field_selector = this.dataset.fieldId.replace(/ /g, "\\ ") |
|
10
|
const field = $('#' + field_selector); |
|
11
|
const fieldType = this.dataset.fieldType; |
|
12
|
|
|
13
|
if (fieldType === 'checkbox') { |
|
14
|
field.prop('checked', this.dataset.default === 'true'); |
|
15
|
} else if (fieldType === 'multi-select') { |
|
16
|
const defaults = JSON.parse(this.dataset.default); |
|
17
|
const stringDefaults = defaults.map(function(v) { return String(v); }); |
|
18
|
// CheckboxSelectMultiple: individual checkboxes inside a wrapper |
|
19
|
field.find('input[type="checkbox"]').each(function() { |
|
20
|
$(this).prop('checked', stringDefaults.indexOf($(this).val()) !== -1); |
|
21
|
}); |
|
22
|
// SelectMultiple: <select multiple> element |
|
23
|
field.find('option').each(function() { |
|
24
|
$(this).prop('selected', stringDefaults.indexOf($(this).val()) !== -1); |
|
25
|
}); |
|
26
|
} else if (fieldType === 'date') { |
|
27
|
const defaultDate = new Date(this.dataset.default * 1000); |
|
28
|
$('#' + this.dataset.fieldId).val(defaultDate.strftime(get_format('DATE_INPUT_FORMATS')[0])); |
|
29
|
} else if (fieldType === 'datetime') { |
|
30
|
const defaultDate = new Date(this.dataset.default * 1000); |
|
31
|
$('#' + this.dataset.fieldId + '_0').val(defaultDate.strftime(get_format('DATE_INPUT_FORMATS')[0])); |
|
32
|
$('#' + this.dataset.fieldId + '_1').val(defaultDate.strftime(get_format('TIME_INPUT_FORMATS')[0])); |
|
33
|
} else { |
|
34
|
field.val(this.dataset.default); |
|
35
|
} |
|
36
|
}); |
|
37
|
}); |
|
38
|
})(django.jQuery); |
|
39
|
|