]> git.agnieray.net Git - galette.git/commitdiff
Factorize replacements legends display
authorJohan Cwiklinski <johan@x-tnd.be>
Mon, 25 Oct 2021 05:48:27 +0000 (07:48 +0200)
committerJohan Cwiklinski <johan@x-tnd.be>
Sun, 7 Nov 2021 08:07:54 +0000 (09:07 +0100)
galette/templates/default/gestion_pdf.tpl
galette/templates/default/gestion_pdf_content.tpl
galette/templates/default/gestion_textes.tpl
galette/templates/default/replacements_legend.tpl [new file with mode: 0644]

index 098181e7956a21d116a1ea06ade916c48b3760ea..a569dc77cdc153350e1a552eb12f572935d9bedf 100644 (file)
 
 {block name="javascripts"}
         <script type="text/javascript">
-            $('#tabs').append('<a id="btnlegend" class="tab-button tooltip action" title="{_T string="Show existing variables"}"><i class="fas fa-info-circle fa-2x"></i> <span class="sr-only">{_T string="Show existing variables" escape="js"}</span></a>');
-
-            var _handleLegend = function(index) {
-                $('#legende' + index + ' h1').remove();
-                $('#legende' + index).dialog({
-                    autoOpen: false,
-                    modal: true,
-                    hide: 'fold',
-                    width: '60em'
-                }).dialog('close');
-
-                $('#btnlegend').unbind('click').click(function(){
-                    $('#legende' + index).dialog('open');
-                        return false;
-                });
-            };
+            _addLegenButton('#tabs');
 
             $(function(){
                 $('#tabs').tabs({
index 5315b799f2eee80fdd590d50022b8dc3ac50454b..d8956fcc9d81d663c86aeafdf708754337b4e442 100644 (file)
                 </button>
             </div>
         </form>
-        <div id="legende{$model->id}" class="texts_legend" title="{_T string="Existing variables"}">
-            <h1>{_T string="Existing variables"}</h1>
-            <table>
-{foreach from=$model->getLegend() item=legend}
-                <tr>
-                    <th colspan="4">
-                        {$legend.title}
-                    </th>
-                </tr>
-    {foreach from=$legend.patterns item=pattern name=patternloop}
-        {if $smarty.foreach.patternloop.index % 2 == 0}
-                <tr>
-        {/if}
-                    <th><tt>{$pattern.pattern|trim:'/'}</tt></th>
-                    <td class="back">{if isset($pattern.title)}{$pattern.title}{/if}</td>
-        {if $smarty.foreach.patternloop.index % 2 != 0}
-                </tr>
-        {/if}
-    {/foreach}
-{/foreach}
-            </table>
-        </div>
+        {include file="replacements_legend.tpl" legends=$model->getLegend() cur_ref=$model->id}
\ No newline at end of file
index 73fb0e9aa720ac33bd380a0b5c37347540cc1e47..1fdde520cb99b7866695499fe242d5d52fe62d2a 100644 (file)
             </button>
         </div>
         </form>
-        <div id="legende{$cur_ref}" class="texts_legend" title="{_T string="Existing variables"}">
-            <h1>{_T string="Existing variables"}</h1>
-            <table>
-                {foreach from=$texts->getLegend() item=legend}
-                    <tr>
-                        <th colspan="4">
-                            {$legend.title}
-                        </th>
-                    </tr>
-                    {foreach from=$legend.patterns item=pattern name=patternloop}
-                        {if $smarty.foreach.patternloop.index % 2 == 0}
-                            <tr>
-                        {/if}
-                        <th><tt>{$pattern.pattern|trim:'/'}</tt></th>
-                        <td class="back">
-                            {if isset($pattern.title)}{$pattern.title}{/if}
-                        </td>
-                        {if $smarty.foreach.patternloop.index % 2 != 0}
-                            </tr>
-                        {/if}
-                    {/foreach}
-                {/foreach}
-            </table>
-        </div>
+        {include file="replacements_legend.tpl" legends=$texts->getLegend() cur_ref=$cur_ref}
 {/block}
 
 {block name="javascripts"}
                     this.form.submit();
                 });
 
-
-                $('fieldset').prepend('<a id="btnlegend" class="tab-button tooltip action" title="{_T string="Show existing variables"}"><i class="fas fa-info-circle fa-2x"></i> <span class="sr-only">{_T string="Show existing variables" escape="js"}</span></a>');
-                $('#legende{$cur_ref} h1').remove();
-                $('#legende{$cur_ref}').dialog({
-                    autoOpen: false,
-                    modal: true,
-                    hide: 'fold',
-                    width: '40%',
-                    create: function (event, ui) {
-                        if ($(window ).width() < 767) {
-                            $(this).dialog('option', {
-                                    'width': '95%',
-                                    'draggable': false
-                            });
-                        }
-                    }
-                }).dialog('close');
-
-                $('#btnlegend').click(function(){
-                    $('#legende{$cur_ref}').dialog('open');
-                        return false;
-                });
+                _addLegenButton('fieldset > p:nth-child(2)');
+                _handleLegend();
             });
         </script>
 {/block}
diff --git a/galette/templates/default/replacements_legend.tpl b/galette/templates/default/replacements_legend.tpl
new file mode 100644 (file)
index 0000000..f7448d9
--- /dev/null
@@ -0,0 +1,56 @@
+<div id="legende{$cur_ref}" class="texts_legend" title="{_T string="Existing variables"}">
+    <h1>{_T string="Existing variables"}</h1>
+    <table>
+    {foreach from=$legends item=legend}
+        <tr>
+            <th colspan="4">
+                {$legend.title}
+            </th>
+        </tr>
+        {foreach from=$legend.patterns item=pattern name=patternloop}
+            {if $smarty.foreach.patternloop.index % 2 == 0}
+                <tr>
+            {/if}
+            <th><tt>{$pattern.pattern|trim:'/'}</tt></th>
+            <td class="back">
+                {if isset($pattern.title)}{$pattern.title}{/if}
+            </td>
+            {if $smarty.foreach.patternloop.index % 2 != 0}
+                </tr>
+            {/if}
+        {/foreach}
+    {/foreach}
+    </table>
+</div>
+<script type="text/javascript">
+
+    var _addLegenButton = function(selector) {
+        $(selector).append('<a id="btnlegend" class="tab-button tooltip action" title="{_T string="Show existing variables"}"><i class="fas fa-info-circle fa-2x"></i> <span class="sr-only">{_T string="Show existing variables" escape="js"}</span></a>');
+    };
+
+    var _handleLegend = function(selector) {
+        if (typeof selector == 'undefined') {
+            selector = '{$cur_ref}';
+        }
+        $('#legende' + selector + ' h1').remove();
+        $('#legende' + selector).dialog({
+            autoOpen: false,
+            modal: true,
+            hide: 'fold',
+            width: '60em',
+            create: function (event, ui) {
+                if ($(window ).width() < 767) {
+                    $(this).dialog('option', {
+                        'width': '95%',
+                        'draggable': false
+                    });
+                }
+            }
+        }).dialog('close');
+
+        $('#btnlegend').unbind('click').click(function(){
+            $('#legende' + selector).dialog('open');
+            return false;
+        });
+    };
+</script>