X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=includes%2Fui%2Fui_input.inc;h=054af15e98ee463c3587ab87b11e4908de4089f1;hb=0388050f6d4c6c7c9a9db06d2f31aa8879da69a8;hp=a85f41a8f3af6285c8a1bf35280fe1887b3532c6;hpb=2150d50b1dbe375fffa2f868ad2bdd791f4ec894;p=fa-stable.git
diff --git a/includes/ui/ui_input.inc b/includes/ui/ui_input.inc
index a85f41a8..054af15e 100644
--- a/includes/ui/ui_input.inc
+++ b/includes/ui/ui_input.inc
@@ -37,6 +37,15 @@ function find_submit($prefix, $numeric=true)
}
return $numeric ? -1 : null;
}
+/*
+ Helper function.
+ Returns true if input $name with $submit_on_change option set is subject to update.
+*/
+function input_changed($name)
+{
+ return isset($_POST['_'.$name.'_changed']);
+}
+
//------------------------------------------------------------------------------
//
// Helper function for simple db table editor pages
@@ -47,11 +56,12 @@ function simple_page_mode($numeric_id = true)
$default = $numeric_id ? -1 : '';
$selected_id = get_post('selected_id', $default);
- foreach (array('ADD_ITEM', 'UPDATE_ITEM', 'RESET') as $m) {
+ foreach (array('ADD_ITEM', 'UPDATE_ITEM', 'RESET', 'CLONE') as $m) {
if (isset($_POST[$m])) {
$Ajax->activate('_page_body');
- if ($m == 'RESET')
+ if ($m == 'RESET' || $m == 'CLONE')
$selected_id = $default;
+ unset($_POST['_focus']);
$Mode = $m; return;
}
}
@@ -74,7 +84,7 @@ function simple_page_mode($numeric_id = true)
//
// Read numeric value from user formatted input
//
-function input_num($postname=null, $dflt=null)
+function input_num($postname=null, $dflt=0)
{
if (!isset($_POST[$postname]) || $_POST[$postname] == "")
return $dflt;
@@ -83,10 +93,16 @@ function input_num($postname=null, $dflt=null)
}
//---------------------------------------------------------------------------------
+//
+// Thanks to hidden fields buffering hidden() helper can be used in arbitrary places and
+// proper html structure is still preserved. Buffered hidden fields are output on the nearest
+// table or form closing tag (see output_hidden()).
+//
+$hidden_fields = array();
function hidden($name, $value=null, $echo=true)
{
- global $Ajax;
+ global $Ajax, $hidden_fields;
if ($value === null)
$value = get_post($name);
@@ -94,7 +110,7 @@ function hidden($name, $value=null, $echo=true)
$ret = "";
$Ajax->addUpdate($name, $name, $value);
if ($echo)
- echo $ret."\n";
+ $hidden_fields[] = $ret;
else
return $ret;
}
@@ -106,31 +122,47 @@ function hidden($name, $value=null, $echo=true)
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
+ 'selector' - ditto with closing current popup editor window
'cancel' - cancel form entry on Escape press; dflt ICON_CANCEL
+ 'process' - displays progress bar during call; optional icon
+ 'nonajax' - ditto, non-ajax submit
+
+ $atype can contain also multiply type selectors separated by space,
+ however make sense only combination of 'process' and one of defualt/selector/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;
- }
+ if ($atype === null) {
+ $aspect = fallback_mode() ? " aspect='fallback'" : " style='display:none;'";
- default_focus($name);
+ } elseif (!is_bool($atype)) { // necessary: switch uses '=='
+
+ $aspect = " aspect='$atype' ";
+ $types = explode(' ', $atype);
+
+ foreach ($types as $type) {
+ switch($type) {
+ case 'selector':
+ $aspect = " aspect='selector' rel = '$value'";
+ $value = _("Select");
+ if ($icon===false) $icon=ICON_SUBMIT; break;
+
+ case 'default':
+ if ($icon===false) $icon=ICON_SUBMIT; break;
+
+ case 'cancel':
+ if ($icon===false) $icon=ICON_ESCAPE; break;
+
+ case 'nonajax':
+ $atype = false;
+ }
+ }
+ }
$submit_str = "\n";
if ($echo)
@@ -149,9 +181,9 @@ function submit($name, $value, $echo=true, $title=false, $atype=false, $icon=fal
function submit_center($name, $value, $echo=true, $title=false, $async=false, $icon=false)
{
- echo "
";
+ if ($echo) echo "";
submit($name, $value, $echo, $title, $async, $icon);
- echo "";
+ if ($echo) echo "";
}
function submit_center_first($name, $value, $title=false, $async=false, $icon=false)
@@ -170,50 +202,48 @@ function submit_center_last($name, $value, $title=false, $async=false, $icon=fal
/*
For following controls:
'both' - use both Ctrl-Enter and Escape hotkeys
+ 'upgrade' - use Ctrl-Enter with progress ajax indicator and Escape hotkeys. Nonajax request for OK option is performed.
'cancel' - apply to 'RESET' button
*/
-function submit_add_or_update($add=true, $title=false, $async=false)
+function submit_add_or_update($add=true, $title=false, $async=false, $clone=false)
{
$cancel = $async;
if ($async === 'both') {
$async = 'default'; $cancel = 'cancel';
- }
- else if ($async === 'default')
+ }
+ elseif ($async === 'upgrade') {
+ $async = 'default nonajax process'; $cancel = 'cancel';
+ }
+ elseif ($async === 'default')
$cancel = true;
- else if ($async === 'cancel')
+ elseif ($async === 'cancel')
$async = true;
if ($add)
submit('ADD_ITEM', _("Add new"), true, $title, $async);
else {
- submit('UPDATE_ITEM', _("Update"), true, $title, $async);
- submit('RESET', _("Cancel"), true, $title, $cancel);
+ submit('UPDATE_ITEM', _("Update"), true, _('Submit changes'), $async);
+ if ($clone) submit('CLONE', _("Clone"), true,
+ _('Edit new record with current data'), $async);
+ submit('RESET', _("Cancel"), true, _('Cancel edition'), $cancel);
}
}
-function submit_add_or_update_center($add=true, $title=false, $async=false)
+function submit_add_or_update_center($add=true, $title=false, $async=false, $clone=false)
{
echo "";
- submit_add_or_update($add, $title, $async);
+ submit_add_or_update($add, $title, $async, $clone);
echo "";
}
-/*
-function submit_add_or_update_row($add=true)
-{
- echo "";
- submit_add_or_update($add);
- echo " |
\n";
-}
-*/
-function submit_add_or_update_row($add=true, $right=true, $extra="", $title=false, $async=false)
+function submit_add_or_update_row($add=true, $right=true, $extra="", $title=false, $async=false, $clone = false)
{
echo "";
if ($right)
echo " | \n";
echo "";
- submit_add_or_update($add, $title, $async);
+ submit_add_or_update($add, $title, $async, $clone);
echo " |
\n";
}
@@ -233,43 +263,69 @@ function submit_row($name, $value, $right=true, $extra="", $title=false, $async=
echo "\n";
}
-function submit_return($name, $value, $title=false, $async=false)
+function submit_return($name, $value, $title=false)
{
- if (count($_SESSION['Context'])) {
- submit($name, $value, true, $title, $async);
+ if (@$_REQUEST['popup']) {
+ submit($name, $value, true, $title, 'selector');
}
}
+
+function submit_js_confirm($name, $msg, $set = true) {
+ global $Ajax;
+ $js = "_validate.$name=".($set ? "function(){ return confirm('"
+ . strtr($msg, array("\n"=>'\\n')) . "');};"
+ : 'null;');
+ if (in_ajax()) {
+ $Ajax->addScript(true, $js);
+ } else
+ add_js_source($js);
+}
//-----------------------------------------------------------------------------------
function set_icon($icon, $title=false)
{
global $path_to_root;
- return "\n";
+ if (basename($icon) === $icon) // standard icons does not contain path separator
+ $icon = "$path_to_root/themes/".user_theme()."/images/$icon";
+ return "\n";
}
-function button($name, $value, $title=false, $icon=false)
+function button($name, $value, $title=false, $icon=false, $aspect='')
{
// php silently changes dots,spaces,'[' and characters 128-159
// to underscore in POST names, to maintain compatibility with register_globals
+ $rel = '';
+ if ($aspect == 'selector') {
+ $rel = " rel='$value'";
+ $value = _("Select");
+ }
if (user_graphic_links() && $icon)
{
if ($value == _("Delete")) // Helper during implementation
$icon = ICON_DELETE;
- return "