-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataSet.js
More file actions
55 lines (47 loc) · 1.75 KB
/
DataSet.js
File metadata and controls
55 lines (47 loc) · 1.75 KB
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
/*
* DataSet module - javascript frontend functions
*
* Performs dataset functions on mouse click
*
* Copyright 2018 Tamas Meszaros <mt+git@webit.hu>
* This file licensed under Mozilla Public License v2.0 http://mozilla.org/MPL/2.0/
*/
function DataSet(command, pageid, title, pathname, fileid) {
var taskerAdminUrl = ProcessWire.config.tasker.adminUrl,
taskerAdminApiUrl = ProcessWire.config.tasker.apiUrl,
timeout = 15000,
unloading = false,
progressLabel = $('div#dataset_file_' + fileid + ''),
args = encodeURI('module=DataSet&function=' + command + '&pageId=' + pageid + '&title=' + title + '&file=' + pathname);
// alert(taskerAdminApiUrl + '?cmd=create&' + args);
progressLabel.text('Creating a task to ' + command + ' the DataSet...');
// signal if the user is leaving the page
$(window).bind('beforeunload', function() { unloading = true; });
// send the HTTP request
performApiCall(taskerAdminApiUrl + '?cmd=create&' + args, createCallback);
function performApiCall(url, callback) {
$.ajax({
dataType: "json",
url: url,
success: callback,
timeout: timeout,
error: function(jqXHR, status, errorThrown) {
if (status == 'timeout') {
progressLabel.text('Request timeout. Please check the backend for more info.');
} else if (unloading) {
progressLabel.text('Cancelling request...');
} else {
progressLabel.text('Error receiving response from the server: ' + status);
}
}
});
}
// callback for task creation
function createCallback(data) {
if (data['status']) { // return status is OK
progressLabel.replaceWith(data['status_html']);
} else { // return status is not OK
progressLabel.text('Error: ' + data['result']);
}
}
}