-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
executable file
·183 lines (134 loc) · 5.39 KB
/
index.php
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
<!DOCTYPE html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<title>Wufoo API jQuery Plugin | Main Combo Example</title>
<link rel='stylesheet' type='text/css' href='css/style.css' />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type='text/javascript' src='js/jquery.wufooapi.js'></script>
<script type='text/javascript'>
// DOM Ready
$(function() {
var current = 0,
i = 0,
globalData = "",
trueIndex = 0;
function processEntries(data, num) {
globalData = data; // Set variable to passed data so it can be passed again without lookup
if (num == undefined) { num = 0; } // if called without specific entry, use the first
i = 0;
// This currently doesn't account for the data object being empty (will error)
$.each(globalData.Entries[num], function(fieldID, value) {
$(".field-row-" + i).append(
"<td class='data-cell'>" + value + "</td>"
);
i++;
});
$("#display, .buttons").fadeIn();
}
function processFields(data) {
trueIndex = 0; // Needed because of possibility that Fields have SubFields and requires sub-loop
$.each(data.Fields, function(fieldsIndex, fieldsObject) {
if (fieldsObject.SubFields) {
$.each(fieldsObject.SubFields, function(subFieldsIndex, subFieldsObject) {
$("<tr />", {
"class": "field-row-" + trueIndex
}).appendTo("#display");
$("<td />", {
"class": "title-cell",
"text": subFieldsObject.Label + " " + fieldsObject.Title
}).appendTo(".field-row-" + trueIndex);
trueIndex++;
});
} else {
$("<tr />", {
"class": "field-row-" + trueIndex
}).appendTo("#display");
$("<td />", {
"class": "title-cell",
"text": fieldsObject.Title
}).appendTo(".field-row-" + trueIndex);
trueIndex++;
}
});
$.wufooAPI.getEntries({
"formHash" : $("#allForms").val(),
"callback" : processEntries
});
};
$(".prev-button").click(function() {
if (current == 0) {
alert("You are at the first entry.")
} else {
$(".data-cell").remove();
current--;
processEntries(globalData, current);
$(".next-button").css("visibility", "visible");
if (current == 0) {
$(".prev-button").css("visibility", "hidden");
}
}
});
$(".next-button").click(function() {
if (globalData.Entries.length == (current+1)) {
alert("You are at the last entry.")
} else {
$(".data-cell").remove();
current++;
processEntries(globalData, current);
$(".prev-button").css("visibility", "visible");
if (globalData.Entries.length == (current+1)) {
$(".next-button").css("visibility", "hidden");
}
}
});
function processForms(data) {
// Fill dropdown will all returned forms
$.each(data.Forms, function(formsIndex, formsObject) {
$("<option />", {
"val": formsObject.Hash,
"text": formsObject.Name
}).appendTo("#allForms");
});
$("#allForms").change(function() {
// Reset All
$("#display, .buttons").fadeOut(200, function(){
$("#display").empty();
$(".prev-button").css("visibility", "hidden");
$(".next-button").css("visibility", "visible");
})
current = 0; i = 0; globalData = ""; trueIndex = 0;
// Get and process all fields for chosen form
$.wufooAPI.getFields({
"formHash" : $(this).val(),
"callback" : processFields
});
})
}
// Step 1: Get all forms, process (fill dropdown)
$.wufooAPI.getForms({
"callback" : processForms
});
});
</script>
</head>
<body>
<div id="page-wrap">
<h1>Wufoo jQuery API Wrapper</h1>
<ol>
<li>Open config.php and enter your subdomain and API key</li>
<li>Select a form: <select id="allForms">
<option val="">Choose</option>
</select>
</ol>
<div class="buttons">
<a href="#" class="button prev-button">← Previous</a>
<a href="#" class="button next-button">Next →</a>
</div>
<table id="display"> </table>
<div class="buttons">
<a href="#" class="button prev-button">← Previous</a>
<a href="#" class="button next-button">Next →</a>
</div>
</div>
</body>
</html>