-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlist.js
102 lines (87 loc) · 2.62 KB
/
list.js
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
$(document).ready(function() {
var loading = $('#newform-loading');
var saveForm = function(upload_id, template_id, callback) {
$.ajax({
url: 'api/service.php',
type: 'post',
dataType: 'json',
data: {
op: 'save_form',
upload_id: upload_id,
template_id: template_id
},
success: callback
});
};
var uploader = new qq.FileUploader({
// pass the dom node (ex. $(selector)[0] for jQuery users)
element: document.getElementById('file-uploader'),
// path to server-side upload script
action: 'upload.php',
allowedExtensions: ['jpg', 'jpeg'],
onComplete: function(id, fileName, responseJSON) {
var upload_id = responseJSON.uuid;
console.log(id, fileName, responseJSON);
$('.upload-step').hide();
loading.show();
// fetch list -- populate select
$.ajax({
url: 'api/service.php',
type: 'post',
dataType: 'json',
data: {
op: 'get_templates',
},
success: function(templates) {
templates = templates || [];
var select = $('<select />');
var options = '<option value="null">-- Choose a Template --</option>';
for (var i = 0; i < templates.length; i++) {
options += '<option value="' + templates[i].template_id + '">' + templates[i].template_id + '</option>';
}
$('#select-template-button').button().click(function() {
$('.upload-step').hide();
loading.show();
var template_id = $('#template-select-list').find('select').val();
saveForm(upload_id, template_id, function() {
window.location.href = 'template.php?id=' + template_id + '&upload_id=' + upload_id;
});
});
select.html(options).change(function() {
$('#select-template-button').button('option', 'disabled', $(this).val() === 'null');
// set selection
}).appendTo('#template-select-list');
$('#new-template-button').button().click(function() {
window.location.href = 'template.php?upload_id=' + upload_id;
});
loading.hide();
$('#upload-step2').fadeIn('slow');
}
});
},
});
$('#new-form-button').button().click(function() {
$('#newform-dialog').dialog({
modal: true,
width: 600,
height: 400
});
});
$.ajax({
url: 'api/service.php',
type: 'post',
dataType: 'json',
data: {
op: 'get_templates'
},
success: function(templates) {
templates = templates || [];
var html = 'Forms <br /><hr />';
for(var i = 0; i<templates.length; i++) {
html += '<a href="template.php?id=' + templates[i].template_id + '&upload_id=' + templates[i].upload_id + '">' +
templates[i].template_id + '</a><br />';
}
$('#list-container').html(html);
}
});
});