{{extend 'default.mobile/layout.html'}}
{{import os, stat, time}}

{{block sectionclass}}errors{{end}}

<style>
table.sortable {
  border-spacing:0px;
}
table.sortable td, table.sortable th {
  padding: 2px 5px 2px 5px;
}
table.sortable thead {
  background-color:#eee;
  color:#666666;
  font-weight: bold;
  cursor: default;
}
tr.error_ticket:hover {
  background-color: #eee;
}
a.unavailable {
  color: #ff0000;
}
</style>

<script language="JavaScript">
  function check(){
    for (var i = 0; i < document.myform.elements.length; i++) {
        var e = document.myform.elements[i];
        if (e.type == 'checkbox') e.checked = true;
    }
  }
  function uncheck(){
    for (var i = 0; i < document.myform.elements.length; i++) {
      var e = document.myform.elements[i];
      if (e.type == 'checkbox') e.checked = false;
    }
  }
  jQuery(document).ready(function() { jQuery('.traceback').hide(); });
</script>
{{if db_ready['status'] == False:
    switchurl = db_ready['errmessage']
    switchbutton = XML("""<a data-role="button" data-inline="true" data-inline="true" href="%(href)s" title="%(title)s" class="unavailable"><span>switch to : db</span></a>""" % dict(href=switchurl, title=db_ready['errmessage']))
else:
    switchurl = URL(args=[app, 'dbnew'])
    switchbutton = XML("""<a data-role="button" data-inline="true" data-inline="true" href="%s"><span>switch to : db</span></a>""" % (switchurl))
pass}}
<h2>{{=T('Error logs for "%(app)s"',dict(app=app))}}</h2>

<div>
  <form name="myform" method="post">
    <div data-role="controlgroup" data-type="horizontal">
    <input name="CheckAll" value="{{=T('check all')}}"
     onclick="check()" type="button">
    <input name="CheckAll" value="{{=T('uncheck all')}}"
     onclick="uncheck()" type="button">
    <input value="{{=T('delete all checked')}}" type="submit"><br><br>
    </div>

    {{ if 'new' in method: }}
    {{base_url = 'db' in method and 'ticketdb' or 'ticket' }}
    <h3>{{=T('Click row to expand traceback')}}</h3>
    <p>
    {{if 'db' in method:}}
        source : db
        <a data-role="button" data-inline="true" href="{{=URL(args=[app, 'new'])}}"><span>switch to : filesystem</span></a>
        <a data-role="button" data-inline="true" href="{{=URL(args=[app, 'dbold'])}}"><span>lists by ticket</span></a>
    {{else:}}
        source : filesystem
        {{=switchbutton}}
        <a data-role="button" data-inline="true" href="{{=URL(args=[app, 'old'])}}"><span>lists by ticket</span></a>
    {{pass}}
    </p>
    <table id="trck_errors" class="sortable">
      <thead>
        <tr>
          <th>{{=T("Delete")}}</th>
          <th>{{=T("Count")}}</th>
          <th>{{=T("File")}}</th>
          <th>{{=T("Error")}}</th>
          <th></th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        {{for e in errors:}}
        <tr class="error_ticket">
          <td><input type="checkbox" name="delete_{{=e['hash']}}" /></td>
          <td>{{=e['count']}}</td>
          <td>{{=e['causer']}}</td>
          <td>{{=A(e['last_line'],_href="#",_onclick="collapse('%s');"%e['hash'])}}</td>
          <td>+</td>
          <td>{{=A(T('details'),_href=URL(base_url,args=[app,e['ticket']]))}}</td>
        </tr>
        <tr id="{{=e['hash']}}" class="traceback">
          <td colspan="6">
            <div>
              {{=CODE(e['pickel']['traceback'])}}
            </div>
          </td>
        </tr>
        {{pass}}
      </tbody>
    </table>
    {{ else: }}
    <h3>{{=T('Click row to view a ticket')}}</h3>
    <p>
    {{if 'db' in method:}}
        source : db
        <a data-role="button" data-inline="true" href="{{=URL(args=[app, 'old'])}}"><span>switch to : filesystem</span></a>
        <a data-role="button" data-inline="true" href="{{=URL(args=[app, 'dbnew'])}}"><span>lists by exception</span></a>
    {{else:}}
        source : filesystem
        {{=switchbutton}}
        <a data-role="button" data-inline="true" href="{{=URL(args=[app, 'new'])}}"><span>lists by exception</span></a>
    {{pass}}
    </p>
    <table class="sortable">
      <thead>
        <tr>
    <th>{{=T("Delete")}}</th>
    <th>{{=T("Ticket")}}</th>
    <th>{{=T("Date and Time")}}</th>
        </tr>
      </thead>
      <tbody>
        {{for ticket in tickets:}}
        <tr>
    <td><input type="checkbox" name="delete_{{=ticket}}"/></td>
    {{if 'db' in method:}}
    <td><a href="{{=URL('ticketdb',args=[app,ticket])}}">{{=ticket}}</a></td>
    <td>{{=time.strftime('%Y-%m-%d %H:%M:%S',times[ticket].timetuple())}}</td>
    {{else:}}
    <td><a href="{{=URL('ticket',args=[app,ticket])}}">{{=ticket}}</a></td>
    <td>{{=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(os.stat(os.path.join(request.folder,'../%s/errors/%s' % (app,ticket)))[stat.ST_CTIME]))}}</td>
    {{pass}}
        </tr>
        {{pass}}
      </tbody>
    </table>
    {{ pass }}
  </form>
</div>

