<?php
/**
 * The more tasks view file of kanban module of ZDOO.
 *
 * @copyright   Copyright 2009-2020 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     ZPL (http://zpl.pub/page/zplv12.html)
 * @author      Gang Liu <liugang@easycorp.ltd>
 * @package     kanban
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<style>
#moreTasks {top: 48px; right: -400px; width: 400px; position: fixed; z-index: 1050; background-color: rgb(255,255,255);}
#moreTasks .panel .panel-body {overflow: auto; padding: 10px;}
#moreTasks .kanban-item {border: 1px solid #ddd;}
#moreTasks .kanban-item > .title {display: block; max-height: 38px; overflow: hidden; color: inherit; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;}
#moreTasks .kanban-item > .title:hover {color: #2272eb}
#moreTasks .kanban-item > .info {margin-top: 5px; position: relative;}
#moreTasks .kanban-item > .info > .pri {height: 14px; border-width: 1px; font-size: 12px; line-height: 12px; min-width: 14px; padding: 0 1px;}
#moreTasks .kanban-item > .info > .time {margin-left: 10px; font-size: 12px}
#moreTasks .kanban-item > .info > .user {position: absolute; right: 0; top: 0}
#moreTasks .task-actions {padding: 15px 10px;}
#moreTasks .task-actions > .btn {display: block;}
#moreTasks .task-actions > .btn + .btn {margin-top: 10px;}
</style>
<div class='panel'>
  <div class='panel-heading text-center'>
    <strong><?php echo $lang->kanban->archivedTask;?></strong>
    <button type="button" class="close" aria-hidden="true">×</button>
  </div>
  <div class='panel-body'>
    <?php foreach($tasks as $task):?>
    <div class='task-item' data-task='<?php echo $task->id;?>'>
      <div class='col-xs-10'>
        <div class="kanban-item" data-id="<?php echo $task->id;?>">
          <?php echo html::a($this->createLink('sys.task', 'view', "taskID=$task->id&from=kanban"), $task->name, "class='title' data-toggle='modal' data-width='80%'");?>
          <div class="info">
            <span class="pri label-pri label-pri-<?php echo $task->pri;?>"><?php echo $task->pri;?></span>
            <?php if($task->left && $task->left != 0) echo "<span class='text-gray'>{$task->left}h</span>";?>
            <?php if($task->deadline && $task->deadline != '0000-00-00'):?>
            <span class="time label label-light"><?php echo $task->deadline . $lang->kanban->deadline;?></span>
            <?php endif;?>
            <?php
            $user       = zget($members, $task->assignedTo);
            $userID     = zget($user, 'id', $task->assignedTo);
            $userName   = zget($user, 'realname', $task->assignedTo);
            $userAvatar = zget($user, 'avatar', '');
            ?>
            <div class="user pull-right" title="<?php echo $userName;?>">
              <?php echo "<div class='avatar avatar-sm avatar-user' data-name='$userName' data-id='$userID'>" . ($userAvatar ? "<img src='$userAvatar' />" : $task->assignedTo) . '</div>';?>
            </div>
          </div>
        </div>
      </div>
      <div class='col-xs-2 task-actions'>
        <?php
        $canRestore = $this->task->isClickable($task, 'restore', $project->taskStatus);
        $canDelete  = $this->task->isClickable($task, 'delete');

        if($canRestore)
        {
            $taskColumn = zget($columns, $task->kanbanColumn);
            if($taskColumn->archived == '0')
            {
                $confirmRestoreDetail = sprintf($lang->task->confirmRestoreDetail, $taskColumn->name);
                echo html::a($this->createLink('task', 'restore', "taskID=$task->id&from=kanban"), $lang->restore, "class='btn btn-xs btn-primary restore-task' data-confirmTitle='{$lang->task->confirmRestore}' data-confirmDetail='{$confirmRestoreDetail}' data-confirmButton='{$lang->restore}' data-confirming='{$lang->restoring}'");
            }
            else
            {
                $confirmRestoreTip = sprintf($lang->task->confirmRestoreTip, $taskColumn->name);
                echo "<button type='button' class='btn btn-xs btn-primary' data-custom='{$confirmRestoreTip}' data-toggle='modal'>{$lang->restore}</button>";
            }
        }

        if($canDelete) echo html::a($this->createLink('task', 'delete', "taskID=$task->id&from=kanban"), $lang->delete, "class='btn btn-xs delete-task' data-confirmTitle='{$lang->task->confirmDelete}' data-confirmDetail='{$lang->task->confirmDeleteDetail}'");
        ?>
      </div>
    </div>
    <?php endforeach;?>
  </div>
</div>
<script>
$(function()
{
    $('#moreTasks .panel .close').click(function()
    {
        $('#moreTasks').animate({right: -400}, 500);
    });

    $.setAjaxConfirmer('.restore-task, .delete-task', function(response)
    {
        if(response.result == 'success' && response.task)
        {
            $('#moreTasks > .panel > .panel-body > .task-item[data-task=' + response.task + ']').remove();
        }
    });
})
</script>
