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

def catalogDatapanel(context, main=None, session=None):
    catalogTab = {
        "@id":1,
        "@name":u"Темы БТЗ",
        "element":[                  
            {"@id": "webThemeGrid",
             "@type": "grid",
             "@subtype": "JS_LIVE_GRID",
             "@plugin": "liveDGrid",
             "@hideOnLoad": "false",
             "@proc": "author.grids.webThemeGrid.gridData.celesta",
             "proc": [
                {"@id": "webThemeGridBar",
                 "@name": "author.grids.webThemeGrid.gridToolBar.celesta",
                 "@type": "TOOLBAR"},                    
                {"@id":'webThemeGridMeta',
                 "@name":'author.grids.webThemeGrid.gridMeta.celesta',
                 "@type": 'METADATA'}]},                  
            {"@id":'createBtzFromAnotherBtzCard',
             "@type":"xforms",
             "@proc":"author.xform.createBtzFromAnotherBtzCard.cardData.celesta",
             "@template":'createBtzFromAnotherBtzCard.xml',
             "proc": {
                "@id":'save',
                "@name":"author.xform.createBtzFromAnotherBtzCard.cardSave.celesta",
                "@type":"SAVE"},
             "@hideOnLoad": "true",
             "related": {"@id": 'webThemeGrid'}},
            {"@id":"btzThemeCard",
             "@type":"xforms",
             "@template": "btzThemeCard.xml",
             "@neverShowInPanel":"true",
             "@proc":"author.xform.btzThemeCard.cardData.celesta",
             "proc": {
                "@id":"btzThemeCardSave",
                "@name":"author.xform.btzThemeCard.cardDataSave.celesta",
                "@type":"SAVE"},
             "related":{"@id":"webThemeGrid"}},                            
            {"@id":"webThemeDeleteCard",
             "@type":"xforms",
             "@template": "webThemeDeleteCard.xml",
             "@neverShowInPanel":"true",
             "@proc":"author.xform.webThemeDeleteCard.cardData.celesta",
             "proc": {
                "@id":"catalogData",
                "@name":"author.xform.webThemeDeleteCard.cardDataDelete.celesta",
                "@type":"SAVE"},
             "related": {"@id":"webThemeGrid"}},
            {"@id":"debugThemeCard",
             "@type":"xforms",
             "@template": "debugThemeCard.xml",
             "@neverShowInPanel":"true",
             "@proc":"author.xform.debugThemeCard.cardData.celesta",
             "proc": {
                "@id":"thmSave",
                "@name":"author.xform.debugThemeCard.cardDataSave.celesta",
                "@type":"SAVE"},
             "related":{"@id":"webThemeGrid"}}]}

    data = {"datapanel": { "tab": catalogTab }}
    
    return XMLJSONConverter.jsonToXml(json.dumps(data))


def catalogThemeDatapanel(context, main=None, session=None):
    catalogTab = {
        "@id":1,
        "@name":u"Вопросы темы",
        "element":[                 
            {"@id": "webQuestionGrid",
             "@type": "grid",
             "@subtype": "JS_LIVE_GRID",
             "@plugin": "liveDGrid",
             "@proc": "author.grids.webQuestionGrid.gridData.celesta",
             "proc": [
                {"@id": "webQuestionToolGridBar",
                 "@name": "author.grids.webQuestionGrid.gridToolBar.celesta",
                 "@type": "TOOLBAR"},                         
                {"@id":'webQuestionGridMeta',
                 "@name":'author.grids.webQuestionGrid.gridMeta.celesta',
                 "@type": 'METADATA'}]},
            {"@id": 'btzAnswerGrid',
             "@type":"grid",
             "@subtype":"JS_PAGE_GRID",
             "@plugin": "pageDGrid",
             "@proc":"author.grids.btzAnswerGrid.gridData.celesta",
             "@hideOnLoad":'true',
             "proc": [
                {"@id":'0001',
                 "@name":'author.grids.btzAnswerGrid.gridMeta.celesta',
                 "@type": 'METADATA'},
                {"@id":'0002',
                 "@name":"author.grids.btzAnswerGrid.gridToolBar.celesta",
                 "@type":"TOOLBAR"}],
             "related": [{"@id":'webQuestionGrid'}]},
#             {"@id":"btzThemeCard",
#              "@type":"xforms",
#              "@template": "btzThemeCard.xml",
#              "@neverShowInPanel":"true",
#              "@proc":"author.xform.btzThemeCard.cardData.celesta",
#              "proc": {
#                 "@id":"btzThemeCardSave",
#                 "@name":"author.xform.btzThemeCard.cardDataSave.celesta",
#                 "@type":"SAVE"},
#              "related":{"@id":"webThemeGrid"}},
#             {"@id":"debugThemeCard",
#              "@type":"xforms",
#              "@template": "debugThemeCard.xml",
#              "@neverShowInPanel":"true",
#              "@proc":"author.xform.debugThemeCard.cardData.celesta",
#              "proc": {
#                 "@id":"thmSave",
#                 "@name":"author.xform.debugThemeCard.cardDataSave.celesta",
#                 "@type":"SAVE"},
#              "related":{"@id":"webThemeGrid"}},
            {"@id":"webQuestionAddEditCard",
             "@type":"xforms",
             "@template": "webQuestionAddEditCard.xml",
             "@neverShowInPanel":"true",
             "@proc":"author.xform.webQuestionAddEditCard.cardData.celesta",
             "proc": {
                "@id":"catalogData",
                "@name":"author.xform.webQuestionAddEditCard.cardDataSave.celesta",
                "@type":"SAVE"},
             "related":[
                {"@id":"webQuestionGrid"}]},                            
            {"@id":"webQuestionDeleteCard",
             "@type":"xforms",
             "@template": "webQuestionDeleteCard.xml",
             "@neverShowInPanel":"true",
             "@proc":"author.xform.webQuestionDeleteCard.cardData.celesta",
             "proc": { 
                "@id":"catalogData",
                "@name":"author.xform.webQuestionDeleteCard.cardDataDelete.celesta",
                "@type":"SAVE"},
             "related": [
                {"@id":"webQuestionGrid"}]},
            {"@id":"btzAnswersCard",
             "@type":"xforms",
             "@template": "btzAnswersCard.xml",
             "@neverShowInPanel":"true",
             "@proc":"author.xform.btzAnswersCard.cardData.celesta",
             "proc": {
                "@id":"btzAnswersCardSave",
                "@name":"author.xform.btzAnswersCard.cardSave.celesta",
                "@type":"SAVE"},
             "related": [
                {"@id":"webQuestionGrid"}]},
            {"@id":"debugQuestionCard",
             "@type":"xforms",
             "@template": "debugQuestionCard.xml",
             "@neverShowInPanel":"true",
             "@proc":"author.xform.debugQuestionCard.cardData.celesta",
             "proc": {
                "@id":"qstSave",
                "@name":"author.xform.debugThemeCard.cardDataSave.celesta",
                "@type":"SAVE"},
             "related":{"@id":"webQuestionGrid"}}]}

    data = {"datapanel": { "tab": catalogTab }}
    
    return XMLJSONConverter.jsonToXml(json.dumps(data))
