# coding:utf-8
import json
from ru.curs.celesta.showcase.utils import XMLJSONConverter

def catalogDatapanel(context, main=None, session=None):
    data = {"datapanel": {"tab": []}}

    tab1 = {"@id":1,
             "@name":u"Каталог БТЗ",
             "element": []}
    btzFilter = {"@id":'btzFilter',
                 "@type":"xforms",
                 "@proc":"author.xform.btzFilter.cardData.celesta",
                 "@template":'btzFilter.xml'}

    btzCatalogGrid = {"@id": 'btzCatalogGrid',
                 "@type":"grid",
                 "@subtype":"JS_PAGE_GRID",
                 "@plugin": "pageDGrid",
                 "@proc":"author.grids.btzCatalogGrid.gridData.celesta",
                 "@hideOnLoad":'true',
                 "proc":
                    [{"@id":'btzCatalogGridToolBar',
                      "@name":"author.grids.btzCatalogGrid.gridToolBar.celesta",
                      "@type":"TOOLBAR"},                     
                    {"@id":'btzCatalogGridMeta',
                     "@name":'author.grids.btzCatalogGrid.gridMeta.celesta',
                     "@type": 'METADATA'}],
                 "related": [{"@id":'btzFilter'}]}
    
    btzUpload = {"@id": "uploadBtzCard",
                "@type": "xforms",
                "@template": "uploadExcelBtz.xml",
                "@proc": "author.xform.uploadBtzCard.cardData.cl",
                "@neverShowInPanel": "true",
                "@hideOnLoad": "true",
                "proc": [
                    {"@id": 'uploadFile',
                     "@name": "author.xform.uploadBtzCard.attachmentUpload.cl",
                     "@type": "UPLOAD"},
                    {"@id": "0004",
                     "@name": "author.xform.uploadBtzCard.cardDataSave.cl",
                     "@type": "SAVE"}],
                "related": {"@id": 'btzCatalogGrid'}}
    
    btzArchiveUpload = {"@id": "uploadBtzArchiveCard",
                "@type": "xforms",
                "@template": "uploadBtzArchive.xml",
                "@proc": "author.xform.uploadBtzArchiveCard.cardData.cl",
                "@neverShowInPanel": "true",
                "@hideOnLoad": "true",
                "proc": [
                    {"@id": 'uploadArchive',
                     "@name": "author.xform.uploadBtzArchiveCard.archiveUpload.cl",
                     "@type": "UPLOAD"},
                    {"@id": "0005",
                     "@name": "author.xform.uploadBtzArchiveCard.cardDataSave.cl",
                     "@type": "SAVE"}],
                "related": {"@id": 'btzCatalogGrid'}}
        
    btzExcelUpload = {"@id": "uploadBtzExcelCard",
                "@type": "xforms",
                "@template": "uploadBtz.xml",
                "@proc": "author.xform.uploadBtzExcelCard.cardData.cl",
                "@neverShowInPanel": "true",
                "@hideOnLoad": "true",
                "proc": [
                    {"@id": 'uploadFile',
                     "@name": "author.xform.uploadBtzExcelCard.attachmentUpload.cl",
                     "@type": "UPLOAD"},
                    {"@id": "0004",
                     "@name": "author.xform.uploadBtzExcelCard.cardDataSave.cl",
                     "@type": "SAVE"}],
                "related": {"@id": 'btzCatalogGrid'}}
    
    btzDownload = {"@id": "downloadBtzCard",
                "@type": "xforms",
                "@template": "downloadBtz.xml",
                "@proc": "author.xform.downloadBtzCard.cardData.cl",
                "@neverShowInPanel": "true",
                "@hideOnLoad": "true",
                "proc": [
                    {"@id": 'downloadBtz',
                     "@name": "author.xform.downloadBtzCard.downloadBtzCard.cl",
                     "@type": "DOWNLOAD"},
                    {"@id": "0005",
                     "@name": "author.xform.downloadBtzCard.cardDataSave.cl",
                     "@type": "SAVE"}],
                "related": {"@id": 'btzCatalogGrid'}}     
    
    btzExcelDownload = {"@id": "downloadBtzExcelCard",
                "@type": "xforms",
                "@template": "downloadBtz.xml",
                "@proc": "author.xform.downloadBtzExcelCard.cardData.cl",
                "@neverShowInPanel": "true",
                "@hideOnLoad": "true",
                "proc": [
                    {"@id": 'downloadBtz',
                     "@name": "author.xform.downloadBtzExcelCard.downloadBtzCard.cl",
                     "@type": "DOWNLOAD"},
                    {"@id": "0005",
                     "@name": "author.xform.downloadBtzExcelCard.cardDataSave.cl",
                     "@type": "SAVE"}],
                "related": {"@id": 'btzCatalogGrid'}}     
 
    btzAttributesGrid = {"@id": 'btzAttributesGrid',
                 "@type":"grid",
                 "@subtype":"JS_PAGE_GRID",
                 "@plugin": "pageDGrid",
                 "@proc":"author.grids.btzAttributesGrid.gridData.celesta",
                 "@hideOnLoad":'true',
                 "proc": [
                    {"@id":'0001',
                     "@name":'author.grids.btzAttributesGrid.gridMeta.celesta',
                     "@type": 'METADATA'},
                     {"@id":'0002',
                      "@name":"author.grids.btzAttributesGrid.gridToolBar.celesta",
                      "@type":"TOOLBAR"}],
                 "related": [
                    {"@id":'btzCatalogGrid'},
                    {"@id":'btzFilter'}]}
    
    btzAttributesAddEditCard = {"@id":"btzAttributesAddEditCard",
                    "@type":"xforms",
                    "@template": "btzAttributesAddEditCard.xml",
                    "@neverShowInPanel":"true",
                    "@proc":"author.xform.btzAttributesAddEditCard.cardData.celesta",
                    "proc": {
                        "@id":"catalogData",
                        "@name":"author.xform.btzAttributesAddEditCard.cardDataSave.celesta",
                        "@type":"SAVE"},
                    "related": [
                        {"@id":"btzCatalogGrid"},
                        {"@id":"btzAttributesGrid"}]}
    
    btzAttributesDeleteCard = {"@id":"btzAttributesDeleteCard",
                    "@type":"xforms",
                    "@template": "btzAttributesDeleteCard.xml",
                    "@neverShowInPanel":"true",
                    "@proc":"author.xform.btzAttributesDeleteCard.cardData.celesta",
                    "proc": {
                        "@id":"btzAttributeDelData",
                        "@name":"author.xform.btzAttributesDeleteCard.cardDataDelete.celesta",
                        "@type":"SAVE"},
                    "related":[
                        {"@id":"btzAttributesGrid"},
                        {"@id":"btzCatalogGrid"}]}
 
    createBtzCopyCard = {"@id":'createBtzCopyCard',
                 "@type":"xforms",
                 "@proc":"author.xform.createBtzCopyCard.cardData.celesta",
                 "@template":'createBtzCopyCard.xml',
                 "proc":
                     {"@id":'save',
                      "@name":"author.xform.createBtzCopyCard.cardSave.celesta",
                      "@type":"SAVE"
                      },
                "@hideOnLoad": "true",
                "related": {"@id": 'btzCatalogGrid'}
                 }
     
    setGlobalSettingsCard = {"@id":'setGlobalSettingsCard',
                 "@type":"xforms",
                 "@proc":"author.xform.setGlobalSettingsCard.cardData.celesta",
                 "@template":'setGlobalSettingsCard.xml',
                 "proc":
                     {"@id":'save',
                      "@name":"author.xform.setGlobalSettingsCard.cardSave.celesta",
                      "@type":"SAVE"
                      },
                "@hideOnLoad": "true",
                "related": {"@id": 'btzCatalogGrid'}
                 }
# 
    addBtzCard = {"@id":'addBtzCard',
                 "@type":"xforms",
                 "@proc":"author.xform.addBtzCard.cardData.celesta",
                 "@template":'addBtzCard.xml',
                 "proc":
                     {"@id":'save',
                      "@name":"author.xform.addBtzCard.cardSave.celesta",
                      "@type":"SAVE"
                      },
                "@hideOnLoad": "true",
                "related": {"@id": 'btzCatalogGrid'}
                 }
 
    delBtzCard = {"@id":'delBtzCard',
                 "@type":"xforms",
                 "@proc":"author.xform.delBtzCard.cardData.celesta",
                 "@template":'delElementStandardCard.xml',
                 "proc":
                     {"@id":'save',
                      "@name":"author.xform.delBtzCard.cardSave.celesta",
                      "@type":"SAVE"
                      },
                "@hideOnLoad": "true",
                "related": {"@id": 'btzCatalogGrid'}
                 }

    createBtzFromManyBtzCard = {"@id":'createBtzFromManyBtzCard',
                 "@type":"xforms",
                 "@proc":"author.xform.createBtzFromManyBtzCard.cardData.celesta",
                 "@template":'createBtzFromManyBtzCard.xml',
                 "proc":
                     {"@id":'save',
                      "@name":"author.xform.createBtzFromManyBtzCard.cardSave.celesta",
                      "@type":"SAVE"
                      },
                "@hideOnLoad": "true",
                "related": {"@id": 'btzCatalogGrid'}
                 }

    changeBtzStatusCard = {"@id":'changeBtzStatusCard',
                 "@type":"xforms",
                 "@proc":"author.xform.changeStatusCard.cardData.celesta",
                 "@template":'changeStatusCard.xml',
                 "proc":
                     {"@id":'save',
                      "@name":"author.xform.changeStatusCard.cardSave.celesta",
                      "@type":"SAVE"
                      },
                "@hideOnLoad": "true",
                "related": {"@id": 'btzCatalogGrid'}
                 }

    publishBtzCard = {"@id":'publishBtzCard',
                 "@type":"xforms",
                 "@proc":"author.xform.publishBtzCard.cardData.celesta",
                 "@template":'publishBtzCard.xml',
                 "@neverShowInPanel":"true",
                 "proc":
                     {"@id":'save',
                      "@name":"author.xform.publishBtzCard.cardSave.celesta",
                      "@type":"SAVE"
                      },
                "@hideOnLoad": "true",
                "related": {"@id": 'btzCatalogGrid'}
                 }
    
    testBtzCard = {"@id":'testBtzCard',
             "@type":"xforms",
             "@proc":"author.xform.testBtzCard.cardData.celesta",
             "@template":'testBtzCard.xml',
             "@neverShowInPanel":"true",
             "proc":
                 {"@id":'save',
                  "@name":"author.xform.testBtzCard.cardSave.celesta",
                  "@type":"SAVE"
                  },
            "@hideOnLoad": "true",
            "related": {"@id": 'btzCatalogGrid'}
             }
    
    createVariantsCard = {"@id":'createVariantsCard',
         "@type":"xforms",
         "@proc":"author.xform.createVariantsCard.cardData.celesta",
         "@template":'createVariantsCard.xml',
         "@neverShowInPanel":"true",
         "proc": [
            {"@id": 'downloadCreatedVariantBtz',
             "@name": "author.xform.createVariantsCard.downloadVariantCard.cl",
             "@type": "DOWNLOAD"},
             {"@id":'save',
              "@name":"author.xform.createVariantsCard.cardSave.celesta",
              "@type":"SAVE"}],
         "@hideOnLoad": "true",
         "related": {"@id": 'btzCatalogGrid'}}

    tab1['element'].append(btzFilter)
    tab1['element'].append(btzCatalogGrid)
    tab1['element'].append(btzAttributesGrid)    
    tab1['element'].append(btzAttributesAddEditCard)
    tab1['element'].append(btzAttributesDeleteCard)
    tab1['element'].append(createBtzCopyCard)
    tab1['element'].append(setGlobalSettingsCard)
    tab1['element'].append(delBtzCard)
    tab1['element'].append(createBtzFromManyBtzCard)
    tab1['element'].append(addBtzCard)
    tab1['element'].append(changeBtzStatusCard)
    tab1['element'].append(publishBtzCard)
    tab1['element'].append(testBtzCard)
    tab1['element'].append(btzUpload)
    tab1['element'].append(btzArchiveUpload)
    tab1['element'].append(btzExcelUpload)
    tab1['element'].append(btzDownload)
    tab1['element'].append(btzExcelDownload)
    tab1['element'].append(createVariantsCard)

    data['datapanel']['tab'].extend([tab1])
    
    return XMLJSONConverter.jsonToXml(json.dumps(data))


def catalogLectureDatapanel(context, main=None, session=None):
    data = {"datapanel": {"tab": []}}

    tab1 = {"@id": 1,
            "@name": u"Каталог лекций",
            "element": []}    
    
    lecturesGrid = {"@id": 'lecturesGrid',
             "@type":"grid",
             "@subtype":"JS_PAGE_GRID",
             "@plugin": "pageDGrid",
             "@proc":"author.grids.lecturesGrid.gridData.celesta",
             "@hideOnLoad":'false',
             "proc": [
                {"@id":'lecturesGridToolBar',
                 "@name":"author.grids.lecturesGrid.gridToolBar.celesta",
                 "@type":"TOOLBAR"},                 
                {"@id": 'lecturesGridMeta',
                "@name": 'author.grids.lecturesGrid.gridMeta.celesta',
                "@type": 'METADATA'}]}
    
    lectureCard = {'@id': 'lectureCard',
            '@type': 'xforms',
            '@proc': 'author.xform.lectureCard.cardData.celesta',
            '@template': 'lectureCard.xml',
            '@neverShowInPanel': 'true',
            'proc': {
                '@id': 'lectureCardSave',
                '@name': 'author.xform.lectureCard.cardSave.celesta',
                '@type': 'SAVE'},
            'related': {'@id': 'lecturesGrid'}}
    
    tab1['element'].append(lecturesGrid)
    tab1['element'].append(lectureCard)
    data['datapanel']['tab'].extend([tab1])
    
    return XMLJSONConverter.jsonToXml(json.dumps(data))
    
    
def catalogPracticalDatapanel(context, main=None, session=None):
    data = {"datapanel": {"tab": []}}

    tab1 = {"@id": 1,
            "@name": u"Каталог практических занятий",
            "element": []}    
    
    practicalFilter = {"@id":'practicalFilter',
                 "@type":"xforms",
                 "@proc":"author.xform.practicalFilter.cardData.celesta",
                 "@template":'practicalFilter.xml'}
    
    practicalGrid = {"@id": 'practicalGrid',
             "@type":"grid",
             "@subtype":"JS_PAGE_GRID",
             "@plugin": "pageDGrid",
             "@proc":"author.grids.practicalGrid.gridData.celesta",
             "@hideOnLoad":'false',
             "proc": [
                {"@id":'practicalGridToolBar',
                 "@name":"author.grids.practicalGrid.gridToolBar.celesta",
                 "@type":"TOOLBAR"},                 
                {"@id": 'practicalGridMeta',
                "@name": 'author.grids.practicalGrid.gridMeta.celesta',
                "@type": 'METADATA'}],
            "related": [{"@id":'practicalFilter'}]}
    
    practicalCard = {'@id': 'practicalCard',
            '@type': 'xforms',
            '@proc': 'author.xform.practicalCard.cardData.celesta',
            '@template': 'practicalCard.xml',
            '@neverShowInPanel': 'true',
            'proc': {
                '@id': 'practicalCardSave',
                '@name': 'author.xform.practicalCard.cardSave.celesta',
                '@type': 'SAVE'},
            'related': {'@id': 'practicalGrid'}}
    
    htmlHint = {
        '@id': 'htmlHint',
        '@type': 'xforms',
        '@proc': 'author.xform.practicalCard.htmlData.celesta',
        '@template': 'practicalHTML.xml',
        '@hideOnLoad': 'true',
        'related': {'@id': 'practicalGrid'}}
    
    tab1['element'].append(practicalFilter)
    tab1['element'].append(practicalGrid)
    tab1['element'].append(practicalCard)
    tab1['element'].append(htmlHint)
    data['datapanel']['tab'].extend([tab1])
    
    return XMLJSONConverter.jsonToXml(json.dumps(data))

