-
Notifications
You must be signed in to change notification settings - Fork 1
/
EMLDialogJS.html
executable file
·83 lines (70 loc) · 2.68 KB
/
EMLDialogJS.html
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
<script>
$(function() {
function savedEML(response) {
$('#save-eml').prop('disabled', false);
$('#save-eml').text('Save');
if (response && response.error) {
showOKAlert('Error', response.message);
} else {
google.script.host.close();
}
}
$('#enable-manual-eml').change(function(e){
$('.eml').toggle(!this.checked);
$('.eml-editor').toggle(this.checked);
});
// Fire event
$('#enable-manual-eml').change();
$('#add-alternate-identifier').click(function(e){
var $identifer = $('<input class="form-control">');
$identifer.prop('id', 'alt-identifier-' + ($('.identifiers input').length+1));
$('.identifiers').append($identifer);
});
// Add creator to creators list
$('#add-creator').click(function(e){
var givenName = $('#creator-given-name').val(),
surname = $('#creator-surname').val(),
email = $('#creator-email').val(),
org = $('#creator-organization-name').val();
if( givenName && surname ){
var op = $(document.createElement("option"));
var value = givenName + "|" + surname + "|" + org + "|" + email;
var text = givenName + " " + surname + " - " + org + "(" + email + ")";
op.prop('value', value);
op.append(document.createTextNode(text));
$('#creators').append(op);
}
});
// Remove creators from creators list
$('#remove-creator').click(function(e){
$("#creators option:selected").remove();
});
$('#save-eml').click(function(e){
$(this).prop('disabled', true);
$(this).text('Saving...');
var data = {};
$('input, select, textarea').each(function(){
var val;
var type = $(this).prop('type');
if ( type == 'checkbox' ){
val = this.checked;
}
else{
val = $(this).val();
}
data[$(this).prop('id')] = val;
});
data['creators'] = $('#creators option').map(function(){
var f = $(this).val().split('|');
return {
givenName: f[0],
surname: f[1],
org: f[2],
email: f[3]
}
}).get();
//Save EML
google.script.run.withSuccessHandler(savedEML).saveEML(data);
});
});
</script>