CCARD : rewrite
This commit is contained in:
parent
b5aa321d93
commit
14cc18d9a9
9 changed files with 433 additions and 116 deletions
77
include/ajax/ajax_category_card_definition.php
Normal file
77
include/ajax/ajax_category_card_definition.php
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of NOALYSS.
|
||||
*
|
||||
* NOALYSS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* NOALYSS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with NOALYSS; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
// Copyright Author Dany De Bontridder danydb@aevalys.eu 7/08/24
|
||||
/*!
|
||||
* \file
|
||||
* \brief ajax from CCARD : add , remove or sort attributes from CCARD
|
||||
*/
|
||||
if (!defined('ALLOWED')) die('Appel direct ne sont pas permis');
|
||||
global $g_user;
|
||||
|
||||
if ($g_user->check_module('CCARD') == 0) return;
|
||||
$http = new HttpInput();
|
||||
try {
|
||||
$fiche_def = $http->request('fiche_def_id', 'number');
|
||||
$op2 = $http->request("op2");
|
||||
} catch (\Exception $e) {
|
||||
echo $e->getMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
global $cn;
|
||||
|
||||
if ($op2 == 'add') {
|
||||
$ad_id=$http->get("ad_id","number");
|
||||
$row = $cn->get_row('select ad_id , ad_text from attr_def where ad_id=$1',[$ad_id]);
|
||||
Fiche_Def::print_existing_attribut($row['ad_id'], $row['ad_text']);
|
||||
|
||||
} elseif ($op2 == 'remove') {
|
||||
$ad_id=$http->get("ad_id","number");
|
||||
$row = $cn->get_row('select ad_id , ad_text from attr_def where ad_id=$1',[$ad_id]);
|
||||
Fiche_Def::print_available_attribut($row['ad_id'], $row['ad_text'],'');
|
||||
} elseif ($op2 == 'save') {
|
||||
|
||||
$str_Attribut=$http->post("attribut");
|
||||
parse_str($str_Attribut, $row);
|
||||
$aAttribut=$row['attribut_card'];
|
||||
$nb_attribut=count($aAttribut);
|
||||
try {
|
||||
$cn->start();
|
||||
$cn->exec_sql("create temporary table xxattribut (x_order int, x_adid int, x_fdid int)");
|
||||
$order = 10;
|
||||
for( $i = 0;$i < $nb_attribut;$i++) {
|
||||
$o=$order*($i+1);
|
||||
$cn->exec_sql("insert into xxattribut values ($1,$2,$3)",[$o,$aAttribut[$i],$fiche_def]);
|
||||
}
|
||||
$cn->exec_sql("delete from jnt_fic_attr where fd_id=$1 and ad_id not in (select x_adid from xxattribut)",[$fiche_def]);
|
||||
$cn->exec_sql("insert into jnt_fic_attr(ad_id,fd_id,jnt_order)
|
||||
select x_adid,x_fdid,x_order
|
||||
from xxattribut
|
||||
on conflict do nothing ");
|
||||
$cn->exec_sql('update jnt_fic_attr set jnt_order = x_order from xxattribut where ad_id=x_adid and fd_id=x_fdid');
|
||||
$cn->commit();
|
||||
echo 'OK';
|
||||
} catch (\Exception $e) {
|
||||
echo $e->getMessage();
|
||||
$cn->rollback();
|
||||
}
|
||||
|
||||
} else {
|
||||
die("[$op2] action inconnue");
|
||||
}
|
||||
|
|
@ -879,5 +879,26 @@ $order
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief display existing attribut
|
||||
* @param $attribut_id int SQL attr_def.ad_id
|
||||
* @param $attribut_text SQL attr_def.ad_text
|
||||
* @return void
|
||||
*/
|
||||
public static function print_existing_attribut($attribut_id,$attribut_text)
|
||||
{
|
||||
include NOALYSS_TEMPLATE.'/fiche_def-print_existing_attribut.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief display available attribut
|
||||
* @param $attribut_id int SQL attr_def.ad_id
|
||||
* @param $attribut_text SQL attr_def.ad_text
|
||||
* @return void
|
||||
*/
|
||||
public static function print_available_attribut($attribut_id,$attribut_text,$class)
|
||||
{
|
||||
include NOALYSS_TEMPLATE.'/fiche_def-print_available_attribut.php';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class INum extends IText
|
|||
parent::__construct($name, $value, $id);
|
||||
|
||||
$this->size=9;
|
||||
$this->style='class="inum"';
|
||||
$this->style='class="inum input_text"';
|
||||
$this->javascript='onchange="format_number(this,2);"';
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,86 +41,69 @@ $available_attribut = $cn->get_array('
|
|||
<div class="row">
|
||||
<div class="col">
|
||||
<h3>Attributs de la classe</h3>
|
||||
<div id="attribut_card">
|
||||
<?php
|
||||
$i = 0;
|
||||
foreach ($existing_attribut
|
||||
|
||||
as $item):
|
||||
$class = ($i % 2 == 0) ? 'even' : 'odd';
|
||||
$i++;
|
||||
?>
|
||||
|
||||
<div id="attr_<?=$item['jnt_id']?>" style="cursor: move;" class="<?= $class ?>" order="<?= $item['jnt_order'] ?>">
|
||||
|
||||
|
||||
<ul id="attribut_card" class="list-unstyled" style="cursor: move;">
|
||||
<?php
|
||||
echo $item['ad_text'];
|
||||
?>
|
||||
<div style="float:right">
|
||||
<?=\Icon_Action::trash("0","")?>
|
||||
</div>
|
||||
</div>
|
||||
$i = 0;
|
||||
foreach ($existing_attribut as $item):
|
||||
|
||||
Fiche_Def::print_existing_attribut($item['ad_id'], $item['ad_text']);
|
||||
?>
|
||||
|
||||
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</div>
|
||||
</ul>
|
||||
</div>
|
||||
<div class=" col-2">
|
||||
<h4> Ranger les attributs</h4>
|
||||
<p>
|
||||
Supprimer un attribut n'est pas réversible: les données de ces attributs
|
||||
Déplacer les attributs de la fiche en cliquant et déplacer sans relacher le bouton de la souris.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Supprimer un attribut n'est pas réversible:() les données de ces attributs
|
||||
seront définitivement perdus.
|
||||
</p>
|
||||
<!-- <input type="submit" class="button" value="Sauver les attributs">-->
|
||||
<p>
|
||||
Ajouter des attributs depuis les attributs disponibles en cliquant sur la flèche.
|
||||
</p>
|
||||
<p>
|
||||
<input type="button" class="button" onclick="categoryCardDefinition.save();return false" value="Sauve">
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col border-dark">
|
||||
<h3>Attributs disponibles</h3>
|
||||
<?php
|
||||
echo HtmlInput::filter_table("avail_attribut_id", '0', '0');
|
||||
?>
|
||||
<table id="avail_attribut_id" style="width: 90%">
|
||||
<div class="col border-dark">
|
||||
<h3>Attributs disponibles</h3>
|
||||
<?php
|
||||
$i = 0;
|
||||
foreach ($available_attribut as $item):
|
||||
$class = ($i % 2 == 0) ? 'even' : 'odd';
|
||||
$i++;
|
||||
echo HtmlInput::filter_list("avail_attribut_id", '0', '0');
|
||||
?>
|
||||
<tr class="<?= $class ?>">
|
||||
<td>
|
||||
<?php
|
||||
// ajout de l'attribut donc cette ligne disparait, et apparait de l'autre cote + maj db
|
||||
$js_add=sprintf("f")
|
||||
?>
|
||||
|
||||
<span class="icon" onclick="<?=$js_add?>">⇦</span>
|
||||
</td>
|
||||
|
||||
|
||||
<td>
|
||||
|
||||
<?php
|
||||
echo $item['ad_text'];
|
||||
?>
|
||||
</td>
|
||||
<ul id="avail_attribut_id" style="width: 90%" class="list-unstyled">
|
||||
<?php
|
||||
$i = 0;
|
||||
foreach ($available_attribut as $item):
|
||||
$class = ($i % 2 == 0) ? 'even' : 'odd';
|
||||
$i++;
|
||||
Fiche_Def::print_available_attribut($item['ad_id'], $item['ad_text'], $class);
|
||||
?>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
|
||||
</table>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="row">
|
||||
|
||||
</div>
|
||||
<script>
|
||||
<script>
|
||||
|
||||
(function() {
|
||||
(function () {
|
||||
Sortable.create('attribut_card', {tag: 'li',hoverclass:'hoverclass-drag'});
|
||||
})();
|
||||
|
||||
Sortable.create('attribut_card',{tag:'div',onChange:function(e) {console.debug(e)},onUpdate:function(e) { console.debug(e)}});
|
||||
|
||||
})();
|
||||
</script>
|
||||
var categoryCardDefinition=new CategoryCardDefinition(<?=Dossier::id()?>,<?=$this->id?>);
|
||||
</script>
|
||||
|
|
|
|||
43
include/template/fiche_def-print_available_attribut.php
Normal file
43
include/template/fiche_def-print_available_attribut.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of NOALYSS.
|
||||
*
|
||||
* NOALYSS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* NOALYSS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with NOALYSS; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
// Copyright Author Dany De Bontridder danydb@aevalys.eu 7/08/24
|
||||
/*!
|
||||
* \file
|
||||
* \brief available attribut for card category
|
||||
*/
|
||||
|
||||
$js_add = sprintf("categoryCardDefinition.add_attribut('%s')",$attribut_id);
|
||||
?>
|
||||
<li id="avail_attr_<?= $attribut_id ?>" class="<?= $class ?>">
|
||||
<span>
|
||||
<?php
|
||||
|
||||
?>
|
||||
|
||||
<span class="icon" onclick="<?= $js_add ?>">🠈</span>
|
||||
</span>
|
||||
|
||||
|
||||
<span class="search-content">
|
||||
|
||||
<?php
|
||||
echo $attribut_text;
|
||||
?>
|
||||
</span>
|
||||
</li>
|
||||
42
include/template/fiche_def-print_existing_attribut.php
Normal file
42
include/template/fiche_def-print_existing_attribut.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of NOALYSS.
|
||||
*
|
||||
* NOALYSS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* NOALYSS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with NOALYSS; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
// Copyright Author Dany De Bontridder danydb@aevalys.eu 7/08/24
|
||||
/*!
|
||||
* \file
|
||||
* \brief display existing attribut
|
||||
*/
|
||||
|
||||
$js_remove = sprintf("categoryCardDefinition.remove_attribut('%s')", $attribut_id);
|
||||
|
||||
?>
|
||||
<li class="hoverclass-drag" style="border:1px solid navy;margin:1px;padding:5px;"
|
||||
id="existing_attr_<?= $attribut_id ?>">
|
||||
|
||||
<span>
|
||||
|
||||
<?php
|
||||
echo $attribut_text;
|
||||
?>
|
||||
</span>
|
||||
<div style="float:right">
|
||||
<?php if ($attribut_id != 1 && $attribut_id != 23) : ?>
|
||||
<?= \Icon_Action::trash(uniqid(), $js_remove) ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</li>
|
||||
Loading…
Add table
Add a link
Reference in a new issue