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