Repository navigation
Expand file tree
/
Copy pathsmwapi-client.js
More file actions
79 lines (65 loc) · 2.14 KB
/
Copy pathsmwapi-client.js
File metadata and controls
79 lines (65 loc) · 2.14 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
(function (smNetClient, $, undefined) {
smNetClient.init = function () {
$('#GetData').click(GetData);
$('#AddOrderNote').click(AddOrderNote);
};
function GetData() {
$('#Outputs').empty();
smNetConsumer.startRequest({
resource: GetResource(),
content: null,
beforeSend: BeforeSend,
fail: Fail,
done: Done
});
}
function AddOrderNote() {
$('#Outputs').empty();
smNetConsumer.startRequest({
resource: smNetConsumer.settings.odataService + '/Orders?$top=1&$select=Id',
content: null,
beforeSend: BeforeSend,
fail: Fail,
done: function (data, textStatus, jqXHR) {
Done(data, textStatus, jqXHR);
if (data && data.value && data.value.length > 0) {
smNetConsumer.startRequest({
method: 'POST',
resource: smNetConsumer.settings.odataService + '/OrderNotes',
content: { OrderId: data.value[0].Id, Note: 'Hello € wörld!', DisplayToCustomer: false, CreatedOnUtc: (new Date()).toISOString() },
beforeSend: BeforeSend,
done: Done,
fail: Fail
});
}
else {
Output('No order found!');
}
}
});
}
function GetResource() {
return $('input[name=service]').val() + $('input[name=resource]').val();
}
function BeforeSend(jqXHR, settings) {
Output('<b>Request</b> ajax settings: ' + JsonStringify(settings), true);
Output('<img class="spinner" src="spinner.gif" style="width:128px; height:15px;" />');
}
function Done(data, textStatus, jqXHR) {
$('img.spinner').parent().remove();
Output('<b>Response</b> ok:\r\n' + jqXHR.getAllResponseHeaders() + '\r\n' + JsonStringify(data));
}
function Fail(jqXHR, textStatus, errorThrown) {
$('img.spinner').parent().remove();
Output('Response failed (' + (errorThrown || '?') + '):\r\n' + jqXHR.getAllResponseHeaders() + '\r\n' + jqXHR.responseText);
}
function Output(str, clear) {
if (str) {
$('#Outputs').append((clear ? '<pre class="clear">' : '<pre>') + str + '</pre>');
$('html, body').animate({ scrollTop: $(document).height() }, 'slow');
}
}
function JsonStringify(obj) {
return obj ? JSON.stringify(obj, undefined, 2) : null;
}
}(window.smNetClient = window.smNetClient || {}, jQuery));