From ff59631e110fc232d097b49b48cddc0ee7ef8e6e Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 7 Feb 2012 16:51:38 +0100 Subject: [PATCH] Fix: works on edit in place with external modules --- htdocs/core/ajax/saveinplace.php | 10 ++++++- htdocs/core/class/commonobject.class.php | 34 ++++++++++++++++++++---- htdocs/core/js/editinplace.js | 2 +- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/htdocs/core/ajax/saveinplace.php b/htdocs/core/ajax/saveinplace.php index e1462e6dd1a..0c1434a4fd8 100644 --- a/htdocs/core/ajax/saveinplace.php +++ b/htdocs/core/ajax/saveinplace.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2011-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -134,6 +134,14 @@ if((isset($_POST['field']) && ! empty($_POST['field'])) if (! $error) { if (! is_object($object)) $object = new GenericObject($db); + + // Specific for add_object_linked() + // TODO add a function for variable treatment + $object->ext_fk_element = $newvalue; + $object->ext_element = $ext_element; + $object->fk_element = $fk_element; + $object->element = $element; + $ret=$object->$savemethodname($field, $newvalue, $table_element, $fk_element, $format); if ($ret > 0) { diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 2f37bd11cca..0182bea4b94 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1654,6 +1654,30 @@ abstract class CommonObject } } + /** + * Delete all links between an object $this + * + * @return int >0 if OK, <0 if KO + */ + function deleteObjectLinked() + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; + $sql.= " WHERE fk_target = ".$this->id; + $sql.= " AND targettype = '".$this->element."'"; + + dol_syslog(get_class($this)."::deleteObjectLinked sql=".$sql, LOG_DEBUG); + if ($this->db->query($sql)) + { + return 1; + } + else + { + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this)."::deleteObjectLinked error=".$this->error, LOG_ERR); + return -1; + } + } + /** * Set statut of an object * @@ -2069,19 +2093,19 @@ abstract class CommonObject if ($objecttype == 'facture') { $tplpath = 'compta/'.$element; } - if ($objecttype == 'propal') { + else if ($objecttype == 'propal') { $tplpath = 'comm/'.$element; } - if ($objecttype == 'shipping') { + else if ($objecttype == 'shipping') { $tplpath = 'expedition'; } - if ($objecttype == 'delivery') { + else if ($objecttype == 'delivery') { $tplpath = 'livraison'; } - if ($objecttype == 'invoice_supplier') { + else if ($objecttype == 'invoice_supplier') { $tplpath = 'fourn/facture'; } - if ($objecttype == 'order_supplier') { + else if ($objecttype == 'order_supplier') { $tplpath = 'fourn/commande'; } diff --git a/htdocs/core/js/editinplace.js b/htdocs/core/js/editinplace.js index 8f91696a4cf..ca3d3bacab8 100644 --- a/htdocs/core/js/editinplace.js +++ b/htdocs/core/js/editinplace.js @@ -236,7 +236,7 @@ $(document).ready(function() { }, callback : function(result, settings) { var obj = $.parseJSON(result); - + if (obj.error) { $(this).html(this.revert); $.jnotify(obj.error, "error", true);