Fix navigation on card generated by modulebuilder

This commit is contained in:
Laurent Destailleur 2017-07-25 10:38:39 +02:00
parent 80da181802
commit dcf5fd20bb
4 changed files with 43 additions and 23 deletions

View File

@ -30,7 +30,7 @@
if (($id > 0 || (! empty($ref) && ! in_array($action, array('create','createtask')))) && empty($cancel)) if (($id > 0 || (! empty($ref) && ! in_array($action, array('create','createtask')))) && empty($cancel))
{ {
$ret = $object->fetch($id,$ref); $ret = $object->fetch($id, $ref);
if ($ret > 0) if ($ret > 0)
{ {
$object->fetch_thirdparty(); $object->fetch_thirdparty();

View File

@ -4905,7 +4905,7 @@ abstract class CommonObject
* *
* @param stdClass $obj Contain data of object from database * @param stdClass $obj Contain data of object from database
*/ */
private function set_vars_by_db(&$obj) private function setVarsFromFetchObj(&$obj)
{ {
foreach ($this->fields as $field => $info) foreach ($this->fields as $field => $info)
{ {
@ -4922,7 +4922,8 @@ abstract class CommonObject
} }
elseif($this->isInt($info)) elseif($this->isInt($info))
{ {
$this->{$field} = (int) $obj->{$field}; if ($field == 'rowid') $this->id = (int) $obj->{$field};
else $this->{$field} = (int) $obj->{$field};
} }
elseif($this->isFloat($info)) elseif($this->isFloat($info))
{ {
@ -4982,6 +4983,7 @@ abstract class CommonObject
$fieldvalues = $this->set_save_query(); $fieldvalues = $this->set_save_query();
if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now); if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now);
if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat']=$user->id;
unset($fieldvalues['rowid']); // We suppose the field rowid is reserved field for autoincrement field. unset($fieldvalues['rowid']); // We suppose the field rowid is reserved field for autoincrement field.
$keys=array(); $keys=array();
@ -5048,8 +5050,10 @@ abstract class CommonObject
// Load source object // Load source object
$object->fetchCommon($fromid); $object->fetchCommon($fromid);
// Reset object // Reset some properties
$object->id = 0; unset($object->id);
unset($object->fk_user_creat);
unset($object->import_key);
// Clear fields // Clear fields
$object->ref = "copy_of_".$object->ref; $object->ref = "copy_of_".$object->ref;
@ -5088,7 +5092,7 @@ abstract class CommonObject
{ {
if (empty($id) && empty($ref)) return false; if (empty($id) && empty($ref)) return false;
$sql = 'SELECT '.$this->get_field_list().', date_creation, tms'; $sql = 'SELECT '.$this->get_field_list();
$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element;
if(!empty($id)) $sql.= ' WHERE rowid = '.$id; if(!empty($id)) $sql.= ' WHERE rowid = '.$id;
@ -5101,12 +5105,7 @@ abstract class CommonObject
{ {
if ($obj) if ($obj)
{ {
$this->id = $id; $this->setVarsFromFetchObj($obj);
$this->set_vars_by_db($obj);
$this->date_creation = $this->db->idate($obj->date_creation);
$this->tms = $this->db->idate($obj->tms);
return $this->id; return $this->id;
} }
else else

View File

@ -55,7 +55,7 @@ class MyObject extends CommonObject
/** /**
* @var string String with name of icon for myobject * @var string String with name of icon for myobject
*/ */
public $picto = 'myobject'; public $picto = 'myobject@mymodule';
/** /**

View File

@ -61,6 +61,7 @@ $langs->loadLangs(array("mymodule","other"));
// Get parameters // Get parameters
$id = GETPOST('id', 'int'); $id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'alpha'); $action = GETPOST('action', 'alpha');
$cancel = GETPOST('cancel', 'aZ09'); $cancel = GETPOST('cancel', 'aZ09');
$backtopage = GETPOST('backtopage', 'alpha'); $backtopage = GETPOST('backtopage', 'alpha');
@ -130,7 +131,7 @@ if (empty($reshook))
{ {
foreach ($object->fields as $key => $val) foreach ($object->fields as $key => $val)
{ {
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'import_key'))) continue; // Ignore special fields if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; // Ignore special fields
$object->$key=GETPOST($key,'alpha'); $object->$key=GETPOST($key,'alpha');
if ($val['notnull'] && $object->$key == '') if ($val['notnull'] && $object->$key == '')
@ -170,7 +171,7 @@ if (empty($reshook))
foreach ($object->fields as $key => $val) foreach ($object->fields as $key => $val)
{ {
$object->$key=GETPOST($key,'alpha'); $object->$key=GETPOST($key,'alpha');
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'import_key'))) continue; if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue;
if ($val['notnull'] && $object->$key == '') if ($val['notnull'] && $object->$key == '')
{ {
$error++; $error++;
@ -263,12 +264,14 @@ if ($action == 'create')
print '<table class="border centpercent">'."\n"; print '<table class="border centpercent">'."\n";
foreach($object->fields as $key => $val) foreach($object->fields as $key => $val)
{ {
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'import_key'))) continue; if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue;
print '<tr><td'; print '<tr id="field_'.$key.'"><td';
print ' class="titlefieldcreate'; print ' class="titlefieldcreate';
if ($val['notnull']) print ' fieldrequired'; if ($val['notnull']) print ' fieldrequired';
print '"'; print '"';
print '>'.$langs->trans($val['label']).'</td><td><input class="flat" type="text" name="'.$key.'" value="'.(GETPOST($key,'alpha')?GETPOST($key,'alpha'):'').'"></td></tr>'; print '>'.$langs->trans($val['label']).'</td>';
print '<td><input class="flat" type="text" name="'.$key.'" value="'.(GETPOST($key,'alpha')?GETPOST($key,'alpha'):'').'"></td>';
print '</tr>';
} }
print '</table>'."\n"; print '</table>'."\n";
@ -294,8 +297,17 @@ if (($id || $ref) && $action == 'edit')
dol_fiche_head(); dol_fiche_head();
print '<table class="border centpercent">'."\n"; print '<table class="border centpercent">'."\n";
// print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input class="flat" type="text" size="36" name="label" value="'.$label.'"></td></tr>'; foreach($object->fields as $key => $val)
// LIST_OF_TD_LABEL_FIELDS_EDIT {
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue;
print '<tr><td';
print ' class="titlefieldcreate';
if ($val['notnull']) print ' fieldrequired';
print '"';
print '>'.$langs->trans($val['label']).'</td>';
print '<td><input class="flat" type="text" name="'.$key.'" value="'.(GETPOST($key,'alpha')?GETPOST($key,'alpha'):'').'"></td>';
print '</tr>';
}
print '</table>'; print '</table>';
dol_fiche_end(); dol_fiche_end();
@ -405,9 +417,18 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '<div class="fichehalfleft">'; print '<div class="fichehalfleft">';
print '<div class="underbanner clearboth"></div>'; print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent">'."\n"; print '<table class="border centpercent">'."\n";
// print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
// LIST_OF_TD_LABEL_FIELDS_VIEW
foreach($object->fields as $key => $val)
{
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue;
print '<tr><td';
print ' class="titlefieldcreate';
if ($val['notnull']) print ' fieldrequired';
print '"';
print '>'.$langs->trans($val['label']).'</td>';
print '<td><input class="flat" type="text" name="'.$key.'" value="'.(GETPOST($key,'alpha')?GETPOST($key,'alpha'):'').'"></td>';
print '</tr>';
}
// Other attributes // Other attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
@ -419,7 +440,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '<div class="underbanner clearboth"></div>'; print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent">'; print '<table class="border centpercent">';
// ...
print '</table>'; print '</table>';
print '</div>'; print '</div>';