# coding: utf-8
"""
Created on 09.02.2016

@author: m.prudyvus
"""

import json

from ru.curs.celesta.showcase.utils import XMLJSONConverter
from common.htmlhints.htmlHint import htmlHintElement

def datapanel(context, main=None, session=None):

    data = {'datapanel': {'tab': []
                          }
            }

    tab1 = {'@id': 1,
            '@name': u'Реестр аккредитационных центров',
            'element': []
            }

    accredCenterGrid = {'@id': 'accredCenterGrid',
                           '@type': 'grid',
                           '@subtype': 'JS_PAGE_GRID',
                           '@plugin': 'pageDGrid',
                           '@proc': 'nci.grid.accredCenterGrid.gridData.celesta',
                           '@hideOnLoad':'false',
                           'proc': [{'@id':'proc1',
                                     '@name':'nci.grid.accredCenterGrid.gridMeta.celesta',
                                     '@type':'METADATA'
                                     },
                                    {'@id':'proc2',
                                     '@name':'nci.grid.accredCenterGrid.gridToolBar.celesta',
                                     '@type':'TOOLBAR'
                                     }
                                    ]
                           }

    accredCenterCard = {'@id': 'accredCenterCard',
                        '@type': 'xforms',
                        '@proc': 'nci.xform.accredCenterCard.cardData.celesta',
                        '@template':'nci/accredCenterCard.xml',
                        '@hideOnLoad':'true',
                        "@buildTemplate": "true",
                        'proc': {'@id':'save',
                                 '@name':'nci.xform.accredCenterCard.cardSave.celesta',
                                 '@type':'SAVE'
                                 },
                        'related': {'@id':'accredCenterGrid'}
                        }

    accredCenterDeleteCard = {'@id': 'accredCenterDeleteCard',
                                 '@type': 'xforms',
                                 '@proc': 'nci.xform.accredCenterCard.deleteCardData.celesta',
                                 '@template': 'delElementStandardCard.xml',
                                 '@hideOnLoad':'true',
                                 'proc': {'@id':'save',
                                          '@name':'nci.xform.accredCenterCard.deleteCardSave.celesta',
                                          '@type':'SAVE'
                                          },
                                 'related': {'@id':'accredCenterGrid'}
                                 }
    tab1['element'].append(htmlHintElement('accred_center_datapanel'))
    tab1['element'].append(accredCenterGrid)
    tab1['element'].append(accredCenterCard)
    tab1['element'].append(accredCenterDeleteCard)
    data['datapanel']['tab'].extend([tab1])

    return XMLJSONConverter.jsonToXml(json.dumps(data))