forked from contentful/extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.html
77 lines (67 loc) · 2.37 KB
/
app.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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" >
<title>Marketo Forms</title>
<link rel="stylesheet" href="https://unpkg.com/contentful-ui-extensions-sdk@3/dist/cf-extension.css">
<script src="https://unpkg.com/contentful-ui-extensions-sdk@3"></script>
<script src="https://unpkg.com/jquery@3"></script>
<style>
.-warning {
color: #d9453f;
margin-top: 4px;
display: none;
}
</style>
</head>
<body>
<div class="cf-form-field">
<select id="mkto-forms" class="cf-form-input">
<option value="-1" disabled>Select...</option>
</select>
<div class="cf-form-hint">Please select the desired Marketo form for this content.</div>
<div class="cf-form-hint -warning" data-mkto-warning>⚠️ The form you have selected in Contentful no longer exists in Marketo.</div>
<div class="cf-form-hint -warning" data-lambda-warning>⚠️ Error fetching data.</div>
</div>
<script type="text/javascript">
window.contentfulExtension.init(function(api) {
api.window.startAutoResizer();
var value = api.field.getValue();
var serviceUri = api.parameters.installation.serviceUri;
var selectField = $("#mkto-forms");
var forms = [];
$.ajax({
url: serviceUri,
type: "GET",
crossDomain: true,
dataType: "json",
success: function(response) {
forms = response;
forms.forEach(function(value, index) {
var option = document.createElement("option");
option.setAttribute("value", index);
option.innerText = value.name;
selectField.append(option);
});
var value = api.field.getValue();
var id = value && value.id;
var index = forms.findIndex(function(form) {
return form.id === id;
});
selectField.val(index);
if (id && index < 0) {
$("[data-mkto-warning]").show();
}
},
error: function(xhr, status) {
$("[data-lambda-warning]").show();
console.log("Error fetching data. Status:", status);
}
});
selectField.on("input", function() {
api.field.setValue(forms[this.value]);
});
});
</script>
</body>
</html>