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