summaryrefslogtreecommitdiff
path: root/includes/view/ShiftTypes_view.php
blob: 3e10be29a93d262687a0cf3088a184678e6e2c41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php

/**
 * @param array $shifttype
 * @return string
 */
function ShiftType_name_render($shifttype)
{
    if (auth()->can('shifttypes')) {
        return '<a href="' . shifttype_link($shifttype) . '">' . $shifttype['name'] . '</a>';
    }
    return $shifttype['name'];
}

/**
 * @param array $shifttype
 * @return string
 */
function ShiftType_delete_view($shifttype)
{
    return page_with_title(sprintf(__('Delete shifttype %s'), $shifttype['name']), [
        info(sprintf(__('Do you want to delete shifttype %s?'), $shifttype['name']), true),
        form([
            buttons([
                button(page_link_to('shifttypes'), glyph('remove') . __('cancel')),
                form_submit(
                    'delete',
                    glyph('ok') . __('delete'),
                    'btn-danger',
                    false
                ),
            ]),
        ]),
    ], true);
}

/**
 * @param string   $name
 * @param int      $angeltype_id
 * @param array[]  $angeltypes
 * @param string   $description
 * @param int|bool $shifttype_id
 * @return string
 */
function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id)
{
    $angeltypes_select = [
        '' => __('All')
    ];
    foreach ($angeltypes as $angeltype) {
        $angeltypes_select[$angeltype['id']] = $angeltype['name'];
    }

    return page_with_title($shifttype_id ? __('Edit shifttype') : __('Create shifttype'), [
        msg(),
        buttons([
            button(page_link_to('shifttypes'), shifttypes_title(), 'back')
        ]),
        form([
            form_text('name', __('Name'), $name),
            form_select('angeltype_id', __('Angeltype'), $angeltypes_select, $angeltype_id),
            form_textarea('description', __('Description'), $description),
            form_info('', __('Please use markdown for the description.')),
            form_submit('submit', __('Save'))
        ])
    ], true);
}

/**
 * @param array $shifttype
 * @param array $angeltype
 * @return string
 */
function ShiftType_view($shifttype, $angeltype)
{
    $parsedown = new Parsedown();
    $title = $shifttype['name'];
    if ($angeltype) {
        $title .= ' <small>' . sprintf(__('for team %s'), $angeltype['name']) . '</small>';
    }
    return page_with_title($title, [
        msg(),
        buttons([
            button(page_link_to('shifttypes'), shifttypes_title(), 'back'),
            $angeltype ? button(
                page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]),
                $angeltype['name']
            ) : '',
            button(
                page_link_to('shifttypes', ['action' => 'edit', 'shifttype_id' => $shifttype['id']]),
                __('edit'),
                'edit'
            ),
            button(
                page_link_to('shifttypes', ['action' => 'delete', 'shifttype_id' => $shifttype['id']]),
                __('delete'),
                'delete'
            )
        ]),
        heading(__('Description'), 2),
        $parsedown->parse($shifttype['description'])
    ], true);
}

/**
 * @param array[] $shifttypes
 * @return string
 */
function ShiftTypes_list_view($shifttypes)
{
    foreach ($shifttypes as &$shifttype) {
        $shifttype['name'] = '<a href="'
            . page_link_to('shifttypes', ['action' => 'view', 'shifttype_id' => $shifttype['id']])
            . '">'
            . $shifttype['name']
            . '</a>';
        $shifttype['actions'] = table_buttons([
            button(
                page_link_to(
                    'shifttypes',
                    ['action' => 'edit', 'shifttype_id' => $shifttype['id']]
                ),
                __('edit'),
                'btn-xs'
            ),
            button(
                page_link_to('shifttypes', ['action' => 'delete', 'shifttype_id' => $shifttype['id']]),
                __('delete'),
                'btn-xs'
            )
        ]);
    }

    return page_with_title(shifttypes_title(), [
        msg(),
        buttons([
            button(page_link_to('shifttypes', ['action' => 'edit']), __('New shifttype'), 'add')
        ]),
        table([
            'name'    => __('Name'),
            'actions' => ''
        ], $shifttypes)
    ], true);
}