1 /**********************************************************************
2 Copyright (C) FrontAccounting, LLC.
3 Released under the terms of the GNU General Public License, GPL,
4 as published by the Free Software Foundation, either version 3
5 of the License, or (at your option) any later version.
6 This program is distributed in the hope that it will be useful,
7 but WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ***********************************************************************/
13 'alt': false, // whether is the Alt key pressed
14 'focus': -1 // currently selected indeks of document.links
18 box = document.getElementById('msgbox')
19 box.innerHTML= box.innerHTML+'<br>'+msg
23 box = document.getElementById('msgbox');
24 box.innerHTML= "<center><table width='98%' border='1' cellpadding=3 "
25 +"bordercolor='#007700' style='border-collapse: collapse'>"
26 +"<tr><td align='center' bgcolor='#ccffcc' >"
27 +"<img src='"+user.theme+"images/progressbar.gif' alt='"
28 +user.loadtxt+"' /></td></tr></table></center><br>";
29 box.style.display = 'block';
32 function save_focus(e) {
33 _focus = e.name||e.id;
34 var h = document.getElementById('hints');
36 h.style.display = e.title && e.title.length ? 'inline' : 'none';
37 h.innerHTML = e.title ? e.title : '';
41 function _expand(tabobj) {
43 var ul = tabobj.parentNode.parentNode;
44 var alltabs=ul.getElementsByTagName("input");
45 var frm = tabobj.form;
47 if (ul.getAttribute("rel")){
48 for (var i=0; i<alltabs.length; i++){
49 alltabs[i].className = "ajaxbutton" //deselect all tabs
51 tabobj.className = "current";
52 JsHttpRequest.request(tabobj)
56 //interface for selecting a tab (plus expand corresponding content)
57 function expandtab(tabcontentid, tabnumber) {
58 var tabs = document.getElementById(tabcontentid);
59 _expand(tabs.getElementsByTagName("input")[tabnumber]);
62 function _set_combo_input(e) {
63 e.setAttribute('_last', e.value);
65 var but_name = this.name.substring(0, this.name.length-4)+'button';
66 var button = document.getElementsByName(but_name)[0];
67 var select = document.getElementsByName(this.getAttribute('rel'))[0];
69 // submit request if there is submit_on_change option set and
70 // search field has changed.
71 if (button && (this.value != this.getAttribute('_last'))) {
72 JsHttpRequest.request(button);
73 } else if(this.className=='combo2') {
74 this.style.display = 'none';
75 select.style.display = 'inline';
76 setFocus(select.name);
80 e.onkeyup = function(ev) {
81 var select = document.getElementsByName(this.getAttribute('rel'))[0];
82 if(select && select.selectedIndex>=0) {
83 var len = select.length;
84 var byid = this.className=='combo';
85 var ac = this.value.toUpperCase();
86 select.options[select.selectedIndex].selected = false;
87 for (i = 0; i < len; i++) {
88 var txt = byid ? select.options[i].value : select.options[i].text;
89 if (txt.toUpperCase().indexOf(ac) >= 0) {
90 select.options[i].selected = true;
96 e.onkeydown = function(ev) {
97 ev = ev||window.event;
98 key = ev.keyCode||ev.which;
106 function _update_box(s) {
107 var byid = s.className=='combo';
108 var rel = s.getAttribute('rel');
109 var box = document.getElementsByName(rel)[0];
110 if(box && s.selectedIndex>=0) {
111 var opt = s.options[s.selectedIndex];
113 box.value = byid ? opt.value : opt.text;
114 box.setAttribute('_last', box.value);
119 function _set_combo_select(e) {
120 // When combo position is changed via js (eg from searchbox)
121 // no onchange event is generated. To ensure proper change
122 // signaling we must track selectedIndex in onblur handler.
123 e.setAttribute('_last', e.selectedIndex);
124 e.onblur = function() {
125 if(this.className=='combo')
127 if (this.selectedIndex != this.getAttribute('_last'))
130 e.onchange = function() {
132 this.setAttribute('_last', this.selectedIndex);
133 if(s.className=='combo')
135 if(s.selectedIndex>=0) {
136 var sname = '_'+s.name+'_update';
137 var update = document.getElementsByName(sname)[0];
139 JsHttpRequest.request(update);
144 e.onkeydown = function(event) {
145 event = event||window.event;
146 key = event.keyCode||event.which;
147 var box = document.getElementsByName(this.getAttribute('rel'))[0];
148 if (box && key == 32 && this.className == 'combo2') {
149 this.style.display = 'none';
150 box.style.display = 'inline';
155 if (this.getAttribute('aspect') == 'editable' && key==115) {
156 // F4: call related database editor - not available in non-js fallback mode
157 JsHttpRequest.request('_'+this.name+'_editor', this.form);
158 return false; // prevent default binding
159 // TODO: stopPropagation when needed
165 Behaviour definitions
168 'form': function(e) {
169 e.onkeydown = function(ev) {
170 ev = ev||window.event;
171 key = ev.keyCode||ev.which;
172 if((ev.ctrlKey && key == 13) || key == 27) {
173 _hotkeys.alt = false;
174 ev.cancelBubble = true;
175 if(ev.stopPropagation) ev.stopPropagation();
176 // here ctrl-enter/escape support
177 ev.returnValue = false;
183 'input': function(e) {
184 if(e.onfocus==undefined) {
185 e.onfocus = function() {
187 if (this.className == 'combo')
191 if (e.className == 'combo' || e.className == 'combo2') {
195 if(e.type == 'text' ) {
196 e.onkeydown = function(ev) {
197 ev = ev||window.event;
198 key = ev.keyCode||ev.which;
200 if(e.className == 'searchbox') e.onblur();
207 'input.combo2,input[aspect="fallback"]':
209 // this hides search button for js enabled browsers
210 e.style.display = 'none';
214 // this shows divs for js enabled browsers only
215 e.style.display = 'block';
217 // '.ajaxsubmit,.editbutton,.navibutton': // much slower on IE7
218 'button.ajaxsubmit,input.ajaxsubmit,input.editbutton,button.navibutton':
220 e.onclick = function() {
221 if (this.getAttribute('aspect') == 'process')
224 JsHttpRequest.request(this);
228 '.amount': function(e) {
229 if(e.onblur==undefined) {
230 e.onblur = function() {
231 var dec = this.getAttribute("dec");
232 price_format(this.name, get_amount(this.name), dec);
236 '.searchbox': // emulated onchange event handling for text inputs
238 e.setAttribute('_last_val', e.value);
239 e.setAttribute('autocomplete', 'off'); //must be off when calling onblur
240 e.onblur = function() {
241 var val = this.getAttribute('_last_val');
242 if (val != this.value) {
243 this.setAttribute('_last_val', this.value);
244 JsHttpRequest.request('_'+this.name+'_changed', this.form);
247 /* e.onkeydown = function(ev) {
248 ev = ev||window.event;
249 key = ev.keyCode||ev.which;
250 if (key == 13 && (this.value != this.getAttribute('_last_val'))) {
256 'select': function(e) {
257 if(e.onfocus==undefined) {
258 e.onfocus = function() {
262 if (c == 'combo' || c == 'combo2')
263 _set_combo_select(e);
266 'textarea,a': function(e) {
267 if(e.onfocus==undefined) {
268 e.onfocus = function() {
273 'a.printlink': function(l) {
274 l.onclick = function() {
276 JsHttpRequest.request(this);
280 'ul.ajaxtabs': function(ul) {
281 var ulist=ul.getElementsByTagName("li");
282 for (var x=0; x<ulist.length; x++){ //loop through each LI e
283 var ulistlink=ulist[x].getElementsByTagName("input")[0];
284 if(ulistlink.onclick==undefined) {
285 // ? var modifiedurl=ulistlink.getAttribute("href").replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/")
286 var url = ulistlink.form.action
287 ulistlink.onclick=function(){
294 '#msgbox': function(e) {
295 // this is to avoid changing div height after ajax update in IE7
296 e.style.display = e.innerHTML.length ? 'block' : 'none';
299 'a.date_picker': function(e) {
300 // this un-hides data picker for js enabled browsers
301 e.href = date_picker(this.getAttribute('rel'));
302 e.style.display = '';
303 e.tabindex = -1; // skip in tabbing order
307 function stopEv(ev) {
308 ev.returnValue = false;
309 ev.cancelBubble = true;
310 if(ev.preventDefault) ev.preventDefault();
314 Modified accesskey system. While Alt key is pressed letter keys moves
315 focus to next marked link. Alt key release activates focused link.
317 function setHotKeys() {
318 document.onkeydown = function(ev) {
319 ev = ev||window.event;
320 key = ev.keyCode||ev.which;
322 if (key == 27 && ev.altKey) { // cancel selection
323 _hotkeys.alt = false;
328 if (ev.altKey && !ev.ctrlKey && ((key>47 && key<58) || (key>64 && key<91))) {
330 var n = _hotkeys.focus;
331 var l = document.links;
333 key = String.fromCharCode(key);
334 for (var i=0; i<cnt; i++) {
336 // check also if the link is visible
337 if (l[n].accessKey==key && l[n].scrollWidth) {
339 // The timeout is needed to prevent unpredictable behaviour on IE.
340 var tmp = function() {document.links[_hotkeys.focus].focus();};
349 document.onkeyup = function(ev) {
350 if (_hotkeys.alt==true) {
351 ev = ev||window.event;
352 key = ev.keyCode||ev.which;
355 _hotkeys.alt = false;
356 if (_hotkeys.focus>=0) {
357 var link = document.links[_hotkeys.focus];
361 if (link.target=='_blank') {
362 window.open(link.href,'','toolbar=no,scrollbar=no,resizable=yes,menubar=no,width=900,height=500');
363 openWindow(link.href,'_blank');
365 window.location = link.href;
374 Behaviour.register(inserts);
376 Behaviour.addLoadEvent(setFocus);
377 Behaviour.addLoadEvent(setHotKeys);