## $Id: browser.py 10823 2013-12-02 16:30:42Z henrik $
##
## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
"""UI components for basic applicants and related components.
"""
import grok
from hurry.workflow.interfaces import IWorkflowState
from zope.formlib.textwidgets import BytesDisplayWidget
from waeup.kofa.widgets.datewidget import (
    FriendlyDateDisplayWidget, FriendlyDateDisplayWidget,)
from waeup.kofa.applicants.browser import (
    ApplicantRegistrationPage, ApplicantsContainerPage)
from waeup.kofa.applicants.pdf import PDFApplicationSlip
from kofacustom.ekodisco.applicants.interfaces import (
    ICustomApplicant, ICustomApplicantEdit)
from kofacustom.nigeria.applicants.browser import (
    NigeriaApplicantDisplayFormPage,
    ApplicantDisplayFormPage,
    ApplicantManageFormPage,
    ApplicantEditFormPage)


from kofacustom.ekodisco.applicants.workflow import STARTED

from kofacustom.ekodisco.interfaces import MessageFactory as _

class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage):
    """A display view for applicant data.
    """
    grok.template('applicantdisplaypage')

    form_fields = grok.AutoFields(ICustomApplicant).omit(
        'locked', 'course_admitted', 'password', 'suspended',
        'course2', 'notice', 'student_id', 'sex')

    form_fields['perm_address'].custom_widget = BytesDisplayWidget
    form_fields['service_address'].custom_widget = BytesDisplayWidget

class CustomApplicantManageFormPage(ApplicantManageFormPage):
    """A full edit view for applicant data.
    """
    grok.template('applicanteditpage')

    form_fields = grok.AutoFields(ICustomApplicant).omit(
        'course2', 'notice', 'student_id', 'sex')
    form_fields['applicant_id'].for_display = True

class CustomApplicantEditFormPage(ApplicantEditFormPage):
    """An applicant-centered edit view for applicant data.
    """
    grok.template('applicanteditpage')

    form_fields = grok.AutoFields(ICustomApplicantEdit).omit(
        'locked', 'course_admitted', 'student_id',
        'suspended', 'course2', 'notice', 'sex'
        )
    form_fields['applicant_id'].for_display = True
    form_fields['reg_number'].for_display = True

    submit_state = STARTED

    @property
    def display_actions(self):
        state = IWorkflowState(self.context).getState()
        actions = [[],[]]
        if state == STARTED:
            actions = [[_('Save'), _('Final Submit')], []]
        return actions

class CustomPDFApplicationSlip(PDFApplicationSlip):
    """Bypass NigeriaPDFApplicationSlip
    """

    form_fields =  grok.AutoFields(ICustomApplicant).omit(
        'locked', 'course_admitted', 'suspended', 'sex', 'course2'
        )
    form_fields['date_of_birth'].custom_widget = FriendlyDateDisplayWidget('le')