## $Id: fileviewlets.py 14203 2016-09-29 07:17:39Z henrik $
##
## Copyright (C) 2014 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 waeup.ikoba.interfaces import MessageFactory as _

from waeup.ikoba.browser.fileviewlets import (
    FileDisplay, FileUpload, Image)

from ikobacustom.uniben.customers.documents import (
    UnibenCustomerPDFDocument,
    UnibenCustomerJPGDocument)

from waeup.ikoba.customers.browser import (
    DocumentDisplayFormPage,
    DocumentManageFormPage,
    DocumentEditFormPage,
    PDFDocumentSlip,)

grok.templatedir('browser_templates')

# File viewlets for customer documents

class JPGScanManageUpload(FileUpload):
    """Scan upload viewlet for officers.
    """
    grok.order(1)
    grok.context(UnibenCustomerJPGDocument)
    grok.view(DocumentManageFormPage)
    grok.require('waeup.manageCustomer')
    label = _(u'JPG File')
    title = _(u'JPG File')
    mus = 1024 * 1000
    download_name = u'scan.jpg'
    tab_redirect = '#tab2'

    @property
    def download_filename(self):
        return u"%s.jpg" % self.context.document_id[:9]


class JPGScanEditUpload(JPGScanManageUpload):
    """Scan upload viewlet for customer.
    """
    grok.view(DocumentEditFormPage)
    grok.require('waeup.handleCustomer')


class JPGScanDisplay(FileDisplay):
    """Scan display viewlet.
    """
    grok.order(1)
    grok.context(UnibenCustomerJPGDocument)
    grok.require('waeup.viewCustomer')
    grok.view(DocumentDisplayFormPage)
    label = _(u'JPG File')
    title = _(u'JPG File')
    download_name = u'scan.jpg'

    @property
    def download_filename(self):
        return u"%s.jpg" % self.context.document_id[:9]


class JPGScanImage(Image):
    """Scan document.
    """
    grok.name('scan.jpg')
    grok.context(UnibenCustomerJPGDocument)
    grok.require('waeup.viewCustomer')
    download_name = u'scan.jpg'

    @property
    def download_filename(self):
        return u"%s.jpg" % self.context.document_id[:9]

class JPGScanPDFSlip(JPGScanDisplay):
    grok.view(PDFDocumentSlip)


class PDFScanManageUpload(FileUpload):
    """Scan upload viewlet for officers.
    """
    grok.view(DocumentManageFormPage)
    grok.context(UnibenCustomerPDFDocument)
    grok.require('waeup.manageCustomer')
    label = _(u'PDF File')
    title = _(u'PDF File')
    mus = 1024 * 1000
    download_name = u'scan.pdf'
    tab_redirect = '#tab2'

    @property
    def download_filename(self):
        return u"%s.pdf" % self.context.document_id[:9]


class PDFScanEditUpload(PDFScanManageUpload):
    """Scan upload viewlet for customer.
    """
    grok.view(DocumentEditFormPage)
    grok.require('waeup.handleCustomer')


class PDFScanDisplay(FileDisplay):
    """Scan display viewlet.
    """
    grok.order(1)
    grok.context(UnibenCustomerPDFDocument)
    grok.require('waeup.viewCustomer')
    grok.view(DocumentDisplayFormPage)
    label = _(u'PDF File')
    title = _(u'PDF File')
    download_name = u'scan.pdf'

    @property
    def download_filename(self):
        return u"%s.pdf" % self.context.document_id[:9]


class PDFScanImage(Image):
    """Scan document.
    """
    grok.name('scan.pdf')
    grok.context(UnibenCustomerPDFDocument)
    grok.require('waeup.viewCustomer')
    download_name = u'scan.pdf'

    @property
    def download_filename(self):
        return u"%s" % self.context.document_id[:9]

class PDFScanSlip(PDFScanDisplay):
    grok.view(PDFDocumentSlip)