diff --git a/html/js/managetable.js b/html/js/managetable.js index 75299d968..deac84fad 100644 --- a/html/js/managetable.js +++ b/html/js/managetable.js @@ -64,11 +64,39 @@ - input */ +/** + @brief receive answer from ajax and fill up the + private object "answer" + @param req Ajax answer + */ +var parseXML = function (req) { + console.log(" start parsing"); + console.log(req.responseText); + try { + var xml = req.responseXML; + var status = getElementsByTagName("status"); + var ctl = xml.getElementsByTagName("ctl"); + var html = xml.getElementsByTagName("html"); + if (status.length == 0 || ctl.length == 0 || html.length == 0) + { + throw "Invalid answer " + req.responseText; + + } + answer['status'] = getNodeText(status[0]); + answer['ctl'] = getNodeText(ctl[0]); + answer['html'] = getNodeText(html[0]); + return answer; + } catch (e) { + console.log("erreur parsing"); + throw e; + } +}; /** * @class ManageTable * @param string p_table_name name of the table and schema */ + var ManageTable = function (p_table_name) { this.callback = "ajax.php"; //!< File to call @@ -107,26 +135,7 @@ var ManageTable = function (p_table_name) this.param = result; return this.param; }; - /** - @brief receive answer from ajax and fill up the - private object "answer" - @param req Ajax answer - */ - this.parseXML = function (req) { - var xml = req.responseXML; - var status = getElementsByTagName("status"); - var ctl = xml.getElementsByTagName("ctl"); - var html = xml.getElementsByTagName("html"); - if (status.length == 0 || ctl.length == 0 || html.length == 0) - { - throw "Invalid answer " + req.responseText; - } - answer['status'] = getNodeText(status[0]); - answer['ctl'] = getNodeText(ctl[0]); - answer['html'] = getNodeText(html[0]); - return answer; - }; /** *@brief call the ajax with the action save *@details update or append @@ -197,21 +206,28 @@ var ManageTable = function (p_table_name) this.param['action'] = 'input'; this.param['ctl_row'] = p_ctl_row; var control = this.control; - var parsexml=this.parseXML; // display the form to enter data new Ajax.Request(this.callback, { parameters: this.param, method: "get", onSuccess: function (req) { remove_waiting_box(); - var x=parsexml(req); - console.log("x"); - console.log(x); - var obj = {id:control, "cssclass": "inner_box", "html": loading()}; - add_div(obj); - var pos = calcy(250); - $(obj.id).setStyle({position:"absolute",top: pos + 'px',width:"auto","margin-left":"10%"}); - $(obj.id).update(req.responseText); + try { + console.log("parse xml"); + var x = parseXML(req); + console.log("x"); + console.log(x); + console.log("create div"); + var obj = {id: control, "cssclass": "inner_box", "html": loading()}; + add_div(obj); + var pos = calcy(250); + $(obj.id).setStyle({position: "absolute", top: pos + 'px', width: "auto", "margin-left": "10%"}); + console.log("set dgb content") + $(obj.id).update(req.responseText); + } catch (e) { + console.log(e.getMessage()); + smoke.alert("ERREUR " + e.getMessage()); + } } }); diff --git a/include/database/class_menu_ref_sql.php b/include/database/class_menu_ref_sql.php index 9bd6b19d2..35c00b05c 100644 --- a/include/database/class_menu_ref_sql.php +++ b/include/database/class_menu_ref_sql.php @@ -1,4 +1,5 @@ "me_code" - , "me_menu" => "me_menu" - , "me_file" => "me_file" - , "me_url" => "me_url" - , "me_description" => "me_description" - , "me_parameter" => "me_parameter" - , "me_javascript" => "me_javascript" - , "me_type" => "me_type" - , 'me_description_etendue'=>'me_description_etendue' - ); - protected $type=array( - "me_code" => "text" - , "me_menu" => "text" - , "me_file" => "text" - , "me_url" => "text" - , "me_description" => "text" - , "me_parameter" => "text" - , "me_javascript" => "text" - , "me_type" => "text" - ,"me_description_etendue"=>"text" - ); - function __construct(Database &$p_cn,$p_id=-1) + + function __construct(Database &$p_cn, $p_id=-1) { - parent::__construct($p_cn,$p_id); + $this->table="public.menu_ref"; + $this->primary_key="me_code"; + $this->name=array( + "me_code"=>"me_code" + , "me_menu"=>"me_menu" + , "me_file"=>"me_file" + , "me_url"=>"me_url" + , "me_description"=>"me_description" + , "me_parameter"=>"me_parameter" + , "me_javascript"=>"me_javascript" + , "me_type"=>"me_type" + , 'me_description_etendue'=>'me_description_etendue' + ); + $this->type=array( + "me_code"=>"text" + , "me_menu"=>"text" + , "me_file"=>"text" + , "me_url"=>"text" + , "me_description"=>"text" + , "me_parameter"=>"text" + , "me_javascript"=>"text" + , "me_type"=>"text" + , "me_description_etendue"=>"text" + ); + parent::__construct($p_cn, $p_id); } } + ?> diff --git a/include/lib/class_manage_table_sql.php b/include/lib/class_manage_table_sql.php index a71bdadd4..b46a10f7d 100644 --- a/include/lib/class_manage_table_sql.php +++ b/include/lib/class_manage_table_sql.php @@ -18,8 +18,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // Copyright Author Dany De Bontridder danydb@aevalys.eu -//@file -//@brief Definition Manage_Table_SQL +///@file +///@brief Definition Manage_Table_SQL /** * @brief Purpose is to propose a librairy to display a table content @@ -37,7 +37,7 @@ class Manage_Table_SQL private $object_name; //!< Object_name is used for the javascript private $row_delete; //!< Flag to indicate if rows can be deleted private $row_update; //!< Flag to indicate if rows can be updated - + private $json_parameter; //!< Default parameter to add (gDossier...) const UPDATABLE=1; const VISIBLE=2; @@ -61,8 +61,30 @@ class Manage_Table_SQL $this->object_name=uniqid("tbl"); $this->row_delete=TRUE; $this->row_update=TRUE; + $this->callback="ajax.php"; + $this->json=json_encode(array("gDossier"=>Dossier::id(), + "op"=>"managetable")); + } + + /** + * Get the object name + * @details : return the object name , it is useful it + * the javascript will return coded without the create_js_script function + * @see create_js_script + */ + function get_js_variable () { + return $this->object_name; + } + /** + * Set the parameter of the object (gDossier, ac, plugin_code...) + * @detail By default , only gDossier will be set . The default value + * is given in the constructor + * @param string with json format $p_json + * + */ + function param_set($p_json) { + $this->json=$p_json; } - /** * @brief set the callback function that is passed to javascript * @param $p_file : callback file by default ajax.php @@ -77,11 +99,12 @@ class Manage_Table_SQL * row. It is the default script . */ function create_js_script() - { + { echo " "; @@ -97,7 +120,7 @@ class Manage_Table_SQL if (!$this->a_prop[$p_key]) throw new Exception(__FILE__.":".__LINE__."$p_key invalid index"); if ($p_value==False) - $this->a_prop[$p_key]=$this->a_prop[$p_key]-self::UPDATABLE; + $this->a_prop[$p_key]=$this->a_prop[$p_key] - self::UPDATABLE; elseif ($p_value==True) $this->a_prop[$p_key]=$this->a_prop[$p_key]|self::UPDATABLE; else @@ -149,7 +172,8 @@ class Manage_Table_SQL */ function get_property_updatable($p_key) { - if ( $this->a_prop[$p_key] & self::UPDATABLE == 1) return true; + $val= $this->a_prop[$p_key] & self::UPDATABLE ; + if ( $val == self::UPDATABLE) return true; return false; } @@ -163,7 +187,7 @@ class Manage_Table_SQL if (!$this->a_prop[$p_key]) throw new Exception(__FILE__.":".__LINE__."$p_key invalid index"); if ($p_value==False) - $this->a_prop[$p_key]=$this->a_prop[$p_key]-self::VISIBLE; + $this->a_prop[$p_key]=$this->a_prop[$p_key] -self::VISIBLE; elseif ($p_value==True) $this->a_prop[$p_key]=$this->a_prop[$p_key]|self::VISIBLE; else @@ -176,7 +200,8 @@ class Manage_Table_SQL */ function get_property_visible($p_key) { - if ( $this->a_prop[$p_key] & self::VISIBLE == 1) return true; + $val = $this->a_prop[$p_key] & self::VISIBLE ; + if ( $val === self::VISIBLE) return true; return false; } @@ -262,8 +287,8 @@ class Manage_Table_SQL function display_table() { $ret=$this->table->seek(); - $nb=Database::num_count($ret); - printf('', $this->object_name); + $nb=Database::num_row($ret); + printf('
', $this->object_name); for ($i=0; $i<$nb; $i++) { if ($i==0) @@ -288,7 +313,8 @@ class Manage_Table_SQL { $key=$this->a_order[$i]; - if ($this->get_property_visible($key)) + + if ($this->get_property_visible($key)==true) echo th($this->a_label_displaid[$key]); } echo ""; @@ -331,24 +357,26 @@ class Manage_Table_SQL $nb_order=count($this->a_order); for ($i=0; $i<$nb_order; $i++) { - $v=$this->a_order($i); + $v=$this->a_order[$i]; if ($this->get_property_visible($v)) echo td($p_row[$v]); } echo ""; echo ""; echo ''; diff --git a/scenario/test_manage_table_sql.php b/scenario/test_manage_table_sql.php new file mode 100644 index 000000000..ec7601fdd --- /dev/null +++ b/scenario/test_manage_table_sql.php @@ -0,0 +1,87 @@ + + ini_set('disable_functions', 'exit,die,header'); + //@description:Test the class manage_table_sql and javascript + + $_GET=array ( + 'gDossier' => '10079', +); +$_POST=array ( +); +$_POST['gDossier']=$gDossierLogInput; +$_GET['gDossier']=$gDossierLogInput; +$_REQUEST=array_merge($_GET,$_POST); +require_once NOALYSS_INCLUDE."/database/class_menu_ref_sql.php"; +require_once NOALYSS_INCLUDE."/lib/class_manage_table_sql.php"; + +$jrn=new Menu_Ref_SQL($cn); + +$manage_table=new Manage_Table_SQL($jrn); +$manage_table->set_callback("ajax_misc.php"); +$manage_table->create_js_script(); +?> + +set_col_label('me_code', "Code"); +$manage_table->set_col_label('me_menu', "Menu"); +$manage_table->set_col_label('me_file', "Fichier"); +$manage_table->set_col_label('me_description', "Description"); +$manage_table->set_col_label('me_description_etendue', "Detail"); + +// Change visible property +$manage_table->set_property_visible("me_javascript", false); +$manage_table->set_property_visible("me_url", false); + + + + +// Change update property +$manage_table->set_property_updatable("me_type", false); +$manage_table->set_property_updatable("me_parameter", false); + +// Check + +echo "me_javascript Visible (false)" .$manage_table->get_property_visible("me_javascript"); +if ( ! $manage_table->get_property_visible("me_javascript")) echo "OK"; else echo "FAIL";echo "
"; +echo "me_javascript updatable (true)" .$manage_table->get_property_updatable("me_javascript"); +if ( $manage_table->get_property_updatable("me_javascript")) echo "OK"; else echo "FAIL";echo "
"; +echo "me_url Visible (false)" .$manage_table->get_property_visible("me_url"); +if ( ! $manage_table->get_property_visible("me_url")) echo "OK"; else echo "FAIL";echo "
"; +echo "me_url updatable (true)" .$manage_table->get_property_updatable("me_url"); +if ( $manage_table->get_property_updatable("me_url")) echo "OK"; else echo "FAIL";echo "
"; + +echo "me_type Visible (true)" ; +if ( $manage_table->get_property_visible("me_type")) echo "OK"; else echo "FAIL";echo "
"; +echo "me_type updatable (false)" ; +if ( ! $manage_table->get_property_updatable("me_type")) echo "OK"; else echo "FAIL";echo "
"; + +echo "me_parameter Visible (true)" ; +if ( $manage_table->get_property_visible("me_parameter")) echo "OK"; else echo "FAIL";echo "
"; +echo "me_parameter updatable (false)" ; +if ( ! $manage_table->get_property_updatable("me_parameter")) echo "OK"; else echo "FAIL";echo "
"; + +$manage_table->display_table(); + + ?>
"; if ($this->can_update_row()) { - $js=printf("ManageTable.input('%s','%s');", - $p_row[$this->table->primary_key], $this->object_name + $js=sprintf("onclick=\"%s.input('%s','%s');\"", + $this->object_name,$p_row[$this->table->primary_key],$this->object_name ); + echo HtmlInput::anchor(_("Modifier"), "", $js); } echo ""; if ($this->can_delete_row()) { - $js=printf("ManageTable.delete('%s','%s');", - $p_row[$this->table->primary_key], $this->object_name + $js=sprintf("onclick=\"%s.delete('%s','%s');\"", + $this->object_name,$p_row[$this->table->primary_key], $this->object_name ); + echo HtmlInput::anchor(_("Effacer"), "", $js); } echo "