Finished ajax improvements to sales & purchase modules,
[fa-stable.git] / includes / ui / ui_input.inc
index 6811076c427c44bd5b66d637360c9e516dea05d0..2dcd14e14aa23406ca57ecff765b5b6fe18d4c18 100644 (file)
@@ -179,11 +179,11 @@ function check($label, $name, $value, $submit_on_change=false, $title=false)
 
        if ($value == null)
                $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
-       
+
                echo "<input"
                    .($value == 1 ? ' checked':'')
                    ." type='checkbox' name='$name' value='1'"
-                   .($submit_on_change ? " onclick='this.form.submit();'" : '')
+                   .($submit_on_change ? " onclick='JsHttpRequest.request(\"_{$name}_update\", this.form);'" : '')
                    .($title ? " title='$title'" : '')
                    ." >\n";
        $Ajax->addUpdate($name, $name, $value);
@@ -241,13 +241,15 @@ function percent_cell($label, $bold=false, $id=null)
        else
                label_cell(percent_format($label), "nowrap align=right", $id);
 }
-
+// 2008-06-15. Changed
 function qty_cell($label, $bold=false, $dec=null, $id=null)
 {
+       if ($dec == null)
+               $dec = get_qty_dec();
        if ($bold)
-               label_cell("<b>".qty_format($label, $dec)."</b>", "nowrap align=right", $id);
+               label_cell("<b>".number_format2($label, $dec)."</b>", "nowrap align=right", $id);
        else
-               label_cell(qty_format($label, $dec), "nowrap align=right", $id);
+               label_cell(number_format2($label, $dec), "nowrap align=right", $id);
 }
 
 function label_cells($label, $value, $params="", $params2="")
@@ -290,7 +292,7 @@ function text_cells($label, $name, $value, $size="", $max="", $title=false, $par
        $Ajax->addUpdate($name, $name, $value);
 }
 
-function text_cells_ex($label, $name, $size, $max=null, $init=null, $title=null, $params=null, $post_label=null)
+function text_cells_ex($label, $name, $size, $max=null, $init=null, $title=null, $params=null, $post_label=null, $submit_on_change=false)
 {
        global $Ajax;
 
@@ -309,8 +311,8 @@ function text_cells_ex($label, $name, $size, $max=null, $init=null, $title=null,
                $max = $size;
 
        echo "<td>";
-
-       echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\""
+       $class = $submit_on_change ? 'class="searchbox"' : '';
+       echo "<input $class type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\""
         .($title ? " title='$title'": '')." >";
 
        if ($post_label)
@@ -367,7 +369,7 @@ function date_cells($label, $name, $title = null, $init=null, $inc_days=0, $inc_
                        $_POST[$name] = $init;
        }
        if ($use_date_picker)
-               $post_label = "<a tabindex='-1' href=\"javascript:date_picker(document.forms[0].$name);\">"
+               $post_label = "<a tabindex='-1' href=\"javascript:date_picker(document.getElementsByName('$name')[0]);\">"
                . "     <img src='$path_to_root/themes/default/images/cal.gif' width='16' height='16' border='0' alt='"._('Click Here to Pick up the date')."'></a>\n";
        else
                $post_label = "";
@@ -383,17 +385,17 @@ function date_row($label, $name, $title=null, $init=null, $inc_days=0, $inc_mont
 
 //-----------------------------------------------------------------------------------
 
-function ref_cells($label, $name, $title=null, $init=null, $params=null)
+function ref_cells($label, $name, $title=null, $init=null, $params=null, $submit_on_change=false)
 {
-       text_cells_ex($label, $name, 16, 18, $init, $title, $params);
+       text_cells_ex($label, $name, 16, 18, $init, $title, $params, null, $submit_on_change);
 }
 
 //-----------------------------------------------------------------------------------
 
-function ref_row($label, $name, $title=null, $init=null)
+function ref_row($label, $name, $title=null, $init=null, $submit_on_change=false)
 {
        echo "<tr>";
-       ref_cells($label, $name, $title, $init);
+       ref_cells($label, $name, $title, $init, null, $submit_on_change);
        echo "</tr>\n";
 }
 
@@ -418,7 +420,7 @@ function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=nu
                $dec = user_price_dec();
        if (!isset($_POST[$name]) || $_POST[$name] == "")
        {
-               if ($init)
+               if ($init !== null)
                        $_POST[$name] = $init;
                else
                        $_POST[$name] = '';
@@ -438,6 +440,7 @@ function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=nu
 
        echo "</td>\n";
        $Ajax->addUpdate($name, $name, $_POST[$name]);
+       $Ajax->addAssign($name, $name, 'dec', $dec);
 }