Task #5689 : improve calc online

This commit is contained in:
sparkyx 2006-06-29 16:45:18 +00:00
parent 1adf667b36
commit 725c0cb9ea
4 changed files with 129 additions and 49 deletions

113
html/js/calc.js Normal file
View file

@ -0,0 +1,113 @@
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/* !\file
*/
/* \brief This file show a little online calculator, in the caller
* the span id result, listing, the id form calc_line and the
* input id inp must exist see constant.php JS_CALC_LINE
*
*/
var str="";
var val="";
var counter=0;
// add input
function cal()
{
p_variable=this.document.getElementById('inp').value;
if (p_variable.search(/^\s*$/) !=-1) {
return;
}
if ( counter==0)
{
this.document.getElementById('result').innerHTML="";
}
// if both parenthesis are not found we increase the counter
if ( p_variable.search(/\)+/) == -1 && p_variable.search(/\(+/) ==-1) {
if ( counter%2 == 0)
{
// number only
var regex=/^\(?[0-9]*\.*[0-9]*\)?$/;
if ( p_variable.search(regex) ==-1)
{
alert ('Nombre uniquement');
return;
}
} else
{
var regex=/^\/?\+?-?\*?=?$/;
// signs
if ( p_variable.search(regex) ==-1)
{
alert ('Signe + - * / = uniquement');
return;
}
}
counter++;
}
if ( p_variable == "=" ) {
Compute();
str="";
val="";
counter=0;
return;
}
str=str+p_variable;
val=val+p_variable;
var str_sub="";
if ( counter%2 != 0 )
{
sub=eval(val);
str_sub="<hr><b><i> Total :"+val+" = "+sub+"<I></b>";
this.document.getElementById("sub_total").innerHTML=str_sub;
}
//alert ('value is '+p_variable+'Global :'+str);
this.document.getElementById("listing").innerHTML=str;
this.document.getElementById('inp').value="";
}
// Clean
//
function Clean()
{
str="";
this.document.getElementById('listing').innerHTML="";
this.document.getElementById('result').innerHTML="";
// this.document.getElementById('sub_total').innerHTML="";
this.document.getElementById('inp').value="";
}
function Compute()
{
var tot=0;
var ret="";
tot=eval(val);
ret+="<hr>";
ret+="<b>Total = "+tot+'</b>';
this.document.getElementById('inp').value="";
this.document.getElementById('result').innerHTML=ret;
this.document.getElementById('inp').focus();
}

View file

@ -137,6 +137,7 @@ div.u_redcontent{
div.u_content{
position: float;
float:left;
padding-top:7px;
width:100%;
font-size:9px;
font-family:sans-serif;
@ -151,13 +152,7 @@ div.no span{
}
div.u_content span {
position :float;
float:left;
margin-left:40px;
}
div.u_content table {
width:100%;
border:solid blue 2px ;
border-style:outset;
}

View file

@ -338,31 +338,21 @@ function SetIt(p_value,p_ctl) {
</script>
");
// One line calculator
define ("JS_CALC_LINE","
<form name=\"calc_line\" onSubmit=\"cal()\">
<input type=\"text\" size=\"20\" name=\"calculator\" onBlur=\"cal()\">
Answer:<span id=\"name\"></span>
<br>
<!-- <input type=\"button\" name=\"B1\" value=\"Calculate\" > -->
<input type=\"reset\" name=\"B2\" value=\"Reset\"><br>
</form>
<SCRIPT language=\"javascript\">
function cal()
{
document.getElementById(\"name\").innerHTML=
eval(document.calc_line.calculator.value)
}
define ("JS_CALC_LINE",'
<div style="border:outset black 2px; position:float; float:right;background-color:white;font-family:sans-serif;font-size:9pt;">
<script type="text/javascript" language="javascript" src="js/calc.js">
</script>
"
<h2 class="info"> Calculette</H2>
<span id="listing"> </span>
<br>
<span id="sub_total"> </span>
<span id="result"> </span>
<form name="calc_line" method="GET" onSubmit="cal();return false;" >
<input type="text" size="30" id="inp" name="calculator">
<input type="button" value="Efface tout" onClick="Clean();return false;" >
</form>
</div>
'
);
define ("JS_TVA","<script language=\"javascript\">

View file

@ -1,20 +1,2 @@
drop function action_gestion_replace_newline() cascade;
alter table action_gestion add column ag_ref_ag_id int4;
create or replace function action_gestion_replace_newline ()
returns trigger
as
$body$
declare
modified action_gestion%rowtype;
begin
modified:=NEW;
modified.ag_comment:=replace(modified.ag_comment,'%0A','');
modified.ag_comment:=replace(modified.ag_comment,'%0D','');
return modified;
end;
$body$ language plpgsql;
create trigger tr_ag_comment_replace before insert or update on action_gestion
for each row execute procedure action_gestion_replace_newline();