<?php
/**
 * The browse file of todo module of ZDOO.
 *
 * @copyright   Copyright 2009-2018 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     ZPL (http://zpl.pub/page/zplv12.html)
 * @author      chujilu <chujilu@cnezsoft.com>
 * @package     todo
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include $app->getModuleRoot() . '../sys/my/view/header.html.php';?>
<?php include '../../../sys/common/view/datepicker.html.php';?>
<?php js::set('mode', $mode);?>
<?php
$canBatchFinish  = commonModel::hasPriv('todo', 'batchFinish');
$canBatchClose   = commonModel::hasPriv('todo', 'batchClose');
$canBatchEdit    = commonModel::hasPriv('todo', 'batchEdit');
$canImport2Today = commonModel::hasPriv('todo', 'import2Today');
$canBatchAction  = ($todos && ($canBatchFinish or $canBatchClose or $canBatchEdit or $canImport2Today));
?>
<div class='panel main-table' data-ride='table'>
  <?php if($canBatchAction):?>
  <form id='jaxForm' method='post'>
  <?php endif;?>
    <table class='table has-sort-head' id='todoList'>
      <thead>
        <tr class='text-center'>
          <?php $vars = "mode=$mode&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?>
          <th class='w-100px text-left'>
            <?php if($canBatchAction):?>
            <div class='checkbox-primary check-all' title='<?php echo $this->lang->selectAll;?>'><label></label></div>
            <?php endif;?>
            <?php commonModel::printOrderLink('id', $orderBy, $vars, $lang->todo->id);?>
          </th>
          <th class='w-100px'><?php commonModel::printOrderLink('date',   $orderBy, $vars, $lang->todo->date);?></th>
          <th class='w-100px'><?php commonModel::printOrderLink('type',   $orderBy, $vars, $lang->todo->type);?></th>
          <th class='w-80px'> <?php commonModel::printOrderLink('pri',    $orderBy, $vars, $lang->todo->pri);?></th>
          <th>                <?php commonModel::printOrderLink('name',   $orderBy, $vars, $lang->todo->name);?></th>
          <th class='w-100px'><?php commonModel::printOrderLink('assignedTo', $orderBy, $vars, $lang->todo->assignedTo);?></th>
          <th class='w-100px'><?php commonModel::printOrderLink('begin',  $orderBy, $vars, $lang->todo->begin);?></th>
          <th class='w-100px'><?php commonModel::printOrderLink('end',    $orderBy, $vars, $lang->todo->end);?></th>
          <th class='w-100px'><?php commonModel::printOrderLink('status', $orderBy, $vars, $lang->todo->status);?></th>
          <th class='w-<?php echo $lang->todo->actionWidth;?>px'><?php echo $lang->actions;?></th>
        </tr>
      </thead>
      <tbody>
        <?php foreach($todos as $todo):?>
        <tr class='text-center'>
          <td class='text-left'>
            <?php if($canBatchAction):?>
            <div class='checkbox-primary'>
              <input type='checkbox' name='todoIDList[]' value="<?php echo $todo->id;?>">
              <label for="todoIDList<?php echo $todo->id;?>"></label>
            </div>
            <?php endif;?>
            <?php echo $todo->id;?>
          </td>
          <td><?php echo formatTime($todo->date, DT_DATE1);?></td>
          <td><?php echo zget($lang->todo->typeList, $todo->type, '');?></td>
          <td><?php echo zget($lang->todo->priList, $todo->pri, '');?></td>
          <td class='text-left c-name' title='<?php echo $todo->name?>'><?php echo $todo->name;?></td>
          <td><?php echo zget($users, $todo->assignedTo);?></td>
          <td><?php echo formatTime($todo->begin, DT_TIME2);?></td>
          <td><?php echo formatTime($todo->end, DT_TIME2);?></td>
          <td><?php echo zget($lang->todo->statusList, $todo->status);?></td>
          <td class='text-left actions'>
            <?php
            echo html::a($this->createLink('todo', 'view', "todoID={$todo->id}"), $lang->view, "data-toggle='modal' data-width='1060px'");
            $disabled = ($this->todo->checkPriv($todo, 'finish') && $this->todo->isClickable($todo, 'finish')) ? '' : 'disabled';
            echo html::a($this->createLink('todo', 'finish', "todoID={$todo->id}"), $lang->todo->finish, "class='$disabled' data-toggle='ajax'");
            echo html::a($this->createLink('todo', 'assignTo', "todoID={$todo->id}"), $lang->todo->assignTo, "data-toggle='modal'");
            $disabled = ($this->todo->checkPriv($todo, 'activate') and $this->todo->isClickable($todo, 'activate')) ? '' : 'disabled';
            echo html::a($this->createLink('todo', 'activate', "todoID={$todo->id}"), $lang->activate, "class='$disabled' data-toggle='ajax'");
            $disabled = ($this->todo->checkPriv($todo, 'close') and $this->todo->isClickable($todo, 'close')) ? '' : 'disabled';
            echo html::a($this->createLink('todo', 'close', "todoID={$todo->id}"), $lang->close, "class='$disabled' data-toggle='ajax'");
            echo html::a($this->createLink('todo', 'edit', "todoID={$todo->id}"), $lang->edit, "data-toggle='modal'");
            echo html::a($this->createLink('todo', 'delete', "todoID={$todo->id}"), $lang->delete, "class='deleter'");
            ?>
          </td>
        </tr>
        <?php endforeach;?>
      </tbody>
    </table>
    <div class='table-footer'>
      <?php if($canBatchAction):?>
      <div class='checkbox-primary check-all'><label><?php echo $lang->selectAll?></label></div>
      <div class='table-statistic'></div>
      <div class='table-actions btn-toolbar'>
        <div class='btn-group dropup no-margin-top'>
          <?php
          $finishLink = $this->createLink('todo', 'batchFinish');
          $class      = $canBatchFinish ? '' : 'disabled';
          echo html::commonButton($lang->finish, "btn btn-default $class", "data-form-action='{$finishLink}'");
          ?>
          <?php if($canBatchClose or $canBatchEdit):?>
          <button type='button' class='btn dropdown-toggle' data-toggle='dropdown'><span class='caret'></span></button>
          <ul class='dropdown-menu'>
            <?php
            if($canBatchClose)
            {
                $closeLink = $this->createLink('todo', 'batchClose');
                echo '<li>' . html::a('javascript:;', $lang->close, "onclick=\"setFormAction('$closeLink')\"") . '</li>';
            }
            if($canBatchEdit)
            {
                $editLink = $this->createLink('todo', 'batchEdit');
                echo '<li>' . html::a('javascript:;', $lang->edit, "onclick=\"setFormAction('$editLink')\"") . '</li>';
            }
            ?>
          </ul>
          <?php endif;?>
        </div>
        <?php if($canImport2Today):?>
        <div class='input-group import-action w-<?php echo $lang->todo->importActionWidth;?>px'>
          <span class='input-group-btn'>
            <?php echo html::commonButton($lang->todo->import, 'btn btn-default import');?>
          </span>
          <div class='datepicker-wrapper datepicker-date hidden'>
            <?php echo html::input('date', date('Y-m-d'), "class='form-control form-date'");?>
          </div>
          <span class='input-group-btn confirm hidden'>
            <?php $actionLink = $this->createLink('todo', 'import2Today');?>
            <?php echo html::commonButton($lang->confirm, 'btn btn-default', "onclick=\"setFormAction('$actionLink')\"");?>
          </span>
        </div>
        <?php endif;?>
      </div>
      <?php endif;?>
      <?php $pager->show();?>
    </div>
  <?php if($canBatchAction):?>
  </form>
  <?php endif;?>
</div>
<?php include $app->getModuleRoot() . 'common/view/footer.html.php';?>
