diff --git a/assets/Flexexport.js b/assets/Flexexport.js index fa123d895fba7ae9fda37f17f9de1e88027801e5..ca1cd414bb7a2fec01bf578fbf24844033f3f69f 100644 --- a/assets/Flexexport.js +++ b/assets/Flexexport.js @@ -18,20 +18,40 @@ STUDIP.Flexexport = { }); }, - - selectItem: function(item_id, item_name) { - var list_selector = jQuery(this).attr('data-item-list'); - if (list_selector.length < 1) { - return; - } - var fieldset = jQuery(this).parents('fieldset.flexexport-config-part')[0]; + selectItemFromSelect: function(event) { + let item_id = jQuery(event.target).val(); + let item_name = jQuery(event.target).find('option:selected').text(); + let list_id = jQuery(event.target).attr('data-item-list'); + let fieldset = jQuery(event.target).parents('fieldset.flexexport-config-part')[0]; if (!fieldset) { return; } - var list = jQuery(fieldset).find(list_selector)[0]; - if (!list) { - return; + let list_element = jQuery(fieldset).find(list_id)[0]; + STUDIP.Flexexport.selectItem(item_id, item_name, list_element); + }, + + selectItem: function(item_id, item_name, list) { + if (!list || list.length == 0) { + var list_selector = jQuery(this).attr('data-item-list'); + if (list_selector.length < 1) { + return; + } + var fieldset = jQuery(this).parents('fieldset.flexexport-config-part')[0]; + if (!fieldset) { + return; + } + var list = jQuery(fieldset).find(list_selector)[0]; + if (!list) { + return; + } } + //Check if the item exists: + /* + let existing_items = jQuery(list).find('li[data-item_id="' + item_id + '"'); + if (existing_items.length > 0) { + return; + }*/ + var input_name = jQuery(list).attr('data-input-name'); if (!input_name) { return; @@ -43,6 +63,7 @@ STUDIP.Flexexport = { } var new_item = jQuery(template).clone(true); + jQuery(new_item).attr('data-item_id', item_id); var new_item_input = jQuery(new_item).find('input[type="hidden"]')[0]; if (!new_item_input) { return; @@ -196,6 +217,9 @@ STUDIP.Flexexport = { } ); + jQuery(document).off('change', '.flexexport-item-selector'); + jQuery(document).on('change', '.flexexport-item-selector', STUDIP.Flexexport.selectItemFromSelect); + jQuery(document).on('click', '#Flexexport-csv-add-field', function(event) { event.preventDefault(); let template = jQuery(event.target).siblings('.csv-static-field.template'); diff --git a/classes/exporters/CourseDateAndRoomBookingExporter.class.php b/classes/exporters/CourseDateAndRoomBookingExporter.class.php index f2e5e88c9146d81eafbec7e6c9866c36470fbe52..1937bf0300c84c5d7fe3a69ba1c37b0040a02792 100644 --- a/classes/exporters/CourseDateAndRoomBookingExporter.class.php +++ b/classes/exporters/CourseDateAndRoomBookingExporter.class.php @@ -58,39 +58,19 @@ class CourseDateAndRoomBookingExporter extends Exporter $template->set_attribute('config_prefix', $config_prefix); - $institute_search = new \QuickSearch('selected_institute_id', new \StandardSearch('Institut_id')); - $institute_search->fireJSFunctionOnSelect('STUDIP.Flexexport.selectItem'); - $institute_search->setAttributes( - [ - 'data-item-list' => 'ul.institute_ids' - ] - ); - $template->set_attribute('institute_search', $institute_search); + $template->set_attribute('institutes', \Institute::getInstitutes()); $template->set_attribute('time_range', $this->config->getParameter('time_range')); $template->set_attribute('hide_past_events', $this->config->getParameter('hide_past_events')); $template->set_attribute('hide_exdates_without_comment', $this->config->getParameter('hide_exdates_without_comment')); - $building_search = new \QuickSearch( - 'selected_building_id', - new \SQLSearch( - "SELECT resources.id, resources.name - FROM resources - INNER JOIN resource_categories rc - ON resources.category_id = rc.id - WHERE - rc.class_name = 'Building' - AND - resources.name LIKE :input - ORDER BY resources.name" - ) - ); - $building_search->fireJSFunctionOnSelect('STUDIP.Flexexport.selectItem'); - $building_search->setAttributes( - [ - 'data-item-list' => 'ul.building_ids' - ] + $buildings = \Building::findBySQL( + "INNER JOIN resource_categories rc + ON resources.category_id = rc.id + WHERE + rc.class_name = 'Building' + ORDER BY resources.name" ); - $template->set_attribute('building_search', $building_search); + $template->set_attribute('buildings', $buildings); $selected_buildings = []; if ($this->config->getParameter('building_ids')) { diff --git a/classes/exporters/CourseDateExporter.class.php b/classes/exporters/CourseDateExporter.class.php index efeb7404c10da4705356497a1d624271ec5e9925..78df870c212aef8d863f50296e67929c84a6921f 100644 --- a/classes/exporters/CourseDateExporter.class.php +++ b/classes/exporters/CourseDateExporter.class.php @@ -67,14 +67,7 @@ class CourseDateExporter extends Exporter $template->set_attribute('hide_past_events', $this->config->getParameter('hide_past_events')); $template->set_attribute('hide_exdates_without_comment', $this->config->getParameter('hide_exdates_without_comment')); - $institute_search = new \QuickSearch('selected_institute_id', new \StandardSearch('Institut_id')); - $institute_search->fireJSFunctionOnSelect('STUDIP.Flexexport.selectItem'); - $institute_search->setAttributes( - [ - 'data-item-list' => 'ul.institute_ids' - ] - ); - $template->set_attribute('institute_search', $institute_search); + $template->set_attribute('institutes', \Institute::getInstitutes()); $selected_institutes = []; if ($this->config->getParameter('institute_ids')) { diff --git a/plugin.manifest b/plugin.manifest index e4ab11450977cf24d77f8a17b09ffba26a3edfc3..23177c9421dd1259cc2445687a38c2b32ca6cc3a 100644 --- a/plugin.manifest +++ b/plugin.manifest @@ -1,7 +1,7 @@ pluginname=Flexexport pluginclassname=Flexexport origin=data-quest -version=0.7.4 +version=0.7.5 studipMinVersion=4.5 studipMaxVersion=5.2.99 description=Das Flexexport-Plugin erlaubt den Export von Stud.IP-Inhalten in verschiedenen Formaten. diff --git a/templates/exporters/course_date_and_room_booking_exporter.php b/templates/exporters/course_date_and_room_booking_exporter.php index 005cf0bfe9daaa26fdc685231f7bc4f7a3c9a292..70be3159dfdc98c3e2d592d408ee795f99472b70 100644 --- a/templates/exporters/course_date_and_room_booking_exporter.php +++ b/templates/exporters/course_date_and_room_booking_exporter.php @@ -45,7 +45,15 @@ </label> <label> <?= dgettext('Flexexport', 'Beschränkung auf Einrichtungen') ?> - <?= $institute_search->render() ?> + <select name="selected_institute_id" class="flexexport-item-selector" + data-item-list="ul.institute_ids"> + <option value=""><?= dgettext('Flexexport', 'Bitte wählen') ?></option> + <? foreach ($institutes as $institute) : ?> + <option value="<?= htmlReady($institute['Institut_id']) ?>"> + <?= htmlReady($institute['Name']) ?> + </option> + <? endforeach ?> + </select> <ul class="default institute_ids selected-items <?= !$selected_institutes ? 'invisible' : '' ?>" data-input-name="<?= htmlReady($config_prefix ?: 'CONFIG_PREFIX') ?>[institute_ids][]"> <? foreach ($selected_institutes as $institute) : ?> @@ -65,7 +73,15 @@ </label> <label> <?= dgettext('Flexexport', 'Beschränkung auf Gebäude') ?> - <?= $building_search->render() ?> + <select name="selected_building_id" class="flexexport-item-selector" + data-item-list="ul.building_ids"> + <option value=""><?= dgettext('Flexexport', 'Bitte wählen') ?></option> + <? foreach ($buildings as $building) : ?> + <option value="<?= htmlReady($building->id) ?>"> + <?= htmlReady($building->name) ?> + </option> + <? endforeach ?> + </select> <ul class="default building_ids selected-items <?= !$selected_buildings ? 'invisible' : '' ?>" data-input-name="<?= htmlReady($config_prefix ?: 'CONFIG_PREFIX') ?>[building_ids][]"> <? foreach ($selected_buildings as $building) : ?> diff --git a/templates/exporters/course_date_exporter.php b/templates/exporters/course_date_exporter.php index f66a623a30c770c54b2a67e024a538f3f707fca2..89cd108b43c6a32111ad5d0099f4c0993e1ab11e 100644 --- a/templates/exporters/course_date_exporter.php +++ b/templates/exporters/course_date_exporter.php @@ -45,11 +45,19 @@ </label> <label> <?= dgettext('Flexexport', 'Beschränkung auf Einrichtungen') ?> - <?= $institute_search->render() ?> + <select name="selected_institute_id" class="flexexport-item-selector" + data-item-list="ul.institute_ids"> + <option value=""><?= dgettext('Flexexport', 'Bitte wählen') ?></option> + <? foreach ($institutes as $institute) : ?> + <option value="<?= htmlReady($institute['Institut_id']) ?>"> + <?= htmlReady($institute['Name']) ?> + </option> + <? endforeach ?> + </select> <ul class="default institute_ids selected-items <?= !$selected_institutes ? 'invisible' : '' ?>" data-input-name="<?= htmlReady($config_prefix ?: 'CONFIG_PREFIX') ?>[institute_ids][]"> <? foreach ($selected_institutes as $institute) : ?> - <li> + <li data-item_id="<?= htmlReady($institute->id) ?>"> <input type="hidden" name="<?= htmlReady($config_prefix ?: 'CONFIG_PREFIX') ?>[institute_ids][]" value="<?= htmlReady($institute->id) ?>"> <?= htmlReady($institute->name) ?>