{% extends "base.html.twig" %} {% block localstyle %} td { padding:5px !important; } {% endblock %} {% block body %} {{ form_start(form) }}

{% if mode=="update" %} Modification TIMER {% elseif mode=="submit" %} Création TIMER {% endif %}

{{ form_widget(form.submit) }} Annuler {% if mode=="update" %} Supprimer {% endif %}

{% if app.session.flashbag.has('error') %}
Erreur
{% for flashMessage in app.session.flashbag.get('error') %} {{ flashMessage }}
{% endfor %}
{% endif %} {% if app.session.flashbag.has('notice') %}
Information
{% for flashMessage in app.session.flashbag.get('notice') %} {{ flashMessage }}
{% endfor %}
{% endif %}
Informations
{{ form_row(form.task) }} {{ form_row(form.description) }} {{ form_row(form.activepenalty) }} {{ form_row(form.additionalhour) }} {{ form_row(form.start) }} {{ form_row(form.end) }} {{ form_row(form.duration) }}
{{ form_end(form) }} {% endblock %} {% block localjavascript %} $("#timer_task").addClass("select2entity"); /* * Pads this string with another string on the left until the resulting string * has specified length. If the padding string has more than one character, the * resulting string may be longer than desired (the padding string is not * truncated and it is only prepended as a whole). Bad API, I know, but it's * good enough for me. */ String.prototype.pad = function(length, padding) { var result = this; while (result.length < length) { result = padding + result; } return result; } /* Some time constants. */ var MILISECONDS_IN_SECOND = 1000; var MILISECONDS_IN_MINUTE = 60 * MILISECONDS_IN_SECOND; var MINUTES_IN_HOUR = 60; /* Formats the time in the H:MM format. */ function formatTime(time) { var timeInMinutes = time / MILISECONDS_IN_MINUTE; var hours = Math.floor(timeInMinutes / MINUTES_IN_HOUR); var minutes = Math.floor(timeInMinutes - hours * MINUTES_IN_HOUR); return String(hours).pad(2, "0") + ":" + String(minutes).pad(2, "0"); } $("#timer_start_time,#timer_end_time").on('input',function(){ console.log($("#timer_start_date").val() +"T"+$("#timer_start_time").val()+":00Z") console.log($("#timer_end_date").val()+"T"+$("#timer_end_time").val()+":00Z") var start = Date.parse($("#timer_start_date").val() +"T"+$("#timer_start_time").val()+":00Z"); var end = Date.parse($("#timer_end_date").val()+"T"+$("#timer_end_time").val()+":00Z"); var diff = end - start; $("#timer_duration").val(formatTime(diff)) }) {% endblock %}