From: Janusz Dobrowolski Date: Mon, 16 Mar 2009 19:19:13 +0000 (+0000) Subject: Support for default buttons with Ctrl-Enter/Escpae hotkeys, arrow navigation in menus. X-Git-Tag: v2.4.2~19^2~1484 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=061f4eff6493a6cca071338156225401ae849d72;p=fa-stable.git Support for default buttons with Ctrl-Enter/Escpae hotkeys, arrow navigation in menus. --- diff --git a/includes/page/footer.inc b/includes/page/footer.inc index 2ce07a29..61c73118 100644 --- a/includes/page/footer.inc +++ b/includes/page/footer.inc @@ -21,6 +21,7 @@ function page_footer($no_menu=false, $is_index=false) include_once($path_to_root."/themes/".user_theme()."/renderer.php"); $rend = new renderer(); $rend->menu_footer($no_menu, $is_index); + echo ""; echo "\n"; } diff --git a/includes/ui/ui_controls.inc b/includes/ui/ui_controls.inc index 8546255b..fe23de17 100644 --- a/includes/ui/ui_controls.inc +++ b/includes/ui/ui_controls.inc @@ -9,21 +9,21 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ +function get_post($name, $dflt='') +{ + return ((!isset($_POST[$name]) || $_POST[$name] === '') ? $dflt : $_POST[$name]); +} //--------------------------------------------------------------------------------- -function start_form($multi=false, $sid=false, $action="", $name="") +function start_form($multi=false, $dummy=false, $action="", $name="") { + // $dummy - leaved for compatibility with 2.0 API + if ($name != "") $name = "name='$name'"; if ($action == "") $action = $_SERVER['PHP_SELF']; - if ($sid) - { - if (strpos($action, "?")) - $action .= "&" . SID; - else - $action .= "?" . SID; - } + if ($multi) echo "
\n"; else @@ -125,7 +125,6 @@ function hyperlink_back($center=true) { if ($center) echo "
"; - //echo ""._("Back")."\n"; echo "

"._("Back")."

\n"; if ($center) echo "
"; @@ -134,10 +133,11 @@ function hyperlink_back($center=true) function hyperlink_no_params($target, $label, $center=true) { + $id = default_focus(); $pars = access_string($label); if ($center) echo "
"; - echo "$pars[0]\n"; + echo "$pars[0]\n"; if ($center) echo "
"; } @@ -149,14 +149,65 @@ function hyperlink_no_params_td($target, $label) echo "\n"; } +function viewer_link($label, $url='', $class='', $id='', $icon=null) +{ + global $path_to_root; + + if ($class != '') + $class = " class='$class'"; + + if ($id != '') + $class = " id='$id'"; + + if ($url != "") + { + $pars = access_string($label); + if (user_graphic_links() && $icon) + $pars[0] = set_icon($icon, $pars[0]); + $preview_str = "$pars[0]"; + } + else + $preview_str = $label; + + return $preview_str; +} + +function menu_link($url, $label, $id=null) +{ + + $id = default_focus($id); + $pars = access_string($label); + return "$pars[0]"; +} + +function submenu_option($title, $url, $id=null) +{ + global $path_to_root; + display_note(menu_link($path_to_root . $url, $title, $id)); + echo '
'; +} + +function submenu_view($title, $type, $number, $id=null) +{ + display_note(get_trans_view_str($type, $number, $title, false, 'menu_option', $id)); + echo '
'; +} + +function submenu_print($title, $type, $number, $id=null) +{ + display_note(print_document_link($number, $title, true, $type, false, 'menu_option', $id)); + echo '
'; +} //----------------------------------------------------------------------------------- function hyperlink_params($target, $label, $params, $center=true) { + $id = default_focus(); + $pars = access_string($label); if ($center) echo "
"; - echo "$pars[0]\n"; + echo "$pars[0]\n"; if ($center) echo "
"; } @@ -172,10 +223,12 @@ function hyperlink_params_td($target, $label, $params) function hyperlink_params_separate($target, $label, $params, $center=false) { + $id = default_focus(); + $pars = access_string($label); if ($center) echo "
"; - echo "$pars[0]\n"; + echo "$pars[0]\n"; if ($center) echo "
"; } diff --git a/includes/ui/ui_input.inc b/includes/ui/ui_input.inc index 3da07206..434117e6 100644 --- a/includes/ui/ui_input.inc +++ b/includes/ui/ui_input.inc @@ -9,11 +9,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ - -function get_post($name, $dflt='') -{ - return ((!isset($_POST[$name]) || $_POST[$name] === '') ? $dflt : $_POST[$name]); -} // // Sets local POST value and adds Value to ajax posting if needed // @@ -103,21 +98,48 @@ function hidden($name, $value=null, $echo=true) else return $ret; } - -function submit($name, $value, $echo=true, $title=false, $async=false, $icon=false) +/* + Universal submit form button. + $atype - type of submit: + Normal submit: + false - normal button; optional icon + null - button visible only in fallback mode; optional icon + Ajax submit: + true - standard button; optional icon + 'process' - displays progress bar during call; optional icon + 'default' - default form submit on Ctrl-Enter press; dflt ICON_OK icon + 'cancel' - cancel form entry on Escape press; dflt ICON_CANCEL +*/ +function submit($name, $value, $echo=true, $title=false, $atype=false, $icon=false) { global $path_to_root; - + + $aspect=''; + if (!is_bool($atype)) // necessary: switch uses '==' + switch($atype) { + case 'process': + $aspect = " aspect='process'"; break; + case 'default': + $aspect = " aspect='default'"; + if ($icon===false) $icon=ICON_SUBMIT; break; + case 'cancel': + $aspect = " aspect='cancel'"; + if ($icon===false) $icon=ICON_ESCAPE; break; + case null: + $aspect = fallback_mode() ? + " aspect='fallback'" : " style='display:none;'"; break; + } + default_focus($name); $submit_str = "\n"; if ($echo) echo $submit_str; diff --git a/includes/ui/ui_view.inc b/includes/ui/ui_view.inc index 1d4f1fc1..d1262f12 100644 --- a/includes/ui/ui_view.inc +++ b/includes/ui/ui_view.inc @@ -14,46 +14,34 @@ include_once($path_to_root . "/includes/types.inc"); //-------------------------------------------------------------------------------------- -function get_supplier_trans_view_str($type, $trans_no, $label="", $icon=false) +function get_supplier_trans_view_str($type, $trans_no, $label="", $icon=false, + $class='', $id='') { - global $path_to_root; - - $viewer = ""; + $viewer = "purchasing/view/"; if ($type == systypes::po()) - $viewer = "view_po.php"; + $viewer .= "view_po.php"; elseif ($type == 20) - $viewer = "view_supp_invoice.php"; + $viewer .= "view_supp_invoice.php"; elseif ($type == 21) - $viewer = "view_supp_credit.php"; + $viewer .= "view_supp_credit.php"; elseif ($type == 22) $viewer = "view_supp_payment.php"; elseif ($type == 25) - $viewer = "view_grn.php"; + $viewer .= "view_grn.php"; else return null; + $viewer .= "?trans_no=$trans_no"; if ($label == "") $label = $trans_no; - if ($viewer != "") - { - $pars = access_string($label); - if (user_graphic_links() && $icon) - $pars[0] = set_icon($icon, $pars[0]); - $preview_str = "$pars[0]"; - } - else - $preview_str = $label; - - return $preview_str; + return viewer_link($label, $viewer, $class, $id, $icon); } //-------------------------------------------------------------------------------------- -function get_gl_view_str($type, $trans_no, $label="", $force=false) +function get_gl_view_str($type, $trans_no, $label="", $force=false, $class='', $id='') { - global $path_to_root; - if (!$force && !user_show_gl_info()) return ""; @@ -63,12 +51,10 @@ function get_gl_view_str($type, $trans_no, $label="", $force=false) $label = _("GL"); $icon = ICON_GL; } - $pars = access_string($label); - if (user_graphic_links() && $icon) - $pars[0] = set_icon($icon, $pars[0]); - $gl_view = "$pars[0]"; - return $gl_view; + return viewer_link($label, + "gl/view/gl_trans_view.php?type_id=$type&trans_no=$trans_no", + $class, $id, $icon); } //-------------------------------------------------------------------------------------- @@ -82,21 +68,21 @@ function get_gl_view_str_cell($type, $trans_no, $label="") //-------------------------------------------------------------------------------------- -function get_customer_trans_view_str($type, $trans_no, $label="", $icon=false) +function get_customer_trans_view_str($type, $trans_no, $label="", $icon=false, + $class='', $id='') { - global $path_to_root; + $viewer = "sales/view/"; - $viewer = ""; if ($type == 10) - $viewer = "view_invoice.php"; + $viewer .= "view_invoice.php"; elseif ($type == 11) - $viewer = "view_credit.php"; + $viewer .= "view_credit.php"; elseif ($type == 12) - $viewer = "view_receipt.php"; + $viewer .= "view_receipt.php"; elseif ($type == 13) - $viewer = "view_dispatch.php"; + $viewer .= "view_dispatch.php"; elseif ($type == 30) - $viewer = "view_sales_order.php"; + $viewer .= "view_sales_order.php"; else return null; @@ -110,27 +96,20 @@ function get_customer_trans_view_str($type, $trans_no, $label="", $icon=false) $lbl = $trans; if($preview_str!='') $preview_str .= ','; - if ($viewer != "") - { - $pars = access_string($lbl); - if (user_graphic_links() && $icon) - $pars[0] = set_icon($icon, $pars[0]); - $preview_str .= "$pars[0]"; - } - else - $preview_str .= $lbl; - } + $preview_str .= viewer_link($lbl, $viewer."?trans_no=$trans", + $class, $id, $icon); - return $preview_str; + } + return $preview_str; } //-------------------------------------------------------------------------------------- -function get_banking_trans_view_str($type, $trans_no, $label="", $icon=false) +function get_banking_trans_view_str($type, $trans_no, $label="", + $icon=false, $class='', $id='') { - global $path_to_root; - - $viewer = ""; + if ($label == "") + $label = $trans_no; if ($type == 4) $viewer = "bank_transfer_view.php"; @@ -139,144 +118,101 @@ function get_banking_trans_view_str($type, $trans_no, $label="", $icon=false) elseif ($type == 2) $viewer = "gl_deposit_view.php"; elseif ($type == 0) - $viewer = ""; + return $label; else return null; - if ($label == "") - $label = $trans_no; - - if ($viewer != "") - { - $pars = access_string($label); - if (user_graphic_links() && $icon) - $pars[0] = set_icon($icon, $pars[0]); - $preview_str = "$pars[0]"; - } - else - $preview_str = $label; - - return $preview_str; + return viewer_link($label, "gl/view/$viewer?trans_no=$trans_no", + $class, $id, $icon); } //-------------------------------------------------------------------------------------- -function get_inventory_trans_view_str($type, $trans_no, $label="", $icon=false) +function get_inventory_trans_view_str($type, $trans_no, $label="", + $icon=false, $class='', $id='') { - global $path_to_root; - - $viewer = ""; + $viewer = "inventory/view/"; if ($type == systypes::inventory_adjustment()) - $viewer = "view_adjustment.php"; + $viewer .= "view_adjustment.php"; elseif ($type == systypes::location_transfer()) - $viewer = "view_transfer.php"; + $viewer .= "view_transfer.php"; else return null; + $viewer .= "?trans_no=$trans_no"; if ($label == "") $label = $trans_no; - if ($viewer != "") - { - $pars = access_string($label); - if (user_graphic_links() && $icon) - $pars[0] = set_icon($icon, $pars[0]); - $preview_str = "$pars[0]"; - } - else - $preview_str = $label; - - return $preview_str; + return viewer_link($label, $viewer, $class, $id, $icon); } //-------------------------------------------------------------------------------------- -function get_manufacturing_trans_view_str($type, $trans_no, $label="", $icon=false) +function get_manufacturing_trans_view_str($type, $trans_no, $label="", + $icon=false, $class='', $id='') { - global $path_to_root; - - $viewer = ""; + $viewer = "manufacturing/view/"; if ($type == 28) - $viewer = "wo_issue_view.php"; + $viewer .= "wo_issue_view.php"; elseif ($type == 29) - $viewer = "wo_production_view.php"; + $viewer .= "wo_production_view.php"; elseif ($type == systypes::work_order()) - $viewer = "work_order_view.php"; + $viewer .= "work_order_view.php"; else return null; + $viewer .= "?trans_no=$trans_no"; + if ($label == "") $label = $trans_no; - if ($viewer != "") - { - $pars = access_string($label); - if (user_graphic_links() && $icon) - $pars[0] = set_icon($icon, $pars[0]); - $preview_str = "$pars[0]"; - } - else - $preview_str = $label; - - return $preview_str; + return viewer_link($label, $viewer, $class, $id, $icon); } //-------------------------------------------------------------------------------------- -function get_dimensions_trans_view_str($type, $trans_no, $label="", $icon=false) +function get_dimensions_trans_view_str($type, $trans_no, $label="", $icon=false, + $class='', $id='') { - global $path_to_root; - - $viewer = ""; - if ($type == 40) - $viewer = "view_dimension.php"; + $viewer = "dimensions/view_dimension.php?trans_no=$trans_no"; else return null; if ($label == "") $label = $trans_no; - if ($viewer != "") - { - $pars = access_string($label); - if (user_graphic_links() && $icon) - $pars[0] = set_icon($icon, $pars[0]); - $preview_str = "$pars[0]"; - } - else - $preview_str = $label; - - return $preview_str; + return viewer_link($label, $viewer, $class, $id, $icon); } //-------------------------------------------------------------------------------------- -function get_trans_view_str($type, $trans_no, $label="", $icon=false) +function get_trans_view_str($type, $trans_no, $label="", $icon=false, + $class='', $id='') { - $view_str = get_customer_trans_view_str($type, $trans_no, $label, $icon); + $view_str = get_customer_trans_view_str($type, $trans_no, $label, $icon, $class, $id); if ($view_str != null) return $view_str; - $view_str = get_supplier_trans_view_str($type, $trans_no, $label, $icon); + $view_str = get_supplier_trans_view_str($type, $trans_no, $label, $icon, $class, $id); if ($view_str != null) return $view_str; - $view_str = get_banking_trans_view_str($type, $trans_no, $label, $icon); + $view_str = get_banking_trans_view_str($type, $trans_no, $label, $icon, $class, $id); if ($view_str != null) return $view_str; - $view_str = get_inventory_trans_view_str($type, $trans_no, $label, $icon); + $view_str = get_inventory_trans_view_str($type, $trans_no, $label, $icon, $class, $id); if ($view_str != null) return $view_str; - $view_str = get_manufacturing_trans_view_str($type, $trans_no, $label, $icon); + $view_str = get_manufacturing_trans_view_str($type, $trans_no, $label, $icon, $class, $id); if ($view_str != null) return $view_str; - $view_str = get_dimensions_trans_view_str($type, $trans_no, $label, $icon); + $view_str = get_dimensions_trans_view_str($type, $trans_no, $label, $icon, $class, $id); if ($view_str != null) return $view_str; @@ -674,11 +610,15 @@ function set_focus($name, $form_no=0) { } // // Set default focus on first field $name if not set yet -// -function default_focus($name, $form_no=0) { +// Returns unique name if $name=null +// +function default_focus($name=null, $form_no=0) { + if ($name==null) + $name = uniqid('_el'); if (!isset($_POST['_focus'])) { set_focus($name); } + return $name; } function get_js_png_fix() diff --git a/js/inserts.js b/js/inserts.js index 0c0067fd..120c2ff2 100644 --- a/js/inserts.js +++ b/js/inserts.js @@ -11,7 +11,7 @@ var _focus; var _hotkeys = { 'alt': false, // whether is the Alt key pressed - 'focus': -1 // currently selected indeks of document.links + 'focus': -1, // currently selected indeks of document.links }; function debug(msg) { @@ -172,7 +172,13 @@ var inserts = { if((ev.ctrlKey && key == 13) || key == 27) { ev.cancelBubble = true; if(ev.stopPropagation) ev.stopPropagation(); -// here ctrl-enter/escape support + // activate submit/escape form + for (var i=0; ip0.y)) || (dir==38 && (p.yp0.x)))) { + var l1 = (p.y-p0.y)*(p.y-p0.y)+(p.x-p0.x)*(p.x-p0.x); + if ((l1 $val) { $pars[$par] = "$par=".urlencode($val); } $pars[] = 'REP_ID='.urlencode($rep); $url .= implode ('&', $pars); - $class = $pdf_debug ? '' : "class='printlink'"; + + if ($class != '') + $class = $pdf_debug ? '' : " class='$class'"; + if ($id != '') + $id = " id='$id'"; $pars = access_string($link_text); if (user_graphic_links() && $icon) $pars[0] = set_icon($icon, $pars[0]); - return "$pars[0]"; + return "$pars[0]"; } function get_first_bank_account() diff --git a/themes/aqua/default.css b/themes/aqua/default.css index 1377e208..1c0f44c5 100644 --- a/themes/aqua/default.css +++ b/themes/aqua/default.css @@ -70,7 +70,7 @@ a:active { text-decoration: none; } -a:hover { +a:hover, a:focus { color: #2d8628; text-decoration: underline; } diff --git a/themes/aqua/renderer.php b/themes/aqua/renderer.php index c671e8e6..87532dcb 100644 --- a/themes/aqua/renderer.php +++ b/themes/aqua/renderer.php @@ -51,8 +51,8 @@ { $acc = access_string($app->name); echo "id ? "class='selected' " : ""). - "href='$local_path_to_root/index.php?application=".$app->id. - SID ."'$acc[1]>" .$acc[0] . ""; + "href='$local_path_to_root/index.php?application=".$app->id + ."'$acc[1]>" .$acc[0] . ""; } echo ""; @@ -151,10 +151,7 @@ if ($appfunction->label == "") echo " 
"; else - { - $lnk = access_string($appfunction->label); - echo "$img$lnk[0]
"; - } + echo $img.menu_link($appfunction->link, $appfunction->label)."
\n"; } } echo ""; @@ -168,10 +165,7 @@ if ($appfunction->label == "") echo " 
"; else - { - $lnk = access_string($appfunction->label); - echo "$img$lnk[0]
"; - } + echo $img.menu_link($appfunction->link, $appfunction->label)."
\n"; } } echo ""; diff --git a/themes/cool/default.css b/themes/cool/default.css index a6439fa3..768029ec 100644 --- a/themes/cool/default.css +++ b/themes/cool/default.css @@ -70,7 +70,7 @@ a:active { text-decoration: none; } -a:hover { +a:hover, a:focus { color: #2d8628; text-decoration: underline; } diff --git a/themes/cool/renderer.php b/themes/cool/renderer.php index 34f1f355..f98e6d16 100644 --- a/themes/cool/renderer.php +++ b/themes/cool/renderer.php @@ -51,8 +51,8 @@ { $acc = access_string($app->name); echo "id ? "class='selected' " : ""). - "href='$local_path_to_root/index.php?application=".$app->id. - SID ."'$acc[1]>" .$acc[0] . ""; + "href='$local_path_to_root/index.php?application=".$app->id + ."'$acc[1]>" .$acc[0] . ""; } echo ""; @@ -150,10 +150,7 @@ if ($appfunction->label == "") echo " 
"; else - { - $lnk = access_string($appfunction->label); - echo "$img$lnk[0]
"; - } + echo $img.menu_link($appfunction->link, $appfunction->label)."
\n"; } } echo ""; @@ -167,10 +164,7 @@ if ($appfunction->label == "") echo " 
"; else - { - $lnk = access_string($appfunction->label); - echo "$img$lnk[0]
"; - } + echo $img.menu_link($appfunction->link, $appfunction->label)."
\n"; } } echo ""; diff --git a/themes/default/default.css b/themes/default/default.css index febd2427..70a132b1 100644 --- a/themes/default/default.css +++ b/themes/default/default.css @@ -70,7 +70,7 @@ a:active { text-decoration: none; } -a:hover { +a:hover, a:focus { color: #2d8628; text-decoration: underline; } diff --git a/themes/default/images/escape.png b/themes/default/images/escape.png index c14484dc..4d84554d 100644 Binary files a/themes/default/images/escape.png and b/themes/default/images/escape.png differ diff --git a/themes/default/renderer.php b/themes/default/renderer.php index 473cf82f..6c4db65c 100644 --- a/themes/default/renderer.php +++ b/themes/default/renderer.php @@ -13,6 +13,7 @@ { function wa_header() { +// add_js_ufile("themes/default/renderer.js"); page(_("Main Menu"), false, true); } @@ -24,7 +25,6 @@ function menu_header($title, $no_menu, $is_index) { global $path_to_root, $help_base_url, $db_connections; - // you can owerride the table styles from config.php here, if you want. //global $table_style, $table_style2; //$table_style = "cellpadding=3 border=1 bordercolor='#8cacbb' style='border-collapse: collapse'"; @@ -51,9 +51,10 @@ foreach($applications as $app) { $acc = access_string($app->name); - echo "id ? "class='selected' " : ""). - "href='$local_path_to_root/index.php?application=".$app->id. - SID ."'$acc[1]>" .$acc[0] . ""; + echo "id ? + ("class='selected'") : "") + ." href='$local_path_to_root/index.php?application=".$app->id + ."'$acc[1]>" .$acc[0] . ""; } echo ""; echo ""; @@ -151,10 +152,7 @@ if ($appfunction->label == "") echo " 
"; else - { - $lnk = access_string($appfunction->label); - echo "$img$lnk[0]
"; - } + echo $img.menu_link($appfunction->link, $appfunction->label)."
\n"; } } echo ""; @@ -168,10 +166,7 @@ if ($appfunction->label == "") echo " 
"; else - { - $lnk = access_string($appfunction->label); - echo "$img$lnk[0]
"; - } + echo $img.menu_link($appfunction->link, $appfunction->label)."
\n"; } } echo "";