Fix: add generic edit in place select input
This commit is contained in:
parent
eeedf86067
commit
419eb248c1
@ -345,7 +345,7 @@ else if ($id)
|
||||
|
||||
// Type
|
||||
print '<tr><td>'.$langs->trans("Type").'</td><td>';
|
||||
print $form->editInPlace($langs->trans($object->type), 'type', $user->rights->deplacement->creer, 'select');
|
||||
print $form->editInPlace($langs->trans($object->type), 'type', $user->rights->deplacement->creer, 'select', 'types_fees');
|
||||
//print $langs->trans($object->type);
|
||||
print '</td></tr>';
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
|
||||
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
|
||||
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
|
||||
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
|
||||
//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
|
||||
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
|
||||
if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
|
||||
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
|
||||
@ -56,7 +56,12 @@ if((isset($_GET['field']) && ! empty($_GET['field']))
|
||||
{
|
||||
if ($type == 'select')
|
||||
{
|
||||
echo json_encode(array("Aberdeen", "Ada", "Adamsville", "Addyston", "Adelphi", "Adena", "Adrian", "Akron"));
|
||||
$methodname = 'load_cache_'.GETPOST('method');
|
||||
$cachename = 'cache_'.GETPOST('method');
|
||||
|
||||
$form = new Form($db);
|
||||
$ret = $form->$methodname();
|
||||
if ($ret > 0) echo json_encode($form->$cachename);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
|
||||
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
|
||||
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
|
||||
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
|
||||
//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
|
||||
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
|
||||
if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
|
||||
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
|
||||
@ -51,7 +51,6 @@ if((isset($_POST['field']) && ! empty($_POST['field']))
|
||||
$fk_element = GETPOST('fk_element');
|
||||
$value = GETPOST('value');
|
||||
$type = GETPOST('type');
|
||||
$timestamp = GETPOST('timestamp');
|
||||
|
||||
$format='text';
|
||||
$return=array();
|
||||
@ -65,6 +64,7 @@ if((isset($_POST['field']) && ! empty($_POST['field']))
|
||||
|
||||
// Clean parameters
|
||||
$newvalue = trim($value);
|
||||
|
||||
if ($type == 'numeric')
|
||||
{
|
||||
$newvalue = price2num($newvalue);
|
||||
@ -78,8 +78,22 @@ if((isset($_POST['field']) && ! empty($_POST['field']))
|
||||
}
|
||||
else if ($type == 'datepicker')
|
||||
{
|
||||
$format = 'date';
|
||||
$newvalue = ($timestamp / 1000);
|
||||
$timestamp = GETPOST('timestamp');
|
||||
$format = 'date';
|
||||
$newvalue = ($timestamp / 1000);
|
||||
}
|
||||
else if ($type == 'select')
|
||||
{
|
||||
$methodname = 'load_cache_'.GETPOST('method');
|
||||
$cachename = 'cache_'.GETPOST('method');
|
||||
|
||||
$form = new Form($db);
|
||||
$ret = $form->$methodname();
|
||||
if ($ret > 0)
|
||||
{
|
||||
$cache = $form->$cachename;
|
||||
$value = $cache[$newvalue];
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
|
||||
@ -150,9 +150,10 @@ class Form
|
||||
* @param string $htmlname DIV ID (field name)
|
||||
* @param int $condition Condition to edit
|
||||
* @param string $area Type of edit
|
||||
* @param string $loadmethod Name of load method
|
||||
* @return string HTML edit in place
|
||||
*/
|
||||
function editInPlace($value, $htmlname, $condition, $type='textarea')
|
||||
function editInPlace($value, $htmlname, $condition, $type='textarea', $loadmethod='')
|
||||
{
|
||||
global $conf;
|
||||
|
||||
@ -167,6 +168,7 @@ class Form
|
||||
{
|
||||
// Use for timestamp format
|
||||
if ($type == 'datepicker') $out.= '<input id="timeStamp" type="hidden"/>';
|
||||
else if ($type == 'select' && ! empty($loadmethod)) $out.= '<input id="loadmethod" value="'.$loadmethod.'" type="hidden"/>';
|
||||
|
||||
$out.= '<div class="edit_'.$type.'" id="'.$htmlname.'">';
|
||||
$out.= $value;
|
||||
|
||||
@ -138,12 +138,14 @@ $(document).ready(function() {
|
||||
loadurl : urlLoadInPlace,
|
||||
loaddata : {
|
||||
type: 'select',
|
||||
method: $('#loadmethod').val(),
|
||||
element: element,
|
||||
table_element: table_element,
|
||||
fk_element: fk_element
|
||||
},
|
||||
submitdata : {
|
||||
type: 'select',
|
||||
method: $('#loadmethod').val(),
|
||||
element: element,
|
||||
table_element: table_element,
|
||||
fk_element: fk_element
|
||||
|
||||
Loading…
Reference in New Issue
Block a user