Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f5e340df

Von Sven Schöling vor mehr als 16 Jahren hinzugefügt

  • ID f5e340dfd90576faa5130ca4530840e6d2ce5e81
  • Vorgänger e2edfbac
  • Nachfolger 2ed420df

Fokus Patch.

Angeregt durch Bug798, allerdings erweitert und verallgemeinert.

Essentiell merkt sich Lx-Office jetzt in den Bereichen Auftrag, Rechnung, Einkaufsrechnung und Lizenzen die Fokusposition bei Update.

Das Javascript ist in common.js enthalten. Um es in andere Bereiche einzubinden muessen die folgenden Schritte gemacht werden:
1. Jedes Formular muss ein input Feld mit dem Namen "cursor_fokus" durchschleifen.
2. Das Script "js/common.js" muss nach dem body tag eingebunden werden.

Alles andere macht das Script von alleine, die Handler sind erweiterbar auf andere onsubmit und onload Scripte.

Unterschiede anzeigen:

SL/Form.pm
577 577
    if ($self->{jsscript} == 1) {
578 578

  
579 579
      $jsscript = qq|
580
        <script type="text/javascript" src="js/common.js"></script>
580 581
        <style type="text/css">\@import url(js/jscalendar/calendar-win2k-1.css);</style>
581 582
        <script type="text/javascript" src="js/jscalendar/calendar.js"></script>
582 583
        <script type="text/javascript" src="js/jscalendar/lang/calendar-de.js"></script>
bin/mozilla/ir.pl
418 418
  $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
419 419
  print qq|
420 420
<body onLoad="$onload">
421

  
421
<script type="text/javascript" src="js/common.js"></script>
422 422
<form method=post action=$form->{script}>
423 423
|;
424 424

  
425 425
  $form->hide_form(qw(id title vc type level creditlimit creditremaining closedto locked shippted storno storno_id
426 426
                      max_dunning_level dunning_amount vendor_id oldvendor selectvendor taxaccounts
427
                      fxgain_accno fxloss_accno taxpart taxservice),
427
                      fxgain_accno fxloss_accno taxpart taxservice cursor_fokus),
428 428
                      map { $_.'_rate', $_.'_description' } split / /, $form->{taxaccounts} );
429 429

  
430 430
  print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
bin/mozilla/is.pl
614 614
                      creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
615 615
                      max_dunning_level dunning_amount
616 616
                      shiptoname shiptostreet shiptozipcode shiptocity shiptocountry  shiptocontact shiptophone shiptofax 
617
                      shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts),
617
                      shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus),
618 618
                      map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts} );
619 619
   
620 620
  print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
bin/mozilla/licenses.pl
72 72
  } @items);
73 73

  
74 74
  print(
75
    qq|</form>
75
    qq|<input type="hidden" name="cursor_field" value='$form->{cursor_field}'></form>
76 76
</body>
77 77
</html>
78 78
|);
bin/mozilla/oe.pl
388 388
        max_dunning_level dunning_amount shiptoname shiptostreet shiptozipcode
389 389
        shiptocity shiptocountry shiptocontact shiptophone shiptofax
390 390
        shiptodepartment_1 shiptodepartment_2 shiptoemail
391
        message email subject cc bcc taxpart taxservice taxaccounts),
391
        message email subject cc bcc taxpart taxservice taxaccounts cursor_fokus),
392 392
        @custom_hiddens,
393 393
        map { $_.'_rate', $_.'_description' } split / /, $form->{taxaccounts} ];  # deleted: discount
394 394

  
js/common.js
1 1

  
2
if (!window.a_onload_functions)   var a_onload_functions   = new Object();
3
if (!window.a_onsubmit_functions) var a_onsubmit_functions = new Object();
4

  
5

  
2 6
function setupPoints(numberformat, wrongFormat) {
3 7
  decpoint = numberformat.substring((numberformat.substring(1, 2).match(/\.|\,/) ? 5 : 4), (numberformat.substring(1, 2).match(/\.|\,/) ? 6 : 5));
4 8
  if (numberformat.substring(1, 2).match(/\.|\,/)) {
......
50 54
  }
51 55

  
52 56
function check_right_number_format(input_name) {
53
//   if(thpoint) {
54
//     if(thpoint == ','){
55
//       var thnumbers = input_name.value.split(',');  
56
//       thnumbers[thnumbers.length-1] = thnumbers[thnumbers.length-1].substring((thnumbers[thnumbers.length-1].lastIndexOf(".") !== -1 ? thnumbers[thnumbers.length-1].lastIndexOf(".") : thnumbers[thnumbers.length-1].length), 0);
57
//     }
58
//     else{
59
//       var thnumbers = input_name.value.split('.');  
60
//       thnumbers[thnumbers.length-1] = thnumbers[thnumbers.length-1].substring((thnumbers[thnumbers.length-1].lastIndexOf(",") !== -1 ? thnumbers[thnumbers.length-1].lastIndexOf(",") : thnumbers[thnumbers.length-1].length), 0);
61
//     }
62
//         
63
//     for(var i = 0; i < thnumbers.length; i++) {
64
//      if(i == 0 && thnumbers[i].length > 3) {
65
//       return show_alert_and_focus(input_name, wrongNumberFormat);
66
//      }
67
//      if(i > 0 && thnumbers[i].length != 3) {
68
//        return show_alert_and_focus(input_name, wrongNumberFormat);
69
//      }
70
//    }
71
//   }
72 57
  if(decpoint == thpoint) {
73 58
    return show_alert_and_focus(input_name, wrongNumberFormat);
74 59
  }
......
153 138
    return the_input[0].value;
154 139
  return '';
155 140
}
141

  
142
window.focused_element = null;
143
document.addEventListener("focus", function(event){ 
144
  var e = event.target;
145
  if (is_element_focussable(e)) window.focused_element = e;
146
}, true);
147

  
148
function get_cursor_position() {
149
  if (window.focused_element)
150
  document.forms[0].cursor_fokus.value = window.focused_element.name;
151
}
152

  
153
function set_cursor_position(n) {
154
  document.getElementsByName(n)[0].focus();
155
}
156

  
157
function restore_cursor_position() {
158
  var e = document.getElementsByName('cursor_fokus')[0];
159
  var f = document.getElementsByName(e.value)[0];
160
  if (is_element_focussable(f)) set_cursor_position(f.name)
161
   else set_cursor_to_first_element();
162
}
163

  
164
function is_element_focussable(e) {
165
  return e && e.type != 'hidden' && e.type != 'submit' && e.disabled != true;
166
}
167

  
168
function set_cursor_to_first_element(){
169
  var df = document.forms;
170
  for (var f = 0; f < df.length; f++)
171
    for (var i = 0; i < df[f].length; i++)
172
      if (is_element_focussable(df[f][i]))
173
        try { df[f][i].focus(); return } catch (er) { }
174
}
175
a_onload_functions["restore_cursor_position"] = restore_cursor_position;
176
a_onsubmit_functions["get_cursor_position"]   = get_cursor_position;
177

  
178
function do_load_events() {
179
  var oldl = window.onload;
180
  window.onload = function() {
181
    if (oldl) oldl();
182
    if (window.a_onload_functions) 
183
      for (var name in window.a_onload_functions) 
184
        a_onload_functions[name]();
185
  }
186
  window.onsubmit = function() {
187
    if (window.a_onsubmit_functions) 
188
      for (var name in window.a_onsubmit_functions) 
189
        a_onsubmit_functions[name]();
190
  }
191
}
192
do_load_events();

Auch abrufbar als: Unified diff