## $Id: viewlets.py 15700 2019-10-24 09:19:46Z 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
##

import grok
from zope.component import getUtility
from waeup.kofa.interfaces import REQUESTED
from waeup.kofa.browser.viewlets import ManageActionButton
from waeup.kofa.students.interfaces import IStudentsUtils, IStudent
from waeup.kofa.students.fileviewlets import (
    StudentFileDisplay, StudentFileUpload, StudentImage)
from waeup.kofa.students.workflow import PAID
from waeup.kofa.students.browser import (
    ExportPDFClearanceSlip, StudyCourseDisplayFormPage,
    StudyLevelDisplayFormPage, StudentBaseDisplayFormPage)
from kofacustom.dspg.students.interfaces import (
    ICustomStudentStudyCourse, ICustomStudentStudyLevel)

from kofacustom.nigeria.interfaces import MessageFactory as _

class GetMatricNumberActionButton(ManageActionButton):
    grok.order(10)
    grok.context(IStudent)
    grok.view(StudentBaseDisplayFormPage)
    grok.require('waeup.viewStudent')
    #grok.require('waeup.manageStudent')
    icon = 'actionicon_count.png'
    text = _('Get Matriculation Number')

    @property
    def target_url(self):
        students_utils = getUtility(IStudentsUtils)
        if self.context.matric_number:
            return ''
        error, matric_number = students_utils.constructMatricNumber(
            self.context)
        if error:
            return ''
        return self.view.url(self.view.context, 'get_matric_number')

class MatricNumberSlipActionButton(ManageActionButton):
    grok.order(10)
    grok.context(IStudent)
    grok.view(StudentBaseDisplayFormPage)
    grok.require('waeup.viewStudent')
    icon = 'actionicon_pdf.png'
    text = _('Download matriculation number slip')
    target = 'matric_number_slip.pdf'

    @property
    def target_url(self):
        if self.context.state not in (PAID,) or not self.context.is_fresh \
            or not self.context.matric_number:
            return ''
        return self.view.url(self.view.context, self.target)

# ND Result

class NDResultDisplay(StudentFileDisplay):
    """ND Result display viewlet.
    """
    grok.order(19)
    label = _(u'ND Result')
    title = _(u'ND Result')
    download_name = u'nd_result'

class NDResultSlip(NDResultDisplay):
    grok.view(ExportPDFClearanceSlip)

class NDResultUpload(StudentFileUpload):
    """ND Result upload viewlet.
    """
    grok.order(19)
    label = _(u'ND Result')
    title = _(u'ND Result Scan')
    download_name = u'nd_result'

    @property
    def show_viewlet(self):
        students_utils = getUtility(IStudentsUtils)
        if self.__name__ in students_utils.SKIP_UPLOAD_VIEWLETS:
            return False
        cm = getattr(self.context,'current_mode', None)
        return cm and cm.startswith('hnd')

class NDResultImage(StudentImage):
    """Renders ND Result scan.
    """
    grok.name('nd_result')
    download_name = u'nd_result'

# O Level Result

class OLevelResultDisplay(StudentFileDisplay):
    """O Level Result display viewlet.
    """
    grok.order(19)
    label = _(u'O Level Result')
    title = _(u'O Level Result')
    download_name = u'o_level_result'

class OLevelResultSlip(OLevelResultDisplay):
    grok.view(ExportPDFClearanceSlip)

class OLevelResultUpload(StudentFileUpload):
    """O Level Result upload viewlet.
    """
    grok.order(19)
    label = _(u'O Level Result')
    title = _(u'O Level Result Scan')
    download_name = u'o_level_result'

class OLevelResultImage(StudentImage):
    """Renders O Level Result scan.
    """
    grok.name('o_level_result')
    download_name = u'o_level_result'

# O Level Result 2

class OLevelResult2Display(StudentFileDisplay):
    """O Level Result 2 display viewlet.
    """
    grok.order(19)
    label = _(u'O Level Result 2')
    title = _(u'O Level Result 2')
    download_name = u'o_level_result_2'

class OLevelResult2Slip(OLevelResult2Display):
    grok.view(ExportPDFClearanceSlip)

class OLevelResult2Upload(StudentFileUpload):
    """O Level Result 2 upload viewlet.
    """
    grok.order(19)
    label = _(u'O Level Result 2')
    title = _(u'O Level Result Scan 2')
    download_name = u'o_level_result_2'

class OLevelResult2Image(StudentImage):
    """Renders O Level Result 2 scan.
    """
    grok.name('o_level_result_2')
    download_name = u'o_level_result_2'

# IT Letter

class ITLetterDisplay(StudentFileDisplay):
    """IT Letter display viewlet.
    """
    grok.order(19)
    label = _(u'IT Letter')
    title = _(u'IT Letter')
    download_name = u'it_letter'

class ITLetterSlip(ITLetterDisplay):
    grok.view(ExportPDFClearanceSlip)

class ITLetterUpload(StudentFileUpload):
    """IT Letter upload viewlet.
    """
    grok.order(19)
    label = _(u'IT Letter')
    title = _(u'IT Letter Scan')
    download_name = u'it_letter'

    @property
    def show_viewlet(self):
        students_utils = getUtility(IStudentsUtils)
        if self.__name__ in students_utils.SKIP_UPLOAD_VIEWLETS:
            return False
        cm = getattr(self.context,'current_mode', None)
        return cm and cm.startswith('hnd')

class ITLetterImage(StudentImage):
    """Renders IT Letter scan.
    """
    grok.name('it_letter')
    download_name = u'it_letter'

# JAMB Result

class JAMBResultDisplay(StudentFileDisplay):
    """JAMB Result display viewlet.
    """
    grok.order(19)
    label = _(u'JAMB Result')
    title = _(u'JAMB Result')
    download_name = u'jamb_result'

class JAMBResultSlip(JAMBResultDisplay):
    grok.view(ExportPDFClearanceSlip)

class JAMBResultUpload(StudentFileUpload):
    """JAMB Result upload viewlet.
    """
    grok.order(19)
    title = _(u'JAMB Result Scan')
    download_name = u'jamb_result'

    @property
    def label(self):
        cm = getattr(self.context,'current_mode', None)
        if cm and cm.startswith('hnd'):
            return u'JAMB Result / ND Admission Letter (optional)'
        else:
            return u'JAMB Result'

class JAMBResultImage(StudentImage):
    """Renders JAMB Result scan.
    """
    grok.name('jamb_result')
    download_name = u'jamb_result'

# Additional Document

class AdditionalDocDisplay(StudentFileDisplay):
    """Additional Document display viewlet.
    """
    grok.order(19)
    label = _(u'Additional Document')
    title = _(u'Additional Document')
    download_name = u'additional_doc'

class AdditionalDocSlip(AdditionalDocDisplay):
    grok.view(ExportPDFClearanceSlip)

class AdditionalDocUpload(StudentFileUpload):
    """Additional Document upload viewlet.
    """
    grok.order(19)
    title = _(u'Additional Document Scan')
    download_name = u'additional_doc'
    label = _(u'Additional Document')

class AdditionalDocImage(StudentImage):
    """Renders Additional Document scan.
    """
    grok.name('additional_doc')
    download_name = u'additional_doc'
