Skip to content
Snippets Groups Projects
Commit 2c78a0dc authored by David Siegfried's avatar David Siegfried
Browse files

replace RoomClipboardWidget with SelectWidget, closes #236

Closes #236

Merge request studip/studip!911
parent 97d455a3
No related branches found
No related tags found
No related merge requests found
......@@ -144,27 +144,12 @@ class Resources_RoomGroupController extends AuthenticatedController
$clipboard->name . ': ' . _('Berechtigungen setzen')
);
$selected_clipboard_item_ids = $_SESSION['selected_clipboard_items'];
if ($selected_clipboard_item_ids) {
$this->room_ids = $clipboard->getSomeRangeIds(
'Room',
$selected_clipboard_item_ids
$this->room_ids = $clipboard->getAllRangeIds('Room');
if (!$this->room_ids) {
PageLayout::postInfo(
_('Die Raumgruppe enthält keine Räume!')
);
if (!$this->room_ids) {
PageLayout::postError(
_('Es wurden keine Räume ausgewählt!')
);
return;
}
} else {
$this->room_ids = $clipboard->getAllRangeIds('Room');
if (!$this->room_ids) {
PageLayout::postInfo(
_('Die Raumgruppe enthält keine Räume!')
);
return;
}
return;
}
$this->rooms = Room::findMany($this->room_ids);
......
......@@ -30,12 +30,11 @@ class RoomManagement_PlanningController extends AuthenticatedController
if (Navigation::hasItem('/resources/planning/index')) {
Navigation::activateItem('/resources/planning/index');
}
$selected_clipboard_id = Request::get('clipboard_id', $selected_clipboard_id);
if ($selected_clipboard_id) {
$_SESSION['selected_clipboard_id'] = $selected_clipboard_id;
$this->redirect(
$this->url_for('room_management/planning/index', $_GET)
);
} else {
$selected_clipboard_id = $_SESSION['selected_clipboard_id'];
}
$this->display_all_requests = Request::get('display_all_requests');
......@@ -80,22 +79,23 @@ class RoomManagement_PlanningController extends AuthenticatedController
$dpicker->addElement(new WidgetElement($picker_html));
$sidebar->addWidget($dpicker);
//Add clipboard widget:
$clipboard_widget = new RoomClipboardWidget();
$clipboard_widget->setApplyButtonTitle(
_('Anzeigen')
);
$sidebar->addWidget($clipboard_widget);
//Check if a clipboard is selected:
$selected_clipboard_id = $_SESSION['selected_clipboard_id'];
if (!$selected_clipboard_id) {
$clipboards = Clipboard::getClipboardsForUser($GLOBALS['user']->id);
if (!empty($clipboards)) {
$selected_clipboard_id = $clipboards[0]->id;
$clipboards = Clipboard::getClipboardsForUser($GLOBALS['user']->id);
if (!empty($clipboards)) {
$clipboard_widget = new SelectWidget(
_('Individuelle Raumgruppen'),
$this->indexURL(),
'clipboard_id',
'get'
);
foreach ($clipboards as $clipboard) {
$clipboard_widget->addElement(new SelectElement(
$clipboard->id,
$clipboard->name,
$clipboard->id === $selected_clipboard_id
), "clipboard_id-{$clipboard->id}");
}
$sidebar->addWidget($clipboard_widget);
}
$selected_clipboard_item_ids = $_SESSION['selected_clipboard_items'];
$rooms = [];
if ($selected_clipboard_id) {
......@@ -105,19 +105,7 @@ class RoomManagement_PlanningController extends AuthenticatedController
PageLayout::setTitle(
$clipboard->name . ': ' . _('Raumgruppen-Belegungsplan')
);
if ($selected_clipboard_item_ids) {
//The array of current clipboard item IDs is not empty.
//This means that at least one but not necessarily all
//clipboard items are selected.
$room_ids = $clipboard->getSomeRangeIds(
'Room',
$selected_clipboard_item_ids
);
} else {
//Use all items from the clipboard:
$room_ids = $clipboard->getAllRangeIds('Room');
}
$room_ids = $clipboard->getAllRangeIds('Room');
$rooms = Room::findMany($room_ids);
} else {
$this->no_clipboard = true;
......@@ -270,11 +258,11 @@ class RoomManagement_PlanningController extends AuthenticatedController
Navigation::activateItem('/resources/planning/semestergroup_plan');
}
$selected_clipboard_id = Request::get('clipboard_id', $selected_clipboard_id);
if ($selected_clipboard_id) {
$_SESSION['selected_clipboard_id'] = $selected_clipboard_id;
$this->redirect(
$this->url_for('room_management/planning/semester_plan', $_GET)
);
} else {
$selected_clipboard_id = $_SESSION['selected_clipboard_id'];
}
$this->display_all_requests = Request::get('display_all_requests');
......@@ -379,17 +367,26 @@ class RoomManagement_PlanningController extends AuthenticatedController
);
$sidebar->addWidget($semester_selector);
//Add clipboard widget:
$clipboard_widget = new RoomClipboardWidget();
$clipboard_widget->setApplyButtonTitle(
_('Anzeigen')
);
$sidebar->addWidget($clipboard_widget);
$clipboards = Clipboard::getClipboardsForUser($GLOBALS['user']->id);
if (!empty($clipboards)) {
$clipboard_widget = new SelectWidget(
_('Individuelle Raumgruppen'),
$this->semester_planURL(),
'clipboard_id',
'get'
);
foreach ($clipboards as $clipboard) {
$clipboard_widget->addElement(new SelectElement(
$clipboard->id,
$clipboard->name,
$clipboard->id === $selected_clipboard_id
), "clipboard_id-{$clipboard->id}");
}
$sidebar->addWidget($clipboard_widget);
}
//Check if a clipboard is selected:
$selected_clipboard_id = $_SESSION['selected_clipboard_id'];
$selected_clipboard_item_ids = $_SESSION['selected_clipboard_items'];
$rooms = [];
if ($selected_clipboard_id) {
$clipboard = Clipboard::find($selected_clipboard_id);
......@@ -398,19 +395,7 @@ class RoomManagement_PlanningController extends AuthenticatedController
PageLayout::setTitle(
$clipboard->name . ': ' . _('Raumgruppen-Semester-Belegungsplan')
);
if ($selected_clipboard_item_ids) {
//The array of current clipboard item IDs is not empty.
//This means that at least one but not necessarily all
//clipboard items are selected.
$room_ids = $clipboard->getSomeRangeIds(
'Room',
$selected_clipboard_item_ids
);
} else {
//Use all items from the clipboard:
$room_ids = $clipboard->getAllRangeIds('Room');
}
$room_ids = $clipboard->getAllRangeIds('Room');
$rooms = Room::findMany($room_ids);
} else {
$this->no_clipboard = true;
......@@ -555,7 +540,6 @@ class RoomManagement_PlanningController extends AuthenticatedController
//Check if the clipboard is selected:
$selected_clipboard_id = $_SESSION['selected_clipboard_id'];
$selected_clipboard_item_ids = $_SESSION['selected_clipboard_items'];
$user = User::findCurrent();
......@@ -602,9 +586,6 @@ class RoomManagement_PlanningController extends AuthenticatedController
}
$this->selected_room_ids = [];
if ($selected_clipboard_id == $this->clipboard->id) {
$this->selected_room_ids = $selected_clipboard_item_ids;
}
//Get all available semesters:
$this->available_semesters = Semester::getAll();
......@@ -1060,11 +1041,11 @@ class RoomManagement_PlanningController extends AuthenticatedController
Navigation::activateItem('/resources/planning/booking_comments');
}
$selected_clipboard_id = Request::get('clipboard_id', $selected_clipboard_id);
if ($selected_clipboard_id) {
$_SESSION['selected_clipboard_id'] = $selected_clipboard_id;
$this->redirect(
$this->url_for('room_management/planning/booking_comments', $_GET)
);
} else {
$selected_clipboard_id = $_SESSION['selected_clipboard_id'];
}
//Get the selected date or use the current date, if none specified:
......@@ -1099,20 +1080,23 @@ class RoomManagement_PlanningController extends AuthenticatedController
$sidebar->addWidget($date_search);
//Add clipboard widget:
$clipboard_widget = new RoomClipboardWidget();
$clipboard_widget->setApplyButtonTitle(
_('Anzeigen')
);
$sidebar->addWidget($clipboard_widget);
$selected_clipboard_id = $_SESSION['selected_clipboard_id'];
if (!$selected_clipboard_id) {
$clipboards = Clipboard::getClipboardsForUser($GLOBALS['user']->id);
if (!empty($clipboards)) {
$selected_clipboard_id = $clipboards[0]->id;
$clipboards = Clipboard::getClipboardsForUser($GLOBALS['user']->id);
if (!empty($clipboards)) {
$clipboard_widget = new SelectWidget(
_('Individuelle Raumgruppen'),
$this->booking_commentsURL(),
'clipboard_id',
'get'
);
foreach ($clipboards as $clipboard) {
$clipboard_widget->addElement(new SelectElement(
$clipboard->id,
$clipboard->name,
$clipboard->id === $selected_clipboard_id
), "clipboard_id-{$clipboard->id}");
}
$sidebar->addWidget($clipboard_widget);
}
$selected_clipboard_item_ids = $_SESSION['selected_clipboard_items'];
$this->current_user = User::findCurrent();
$this->room_ids = [];
......@@ -1123,26 +1107,12 @@ class RoomManagement_PlanningController extends AuthenticatedController
PageLayout::setTitle(
$clipboard->name . ': ' . _('Buchungen mit Kommentaren')
);
if ($selected_clipboard_item_ids) {
//The array of current clipboard item IDs is not empty.
//This means that at least one but not necessarily all
//clipboard items are retrieved, checked for user
//resource permissions and then added, if the user's
//permissions are high enough.
$room_ids = $clipboard->getSomeRangeIds(
'Room',
$selected_clipboard_item_ids
);
} else {
//Use all items from the clipboard:
$room_ids = $clipboard->getAllRangeIds('Room');
}
$room_ids = $clipboard->getAllRangeIds('Room');
$rooms = Resource::findMany($room_ids);
foreach ($rooms as $room) {
$room = $room->getDerivedClassInstance();
if ($room instanceof Room) {
if ($room->userHasPermission($this->current_user, 'user')) {
if ($room->userHasPermission($this->current_user)) {
$this->room_ids[] = $room->id;
}
}
......
......@@ -87,7 +87,6 @@ class RoomClipboard extends \RESTAPI\RouteMap
//Check if a clipboard is selected:
$selected_clipboard_id = $_SESSION['selected_clipboard_id'];
$selected_clipboard_item_ids = $_SESSION['selected_clipboard_items'];
$rooms = [];
if ($clipboard_id) {
......@@ -98,21 +97,7 @@ class RoomClipboard extends \RESTAPI\RouteMap
$this->halt(400, 'No clipboard selected!');
}
if ($clipboard) {
$room_ids = [];
if ($selected_clipboard_id && $selected_clipboard_item_ids) {
//The array of current clipboard item IDs is not empty.
//This means that at least one but not necessarily all
//clipboard items are selected.
$room_ids = $clipboard->getSomeRangeIds(
'Room',
$selected_clipboard_item_ids
);
} else {
//Use all items from the clipboard:
$room_ids = $clipboard->getAllRangeIds('Room');
}
$rooms = \Room::findMany($room_ids);
$rooms = \Room::findMany($clipboard->getAllRangeIds('Room'));
} else {
$this->halt(404, 'Clipboard not found!');
}
......@@ -200,7 +185,6 @@ class RoomClipboard extends \RESTAPI\RouteMap
//Check if a clipboard is selected:
$selected_clipboard_id = $_SESSION['selected_clipboard_id'];
$selected_clipboard_item_ids = $_SESSION['selected_clipboard_items'];
$rooms = [];
if ($clipboard_id) {
......@@ -211,21 +195,7 @@ class RoomClipboard extends \RESTAPI\RouteMap
$this->halt(400, 'No clipboard selected!');
}
if ($clipboard) {
$room_ids = [];
if ($selected_clipboard_id && $selected_clipboard_item_ids) {
//The array of current clipboard item IDs is not empty.
//This means that at least one but not necessarily all
//clipboard items are selected.
$room_ids = $clipboard->getSomeRangeIds(
'Room',
$selected_clipboard_item_ids
);
} else {
//Use all items from the clipboard:
$room_ids = $clipboard->getAllRangeIds('Room');
}
$rooms = \Room::findMany($room_ids);
$rooms = \Room::findMany($clipboard->getAllRangeIds('Room'));
} else {
$this->halt(404, 'Clipboard not found!');
}
......
......@@ -11,7 +11,6 @@
class ClipboardWidget extends SidebarWidget
{
protected $draggable_items;
protected $current_selected_items = [];
/**
* clipboard_widget_id is required in the case that multiple
......@@ -71,10 +70,6 @@ class ClipboardWidget extends SidebarWidget
$this->updateSessionVariables();
$this->current_clipboard_id = $_SESSION['selected_clipboard_id'];
if (is_array($_SESSION['selected_clipboard_items'])) {
$this->current_selected_items = $_SESSION['selected_clipboard_items'];
}
$this->setId("ClipboardWidget_{$this->clipboard_widget_id}");
$this->setAdditionalAttribute('data-widget_id', $this->clipboard_widget_id);
$this->addLayoutCSSClass('clipboard-widget');
......@@ -88,12 +83,7 @@ class ClipboardWidget extends SidebarWidget
if (Request::submitted('clipboard_update_session_special_action')) {
CSRFProtection::verifyUnsafeRequest();
$_SESSION['selected_clipboard_id'] = Request::get(
'selected_clipboard_id'
);
$_SESSION['selected_clipboard_items'] = Request::getArray(
'selected_clipboard_items'
);
$_SESSION['selected_clipboard_id'] = Request::get('selected_clipboard_id');
}
}
......@@ -117,7 +107,6 @@ class ClipboardWidget extends SidebarWidget
if (!$this->current_clipboard_id && $clipboards) {
$_SESSION['selected_clipboard_id'] = $clipboards[0]->id;
$_SESSION['selected_clipboard_items'] = [];
$this->current_clipboard_id = $clipboards[0]->id;
}
......@@ -129,7 +118,6 @@ class ClipboardWidget extends SidebarWidget
'apply_button_title' => $this->apply_button_title,
'elements' => $this->elements,
'selected_clipboard_id' => $this->current_clipboard_id,
'selected_clipboard_items' => $this->current_selected_items,
]);
}
......
......@@ -884,7 +884,7 @@ STUDIP.domReady(function() {
'.room-clipboard-group-action',
function (event) {
//Get the IDs of the rooms of the clipboard:
var active_clipboard = jQuery(event.target).parents("#clipboard-group-container").find(
let active_clipboard = jQuery(event.target).parents("#clipboard-group-container").find(
'.clipboard-area:not(.invisible)'
)[0];
if (!active_clipboard) {
......@@ -892,41 +892,12 @@ STUDIP.domReady(function() {
return;
}
var clipboard_id = jQuery(active_clipboard).data('id');
var action_needs_items = jQuery(event.target).data('needs_items');
var show_in_dialog = jQuery(event.target).data('show_in_dialog');
var ids = [];
if (action_needs_items) {
var items = jQuery(active_clipboard).find(
'tr.clipboard-item:not(.clipboard-item-template)'
);
for (var item of items) {
var input = jQuery(item).find("input[name='selected_clipboard_items[]']:checked")[0];
if (input) {
var id = jQuery(item).data('range_id');
//Check if id is an md5 sum:
if (id.match(/[0-9a-f]{32}/)) {
ids.push(id);
}
}
}
if (ids.length == items.length) {
//All items are selected. No need to use the Range-IDs, we
//can use the clipboard-ID instead.
action_needs_items = false;
}
}
var url_path = jQuery(event.target).attr('href');
let clipboard_id = jQuery(active_clipboard).data('id');
let show_in_dialog = jQuery(event.target).data('show_in_dialog');
let url_path = jQuery(event.target).attr('href');
url_path = url_path.replace(/CLIPBOARD_ID/, clipboard_id);
var complete_url = STUDIP.URLHelper.getURL(
url_path,
(
action_needs_items ? {'resource_ids': ids} : null
)
);
let complete_url = STUDIP.URLHelper.getURL(url_path);
if (show_in_dialog) {
//If we have collected at least one ID we can create a dialog
......@@ -934,7 +905,7 @@ STUDIP.domReady(function() {
STUDIP.Dialog.fromURL(
complete_url,
{
size: 'normal'
size: 'auto'
}
);
} else {
......
......@@ -301,8 +301,9 @@ const Clipboard = {
jQuery(new_item_node).removeClass('clipboard-item-template');
jQuery(new_item_node).removeClass('invisible');
let name_label = jQuery(new_item_node).find('label');
jQuery('<span/>').text(response_data['name']).appendTo(name_label)
let name_column = jQuery(new_item_node).find('td.item-name');
console.log(name_column);
jQuery('<span/>').text(response_data['name']).appendTo(name_column)
let id_field = jQuery(new_item_node).find("input[name='selected_clipboard_items[]']");
jQuery(id_field).val(checkbox_id);
......
......@@ -79,21 +79,7 @@
? 'draggable'
: '' ?>"
data-range_id="<?= htmlReady($item['range_id']) ?>">
<td>
<label>
<input type="checkbox"
name="selected_clipboard_items[]"
title="<?= sprintf(_('%s auswählen.'), htmlReady($item['name'])) ?>"
value="<?= htmlReady($item['id']) ?>"
<?= in_array($item['id'], $selected_clipboard_items)
? 'checked="checked"'
: (!$selected_clipboard_items
? 'checked="checked"'
: '') ?>
>
<?= htmlReady($item['name']) ?>
</label>
</td>
<td class="item-name"><?= htmlReady($item['name']) ?></td>
<td class="actions">
<?= Icon::create('trash')->asInput(
[
......@@ -126,12 +112,7 @@
: ''
?> clipboard-item-template invisible"
data-range_id="">
<td class="item-name">
<input type="checkbox"
name="selected_clipboard_items[]"
value=""
class="item-id">
</td>
<td class="item-name"></td>
<td class="item-actions">
<?= Icon::create('trash')->asInput(
[
......@@ -169,13 +150,7 @@
: ''
?> clipboard-item-template invisible"
data-range_id="">
<td>
<input type="checkbox"
name="selected_clipboard_items[]"
title="<?= _('Diesen Eintrag auswählen.') ?>"
value="">
<label></label>
</td>
<td class="item-name"></td>
<td>
<?= Icon::create('trash')->asInput(
[
......
......@@ -30,26 +30,11 @@ if (!$item) {
?>
<tr class="<?= htmlReady($classes) ?>"
data-range_id="<?= htmlReady($item['range_id']) ?>">
<td>
<label>
<input type="checkbox"
name="selected_clipboard_items[]"
title="<?= _('Diesen Raum auswählen.') ?>"
value="<?= htmlReady($item['id']) ?>"
<?= in_array($item['id'], $selected_clipboard_items)
? 'checked="checked"'
: (!$selected_clipboard_items
? 'checked="checked"'
: ''
) ?>
>
<?= htmlReady($item['name']) ?>
</label>
</td>
<td class="item-name"><?= htmlReady($item['name']) ?></td>
<td class="actions">
<a href="<?= Room::getLinkForAction('show', ($item ? $item['range_id'] : 'RANGE_ID')) ?>" data-dialog>
<?= Icon::create(
'info',
'info-circle',
Icon::ROLE_CLICKABLE,
[
'title' => _('Rauminformationen'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment