/
AddDispute.ejs
131 lines (115 loc) · 3.06 KB
/
AddDispute.ejs
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
<%
var TAGNAME = 0
var CONTENT = 1
var ATTRS = 2
var ANCESTORS = 3
//check if an associative array is empty
function isaaEmpty(aa){
for (key in aa)
return false
return true
}
//attrs is an associative array that holds attributes key-value pairs
function openTag(tagName, attrs){%>
<<%= tagName %>
<%for (attrKey in attrs){%>
<%= attrKey %> = "<%= attrs[attrKey] %>"
<%}%>
>
<%}
function closeTag(tagName){%>
</<%=tagName%>>
<%}
function insert(value){%>
<%= value %>
<%}
function printAncestors(ancestorTags){
if (! (ancestorTags instanceof Array))
return
for (var i = 0; i < ancestorTags.length; i++)
openTag(ancestorTags[i])
}
function tagNode(tagName, value, attrs){
var tmp =
{
'tagName' : tagName,
'attrs' : attrs,
'isEmpty' : false,
'print' : function(){
if(this.isEmpty)
return
for (var i = 0; i < this.value.length; i++){%>
<<%= tagName %>
<%for (attrKey in attrs){%>
<%= attrKey %> = "<%= attrs[attrKey] %>"
<%}%>
><%= this.value[i] %></<%=tagName%>>
<%}
}
}
//take either one or array of values
if (value instanceof Array)
tmp.value = value
else{
tmp.value = [value]
if (value == null)
tmp.isEmpty = true
}
return tmp
}
function printTagNode(tagName, value, attrs){
var tmp = tagNode(tagName, value, attrs)
tmp.print()
}
function tagTree(tagName, children, attrs){
var tmp = {
'tagName' : tagName,
'attrs' : attrs,
'print' : function(){
if(this.isEmpty)
return
for(var childIdx = 0; childIdx < this.children.length; childIdx++){
openTag(this.tagName)
var child = this.children[childIdx]
for (var childTag =0; childTag <child.length; childTag++){
child[childTag].print()
}
closeTag(this.tagName)
}
}
}
if (!(children[0] instanceof Array))
tmp.children = [children]
else
tmp.children = children
tmp.isEmpty = true
for (var childIdx = 0; childIdx < tmp.children.length; childIdx++){
var child = tmp.children[childIdx]
for (var childTag =0; childTag <child.length; childTag++){
if (!(child[childTag].isEmpty)){
tmp.isEmpty = false
break
}
}if(!tmp.isEmpty)
break
}
return tmp
}
function printTagTree(tagName, children, attrs){
var tmp = tagTree(tagName, children, attrs)
tmp.print()
}
%>
<?xml version="1.0" encoding="utf-8"?>
<AddDisputeRequest xmlns="urn:ebay:apis:eBLBaseComponents"><%
printTagTree('RequesterCredentials', [tagNode('eBayAuthToken', params['RequesterCredentials.eBayAuthToken'])])
printTagNode('ErrorLanguage', params.ErrorLanguage)
printTagNode('MessageID', params.MessageID)
printTagNode('Version', params.Version)
printTagNode('WarningLevel', params.WarningLevel)
printTagNode('DisputeExplanation', params.DisputeExplanation)
printTagNode('DisputeReason', params.DisputeReason)
printTagNode('ItemID', params.ItemID)
printTagNode('OrderLineItemID', params.OrderLineItemID)
printTagNode('TransactionID', params.TransactionID)
%></AddDisputeRequest>