]> git.agnieray.net Git - galette.git/commitdiff
Add information to display on dynamic fields; closes #1190
authorJohan Cwiklinski <johan@x-tnd.be>
Fri, 12 Nov 2021 05:36:34 +0000 (06:36 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Fri, 12 Nov 2021 05:43:01 +0000 (06:43 +0100)
galette/install/scripts/mysql.sql
galette/install/scripts/pgsql.sql
galette/install/scripts/upgrade-to-0.96-mysql.sql
galette/install/scripts/upgrade-to-0.96-pgsql.sql
galette/lib/Galette/DynamicFields/DynamicField.php
galette/templates/default/edit_dynamic_fields.tpl
galette/templates/default/editer_champ.tpl
tests/Galette/DynamicFields/tests/units/DynamicField.php

index 735fc2f84b17cca3ed58563ef2d109ac737db89b..4461b07bc741450c03b60c04a887e86ca8ec9c8f 100644 (file)
@@ -137,7 +137,7 @@ CREATE TABLE galette_field_types (
     field_height int(10) default NULL,
     field_size int(10) default NULL,
     field_repeat int(10) default NULL,
-    field_layout int(10) default NULL,
+    field_information TEXT default NULL,
     PRIMARY KEY (field_id),
     INDEX (field_form)
 ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
index ae1adc38c1170b6e4d3118778b8b9ce0ff658255..fc5f5d93626c5144462ca0d584d09c3fd59e13e1 100644 (file)
@@ -302,7 +302,7 @@ CREATE TABLE galette_field_types (
   field_height integer DEFAULT NULL,
   field_size integer DEFAULT NULL,
   field_repeat integer DEFAULT NULL,
-  field_layout integer DEFAULT NULL,
+  field_information text DEFAULT NULL,
   PRIMARY KEY (field_id)
 );
 -- add index, field_form is used elsewhere
index 77009d6ac556090613a93c74851544e15c172c06..338815c8053c6f6441d091ac5c1acd964edfc8db 100644 (file)
@@ -46,4 +46,9 @@ ALTER TABLE galette_searches DROP COLUMN parameters_sum;
 -- drop groups unique name constraint
 ALTER TABLE galette_groups DROP INDEX `name`;
 
+-- add information on dynamic fields
+ALTER TABLE galette_field_types ADD COLUMN field_information text DEFAULT NULL;
+-- field that has never been used
+ALTER TABLE galette_field_types DROP COLUMN field_layout;
+
 UPDATE galette_database SET version = 0.960;
\ No newline at end of file
index 6e8127430e67df5abe31c9392d3edc61e953a07d..4bf1b953c07d9144f802789c31320629a1e53e0c 100644 (file)
@@ -54,4 +54,9 @@ ALTER TABLE galette_searches DROP COLUMN parameters_sum;
 -- drop groups unique name constraint
 ALTER TABLE galette_groups DROP CONSTRAINT name;
 
+-- add information on dynamic fields
+ALTER TABLE galette_field_types ADD COLUMN field_information text DEFAULT NULL;
+-- field that has never been used
+ALTER TABLE galette_field_types DROP COLUMN field_layout;
+
 UPDATE galette_database SET version = 0.960;
\ No newline at end of file
index 67e24a1e0c500b37b26440813a27203149e05896..3ee1aa2b513f49af5246184b82224af6b2390a3b 100644 (file)
@@ -53,7 +53,7 @@ use Laminas\Db\Sql\Predicate\Expression as PredicateExpression;
  * @package   Galette
  *
  * @author    Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2012-2014 The Galette Team
+ * @copyright 2012-2021 The Galette Team
  * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
  * @link      http://galette.tuxfamily.org
  */
@@ -112,6 +112,9 @@ abstract class DynamicField
     protected $old_size;
     protected $values;
     protected $form;
+    protected $information;
+    protected $name;
+    protected $old_name;
 
     protected $errors = [];
 
@@ -255,6 +258,7 @@ abstract class DynamicField
         $this->repeat = (int)$rs->field_repeat;
         $this->size = $rs->field_size;
         $this->form = $rs->field_form;
+        $this->information = $rs->field_information;
         if ($values && $this->hasFixedValues()) {
             $this->loadFixedValues();
         }
@@ -404,7 +408,6 @@ abstract class DynamicField
         return (bool)$this->has_permissions;
     }
 
-
     /**
      * Get field id
      *
@@ -425,7 +428,6 @@ abstract class DynamicField
         return $this->perm;
     }
 
-
     /**
      * Is field required?
      *
@@ -496,6 +498,16 @@ abstract class DynamicField
         return $this->index;
     }
 
+    /**
+     * Get field information
+     *
+     * @return string
+     */
+    public function getInformation(): string
+    {
+        return $this->information ?? '';
+    }
+
     /**
      * Retrieve permissions names for display
      *
@@ -648,6 +660,11 @@ abstract class DynamicField
             $this->repeat = $values['field_repeat'];
         }
 
+        if (isset($values['field_information']) && trim($values['field_information']) != '') {
+            global $preferences;
+            $this->information = $preferences->cleanHtmlValue($values['field_information']);
+        }
+
         if ($this->hasFixedValues() && isset($values['fixed_values'])) {
             $fixed_values = [];
             foreach (explode("\n", $values['fixed_values']) as $val) {
@@ -708,7 +725,8 @@ abstract class DynamicField
                 'field_size'        => ($this->size === null ? new Expression('NULL') : $this->size),
                 'field_repeat'      => ($this->repeat === null ? new Expression('NULL') : $this->repeat),
                 'field_form'        => $this->form,
-                'field_index'       => $this->index
+                'field_index'       => $this->index,
+                'field_information' => ($this->information === null ? new Expression('NULL') : $this->information)
             );
 
             if ($this->required === false) {
index a4bea2f83ceab52d84e600f911cfee16ce27e536..84e445dd0a9dd047515477a815a9c15db0339493 100644 (file)
     <div>
     {assign var=access_level value=$login->getAccessLevel()}
     {foreach from=$fields item=field}
+        {if $field->getInformation()}
+            <div>{$field->getInformation()}</div>
+        {/if}
+
         {assign var=perm value=$field->getPerm()}
         {if $field|is_a:'Galette\DynamicFields\Separator'}
         <div class="separator">{$field->getName()|escape}</div>
         {elseif ($field|is_a:'Galette\DynamicFields\File' || $field->isRepeatable())  && $masschange}
-            <!-- File and repetable fields not shown in mass changes form -->
+            <!-- File and repeatable fields not shown in mass changes form -->
         {else}
         <p{if $field->isRepeatable()} class="repetable"{/if}>
             {assign var=disabled value=false}
index 41fbeb54b0d00b7991d5d4a1fba1c0eb87b6272c..65b2a6c70057893699ec8f0652fb255c599f727b 100644 (file)
                 <br/><span class="exemple">{_T string="Choice list (one entry per line)."}</span>
             </p>
 {/if}
+            <p>
+                <label for="field_information" class="bline tooltip">{_T string="Information:"}</label>
+                <span class="tip">{_T string="Extra information displayed along with dynamic field."}</span>
+                <textarea name="field_information" id="field_information" cols="20" rows="6">{$df->getInformation()}</textarea>
+            </p>
         </fieldset>
             <div class="button-container">
                 <button type="submit" class="action">
     </form>
 {/if}
 {/block}
+
+{block name="javascripts"}
+    <script>
+        $('#field_information').summernote({
+            lang: '{$i18n->getID()|replace:'_':'-'}',
+            height: 240,
+            toolbar: [
+                ['style', ['style']],
+                ['font', ['bold', 'italic', 'strikethrough', 'clear']],
+                ['para', ['ul', 'ol', 'paragraph']],
+                ['insert', ['link', 'picture']],
+                ['view', ['codeview', 'help']]
+            ],
+            styleTags: [
+                'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
+            ]
+        });
+        $('#field_information').summernote('focus');
+
+    </script>
+{/block}
index 0dc2a550d7322c3b539255e1bba1bb801dc7d72a..787ff066b3d53bedf095f160c6bc050e606e8da3 100644 (file)
@@ -516,4 +516,33 @@ class DynamicField extends atoum
         )->isInstanceOf('\PDOException');
         $this->boolean(\Galette\DynamicFields\DynamicField::loadFieldType($this->zdb, $df_id))->isFalse();
     }
+
+    /**
+     * Test information
+     *
+     * @return void
+     */
+    public function testInformation()
+    {
+        $field_data = [
+            'form_name'         => 'adh',
+            'field_name'        => 'A first text field',
+            'field_perm'        => \Galette\DynamicFields\DynamicField::PERM_USER_WRITE,
+            'field_type'        => \Galette\DynamicFields\DynamicField::TEXT,
+            'field_information' => '<p>This is an important information.</p><p>And here an xss...  <img src=img.png onerror=alert(1) /></p>'
+        ];
+
+        $df = \Galette\DynamicFields\DynamicField::getFieldType($this->zdb, $field_data['field_type']);
+        $stored = $df->store($field_data);
+        $this->boolean($stored)->isTrue(
+            implode(
+                ' ',
+                $df->getErrors() + $df->getWarnings()
+            )
+        );
+        $this->boolean($stored)->isTrue();
+        $this->object(\Galette\DynamicFields\DynamicField::loadFieldType($this->zdb, $df->getId()))->isEqualTo($df);
+
+        $this->string($df->getInformation())->isIdenticalTo('<p>This is an important information.</p><p>And here an xss...  <img src="img.png" alt="img.png" /></p>');
+    }
 }