Skip to content
Snippets Groups Projects
Commit d951db97 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by Jan-Hendrik Willms
Browse files

correctly render clipboard widgets

Closes #1102

Merge request studip/studip!654
parent 65865c7f
No related branches found
No related tags found
No related merge requests found
......@@ -65,7 +65,7 @@ class ClipboardWidget extends SidebarWidget
$this->allowed_item_classes = $allowed_item_classes;
$this->template = 'sidebar/clipboard-widget';
$this->title = _('Merkzettel');
$this->title = _('Eigene Merkzettel');
$this->readonly = false;
$this->apply_button_title = _('Hauptbereich aktualisieren');
......@@ -78,6 +78,10 @@ class ClipboardWidget extends SidebarWidget
if (!is_array($this->current_selected_items)) {
$this->current_selected_items = [];
}
$this->setId("ClipboardWidget_{$this->clipboard_widget_id}");
$this->setAdditionalAttribute('data-widget_id', $this->getId());
$this->addLayoutCSSClass('clipboard-widget');
}
......@@ -158,62 +162,27 @@ class ClipboardWidget extends SidebarWidget
public function render($variables = [])
{
$template = $GLOBALS['template_factory']->open(
$this->template
);
$layout = $GLOBALS['template_factory']->open(
'widgets/widget-layout'
);
$template->set_layout('widgets/widget-layout');
$clipboards = Clipboard::getClipboardsForUser(
$GLOBALS['user']->id
);
if (!$this->current_clipboard_id) {
if ($clipboards) {
$_SESSION['selected_clipboard_id'] = $clipboards[0]->id;
$_SESSION['selected_clipboard_items'] = [];
$this->current_clipboard_id = $clipboards[0]->id;
}
if (!$this->current_clipboard_id && $clipboards) {
$_SESSION['selected_clipboard_id'] = $clipboards[0]->id;
$_SESSION['selected_clipboard_items'] = [];
$this->current_clipboard_id = $clipboards[0]->id;
}
$template->set_attribute(
'selected_clipboard_id',
$this->current_clipboard_id
);
$template->set_attribute(
'selected_clipboard_items',
$this->current_selected_items
);
$template->set_attribute('clipboards', $clipboards);
$template->set_attribute(
'allowed_item_classes',
$this->allowed_item_classes
);
$template->set_attribute(
'clipboard_widget_id',
$this->clipboard_widget_id
);
$template->set_attribute(
'draggable_items',
$this->draggable_items
);
$template->set_attribute(
'readonly',
$this->readonly
);
$template->set_attribute(
'apply_button_title',
$this->apply_button_title
);
$template->set_attribute(
'elements',
$this->elements
);
return $template->render();
return parent::render($variables + [
'clipboards' => $clipboards,
'allowed_item_classes' => $this->allowed_item_classes,
'clipboard_widget_id' => $this->clipboard_widget_id,
'draggable_items' => $this->draggable_items,
'readonly' => $this->readonly,
'apply_button_title' => $this->apply_button_title,
'elements' => $this->elements,
'selected_clipboard_id' => $this->current_clipboard_id,
'selected_clipboard_items' => $this->current_selected_items,
]);
}
/**
......
......@@ -18,6 +18,9 @@ class RoomClipboardWidget extends ClipboardWidget
parent::__construct(['Room']);
$this->setTitle(_('Individuelle Raumgruppen'));
$this->template = 'sidebar/room-clipboard-widget';
$current_user = User::findCurrent();
$this->addLink(
......@@ -49,7 +52,5 @@ class RoomClipboardWidget extends ClipboardWidget
'data-show_in_dialog' => '1']
);
}
$this->template = 'sidebar/room-clipboard-widget';
}
}
......@@ -9,6 +9,9 @@
*/
class SidebarWidget extends Widget
{
protected $additional_attributes = [];
public function __construct()
{
$this->layout = 'sidebar/widget-layout.php';
......@@ -46,7 +49,7 @@ class SidebarWidget extends Widget
{
$this->extra = $extra;
}
public function getExtra()
{
return $this->extra;
......@@ -57,6 +60,24 @@ class SidebarWidget extends Widget
$this->extra = false;
}
public function setAdditionalAttribute(string $key, $value)
{
$this->additional_attributes[$key] = $value;
}
public function setAdditionalAttributes(array $attributes)
{
foreach ($attributes as $key => $value) {
$this->setAdditionalAttribute($key, $value);
}
}
public function removeAdditionalAttribute(string $key)
{
unset($this->additional_attributes[$key]);
}
/**
* Renders the widget.
* The widget will only be rendered if it contains at least one element.
......@@ -65,6 +86,12 @@ class SidebarWidget extends Widget
*/
public function render($variables = [])
{
$attributes = $this->additional_attributes;
if (!empty($this->id)) {
$attributes['id'] = $this->id;
}
$variables['additional_attributes'] = $attributes;
return parent::render($variables);
}
}
\ No newline at end of file
}
<section class="sidebar-widget clipboard-widget"
id="ClipboardWidget_<?= htmlReady($clipboard_widget_id) ?>"
data-widget_id="<?= htmlReady($clipboard_widget_id) ?>">
<header class="sidebar-widget-header">
<?= _('Eigene Merkzettel') ?>
</header>
<section class="sidebar-widget-content">
<?= $this->render_partial(
'sidebar/clipboard-area.php',
[
'clipboards' => $clipboards,
'empty_clipboard_string' => _('Ziehen Sie Elemente in diesen Bereich um den Merkzettel zu füllen.'),
'selected_clipboard_id' => ($clipboards[0] instanceof Clipboard
? $clipboards[0]->id
: ''),
'draggable_items' => $draggable_items,
'clipboard_widget_id' => $clipboard_widget_id
]
) ?>
<?= $this->render_partial(
'sidebar/clipboard-area.php',
[
'clipboards' => $clipboards,
'empty_clipboard_string' => _('Ziehen Sie Elemente in diesen Bereich um den Merkzettel zu füllen.'),
'selected_clipboard_id' => ($clipboards[0] instanceof Clipboard
? $clipboards[0]->id
: ''),
'draggable_items' => $draggable_items,
'clipboard_widget_id' => $clipboard_widget_id
]
) ?>
<ul class="widget-list widget-links invisible">
<? foreach ($elements as $index => $element): ?>
<li id="<?= htmlReady('link-' . md5($element->url)) ?>" <?= $element->icon ? 'style="' . $element->icon->asCSS() .'"' : '' ?>>
<?= $element->render() ?>
</li>
<? endforeach; ?>
</ul>
<ul class="widget-list widget-links invisible">
<? foreach ($elements as $index => $element): ?>
<li id="<?= htmlReady('link-' . md5($element->url)) ?>" <?= $element->icon ? 'style="' . $element->icon->asCSS() .'"' : '' ?>>
<?= $element->render() ?>
</li>
<? endforeach; ?>
</ul>
<? if (!$readonly): ?>
<form class="default new-clipboard-form"
action="<?= URLHelper::getLink(
'dispatch.php/clipboard/add'
)?>"
method="post">
<?= CSRFProtection::tokenTag() ?>
<input type="hidden" name="allowed_item_class"
value="<?= htmlReady($allowed_item_class) ?>">
<input type="hidden" name="widget_id"
value="<?= htmlReady($clipboard_widget_id) ?>">
<label>
<?= _('Merkzettel hinzufügen') ?>
<?= tooltipIcon(_('Geben Sie bitte einen Namen ein und klicken Sie auf das Plus-Symbol um einen neuen Merkzettel zu erstellen.')) ?>
<input type="text" name="name" placeholder="<?= _('Name des neuen Merkzettels') ?>"
</label>
<? if (!$readonly): ?>
<form class="default new-clipboard-form"
action="<?= URLHelper::getLink(
'dispatch.php/clipboard/add'
)?>"
method="post">
<?= CSRFProtection::tokenTag() ?>
<input type="hidden" name="allowed_item_class"
value="<?= htmlReady($allowed_item_class) ?>">
<input type="hidden" name="widget_id"
value="<?= htmlReady($clipboard_widget_id) ?>">
<label>
<?= _('Merkzettel hinzufügen') ?>
<?= tooltipIcon(_('Geben Sie bitte einen Namen ein und klicken Sie auf das Plus-Symbol um einen neuen Merkzettel zu erstellen.')) ?>
<input type="text" name="name" placeholder="<?= _('Name des neuen Merkzettels') ?>"
</label>
<?= Icon::create('add', 'clickable',
[ 'title' => _('Hinzufügen')])->asInput([
'name' => 'save',
'id' => 'add-clipboard-button',
'class' => 'middle',
'disabled' => 'disabled'
]) ?>
</form>
<? endif ?>
</section>
</section>
<?= Icon::create('add', 'clickable',
[ 'title' => _('Hinzufügen')])->asInput([
'name' => 'save',
'id' => 'add-clipboard-button',
'class' => 'middle',
'disabled' => 'disabled'
]) ?>
</form>
<? endif ?>
<section class="sidebar-widget clipboard-widget"
id="ClipboardWidget_<?= htmlReady($clipboard_widget_id) ?>"
data-widget_id="<?= htmlReady($clipboard_widget_id) ?>">
<header class="sidebar-widget-header">
<?= _('Individuelle Raumgruppen') ?>
</header>
<section class="sidebar-widget-content">
<div id="clipboard-group-container" class="<?= $clipboards ? '' : 'invisible' ?>">
<?= $this->render_partial(
'sidebar/clipboard-area.php',
[
'clipboards' => $clipboards,
'allowed_item_class' => $allowed_item_class,
'empty_clipboard_string' => _('Ziehen Sie Räume in diesen Bereich um die Raumgruppe zu füllen.'),
'selected_clipboard_id' => $selected_clipboard_id,
'draggable_items' => $draggable_items,
'special_item_template' => 'sidebar/room-clipboard-item',
'clipboard_widget_id' => $clipboard_widget_id
]
); ?>
<div id="clipboard-group-container" class="<?= $clipboards ? '' : 'invisible' ?>">
<?= $this->render_partial(
'sidebar/clipboard-area.php',
[
'clipboards' => $clipboards,
'allowed_item_class' => $allowed_item_class,
'empty_clipboard_string' => _('Ziehen Sie Räume in diesen Bereich um die Raumgruppe zu füllen.'),
'selected_clipboard_id' => $selected_clipboard_id,
'draggable_items' => $draggable_items,
'special_item_template' => 'sidebar/room-clipboard-item',
'clipboard_widget_id' => $clipboard_widget_id
]
); ?>
<? if (!$readonly): ?>
<ul class="widget-list widget-links invisible">
<? foreach ($elements as $index => $element): ?>
<li id="<?= htmlReady('link-' . md5($element->url)) ?>" <?= $element->icon ? 'style="' . $element->icon->asCSS() .'"' : '' ?>>
<a <?= arrayToHtmlAttributes($element->attributes) ?>
data-url_path = "<?= htmlReady($element->url) ?>">
<?= htmlReady($element->label) ?>
</a>
</li>
<? endforeach; ?>
</ul>
<? if (!$readonly): ?>
<ul class="widget-list widget-links invisible">
<? foreach ($elements as $index => $element): ?>
<li id="<?= htmlReady('link-' . md5($element->url)) ?>" <?= $element->icon ? 'style="' . $element->icon->asCSS() .'"' : '' ?>>
<a <?= arrayToHtmlAttributes($element->attributes) ?>
data-url_path = "<?= htmlReady($element->url) ?>">
<?= htmlReady($element->label) ?>
</a>
</li>
<? endforeach; ?>
</ul>
<form class="default new-clipboard-form"
action="<?= URLHelper::getLink(
'dispatch.php/clipboard/add'
)?>"
method="post">
<?= CSRFProtection::tokenTag() ?>
<input type="hidden" name="allowed_item_class"
value="<?= htmlReady($allowed_item_class) ?>">
<input type="hidden" name="widget_id"
value="<?= htmlReady($clipboard_widget_id) ?>">
<label>
<?= _('Raumgruppe hinzufügen') ?>
<?= tooltipIcon(_('Geben Sie bitte einen Namen ein und klicken Sie auf das Plus-Symbol um eine neue Raumgruppe zu erstellen.')) ?>
<input type="text" name="name" placeholder="<?= _('Name der neuen Raumgruppe') ?>">
</div>
<?= Icon::create('add', 'clickable',
[ 'title' => _('Hinzufügen')])->asInput([
'name' => 'save',
'id' => 'add-clipboard-button',
'class' => 'middle',
'disabled' => 'disabled'
]) ?>
</label>
<form class="default new-clipboard-form"
action="<?= URLHelper::getLink(
'dispatch.php/clipboard/add'
)?>"
method="post">
<?= CSRFProtection::tokenTag() ?>
<input type="hidden" name="allowed_item_class"
value="<?= htmlReady($allowed_item_class) ?>">
<input type="hidden" name="widget_id"
value="<?= htmlReady($clipboard_widget_id) ?>">
<label>
<?= _('Raumgruppe hinzufügen') ?>
<?= tooltipIcon(_('Geben Sie bitte einen Namen ein und klicken Sie auf das Plus-Symbol um eine neue Raumgruppe zu erstellen.')) ?>
<input type="text" name="name" placeholder="<?= _('Name der neuen Raumgruppe') ?>">
<?= Icon::create('add', 'clickable',
[ 'title' => _('Hinzufügen')])->asInput([
'name' => 'save',
'id' => 'add-clipboard-button',
'class' => 'middle',
'disabled' => 'disabled'
]) ?>
</label>
</form>
<? endif ?>
</section>
</section>
</form>
<? endif ?>
</div>
<div class="<?= $base_class ?>-widget <? if ($layout_css_classes && is_array($layout_css_classes)) echo htmlReady(implode(' ', $layout_css_classes)); ?>"
<? if ($id) printf('id="%s"', htmlReady($id)) ?>
<? if ($style) printf('style="%s"', $style) ?>>
<div class="<?= $base_class ?>-widget <?= is_array($layout_css_classes) ? htmlReady(implode(' ', $layout_css_classes)) : '' ?>"
<?= arrayToHtmlAttributes($additional_attributes) ?>>
<? if ($title): ?>
<div class="<?= $base_class ?>-widget-header">
<? if ($extra): ?>
......
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