1 function setupPoints(numberformat, wrongFormat) {
2 decpoint = numberformat.substring((numberformat.substring(1, 2).match(/\.|\,|\'/) ? 5 : 4), (numberformat.substring(1, 2).match(/\.|\,|\'/) ? 6 : 5));
3 if (numberformat.substring(1, 2).match(/\.|\,|\'/)) {
4 thpoint = numberformat.substring(1, 2);
9 wrongNumberFormat = wrongFormat + " ( " + numberformat + " ) ";
12 function setupDateFormat(setDateFormat, setWrongDateFormat) {
13 dateFormat = setDateFormat;
14 wrongDateFormat = setWrongDateFormat + " ( " + setDateFormat + " ) ";
15 formatArray = new Array();
16 if(dateFormat.match(/^\w\w\W/)) {
17 seperator = dateFormat.substring(2,3);
20 seperator = dateFormat.substring(4,5);
24 function centerParms(width,height,extra) {
25 xPos = (screen.width - width) / 2;
26 yPos = (screen.height - height) / 2;
28 string = "left=" + xPos + ",top=" + yPos;
31 string += "width=" + width + ",height=" + height;
36 function check_right_number_format(input_name) {
37 var test_val = input_name.value;
38 if(thpoint && thpoint == ','){
39 test_val = test_val.replace(/,/g, '');
41 if(thpoint && thpoint == '.'){
42 test_val = test_val.replace(/\./g, '');
44 if(thpoint && thpoint == "'"){
45 test_val = test_val.replace(/\'/g, '');
47 if(decpoint && decpoint == ','){
48 test_val = test_val.replace(/,/g, '.');
50 var forbidden = test_val.match(/[^\s\d\(\)\-\+\*\/\.]/g);
51 if (forbidden && forbidden.length > 0 ){
52 return annotate(input_name, kivi.t8('wrongformat'), kivi.myconfig.numberformat);
58 return annotate(input_name, kivi.t8('wrongformat'), kivi.myconfig.numberformat);
61 return annotate(input_name);
64 function check_right_date_format(input_name) {
65 if(input_name.value == "") {
70 if ( ( input_name.value.match(/^\d+$/ ) ) && !(dateFormat.lastIndexOf("y") == 3) ) {
71 // date shortcuts for entering date without separator for three date styles, e.g.
72 // 31122014 -> 12.04.2014
73 // 12312014 -> 12/31/2014
74 // 31122014 -> 31/12/2014
76 if (input_name.value.match(/^\d{8}$/)) {
77 input_name.value = input_name.value.replace(/^(\d\d)(\d\d)(\d\d\d\d)$/, "$1" + seperator + "$2" + seperator + "$3")
78 } else if (input_name.value.match(/^\d{6}$/)) {
79 // 120414 -> 12.04.2014
80 input_name.value = input_name.value.replace(/^(\d\d)(\d\d)(\d\d)$/, "$1" + seperator + "$2" + seperator + "$3")
81 } else if (input_name.value.match(/^\d{4}$/)) {
83 var today = new Date();
84 var year = today.getYear();
85 if (year < 999) year += 1900;
86 input_name.value = input_name.value.replace(/^(\d\d)(\d\d)$/, "$1" + seperator + "$2");
87 input_name.value = input_name.value + seperator + year;
88 } else if ( input_name.value.match(/^\d{1,2}$/ ) ) {
89 // assume the entry is the day of the current month and current year
90 var today = new Date();
91 var day = input_name.value;
92 var month = today.getMonth() + 1;
93 var year = today.getYear();
94 if( day.length == 1 && day < 10) {
100 if (year < 999) year += 1900;
101 if ( dateFormat.lastIndexOf("d") == 1) {
102 input_name.value = day + seperator + month + seperator + year;
104 input_name.value = month + seperator + day + seperator + year;
109 var matching = new RegExp(dateFormat.replace(/\w/g, '\\d') + "\$","ig");
110 if(!(dateFormat.lastIndexOf("y") == 3) && !matching.test(input_name.value)) {
111 matching = new RegExp(dateFormat.replace(/\w/g, '\\d') + '\\d\\d\$', "ig");
112 if(!matching.test(input_name.value)) {
113 return annotate(input_name, kivi.t8('Falsches Datumsformat!'), kivi.myconfig.dateformat);
117 if (dateFormat.lastIndexOf("y") == 3 && !matching.test(input_name.value)) {
118 return annotate(input_name, kivi.t8('Falsches Datumsformat!'), kivi.myconfig.dateformat);
121 return annotate(input_name);
124 function annotate(input_name, error, expected) {
125 var $e = $(input_name);
127 $e.addClass('kivi-validator-invalid');
128 var tooltip = error + ' (' + expected + ')';
129 if ($e.hasClass('tooltipstered'))
130 $e.tooltipster('destroy');
134 theme: 'tooltipster-light',
136 $e.tooltipster('show');
138 $e.removeClass('kivi-validator-invalid');
139 if ($e.hasClass('tooltipstered'))
140 $e.tooltipster('destroy');
144 function get_input_value(input_name) {
145 var the_input = document.getElementsByName(input_name);
146 if (the_input && the_input[0])
147 return the_input[0].value;
151 function set_cursor_position(n) {
152 $('[name=' + n + ']').focus();
155 function focussable(e) {
156 return e && e.name && e.type != 'hidden' && e.type != 'submit' && e.disabled != true;
159 function set_cursor_to_first_element(){
160 var df = document.forms;
161 for (var f = 0; f < df.length; f++)
162 for (var i = 0; i < df[f].length; i++)
163 if (focussable(df[f][i]))
164 try { df[f][i].focus(); return } catch (er) { }
167 function getElementByIndirectName(name){
168 var e = document.getElementsByName(name)[0];
169 if (e) return document.getElementsByName(e.value)[0];
172 function focus_by_name(name){
173 var f = getElementByIndirectName(name);
175 set_cursor_position(f.name);
182 $('input').focus(function(){
183 if (focussable(this)) window.focused_element = this;
186 // setting focus inside a tabbed area fails if this is encountered before the tabbing is complete
187 // in that case the elements count as hidden and jquery aborts .focus()
188 setTimeout(function(){
189 // Lowest priority: first focussable element in form.
190 set_cursor_to_first_element();
192 // Medium priority: class set in template
193 var initial_focus = $(".initial_focus").filter(':visible')[0];
195 $(initial_focus).focus();
197 // special: honour focus_position
198 // if no higher priority applies set focus to the appropriate element
199 if ($("#display_row")[0] && kivi.myconfig.focus_position) {
200 switch(kivi.myconfig.focus_position) {
201 case 'last_partnumber' : $('#display_row tr.row:gt(-3):lt(-1) input[name*="partnumber"]').focus(); break;
202 case 'last_description' : $('#display_row tr.row:gt(-3):lt(-1) input[name*="description"]').focus(); break;
203 case 'last_qty' : $('#display_row tr.row:gt(-3):lt(-1) input[name*="qty"]').focus(); break;
204 case 'new_partnumber' : $('#display_row tr:gt(1) input[name*="partnumber"]').focus(); break;
205 case 'new_description' : $('#display_row tr:gt(1) input[name*="description"]').focus(); break;
206 case 'new_qty' : $('#display_row tr:gt(1) input[name*="qty"]').focus(); break;
210 // all of this screws with the native location.hash focus, so reimplement this as well
212 var hash_name = location.hash.substr(1);
213 var $hash_by_id = $(location.hash + ':visible');
214 if ($hash_by_id.length > 0) {
215 $hash_by_id.get(0).focus();
217 var $by_name = $('[name=' + hash_name + ']:visible');
218 if ($by_name.length > 0) {
219 $by_name.get(0).focus();
224 // legacy. some forms install these
225 if (typeof fokus == 'function') { fokus(); return; }
226 if (focus_by_name('cursor_fokus')) return;
230 $('form').submit(function(){
231 if (window.focused_element)
232 document.forms[0].cursor_fokus.value = window.focused_element.name;