From 389002d27501ddfcfe37c55aa64666240a2110e7 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sun, 4 Jul 2010 10:37:51 +0000 Subject: [PATCH] Remove / modify / add attribut for the cat. --- html/ajax_card.php | 21 +++++++++++++++++++++ html/js/card.js | 26 ++++++++++++++++++++++++-- include/card_attr.inc.php | 21 +++++++++++++++++---- include/function_javascript.php | 11 +++++++++++ 4 files changed, 73 insertions(+), 6 deletions(-) diff --git a/html/ajax_card.php b/html/ajax_card.php index c7b4bd10e..dc919297d 100644 --- a/html/ajax_card.php +++ b/html/ajax_card.php @@ -58,6 +58,7 @@ require_once('class_iradio.php'); require_once('function_javascript.php'); require_once('ac_common.php'); require_once ('class_user.php'); +require_once ('class_fiche_attr.php'); $var=array('gDossier','op','ctl'); $cont=0; @@ -76,6 +77,26 @@ $cn=new Database($gDossier); $user=new User($cn); $user->check(true);$user->check_dossier($gDossier,true); $html=var_export($_REQUEST,true); switch($op) { + /* ------------------------------------------------------------ */ + /* Remove a attribut */ + /* ------------------------------------------------------------ */ +case 'rmfa': + ob_start(); + if( ! isset($_GET['ad_id']) || isNumber($_GET['ad_id']) ==0) + throw new Exception ( "Parametre ad_id est invalide",11); + $ad_id= $_GET['ad_id']; + try { + $cn->start(); + $fa=new Fiche_Attr($cn,$ad_id); + $fa->delete(); + $cn->commit(); + } catch (Exception $e) { + $cn->rollback(); + echo $e->getMessage(); + } + $html=ob_get_contents(); + ob_clean(); + break; /* ------------------------------------------------------------ */ /* Display card detail */ /* ------------------------------------------------------------ */ diff --git a/html/js/card.js b/html/js/card.js index 0fef470f1..b0252ad96 100644 --- a/html/js/card.js +++ b/html/js/card.js @@ -401,6 +401,28 @@ function save_card_category(obj) { ); } /** - *@brief Display a form to modify a category - * + *@brief Remove a definition of an attribut + *@param attr_def.ad_id + *@param gDossier + *@param table_id to rm the row + *@param special this pointer of the row */ + +function removeCardAttribut(ad_id,gDossier,table_id,row) { + var queryString='?gDossier='+gDossier; + queryString+='&op=rmfa'; + queryString+='&ctl=debug'; // debug id + queryString+='&ad_id='+ad_id; + var action=new Ajax.Request ( 'ajax_card.php', + { + method:'get', + parameters:queryString, + onFailure:null, + onSuccess:null + } + ); + deleteRowRec(table_id,row); + + +} + diff --git a/include/card_attr.inc.php b/include/card_attr.inc.php index 87124d012..28e364d54 100644 --- a/include/card_attr.inc.php +++ b/include/card_attr.inc.php @@ -24,8 +24,11 @@ * \brief Manage the attributs */ require_once('class_fiche_attr.php'); -$fa=new Fiche_Attr($cn); +echo js_include('card.js'); + +$fa=new Fiche_Attr($cn); +// echo '
'; ///////////////////////////////////////////////////////////////////////////// // If data are post we save them first ///////////////////////////////////////////////////////////////////////////// @@ -49,7 +52,7 @@ if ( isset($_POST['save'])) { { $e->getMessage();$cn->rollback();} } /* show list of existing */ - +$gDossier=dossier::id(); $array=$fa->seek(); $select_type=new ISelect('type[]'); @@ -61,12 +64,14 @@ $select_type->value=array( array('value'=>'numeric','label'=>'Nombre'), array('value'=>'date','label'=>'Date') ); +$remove=new IButton('rmfa'); +$remove->label='Effacer'; echo '
'; echo '
'; echo HtmlInput::hidden('sa','fat'); echo HtmlInput::hidden('p_action','divers'); -echo ''; +echo '
'; for ($e=0;$ereadOnly=false; $desc->readOnly=false; $r.=td($desc->input()); + $r.=td($select_type->input()); + + $remove->javascript=sprintf('if ( confirm(\'Vous confirmez ?\')) { removeCardAttribut(%d,%d,\'tb_rmfa\',this);}', + $row->get_parameter('id'),$gDossier); + $msg=' Attention : effacera les données qui y sont liées '; + $r.=td($remove->input().$msg); } else { $select_type->readOnly=true; $desc->readOnly=true; $r.=td($desc->input().HtmlInput::hidden('type[]','')); + $r.=td($select_type->input()); + $r.=td(""); } - $r.=td($select_type->input()); + echo tr($r); diff --git a/include/function_javascript.php b/include/function_javascript.php index 491dd0a3b..def0b2907 100644 --- a/include/function_javascript.php +++ b/include/function_javascript.php @@ -10,8 +10,19 @@ License: GPL *\return the HTML script */ function js_include($p_string) { + static $ajs=array(); /* avoid to add twice the same script */ + static $seq=0; + if ( in_array($p_string,$ajs)) return ''; + $ajs[$seq]=$p_string; + $seq++; + + if ( ! file_exists('js/'.$p_string)) + alert("Erreur js/$p_string n existe pas"); $script=''; + // debug + echo "insert js $p_string "; return $script; + } /*! *\brief create the HTML for adding the script tags around of the script