Pouvoir modifier les profils

This commit is contained in:
Michael RICOIS 2012-04-06 13:11:46 +00:00
parent 689566d34c
commit 86cfe1e141
6 changed files with 130 additions and 75 deletions

View File

@ -19,8 +19,6 @@ class ProfilController extends Zend_Controller_Action
require_once 'Scores/Enrichissement.php';
$data = new Enrichissement();
$this->view->assign('elements', $data->getDico());
if ( $id != null ) {
$profilM = new Application_Model_Profil();
$profil = $profilM->find($id);
@ -30,6 +28,7 @@ class ProfilController extends Zend_Controller_Action
$tmp[] = $data->getDicoLib($critere);
}
$this->view->assign('profil', $tmp);
$this->view->assign('reference', $profil->current()->reference);
}
}
@ -41,7 +40,31 @@ class ProfilController extends Zend_Controller_Action
require_once 'Scores/Enrichissement.php';
$data = new Enrichissement();
if ( $id != null ) {
$profilM = new Application_Model_Profil();
$profil = $profilM->find($id);
$criteres = json_decode($profil->current()->criteres, true);
$tmp = array();
foreach ($criteres as $critere) {
$values = false;
if (preg_match('/(.*)\((.*)\)/', $critere, $matches))
{
$values = $matches[2];
}
$tmp[$critere] = array(
'lib' => $data->getDicoLib($critere),
'values' => $values,
);
}
$this->view->assign('criteres', $tmp);
$this->view->assign('reference', $profil->current()->reference);
}
$this->view->assign('id', $id);
$this->view->assign('edit', true);
$this->view->assign('elements', $data->getDico());
}
public function saveAction()
@ -59,12 +82,22 @@ class ProfilController extends Zend_Controller_Action
'reference' => $reference,
'criteres' => json_encode($criteres),
);
$id = $request->getParam('id', null);
if ( $id != null ) {
if ( $profilM->update($data, 'id='.$id) ){
echo '';
} else {
echo 'Erreur';
}
} else {
if ( $profilM->insert($data) ){
echo '';
} else {
echo 'Erreur';
}
}
}
public function setAction()
{

View File

@ -3,7 +3,7 @@ div#entete {
width:45%;
float:left;
border:1px solid #bebebe;
height:400px;
height:500px;
overflow:auto;
margin:5px 0;
}
@ -16,12 +16,12 @@ div#entete li {
font-weight:bold;
color:#000000;
margin-left:30px;
padding-left:10px;
padding:5px 10px;
}
div#dico {
width:45%;
height:400px;
height:500px;
float:right;
border:1px solid #bebebe;
overflow:auto;
@ -30,7 +30,7 @@ div#dico {
div#dico li {
list-style-type:none;
padding-left:10px;
padding:5px 10px;
background-color:#4D90FE;
border-top:2px solid #ffffff;
border-bottom:2px solid #ffffff;
@ -39,15 +39,28 @@ div#dico li {
color:#000000;
}
input[type="text"] {
border:1px solid;
}
</style>
<div id="entete">
<h1 class="ui-widget-header">Entete</h1>
<div class="ui-widget-content">
<ol>
<h1 class="ui-widget-header">Entete</h1>
<div class="ui-widget-content">
<ol>
<?php if (count($this->criteres)==0) {?>
<span class="placeholder">Placer les elements ici</span>
</ol>
</div>
<?php } else {?>
<?php foreach($this->criteres as $key => $element) {?>
<li id="<?=$key?>">
<?php if (isset($element['lib'])) { echo $element['lib']; } else { echo $key; }?>
<?php if (isset($element['values']) && $element['values']!==false ) {
echo "<input type=\"text\" name=\"".$key."\" value=\"".$element['values']."\"/>"; }?>
</li>
<?php }?>
<?php }?>
</ol>
</div>
</div>
<div id="dico">
@ -64,7 +77,12 @@ div#dico li {
<div style="clear:both;">
Référence <input type="text" name="profil" value="" />
<?php if ($this->edit) { ?>
<a id="save" href="<?=$this->url(array('controller'=>'profil', 'action'=>'save', 'id'=>$this->id))?>">Modifier</a>
<?php } else {?>
<a id="save" href="<?=$this->url(array('controller'=>'profil', 'action'=>'save'))?>">Sauvegarder</a>
<?php }?>
</div>
<script>
@ -77,7 +95,8 @@ $(function() {
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
accept: ":not(.ui-sortable-helper)",
drop: function( event, ui ) {
drop: function( e, ui ) {
e.preventDefault();
$( this ).find( ".placeholder" ).remove();
var id = ui.draggable.attr('id');
$('<li id="'+id+'"></li>').html( ui.draggable.html() ).appendTo( this );
@ -90,13 +109,15 @@ $(function() {
});
$("#entete").delegate("a.delete","click", function(){
e.preventDefault();
$(this).parent().remove();
});
$("#entete ol").delegate("li" , "hover", function(e) {
e.preventDefault();
if (e.type === 'mouseenter') {
var html = $(this).html();
$(this).html(html+'<a href="#" class="delete">Supprimer</a>');
$(this).html(html+'<a href="#" style="float:right;" class="delete">Supprimer</a>');
} else {
$( this ).find( ".delete" ).remove();
}

View File

@ -1,4 +1,5 @@
<div>
<h2>Profil : <?=$this->reference?></h2>
<ol>
<?php foreach ($this->profil as $item) {?>
<li><?=$item?></li>

View File

@ -1,6 +1,6 @@
<div>
<h2>Gestion des profils</h2>
<?php if (count($this->profils)>0) {?>
<table>
<thead>
<tr>
@ -12,7 +12,7 @@
<?php foreach($this->profils as $profil) {?>
<tr>
<td><a href="<?=$this->url(array('controller'=>'profil', 'action'=>'detail', 'id'=>$profil->id))?>"><?=$profil->reference?></a></td>
<td></td>
<td><a href="<?=$this->url(array('controller'=>'profil', 'action'=>'create', 'id'=>$profil->id))?>">Edition</a></td>
</tr>
<?php }?>
</tbody>

View File

@ -13,7 +13,7 @@ body {
}
#header {
height: 100px;
height: 10px;
padding: 0 40px;
position: relative;
}