1 | // Crossbrowser event listeners adder |
---|
2 | function addEvent(obj, evType, fn, useCap) { |
---|
3 | var r = false; |
---|
4 | if (obj.addEventListener){ |
---|
5 | if (typeof(useCap) == 'undefined') |
---|
6 | useCap = false; |
---|
7 | obj.addEventListener(evType, fn, useCap); |
---|
8 | r = true; |
---|
9 | } |
---|
10 | else if (obj.attachEvent) { |
---|
11 | var id = obj.sourceIndex || -1; |
---|
12 | |
---|
13 | if (!fn[evType + id]) { |
---|
14 | var f = fn[evType + id] = function(e) { |
---|
15 | var o = document.all[id] || document; |
---|
16 | o._f = fn; |
---|
17 | var s = o._f(e); |
---|
18 | o._f = null; |
---|
19 | return s; |
---|
20 | }; |
---|
21 | |
---|
22 | r = obj.attachEvent("on" + evType, f); |
---|
23 | obj = null; |
---|
24 | } |
---|
25 | } |
---|
26 | return r; |
---|
27 | }; |
---|
28 | |
---|
29 | function triggerTitleClass(e) { |
---|
30 | var currnode = window.event ? window.event.srcElement : e.currentTarget; |
---|
31 | |
---|
32 | // fetch required data structure |
---|
33 | var element = getThisOrParentElement(currnode, "INPUT"); |
---|
34 | // If no input tag found - leave function |
---|
35 | if (element == null || element.tagName.toUpperCase() == "BODY") |
---|
36 | return; |
---|
37 | |
---|
38 | var current = element.value; |
---|
39 | var initial = element.getAttribute("default_value"); |
---|
40 | if (initial == null || current == null) |
---|
41 | return; |
---|
42 | |
---|
43 | if (initial == current) { |
---|
44 | setClassAttr(element, "not-changed-title-field") |
---|
45 | } else { |
---|
46 | setClassAttr(element, "changed-title-field") |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | function setClassAttr(element, value) { |
---|
51 | if (element.className) { |
---|
52 | element.className = value |
---|
53 | } else { |
---|
54 | element.setAttribute("CLASS", value) |
---|
55 | } |
---|
56 | } |
---|
57 | // Trigger styles on focusing on the element |
---|
58 | function triggerOnFocusStyles(e) { |
---|
59 | var currnode = window.event ? window.event.srcElement : e.currentTarget; |
---|
60 | |
---|
61 | // fetch required data structure |
---|
62 | var element = getThisOrParentElement(currnode, "INPUT"); |
---|
63 | // If no input tag found - leave function |
---|
64 | if (element == null || element.tagName.toUpperCase() == "BODY") |
---|
65 | return; |
---|
66 | setClassAttr(element, "changed-title-field") |
---|
67 | } |
---|
68 | |
---|
69 | function getThisOrParentElement(currnode, tagname) { |
---|
70 | /* Find the first parent node with the given tag name */ |
---|
71 | |
---|
72 | tagname = tagname.toUpperCase(); |
---|
73 | var parent = currnode; |
---|
74 | |
---|
75 | while(parent.tagName.toUpperCase() != tagname) { |
---|
76 | parent = parent.parentNode; |
---|
77 | // Next line is a safety belt |
---|
78 | if(parent.tagName.toUpperCase() == "BODY") |
---|
79 | return null; |
---|
80 | } |
---|
81 | |
---|
82 | return parent; |
---|
83 | } |
---|
84 | |
---|
85 | |
---|
86 | // function to open the popup window |
---|
87 | function getOrderIndex(currnode) { |
---|
88 | if (typeof(dataGridFieldFunctions) == "object") { |
---|
89 | var rows = dataGridFieldFunctions.getWidgetRows(currnode); |
---|
90 | var row = dataGridFieldFunctions.getParentElementById(currnode, "datagridwidget-row"); |
---|
91 | if(row == null) { |
---|
92 | alert("Couldn't find DataGridWidget row"); |
---|
93 | return; |
---|
94 | } |
---|
95 | |
---|
96 | var idx = null |
---|
97 | |
---|
98 | // We can't use nextSibling because of blank text nodes in some browsers |
---|
99 | // Need to find the index of the row |
---|
100 | for(var t = 0; t < rows.length; t++) { |
---|
101 | if(rows[t] == row) { |
---|
102 | idx = t; |
---|
103 | break; |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | // Abort if the current row wasn't found |
---|
108 | if(idx == null) |
---|
109 | return; |
---|
110 | return idx; |
---|
111 | } |
---|
112 | return; |
---|
113 | } |
---|
114 | |
---|
115 | function getOrderedElement(widget_id, order_idx) { |
---|
116 | // First get first element for the current field |
---|
117 | var element=document.getElementById(widget_id); |
---|
118 | |
---|
119 | // If it is about DataGridField use it to chose correct element |
---|
120 | if (typeof(dataGridFieldFunctions) == "object" && order_idx >= 0) { |
---|
121 | var rows = dataGridFieldFunctions.getWidgetRows(element); |
---|
122 | if (rows.length >= order_idx) { |
---|
123 | var row = rows[order_idx] |
---|
124 | var inputs = row.getElementsByTagName("input") |
---|
125 | for (var i=0;i<=inputs.length;i++) { |
---|
126 | if (inputs[i].id == widget_id) { |
---|
127 | element = inputs[i]; |
---|
128 | break; |
---|
129 | } |
---|
130 | } |
---|
131 | } |
---|
132 | } |
---|
133 | return element; |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | function referencedatagridbrowser_openBrowser(path, fieldName, at_url, fieldRealName, fieldTitleName, fieldLinkName, currnode) { |
---|
138 | var url = path + '/referencebrowser_popup?fieldName=' + fieldName + '&fieldRealName=' + fieldRealName +'&at_url=' + at_url; |
---|
139 | |
---|
140 | var order_idx = getOrderIndex(currnode); |
---|
141 | url += (typeof(order_idx) == 'number')? '&order_idx=' + order_idx: ""; |
---|
142 | url += (typeof(fieldTitleName) != 'undefined')? '&fieldTitleName=' + fieldTitleName: ""; |
---|
143 | url += (typeof(fieldLinkName) != 'undefined')? '&fieldLinkName=' + fieldLinkName: ""; |
---|
144 | |
---|
145 | atrefpopup = window.open(url, 'referencebrowser_popup','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=550'); |
---|
146 | } |
---|
147 | |
---|
148 | // function for Array detecting |
---|
149 | function typeOf(value) { |
---|
150 | var s = typeof value; |
---|
151 | if (s === 'object') { |
---|
152 | if (value) { |
---|
153 | if (value instanceof Array) { |
---|
154 | s = 'array'; |
---|
155 | } |
---|
156 | } else { |
---|
157 | s = 'null'; |
---|
158 | } |
---|
159 | } |
---|
160 | return s; |
---|
161 | } |
---|
162 | |
---|
163 | // function to return a reference from the popup window back into the widget |
---|
164 | function referencedatagridbrowser_setReference(widget_id, uid, label, multi, order_idx, widget_title_id, link_title, widget_link_id, link_path) |
---|
165 | { |
---|
166 | if (order_idx >= 0) { |
---|
167 | // process ReferenceDataGridField |
---|
168 | uid_element=getOrderedElement(widget_id, order_idx); |
---|
169 | uid_element.value=uid; |
---|
170 | title_element=getOrderedElement(widget_title_id, order_idx); |
---|
171 | title_element.value=link_title; |
---|
172 | title_element.className="not-changed-title-field"; |
---|
173 | title_element.setAttribute("default_value", link_title); |
---|
174 | addEvent(title_element, 'blur', triggerTitleClass, false) |
---|
175 | addEvent(title_element, 'focus', triggerOnFocusStyles, false) |
---|
176 | link_element=getOrderedElement(widget_link_id, order_idx); |
---|
177 | link_element.readOnly=false; |
---|
178 | link_element.value=link_path; |
---|
179 | link_element.readOnly=true; |
---|
180 | link_element.className="hidden-field" |
---|
181 | } else if (multi==0) { |
---|
182 | // differentiate between the single and mulitselect widget |
---|
183 | // since the single widget has an extra label field. |
---|
184 | element=document.getElementById(widget_id); |
---|
185 | label_element=document.getElementById(widget_id + '_label'); |
---|
186 | element.value=uid; |
---|
187 | label_element.value=label; |
---|
188 | } else { |
---|
189 | // check if the item isn't already in the list |
---|
190 | var current_values = cssQuery('#' + widget_id + ' input'); |
---|
191 | for (var i=0; i < current_values.length; i++) { |
---|
192 | if (current_values[i].value == uid) { |
---|
193 | return false; |
---|
194 | } |
---|
195 | } |
---|
196 | // now add the new item |
---|
197 | list=document.getElementById(widget_id); |
---|
198 | li = document.createElement('li'); |
---|
199 | label_element = document.createElement('label'); |
---|
200 | input = document.createElement('input'); |
---|
201 | input.type = 'checkbox'; |
---|
202 | input.value = uid; |
---|
203 | input.checked = true; |
---|
204 | input.name = widget_id + ':list'; |
---|
205 | label_element.appendChild(input); |
---|
206 | label_element.appendChild(document.createTextNode(label)); |
---|
207 | li.appendChild(label_element); |
---|
208 | list.appendChild(li); |
---|
209 | // fix on IE7 - check *after* adding to DOM |
---|
210 | input.checked = true; |
---|
211 | } |
---|
212 | } |
---|
213 | |
---|
214 | // function to clear the reference field or remove items |
---|
215 | // from the multivalued reference list. |
---|
216 | function referencebrowser_removeReference(widget_id, multi) |
---|
217 | { |
---|
218 | if (multi) { |
---|
219 | list=document.getElementById(widget_id) |
---|
220 | for (var x=list.length-1; x >= 0; x--) { |
---|
221 | if (list[x].selected) { |
---|
222 | list[x]=null; |
---|
223 | } |
---|
224 | } |
---|
225 | for (var x=0; x < list.length; x++) { |
---|
226 | list[x].selected='selected'; |
---|
227 | } |
---|
228 | } else { |
---|
229 | element=document.getElementById(widget_id); |
---|
230 | label_element=document.getElementById(widget_id + '_label'); |
---|
231 | label_element.value = ""; |
---|
232 | element.value=""; |
---|
233 | } |
---|
234 | } |
---|
235 | |
---|
236 | |
---|