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

@author: v.popov
'''
import json
from ru.curs.celesta.showcase.utils import XMLJSONConverter
try:
    from ru.curs.showcase.core.jython import JythonDTO
except:
    from ru.curs.celesta.showcase import JythonDTO



def webtext(context, main=None, add=None, filterinfo=None, session=None, elementId=None):




    lk_button = {"div":
                    {"@class":"button200",
                     "@style": "float:left;padding: 10px;width:300px;",
                         "span":
                            {"button":
                                {"@style":"cursor: pointer; width: 100%; height: 50px;",
                                 "@onclick":"var url='?userdata=authoring';window.open(url,'_self');",
                                 "span":
                                    {"@class":"xforms-label",
                                     "#text":u'Авторская подсистема'
                                     }
                                 }
                             }
                         }
                     }


   

    buttons_div = {'div': [lk_button],
                   "@style": "width: 350px; height: 100%; float:left;"}

    webtextsettings = {"properties": ''
                }



    webtextdata = {"div":
                    {'div': [buttons_div],
                     "@style": "width: 1000px;margin: 0 auto;height: 100%;"
                     }
                   }


    settings = XMLJSONConverter.jsonToXml(json.dumps(webtextsettings))
    data = XMLJSONConverter.jsonToXml(json.dumps(webtextdata))

    return JythonDTO(data, settings)

def header(context, main=None, add=None, filterinfo=None, session=None, elementId=None):

    person = json.loads(session)['sessioncontext']['fullusername']
    userdata = json.loads(session)['sessioncontext']['userdata']

    data = {'div': {"@class": "wrap",
                    "#sorted": [
#                                 {'nav': {"@class": "ed-menu dark", "@style": 'float: left', 'ul': []}},
#                                 {'nav': {"@class": "ed-menu dark", "@style": 'float: left', 'ul': []}},
#                                 {'nav': {"@class": "ed-menu dark", "@style": 'float: left', 'ul': []}},
#                                 {'nav': {"@class": "ed-menu dark", "@style": 'float: left', 'ul': []}},
#                                 {'nav': {"@class": "ed-menu dark", "@style": 'float: right', 'ul': []}},
#                                 {'div': {"@style": "float: right; padding: 4px 10px;",
#                                          'img': {"@class": 'user',
#                                         '@width': "24px",
#                                         '@height': "24px",
#                                         '@src': 'solutions/default/resources/icons/user2.ico',
#                                         'span': {'@class': "person",
#                                                  "#text": person}}}}
                                ]}}
    if userdata != 'default':
#         data['div']["#sorted"].append({'nav': {"@class": "ed-menu dark", "@style": 'float: left', 'ul': [{'li': {'a': {'@href': '.', '#text': u'На главную'}}}]}})
        if userdata != 'qtAuthor':
            data['div']["#sorted"].append({'nav': {
                                            "@class": "ed-menu dark", 
                                            "@style": 'float: left', 
                                            'ul': [
                                                {'li': {
                                                    'a': {
                                                        '@href': '.', 
                                                        '@title': u'На главную страницу',
                                                        'img': {
                                                            '@width': "24px",
                                                            '@height': "24px",
                                                            '@src': 'solutions/default/resources/icons/ic_arrow_back_white_24dp.png'}}}}]}})
        data['div']["#sorted"].append({'nav': {"@class": "ed-menu dark", "@style": 'float: left', 'ul': [{'li': {'a': {'@onclick': 'showAboutFeedbackJSNIFunction()', 'span': u'О программе...'}}}]}})

    else:
        data['div']["#sorted"].append({'nav': {"@class": "ed-menu dark", "@style": 'float: left', 'ul': [{'li': {'a': {'@href': 'log/lastLogEvents.jsp', 'span': u'Открыть веб-консоль'}}}]}})
    
#     data['div']["#sorted"].append({'nav': {"@class": "ed-menu dark", "@style": 'float: right', 'ul': [{'li': {'a': {'@id': "logoutLink", '@onclick': "showcaseLogout()", "#text": u'Выход'}}}]}})
    data['div']["#sorted"].append({'nav': {
                                    "@class": "ed-menu dark", 
                                    "@style": 'float: right', 
                                    'ul': [
                                        {'li': 
                                            {'a': {
                                                '@id': "logoutLink", 
                                                '@onclick': "showcaseLogout()",  
                                                '@title': u'Выход из системы',
                                                '@style': 'cursor: pointer;',
                                                'img': {
                                                    '@width': "24px",
                                                    '@height': "24px",
                                                    '@src': 'solutions/default/resources/icons/ic_exit_to_app_white_24dp.png'}}}}]}})
    
    data['div']["#sorted"].append({'div': {
                                    "@class": "user",
                                    'img': {
                                        '@width': "24px",
                                        '@height': "24px",
                                        '@src': 'solutions/default/resources/icons/ic_account_box_white_24dp.png',
                                        'span': {
                                            '@class': "person",
                                            "#text": person}}}})
#     data['div']["#sorted"][-2]['nav']['ul'].append({'li': {'a': {'@id': "logoutLink", '@onclick': "showcaseLogout()", "#text": u'Выход'}}})
#     data['div']["#sorted"][0]['nav']['ul'].append({'li': {'a': {'@href': '?userdata=kod', '#text': u'КОД'}}})
#     data['div']["#sorted"][1]['nav']['ul'].append({'li': {'a': {'@href': '?userdata=projects', '#text': u'Проекты'}}})
#     data['div']["#sorted"][2]['nav']['ul'].append({'li': {'a': {'@href': '?userdata=contracts', '#text': u'Договоры'}}})
#     data['div']["#sorted"][3]['nav']['ul'].append({'li': {'a': {'@href': '?userdata=security', '#text': u'Администрирование'}}})

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