1
|
|
2
|
function get_reviews() {
|
3
|
new Ajax.Request("@servlet-path@?action=read&docid=[%reviewdocid%]",
|
4
|
{asynchronous:true, evalScripts:true, method:'post',
|
5
|
onLoading:function(request){Element.show('busy')},
|
6
|
onComplete: render_reviews});
|
7
|
}
|
8
|
|
9
|
function render_reviews(request) {
|
10
|
//alert(request.responseText);
|
11
|
var reviews = request.responseXML.getElementsByTagName("review");
|
12
|
var div_panel;
|
13
|
|
14
|
// for each review...
|
15
|
for (var i=0; i<reviews.length; i++) {
|
16
|
|
17
|
div_panel = document.createElement("div");
|
18
|
panelName = "panel" + (i+1);
|
19
|
|
20
|
var packageId_string = getText(reviews[i], "packageId");
|
21
|
var action = document.createTextNode("Action: " + getText(reviews[i], "action"));
|
22
|
var datetime = document.createTextNode(getText(reviews[i], "datetime"));
|
23
|
var text_string = getText(reviews[i], "text");
|
24
|
var text = document.createTextNode(text_string);
|
25
|
|
26
|
// 22 title chars or 34 blurb chars can fit in one title bar
|
27
|
var title_max_length = 21;
|
28
|
var blurb_max_length = 28;
|
29
|
var title_length = packageId_string.length;
|
30
|
|
31
|
var blurb_string = "";
|
32
|
if (title_length > title_max_length) {
|
33
|
// abbreviate the title
|
34
|
packageId_string = packageId_string.substring(0, title_max_length-3) + "...";
|
35
|
} else {
|
36
|
// try to squeeze in the blurb
|
37
|
blurb_length = Math.floor((title_max_length - title_length) * (blurb_max_length / title_max_length));
|
38
|
if (text_string.length > blurb_length) {
|
39
|
// abbreviate the blurb
|
40
|
if (blurb_length > 3) {
|
41
|
blurb_length -= 3;
|
42
|
suffix = "...";
|
43
|
} else {
|
44
|
suffix = "";
|
45
|
}
|
46
|
blurb_string = text_string.substring(0, blurb_length) + suffix;
|
47
|
}
|
48
|
}
|
49
|
|
50
|
|
51
|
var packageId = document.createTextNode(packageId_string);
|
52
|
var blurb = document.createTextNode(blurb_string);
|
53
|
|
54
|
var div_header = document.createElement("div");
|
55
|
var span_blurb = document.createElement("span");
|
56
|
var div_content = document.createElement("div");
|
57
|
var p_tstamp = document.createElement("p");
|
58
|
var p_action = document.createElement("p");
|
59
|
var p_text = document.createElement("p");
|
60
|
|
61
|
|
62
|
div_header.appendChild(packageId);
|
63
|
span_blurb.appendChild(blurb);
|
64
|
div_header.appendChild(span_blurb);
|
65
|
|
66
|
p_tstamp.appendChild(datetime);
|
67
|
p_action.appendChild(action);
|
68
|
p_text.appendChild(text);
|
69
|
div_content.appendChild(p_tstamp);
|
70
|
div_content.appendChild(p_action);
|
71
|
div_content.appendChild(p_text);
|
72
|
|
73
|
div_panel.setAttribute("id", panelName);
|
74
|
div_header.setAttribute("id", panelName + "Header");
|
75
|
div_header.setAttribute("class", "tabtitle");
|
76
|
div_content.setAttribute("id", panelName + "Content");
|
77
|
span_blurb.setAttribute("id", panelName + "Blurb");
|
78
|
span_blurb.setAttribute("class", "review_blurb");
|
79
|
div_content.setAttribute("class", "accordionTabContentBox");
|
80
|
p_tstamp.setAttribute("class", "review_tstamp");
|
81
|
p_action.setAttribute("class", "review_action");
|
82
|
p_text.setAttribute("class", "review_text");
|
83
|
|
84
|
div_header.setAttribute("className", "tabtitle");
|
85
|
span_blurb.setAttribute("className", "review_blurb");
|
86
|
div_content.setAttribute("className", "accordionTabContentBox");
|
87
|
p_tstamp.setAttribute("className", "review_tstamp");
|
88
|
p_action.setAttribute("className", "review_action");
|
89
|
p_text.setAttribute("className", "review_text");
|
90
|
|
91
|
div_panel.appendChild(div_header);
|
92
|
div_panel.appendChild(div_content);
|
93
|
|
94
|
document.getElementById("review_list").appendChild(div_panel);
|
95
|
}
|
96
|
|
97
|
var which_tab = 0;
|
98
|
Element.hide("panel" + (which_tab+1) + "Blurb");
|
99
|
var accordion = new Rico.Accordion('review_list',
|
100
|
{
|
101
|
borderColor:"#fff",
|
102
|
expandedBg:"#DEF1F1",
|
103
|
expandedTextColor:"#000",
|
104
|
collapsedBg:"#A3DADA",
|
105
|
collapsedTextColor:"#444",
|
106
|
hoverBg:"#DEF1F1",
|
107
|
hoverTextColor:"#222",
|
108
|
panelHeight:150,
|
109
|
onLoadShowTab:which_tab
|
110
|
});
|
111
|
|
112
|
// could have used onShowTab/onHideTab but this has a better effect
|
113
|
accordion.clickBeforeActions.push(show_current_blurb);
|
114
|
accordion.clickAfterActions.push(hide_current_blurb);
|
115
|
|
116
|
// not busy anymore
|
117
|
setTimeout("Element.hide('busy')", 1000);
|
118
|
}
|
119
|
|
120
|
// for accordion
|
121
|
function get_current_panel(tab) {
|
122
|
var panelName = tab.accordion.lastExpandedTab.titleBar.id;
|
123
|
return panelName.substring(0, panelName.indexOf("Header"));
|
124
|
}
|
125
|
|
126
|
// for accordion
|
127
|
function show_current_blurb(tab) {
|
128
|
Element.show(get_current_panel(tab) + "Blurb");
|
129
|
}
|
130
|
|
131
|
// for accordion
|
132
|
function hide_current_blurb(tab) {
|
133
|
Element.hide(get_current_panel(tab) + "Blurb");
|
134
|
}
|
135
|
|
136
|
|
137
|
function getText(elem, tag) {
|
138
|
var node = elem.getElementsByTagName(tag)[0];
|
139
|
if (node != null && node.firstChild != null) {
|
140
|
return elem.getElementsByTagName(tag)[0].firstChild.nodeValue.trim();
|
141
|
}
|
142
|
return "";
|
143
|
}
|
144
|
|
145
|
function expand_detail(rid) {
|
146
|
id = "review_" + rid;
|
147
|
Element.hide(id + '_show');
|
148
|
Element.hide(id + '_blurb');
|
149
|
Element.show(id + '_hide');
|
150
|
new Effect.BlindDown(id + "_detail", {duration:0.3})
|
151
|
}
|
152
|
|
153
|
function hide_detail(rid) {
|
154
|
id = "review_" + rid;
|
155
|
new Effect.BlindUp(id + "_detail", {duration:0.3})
|
156
|
Element.hide(id + '_hide');
|
157
|
Element.show(id + '_show');
|
158
|
Element.show(id + '_blurb');
|
159
|
//setTimeout("Element.show(id + '_show'); Element.show(id + '_blurb')", 250)
|
160
|
}
|
161
|
|
162
|
|