$fieldName) && in_array($fieldName, $myReadonlyFields) ); //return ( in_array($fieldName, $readonlyFields) ); return ( array_key_exists($fieldName, $readonlyFields) ); } /* private function getLabelForFieldName ($fieldName) { if ( substr($fieldName, -3) === '_id' ) $fieldName = substr($fieldName,0,-3); return ucfirst($fieldName); } */ // (EP) Fonction utilisée dans la vue Materiels/add_or_edit function control( $IS_ADD, $readonlyFields, $fieldName, $label=null, $empty=null, $default=null, $type=null, $class=null, $placeholder=null, $value=null ) { $fieldValue = $this->_View->viewVars['entity']->$fieldName; $options = [ //'type' => 'text', //'label' => $label ? $label : $this->getLabelForFieldName($fieldName), 'label' => $label, // si null, c'est le framework qui génère un label auto //'empty' => 'Choisir un domaine', 'empty' => $empty, 'default' => $default, 'type' => $type, 'class' => $class, 'placeholder' => $placeholder, //'value' => $value, //'style' => 'width: 260px', // inutile car automatique si le nom de la variable passée par le controleur respecte la norme //'options' => $surCategories, //'default' => $Designation, // ADD only /////'default' => $materiel->designation, //'default' => $designations, //'default' => $designations->toArray(), // EDIT only // disabled ssi EDIT && readonly && pas vide (jamais disabled si mode ADD) 'disabled' => !$IS_ADD && $this->isReadonlyField($fieldName, $readonlyFields) && !empty($fieldValue) //'disabled' => $IS_ADD ? false : $this->isReadonlyField($fieldName, $readonlyFields) && !empty($this->Form->getData($fieldName)) ]; //if (!is_null($default)) $options['default'] = $default; if (!is_null($value)) $options['value'] = $value; return $this->Form->control($fieldName, $options); } function echoListToManageOrViewWithIcon($can_manage=false, $list_name, $controller_name, $action_name='index') { //function echo_list($html, $verb, $list_name, $controller_name, $action_name) { $verb = $can_manage ? 'Gérer' : 'Voir'; $icon_name = $can_manage ? 'config2.png' : 'see2.png'; $this->echoMenuItemWithIcon($icon_name, "$verb les $list_name", $controller_name, $action_name, 'nom'); } function echoMenuItemPostLinkWithIcon($icon_name, $title, $controller_name, $action_name) { $this->echoMenuItemLinkOrPostLinkWithIcon(true, $icon_name, $title, $controller_name, $action_name); } function echoMenuItemWithIcon($img_name, $title, $controller_name, $action_name=null, $sort_field=null) { $this->echoMenuItemLinkOrPostLinkWithIcon(false, $img_name, $title, $controller_name, $action_name, $sort_field); } function echoMenuItemLinkOrPostLinkWithIcon($postlink, $img_name, $title, $controller_name, $action_name=null, $sort_field=null) { $icon_size=40; echo ''; echo ""; echo $this->Html->image("icons/$img_name", [ "alt" => $title, 'height' => $icon_size, 'width' => $icon_size, 'url' => ['controller' => $controller_name, 'action' => $action_name] ]); echo ''; echo ''; if (! $postlink) { echo $this->Html->link($title, [ 'controller' => $controller_name, 'action' => $action_name, 'sort' => $sort_field, ]); } else { echo $this->Form->postlink($title, [ 'controller' => $controller_name, 'action' => $action_name, ], [ 'confirm' => __('Êtes-vous sur ?') ]); } echo ''; echo ''; } public function getActionButton($icon_class, $buttonStyle, $title, $controller, $action, $id, $other_args=[], $tip='', $confirmMessage='', $moreButtonStyle='') { if ($controller=='') $controller='materiels'; $controllerArgs = []; $controllerArgs['controller'] = $controller; $controllerArgs['action'] = $action; $controllerArgs[] = $id; foreach ($other_args as $other_arg) $controllerArgs[] = $other_arg; return $this->Html->link( __("$title"), $controllerArgs, /* [ 'controller' => $controller, 'action' => $action, $id, $other_args ], */ [ 'title' => $tip, 'escape' => false, 'onclick' => 'return true;', //'style' => 'margin-right: 10px'.$moreButtonStyle, 'style' => $buttonStyle, 'confirm' => $confirmMessage ] ); } public function displayTableRowLabelAndValue($label, $value, $params = "") { $this->displayElement($label, $value, $params); } //@deprecated public function displayElement($label, $value, $params = "") { $TD = ($params=="") ? 'TD' : "TD $params"; //$TD = ($params=="") ? '' : ''; //$tdstyle = $params!="" ? $params : ''; // Ca c'est parce que sinon y'a au moins deux tests qui passent pas, a cause de l'espace dans la balise ... //if ($valeur != "") echo ' '.$nom.' ' . $TD.$valeur.''; //if ($valeur != "") echo '' . $nom . ' ' . $balise . $valeur . ''; //if ($valeur!="") echo " ".__($nom)." <$TD>".h($valeur)." "; //if ($valeur!="") echo " ".__($nom)." <$TD>".$valeur." "; if ($value!==null && $value!=='') { $val = $value; if ($value === true) $val = 'Oui'; if ($value === false) $val = 'Non'; echo " ".__($label)." <$TD>".$val." "; } //if ($valeur!="") echo " $nom <$TD>$valeur "; } public function echoActionButton ( $icon_class, $buttonStyle, $title, $action, $id, $controller=null, // si controleur null =>controleur par défaut $other_args=[], $tip='', $confirmMessage='', $moreButtonStyle='', $with_confirm=false ) { //if ($controller=='') $controller='materiels'; $controllerArgs = []; if ($controller) $controllerArgs['controller'] = $controller; $controllerArgs['action'] = $action; $controllerArgs[] = $id; foreach ($other_args as $other_arg) $controllerArgs[] = $other_arg; // Avec confirmation (avant de déclencher l'action) if ($with_confirm) { if (!$confirmMessage) $confirmMessage = __("Êtes-vous sur de vouloir $title cette entité ?"); echo $this->Form->postLink(__("$title"), $controllerArgs, [ 'title' => $title, //'style' => $buttonStyle, 'style' => 'margin-left: 10px', 'escape' => false, 'confirm' => $confirmMessage, //'confirm' => $confirmMessage //'confirm' => __("Êtes-vous sur de vouloir $title cette entité ?"), //'confirm' => __('Êtes-vous sur de vouloir supprimer # {0}?', $suivi->id) ]); } // Sans confirmation (action directe) else { echo $this->Html->link( __("$title"), $controllerArgs, /* [ 'controller' => $controller, 'action' => $action, $id, $other_args ], */ [ 'title' => $tip, 'escape' => false, 'onclick' => 'return true;', //'style' => 'margin-right: 10px'.$moreButtonStyle, 'style' => $buttonStyle, //'confirm' => $confirmMessage ? $confirmMessage : $tip, ] ); } } public function echoEditButton () { $this->echoButtonForAction('icon-pencil', 'edit', 'Editer', 'Modifier'); } public function echoButtonForAction ($icon_class, $action, $label, $tooltip, $with_confirm=false) { //$icon_class = 'icon-pencil'; $buttonStyle = 'margin-right: 10px'; echo '
'; $this->echoActionButton($icon_class, $buttonStyle, " $label", $action, null, null, [], $tooltip, '', '', $with_confirm ); echo "
"; } public function echoDeleteButton ( $title, $id, $controller=null, // si controleur null =>controleur par défaut $other_args=[], $confirmMessage='', $moreButtonStyle='' ) { //if ($controller=='') $controller='materiels'; $controllerArgs = []; if ($controller) $controllerArgs['controller'] = $controller; $controllerArgs['action'] = 'delete'; $controllerArgs[] = $id; foreach ($other_args as $other_arg) $controllerArgs[] = $other_arg; echo $this->Form->postLink(__("$title"), $controllerArgs, [ 'title' => 'Supprimer', //'style' => $buttonStyle, 'style' => 'margin-left: 10px', 'escape' => false, //'confirm' => $confirmMessage 'confirm' => __('Êtes-vous sur de vouloir supprimer cette entité ?'), //'confirm' => __('Êtes-vous sur de vouloir supprimer # {0}?', $suivi->id) ]); } /* Pour src/Template/Configurations/view et edit */ public function echoSectionStart($title, $nice_title=null) { $icon_class = 'icon-chevron-up'; // 'icon-chevron-down'; if (!$nice_title) $nice_title = $title; $WITH_TABLE=true; //echo '

'; //echo "

"; echo "

"; //echo ''; //echo ''; echo ""; echo ' '.''.$nice_title.''; echo '

'; //echo '
'; echo '
'; if ($WITH_TABLE) { echo ''; echo ''; } } public function echoSectionStop() { $WITH_TABLE=true; if ($WITH_TABLE) echo '
'; echo '
'; } //function displaySectionShowHide($controller_name, $entity_type_name, $title, $id_name, $is_masculine, $name_field_name, $entities) { //function displaySectionShowHide($controller_name, $entity_type_name, $title, $is_masculine, $name_field_name, $entities) { function displayAssociatedEntitiesAsSectionShowHide($controller_name, $entity_type_name, $title, $is_masculin, $name_field_name, $entities) { $id_name = $controller_name; $id_h3 = 't_'.$id_name; $id_i = 'i_'.$id_name; $title = ucfirst($title).' associé'. ($is_masculin ? 's' : 'es'); echo "

"; //echo ""; echo ""; //echo " $title (".$entities->count().")"; echo " $title (".count($entities).")"; echo "

"; echo "
"; //if (true) { $shift3 = '   '; $shift5 = '     '; //if ($entities->isEmpty()) { if (empty($entities)) { //echo "Aucune $entity_name liée à ce domaine."; echo $shift5.($is_masculin ? "Aucun $entity_type_name associé" : "Aucune $entity_type_name associée"); } else { echo ""; /* */ foreach ($entities as $entity) { echo ""; echo ""; /* */ echo ""; } echo "
<= __('Nom') ?> <= __('Détail') ?>
"; // Nom de l'entité (ou numéro de l'entité si nom vide, comme pour les emprunts par exemple...) $name = $entity->$name_field_name ? $entity->$name_field_name : "$entity_type_name #".$entity->id; echo $shift3.$this->Html->link(h($name), ['controller' => $controller_name, 'action' => 'view', h($entity->id)]); echo " <= $this->Html->link(__(''), ['controller' => $controller, 'action' => 'view', $entity->id], ['escape' => false, 'style' => 'margin:0']) ?>
"; } echo "
"; } // displaySectionShowHide() }