# coding: utf-8
'''
Created on 27.07.2015

☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦
@author: tr0glo)|(I╠╣
☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦☦
'''
from ru.curs.celesta.showcase.utils import XMLJSONConverter
import json

def startDatapanel(context, main=None, session=None):
    u'''Датапанель стартовой страницы тестирования'''
    data = {"datapanel":
                {"tab": []}}

    tab1 = {"@id":"1",
             "@name":u"Карточка теста",
             "element":
                 []
                 }

    startCard = {"@id":'4',
                 "@type":"xforms",
                 "@proc":"qt.xform.startCard.cardData.cl",
                 "@template":'startCard.xml',
                 "proc":
                [
                 {"@id":'proc1',
                  "@name":"qt.xform.startCard.cardDataSave.cl",
                  "@type":"SAVE"
                  }
                  ]
                 }    

    tab1['element'].append(startCard)

    data['datapanel']['tab'].extend([tab1])    
#    raise Exception(converterInstString.parse())
    return XMLJSONConverter.jsonToXml(json.dumps(data))
    

def finishDatapanel(context, main=None, session=None):
    u'''Датапанель результатов тестирования'''
    data = {"datapanel":
                {"tab": []}}

    tab1 = {"@id":"1",
             "@name":u"Завершение тестирования",
             "element":
                 []
                 }

    finishCard = {"@id":'4',
                 "@type":"xforms",
                 "@proc":"qt.xform.finishCard.cardData.cl",
                 "@template":'finishCard.xml'
                 }    

    tab1['element'].append(finishCard)

    data['datapanel']['tab'].extend([tab1])    
#    raise Exception(converterInstString.parse())
    return XMLJSONConverter.jsonToXml(json.dumps(data))


def contentDatapanel(context, main=None, session=None):
    u'''Датапанель списка вопросов'''
    data = {"datapanel":
                {"tab": []}}
                
    tab1 = {"@id":"1",
             "@name":u"Оглавление теста",
             "element":
                 []
                 }
                 
    contentCard = {"@id":'4',
                 "@type":"xforms",
                 "@proc":"qt.xform.contentCard.cardData.cl",
                 "@template":'contentForm.xml'
                 }    

    tab1['element'].append(contentCard)

    data['datapanel']['tab'].extend([tab1])    
#    raise Exception(converterInstString.parse())
    return XMLJSONConverter.jsonToXml(json.dumps(data))


def simpleQuestionDatapanel(context, main=None, session=None):
    u'''Датапанель вопроса с одиночным выбором'''
    data = {"datapanel":
                {"tab": []}}

    tab1 = {"@id":"1",
             "@name":u"Вопрос",
             "element":
                 []
                 }

    simpleCard = {"@id":'4',
                 "@type":"xforms",
                  "@proc":"qt.xform.simpleCard.cardData.cl",
#                  "@proc":'simpleCard',
                 "@template":'simpleCard.xml',
                 "proc":
                [
                 {"@id":'proc1',
                  "@name":"qt.xform.simpleCard.cardDataSave.cl",
                  "@type":"SAVE"
                  }
                  ]
                 }    

    tab1['element'].append(simpleCard)

    data['datapanel']['tab'].extend([tab1])    
#    raise Exception(converterInstString.parse())
    return XMLJSONConverter.jsonToXml(json.dumps(data))


def multiQuestionDatapanel(context, main=None, session=None):
    u'''Датапанель вопроса с множественным выбором'''
    data = {"datapanel":
                {"tab": []}}

    tab1 = {"@id":"1",
             "@name":u"Вопрос",
             "element":
                 []
                 }

    multiCard = {"@id":'4',
                 "@type":"xforms",
                 "@proc":"qt.xform.simpleCard.cardData.cl",
                 "@template":'multiCard.xml',
                 "proc":
                [
                 {"@id":'proc1',
                  "@name":"qt.xform.simpleCard.cardDataSave.cl",
                  "@type":"SAVE"
                  }
                  ]
                 }    

    tab1['element'].append(multiCard)

    data['datapanel']['tab'].extend([tab1])    
#    raise Exception(converterInstString.parse())
    return XMLJSONConverter.jsonToXml(json.dumps(data))


def textQuestionDatapanel(context, main=None, session=None):
    u'''Датапанель текстового вопроса'''
    data = {"datapanel":
                {"tab": []}}

    tab1 = {"@id":"1",
             "@name":u"Вопрос",
             "element":
                 []
                 }

    textCard = {"@id":'4',
                 "@type":"xforms",
                 "@proc":"qt.xform.textCard.cardData.cl",
                 "@template":'textCard.xml',
                 "proc":
                [
                 {"@id":'proc1',
                  "@name":"qt.xform.simpleCard.cardDataSave.cl",
                  "@type":"SAVE"
                  }
                  ]
                 }    

    tab1['element'].append(textCard)

    data['datapanel']['tab'].extend([tab1])    
#    raise Exception(converterInstString.parse())
    return XMLJSONConverter.jsonToXml(json.dumps(data))


def corrQuestionDatapanel(context, main=None, session=None):
    u'''Датапанель вопроса-сопоставления'''
    data = {"datapanel":
                {"tab": []}}

    tab1 = {"@id":"1",
             "@name":u"Вопрос",
             "element":
                 []
                 }

    corrCard = {"@id":'4',
                 "@type":"xforms",
                 "@proc":"qt.xform.corrCard.cardData.cl",
                 "@template":'corrCard.xml',
                 "proc":
                [
                 {"@id":'proc1',
                  "@name":"qt.xform.simpleCard.cardDataSave.cl",
                  "@type":"SAVE"
                  }
                  ]
                 }    

    tab1['element'].append(corrCard)

    data['datapanel']['tab'].extend([tab1])    
#    raise Exception(converterInstString.parse())
    return XMLJSONConverter.jsonToXml(json.dumps(data))

def sortQuestionDatapanel(context, main=None, session=None):
    u'''Датапанель вопроса-сортировки'''
    data = {"datapanel":
                {"tab": []}}

    tab1 = {"@id":"1",
             "@name":u"Вопрос",
             "element":
                 []
                 }

    sortCard = {"@id":'4',
                 "@type":"xforms",
                 "@proc":"qt.xform.sortCard.cardData.cl",
#                   "@proc":"sortCard",
                 "@template":'sortCard.xml',
                 "proc":
                [
                 {"@id":'proc1',
#                   "@name":'xforms_savesimple',
                "@name":"qt.xform.simpleCard.cardDataSave.cl",
                  "@type":"SAVE"
                  }
                  ]
                 }    

    tab1['element'].append(sortCard)

    data['datapanel']['tab'].extend([tab1])    
#    raise Exception(converterInstString.parse())
    return XMLJSONConverter.jsonToXml(json.dumps(data))


def classificationQuestionDatapanel(context, main=None, session=None):
    u'''Датапанель вопроса-классификации'''
    data = {"datapanel":
                {"tab": []}}

    tab1 = {"@id":"1",
             "@name":u"Вопрос",
             "element":
                 []
                 }

    sortCard = {"@id":'4',
                 "@type":"xforms",
#                 "@proc":"classifCard",
                  "@proc":"qt.xform.classificationCard.cardData.cl",
                 "@template":'classifCard.xml',
                 "proc":
                [
                 {"@id":'proc1',
#                   "@name":'xforms_savesimple',
                 "@name":"qt.xform.simpleCard.cardDataSave.cl",
                  "@type":"SAVE"
                  }
                  ]
                 }    

    tab1['element'].append(sortCard)

    data['datapanel']['tab'].extend([tab1])    
#    raise Exception(converterInstString.parse())
    return XMLJSONConverter.jsonToXml(json.dumps(data))


def capDatapanel(context, main=None, session=None):
    u'''Датапанель для заглушки'''
    data = {"datapanel":
                {"tab": []}}

    tab1 = {"@id":"1",
             "@name":u"Каталог",
             "element":
                 []
                 }

    capText = {"@id":'4',
                 "@type":"webtext",
                 "@proc":"qt.webtext.cap.webtextData.cl"                 
                 }    

    tab1['element'].append(capText)

    data['datapanel']['tab'].extend([tab1])    
#    raise Exception(converterInstString.parse())
    return XMLJSONConverter.jsonToXml(json.dumps(data))
    
    
def simpleImageMapQuestionDatapanel(context, main=None, session=None):
    u'''Датапанель вопроса с одиночным выбором по изображению-карте'''
    data = {"datapanel":
                {"tab": []}}

    tab1 = {"@id":"1",
             "@name":u"Вопрос",
             "element":
                 []
                 }
    
    simpleCard = {"@id":'4',
                 "@type":"xforms",
                  "@proc":"qt.xform.simpleImageMapCard.cardData.cl",
#                  "@proc":'simpleCard',
                 "@template":'simpleImageMapCard.xml',
                 "proc":
                [
                 {"@id":'proc1',
                  "@name":"qt.xform.simpleImageMapCard.cardDataSave.cl",
                  "@type":"SAVE"
                  }
                  ]
                 }

    imageCard = {"@id":'imageMapCard',
                 "@type":"xforms",
                 "@proc":"qt.xform.imageCard.cardData.cl",
                 "@template":'imageCard.xml'}
    
    tab1['element'].append(simpleCard)
    tab1['element'].append(imageCard)

    data['datapanel']['tab'].extend([tab1])    
#    raise Exception(converterInstString.parse())
    return XMLJSONConverter.jsonToXml(json.dumps(data))    
