From: Janusz Dobrowolski Date: Mon, 6 Oct 2008 17:02:45 +0000 (+0000) Subject: Menu hotkeys system implementation. X-Git-Tag: v2.4.2~19^2~1855 X-Git-Url: https://delta.frontaccounting.com/gitweb/?p=fa-stable.git;a=commitdiff_plain;h=b1c79afd0a78ec37ff813f1305e9e0804be78ef3 Menu hotkeys system implementation. --- diff --git a/includes/page/header.inc b/includes/page/header.inc index 97529207..2ab707cc 100644 --- a/includes/page/header.inc +++ b/includes/page/header.inc @@ -17,7 +17,7 @@ function help_url($title, $app) } elseif ($title==_("Main Menu")) { - $help_page_url = $applications[$app]; + $help_page_url = access_string($applications[$app], true); } else { diff --git a/includes/ui/ui_controls.inc b/includes/ui/ui_controls.inc index 1883ba2a..2693b079 100644 --- a/includes/ui/ui_controls.inc +++ b/includes/ui/ui_controls.inc @@ -59,6 +59,27 @@ function meta_forward($forward_to, $params="") } //----------------------------------------------------------------------------------- +// Find and replace hotkey marker. +// if $clean == true marker is removed and clean label is returned +// (for use in wiki help system), otherwise result is array of label +// with underlined hotkey letter and access property string. +// +function access_string($label, $clean=false) +{ + $access = ''; + $slices = array(); + + if (preg_match('/(.*)&([a-zA-Z0-9])(.*)/', $label, $slices)) + { + $label = $clean ? $slices[1].$slices[2].$slices[3] : + $slices[1].''.$slices[2].''.$slices[3]; + $access = " accesskey='".strtoupper($slices[2])."'"; + } + + $label = str_replace( '&&', '&', $label); + + return $clean ? $label : array($label, $access); +} function hyperlink_back($center=true) { @@ -73,9 +94,10 @@ function hyperlink_back($center=true) function hyperlink_no_params($target, $label, $center=true) { + $pars = access_string($label); if ($center) echo "
"; - echo "$label\n"; + echo "$pars[0]\n"; if ($center) echo "
"; } @@ -91,9 +113,10 @@ function hyperlink_no_params_td($target, $label) function hyperlink_params($target, $label, $params, $center=true) { + $pars = access_string($label); if ($center) echo "
"; - echo "$label\n"; + echo "$pars[0]\n"; if ($center) echo "
"; } @@ -109,9 +132,10 @@ function hyperlink_params_td($target, $label, $params) function hyperlink_params_separate($target, $label, $params, $center=false) { + $pars = access_string($label); if ($center) echo "
"; - echo "$label\n"; + echo "$pars[0]\n"; if ($center) echo "
"; } diff --git a/includes/ui/ui_input.inc b/includes/ui/ui_input.inc index 3c2151bc..3817bc9f 100644 --- a/includes/ui/ui_input.inc +++ b/includes/ui/ui_input.inc @@ -94,50 +94,45 @@ function hidden($name, $value=null, $echo=true) return $ret; } -//--------------------------------------------------------------------------------- -// Submit button. -// $async parameter can have 3 values: -// null - fallback button not visible in js enabled mode -// false - normal submit via form action -// true - when js is on submition via ajax call -// 'process' - ditto with processing indicator in msgbox -// -function submit($name, $value, $echo=true, $title=false, $async=false) +function submit($name, $value, $echo=true, $title=false, $async=false, $icon=false) { - + global $path_to_root; + default_focus($name); - $submit_str = "\n"; + .">$value" + .($icon ? "" : '') + ."\n"; if ($echo) echo $submit_str; else return $submit_str; } -function submit_center($name, $value, $echo=true, $title=false, $async=false) +function submit_center($name, $value, $echo=true, $title=false, $async=false, $icon=false) { echo "
"; - submit($name, $value, $echo, $title, $async); + submit($name, $value, $echo, $title, $async, $icon); echo "
"; } -function submit_center_first($name, $value, $title=false, $async=false) +function submit_center_first($name, $value, $title=false, $async=false, $icon=false) { echo "
"; - submit($name, $value, true, $title, $async); + submit($name, $value, true, $title, $async, $icon); echo " "; } -function submit_center_last($name, $value, $title=false, $async=false) +function submit_center_last($name, $value, $title=false, $async=false, $icon=false) { echo " "; - submit($name, $value, true, $title, $async); + submit($name, $value, true, $title, $async, $icon); echo "
"; } diff --git a/js/JsHttpRequest.js b/js/JsHttpRequest.js index d89ff4b2..654362dc 100644 --- a/js/JsHttpRequest.js +++ b/js/JsHttpRequest.js @@ -255,7 +255,7 @@ function JsHttpRequest() { if (tn == 'FORM') { // FORM itself is passed. formAdded = true; - } else if (tn == 'INPUT' || tn == 'TEXTAREA' || tn == 'SELECT') { + } else if (tn == 'INPUT' || tn == 'TEXTAREA' || tn == 'SELECT' || tn == 'BUTTON') { // This is a single form elemenent. } else { return this._error('inv_form_el', (v.name||''), v.tagName); diff --git a/js/inserts.js b/js/inserts.js index 0eb4369f..01fad998 100644 --- a/js/inserts.js +++ b/js/inserts.js @@ -1,4 +1,8 @@ var _focus; +var _hotkeys = { + 'alt': false, // whether is the Alt key pressed + 'focus': -1 // currently selected indeks of document.links +}; function debug(msg) { box = document.getElementById('msgbox') @@ -142,7 +146,7 @@ function _set_combo_select(e) { // F4: call related database editor - not available in non-js fallback mode JsHttpRequest.request('_'+this.name+'_editor', this.form); return false; // prevent default binding - // TODO: preventDefault, stopPropagation when needed + // TODO: stopPropagation when needed } } } @@ -151,6 +155,20 @@ function _set_combo_select(e) { Behaviour definitions */ var inserts = { + 'form': function(e) { + e.onkeydown = function(ev) { + ev = ev||window.event; + key = ev.keyCode||ev.which; + if((ev.ctrlKey && key == 13) || key == 27) { + ev.cancelBubble = true; + if(ev.stopPropagation) ev.stopPropagation(); +// here ctrl-enter/escape support + ev.returnValue = false; + return false; + } + return true; + } + }, 'input': function(e) { if(e.onfocus==undefined) { e.onfocus = function() { @@ -185,7 +203,7 @@ var inserts = { // this shows divs for js enabled browsers only e.style.display = 'block'; }, - 'input.ajaxsubmit,input.editbutton,input.navibutton': + 'input.ajaxsubmit','button.ajaxsubmit,button.editbutton,button.navibutton': function(e) { e.onclick = function() { if (this.getAttribute('aspect') == 'process') @@ -266,7 +284,68 @@ var inserts = { } */ }; +function stopEv(ev) { + ev.returnValue = false; + ev.cancelBubble = true; + if(ev.preventDefault) ev.preventDefault(); + return false; +} +/* + Modified accesskey system. While Alt key is pressed letter keys moves + focus to next marked link. Alt key release activates focused link. +*/ +function setHotKeys() { + document.onkeydown = function(ev) { + ev = ev||window.event; + key = ev.keyCode||ev.which; + if (key == 18) { // start selection + _hotkeys.alt = true; + _hotkeys.focus = -1; + return stopEv(ev); + } else + if (key == 27) { // cancel selection + _hotkeys.alt = false; + _hotkeys.focus = -1; + return stopEv(ev); + } + else if (_hotkeys.alt && ((key>47 && key<58) || (key>64 && key<91))) { + var n = _hotkeys.focus; + var l = document.links; + var cnt = l.length; + key = String.fromCharCode(key); + for (var i=0; i=0) { + window.location = document.links[_hotkeys.focus].href; + } + } + return stopEv(ev); + } + return true; + } +} Behaviour.register(inserts); Behaviour.addLoadEvent(setFocus); +Behaviour.addLoadEvent(setHotKeys); diff --git a/js/utils.js b/js/utils.js index 761917a2..b2fc71c4 100644 --- a/js/utils.js +++ b/js/utils.js @@ -183,7 +183,11 @@ function goBack() { } function setFocus(name, byId) { - + if(document.location.pathname.indexOf('index.php') != -1) { + // this is application menu page - set focus on first link + // var el = document.getElementById('msgbox'); + // TODO find first link after msgbox and set focus + } if(!name) { if (_focus) name = _focus; // last focus set in onfocus handlers diff --git a/reporting/includes/reports_classes.inc b/reporting/includes/reports_classes.inc index 0dabe11c..e180ed3b 100644 --- a/reporting/includes/reports_classes.inc +++ b/reporting/includes/reports_classes.inc @@ -31,11 +31,12 @@ class BoxReports foreach($this->ar_classes as $key=>$value) { $style = $class_counter==0 ? '' : $style = "style='display:none'"; - $st_classes .= "$key
"; + $acc = access_string($key); + $st_classes .= "$acc[0]
"; $st_reports .= ""; foreach($value as $report) - { - $st_reports .= ""; + { $acc = access_string($report->name); + $st_reports .= ""; $st_params .= "
" . _("Reports For Class: ") . " $key
" . $report->name . "
$acc[0]
"; $st_params .= ""; } diff --git a/sales/manage/customers.php b/sales/manage/customers.php index 2605cae4..944d63e0 100644 --- a/sales/manage/customers.php +++ b/sales/manage/customers.php @@ -274,7 +274,9 @@ credit_status_list_row(_("Credit Status:"), 'credit_status', $_POST['credit_stat if (!$new_customer) { start_row(); echo ''._('Customer branches').':'; - hyperlink_params_td($path_to_root . "/sales/manage/customer_branches.php",''. (count($_SESSION['Context']) ? _("Select or Add") : _("Add or Edit")).'', "debtor_no=".$_POST['customer_id']); + hyperlink_params_td($path_to_root . "/sales/manage/customer_branches.php", + ''. (count($_SESSION['Context']) ? _("Select or &Add") : _("&Add or Edit ")).'', + "debtor_no=".$_POST['customer_id']); end_row(); } end_table(); diff --git a/sales/sales_order_entry.php b/sales/sales_order_entry.php index 9891d0c5..70ca31a4 100644 --- a/sales/sales_order_entry.php +++ b/sales/sales_order_entry.php @@ -487,14 +487,15 @@ if ($customer_error == "") { if ($_SESSION['Items']->trans_no == 0) { submit_center_first('ProcessOrder', $porder, - _('Check entered data and save document'), true); + _('Check entered data and save document'), true, 'confirm.png'); } else { submit_center_first('ProcessOrder', $corder, - _('Validate changes and update document'), true); + _('Validate changes and update document'), true, 'confirm.png'); } submit_center_last('CancelOrder', $cancelorder, - _('Cancels document entry or removes sales order when editing an old document')); + _('Cancels document entry or removes sales order when editing an old document'), + true, 'escape.png'); } else { display_error($customer_error); } diff --git a/themes/aqua/default.css b/themes/aqua/default.css index e7323a8a..d0d87e99 100644 --- a/themes/aqua/default.css +++ b/themes/aqua/default.css @@ -71,6 +71,17 @@ a:hover { text-decoration: underline; } +button { + font-size: 11px; + border: 1px #0066cc solid; + padding: 1px 0px; +} + +button img, span { + padding: 0px 2px ; + vertical-align: middle; +} + .login { background-color: #ffffff; border: none; diff --git a/themes/aqua/renderer.php b/themes/aqua/renderer.php index ad4cd21e..8e42fca7 100644 --- a/themes/aqua/renderer.php +++ b/themes/aqua/renderer.php @@ -37,9 +37,10 @@ echo "
"; foreach($applications as $app => $name) { + $acc = access_string($name); echo "" .$name . ""; + SID ."'$acc[1]>" .$acc[0] . ""; } echo "
"; @@ -129,8 +130,11 @@ foreach ($module->lappfunctions as $appfunction) { - if ($_SESSION["wa_current_user"]->can_access_page($appfunction->access)) - echo " " . $appfunction->label . "
"; + if ($_SESSION["wa_current_user"]->can_access_page($appfunction->access)) + { + $lnk = access_string($appfunction->label); + echo "$lnk[0]
"; + } } echo ""; if (sizeof($module->rappfunctions) > 0) @@ -138,8 +142,11 @@ echo ""; foreach ($module->rappfunctions as $appfunction) { - if ($_SESSION["wa_current_user"]->can_access_page($appfunction->access)) - echo " " . $appfunction->label . "
"; + if ($_SESSION["wa_current_user"]->can_access_page($appfunction->access)) + { + $lnk = access_string($appfunction->label); + echo "$lnk[0]
"; + } } echo ""; } diff --git a/themes/cool/default.css b/themes/cool/default.css index fc84e8b9..85f8342d 100644 --- a/themes/cool/default.css +++ b/themes/cool/default.css @@ -71,6 +71,16 @@ a:hover { text-decoration: underline; } +button { + font-size: 11px; + border: 1px #0066cc solid; + padding: 1px 0px; +} + +button img, span { + padding: 0px 2px ; + vertical-align: middle; +} .login { background-color: #ffffff; diff --git a/themes/cool/renderer.php b/themes/cool/renderer.php index ad4cd21e..8e42fca7 100644 --- a/themes/cool/renderer.php +++ b/themes/cool/renderer.php @@ -37,9 +37,10 @@ echo "
"; foreach($applications as $app => $name) { + $acc = access_string($name); echo "" .$name . ""; + SID ."'$acc[1]>" .$acc[0] . ""; } echo "
"; @@ -129,8 +130,11 @@ foreach ($module->lappfunctions as $appfunction) { - if ($_SESSION["wa_current_user"]->can_access_page($appfunction->access)) - echo " " . $appfunction->label . "
"; + if ($_SESSION["wa_current_user"]->can_access_page($appfunction->access)) + { + $lnk = access_string($appfunction->label); + echo "$lnk[0]
"; + } } echo ""; if (sizeof($module->rappfunctions) > 0) @@ -138,8 +142,11 @@ echo ""; foreach ($module->rappfunctions as $appfunction) { - if ($_SESSION["wa_current_user"]->can_access_page($appfunction->access)) - echo " " . $appfunction->label . "
"; + if ($_SESSION["wa_current_user"]->can_access_page($appfunction->access)) + { + $lnk = access_string($appfunction->label); + echo "$lnk[0]
"; + } } echo ""; } diff --git a/themes/default/default.css b/themes/default/default.css index a32fa4e9..ef361e15 100644 --- a/themes/default/default.css +++ b/themes/default/default.css @@ -71,6 +71,17 @@ a:hover { text-decoration: underline; } +button { + font-size: 11px; + border: 1px #0066cc solid; + padding: 1px 0px; +} + +button img, span { + padding: 0px 2px ; + vertical-align: middle; +} + .login { background-color: #ffffff; border: none; diff --git a/themes/default/renderer.php b/themes/default/renderer.php index 51cbc8e4..00bff4ea 100644 --- a/themes/default/renderer.php +++ b/themes/default/renderer.php @@ -37,9 +37,10 @@ echo "
"; foreach($applications as $app => $name) { + $acc = access_string($name); echo "" .$name . ""; + SID ."'$acc[1]>" .$acc[0] . ""; } echo "
"; echo ""; @@ -129,8 +130,11 @@ foreach ($module->lappfunctions as $appfunction) { - if ($_SESSION["wa_current_user"]->can_access_page($appfunction->access)) - echo " " . $appfunction->label . "
"; + if ($_SESSION["wa_current_user"]->can_access_page($appfunction->access)) + { + $lnk = access_string($appfunction->label); + echo "$lnk[0]
"; + } } echo ""; if (sizeof($module->rappfunctions) > 0) @@ -138,8 +142,11 @@ echo ""; foreach ($module->rappfunctions as $appfunction) { - if ($_SESSION["wa_current_user"]->can_access_page($appfunction->access)) - echo " " . $appfunction->label . "
"; + if ($_SESSION["wa_current_user"]->can_access_page($appfunction->access)) + { + $lnk = access_string($appfunction->label); + echo "$lnk[0]
"; + } } echo ""; }