CMCARD : template of card, drag'n drop to order the attributes
This commit is contained in:
parent
a596b020c4
commit
b1896b410f
6 changed files with 90 additions and 27 deletions
|
|
@ -266,11 +266,17 @@ category_card.add_attribut=function (p_dossier,p_fiche_def_ref,p_object_name) {
|
||||||
onSuccess:function(req) {
|
onSuccess:function(req) {
|
||||||
var answer=req.responseText.evalJSON();
|
var answer=req.responseText.evalJSON();
|
||||||
if ( answer.status == 'OK') {
|
if ( answer.status == 'OK') {
|
||||||
var newli=document.createElement("li")
|
var newli = document.createElement("li")
|
||||||
newli.setAttribute("id",p_object_name+"_elt"+selected_attr);
|
|
||||||
newli.innerHTML=answer.content
|
$(p_object_name + "_list").append(newli);
|
||||||
$(p_object_name+"_list").append(newli);
|
newli.replace(answer.content);
|
||||||
|
document.getElementById('attribut_order').value = Sortable.serialize(p_object_name + "_list");
|
||||||
select.remove(select.selectedIndex);
|
select.remove(select.selectedIndex);
|
||||||
|
Sortable.create(p_object_name + '_list', {
|
||||||
|
onUpdate: function () {
|
||||||
|
document.getElementById('attribut_order').value = Sortable.serialize(p_object_name + "_list")
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
smoke.alert(answer.message);
|
smoke.alert(answer.message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,9 +68,13 @@ switch ($action)
|
||||||
$answer['message']="";
|
$answer['message']="";
|
||||||
$js=sprintf("category_card.remove_attribut('%s','%s','%s',%d)",
|
$js=sprintf("category_card.remove_attribut('%s','%s','%s',%d)",
|
||||||
Dossier::id(), $frd_id, $objname, $ad_id);
|
Dossier::id(), $frd_id, $objname, $ad_id);
|
||||||
$answer['content']=$cn->get_value("select ad_text from attr_def where ad_id=$1",
|
$label=$cn->get_value("select ad_text from attr_def where ad_id=$1",
|
||||||
[$ad_id]).
|
[$ad_id]);
|
||||||
Icon_Action::trash(uniqid(), $js);
|
$content=sprintf('<li id="%s_elt%d" style="cursor:move;border:1px solid navy;padding : 0.5rem 0.2rem 0.5rem 0.2rem;margin-top:2px">%s', $objname
|
||||||
|
,$ad_id,$label);
|
||||||
|
$content.=Icon_Action::trash(uniqid(), $js);
|
||||||
|
$content.='</li>';
|
||||||
|
$answer['content']=$content;
|
||||||
}
|
}
|
||||||
catch (Exception $exc)
|
catch (Exception $exc)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,9 @@ if ( $action == 'remove_cat' )
|
||||||
'Les fiches non utilisées ont cependant été effacées'));
|
'Les fiches non utilisées ont cependant été effacées'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$fiche_def=new Fiche_def($cn);
|
||||||
|
$fiche_def->display();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
/*******************************************************************************************/
|
/*******************************************************************************************/
|
||||||
// Change some basis info
|
// Change some basis info
|
||||||
|
|
|
||||||
|
|
@ -253,7 +253,7 @@ $order
|
||||||
$p_create='true';
|
$p_create='true';
|
||||||
else
|
else
|
||||||
$p_create='false';
|
$p_create='false';
|
||||||
|
$add_accounting=false;
|
||||||
// Class is valid ?
|
// Class is valid ?
|
||||||
if ( sql_string($p_class_base) != null || ( $p_class_base !='' && strpos(',',$p_class_base) != 0 ))
|
if ( sql_string($p_class_base) != null || ( $p_class_base !='' && strpos(',',$p_class_base) != 0 ))
|
||||||
{
|
{
|
||||||
|
|
@ -272,10 +272,11 @@ $order
|
||||||
// Get the fd_id
|
// Get the fd_id
|
||||||
$fd_id=$this->cn->get_current_seq('s_fdef');
|
$fd_id=$this->cn->get_current_seq('s_fdef');
|
||||||
|
|
||||||
// update jnt_fic_attr
|
// // update jnt_fic_attr
|
||||||
$sql=sprintf("insert into jnt_fic_attr(fd_id,ad_id,jnt_order)
|
// $sql=sprintf("insert into jnt_fic_attr(fd_id,ad_id,jnt_order)
|
||||||
values (%d,%d,10)",$fd_id,ATTR_DEF_ACCOUNT);
|
// values (%d,%d,10)",$fd_id,ATTR_DEF_ACCOUNT);
|
||||||
$Res=$this->cn->exec_sql($sql);
|
// $Res=$this->cn->exec_sql($sql);
|
||||||
|
$add_accounting=true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -295,24 +296,39 @@ $order
|
||||||
|
|
||||||
//if defaut attr not null
|
//if defaut attr not null
|
||||||
// build the sql insert for the table attr_def
|
// build the sql insert for the table attr_def
|
||||||
|
$add_qcode=true;
|
||||||
if (sizeof($def_attr) != 0 )
|
if (sizeof($def_attr) != 0 )
|
||||||
{
|
{
|
||||||
// insert all the mandatory fields into jnt_fiche_attr
|
// insert all the mandatory fields into jnt_fiche_attr
|
||||||
foreach ( $def_attr as $row)
|
foreach ( $def_attr as $row)
|
||||||
{
|
{
|
||||||
$order=$row['ad_default_order'];
|
|
||||||
if ( $row['ad_id'] == ATTR_DEF_NAME )
|
|
||||||
$order=0;
|
|
||||||
$count=$this->cn->get_value("select count(*) from jnt_fic_attr where fd_id=$1 and ad_id=$2",array($fd_id,$row['ad_id']));
|
$count=$this->cn->get_value("select count(*) from jnt_fic_attr where fd_id=$1 and ad_id=$2",array($fd_id,$row['ad_id']));
|
||||||
if ($count == 0)
|
if ($count == 0)
|
||||||
{
|
{
|
||||||
$sql=sprintf("insert into jnt_fic_Attr(fd_id,ad_id,jnt_order)
|
$sql=sprintf("insert into jnt_fic_Attr(fd_id,ad_id,jnt_order)
|
||||||
values (%d,%s,%d)",
|
values (%d,%s,%d)",
|
||||||
$fd_id,$row['ad_id'],$order);
|
$fd_id,$row['ad_id'],$row['ad_default_order']);
|
||||||
$this->cn->exec_sql($sql);
|
$this->cn->exec_sql($sql);
|
||||||
}
|
}
|
||||||
|
// if there is an accounting , then not needed to add one
|
||||||
|
if ( $row['ad_id']==ATTR_DEF_ACCOUNT) $add_accounting=FALSE;
|
||||||
|
if ( $row['ad_id']==ATTR_DEF_QUICKCODE) $add_qcode=FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// if there is an base accounting, and the accounting is not in ATTR_MIN,
|
||||||
|
// then it is needed to add it
|
||||||
|
if ( $add_accounting) {
|
||||||
|
$sql=sprintf("insert into jnt_fic_attr(fd_id,ad_id,jnt_order)
|
||||||
|
values (%d,%d,10)",$fd_id,ATTR_DEF_ACCOUNT);
|
||||||
|
$Res=$this->cn->exec_sql($sql);
|
||||||
|
}
|
||||||
|
// if there is no quick code in attr_min, it is added
|
||||||
|
if ( $add_qcode) {
|
||||||
|
$sql=sprintf("insert into jnt_fic_attr(fd_id,ad_id,jnt_order)
|
||||||
|
values (%d,%d,10000)",$fd_id,ATTR_DEF_QUICKCODE);
|
||||||
|
$Res=$this->cn->exec_sql($sql);
|
||||||
|
}
|
||||||
$this->id=$fd_id;
|
$this->id=$fd_id;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
@ -710,9 +726,10 @@ $order
|
||||||
{
|
{
|
||||||
|
|
||||||
// find the min attr for the fiche_def_ref
|
// find the min attr for the fiche_def_ref
|
||||||
$Sql="select ad_id,ad_text ,ad_default_order
|
$Sql="select ad_id,ad_text ,attr_min.ad_default_order
|
||||||
from attr_min natural join attr_def
|
from attr_min
|
||||||
natural join fiche_def_ref
|
join attr_def using(ad_id)
|
||||||
|
join fiche_def_ref using(frd_id)
|
||||||
where
|
where
|
||||||
frd_id= $1 order by ad_default_order";
|
frd_id= $1 order by ad_default_order";
|
||||||
$Res=$this->cn->exec_sql($Sql,array($p_fiche_def_ref));
|
$Res=$this->cn->exec_sql($Sql,array($p_fiche_def_ref));
|
||||||
|
|
|
||||||
|
|
@ -148,19 +148,20 @@ EOF;
|
||||||
$cn=Dossier::connect();
|
$cn=Dossier::connect();
|
||||||
$dossier_id=Dossier::id();
|
$dossier_id=Dossier::id();
|
||||||
$objname=$this->get_object_name();
|
$objname=$this->get_object_name();
|
||||||
$a_attribut=$cn->get_array("select ad_id,ad_text,ad_type from attr_min join attr_def using (ad_id) where frd_id=$1 order by 2",
|
$a_attribut=$cn->get_array("select ad_id,ad_text,ad_type,a1.ad_default_order from attr_min a1 join attr_def using (ad_id) where frd_id=$1 order by a1.ad_default_order",
|
||||||
[$this->table->frd_id]);
|
[$this->table->frd_id]);
|
||||||
$nb_attribut=count($a_attribut);
|
$nb_attribut=count($a_attribut);
|
||||||
printf('<ul id="%s_list"> ', $objname);
|
printf('<ul class="list-unstyled" style="width: 60%%;margin-left: 21%%" id="%s_list"> ', $objname);
|
||||||
$used=$cn->get_value("select count(*) from jnt_fic_attr join fiche_def using (fd_id) where frd_id=$1",
|
$used=$cn->get_value("select count(*) from jnt_fic_attr join fiche_def using (fd_id) where frd_id=$1",
|
||||||
[$this->table->frd_id]);
|
[$this->table->frd_id]);
|
||||||
if ($used!=0)
|
if ($used!=0)
|
||||||
{
|
{
|
||||||
echo _("Catégorie utilisée, les attributs ne peuvent pas être modifiés");
|
echo_warning( _("Catégorie utilisée, les attributs de base ne peuvent pas être modifiés"));
|
||||||
}
|
}
|
||||||
|
echo _("Vous pouvez modifier l'ordre des attributs avec la souris");
|
||||||
for ($i=0; $i<$nb_attribut; $i++)
|
for ($i=0; $i<$nb_attribut; $i++)
|
||||||
{
|
{
|
||||||
printf('<li id="%s_elt%d">', $objname
|
printf('<li id="%s_elt%d" style="cursor:move;border:1px solid navy;padding : 0.5rem 0.2rem 0.5rem 0.2rem;margin-top:2px">', $objname
|
||||||
, $a_attribut[$i]['ad_id']);
|
, $a_attribut[$i]['ad_id']);
|
||||||
echo $a_attribut[$i]['ad_text'];
|
echo $a_attribut[$i]['ad_text'];
|
||||||
// cannot delete NAME and QUICKCODE + attribute used in a
|
// cannot delete NAME and QUICKCODE + attribute used in a
|
||||||
|
|
@ -193,22 +194,51 @@ EOF;
|
||||||
$dossier_id, $this->table->frd_id, $objname);
|
$dossier_id, $this->table->frd_id, $objname);
|
||||||
echo Icon_Action::icon_add(uniqid(), $js_script);
|
echo Icon_Action::icon_add(uniqid(), $js_script);
|
||||||
}
|
}
|
||||||
|
echo \HtmlInput::hidden("attribut_order", "");
|
||||||
|
echo create_script("Sortable.create('{$objname}_list',{
|
||||||
|
onUpdate:function(){document.getElementById('attribut_order').value=Sortable.serialize('{$objname}_list')}})");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When adding a template of category of card, the minimum is the name
|
* @brief When adding a template of category of card, the minimum is the name
|
||||||
* and the quickcode, which must be added into attr_min
|
* and the quickcode, which must be added into attr_min
|
||||||
*/
|
*/
|
||||||
function add_mandatory_attr()
|
function add_mandatory_attr()
|
||||||
{
|
{
|
||||||
$cn=Dossier::connect();
|
$cn=Dossier::connect();
|
||||||
$frd_id=$this->get_table()->getp("frd_id");
|
$frd_id=$this->get_table()->getp("frd_id");
|
||||||
|
$cn->exec_sql("insert into attr_min (frd_id,ad_id,ad_default_order) values ($1,$2)",
|
||||||
|
[$frd_id, ATTR_DEF_NAME],1);
|
||||||
$cn->exec_sql("insert into attr_min (frd_id,ad_id) values ($1,$2)",
|
$cn->exec_sql("insert into attr_min (frd_id,ad_id) values ($1,$2)",
|
||||||
[$frd_id, ATTR_DEF_NAME]);
|
[$frd_id, ATTR_DEF_QUICKCODE,10000]);
|
||||||
$cn->exec_sql("insert into attr_min (frd_id,ad_id) values ($1,$2)",
|
}
|
||||||
[$frd_id, ATTR_DEF_QUICKCODE]);
|
|
||||||
|
/**
|
||||||
|
* @brief save also the order
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function save()
|
||||||
|
{
|
||||||
|
parent::save();
|
||||||
|
$cn=$this->get_table()->get_cn();
|
||||||
|
$table_sql=$this->get_table();
|
||||||
|
$http=new HttpInput();
|
||||||
|
$ctl=$http->request("ctl")."_list";
|
||||||
|
$attribut_order=$http->post('attribut_order','string','');
|
||||||
|
if ($attribut_order=='') return;
|
||||||
|
parse_str($attribut_order,$aOrder);
|
||||||
|
if ( isset($aOrder[$ctl])) {
|
||||||
|
$order = 10;
|
||||||
|
foreach( $aOrder[$ctl] as $item) {
|
||||||
|
$ad_id = str_replace('elt','',$item);
|
||||||
|
$cn->exec_sql("update attr_min set ad_default_order = $1 where ad_id=$2 and frd_id=$3",
|
||||||
|
[$order,$ad_id,$table_sql->get('frd_id')]);
|
||||||
|
$order+=10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
alter table attr_min add ad_default_order int;
|
||||||
|
|
||||||
|
update attr_min set ad_default_order = a1.ad_default_order from attr_def a1 where a1.ad_id = attr_min.ad_id;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue