2015-09-27 00:35:53 +02:00
/ *
* This file is part of NOALYSS .
*
* NOALYSS 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 .
*
* NOALYSS 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 NOALYSS ; 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 danydb@aevalys.eu
/ * ! \ f i l e
* \ brief javascript script , always added to every page
*
* /
var ask _reload = 0 ;
var tag _choose = '' ;
2018-04-13 18:58:28 +02:00
var aDraggableElement = new Array ( ) ;
2015-09-27 00:35:53 +02:00
/ * *
* callback function when we just need to update a hidden div with an info
* message
* /
function infodiv ( req , json )
{
try
{
remove _waiting _box ( ) ;
var answer = req . responseXML ;
var a = answer . getElementsByTagName ( 'ctl' ) ;
var html = answer . getElementsByTagName ( 'code' ) ;
if ( a . length === 0 )
{
var rec = req . responseText ;
alert _box ( 'erreur :' + rec ) ;
}
var name _ctl = a [ 0 ] . firstChild . nodeValue ;
var code _html = getNodeText ( html [ 0 ] ) ;
code _html = unescape _xml ( code _html ) ;
g ( name _ctl + "info" ) . innerHTML = code _html ;
}
catch ( e )
{
alert _box ( "success_box" + e . message ) ;
}
try
{
code _html . evalScripts ( ) ;
}
catch ( e )
{
alert _box ( "answer_box Impossible executer script de la reponse\n" + e . message ) ;
}
}
/ * *
* @ brief delete a row from a table ( tb ) the input button send the this
as second parameter
* /
function deleteRow ( tb , obj )
{
smoke . confirm ( 'Confirmez effacement' , function ( e )
{
if ( e ) {
var td = obj . parentNode ;
var tr = td . parentNode ;
var lidx = tr . rowIndex ;
g ( tb ) . deleteRow ( lidx ) ;
} else {
return ;
}
} ) ;
}
function deleteRowRec ( tb , obj )
{
var tr = obj ;
var lidx = tr . rowIndex ;
g ( tb ) . deleteRow ( lidx ) ;
}
/ * ! \ b r i e f r e m o v e t r a i l i n g a n d h e a d i n g s p a c e
* \ param the string to modify
* \ return string without heading and trailing space
* /
function trim ( s )
{
return s . replace ( /^\s+/ , '' ) . replace ( /\s+$/ , '' ) ;
}
/ * *
* @ brief retrieve an element thanks its ID
* @ param ID is a string
* @ return the found object of undefined if not found
* /
function g ( ID )
{
if ( document . getElementById )
{
return this . document . getElementById ( ID ) ;
}
else if ( document . all )
{
return document . all [ ID ] ;
}
else
{
return undefined ;
}
}
/ * *
* @ brief enable the type of periode
* /
function enable _type _periode ( )
{
if ( $ ( "type_periode" ) . options [ $ ( "type_periode" ) . selectedIndex ] . value == 0 )
{
$ ( 'from_periode' ) . enable ( ) ;
$ ( 'to_periode' ) . enable ( ) ;
$ ( 'from_date' ) . disable ( ) ;
$ ( 'to_date' ) . disable ( ) ;
$ ( 'p_step' ) . enable ( ) ;
}
else
{
$ ( 'from_periode' ) . disable ( ) ;
$ ( 'to_periode' ) . disable ( ) ;
$ ( 'from_date' ) . enable ( ) ;
$ ( 'to_date' ) . enable ( ) ;
$ ( 'p_step' ) . disable ( ) ;
}
}
/ * *
* @ brief will reload the window but it is dangerous if we have submitted
* a form with POST
* /
function refresh _window ( )
{
window . location . reload ( ) ;
}
/ * *
* @ fn encodeJSON ( obj )
* @ brief we receive a json object as parameter and the function returns the string
* with the format variable = value & var2 = val2 ...
* /
function encodeJSON ( obj )
{
if ( typeof obj != 'object' )
{
alert _box ( 'encodeParameter obj n\'est pas un objet' ) ;
}
try
{
var str = '' ;
var e = 0 ;
2018-04-13 18:58:28 +02:00
for ( var i in obj )
2015-09-27 00:35:53 +02:00
{
if ( e !== 0 )
{
str += '&' ;
}
else
{
e = 1 ;
}
str += i ;
str += '=' + encodeURI ( obj [ i ] ) ;
}
return str ;
}
catch ( e )
{
alert _box ( 'encodeParameter ' + e . message ) ;
return "" ;
}
}
function hide ( p _param )
{
g ( p _param ) . style . display = 'none' ;
}
function show ( p _param )
{
g ( p _param ) . style . display = 'block' ;
}
/ * *
* @ brief set the focus on the selected field
* @ param Field id of the control
* @ param selectIt : the value selected in case of Field is a object select , numeric
* /
function SetFocus ( Field , SelectIt )
{
var elem = g ( Field ) ;
if ( elem )
{
elem . focus ( ) ;
}
return true ;
}
/ * *
* @ brief set a DOM id with a value in the parent window ( the caller ) ,
@ param p _ctl is the name of the control
@ param p _value is the value to set in
@ param p _add if we don ' t replace the current value but we add something
* /
function set _inparent ( p _ctl , p _value , p _add )
{
self . opener . set _value ( p _ctl , p _value , p _add ) ;
}
/ * *
* @ brief set a DOM id with a value , it will consider if it the attribute
value or innerHTML has be used
@ param p _ctl is the name of the control
@ param p _value is the value to set in
@ param p _add if we don ' t replace the current value but we add something
* /
function set _value ( p _ctl , p _value , p _add )
{
if ( g ( p _ctl ) )
{
var g _ctrl = g ( p _ctl ) ;
if ( p _add != undefined && p _add === 1 )
{
if ( g _ctrl . value )
{
p _value = g _ctrl . value + ',' + p _value ;
}
}
if ( g _ctrl . tagName === 'INPUT' )
{
g ( p _ctl ) . value = p _value ;
}
if ( g _ctrl . tagName === 'SPAN' )
{
g ( p _ctl ) . innerHTML = p _value ;
}
if ( g _ctrl . tagName === 'SELECT' )
{
g ( p _ctl ) . value = p _value ;
}
}
}
/ * *
* @ brief format the number change comma to point
* @ param HTML obj
* /
function format _number ( obj , p _prec )
{
var precision = 2 ;
if ( p _prec === undefined )
{
precision = 2 ;
} else {
precision = p _prec ;
}
var value = obj . value ;
value = value . replace ( /,/ , '.' ) ;
value = parseFloat ( value ) ;
if ( isNaN ( value ) )
{
value = 0 ;
}
var arrondi = Math . pow ( 10 , precision ) ;
value = Math . round ( value * arrondi ) / arrondi ;
$ ( obj ) . value = value ;
}
/ * *
* @ brief check if the object is hidden or show and perform the opposite ,
* show the hidden obj or hide the shown one
* @ param name of the object
* /
function toggleHideShow ( p _obj , p _button )
{
var stat = g ( p _obj ) . style . display ;
var str = g ( p _button ) . value ;
if ( stat === 'none' )
{
show ( p _obj ) ;
str = str . replace ( /Afficher/ , 'Cacher' ) ;
g ( p _button ) . value = str ;
}
else
{
hide ( p _obj ) ;
str = str . replace ( /Cacher/ , 'Afficher' ) ;
g ( p _button ) . value = str ;
}
}
/ * *
* @ brief open popup with the search windows
* @ param p _dossier the dossier where to search
* @ param p _style style of the detail value are E for expert or S for simple
* /
function popup _recherche ( p _dossier )
{
var w = window . open ( "recherche.php?gDossier=" + p _dossier + "&ac=SEARCH" , '' , 'statusbar=no,scrollbars=yes,toolbar=no' ) ;
w . focus ( ) ;
}
/ * *
* @ brief replace the special characters ( > < ' " ) by their HTML representation
* @ return a string without the offending char .
* /
function unescape _xml ( code _html )
{
code _html = code _html . replace ( /\</ , '<' ) ;
code _html = code _html . replace ( /\>/ , '>' ) ;
code _html = code _html . replace ( /\"/ , '"' ) ;
code _html = code _html . replace ( /\'/ , "'" ) ;
code _html = code _html . replace ( /\&/ , '&' ) ;
return code _html ;
}
/ * *
* @ brief Firefox splits the XML into 4 K chunk , so to retrieve everything we need
* to get the different parts thanks textContent
* @ param xmlNode a node ( result of var data = = answer . getElementsByTagName ( 'code' ) )
* @ return all the content of the XML node
* /
function getNodeText ( xmlNode )
{
if ( ! xmlNode )
return '' ;
if ( typeof ( xmlNode . textContent ) != "undefined" )
{
return xmlNode . textContent ;
}
if ( xmlNode . firstChild && xmlNode . firstChild . nodeValue )
return xmlNode . firstChild . nodeValue ;
return "" ;
}
/ * *
* @ brief change the periode in the calendar of the dashboard
* @ param object select
* /
function change _month ( obj )
{
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' ,
parameters : { gDossier : obj . gDossier , op : 'cal' , "per" : obj . value , t : obj . type _display , notitle : obj . notitle } ,
onFailure : ajax _misc _failure ,
onSuccess : success _misc
}
) ;
}
/ * *
* @ brief basic answer to ajax on success , it will fill the DOMID code with
* the code . In that case , you need to create the object before the Ajax . Request
* The difference with success box is that
* @ see add _div removeDiv success _box is that the width and height are not changed ajax _misc . php
2018-04-13 18:58:28 +02:00
* @ param code is the ID of the object containing the html ( div , button ... )
* @ param value is the html code , with it you fill the ctl element
2015-09-27 00:35:53 +02:00
* /
function success _misc ( req )
{
try
{
var answer = req . responseXML ;
var html = answer . getElementsByTagName ( 'code' ) ;
if ( html . length === 0 )
{
var rec = req . responseText ;
alert _box ( 'erreur :' + rec ) ;
}
var nodeXml = html [ 0 ] ;
var code _html = getNodeText ( nodeXml ) ;
code _html = unescape _xml ( code _html ) ;
$ ( "user_cal" ) . innerHTML = code _html ;
}
catch ( e )
{
alert _box ( e . message ) ;
}
try
{
code _html . evalScripts ( ) ;
}
catch ( e )
{
alert _box ( "Impossible executer script de la reponse\n" + e . message ) ;
}
}
function loading ( )
{
var str = '<h2> Un instant ...</h2>' ;
str = str + '<image src="image/loading.gif" alt="chargement"></image>' ;
return str ;
}
function ajax _misc _failure ( )
{
alert _box ( 'Ajax Misc failed' ) ;
}
/ * *
* @ brief remove a document _modele
* /
function cat _doc _remove ( p _dt _id , p _dossier )
{
var queryString = "gDossier=" + p _dossier + "&op=rem_cat_doc" + "&dt_id=" + p _dt _id ;
var action = new Ajax . Request (
"ajax_misc.php" , { method : 'get' ,
parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req )
{
try
{
var answer = req . responseXML ;
var html = answer . getElementsByTagName ( 'dtid' ) ;
if ( html . length === 0 )
{
var rec = req . responseText ;
alert _box ( 'erreur <br>' + rec ) ;
return ;
}
2018-04-13 18:58:28 +02:00
var nodeXML = html [ 0 ] ;
var row _id = getNodeText ( nodeXML ) ;
2015-09-27 00:35:53 +02:00
if ( row _id === 'nok' )
{
var message _node = answer . getElementsByTagName ( 'message' ) ;
var message _text = getNodeText ( message _node [ 0 ] ) ;
alert _box ( 'erreur <br>' + message _text ) ;
return ;
}
$ ( 'row' + row _id ) . style . textDecoration = "line-through" ;
$ ( 'X' + row _id ) . style . display = 'none' ;
$ ( 'M' + row _id ) . style . display = 'none' ;
}
catch ( e )
{
alert _box ( e . message ) ;
}
}
}
) ;
}
/ * *
* @ brief change a document _modele
* /
function cat _doc _change ( p _dt _id , p _dossier )
{
var queryString = "gDossier=" + p _dossier + "&op=mod_cat_doc" + "&dt_id=" + p _dt _id ;
var nTop = calcy ( posY ) ;
var nLeft = "200px" ;
var str _style = "top:" + nTop + "px;left:" + nLeft + ";width:50em;height:auto" ;
removeDiv ( 'change_doc_div' ) ;
waiting _box ( ) ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' , parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req ) {
remove _waiting _box ( ) ;
add _div ( { id : 'change_doc_div' , style : str _style , cssclass : 'inner_box' , drag : "1" } ) ;
$ ( 'change_doc_div' ) . innerHTML = req . responseText ;
}
}
) ;
}
/ * *
* @ brief display the popup with vat and explanation
* @ param obj with 4 attributes gdossier , ctl , popup
* /
function popup _select _tva ( obj )
{
try
{
if ( $ ( 'tva_select' ) ) {
removeDiv ( 'tva_select' ) ;
}
var queryString = "gDossier=" + obj . gDossier + "&op=dsp_tva" + "&ctl=" + obj . ctl + '&popup=' + 'tva_select' ;
if ( obj . jcode )
queryString += '&code=' + obj . jcode ;
if ( obj . compute )
queryString += '&compute=' + obj . compute ;
2018-04-13 18:58:28 +02:00
if ( obj . filter )
queryString += '&filter=' + obj . filter ;
2015-09-27 00:35:53 +02:00
var action = new Ajax . Request (
"ajax_misc.php" ,
{ method : 'get' ,
parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req )
{
try
{
var answer = req . responseXML ;
var popup = answer . getElementsByTagName ( 'popup' ) ;
if ( popup . length === 0 )
{
var rec = req . responseText ;
alert _box ( 'erreur :' + rec ) ;
}
var html = answer . getElementsByTagName ( 'code' ) ;
var name _ctl = popup [ 0 ] . firstChild . nodeValue ;
var nodeXml = html [ 0 ] ;
var code _html = getNodeText ( nodeXml ) ;
code _html = unescape _xml ( code _html ) ;
var nTop = posY - 200 ;
var nLeft = "15%" ;
var str _style = "top:" + nTop + "px;left:" + nLeft + ";right:" + nLeft + ";width:55em;height:auto" ;
2018-04-13 18:58:28 +02:00
var popup = { 'id' : 'tva_select' , 'cssclass' : 'inner_box' , 'style' : str _style , 'html' : code _html , 'drag' : false } ;
2015-09-27 00:35:53 +02:00
add _div ( popup ) ;
$ ( 'lk_tva_select_table' ) . focus ( ) ;
}
catch ( e )
{
alert _box ( "success_popup_select_tva " + e . message ) ;
}
}
}
) ;
}
catch ( e )
{
alert _box ( "popup_select_tva " + e . message ) ;
}
}
/ * *
* @ brief display the popup with vat and explanations
2018-04-13 18:58:28 +02:00
* @ deprecated this function is not used anymore
2015-09-27 00:35:53 +02:00
* /
function success _popup _select _tva _obsolete ( req )
{
}
/ * *
* @ brief display the popup with vat and explanation
* @ param obj with 4 attributes gdossier , ctl , popup
* /
function set _tva _label ( obj )
{
try
{
var queryString = "gDossier=" + obj . gDossier + "&op=label_tva" + "&id=" + obj . value ;
if ( obj . jcode )
queryString += '&code=' + obj . jcode ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{ method : 'get' ,
parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : success _set _tva _label
}
) ;
}
catch ( e )
{
alert _box ( "set_tva_label " + e . message ) ;
}
}
/ * *
* @ brief display the popup with vat and explanations
* /
function success _set _tva _label ( req )
{
try
{
var answer = req . responseXML ;
var code = answer . getElementsByTagName ( 'code' ) ;
var value = answer . getElementsByTagName ( 'value' ) ;
if ( code . length === 0 )
{
var rec = req . responseText ;
alert _box ( 'erreur :' + rec ) ;
}
var label _code = code [ 0 ] . firstChild . nodeValue ;
var label _value = value [ 0 ] . firstChild . nodeValue ;
set _value ( label _code , label _value ) ;
}
catch ( e )
{
alert _box ( "success_set_tva_label " + e . message ) ;
}
}
/ * *
* @ brief set loading for waiting
* @ param name of ipopup
* @ see showIPopup
2018-04-13 18:58:28 +02:00
* @ deprecated
2015-09-27 00:35:53 +02:00
* /
function set _wait _obsolete ( name )
{
var content = name + "_content" ;
$ ( content ) . innerHTML = 'Un instant...<image src="image/loading.gif" border="0" alt="Chargement...">' ;
}
/ * *
* Create a div without showing it
* @ param { type } obj
* the attributes are
* - style to add style
* - id to add an id
* - cssclass to add a class
* - html is the content
* - drag is the div can be moved
* @ returns html dom element
* @ see add _div
* /
function create _div ( obj )
{
try
{
var top = document ;
var elt = null ;
if ( ! $ ( obj . id ) ) {
elt = top . createElement ( 'div' ) ;
}
else {
elt = $ ( obj . id ) ;
}
if ( obj . id )
{
elt . setAttribute ( 'id' , obj . id ) ;
}
if ( obj . style )
{
if ( elt . style . setAttribute )
{ /* IE7 bug */
elt . style . setAttribute ( 'cssText' , obj . style ) ;
}
else
{ /* good Browser */
elt . setAttribute ( 'style' , obj . style ) ;
}
}
if ( obj . cssclass )
{
elt . setAttribute ( 'class' , obj . cssclass ) ; /* FF */
elt . setAttribute ( 'className' , obj . cssclass ) ; /* IE */
}
if ( obj . html )
{
elt . innerHTML = obj . html ;
}
var bottom _div = document . body ;
elt . hide ( ) ;
bottom _div . appendChild ( elt ) ;
/ * i f ( o b j . e f f e c t & & o b j . e f f e c t ! = ' n o n e ' ) { E f f e c t . G r o w ( o b j . i d , { d i r e c t i o n : ' t o p - r i g h t ' , d u r a t i o n : 0 . 1 } ) ; }
else if ( ! obj . effect ) { Effect . Grow ( obj . id , { direction : 'top-right' , duration : 0.1 } ) ; } * /
if ( obj . drag )
{
2018-04-13 18:58:28 +02:00
aDraggableElement [ obj . id ] = new Draggable ( obj . id , { starteffect : function ( )
2015-09-27 00:35:53 +02:00
{
new Effect . Highlight ( obj . id , { scroll : window , queue : 'end' } ) ;
} }
) ;
2018-04-13 18:58:28 +02:00
2015-09-27 00:35:53 +02:00
}
return elt ;
}
catch ( e )
{
error _message ( "create_div " + e . message ) ;
}
}
/ * *
* @ brief add dynamically a object for AJAX
* @ param obj .
* the attributes are
* - style to add style
* - id to add an id
* - cssclass to add a class
* - html is the content
* - drag is the div can be moved
* /
function add _div ( obj )
{
try {
var elt = create _div ( obj ) ;
/* elt.setStyle({visibility:'visible'}); */
elt . style . visibility = 'visible' ;
elt . show ( ) ;
}
catch ( e )
{
alert _box ( "add_div " + e . message ) ;
}
}
/ * *
* remove a object created with add _div
* @ param elt id of the elt
* /
function removeDiv ( elt )
{
if ( g ( elt ) )
{
document . body . removeChild ( g ( elt ) ) ;
}
// if reloaded if asked the window will be reloaded when
// the box is closed
if ( ask _reload === 1 )
{
// avoid POST window.location = window.location.href;
window . location . reload ( ) ;
}
}
function waiting _node ( )
{
$ ( 'info_div' ) . innerHTML = 'Un instant' ;
$ ( 'info_div' ) . style . display = "block" ;
}
/ * *
* show a box while loading
* must be remove when ajax is successfull
* the id is wait _box
* /
function waiting _box ( )
{
var obj = {
id : 'wait_box' , html : '<h2 class="title">Chargement</h2>' + loading ( )
} ;
var y = fixed _position ( 10 , 250 )
obj . style = y + ";width:20%;margin-left:40%;" ;
if ( $ ( 'wait_box' ) ) {
removeDiv ( 'wait_box' ) ;
}
waiting _node ( ) ;
add _div ( obj ) ;
2018-04-13 18:58:28 +02:00
2015-09-27 00:35:53 +02:00
}
/ * *
* @ brief call add _div to add a DIV and after call the ajax
* the queryString , the callback for function for success and error management
* the method is always GET
* @ param obj , the mandatory attributes are
* - obj . qs querystring
* - obj . js _success callback function in javascript for handling the xml answer
* - obj . js _error callback function for error
* - obj . callback the php file to call
* - obj . fixed optional let you determine the position , otherwise works like IPopup
* @ see add _div IBox
* /
function show _box ( obj )
{
add _div ( obj ) ;
if ( ! obj . fixed )
{
2018-04-13 18:58:28 +02:00
g ( obj . id ) . style . top = calc ( 40 ) + "px" ;
2015-09-27 00:35:53 +02:00
show ( obj . id ) ;
}
else
{
show ( obj . id ) ;
}
var action = new Ajax . Request (
obj . callback ,
{
method : 'GET' ,
parameters : obj . qs ,
onFailure : eval ( obj . js _error ) ,
onSuccess : eval ( obj . js _success )
} ) ;
}
/ * *
* @ brief receive answer from ajax and just display it into the IBox
* XML must contains at least 2 fields : ctl is the ID of the IBOX and
* code is the HTML to put in it
* @ see fill _box
* /
function success _box ( req , json )
{
try
{
var answer = req . responseXML ;
var a = answer . getElementsByTagName ( 'ctl' ) ;
var html = answer . getElementsByTagName ( 'code' ) ;
if ( a . length === 0 )
{
var rec = req . responseText ;
alert _box ( 'erreur :' + rec ) ;
}
var name _ctl = a [ 0 ] . firstChild . nodeValue ;
var code _html = getNodeText ( html [ 0 ] ) ;
code _html = unescape _xml ( code _html ) ;
g ( name _ctl ) . innerHTML = code _html ;
g ( name _ctl ) . style . height = 'auto' ;
if ( name _ctl == 'popup' )
g ( name _ctl ) . style . width = 'auto' ;
}
catch ( e )
{
alert _box ( "success_box" + e . message ) ;
}
try
{
code _html . evalScripts ( ) ;
}
catch ( e )
{
alert _box ( "answer_box Impossible executer script de la reponse\n" + e . message ) ;
}
}
function error _box ( )
{
alert _box ( '[error_box] ajax not implemented' ) ;
}
/ * *
* show the ledger choice
* /
function show _ledger _choice ( json _obj )
{
try
{
waiting _box ( ) ;
var i = 0 ;
var query = "gDossier=" + json _obj . dossier + '&type=' + json _obj . type + '&div=' + json _obj . div + '&op=ledger_show' ;
query = query + '&nbjrn=' + $ ( json _obj . div + 'nb_jrn' ) . value ;
query = query + '&all_type=' + json _obj . all _type ;
for ( i = 0 ; i < $ ( json _obj . div + 'nb_jrn' ) . value ; i ++ ) {
query = query + "&r_jrn[]=" + $ ( json _obj . div + 'r_jrn[' + i + ']' ) . value ;
}
2018-04-13 18:58:28 +02:00
query = encodeURI ( query ) ;
2015-09-27 00:35:53 +02:00
var action = new Ajax . Request (
"ajax_misc.php" ,
{ method : 'get' ,
parameters : query ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req , json ) {
try {
var obj = {
id : json _obj . div + 'jrn_search' ,
cssclass : 'inner_box' ,
2018-04-13 18:58:28 +02:00
style : ';position:absolute;width:auto;z-index:20;margin-left:20%' ,
2015-09-27 00:35:53 +02:00
drag : 1
} ;
//var y=calcy(posY);
var y = posY ;
2018-04-13 18:58:28 +02:00
2015-09-27 00:35:53 +02:00
obj . style = "top:" + y + 'px;' + obj . style ;
/ * i f ( j s o n _ o b j . c l a s s )
{
obj . cssclass = json _obj . class ;
} * /
add _div ( obj ) ;
var answer = req . responseXML ;
var a = answer . getElementsByTagName ( 'ctl' ) ;
var html = answer . getElementsByTagName ( 'code' ) ;
if ( a . length === 0 ) {
var rec = req . responseText ;
alert _box ( 'erreur :' + rec ) ;
}
var name _ctl = a [ 0 ] . firstChild . nodeValue ;
var code _html = getNodeText ( html [ 0 ] ) ;
code _html = unescape _xml ( code _html ) ;
remove _waiting _box ( ) ;
g ( obj . id ) . innerHTML = code _html ;
}
catch ( e ) {
alert _box ( "show_ledger_callback" + e . message ) ;
}
try {
code _html . evalScripts ( ) ;
}
catch ( e ) {
alert _box ( "answer_box Impossible executer script de la reponse\n" + e . message ) ;
}
}
}
) ;
} catch ( e ) {
alert _box ( 'show_ledger_choice' + e . message ) ;
}
}
/ * *
* hide the ledger choice
* /
function hide _ledger _choice ( p _frm _search )
{
try
{
var nb = $ ( p _frm _search ) . nb _jrn . value ;
2018-04-13 18:58:28 +02:00
var div = "" ;
if ( $ ( p _frm _search ) . div ) {
div = $ ( p _frm _search ) . div . value ;
}
2015-09-27 00:35:53 +02:00
var i = 0 ;
var str = "" ;
var name = "" ;
var n _name = "" ;
var sel = 0 ;
for ( i = 0 ; i < nb ; i ++ ) {
n _name = div + "r_jrn[" + sel + "]" ;
name = div + "r_jrn" + i ;
2018-04-13 18:58:28 +02:00
if ( $ ( name ) . checked ) {
2015-09-27 00:35:53 +02:00
str += '<input type="hidden" id="' + n _name + '" name="' + n _name + '" value="' + $ ( name ) . value + '">' ;
sel ++ ;
}
}
str += '<input type="hidden" name="' + div + 'nb_jrn" id="' + div + 'nb_jrn" value="' + sel + '">' ;
$ ( 'ledger_id' + div ) . innerHTML = str ;
removeDiv ( div + 'jrn_search' ) ;
return false ;
} catch ( e ) {
alert _box ( 'hide_ledger_choice' + e . message ) ;
return false ;
}
}
/ * *
* show the cat of ledger choice
* /
function show _cat _choice ( )
{
g ( 'div_cat' ) . style . visibility = 'visible' ;
}
/ * *
* hide the cat of ledger choice
* /
function hide _cat _choice ( )
{
g ( 'div_cat' ) . style . visibility = 'hidden' ;
}
/ * *
* add a row for the forecast item
* /
function for _add _row ( tableid )
{
style = 'class="input_text"' ;
var mytable = g ( tableid ) . tBodies [ 0 ] ;
var nNumberRow = mytable . rows . length ;
var oRow = mytable . insertRow ( nNumberRow ) ;
var rowToCopy = mytable . rows [ 1 ] ;
var nNumberCell = rowToCopy . cells . length ;
var nb = g ( "nbrow" ) ;
var oNewRow = mytable . insertRow ( nNumberRow ) ;
for ( var e = 0 ; e < nNumberCell ; e ++ )
{
var newCell = oRow . insertCell ( e ) ;
var tt = rowToCopy . cells [ e ] . innerHTML ;
new _tt = tt . replace ( /an_cat0/g , "an_cat" + nb . value ) ;
new _tt = new _tt . replace ( /an_cat_acc0/g , "an_cat_acc" + nb . value ) ;
new _tt = new _tt . replace ( /an_qc0/g , "an_qc" + nb . value ) ;
new _tt = new _tt . replace ( /an_label0/g , "an_label" + nb . value ) ;
new _tt = new _tt . replace ( /month0/g , "month" + nb . value ) ;
new _tt = new _tt . replace ( /an_cat_amount0/g , "an_cat_amount" + nb . value ) ;
new _tt = new _tt . replace ( /an_deb0/g , "an_deb" + nb . value ) ;
newCell . innerHTML = new _tt ;
new _tt . evalScripts ( ) ;
}
$ ( "an_cat_acc" + nb . value ) . value = "" ;
$ ( "an_qc" + nb . value ) . value = "" ;
$ ( "an_label" + nb . value ) . value = "" ;
$ ( "an_cat_amount" + nb . value ) . value = "0" ;
nb . value ++ ;
}
/ * *
* toggle all the checkbox in a given form
* @ param form _id id of the form
* /
function toggle _checkbox ( form _id )
{
var form = g ( form _id ) ;
for ( var i = 0 ; i < form . length ; i ++ )
{
var e = form . elements [ i ] ;
if ( e . type === 'checkbox' )
{
if ( e . checked === true )
{
e . checked = false ;
}
else
{
e . checked = true ;
}
}
}
}
/ * *
* select all the checkbox in a given form
* @ param form _id id of the form
* /
function select _checkbox ( form _id )
{
var form = $ ( form _id ) ;
for ( var i = 0 ; i < form . length ; i ++ )
{
var e = form . elements [ i ] ;
if ( e . type === 'checkbox' )
{
e . checked = true ;
}
}
}
2018-04-13 18:58:28 +02:00
/ * *
* select all the checkbox in a given form if the specific attribute
* has the given value
* @ param form _id id of the form
* @ param attribute name
* @ param attribute value
* /
function select _checkbox _attribute ( form _id , p _attribute _name , p _attribute _value )
{
var form = $ ( form _id ) ;
for ( var i = 0 ; i < form . length ; i ++ )
{
var e = form . elements [ i ] ;
if ( e . type === 'checkbox' && e . getAttribute ( p _attribute _name ) == p _attribute _value )
{
e . checked = true ;
}
}
}
2015-09-27 00:35:53 +02:00
/ * *
* unselect all the checkbox in a given form
* @ param form _id id of the form
* /
function unselect _checkbox ( form _id )
{
var form = $ ( form _id ) ;
for ( var i = 0 ; i < form . length ; i ++ )
{
var e = form . elements [ i ] ;
if ( e . type === 'checkbox' )
{
e . checked = false ;
}
}
}
/ * *
* show the calculator
* /
function show _calc ( )
{
if ( g ( 'calc1' ) )
{
this . document . getElementById ( 'inp' ) . value = "" ;
this . document . getElementById ( 'inp' ) . focus ( ) ;
return ;
}
var sid = 'calc1' ;
var shtml = '' ;
2018-04-13 18:58:28 +02:00
shtml += "<div class=\"bxbutton\">" ;
shtml += '<a class="icon" onclick="pin(\'calc1\')" id="pin_calc1"></a> <a onclick="removeDiv(\'calc1\');" href="javascript:void(0)" title="" class="icon">⨉</a>' ;
shtml += "</div>" ;
shtml += ' <h2 class="title">Calculatrice</h2>' ;
shtml += '<form name="calc_line" method="GET" onSubmit="cal();return false;" >Calculatrice simplifiée: écrivez simplement les opérations que vous voulez puis la touche retour. exemple : 1+2+3*(1/5) <input class="input_text" type="text" size="30" id="inp" name="calculator"> <input type="button" value="Efface" class="button" onClick="Clean();return false;" > <input type="button" value="Efface historique" class="button" onClick="CleanHistory();return false;" > <input type="button" class="button" value="Fermer" onClick="removeDiv(\'calc1\')" >' ;
shtml += '</form><span class="highligth" style="display:block" id="sub_total"> Taper une formule (ex 20*5.1) puis enter </span><span style="display:block" id="listing"> </span>' ;
2015-09-27 00:35:53 +02:00
var obj = { id : sid , html : shtml ,
2018-04-13 18:58:28 +02:00
drag : false , style : 'z-index:98'
2015-09-27 00:35:53 +02:00
} ;
add _div ( obj ) ;
this . document . getElementById ( 'inp' ) . focus ( ) ;
}
function display _periode ( p _dossier , p _id )
{
try
{
var queryString = "gDossier=" + p _dossier + "&op=input_per" + "&p_id=" + p _id ;
var popup = { 'id' : 'mod_periode' , 'cssclass' : 'inner_box' , 'html' : loading ( ) , 'style' : 'width:30em' , 'drag' : true } ;
if ( ! $ ( 'mod_periode' ) ) {
add _div ( popup ) ;
}
var action = new Ajax . Request (
"ajax_misc.php" ,
{ method : 'get' ,
parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : success _display _periode
}
) ;
$ ( 'mod_periode' ) . style . top = ( posY - 70 ) + "px" ;
$ ( 'mod_periode' ) . style . left = ( posX - 70 ) + "px" ;
}
catch ( e )
{
alert _box ( "display_periode " + e . message ) ;
}
}
function success _display _periode ( req )
{
try
{
var answer = req . responseXML ;
var html = answer . getElementsByTagName ( 'data' ) ;
if ( html . length === 0 )
{
var rec = req . responseText ;
alert _box ( 'erreur :' + rec ) ;
}
var code _html = getNodeText ( html [ 0 ] ) ;
code _html = unescape _xml ( code _html ) ;
$ ( 'mod_periode' ) . innerHTML = code _html ;
}
catch ( e )
{
alert _box ( "success_display_periode" . e . message ) ;
}
try
{
code _html . evalScripts ( ) ;
}
catch ( e )
{
alert _box ( "success_display_periode Impossible executer script de la reponse\n" + e . message ) ;
}
}
function save _periode ( obj )
{
try
{
var queryString = $ ( obj ) . serialize ( ) + "&op=save_per" ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{ method : 'post' ,
parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : success _display _periode
}
) ;
}
catch ( e )
{
alert _box ( "display_periode " + e . message ) ;
}
return false ;
}
/ * *
* @ brief basic answer to ajax on success , it will fill the ctl with
* the code . In that case , you need to create the object before the Ajax . Request
* The difference with success box is that
* @ see add _div removeDiv success _box is that the width and height are not changed
2018-04-13 18:58:28 +02:00
* @ param ctl is the ID of the object containing the html ( div , button ... )
* @ param code is the html code , with it you fill the ctl element
2015-09-27 00:35:53 +02:00
* /
function fill _box ( req )
{
try {
remove _waiting _box ( ) ;
var answer = req . responseXML ;
var a = answer . getElementsByTagName ( 'ctl' ) ;
var html = answer . getElementsByTagName ( 'code' ) ;
if ( a . length === 0 ) {
var rec = req . responseText ;
alert _box ( 'erreur :' + rec ) ;
}
var name _ctl = a [ 0 ] . firstChild . nodeValue ;
var code _html = getNodeText ( html [ 0 ] ) ; // Firefox ne prend que les 4096 car.
code _html = unescape _xml ( code _html ) ;
$ ( name _ctl ) . innerHTML = code _html ;
}
catch ( e ) {
alert _box ( e . message ) ;
2018-04-13 18:58:28 +02:00
if ( console ) {
console . error ( e ) ;
console . error ( "log answer = " + e . responseText ) ;
}
2015-09-27 00:35:53 +02:00
}
try {
code _html . evalScripts ( ) ;
}
catch ( e ) {
2018-04-13 18:58:28 +02:00
if ( console ) {
console . error ( e ) ;
console . error ( "log answer = " + e . responseText ) ;
}
2015-09-27 00:35:53 +02:00
alert _box ( "Impossible executer script de la reponse\n" + e . message ) ;
}
}
/ * *
* display a popin to let you modified a predefined operation
* @ param dossier _id
* @ param od _id from table op _predef
* /
function mod _predf _op ( dossier _id , od _id )
{
var target = "mod_predf_op" ;
removeDiv ( target ) ;
var sx = '20%' ;
var sy = '10%' ;
var str _style = "top:" + sx + ";left:" + sy + ";" ;
var div = { id : target , cssclass : 'inner_box' , style : str _style , html : loading ( ) , drag : 1 } ;
add _div ( div ) ;
var qs = "gDossier=" + dossier _id + '&op=mod_predf&id=' + od _id ;
var action = new Ajax . Request ( 'ajax_misc.php' ,
{
method : 'get' ,
parameters : qs ,
onFailure : null ,
onSuccess : fill _box
}
) ;
}
function save _predf _op ( obj )
{
waiting _box ( ) ;
var querystring = $ ( obj ) . serialize ( ) + '&op=save_predf' ;
// Create a ajax request to get all the person
var action = new Ajax . Request ( 'ajax_misc.php' ,
{
method : 'post' ,
parameters : querystring ,
onFailure : null ,
onSuccess : refresh _window
}
) ;
return false ;
}
/ * *
* ctl _concern is the widget to update
* amount _id is either a html obj . or an amount and the field tiers if given
* @ param { type } dossier
* @ param { type } ctl _concern
* @ param { type } amount _id
* @ param { type } ledger
2018-04-13 18:58:28 +02:00
* @ param { type } p _id _targetDom Element ( div ) where to display the search result
* @ param p _tiers id of the Tiers
2015-09-27 00:35:53 +02:00
* @ returns { undefined }
* /
2018-04-13 18:58:28 +02:00
function search _reconcile ( dossier , ctl _concern , amount _id , ledger , p _id _target , p _tiers )
2015-09-27 00:35:53 +02:00
{
var dossier = g ( 'gDossier' ) . value ;
if ( amount _id === undefined )
{
amount _id = 0 ;
}
else if ( $ ( amount _id ) )
{
if ( $ ( amount _id ) . value )
{
amount _id = $ ( amount _id ) . value ;
}
else if
( $ ( amount _id ) . innerHTML ) {
amount _id = $ ( amount _id ) . innerHTML ;
}
}
2018-04-13 18:58:28 +02:00
var tiers = ""
if ( p _tiers ) tiers = p _tiers ;
var target = "" ;
if ( p _id _target != "" ) {
target = p _id _target ;
} else {
target = "search" + layer ;
removeDiv ( target ) ;
}
2015-09-27 00:35:53 +02:00
var str _style = fixed _position ( 77 , 99 ) ;
str _style += ";width:92%;overflow:auto;" ;
waiting _box ( ) ;
2018-04-13 18:58:28 +02:00
var param _send = { gDossier : dossier ,
2015-09-27 00:35:53 +02:00
ctlc : ctl _concern ,
op : 'search_op' ,
ac : 'JSSEARCH' ,
amount _id : amount _id ,
ledger : ledger ,
2018-04-13 18:58:28 +02:00
target : target ,
tiers : tiers
} ;
2015-09-27 00:35:53 +02:00
2018-04-13 18:58:28 +02:00
var qs = encodeJSON ( param _send ) ;
2015-09-27 00:35:53 +02:00
var action = new Ajax . Request ( 'ajax_misc.php' ,
{
method : 'get' ,
parameters : qs ,
onFailure : null ,
onSuccess : function ( req ) {
remove _waiting _box ( ) ;
2018-04-13 18:58:28 +02:00
var div = { id : target , cssclass : 'inner_box' , style : str _style , drag : 0 } ;
2015-09-27 00:35:53 +02:00
add _div ( div ) ;
2018-04-13 18:58:28 +02:00
$ ( target ) . innerHTML = req . responseText ;
2015-09-27 00:35:53 +02:00
req . responseText . evalScripts ( ) ;
}
}
) ;
}
/ * *
* search in a popin obj if the object form
* /
function search _operation ( obj )
{
try {
var dossier = g ( 'gDossier' ) . value ;
waiting _box ( ) ;
2018-04-13 18:58:28 +02:00
var target = "search" + layer ;
if ( $ ( obj ) [ "target" ] ) {
target = $ ( obj ) [ "target" ] . value ;
}
var qs = Form . serialize ( 'search_form_ajx' ) + "&op=search_op" ;
2015-09-27 00:35:53 +02:00
var action = new Ajax . Request ( 'ajax_misc.php' ,
{
method : 'get' ,
parameters : qs ,
onFailure : null ,
onSuccess : function ( req ) {
remove _waiting _box ( ) ;
2018-04-13 18:58:28 +02:00
$ ( target ) . innerHTML = req . responseText ;
2015-09-27 00:35:53 +02:00
req . responseText . evalScripts ( ) ;
}
}
) ;
} catch ( e )
{
remove _waiting _box ( ) ;
alert _box ( e . message ) ;
}
}
/ * *
* Update the field e _concerned , from class _iconcerned
* Value is the field where to put the quick - code but only if one checkbox has been
* selected
* @ param { type } obj
* @ returns { undefined }
* /
function set _reconcile ( obj )
{
try
{
var ctlc = obj . elements [ 'ctlc' ] ;
2018-04-13 18:58:28 +02:00
var tiers = obj . elements [ 'tiers' ] ;
2015-09-27 00:35:53 +02:00
if ( ! obj . elements [ 'target' ] ) return ;
var target = obj . elements [ 'target' ] . value ;
for ( var e = 0 ; e < obj . elements . length ; e ++ )
{
2018-04-13 18:58:28 +02:00
2015-09-27 00:35:53 +02:00
var elmt = obj . elements [ e ] ;
if ( elmt . type === "checkbox" )
{
if ( elmt . checked === true )
{
var str _name = elmt . name ;
var nValue = str _name . replace ( "jr_concerned" , "" ) ;
if ( $ ( ctlc . value ) . value != '' ) {
$ ( ctlc . value ) . value += ',' ;
} else {
2018-04-13 18:58:28 +02:00
if ( tiers && tiers . value != "" ) {
$ ( tiers . value ) . value = elmt . value ;
2015-09-27 00:35:53 +02:00
}
}
$ ( ctlc . value ) . value += nValue ;
}
}
}
2018-04-13 18:58:28 +02:00
removeDiv ( obj . elements [ 'target' ] . value ) ;
2015-09-27 00:35:53 +02:00
}
catch ( e )
{
alert _box ( e . message )
}
}
function remove _waiting _node ( )
{
$ ( 'info_div' ) . innerHTML = "" ;
$ ( 'info_div' ) . style . display = "none" ;
}
function remove _waiting _box ( )
{
removeDiv ( 'wait_box' ) ;
remove _waiting _node ( ) ;
}
/ * *
* Show all the detail of a profile : Menu , Management , Repository and
* let the user to modify it
* @ param { type } gDossier
* @ param { type } profile _id
* @ returns { undefined }
* /
function get _profile _detail ( gDossier , profile _id )
{
waiting _box ( ) ;
var qs = "op=display_profile&gDossier=" + gDossier + "&p_id=" + profile _id + "&ctl=detail_profile" ;
var action = new Ajax . Request ( 'ajax_misc.php' ,
{
method : 'get' ,
parameters : qs ,
onFailure : null ,
onSuccess : function ( req ) {
remove _waiting _box ( ) ;
$ ( 'list_profile' ) . hide ( ) ;
$ ( 'detail_profile' ) . innerHTML = req . responseText ;
req . responseText . evalScripts ( ) ;
$ ( 'detail_profile' ) . show ( ) ;
if ( profile _id != "-1" )
profile _show ( 'profile_gen_div' ) ;
}
}
) ;
}
function get _profile _detail _success _obsolete ( xml )
{
remove _waiting _box ( ) ;
}
/ * *
* @ brief compute the string to position a div in a fixed way
* @ return string
* /
function fixed _position ( p _sx , p _sy )
{
var sx = p _sx ;
var sy = calcy ( p _sy ) ;
var str _style = "top:" + sy + "px;left:" + sx + "px;position:absolute" ;
return str _style ;
}
/ * *
* @ brief compute Y even if the windows has scrolled down or up
* @ return the correct Y position
* /
function calcy ( p _sy )
{
var sy = p _sy ;
2018-04-13 18:58:28 +02:00
if ( window . pageYOffset )
2015-09-27 00:35:53 +02:00
{
2018-04-13 18:58:28 +02:00
sy = window . pageYOffset + p _sy ;
2015-09-27 00:35:53 +02:00
}
else
{
2018-04-13 18:58:28 +02:00
sy = document . documentElement . scrollTop + p _sy ;
2015-09-27 00:35:53 +02:00
}
return sy ;
}
/ * *
* @ brief display a box with the menu option
* @ param { type } gdossier
* @ param { type } pm _id
* @ returns { undefined }
* /
function mod _menu ( gdossier , pm _id )
{
waiting _box ( ) ;
removeDiv ( 'divdm' + pm _id ) ;
var qs = "op=det_menu&gDossier=" + gdossier + "&pm_id=" + pm _id + "&ctl=divdm" + pm _id ;
var pos = fixed _position ( 50 , 250 ) ;
var action = new Ajax . Request ( 'ajax_misc.php' ,
{
method : 'get' ,
parameters : qs ,
onFailure : null ,
onSuccess : function ( req ) {
try {
remove _waiting _box ( ) ;
add _div ( { id : "divdm" + pm _id , drag : 1 , cssclass : "inner_box" , style : pos } ) ;
$ ( 'divdm' + pm _id ) . innerHTML = req . responseText ;
} catch ( e ) {
alert _box ( e . message ) ;
}
}
}
) ;
}
/ * *
* Display the submenu of a menu or a module , used in setting the menu
*
* @ param { type } p _dossier
* @ param { type } p _profile
* @ param { type } p _dep
* @ returns { undefined }
* /
function display _sub _menu ( p _dossier , p _profile , p _dep , p _level )
{
waiting _box ( ) ;
new Ajax . Request ( 'ajax_misc.php' ,
{
method : 'get' ,
parameters : { op : 'display_submenu' ,
gDossier : p _dossier ,
dep : p _dep ,
p _profile : p _profile ,
p _level : p _level
} ,
onSuccess : function ( req ) {
try {
remove _waiting _box ( ) ;
if ( $ ( 'menu_table' ) . rows . length > p _level ) {
$ ( 'menu_table' ) . rows [ 1 ] . remove ( ) ;
}
2018-04-13 18:58:28 +02:00
$ ( 'sub' + p _dep ) . addClassName ( "selectedmenu" ) ;
2015-09-27 00:35:53 +02:00
var new _row = document . createElement ( 'TR' ) ;
new _row . innerHTML = req . responseText ;
$ ( 'menu_table' ) . appendChild ( new _row ) ;
} catch ( e ) {
alert _box ( e . message ) ;
}
}
} )
}
/ * *
* in CFGPRO , ask to confirm before removing a submenu and its children
* @ param { type } p _dossier
* @ param { type } profile _menu _id
* @ returns { undefined }
* /
function remove _sub _menu ( p _dossier , profile _menu _id )
{
confirm _box ( null , 'Confirme ?' ,
function ( ) {
waiting _box ( ) ;
new Ajax . Request ( 'ajax_misc.php' ,
{
method : 'get' ,
parameters : { op : 'remove_submenu' , gDossier : p _dossier ,
p _profile _menu _id : profile _menu _id } ,
onSuccess : function ( req ) {
try {
remove _waiting _box ( ) ;
$ ( 'sub' + profile _menu _id ) . remove ( ) ;
if ( $ ( 'menu_table' ) . rows . length > 1 ) {
$ ( 'menu_table' ) . rows [ 1 ] . remove ( ) ;
}
} catch ( e )
{
alert _box ( e . message ) ;
}
}
}
)
} ) ;
}
/ * *
* @ brief add a menu to a profile , propose only the available menu
* @ param obj json object
* - dossier : ,
* - p _id : profile id ,
* - type : Type of menu are "pr" for Printing "me" for plain menu
* - p _level : level of menu ( 0 - > module , 1 - > top menu , 2 - > submenu )
* - dep : the parent menu id ( pm _id )
*
* /
function add _menu ( obj )
{
var pdossier = obj . dossier ;
var p _id = obj . p _id ;
var p _type = obj . type ;
waiting _box ( ) ;
removeDiv ( 'divdm' + p _id ) ;
var pos = fixed _position ( 250 , 150 ) + ";width:50%;" ;
var action = new Ajax . Request ( 'ajax_misc.php' ,
{
method : 'get' ,
parameters : { op : 'add_menu' ,
'gDossier' : pdossier ,
'p_id' : p _id ,
'ctl' : 'divdm' + p _id ,
'type' : p _type ,
'dep' : obj . dep ,
'p_level' : obj . p _level } ,
onFailure : null ,
onSuccess : function ( req ) {
try {
remove _waiting _box ( ) ;
add _div ( { id : "divdm" + p _id , drag : 1 , "cssclass" : "inner_box" , "style" : pos } ) ;
$ ( 'divdm' + p _id ) . innerHTML = req . responseText ;
} catch ( e ) {
alert _box ( e . message ) ;
}
}
}
) ;
}
/ * *
* @ brief Display a box to enter data for adding a new plugin from
* the CFGMENU
* @ param { type } p _dossier
* @ returns { undefined }
* /
function add _plugin ( p _dossier )
{
waiting _box ( ) ;
removeDiv ( 'divplugin' ) ;
var qs = "op=add_plugin&gDossier=" + p _dossier + "&ctl=divplugin" ;
var action = new Ajax . Request ( 'ajax_misc.php' ,
{
method : 'get' ,
parameters : qs ,
onFailure : null ,
onSuccess : function ( req ) {
try {
remove _waiting _box ( ) ;
var pos = fixed _position ( 250 , 150 ) + ";width:30%" ;
add _div ( { id : "divplugin" , drag : 1 , cssclass : "inner_box" , style : pos } ) ;
$ ( 'divplugin' ) . innerHTML = req . responseText ;
} catch ( e ) {
alert _box ( e . message ) ;
}
}
}
) ;
}
/ * *
* Modify a menu
* @ param { type } p _dossier
* @ param { type } me _code
* @ returns { undefined }
* /
function mod _plugin ( p _dossier , me _code )
{
waiting _box ( ) ;
removeDiv ( 'divplugin' ) ;
var qs = "op=mod_plugin&gDossier=" + p _dossier + "&ctl=divplugin&me_code=" + me _code ;
var action = new Ajax . Request ( 'ajax_misc.php' ,
{
method : 'get' ,
parameters : qs ,
onFailure : null ,
onSuccess : function ( req ) {
try {
remove _waiting _box ( ) ;
var pos = fixed _position ( 250 , 150 ) + ";width:30%" ;
add _div ( { id : "divplugin" , drag : 1 , cssclass : "inner_box" , style : pos } ) ;
$ ( 'divplugin' ) . innerHTML = req . responseText ;
} catch ( e ) {
alert _box ( e . message ) ;
}
}
}
) ;
}
function create _menu ( p _dossier )
{
waiting _box ( ) ;
removeDiv ( 'divmenu' ) ;
var qs = "op=create_menu&gDossier=" + p _dossier + "&ctl=divmenu" ;
var action = new Ajax . Request ( 'ajax_misc.php' ,
{
method : 'get' ,
parameters : qs ,
onFailure : null ,
onSuccess : function ( req ) {
try {
remove _waiting _box ( ) ;
var pos = fixed _position ( 250 , 150 ) + ";width:30%" ;
add _div ( {
id : "divmenu" ,
drag : 1 ,
cssclass : "inner_box" ,
style : pos
} ) ;
$ ( 'divmenu' ) . innerHTML = req . responseText ;
} catch ( e ) {
alert _box ( e . message ) ;
}
}
}
) ;
}
function modify _menu ( p _dossier , me _code )
{
waiting _box ( ) ;
removeDiv ( 'divmenu' ) ;
var qs = "op=modify_menu&gDossier=" + p _dossier + "&ctl=divmenu&me_code=" + me _code ;
var action = new Ajax . Request ( 'ajax_misc.php' ,
{
method : 'get' ,
parameters : qs ,
onFailure : null ,
onSuccess : function ( req ) {
try {
remove _waiting _box ( ) ;
var pos = fixed _position ( 250 , 150 ) + ";width:30%" ;
add _div ( {
id : "divmenu" ,
drag : 1 ,
cssclass : "inner_box" ,
style : pos
} ) ;
$ ( 'divmenu' ) . innerHTML = req . responseText ;
} catch ( e ) {
alert _box ( e . message ) ;
}
}
}
) ;
}
function get _properties ( obj )
{
var a _array = [ ] ;
var s _type = "[" + typeof obj + "]" ;
for ( var m in obj )
{
a _array . push ( m ) ;
}
alert _box ( s _type + a _array . join ( "," ) ) ;
}
/ * *
* @ brief add a line in the form for the report
* @ param p _dossier dossier id to connect
* /
function rapport _add _row ( p _dossier )
{
style = 'style="border: 1px solid blue;"' ;
var table = $ ( "rap1" ) ;
var line = table . rows . length ;
var row = table . insertRow ( line ) ;
// left cell
var cellPos = row . insertCell ( 0 ) ;
cellPos . innerHTML = '<input type="text" ' + style + ' size="3" id="pos' + line + '" name="pos' + line + '" value="' + line + '">' ;
// right cell
var cellName = row . insertCell ( 1 ) ;
cellName . innerHTML = '<input type="text" ' + style + ' size="40" id="text' + line + '" name="text' + line + '">' ;
// button + formula
var cellbutton = row . insertCell ( 2 ) ;
var but _html = table . rows [ 1 ] . cells [ 2 ] . innerHTML ;
but _html = but _html . replace ( /form0/g , "form" + line ) ;
cellbutton . innerHTML = but _html ;
but _html . evalScripts ( ) ;
g ( 'form' + line ) . value = '' ;
}
/ * *
* Search an action in an inner box
* /
function search _action ( dossier , ctl _concern )
{
try
{
2018-04-13 18:58:28 +02:00
waiting _box ( ) ;
2015-09-27 00:35:53 +02:00
var dossier = g ( 'gDossier' ) . value ;
var target = "search_action_div" ;
removeDiv ( target ) ;
var str _style = fixed _position ( 77 , 99 ) ;
var div = { id : target , cssclass : 'inner_box' , style : str _style , html : loading ( ) , drag : 1 } ;
2018-04-13 18:58:28 +02:00
2015-09-27 00:35:53 +02:00
var target = { gDossier : dossier ,
ctlc : ctl _concern ,
op : 'search_action' ,
ctl : target
} ;
var qs = encodeJSON ( target ) ;
var action = new Ajax . Request ( 'ajax_misc.php' ,
{
method : 'get' ,
parameters : qs ,
onFailure : null ,
onSuccess : function ( req ) {
try {
remove _waiting _box ( ) ;
2018-04-13 18:58:28 +02:00
add _div ( div ) ;
2015-09-27 00:35:53 +02:00
$ ( 'search_action_div' ) . innerHTML = req . responseText ;
req . responseText . evalScripts ( ) ;
} catch ( e ) {
alert _box ( e . message ) ;
}
}
}
) ;
} catch ( e ) {
alert _box ( e . message ) ;
}
}
function result _search _action ( obj )
{
try
{
var queryString = $ ( obj ) . serialize ( ) + "&op=search_action" ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{ method : 'get' ,
parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req ) {
try {
remove _waiting _box ( ) ;
$ ( 'search_action_div' ) . innerHTML = req . responseText ;
req . responseText . evalScripts ( ) ;
} catch ( e ) {
alert _box ( e . message ) ;
}
}
}
)
}
catch ( e )
{
alert _box ( "display_periode " + e . message ) ;
}
return false ;
}
function set _action _related ( p _obj )
{
try
{
var obj = $ ( p _obj ) ;
var ctlc = obj . elements [ 'ctlc' ] ;
for ( var e = 0 ; e < obj . elements . length ; e ++ )
{
var elmt = obj . elements [ e ] ;
if ( elmt . type === "checkbox" )
{
if ( elmt . checked === true )
{
var str _name = elmt . name ;
var nValue = elmt . value ;
if ( $ ( ctlc . value ) . value != '' ) {
$ ( ctlc . value ) . value += ',' ;
}
$ ( ctlc . value ) . value += nValue ;
}
}
}
removeDiv ( 'search_action_div' ) ;
return false ;
}
catch ( e )
{
alert _box ( e . message ) ;
return false ;
}
}
/ * *
2018-04-13 18:58:28 +02:00
* @ brief Show a form to modify or add a new repository
* @ param p _dossier
* @ param r _id : repository id
2015-09-27 00:35:53 +02:00
* /
function stock _repo _change ( p _dossier , r _id )
{
var queryString = "gDossier=" + p _dossier + "&op=mod_stock_repo" + "&r_id=" + r _id ;
var nTop = calcy ( posY ) ;
2018-04-13 18:58:28 +02:00
var nLeft = "10.1562%" ;
var str _style = "top:" + nTop + "px;left:" + nLeft + ";height:auto;width:auto" ;
2015-09-27 00:35:53 +02:00
removeDiv ( 'change_stock_repo_div' ) ;
waiting _box ( ) ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' , parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req ) {
remove _waiting _box ( ) ;
add _div ( { id : 'change_stock_repo_div' , style : str _style , cssclass : 'inner_box' , drag : "1" } ) ;
$ ( 'change_stock_repo_div' ) . innerHTML = req . responseText ;
}
}
) ;
}
function stock _inv _detail ( p _dossier , p _id )
{
var queryString = "gDossier=" + p _dossier + "&op=view_mod_stock" + "&c_id=" + p _id + "&ctl=view_mod_stock_div" ;
var nTop = calcy ( posY ) ;
var nLeft = "10%" ;
var str _style = "top:" + nTop + "px;left:" + nLeft + ";width:80%;" ;
removeDiv ( 'view_mod_stock_div' ) ;
waiting _box ( ) ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' , parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req ) {
remove _waiting _box ( ) ;
add _div ( { id : 'view_mod_stock_div' , style : str _style , cssclass : 'inner_box' , drag : "1" } ) ;
$ ( 'view_mod_stock_div' ) . innerHTML = req . responseText ;
req . responseText . evalScripts ( ) ;
}
}
) ;
}
function show _fin _chdate ( obj _id )
{
try
{
var ch = $ ( obj _id ) . options [ $ ( obj _id ) . selectedIndex ] . value ;
if ( ch == 2 ) {
$ ( 'chdate_ext' ) . hide ( ) ;
$ ( 'thdate' ) . show ( ) ;
}
if ( ch == 1 ) {
$ ( 'chdate_ext' ) . show ( ) ;
$ ( 'thdate' ) . hide ( ) ;
}
var nb = $ ( 'nb_item' ) . value ;
for ( i = 0 ; i < nb ; i ++ ) {
if ( $ ( 'tdchdate' + i ) ) {
if ( ch == 2 ) {
$ ( 'tdchdate' + i ) . show ( ) ;
}
if ( ch == 1 ) {
$ ( 'tdchdate' + i ) . hide ( ) ;
}
}
}
} catch ( e ) {
alert _box ( e . message ) ;
}
}
/ * *
* tab menu for the profile parameter
* /
function profile _show ( p _div )
{
try {
var div = [ 'profile_gen_div' , 'profile_menu_div' , 'profile_print_div' , 'profile_gestion_div' , 'profile_repo_div' ] ;
for ( var r = 0 ; r < div . length ; r ++ ) {
$ ( div [ r ] ) . hide ( ) ;
}
$ ( p _div ) . show ( ) ;
} catch ( e )
{
2018-04-13 18:58:28 +02:00
alert _box ( e . message ) ;
2015-09-27 00:35:53 +02:00
}
}
function detail _category _show ( p _div , p _dossier , p _id )
{
$ ( p _div ) . show ( ) ;
waiting _box ( ) ;
$ ( 'detail_category_div' ) . innerHTML = "" ;
var queryString = "gDossier=" + p _dossier + "&id=" + p _id + "&op=fddetail" ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' , parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req ) {
remove _waiting _box ( ) ;
$ ( 'list_cat_div' ) . hide ( ) ;
$ ( 'detail_category_div' ) . innerHTML = req . responseText ;
$ ( 'detail_category_div' ) . show ( ) ;
req . responseText . evalScripts ( ) ;
}
}
) ;
}
/ * *
* @ brief check if the parameter is a valid a valid date or not , returns true if it is valid otherwise
* false
2018-04-13 18:58:28 +02:00
* @ param p _str _date the string of the date ( format DD . MM . YYYY )
2015-09-27 00:35:53 +02:00
* /
function check _date ( p _str _date )
{
var format = /^\d{2}\.\d{2}\.\d{4}$/ ;
if ( ! format . test ( p _str _date ) ) {
return false ;
}
else {
var date _temp = p _str _date . split ( '.' ) ;
var nMonth = parseFloat ( date _temp [ 1 ] ) - 1 ;
var ma _date = new Date ( date _temp [ 2 ] , nMonth , date _temp [ 0 ] ) ;
if ( ma _date . getFullYear ( ) == date _temp [ 2 ] && ma _date . getMonth ( ) == nMonth && ma _date . getDate ( ) == date _temp [ 0 ] ) {
return true ;
}
else {
return false ;
}
}
}
/ * *
* @ brief get the string in the id and check if the date is valid
2018-04-13 18:58:28 +02:00
* @ param p _id _date is the id of the element to check
2015-09-27 00:35:53 +02:00
* @ return true if the date is valid
* @ see check _date
* /
function check _date _id ( p _id _date )
{
var str _date = $ ( p _id _date ) . value ;
return check _date ( str _date ) ;
}
/ * *
*
* @ param ag _id to view
* @ param dossier is the folder
* @ param modify : show the modify button values : 0 for no 1 for yes
* /
function view _action ( ag _id , dossier , modify )
{
waiting _box ( ) ;
layer ++ ;
id = 'action' + layer ;
querystring = 'gDossier=' + dossier + '&op=vw_action&ag_id=' + ag _id + '&div=' + id + '&mod=' + modify ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' ,
parameters : querystring ,
onFailure : error _box ,
onSuccess : function ( req ) {
try {
remove _waiting _box ( ) ;
var answer = req . responseXML ;
var ctl = answer . getElementsByTagName ( 'ctl' ) ;
if ( ctl . length == 0 ) {
throw 'ajax failed ctl view_action' ;
}
var ctl _txt = getNodeText ( ctl [ 0 ] ) ;
var html = answer . getElementsByTagName ( 'code' ) ;
if ( html . length === 0 )
{
var rec = req . responseText ;
throw 'ajax failed html view_action' ;
}
var code _html = getNodeText ( html [ 0 ] ) ;
code _html = unescape _xml ( code _html ) ;
var pos = fixed _position ( 0 , 50 ) + ";width:90%;left:5%;" ;
add _div ( {
id : id ,
cssclass : "inner_box" ,
style : pos
} ) ;
$ ( id ) . innerHTML = code _html ;
if ( ctl _txt == 'ok' ) { compute _all _ledger ( ) ; }
2018-04-13 18:58:28 +02:00
code _html . evalScripts ( ) ;
2015-09-27 00:35:53 +02:00
} catch ( e ) {
alert _box ( 'view_action' + e . message ) ;
}
}
}
) ;
}
/ * *
* @ brief filter quickly a table
* @ param phrase : phrase to seach
* @ param _id : id of the table
* @ param colnr : string containing the column number where you ' re searching separated by a comma
* @ param start _row : first row ( 1 if you have table header )
* @ returns nothing
* @ see HtmlInput : : filter _table
* /
function filter _table ( phrase , _id , colnr , start _row ) {
$ ( 'info_div' ) . innerHTML = "Un instant" ;
$ ( 'info_div' ) . style . display = "block" ;
var words = $ ( phrase ) . value . toLowerCase ( ) ;
var table = document . getElementById ( _id ) ;
// if colnr contains a comma then check several columns
var aCol = new Array ( ) ;
if ( colnr . indexOf ( ',' ) >= 0 ) {
aCol = colnr . split ( ',' ) ;
} else {
aCol [ 0 ] = colnr ;
}
var ele ;
var tot _found = 0 ;
for ( var r = start _row ; r < table . rows . length ; r ++ ) {
var found = 0 ;
for ( var col = 0 ; col < aCol . length ; col ++ )
{
var idx = aCol [ col ] ;
if ( table . rows [ r ] . cells [ idx ] )
{
ele = table . rows [ r ] . cells [ idx ] . innerHTML . replace ( /<[^>]+>/g , "" ) ;
//var displayStyle = 'none';
if ( ele . toLowerCase ( ) . indexOf ( words ) >= 0 ) {
found = 1 ;
}
}
}
if ( found === 1 ) {
tot _found ++ ;
table . rows [ r ] . style . display = '' ;
} else {
table . rows [ r ] . style . display = 'none' ;
}
$ ( 'info_div' ) . style . display = "none" ;
$ ( 'info_div' ) . innerHTML = "" ;
}
if ( tot _found == 0 ) {
if ( $ ( 'info_' + _id ) ) {
$ ( 'info_' + _id ) . innerHTML = " Aucun résultat " ;
}
} else {
if ( $ ( 'info_' + _id ) ) {
$ ( 'info_' + _id ) . innerHTML = " " ;
}
}
}
/ * *
* @ brief
* Display the task late or for today in dashboard
* /
function display _task ( p _id )
{
2018-04-13 18:58:28 +02:00
2015-09-27 00:35:53 +02:00
$ ( p _id ) . style . top = posY + 'px' ;
$ ( p _id ) . style . left = "10%" ;
$ ( p _id ) . style . width = "80%" ;
$ ( p _id ) . style . display = 'block' ;
}
/ * *
* @ brief
* Set a message in the info
* /
function info _message ( p _message )
{
$ ( 'info_div' ) . innerHTML = p _message ;
$ ( 'info_div' ) . style . display = "block" ;
}
/ * *
* @ brief hide the info box
* /
function info _hide ( )
{
$ ( 'info_div' ) . style . display = "none" ;
}
/ * *
* Show the navigator in a internal window
* @ returns { undefined }
* /
function ask _navigator ( p _dossier ) {
try {
waiting _box ( ) ;
removeDiv ( 'navi_div' )
var queryString = "gDossier=" + p _dossier + "&op=navigator" ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' , parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req ) {
remove _waiting _box ( ) ;
add _div ( { id : 'navi_div' , style : 'top:2em;left:2em;width:90%' , cssclass : 'inner_box' } ) ;
$ ( 'navi_div' ) . innerHTML = req . responseText ;
try
{
req . responseText . evalScripts ( ) ;
sorttable . makeSortable ( $ ( "navi_tb" ) ) ;
}
catch ( e )
{
alert _box ( "answer_box Impossible executer script de la reponse\n" + e . message ) ;
}
}
}
) ;
} catch ( e ) {
2018-04-13 18:58:28 +02:00
info _message ( e . message ) ;
2015-09-27 00:35:53 +02:00
}
}
/ * *
* @ brief Display an internal windows to set the user ' s preference
*
* /
function set _preference ( p _dossier ) {
try {
waiting _box ( ) ;
removeDiv ( 'preference_div' )
var queryString = "gDossier=" + p _dossier + "&op=preference" ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' , parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req ) {
remove _waiting _box ( ) ;
add _div ( { id : 'preference_div' , drag : 1 } ) ;
$ ( 'preference_div' ) . innerHTML = req . responseText ;
try
{
req . responseText . evalScripts ( ) ;
}
catch ( e )
{
alert _box ( "answer_box Impossible executer script de la reponse\n" + e . message ) ;
}
}
}
) ;
} catch ( e ) {
2018-04-13 18:58:28 +02:00
info _message ( e . message ) ;
2015-09-27 00:35:53 +02:00
}
}
/ * *
* @ brief Display user ' s bookmark
*
* /
function show _bookmark ( p _dossier ) {
try {
waiting _box ( ) ;
removeDiv ( 'bookmark_div' ) ;
var param = window . location . search ;
param = param . gsub ( '?' , '' ) ;
var queryString = "gDossier=" + p _dossier + "&op=bookmark&" + param ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' , parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req ) {
remove _waiting _box ( ) ;
add _div ( { id : 'bookmark_div' , cssclass : 'inner_box' , drag : 1 } ) ;
$ ( 'bookmark_div' ) . innerHTML = req . responseText ;
try
{
req . responseText . evalScripts ( ) ;
}
catch ( e )
{
alert _box ( "answer_box Impossible executer script de la reponse\n" + e . message ) ;
}
}
}
) ;
} catch ( e ) {
2018-04-13 18:58:28 +02:00
info _message ( e . message ) ;
2015-09-27 00:35:53 +02:00
}
}
/ * *
* @ brief save the bookmark
* /
function save _bookmark ( ) {
try {
waiting _box ( ) ;
var queryString = "op=bookmark&" + $ ( "bookmark_frm" ) . serialize ( ) ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' , parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req ) {
remove _waiting _box ( ) ;
// removeDiv('bookmark_div');
//
$ ( 'bookmark_div' ) . innerHTML = req . responseText ;
try
{
req . responseText . evalScripts ( ) ;
}
catch ( e )
{
alert _box ( "answer_box Impossible executer script de la reponse\n" + e . message ) ;
}
}
}
) ;
} catch ( e ) {
2018-04-13 18:58:28 +02:00
info _message ( e . message ) ;
2015-09-27 00:35:53 +02:00
}
}
/ * *
* @ brief remove selected bookmark
* /
function remove _bookmark ( ) {
try {
waiting _box ( ) ;
var queryString = "op=bookmark&" + $ ( "bookmark_del_frm" ) . serialize ( ) ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' , parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req ) {
remove _waiting _box ( ) ;
$ ( 'bookmark_div' ) . innerHTML = req . responseText ;
try
{
req . responseText . evalScripts ( ) ;
}
catch ( e )
{
alert _box ( "answer_box Impossible executer script de la reponse\n" + e . message ) ;
}
}
}
) ;
} catch ( e ) {
2018-04-13 18:58:28 +02:00
error _message ( e . message ) ;
2015-09-27 00:35:53 +02:00
}
}
/ * *
* @ brief display the error message into the div error _content _div ( included into error _div )
* @ param message message to display
* @ note there is no protection
* /
function error _message ( message )
{
$ ( 'error_content_div' ) . innerHTML = message ;
$ ( 'error_div' ) . style . visibility = 'visible' ;
}
/ * *
* @ brief show the detail of a tag and propose to save it
* /
function show _tag ( p _dossier , p _ac , p _tag _id , p _post )
{
try {
waiting _box ( ) ;
var queryString = "op=tag_detail&tag=" + p _tag _id + "&gDossier=" + p _dossier + "&ac=" + p _ac + '&form=' + p _post ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' , parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req ) {
var answer = req . responseXML ;
var html = answer . getElementsByTagName ( 'code' ) ;
if ( html . length === 0 )
{
var rec = req . responseText ;
alert _box ( 'erreur :' + rec ) ;
}
var code _html = getNodeText ( html [ 0 ] ) ;
code _html = unescape _xml ( code _html ) ;
remove _waiting _box ( ) ;
2018-04-13 18:58:28 +02:00
var posy = calcy ( 250 ) ;
add _div ( { id : 'tag_div' , cssclass : 'inner_box' , drag : 0 , style : "position:fixed;top:" + posy + "px" } ) ;
2015-09-27 00:35:53 +02:00
$ ( 'tag_div' ) . innerHTML = code _html ;
try
{
code _html . evalScripts ( ) ;
}
catch ( e )
{
alert _box ( "answer_box Impossible executer script de la reponse\n" + e . message ) ;
}
}
}
) ;
} catch ( e ) {
2018-04-13 18:58:28 +02:00
error _message ( e . message ) ;
2015-09-27 00:35:53 +02:00
}
}
/ * *
* @ brief save the modified tag
* /
function save _tag ( )
{
try {
waiting _box ( ) ;
var queryString = "op=tag_save&" + $ ( "tag_detail_frm" ) . serialize ( ) ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' ,
parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req , j ) {
remove _waiting _box ( ) ;
removeDiv ( 'tag_div' ) ;
}
}
) ;
} catch ( e ) {
2018-04-13 18:58:28 +02:00
error _message ( e . message ) ;
2015-09-27 00:35:53 +02:00
return false ;
}
return false ;
}
/ * *
* Show a list of tag which can be added to the current followup document
* @ param { type } p _dossier
* @ param { type } ag _id
* @ returns { undefined }
* /
function action _tag _select ( p _dossier , ag _id )
{
try {
waiting _box ( ) ;
var queryString = "ag_id=" + ag _id + "&op=tag_list&gDossier=" + p _dossier ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' , parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req , j ) {
var answer = req . responseXML ;
var html = answer . getElementsByTagName ( 'code' ) ;
if ( html . length === 0 )
{
var rec = unescape _xml ( req . responseText ) ;
error _message ( 'erreur :' + rec ) ;
}
var code _html = getNodeText ( html [ 0 ] ) ;
code _html = unescape _xml ( code _html ) ;
2018-04-13 18:58:28 +02:00
var pos = fixed _position ( 35 , 229 ) ;
add _div ( { id : 'tag_div' , style : pos , cssclass : 'inner_box tag' , drag : 0 } ) ;
2015-09-27 00:35:53 +02:00
remove _waiting _box ( ) ;
$ ( 'tag_div' ) . innerHTML = code _html ;
}
}
) ;
} catch ( e ) {
2018-04-13 18:58:28 +02:00
error _message ( e . message ) ;
2015-09-27 00:35:53 +02:00
}
}
/ * *
* @ brief Add the current tag to the current ag _id
* @ param { type } p _dossier
* @ param { type } ag _id
* @ returns { undefined }
* /
function action _tag _add ( p _dossier , ag _id , t _id )
{
try {
waiting _box ( ) ;
var queryString = "t_id=" + t _id + "&ag_id=" + ag _id + "&op=tag_add&gDossier=" + p _dossier ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' , parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req , j ) {
var answer = req . responseXML ;
var html = answer . getElementsByTagName ( 'code' ) ;
if ( html . length === 0 )
{
var rec = unescape _xml ( req . responseText ) ;
error _message ( 'erreur :' + rec ) ;
}
var code _html = getNodeText ( html [ 0 ] ) ;
code _html = unescape _xml ( code _html ) ;
remove _waiting _box ( ) ;
$ ( 'action_tag_td' ) . innerHTML = code _html ;
removeDiv ( 'tag_div' ) ;
}
}
) ;
} catch ( e ) {
2018-04-13 18:58:28 +02:00
error _message ( e . message ) ;
2015-09-27 00:35:53 +02:00
}
}
/ * *
* @ brief remove the current tag to the current ag _id
* @ param { type } p _dossier
* @ param { type } ag _id
* @ returns { undefined }
* /
function action _tag _remove ( p _dossier , ag _id , t _id )
{
2018-04-13 18:58:28 +02:00
confirm _box ( null , 'Enlevez ce tags ?' , function ( ) {
try {
waiting _box ( ) ;
var queryString = "t_id=" + t _id + "&ag_id=" + ag _id + "&op=tag_remove&gDossier=" + p _dossier ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' , parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req , j ) {
var answer = req . responseXML ;
var html = answer . getElementsByTagName ( 'code' ) ;
if ( html . length === 0 )
{
var rec = unescape _xml ( req . responseText ) ;
error _message ( 'erreur :' + rec ) ;
}
var code _html = getNodeText ( html [ 0 ] ) ;
code _html = unescape _xml ( code _html ) ;
remove _waiting _box ( ) ;
$ ( 'action_tag_td' ) . innerHTML = code _html ;
2015-09-27 00:35:53 +02:00
2018-04-13 18:58:28 +02:00
}
2015-09-27 00:35:53 +02:00
}
2018-04-13 18:58:28 +02:00
) ;
} catch ( e ) {
error _message ( e . message ) ;
}
} ) ;
2015-09-27 00:35:53 +02:00
}
2018-04-13 18:58:28 +02:00
/ * *
* Activate a tag
* @ param int p _dossier
* @ param int p _tag _id
* /
function activate _tag ( p _dossier , p _tag _id ) {
waiting _box ( ) ;
new Ajax . Request ( "ajax_misc.php" ,
{
method : "get" ,
parameters : { gDossier : p _dossier , op : 'tag_activate' , t _id : p _tag _id } ,
onSuccess : function ( req ) {
remove _waiting _box ( ) ;
var answer = req . responseText . evalJSON ( ) ;
var tagId = "tag_onoff" + p _tag _id ;
$ ( tagId ) . update ( answer . code ) ;
$ ( tagId ) . setStyle ( answer . style ) ;
remove _waiting _box ( ) ;
}
} )
}
2015-09-27 00:35:53 +02:00
/ * *
* Display a div with available tags , this div can update the cell
* tag _choose _td
* @ param { type } p _dossier
* @ returns { undefined }
* /
function search _display _tag ( p _dossier , p _prefix )
{
try {
waiting _box ( ) ;
var queryString = "op=search_display_tag&gDossier=" + p _dossier + "&pref=" + p _prefix ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' , parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req , j ) {
var answer = req . responseXML ;
var html = answer . getElementsByTagName ( 'code' ) ;
if ( html . length === 0 )
{
var rec = unescape _xml ( req . responseText ) ;
error _message ( 'erreur :' + rec ) ;
}
var code _html = getNodeText ( html [ 0 ] ) ;
code _html = unescape _xml ( code _html ) ;
remove _waiting _box ( ) ;
2018-04-13 18:58:28 +02:00
add _div ( { id : p _prefix + 'tag_div' , style : 'left:10%;width:70%' , cssclass : 'inner_box' , drag : 1 } ) ;
2015-09-27 00:35:53 +02:00
$ ( p _prefix + 'tag_div' ) . style . top = posY - 80 + "px" ;
$ ( p _prefix + 'tag_div' ) . style . left = posX - 200 + "px" ;
remove _waiting _box ( ) ;
$ ( p _prefix + 'tag_div' ) . innerHTML = code _html ;
2018-04-13 18:58:28 +02:00
code _html . evalScripts ( ) ;
2015-09-27 00:35:53 +02:00
}
}
) ;
} catch ( e ) {
2018-04-13 18:58:28 +02:00
error _message ( e . message ) ;
2015-09-27 00:35:53 +02:00
}
}
/ * *
* @ brief Add the selected tag ( p _tag _id ) to the cell of tag _choose _td in the search screen
* in the search screen
* @ param { type } p _dossier
* @ param { type } p _tag _id
* /
function search _add _tag ( p _dossier , p _tag _id , p _prefix )
{
try {
var clear _button = 0 ;
if ( tag _choose === '' && p _prefix === 'search' ) {
tag _choose = $ ( p _prefix + 'tag_choose_td' ) . innerHTML ;
clear _button = 1 ;
}
waiting _box ( ) ;
var queryString = "op=search_add_tag&gDossier=" + p _dossier + "&id=" + p _tag _id + "&clear=" + clear _button + '&pref=' + p _prefix ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' , parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req , j ) {
var answer = req . responseXML ;
var html = answer . getElementsByTagName ( 'html' ) ;
if ( html . length === 0 )
{
var rec = unescape _xml ( req . responseText ) ;
error _message ( 'erreur :' + rec ) ;
}
var code _html = getNodeText ( html [ 0 ] ) ;
code _html = unescape _xml ( code _html ) ;
remove _waiting _box ( ) ;
$ ( p _prefix + 'tag_choose_td' ) . innerHTML = $ ( p _prefix + 'tag_choose_td' ) . innerHTML + code _html ;
removeDiv ( p _prefix + 'tag_div' ) ;
}
}
) ;
} catch ( e ) {
2018-04-13 18:58:28 +02:00
error _message ( e . message ) ;
2015-09-27 00:35:53 +02:00
}
}
/ * *
* Clear the tags in the cell tag _choose _td of the search screen
* @ returns { undefined }
* /
function search _clear _tag ( p _dossier , p _prefix )
{
if ( p _prefix != 'search' ) {
$ ( p _prefix + 'tag_choose_td' ) . innerHTML = "" ;
return ;
}
try {
var queryString = "op=search_clear_tag&gDossier=" + p _dossier + "&pref=" + p _prefix ;
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' , parameters : queryString ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req , j ) {
var answer = req . responseXML ;
var html = answer . getElementsByTagName ( 'html' ) ;
if ( html . length === 0 )
{
var rec = unescape _xml ( req . responseText ) ;
error _message ( 'erreur :' + rec ) ;
}
var code _html = getNodeText ( html [ 0 ] ) ;
code _html = unescape _xml ( code _html ) ;
$ ( p _prefix + 'tag_choose_td' ) . innerHTML = code _html ;
tag _choose = "" ;
}
}
) ;
} catch ( e ) {
2018-04-13 18:58:28 +02:00
error _message ( e . message ) ;
2015-09-27 00:35:53 +02:00
}
}
function action _show _checkbox ( )
{
var a = document . getElementsByName ( 'ag_id_td' ) ;
for ( var i = 0 ; i < a . length ; i ++ ) {
a [ i ] . style . display = 'block' ;
}
}
function action _hide _checkbox ( )
{
var a = document . getElementsByName ( 'ag_id_td' ) ;
for ( var i = 0 ; i < a . length ; i ++ ) {
a [ i ] . style . display = 'none' ;
}
}
/ * *
*
* @ param { type } obj
* object attribute : g
* - Dossier dossier _id ,
* - invalue DOM Element where you can find the periode to zoom
* - outdiv ID of the target ( DIV )
*
* /
function calendar _zoom ( obj )
{
try {
waiting _box ( ) ;
var per _periode = null ;
var notitle = 0 ;
var from = 0 ;
if ( $ ( obj . invalue ) ) { per _periode = $ ( obj . invalue ) . value ; }
if ( obj . notitle && obj . notitle == 1 ) { notitle = 1 ; }
var action = new Ajax . Request (
"ajax_misc.php" ,
{
method : 'get' ,
parameters : { "notitle" : notitle , "op" : 'calendar_zoom' , 'from' : from , 'gDossier' : obj . gDossier , 'in' : per _periode , 'out' : obj . outdiv , 'distype' : obj . distype } ,
onFailure : ajax _misc _failure ,
onSuccess : function ( req , j ) {
var answer = req . responseXML ;
var html = answer . getElementsByTagName ( 'html' ) ;
if ( html . length === 0 )
{
var rec = unescape _xml ( req . responseText ) ;
error _message ( 'erreur :' + rec ) ;
}
var code _html = getNodeText ( html [ 0 ] ) ;
code _html = unescape _xml ( code _html ) ;
// if the target doesn't exist
// then create it
if ( obj . outdiv === undefined ) {
obj . outdiv = 'calendar_zoom_div' ;
}
if ( $ ( obj . outdiv ) == undefined ) {
2018-04-13 18:58:28 +02:00
var str _style = 'top:10%;margin-left:2%;' ;
// var str_style = fixed_position(0, 120);
add _div ( { id : obj . outdiv , style : 'margin-left:3%;width:94%;' + str _style , cssclass : "inner_box" , drag : 0 } ) ;
2015-09-27 00:35:53 +02:00
}
remove _waiting _box ( ) ;
$ ( obj . outdiv ) . innerHTML = code _html ;
$ ( obj . outdiv ) . show ( ) ;
}
}
) ;
} catch ( e ) {
2018-04-13 18:58:28 +02:00
error _message ( 'calendar_zoom ' + e . message ) ;
2015-09-27 00:35:53 +02:00
}
}
/ * *
* @ brief add a line in the form for the stock
* /
function stock _add _row ( )
{
try {
style = 'class="input_text"' ;
var mytable = g ( "stock_tb" ) . tBodies [ 0 ] ;
var ofirstRow = mytable . rows [ 1 ] ;
var line = mytable . rows . length ;
var nCell = mytable . rows [ 1 ] . cells . length ;
var row = mytable . insertRow ( line ) ;
var nb = g ( "row" ) ;
for ( var e = 0 ; e < nCell ; e ++ )
{
var newCell = row . insertCell ( e ) ;
if ( mytable . rows [ 1 ] . cells [ e ] . hasClassName ( 'num' ) ) {
newCell . addClassName ( "num" ) ;
}
var tt = ofirstRow . cells [ e ] . innerHTML ;
var new _tt = tt . replace ( /sg_code0/g , "sg_code" + nb . value ) ;
new _tt = new _tt . replace ( /sg_quantity0/g , "sg_quantity" + nb . value ) ;
new _tt = new _tt . replace ( /label0/g , "label" + nb . value ) ;
newCell . innerHTML = new _tt ;
new _tt . evalScripts ( ) ;
}
g ( "sg_code" + nb . value ) . innerHTML = ' ' ;
g ( "sg_code" + nb . value ) . value = '' ;
g ( "label" + nb . value ) . innerHTML = '' ;
g ( "sg_quantity" + nb . value ) . value = '0' ;
nb . value ++ ;
new _tt . evalScripts ( ) ;
} catch ( e ) {
alert _box ( e . message ) ;
}
}
function show _description ( p _id )
{
$ ( 'print_desc' + p _id ) . hide ( ) ;
$ ( 'input_desc' + p _id ) . show ( ) ;
}
/ * *
2018-04-13 18:58:28 +02:00
* Display an empty card to fill , with the right card category
* @ param pn _fiche _card _id : fiche _def . fd _id
* @ param pn _dossier _id
* /
function select _cat ( pn _fiche _card _id , pn _dossier _id , ps _element _id )
2015-09-27 00:35:53 +02:00
{
2018-04-13 18:58:28 +02:00
dis _blank _card ( { "ctl" : "div_new_card" , "fd_id" : pn _fiche _card _id , "op2" : "bc" , "op" : "card" , gDossier : pn _dossier _id , "elementId" : ps _element _id } ) ;
removeDiv ( 'select_card_div' ) ;
2015-09-27 00:35:53 +02:00
}
/ * *
* Show the DIV and hide the other , the array of possible DIV are
* in a _tabs ,
* @ param { array } a _tabs name of possible tabs
* @ param { strng } p _display _tab tab to display
* /
function show _tabs ( a _tabs , p _display _tab )
{
try
{
if ( a _tabs . length == 0 )
trow ( 'a_tabs in empty' ) ;
var i = 0 ;
for ( i = 0 ; i < a _tabs . length ; i ++ ) {
$ ( a _tabs [ i ] ) . hide ( ) ;
}
$ ( p _display _tab ) . show ( ) ;
} catch ( e ) {
alert _box ( e . message ) ;
}
}
/ * *
* Change the class of all the "LI" element of a UL or OL
* @ param node of ul ( this )
* /
function unselect _other _tab ( p _tab )
{
try {
var other = p _tab . getElementsByTagName ( "li" ) ;
var i = 0 ;
var tab = null ;
for ( i = 0 ; i < other . length ; i ++ ) {
tab = other [ i ] ;
tab . className = "tabs" ;
}
} catch ( e ) {
if ( console )
console . log ( e . message ) ;
2018-04-13 18:58:28 +02:00
alert _box ( 'unselect_other_tab ' + e . message ) ;
2015-09-27 00:35:53 +02:00
}
}
/ * *
* logout function call from ajax
* @ see ajax _disconnected
* @ returns { undefined }
* /
function logout ( )
{
var tmp _place = window . location . href
var tmp _b = tmp _place . split ( '/' )
var tmp _last = tmp _b . length - 1
var place _logout = tmp _place . replace ( tmp _b [ tmp _last ] , 'logout.php' ) ;
window . location . href = place _logout ;
}
/ * *
* Create a div which can be used in a anchor
* @ returns { undefined }
* /
function create _anchor _up ( )
{
2018-04-13 18:58:28 +02:00
if ( document . getElementById ( 'up_top' ) ) return ;
2015-09-27 00:35:53 +02:00
2018-04-13 18:58:28 +02:00
var newElt = document . createElement ( 'div' ) ;
2015-09-27 00:35:53 +02:00
newElt . setAttribute ( 'id' , 'up_top' ) ;
newElt . innerHTML = '<a id="up_top"></a>' ;
var parent = $ ( 'info_div' ) . parentNode ;
parent . insertBefore ( newElt , $ ( 'info_div' ) ) ;
}
/ * *
* Initialize the window to show the button "UP" if the window is scrolled
* vertically
* @ returns { undefined }
* /
function init _scroll ( )
{
var up = new Element ( 'div' , { "class" : "inner_box" ,
2018-04-13 18:58:28 +02:00
"style" : "padding:5px;left:auto;width:auto;height: auto;display:none;position:fixed;bottom:105px;right:50px;text-align:center;font-size:20px" ,
2015-09-27 00:35:53 +02:00
id : "go_up"
} ) ;
2018-04-13 18:58:28 +02:00
up . innerHTML = ' <a class="icon" href="#up_top" ></a><a href="javascript:show_calc()" class="icon"></a>' ;
2015-09-27 00:35:53 +02:00
document . body . appendChild ( up ) ;
window . onscroll = function ( ) {
if ( document . viewport . getScrollOffsets ( ) . top > 0 ) {
if ( $ ( 'go_up' ) . visible ( ) == false ) {
2018-04-13 18:58:28 +02:00
$ ( 'go_up' ) . setOpacity ( 0.65 ) ;
2015-09-27 00:35:53 +02:00
$ ( 'go_up' ) . show ( ) ;
2018-04-13 18:58:28 +02:00
$ ( 'go_up' ) . style . zIndex = 99 ;
2015-09-27 00:35:53 +02:00
}
} else {
$ ( 'go_up' ) . hide ( ) ;
}
}
}
/ * *
* Confirm a form thanks a modal dialog Box , it returns true if we agree otherwise
* false
* @ code
< form onsubmit = "return confirm_box(this,'message')" >
< / f o r m >
* @ endcode
* @ param p _obj form element ( object ) or element id ( string )
* @ param p _message message to display
* @ returns true or false
* /
function confirm _box ( p _obj , p _message , p _callback _true )
{
waiting _box ( ) ;
try {
// Find id of the end
var name = "" ;
if ( p _obj != null )
{
if ( typeof ( p _obj ) === "object" ) {
name = p _obj . id ;
} else {
name = p _obj ;
}
}
// execute the callback function or submit the form
if ( p _callback _true == undefined || p _callback _true == null )
{
smoke . confirm ( p _message , function ( e ) {
if ( e ) {
$ ( name ) . submit ( ) ;
}
} ) ;
} else {
smoke . confirm ( p _message , function ( e )
{
if ( e ) { p _callback _true . apply ( ) ; }
} ) ;
}
} catch ( e ) {
2018-04-13 18:58:28 +02:00
alert _box ( e . message ) ;
2015-09-27 00:35:53 +02:00
}
remove _waiting _box ( ) ;
return false ;
}
/ * *
* Alert box in CSS and HTML to replace the common javascript alert
* @ param p _message message to display
* @ returns void
* /
function alert _box ( p _message )
{
smoke . alert ( p _message , false , { ok : 'ok' , classname : "inner_box" } ) ;
}
2018-04-13 18:58:28 +02:00
2015-09-27 00:35:53 +02:00
/ * *
2018-04-13 18:58:28 +02:00
* @ brief Colorize the rows of the table
* @ param string p _table id of the table
* /
function alternate _row _color ( p _table )
{
var len = $ ( p _table ) . tBodies [ 0 ] . rows . length ;
var i = 0 ;
var localClass = "" ;
for ( i = 1 ; i < len ; i ++ ) {
localClass = ( i % 2 == 0 ) ? "even" : "odd" ;
if ( localClass == "even" && $ ( p _table ) . tBodies [ 0 ] . rows [ i ] . hasClassName ( "odd" ) )
{
$ ( p _table ) . tBodies [ 0 ] . rows [ i ] . removeClassName ( "odd" ) ;
}
if ( localClass == "even" && ! $ ( p _table ) . tBodies [ 0 ] . rows [ i ] . hasClassName ( "even" ) )
{
$ ( p _table ) . tBodies [ 0 ] . rows [ i ] . addClassName ( "even" ) ;
}
if ( localClass == "odd" && $ ( p _table ) . tBodies [ 0 ] . rows [ i ] . hasClassName ( "even" ) )
{
$ ( p _table ) . tBodies [ 0 ] . rows [ i ] . removeClassName ( "even" ) ;
}
if ( localClass == "odd" && ! $ ( p _table ) . tBodies [ 0 ] . rows [ i ] . hasClassName ( "odd" ) )
{
$ ( p _table ) . tBodies [ 0 ] . rows [ i ] . addClassName ( "odd" ) ;
}
}
}
/ * *
* Make an DOM element draggable or not
* @ param object _id DOM id
* /
function pin ( object _id ) {
if ( aDraggableElement [ object _id ] ) {
aDraggableElement [ object _id ] . destroy ( ) ;
aDraggableElement [ object _id ] = undefined ;
$ ( 'pin_' + object _id ) . innerHTML = "" ;
} else {
aDraggableElement [ object _id ] = new Draggable ( object _id , { starteffect : function ( )
{
new Effect . Highlight ( object _id , { scroll : window , queue : 'end' } ) ;
} }
) ;
$ ( 'pin_' + object _id ) . innerHTML = "" ;
}
}
/ * *
* Show only the rows into the table ( p _table _id ) with the attribute ( p _attribute _name ) and if this attribute
* has the value of ( attribut _value )
* @ param p _table _id table id
* @ param p _attribute _name the name of the attribute
* @ param p _attribute _value the value of the attribute we want to show
2015-09-27 00:35:53 +02:00
* /
2018-04-13 18:58:28 +02:00
function show _only _row ( p _table _id , p _attribute _name , p _attribute _value )
2015-09-27 00:35:53 +02:00
{
2018-04-13 18:58:28 +02:00
if ( ! $ ( p _table _id ) ) {
throw "Invalide table id"
}
var mTable = $ ( p _table _id ) ;
var ncount = mTable . rows . length
for ( var i = 0 ; i < ncount ; i ++ ) {
var mRow = mTable . rows [ i ] ;
if ( mRow . getAttribute ( p _attribute _name ) != undefined && mRow . getAttribute ( p _attribute _name ) != p _attribute _value ) {
mRow . hide ( ) ;
} else {
mRow . show ( ) ;
}
}
}
/ * *
* Show all the rows into the table ( p _table _id )
* @ param p _table _id table id
* /
function show _all _row ( p _table _id )
{
if ( ! $ ( p _table _id ) ) {
throw "Invalide table id"
}
var mTable = $ ( p _table _id ) ;
var ncount = mTable . rows . length
for ( var i = 0 ; i < ncount ; i ++ ) {
var mRow = mTable . rows [ i ] ;
mRow . show ( ) ;
}
}
/ * *
* @ class
* Periode handling
* Variables :
* - id of the row of the periode row _per _ ( p _periode _id ) , attribute exercice = per _exercice , periode _id = p _id
* - ( this . dialog )
* - id of the table with the rows : periode _tbl
*
* Members :
* - periode _id the concerned Periode , 0 none
* - p _ledger : the id of ledger ( jrn _def . jrn _def _id ) , 0 for global
* - pcallback : default ajax _misc . php ( this . callback ) with the parameter { op : 'periode' , gDossier , [ action : display , remove , save ] , p _id : p _periode _id }
* - dossier
* - js _obj _name : name of the js object ( this . js _obj _name )
* - ajax _test : file to include for debugging
* - dialog : id of the dialog box ( update / add ) periode _box
*
* /
var Periode = function ( p _ledger ) {
this . periode _id = 0 ;
this . p _ledger = p _ledger ;
this . dialog = 'periode_box' ;
this . pcallback = 'ajax_misc.php' ;
this . dossier = 0 ;
this . js _obj _name = "" ;
this . ajax _test = "" ;
this . set _callback = function ( p _phpfile ) { this . pcallback = p _phpfile ; } ;
this . set _dossier = function ( p _dosid ) { this . dossier = p _dosid ; } ;
/ * *
* set _js _obj _name ( p _js _obj _name )
* We need to know the javascript variable name , to pass it to ajax and
* create a HTML containing the right variable
* @ param p _js _obj _name name of the variable js we use on caller side
* /
this . set _js _obj _name = function ( p _js _obj _name ) { this . js _obj _name = p _js _obj _name ; } ;
/ * *
* Remove the periode , so call new Ajax and hide the row if successful
* otherwise show dialog box .
* @ parameter p _periode _id is the id of periode
* /
this . remove = function ( p _periode _id ) {
var js _param = { "gDossier" : this . dossier ,
"op" : "periode" ,
"act" : "remove" ,
"p_id" : p _periode _id ,
"ledger_id" : 0 ,
"js_var" : this . js _obj _name } ;
if ( this . ajax _test != "" ) {
js _param [ "TestAjaxFile" ] = this . ajax _test ;
}
here = this ;
smoke . confirm ( "Confirmer ?" , function ( e ) {
if ( e ) {
waiting _box ( ) ;
new Ajax . Request ( here . pcallback ,
{
method : "POST" ,
parameters : js _param ,
onSuccess : function ( req ) {
var answer = req . responseText . evalJSON ( ) ;
remove _waiting _box ( ) ;
if ( answer . status == "OK" )
{
$ ( "row_per_" + p _periode _id ) . remove ( ) ;
alternate _row _color ( "periode_tbl" ) ;
} else {
smoke . alert ( answer . content ) ;
}
}
} ) ;
}
} ) ;
} ;
/ * *
* display a dialog box to update a periode , call save either display
* an error box or update the row .
* the name of variable is requested
* to build the right button , javascript in the html of answer
* @ parameter p _periode _id is the id of periode
* /
this . box _display = function ( p _periode _id ) {
if ( this . js _obj _name == "" ) {
smoke . alert ( "ERROR BOX_ADD" )
}
var js _param = { "gDossier" : this . dossier ,
"op" : "periode" ,
"act" : "show" ,
"p_id" : p _periode _id ,
"ledger_id" : this . p _ledger ,
"js_var" : this . js _obj _name } ;
if ( this . ajax _test != "" ) {
js _param [ "TestAjaxFile" ] = this . ajax _test ;
}
var here = this ;
new Ajax . Request ( here . pcallback ,
{
method : "POST" ,
parameters : js _param ,
onSuccess : function ( req ) {
remove _waiting _box ( ) ;
var json = req . responseText . evalJSON ( ) ;
var y = calcy ( 100 ) ;
add _div ( { "id" : "mod_periode" , "style" : "position:fixed;top:" + y + "px;width:50%" , "cssclass" : "inner_box" , 'html' : "wait" } ) ;
$ ( 'mod_periode' ) . update ( json . content ) ;
}
} ) ;
} ;
/ * *
* close the periode , call ajax and receive a json object with the attribute
* status , content
* @ parameter p _periode _id is the id of periode
* /
this . close _periode = function ( p _periode _id ) {
if ( this . js _obj _name == "" ) {
smoke . alert ( "ERROR BOX_ADD" )
}
if ( this . ajax _test != "" ) {
js _param [ "TestAjaxFile" ] = this . ajax _test ;
}
var here = this ;
smoke . confirm ( "Confirmer ?" , function ( e ) {
if ( e ) {
here . _close ( p _periode _id ) ;
}
} ) ;
} ;
/ * *
* Internal function to close without confirming
* @ param { type } p _periode _id
* @ returns { undefined }
* /
this . _close = function ( p _periode _id ) {
if ( this . js _obj _name == "" ) {
smoke . alert ( "ERROR BOX_ADD" )
}
var js _param = { "gDossier" : this . dossier ,
"op" : "periode" ,
"act" : "close" ,
"ledger_id" : this . p _ledger ,
"p_id" : p _periode _id ,
"js_var" : this . js _obj _name
} ;
if ( this . ajax _test != "" ) {
js _param [ "TestAjaxFile" ] = this . ajax _test ;
}
var here = this ;
waiting _box ( ) ;
new Ajax . Request ( here . pcallback ,
{
method : "POST" ,
parameters : js _param ,
onSuccess : function ( req ) {
remove _waiting _box ( ) ;
var json = req . responseText . evalJSON ( ) ;
if ( json . status == 'OK' )
{
$ ( 'row_per_' + p _periode _id ) . update ( json . content ) ;
new Effect . Highlight ( 'row_per_' + p _periode _id , { startcolor : '#FAD4D4' , endcolor : '#F78082' } ) ;
} else {
smoke . alert ( json . content ) ;
}
}
} ) ;
} ;
/ * *
* reopen the periode
* @ parameter p _periode _id is the SQL id of parm _periode or the id of
* jrn _periode
* /
this . open _periode = function ( p _periode _id ) {
if ( this . js _obj _name == "" ) {
smoke . alert ( "ERROR BOX_ADD" )
}
var js _param = { "gDossier" : this . dossier ,
"op" : "periode" ,
"act" : "reopen" ,
"ledger_id" : this . p _ledger ,
"p_id" : p _periode _id ,
"js_var" : this . js _obj _name
} ;
if ( this . ajax _test != "" ) {
js _param [ "TestAjaxFile" ] = this . ajax _test ;
}
var here = this ;
smoke . confirm ( "Confirmer ?" , function ( e ) {
if ( e ) {
waiting _box ( ) ;
new Ajax . Request ( here . pcallback ,
{
method : "POST" ,
parameters : js _param ,
onSuccess : function ( req ) {
remove _waiting _box ( ) ;
var json = req . responseText . evalJSON ( ) ;
if ( json . status == 'OK' )
{
$ ( 'row_per_' + p _periode _id ) . update ( json . content ) ;
new Effect . Highlight ( 'row_per_' + p _periode _id , { startcolor : '#FAD4D4' , endcolor : '#F78082' } ) ;
} else {
smoke . alert ( json . content ) ;
}
}
} ) ;
}
} ) ;
} ;
/ * *
* This DOMID of the DIV containing the form is mod _periode
* @ param { type } p _frm
* @ returns { Boolean }
* /
this . save = function ( p _frm ) {
var js _param = $ ( p _frm ) . serialize ( true ) ;
waiting _box ( ) ;
js _param [ "js_var" ] = this . js _obj _name ;
js _param [ "act" ] = "save" ;
js _param [ "op" ] = "periode" ;
var here = this ;
new Ajax . Request ( this . pcallback , {
method : "POST" ,
parameters : js _param ,
onSuccess : function ( req ) {
var answer = req . responseText . evalJSON ( ) ;
remove _waiting _box ( ) ;
if ( answer . status == "OK" ) {
$ ( 'row_per_' + js _param [ 'periode_id' ] ) . update ( answer . content ) ;
removeDiv ( 'mod_periode' ) ;
new Effect . Highlight ( 'row_per_' + js _param [ 'periode_id' ] , { startcolor : '#FAD4D4' , endcolor : '#F78082' } ) ;
} else {
smoke . alert ( answer . content ) ;
}
}
} ) ;
return false ;
} ;
/ * *
* Thanks the object DOMID sel _per _closed [ ] the selected periodes are
* closed
* @ see Periode . _close
* /
this . close _selected = function ( ) {
var here = this ;
var a _selected = document . getElementsByName ( 'sel_per_close[]' ) ;
var count = 0 ;
var i = 0 ;
for ( i = 0 ; i < a _selected . length ; i ++ ) {
if ( a _selected [ i ] . checked == true ) {
// Close the selected periode
count ++ ;
}
}
if ( count == 0 ) {
smoke . signal ( "Sélectionner au moins une période" , function ( ) { } , { duration : 1500 } ) ;
return ;
}
smoke . confirm ( "Confirmer fermeture de " + count + " periode" , function ( e ) {
if ( e ) {
var a _selected = document . getElementsByName ( 'sel_per_close[]' ) ;
var i = 0 ;
for ( i = 0 ; i < a _selected . length ; i ++ ) {
if ( a _selected [ i ] . checked == true ) {
// Close the selected periode
here . _close ( a _selected [ i ] . value ) ;
}
}
}
}
) ;
} ;
/ * *
* @ brief Insert a periode into the list , always at the bottom !
* DomId :
* # FORM id : insert _periode _frm
* # DIV id = periode _add
* # table id = periode _tbl
* /
this . insert _periode = function ( ) {
var p _frm = 'insert_periode_frm' ;
var js _param = $ ( p _frm ) . serialize ( true ) ;
waiting _box ( ) ;
js _param [ "js_var" ] = this . js _obj _name ;
js _param [ "act" ] = "insert_periode" ;
js _param [ "op" ] = "periode" ;
js _param [ "p_id" ] = "-1" ;
js _param [ "ledger_id" ] = "0" ;
var here = this ;
new Ajax . Request ( this . pcallback , {
method : "POST" ,
parameters : js _param ,
onSuccess : function ( req ) {
var answer = req . responseText . evalJSON ( ) ;
remove _waiting _box ( ) ;
if ( answer . status == "OK" ) {
var new _row = document . createElement ( "tr" ) ;
$ ( 'periode_tbl' ) . append ( new _row ) ;
new _row . replace ( answer . content ) ;
// hide the form
$ ( 'periode_add' ) . hide ( ) ;
new Effect . Highlight ( 'row_per_' + answer . p _id , { startcolor : '#FAD4D4' , endcolor : '#F78082' } ) ;
alternate _row _color ( 'periode_tbl' ) ;
} else {
smoke . alert ( answer . content ) ;
}
}
} ) ;
return false ;
}
}
/ * *
* Show the periodes from the exercice contained into the id ( p _exercice _sel )
* @ param p _table _id DOM ID of the table
* /
Periode . filter _exercice = function ( p _table _id ) {
var rows = $ ( p _table _id ) . rows ;
var selected _value = $ ( 'p_exercice_sel' ) . value ;
for ( var i = 1 ; i < rows . length ; i ++ ) {
var exercice = rows [ i ] . getAttribute ( "per_exercice" ) ;
if ( selected _value == - 1 ) {
rows [ i ] . show ( ) ;
} else if ( selected _value == exercice ) {
rows [ i ] . show ( ) ;
} else {
rows [ i ] . hide ( ) ;
}
}
} ;
// keep track of progress bar
var progressBar = [ ] ;
// idx of progress bar
var progressIdx = 0 ;
/ * *
* Start the progress bar
* @ param { string } p _taskid id to monitor
* @ param { int } p _dossier
* /
function progress _bar _start ( p _taskid , p _message )
{
try {
progressIdx ++ ;
// block the window
var message = "Un instant svp" ;
if ( p _message ) {
message = p _message ;
}
add _div ( { id : "blocking" + progressIdx , cssclass : "smoke-base smoke-visible " } ) ;
add _div ( { id : "message" + progressIdx , cssclass : "inner_box" , style : "z-index:1000;position:fixed;top:30%;width:40%;left:30%" } ) ;
$ ( "message" + progressIdx ) . update ( message ) ;
// Create a div
add _div ( { id : "progressDiv" + progressIdx , cssclass : "progressbar" , html : '<span id="progressValue">0</span>' } ) ;
// Check status every sec.
progressBar [ progressIdx ] = setInterval ( progress _bar _check . bind ( null , progressIdx , p _taskid ) , 1000 ) ;
} catch ( e ) {
console . error ( e . message ) ;
}
}
/ * *
* Check every second the status
* @ param { integer } p _idx idx of progressbar
* @ param { string } p _taskid id to monitor
* /
function progress _bar _check ( p _idx , p _taskid )
{
try {
new Ajax . Request ( "ajax_misc.php" , {
parameters : { gDossier : 0 , task _id : p _taskid , op : "progressBar" } ,
method : "get" ,
onSuccess : function ( req ) {
try
{
var answer = req . responseText . evalJSON ( ) ;
var progress _div = $ ( "progressDiv" + progressIdx ) ;
var a _child = progress _div . childNodes ;
var i = 0 ;
for ( i = 0 ; i < a _child . length ; i ++ ) {
if ( a _child [ i ] . id = "progressValue" ) {
var progressValue = a _child [ i ] ;
}
}
var progress = parseFloat ( progressValue . innerHTML ) ;
if ( answer . value <= progress ) {
return ;
}
progressValue . innerHTML = answer . value ;
progressValue . setStyle ( "width:" + answer . value + "%" ) ;
if ( answer . value == 100 ) {
clearInterval ( progressBar [ p _idx ] ) ;
progressValue . innerHTML = "Success" ;
Effect . BlindUp ( "progressDiv" + p _idx , { duration : 1.0 , scaleContent : false } )
$ ( "message" + p _idx ) . remove ( ) ;
$ ( "blocking" + p _idx ) . remove ( ) ;
setTimeout ( function ( ) { $ ( "progressDiv" + progressIdx ) . remove } , 1100 ) ;
}
} catch ( e ) {
clearInterval ( progressBar [ p _idx ] ) ;
document . getElementById ( "progressValue" ) . innerHTML = req . responseText ;
console . error ( e . message ) ;
}
}
} ) ;
} catch ( e ) {
clearInterval ( progressBar [ p _idx ] ) ;
console . error ( e . message ) ;
}
}
/ * *
* In the user ' s setting box , update the period list with the choosen exercice
* @ param { int } p _dossier
* /
function updatePeriodePreference ( p _dossier )
{
waiting _box ( ) ;
var exercice = $ ( 'exercice_setting' ) . value ;
new Ajax . Updater ( 'setting_period' , "ajax_misc.php" , { method : "get" , parameters : { "op" : "pref_exercice" , "gDossier" : p _dossier , "exercice" : exercice } } ) ;
remove _waiting _box ( ) ;
}
/ * *
* Update the from and to periode list when changing the exercice
* @ param { int } p _dossier
* @ param { string } p _exercice id of the exercice
* @ param { type } p _periode _from id of the starting periode
* @ param { type } p _periode _to id of the ending periode
* @ param { type } p _last possible value = 1 to show last periode or 0 the first
* /
function updatePeriode ( p _dossier , p _exercice , p _periode _from , p _periode _to , p _last )
{
waiting _box ( ) ;
var exercice = $ ( p _exercice ) . value ;
new Ajax . Updater ( p _periode _from , "ajax_misc.php" , { method : "get" , parameters : { op : "periode_change" , "gDossier" : p _dossier , "exercice" : exercice , field : p _periode _from , "type" : "from" , "last" : p _last } } ) ;
new Ajax . Updater ( p _periode _to , "ajax_misc.php" , { method : "get" , parameters : { op : "periode_change" , "gDossier" : p _dossier , "exercice" : exercice , field : p _periode _to , "type" : "to" , "last" : p _last } } ) ;
remove _waiting _box ( ) ;
2015-09-27 00:35:53 +02:00
}