X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=includes%2Fui%2Fui_input.inc;h=bdb7e94545bba833171ea38d60b22a969facea16;hb=5ac9ea61baac0cf298b07317051da51e781645b7;hp=391cd7fc5a4e0952b10ee5878ce842478e23f39e;hpb=872e4d4be9935e50cb58b1408bbe9ae2300ec8ca;p=fa-stable.git
diff --git a/includes/ui/ui_input.inc b/includes/ui/ui_input.inc
index 391cd7fc..bdb7e945 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
@@ -84,10 +93,16 @@ function input_num($postname=null, $dflt=0)
}
//---------------------------------------------------------------------------------
+//
+// 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);
@@ -95,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;
}
@@ -112,6 +127,7 @@ function hidden($name, $value=null, $echo=true)
'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
@@ -126,7 +142,7 @@ function submit($name, $value, $echo=true, $title=false, $atype=false, $icon=fal
} elseif (!is_bool($atype)) { // necessary: switch uses '=='
- $aspect = "aspect='$atype' ";
+ $aspect = " aspect='$atype' ";
$types = explode(' ', $atype);
foreach ($types as $type) {
@@ -141,6 +157,9 @@ function submit($name, $value, $echo=true, $title=false, $atype=false, $icon=fal
case 'cancel':
if ($icon===false) $icon=ICON_ESCAPE; break;
+
+ case 'nonajax':
+ $atype = false;
}
}
}
@@ -151,7 +170,7 @@ function submit($name, $value, $echo=true, $title=false, $atype=false, $icon=fal
." name=\"$name\" id=\"$name\" value=\"$value\""
.($title ? " title='$title'" : '')
.">"
- .($icon ? "" : '')
+ .($icon ? "
" : '')
."$value"
."\n";
if ($echo)
@@ -183,6 +202,7 @@ 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, $clone=false)
@@ -191,7 +211,10 @@ function submit_add_or_update($add=true, $title=false, $async=false, $clone=fals
if ($async === 'both') {
$async = 'default'; $cancel = 'cancel';
- }
+ }
+ elseif ($async === 'upgrade') {
+ $async = 'default nonajax process'; $cancel = 'cancel';
+ }
else if ($async === 'default')
$cancel = true;
else if ($async === 'cancel')
@@ -247,17 +270,24 @@ function submit_return($name, $value, $title=false)
}
}
-function submit_js_confirm($name, $msg) {
- add_js_source(
- "_validate.$name=function(){ return confirm('"
- . strtr($msg, array("\n"=>'\\n')) . "');};");
-};
+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, $aspect='')
@@ -273,21 +303,23 @@ function button($name, $value, $title=false, $icon=false, $aspect='')
{
if ($value == _("Delete")) // Helper during implementation
$icon = ICON_DELETE;
- return "\n";
}
else
return "'=2E',' '=>'=20','='=>'=3D','['=>'=5B')))
+ .htmlentities(strtr($name, array('.'=>'=2E', '='=>'=3D',// ' '=>'=20','['=>'=5B'
+ )))
."' value='$value'"
.($title ? " title='$title'":'')
. ($aspect ? " aspect='$aspect'" : '')
. $rel
- ." />\n";
+ ." >\n";
}
function button_cell($name, $value, $title=false, $icon=false, $aspect='')
@@ -370,7 +402,21 @@ function check_row($label, $name, $value=null, $submit_on_change=false, $title=f
}
//-----------------------------------------------------------------------------------
+function radio($label, $name, $value, $selected=null, $submit_on_change=false)
+{
+ if (!isset($selected))
+ $selected = get_post($name) === (string)$value;
+
+ if ($submit_on_change === true)
+ $submit_on_change =
+ "JsHttpRequest.request(\"_{$name}_update\", this.form);";
+ return "".($label ? $label : '');
+}
+
+//-----------------------------------------------------------------------------------
function labelheader_cell($label, $params="")
{
echo "