xref: /webtrees/resources/views/edit-blocks-page.phtml (revision dd6b2bfcc550270bb6d6778e11576148f71e4330)
1*dd6b2bfcSGreg Roach<?php use Fisharebest\Webtrees\FontAwesome; ?>
2*dd6b2bfcSGreg Roach<?php use Fisharebest\Webtrees\I18N; ?>
3*dd6b2bfcSGreg Roach
4*dd6b2bfcSGreg Roach<script>
5*dd6b2bfcSGreg Roach  /**
6*dd6b2bfcSGreg Roach   * This function moves the selected option up in the given select list
7*dd6b2bfcSGreg Roach   *
8*dd6b2bfcSGreg Roach   * @param section_name the name of the select to move the options
9*dd6b2bfcSGreg Roach   */
10*dd6b2bfcSGreg Roach  function move_up_block(section_name) {
11*dd6b2bfcSGreg Roach    var section_select = document.getElementById(section_name);
12*dd6b2bfcSGreg Roach    if (section_select) {
13*dd6b2bfcSGreg Roach      if (section_select.selectedIndex <= 0) {
14*dd6b2bfcSGreg Roach        return false;
15*dd6b2bfcSGreg Roach      }
16*dd6b2bfcSGreg Roach      var index = section_select.selectedIndex;
17*dd6b2bfcSGreg Roach      var temp = new Option(section_select.options[index-1].text, section_select.options[index-1].value);
18*dd6b2bfcSGreg Roach      section_select.options[index-1] = new Option(section_select.options[index].text, section_select.options[index].value);
19*dd6b2bfcSGreg Roach      section_select.options[index] = temp;
20*dd6b2bfcSGreg Roach      section_select.selectedIndex = index-1;
21*dd6b2bfcSGreg Roach    }
22*dd6b2bfcSGreg Roach
23*dd6b2bfcSGreg Roach    return false;
24*dd6b2bfcSGreg Roach  }
25*dd6b2bfcSGreg Roach
26*dd6b2bfcSGreg Roach  /**
27*dd6b2bfcSGreg Roach   * This function moves the selected option down in the given select list
28*dd6b2bfcSGreg Roach   *
29*dd6b2bfcSGreg Roach   * @param section_name the name of the select to move the options
30*dd6b2bfcSGreg Roach   */
31*dd6b2bfcSGreg Roach  function move_down_block(section_name) {
32*dd6b2bfcSGreg Roach    var section_select = document.getElementById(section_name);
33*dd6b2bfcSGreg Roach    if (section_select) {
34*dd6b2bfcSGreg Roach      if (section_select.selectedIndex < 0) {
35*dd6b2bfcSGreg Roach        return false;
36*dd6b2bfcSGreg Roach      }
37*dd6b2bfcSGreg Roach      if (section_select.selectedIndex >= section_select.length - 1) {
38*dd6b2bfcSGreg Roach        return false;
39*dd6b2bfcSGreg Roach      }
40*dd6b2bfcSGreg Roach      var index = section_select.selectedIndex;
41*dd6b2bfcSGreg Roach      var temp = new Option(section_select.options[index + 1].text, section_select.options[index + 1].value);
42*dd6b2bfcSGreg Roach      section_select.options[index + 1] = new Option(section_select.options[index].text, section_select.options[index].value);
43*dd6b2bfcSGreg Roach      section_select.options[index] = temp;
44*dd6b2bfcSGreg Roach      section_select.selectedIndex = index + 1;
45*dd6b2bfcSGreg Roach    }
46*dd6b2bfcSGreg Roach
47*dd6b2bfcSGreg Roach    return false;
48*dd6b2bfcSGreg Roach  }
49*dd6b2bfcSGreg Roach
50*dd6b2bfcSGreg Roach  /**
51*dd6b2bfcSGreg Roach   * This function moves the selected option down in the given select list
52*dd6b2bfcSGreg Roach   *
53*dd6b2bfcSGreg Roach   * @param from_column the name of the select to move the option from
54*dd6b2bfcSGreg Roach   * @param to_column the name of the select to remove the option to
55*dd6b2bfcSGreg Roach   */
56*dd6b2bfcSGreg Roach  function move_left_right_block(from_column, to_column) {
57*dd6b2bfcSGreg Roach    var to_select = document.getElementById(to_column);
58*dd6b2bfcSGreg Roach    var from_select = document.getElementById(from_column);
59*dd6b2bfcSGreg Roach    if ((to_select) && (from_select)) {
60*dd6b2bfcSGreg Roach      var add_option = from_select.options[from_select.selectedIndex];
61*dd6b2bfcSGreg Roach      if (to_column !== "available_select") {
62*dd6b2bfcSGreg Roach        to_select.options[to_select.length] = new Option(add_option.text, add_option.value);
63*dd6b2bfcSGreg Roach      }
64*dd6b2bfcSGreg Roach      if (from_column !== "available_select") {
65*dd6b2bfcSGreg Roach        from_select.options[from_select.selectedIndex] = null; //remove from list
66*dd6b2bfcSGreg Roach      }
67*dd6b2bfcSGreg Roach    }
68*dd6b2bfcSGreg Roach
69*dd6b2bfcSGreg Roach    return false;
70*dd6b2bfcSGreg Roach  }
71*dd6b2bfcSGreg Roach  /**
72*dd6b2bfcSGreg Roach   * Select Options Javascript function
73*dd6b2bfcSGreg Roach   *
74*dd6b2bfcSGreg Roach   * This function selects all the options in the multiple select lists
75*dd6b2bfcSGreg Roach   */
76*dd6b2bfcSGreg Roach  function select_options() {
77*dd6b2bfcSGreg Roach    var section_select = document.getElementById("main_select");
78*dd6b2bfcSGreg Roach    var i;
79*dd6b2bfcSGreg Roach    if (section_select) {
80*dd6b2bfcSGreg Roach      for (i = 0; i < section_select.length; i++) {
81*dd6b2bfcSGreg Roach        section_select.options[i].selected=true;
82*dd6b2bfcSGreg Roach      }
83*dd6b2bfcSGreg Roach    }
84*dd6b2bfcSGreg Roach    section_select = document.getElementById("side_select");
85*dd6b2bfcSGreg Roach    if (section_select) {
86*dd6b2bfcSGreg Roach      for (i = 0; i < section_select.length; i++) {
87*dd6b2bfcSGreg Roach        section_select.options[i].selected=true;
88*dd6b2bfcSGreg Roach      }
89*dd6b2bfcSGreg Roach    }
90*dd6b2bfcSGreg Roach    return true;
91*dd6b2bfcSGreg Roach  }
92*dd6b2bfcSGreg Roach
93*dd6b2bfcSGreg Roach  /**
94*dd6b2bfcSGreg Roach   * Show Block Description Javascript function
95*dd6b2bfcSGreg Roach   *
96*dd6b2bfcSGreg Roach   * This function shows a description for the selected option
97*dd6b2bfcSGreg Roach   *
98*dd6b2bfcSGreg Roach   * @param list_name the name of the select to get the option from
99*dd6b2bfcSGreg Roach   */
100*dd6b2bfcSGreg Roach  function show_description(list_name) {
101*dd6b2bfcSGreg Roach    var list_select = document.getElementById(list_name);
102*dd6b2bfcSGreg Roach    var instruct = document.getElementById("instructions");
103*dd6b2bfcSGreg Roach    if (block_descr[list_select.options[list_select.selectedIndex].value] && instruct) {
104*dd6b2bfcSGreg Roach      instruct.innerHTML = block_descr[list_select.options[list_select.selectedIndex].value];
105*dd6b2bfcSGreg Roach    } else {
106*dd6b2bfcSGreg Roach      instruct.innerHTML = block_descr["advice1"];
107*dd6b2bfcSGreg Roach    }
108*dd6b2bfcSGreg Roach    if (list_name === "main_select") {
109*dd6b2bfcSGreg Roach      document.getElementById("available_select").selectedIndex = -1;
110*dd6b2bfcSGreg Roach      document.getElementById("side_select").selectedIndex = -1;
111*dd6b2bfcSGreg Roach    }
112*dd6b2bfcSGreg Roach    if (list_name === "available_select") {
113*dd6b2bfcSGreg Roach      document.getElementById("main_select").selectedIndex = -1;
114*dd6b2bfcSGreg Roach      document.getElementById("side_select").selectedIndex = -1;
115*dd6b2bfcSGreg Roach    }
116*dd6b2bfcSGreg Roach    if (list_name === "side_select") {
117*dd6b2bfcSGreg Roach      document.getElementById("main_select").selectedIndex = -1;
118*dd6b2bfcSGreg Roach      document.getElementById("available_select").selectedIndex = -1;
119*dd6b2bfcSGreg Roach    }
120*dd6b2bfcSGreg Roach  }
121*dd6b2bfcSGreg Roach  var block_descr = { advice1: "&nbsp;"};
122*dd6b2bfcSGreg Roach    <?php foreach ($all_blocks as $block_name => $block) : ?>
123*dd6b2bfcSGreg Roach  block_descr[<?= json_encode($block_name) ?>] = <?= json_encode($block->getDescription()) ?>;
124*dd6b2bfcSGreg Roach    <?php endforeach ?>
125*dd6b2bfcSGreg Roach</script>
126*dd6b2bfcSGreg Roach
127*dd6b2bfcSGreg Roach<h2><?= $title ?></h2>
128*dd6b2bfcSGreg Roach
129*dd6b2bfcSGreg Roach<p>
130*dd6b2bfcSGreg Roach    <?= I18N::translate('Select a block and use the arrows to move it.') ?>
131*dd6b2bfcSGreg Roach</p>
132*dd6b2bfcSGreg Roach
133*dd6b2bfcSGreg Roach<form name="config_setup" method="post" action="<?= e($url_save) ?>" onsubmit="select_options();" >
134*dd6b2bfcSGreg Roach    <?= csrf_field() ?>
135*dd6b2bfcSGreg Roach    <table border="1" id="change_blocks">
136*dd6b2bfcSGreg Roach        <thead>
137*dd6b2bfcSGreg Roach            <tr>
138*dd6b2bfcSGreg Roach                <th class="descriptionbox center vmiddle" colspan="2">
139*dd6b2bfcSGreg Roach                    <label for="main_select">
140*dd6b2bfcSGreg Roach                        <?= I18N::translate('Main section blocks') ?>
141*dd6b2bfcSGreg Roach                    </label>
142*dd6b2bfcSGreg Roach                </th>
143*dd6b2bfcSGreg Roach                <th class="descriptionbox center vmiddle" colspan="3">
144*dd6b2bfcSGreg Roach                    <label for="available_select">
145*dd6b2bfcSGreg Roach                        <?= I18N::translate('Available blocks') ?>
146*dd6b2bfcSGreg Roach                    </label>
147*dd6b2bfcSGreg Roach                </th>
148*dd6b2bfcSGreg Roach                <th class="descriptionbox center vmiddle" colspan="2">
149*dd6b2bfcSGreg Roach                    <label for="side_select">
150*dd6b2bfcSGreg Roach                        <?= I18N::translate('Right section blocks') ?>
151*dd6b2bfcSGreg Roach                    </label>
152*dd6b2bfcSGreg Roach                </th>
153*dd6b2bfcSGreg Roach            </tr>
154*dd6b2bfcSGreg Roach        </thead>
155*dd6b2bfcSGreg Roach        <tbody>
156*dd6b2bfcSGreg Roach            <tr>
157*dd6b2bfcSGreg Roach                <td class="optionbox center vmiddle">
158*dd6b2bfcSGreg Roach                    <?= FontAwesome::linkIcon('arrow-up', I18N::translate('Move up'), ['class' => 'btn btn-link', 'href' => '#', 'onclick' => 'return move_up_block("main_select");']) ?>
159*dd6b2bfcSGreg Roach                    <br>
160*dd6b2bfcSGreg Roach                    <?= FontAwesome::linkIcon('arrow-end', I18N::translate('Move right'), ['class' => 'btn btn-link', 'href' => '#', 'onclick' => 'return move_left_right_block("main_select", "side_select");']) ?>
161*dd6b2bfcSGreg Roach                    <br>
162*dd6b2bfcSGreg Roach                    <?= FontAwesome::linkIcon('delete', I18N::translate('Remove'), ['class' => 'btn btn-link', 'href' => '#', 'onclick' => 'return move_left_right_block("main_select", "available_select");']) ?>
163*dd6b2bfcSGreg Roach                    <br>
164*dd6b2bfcSGreg Roach                    <?= FontAwesome::linkIcon('arrow-down', I18N::translate('Move down'), ['class' => 'btn btn-link', 'href' => '#', 'onclick' => 'return move_down_block("main_select");']) ?>
165*dd6b2bfcSGreg Roach                </td>
166*dd6b2bfcSGreg Roach                <td class="optionbox center">
167*dd6b2bfcSGreg Roach                    <select multiple="multiple" id="main_select" name="main[]" size="10" onchange="show_description('main_select');">
168*dd6b2bfcSGreg Roach                        <?php foreach ($main_blocks as $block_id => $block) : ?>
169*dd6b2bfcSGreg Roach                            <option value="<?= $block_id ?>">
170*dd6b2bfcSGreg Roach                                <?= $all_blocks[$block->getName()]->getTitle() ?>
171*dd6b2bfcSGreg Roach                            </option>
172*dd6b2bfcSGreg Roach                        <?php endforeach ?>
173*dd6b2bfcSGreg Roach                    </select>
174*dd6b2bfcSGreg Roach                </td>
175*dd6b2bfcSGreg Roach                <td class="optionbox center vmiddle">
176*dd6b2bfcSGreg Roach                    <?= FontAwesome::linkIcon('arrow-start', I18N::translate('Add'), ['class' => 'btn btn-link', 'href' => '#', 'onclick' => 'return move_left_right_block("available_select", "main_select");']) ?>
177*dd6b2bfcSGreg Roach                </td>
178*dd6b2bfcSGreg Roach                <td class="optionbox center">
179*dd6b2bfcSGreg Roach                    <select multiple id="available_select" size="10" onchange="show_description('available_select');">
180*dd6b2bfcSGreg Roach                        <?php foreach ($all_blocks as $block_name => $block) : ?>
181*dd6b2bfcSGreg Roach                            <option value="<?= $block_name ?>">
182*dd6b2bfcSGreg Roach                                <?= $block->getTitle() ?>
183*dd6b2bfcSGreg Roach                            </option>
184*dd6b2bfcSGreg Roach                        <?php endforeach ?>
185*dd6b2bfcSGreg Roach                    </select>
186*dd6b2bfcSGreg Roach                </td>
187*dd6b2bfcSGreg Roach                <td class="optionbox center vmiddle">
188*dd6b2bfcSGreg Roach                    <?= FontAwesome::linkIcon('arrow-end', I18N::translate('Add'), ['class' => 'btn btn-link', 'href' => '#', 'onclick' => 'return move_left_right_block("available_select", "side_select");']) ?>
189*dd6b2bfcSGreg Roach                </td>
190*dd6b2bfcSGreg Roach                <td class="optionbox center">
191*dd6b2bfcSGreg Roach                    <select multiple="multiple" id="side_select" name="side[]" size="10" onchange="show_description('side_select');">
192*dd6b2bfcSGreg Roach                        <?php foreach ($side_blocks as $block_id => $block) : ?>
193*dd6b2bfcSGreg Roach                            <option value="<?= $block_id ?>">
194*dd6b2bfcSGreg Roach                                <?= $all_blocks[$block->getName()]->getTitle() ?>
195*dd6b2bfcSGreg Roach                            </option>
196*dd6b2bfcSGreg Roach                        <?php endforeach ?>
197*dd6b2bfcSGreg Roach                    </select>
198*dd6b2bfcSGreg Roach                </td>
199*dd6b2bfcSGreg Roach                <td class="optionbox center vmiddle">
200*dd6b2bfcSGreg Roach                    <?= FontAwesome::linkIcon('arrow-up', I18N::translate('Move up'), ['class' => 'btn btn-link', 'href' => '#', 'onclick' => 'return move_up_block("side_select");']) ?>
201*dd6b2bfcSGreg Roach                    <br>
202*dd6b2bfcSGreg Roach                    <?= FontAwesome::linkIcon('arrow-start', I18N::translate('Move left'), ['class' => 'btn btn-link', 'href' => '#', 'onclick' => 'return move_left_right_block("side_select", "main_select");']) ?>
203*dd6b2bfcSGreg Roach                    <br>
204*dd6b2bfcSGreg Roach                    <?= FontAwesome::linkIcon('delete', I18N::translate('Remove'), ['class' => 'btn btn-link', 'href' => '#', 'onclick' => 'return move_left_right_block("side_select", "available_select");']) ?>
205*dd6b2bfcSGreg Roach                    <br>
206*dd6b2bfcSGreg Roach                    <?= FontAwesome::linkIcon('arrow-down', I18N::translate('Move down'), ['class' => 'btn btn-link', 'href' => '#', 'onclick' => 'return move_down_block("side_select");']) ?>
207*dd6b2bfcSGreg Roach                </td>
208*dd6b2bfcSGreg Roach            </tr>
209*dd6b2bfcSGreg Roach        </tbody>
210*dd6b2bfcSGreg Roach        <tfoot>
211*dd6b2bfcSGreg Roach            <tr>
212*dd6b2bfcSGreg Roach                <td class="descriptionbox wrap" colspan="7">
213*dd6b2bfcSGreg Roach                    <div id="instructions">
214*dd6b2bfcSGreg Roach                        &nbsp;
215*dd6b2bfcSGreg Roach                    </div>
216*dd6b2bfcSGreg Roach                </td>
217*dd6b2bfcSGreg Roach            </tr>
218*dd6b2bfcSGreg Roach            <tr>
219*dd6b2bfcSGreg Roach                <td class="topbottombar" colspan="4">
220*dd6b2bfcSGreg Roach                    <?php if ($can_reset) : ?>
221*dd6b2bfcSGreg Roach                        <label>
222*dd6b2bfcSGreg Roach                            <input type="checkbox" name="default">
223*dd6b2bfcSGreg Roach                            <?= I18N::translate('Restore the default block layout') ?>
224*dd6b2bfcSGreg Roach                        </label>
225*dd6b2bfcSGreg Roach                    <?php endif ?>
226*dd6b2bfcSGreg Roach                </td>
227*dd6b2bfcSGreg Roach                <td class="topbottombar" colspan="3">
228*dd6b2bfcSGreg Roach                    <button type="submit" class="btn btn-primary">
229*dd6b2bfcSGreg Roach                        <?= FontAwesome::decorativeIcon('save') ?>
230*dd6b2bfcSGreg Roach                        <?= I18N::translate('save') ?>
231*dd6b2bfcSGreg Roach                    </button>
232*dd6b2bfcSGreg Roach                    <a class="btn btn-secondary" href="<?= e($url_cancel) ?>">
233*dd6b2bfcSGreg Roach                        <?= FontAwesome::decorativeIcon('cancel') ?>
234*dd6b2bfcSGreg Roach                        <?= I18N::translate('cancel') ?>
235*dd6b2bfcSGreg Roach                    </a>
236*dd6b2bfcSGreg Roach                </td>
237*dd6b2bfcSGreg Roach            </tr>
238*dd6b2bfcSGreg Roach        </tfoot>
239*dd6b2bfcSGreg Roach    </table>
240*dd6b2bfcSGreg Roach</form>
241*dd6b2bfcSGreg Roach
242