1<?php
2global $thisstaff;
3
4$role = $ticket->getRole($thisstaff);
5
6$tasks = Task::objects()
7    ->select_related('dept', 'staff', 'team')
8    ->order_by('-created');
9
10$tasks->filter(array(
11            'object_id' => $ticket->getId(),
12            'object_type' => 'T'));
13
14$count = $tasks->count();
15$pageNav = new Pagenate($count,1, 100000); //TODO: support ajax based pages
16$showing = $pageNav->showing().' '._N('task', 'tasks', $count);
17
18?>
19<div id="tasks_content" style="display:block;">
20<div class="pull-left">
21   <?php
22    if ($count) {
23        echo '<strong>'.$showing.'</strong>';
24    } else {
25        echo sprintf(__('%s does not have any tasks'), $ticket? 'This ticket' :
26                'System');
27    }
28   ?>
29</div>
30<div class="pull-right">
31    <?php
32    if ($role && $role->hasPerm(Task::PERM_CREATE)) { ?>
33        <a
34        class="green button action-button ticket-task-action"
35        data-url="tickets.php?id=<?php echo $ticket->getId(); ?>#tasks"
36        data-dialog-config='{"size":"large"}'
37        href="#tickets/<?php
38            echo $ticket->getId(); ?>/add-task">
39            <i class="icon-plus-sign"></i> <?php
40            print __('Add New Task'); ?></a>
41    <?php
42    }
43    foreach ($tasks as $task)
44        $taskStatus .= $task->isOpen() ? 'open' : 'closed';
45
46    if ($count)
47        Task::getAgentActions($thisstaff, array(
48                    'container' => '#tasks_content',
49                    'callback_url' => sprintf('ajax.php/tickets/%d/tasks',
50                        $ticket->getId()),
51                    'morelabel' => __('Options'),
52                    'status' => $taskStatus ? $taskStatus : '')
53                );
54    ?>
55</div>
56<div class="clear"></div>
57<div>
58<?php
59if ($count) { ?>
60<form action="#tickets/<?php echo $ticket->getId(); ?>/tasks" method="POST"
61    name='tasks' id="tasks" style="padding-top:7px;">
62<?php csrf_token(); ?>
63 <input type="hidden" name="a" value="mass_process" >
64 <input type="hidden" name="do" id="action" value="" >
65 <table class="list" border="0" cellspacing="1" cellpadding="2" width="940">
66    <thead>
67        <tr>
68            <?php
69            if (1) {?>
70            <th width="8px">&nbsp;</th>
71            <?php
72            } ?>
73            <th width="70"><?php echo __('Number'); ?></th>
74            <th width="100"><?php echo __('Date'); ?></th>
75            <th width="100"><?php echo __('Status'); ?></th>
76            <th width="300"><?php echo __('Title'); ?></th>
77            <th width="200"><?php echo __('Department'); ?></th>
78            <th width="200"><?php echo __('Assignee'); ?></th>
79        </tr>
80    </thead>
81    <tbody class="tasks">
82    <?php
83    foreach($tasks as $task) {
84        $id = $task->getId();
85        $access = $task->checkStaffPerm($thisstaff);
86        $assigned='';
87        if ($task->staff || $task->team) {
88            $assigneeType = $task->staff ? 'staff' : 'team';
89            $icon = $assigneeType == 'staff' ? 'staffAssigned' : 'teamAssigned';
90            $assigned=sprintf('<span class="Icon %s">%s</span>',
91                    $icon,
92                    Format::truncate($task->getAssigned(),40));
93        }
94
95        $status = $task->isOpen() ? '<strong>open</strong>': 'closed';
96
97        $title = Format::htmlchars(Format::truncate($task->getTitle(),40));
98        $threadcount = $task->getThread() ?
99            $task->getThread()->getNumEntries() : 0;
100
101        if ($access)
102            $viewhref = sprintf('#tickets/%d/tasks/%d/view', $ticket->getId(), $id);
103        else
104            $viewhref = '#';
105
106        ?>
107        <tr id="<?php echo $id; ?>">
108            <td align="center" class="nohover">
109                <input class="ckb" type="checkbox" name="tids[]"
110                value="<?php echo $id; ?>" <?php echo $sel?'checked="checked"':''; ?>>
111            </td>
112            <td align="center" nowrap>
113              <a class="Icon no-pjax preview"
114                title="<?php echo __('Preview Task'); ?>"
115                href="<?php echo $viewhref; ?>"
116                data-preview="#tasks/<?php echo $id; ?>/preview"
117                ><?php echo $task->getNumber(); ?></a></td>
118            <td align="center" nowrap><?php echo
119            Format::datetime($task->created); ?></td>
120            <td><?php echo $status; ?></td>
121            <td>
122                <?php
123                if ($access) { ?>
124                    <a <?php if ($flag) { ?> class="no-pjax"
125                        title="<?php echo ucfirst($flag); ?> Task" <?php } ?>
126                        href="<?php echo $viewhref; ?>"><?php
127                    echo $title; ?></a>
128                 <?php
129                } else {
130                     echo $title;
131                }
132                    if ($threadcount>1)
133                        echo "<small>($threadcount)</small>&nbsp;".'<i
134                            class="icon-fixed-width icon-comments-alt"></i>&nbsp;';
135                    if ($row['collaborators'])
136                        echo '<i class="icon-fixed-width icon-group faded"></i>&nbsp;';
137                    if ($row['attachments'])
138                        echo '<i class="icon-fixed-width icon-paperclip"></i>&nbsp;';
139                ?>
140            </td>
141            <td><?php echo Format::truncate($task->dept->getName(), 40); ?></td>
142            <td>&nbsp;<?php echo $assigned; ?></td>
143        </tr>
144   <?php
145    }
146    ?>
147    </tbody>
148</table>
149</form>
150<?php
151 } ?>
152</div>
153</div>
154<div id="task_content" style="display:none;">
155</div>
156<script type="text/javascript">
157$(function() {
158
159    $(document).off('click.taskv');
160    $(document).on('click.taskv', 'tbody.tasks a, a#reload-task', function(e) {
161        e.preventDefault();
162        e.stopImmediatePropagation();
163        if ($(this).attr('href').length > 1) {
164            var url = 'ajax.php/'+$(this).attr('href').substr(1);
165            var $container = $('div#task_content');
166            var $stop = $('ul#ticket_tabs').offset().top;
167            $.pjax({url: url, container: 'div#task_content', push: false, scrollTo: $stop})
168            .done(
169                function() {
170                $container.show();
171                $('.tip_box').remove();
172                $('div#tasks_content').hide();
173                });
174        } else {
175            $(this).trigger('mouseenter');
176        }
177
178        return false;
179     });
180    // Ticket Tasks
181    $(document).off('.ticket-task-action');
182    $(document).on('click.ticket-task-action', 'a.ticket-task-action', function(e) {
183        e.preventDefault();
184        var url = 'ajax.php/'
185        +$(this).attr('href').substr(1)
186        +'?_uid='+new Date().getTime();
187        var $redirect = $(this).data('href');
188        var $options = $(this).data('dialogConfig');
189        $.dialog(url, [201], function (xhr) {
190            var tid = parseInt(xhr.responseText);
191            if (tid) {
192                var url = 'ajax.php/tickets/'+<?php echo $ticket->getId();
193                ?>+'/tasks';
194                var $container = $('div#task_content');
195                $container.load(url+'/'+tid+'/view', function () {
196                    $('.tip_box').remove();
197                    $('div#tasks_content').hide();
198                    $.pjax({url: url, container: '#tasks_content', timeout: 30000, push: false});
199                }).show();
200            } else {
201                window.location.href = $redirect ? $redirect : window.location.href;
202            }
203        }, $options);
204        return false;
205    });
206
207    $('#ticket-tasks-count').html(<?php echo $count; ?>);
208});
209</script>
210