<%@ page import="com.agnitas.emm.core.mailing.dao.ComMailingParameterDao" %>
<%@ page import="com.agnitas.emm.core.Permission" %>

<emm:ShowByPermission token="mailing.interval">
    <c:set var="MAILING_CONTENT_CHANGE_ALWAYS" value="<%= Permission.MAILING_CONTENT_CHANGE_ALWAYS.toString() %>"/>

    <c:set var="INTERVAL_NONE" value="<%= ComMailingParameterDao.IntervalType.None %>"/>
    <c:set var="INTERVAL_SHORT" value="<%= ComMailingParameterDao.IntervalType.Short %>"/>
    <c:set var="INTERVAL_WEEKLY" value="<%= ComMailingParameterDao.IntervalType.Weekly %>"/>
    <c:set var="INTERVAL_TWO_WEEKLY" value="<%= ComMailingParameterDao.IntervalType.TwoWeekly %>"/>
    <c:set var="INTERVAL_MONTHLY" value="<%= ComMailingParameterDao.IntervalType.Monthly %>"/>
    <c:set var="INTERVAL_WEEKDAILY" value="<%= ComMailingParameterDao.IntervalType.Weekdaily %>"/>

    <c:set var="isEditingDenied" value="${form.worldMailingSend}"/>
    <emm:ShowByPermission token="${MAILING_CONTENT_CHANGE_ALWAYS}">
        <c:set var="isEditingDenied" value="${false}"/>
    </emm:ShowByPermission>

    <mvc:form servletRelativeAction="/mailing/send/activate-interval.action" modelAttribute="form" id="intervalSettingsForm" data-form="resource">
        <mvc:hidden path="mailingID"/>

        <div class="tile" data-field="toggle-vis">
            <div class="tile-header">
                <h2 class="headline">
                    <mvc:message code="default.interval" />
                </h2>
            </div>
            <div class="tile-content tile-content-forms">
                <div class="form-group">
                    <div class="col-sm-4">
                        <label class="control-label"><mvc:message code="mailing.interval" /></label>
                    </div>
                    <div class="col-sm-8">
                    <div>
                        <label class="radio-inline">
                            <mvc:radiobutton path="intervalSettings.intervalType" id="interval[none]_id"
                                             data-field-vis="" data-field-vis-nondisabled="" data-field-vis-hide="#field-interval-weekdays, #field-interval-months, #field-interval-time, #field-interval-weeday-ordinal"
                                             value="${INTERVAL_NONE}" disabled="${isEditingDenied}"/>
                            <mvc:message code="Interval.none"/>
                        </label>
                        <emm:ShowByPermission token="mailing.interval.short">
                            <label class="radio-inline">
                                <mvc:radiobutton path="intervalSettings.intervalType" id="interval[short]_id"
                                                 data-field-vis="" data-field-vis-nondisabled="" data-field-vis-hide="#field-interval-months, #field-interval-weekdays, #field-interval-weeday-ordinal, #field-interval-time"
                                                 value="${INTERVAL_SHORT}" disabled="${isEditingDenied}"/>
                                <mvc:message code="Interval.short"/>
                            </label>
                        </emm:ShowByPermission>
                        <label class="radio-inline">
                            <mvc:radiobutton path="intervalSettings.intervalType" id="interval[weekly]_id"
                                             data-field-vis="" data-field-vis-nondisabled="" data-field-vis-hide="#field-interval-months, #field-interval-weeday-ordinal"
                                             data-field-vis-show="#field-interval-weekdays, #field-interval-time"
                                             value="${INTERVAL_WEEKLY}" disabled="${isEditingDenied}"/>
                            <mvc:message code="Interval.weekly"/>
                        </label>
                        <label class="radio-inline">
                            <mvc:radiobutton path="intervalSettings.intervalType" id="interval[2weekly]_id"
                                             data-field-vis="" data-field-vis-nondisabled="" data-field-vis-hide="#field-interval-months, #field-interval-weeday-ordinal"
                                             data-field-vis-show="#field-interval-weekdays, #field-interval-time"
                                             value="${INTERVAL_TWO_WEEKLY}" disabled="${isEditingDenied}"/>
                            <mvc:message code="Interval.2weekly"/>
                        </label>
                        <label class="radio-inline">
                            <mvc:radiobutton path="intervalSettings.intervalType" id="interval[monthly]_id"
                                             data-field-vis="" data-field-vis-nondisabled="" data-field-vis-hide="#field-interval-weekdays, #field-interval-weeday-ordinal"
                                             data-field-vis-show="#field-interval-months, #field-interval-time"
                                             value="${INTERVAL_MONTHLY}" disabled="${isEditingDenied}"/>
                            <mvc:message code="Interval.monthly"/>
                        </label>
                        <label class="radio-inline">
                            <mvc:radiobutton path="intervalSettings.intervalType" id="interval[weekdaily]_id"
                                             data-field-vis="" data-field-vis-nondisabled="" data-field-vis-hide="#field-interval-months"
                                             data-field-vis-show="#field-interval-weekdays, #field-interval-weeday-ordinal, #field-interval-time"
                                             value="${INTERVAL_WEEKDAILY}" disabled="${isEditingDenied}"/>
                            <mvc:message code="report.autosend.days"/>
                        </label>
                    </div>
                    </div>                     
                </div>

                <div id="field-interval-weeday-ordinal" class="form-group">
                    <div class="col-sm-4">
                        <label class="control-label">
                            <mvc:message code="mailing.interval.weekdaily.ordinal"/>
                        </label>
                    </div>

                    <div class="col-sm-8">
                        <label class="radio-inline">
                            <mvc:radiobutton id="interval[weekday1]_id" path="intervalSettings.weekdayOrdinal" value="1" disabled="${isEditingDenied}"/>
                            <mvc:message code="mailing.interval.weekdayOrdinal.1"/>
                        </label>
                        <label class="radio-inline">
                            <mvc:radiobutton id="interval[weekday2]_id" path="intervalSettings.weekdayOrdinal" value="2" disabled="${isEditingDenied}"/>
                            <mvc:message code="mailing.interval.weekdayOrdinal.2"/>
                        </label>
                        <label class="radio-inline">
                            <mvc:radiobutton id="interval[weekday3]_id" path="intervalSettings.weekdayOrdinal" value="3" disabled="${isEditingDenied}"/>
                            <mvc:message code="mailing.interval.weekdayOrdinal.3"/>
                        </label>
                        <label class="radio-inline">
                            <mvc:radiobutton id="interval[weekday4]_id" path="intervalSettings.weekdayOrdinal" value="4" disabled="${isEditingDenied}"/>
                            <mvc:message code="mailing.interval.weekdayOrdinal.4"/>
                        </label>
                        <label class="radio-inline">
                            <mvc:radiobutton id="interval[weekday5]_id" path="intervalSettings.weekdayOrdinal" value="5" disabled="${isEditingDenied}"/>
                            <mvc:message code="mailing.interval.weekdayOrdinal.5"/>
                        </label>
                    </div>
                </div>

                <div id="field-interval-weekdays" class="form-group">
                    <div class="col-sm-4">
                        <label class="control-label"><mvc:message code="report.autosend.days"/></label>
                    </div>

                    <div class="col-sm-8">
                        <label class="checkbox-inline">
                            <mvc:checkbox id="interval[monday]_id" path="intervalSettings.intervalDays[1]" value="true" disabled="${isEditingDenied}"/>
                            <mvc:message code="calendar.dayOfWeek.2"/>
                        </label>
                        <label class="checkbox-inline">
                            <mvc:checkbox id="interval[tuesday]_id" path="intervalSettings.intervalDays[2]" value="true" disabled="${isEditingDenied}"/>
                            <mvc:message code="calendar.dayOfWeek.3"/>
                        </label>
                        <label class="checkbox-inline">
                            <mvc:checkbox id="interval[wednesday]_id" path="intervalSettings.intervalDays[3]" value="true" disabled="${isEditingDenied}"/>
                            <mvc:message code="calendar.dayOfWeek.4"/>
                        </label>
                        <label class="checkbox-inline">
                            <mvc:checkbox id="interval[thursday]_id" path="intervalSettings.intervalDays[4]" value="true" disabled="${isEditingDenied}"/>
                            <mvc:message code="calendar.dayOfWeek.5"/>
                        </label>
                        <label class="checkbox-inline">
                            <mvc:checkbox id="interval[friday]_id" path="intervalSettings.intervalDays[5]" value="true" disabled="${isEditingDenied}"/>
                            <mvc:message code="calendar.dayOfWeek.6"/>
                        </label>
                        <label class="checkbox-inline">
                            <mvc:checkbox id="interval[saturday]_id" path="intervalSettings.intervalDays[6]" value="true" disabled="${isEditingDenied}"/>
                            <mvc:message code="calendar.dayOfWeek.7"/>
                        </label>
                        <label class="checkbox-inline">
                            <mvc:checkbox id="interval[sunday]_id" path="intervalSettings.intervalDays[0]" value="true" disabled="${isEditingDenied}"/>
                            <mvc:message code="calendar.dayOfWeek.1"/>
                        </label>
                    </div>
                </div>

                <div id="field-interval-months" class="form-group">
                    <div class="form-group">
                        <div class="col-sm-4 col-sm-push-4">
                            <mvc:select path="intervalSettings.numberOfMonth" cssClass="form-control js-select" disabled="${isEditingDenied}">
                                <c:forEach var="month" begin="1" end="12">
                                    <mvc:option value="${month}"><mvc:message code="default.every${month}Month"/></mvc:option>
                                </c:forEach>
                            </mvc:select>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-4 col-sm-push-4">
                            <mvc:select path="intervalSettings.dayOfMonth" cssClass="form-control" disabled="${isEditingDenied}">
                                <mvc:option value="1"><mvc:message code="firstDayOfMonth"/></mvc:option>
                                <c:forEach var="dayOfMonth" begin="2" end="31">
                                    <mvc:option value="${dayOfMonth}">${dayOfMonth}.</mvc:option>
                                </c:forEach>
                                <mvc:option value="99"><mvc:message code="ultimoDayOfMonth"/></mvc:option>
                            </mvc:select>
                        </div>
                    </div>
                </div>

                <div id="field-interval-time" class="form-group">
                    <div class="col-sm-4">
                        <label class="control-label">
                            <mvc:message code="default.Time"/>
                        </label>
                    </div>

                    <div class="col-sm-4">
                        <div class="input-group">
                            <div class="input-group-controls">
                                <mvc:text path="intervalSettings.intervalTime" cssClass="form-control js-timepicker" data-timepicker-options="mask: 'h:s'" disabled="${isEditingDenied}" />
                            </div>
                            <div class="input-group-addon">
                                <span class="addon"><i class="icon icon-clock-o"></i></span>
                            </div>
                        </div>
                        <p class="help-block"><mvc:message code="default.interval"/>: <mvc:message code="default.minutes.10"/></p>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-8 col-sm-push-4 ">
                        <a href="#" class="btn btn-regular btn-primary" data-form-target='#intervalSettingsForm' data-form-url='<c:url value="/mailing/send/interval.action"/>' data-form-submit>
                            <i class="icon icon-save"></i>
                            <span class="text"><mvc:message code="button.Save"/></span>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </mvc:form>
</emm:ShowByPermission>
