def cat_list(SITE): print('FUNCTION -> system_> calalog -> cat -> cat_list') SITE.addHeadFile('/templates/system/catalog/cat/cat.js') CATALOG = Catalog(SITE) rows = CATALOG.getItems() row_out = '' i = 1 if (rows): for row in rows: row_out += f''' <tr> <td>{ i }</td> <td> <div class="flex_row contextmenu_wrap"> <svg class="contextmenu_ico" title="Действия" data-id="{ row['id'] }"> <use xlink:href="/templates/system/svg/sprite.svg#menu_3"></use> </svg> </div> </td> <td> <a href="/system/catalog/cat/{ row['id'] }">{ row['name'] }</a> </td> </tr> ''' i += 1 SITE.content += f'''<div class="bg_gray">
def delete(SITE): print('FUNCTION -> system-> calalog -> cat -> delete') if 'agree' in SITE.post and SITE.post['agree'] == 'yes': CATALOG = Catalog(SITE) catalog = CATALOG.delete(SITE.post['id']) # Удаляем текущий элемент return {'redirect': '/system/catalog/cat'}
def settings_update(SITE): print('FUNCTION -> system-> calalog -> cat -> settings_update') CATALOG = Catalog(SITE) catalog = CATALOG.settingsUpdate( SITE.p[3], SITE.post['settings']) # Удаляем текущий элемент return {'redirect': '/system/catalog/cat'}
def ordering(SITE): print('FUNCTION -> system-> calalog -> cat -> ordering') type = SITE.p[2] id = SITE.p[3] CATALOG = Catalog(SITE) catalog = CATALOG.ordering(type, id) if 'cancel' in SITE.post: return {'redirect': '/system/catalog/cat'} return {'redirect': '/system/catalog/cat'}
def edit(SITE): print('FUNCTION -> system_> calalog -> cat -> edit') CATALOG = Catalog(SITE) if SITE.p[2] == 'edit': catalog = CATALOG.getItem(SITE.p[3]) title = 'Редактировать каталог' action = 'update/' + SITE.p[3] else: title = 'Добавить каталог' action = 'insert' ordering = CATALOG.getMaxOrdering() + 1 catalog = {'name': '', 'url': '', 'ordering': ordering} SITE.content += '''<div class="bg_gray"> <h1>''' + title + '''</h1> <div class="breadcrumbs"> <a href="/system/"><svg class="home"><use xlink:href="/templates/system/svg/sprite.svg#home"></use></svg></a> <svg><use xlink:href="/templates/system/svg/sprite.svg#arrow_right_1"></use></svg> <a href="/system/catalog">Каталог</a> <svg><use xlink:href="/templates/system/svg/sprite.svg#arrow_right_1"></use></svg> <span>''' + title + '''</span> </div> <form method="post" action="/system/catalog/cat/''' + action + '''"> <div class="tc_container"> <div class="flex_row p_5_20"> <div class="tc_item_l">Наименование</div> <div class="tc_item_r flex_grow"> <input class="input input_long" name="name" placeholder="Интернет магазин" required value="''' + catalog[ 'name'] + '''"> </div> </div> <div class="flex_row p_5_20"> <div class="tc_item_l">URL адрес каталога</div> <div class="tc_item_r flex_grow"> <input id="url" class="input" name="url" placeholder="catalog" required value="''' + catalog[ 'url'] + '''"> <div id="url_status"></div> </div> </div> <div class="flex_row p_5_20"> <div class="tc_item_l">Порядок следования</div> <div class="tc_item_r flex_grow"> <input class="input" name="ordering" type="number" value="''' + str( catalog['ordering']) + '''">
def settings_edit(SITE): print('FUNCTION -> system-> calalog -> cat -> settings_edit') CATALOG = Catalog(SITE) catalog = CATALOG.getItem(SITE.p[3]) SITE.content += '''<div class="bg_gray"> <h1>Настройки каталога ''' + catalog['name'] + '''</h1> <div class="breadcrumbs"> <a href="/system/"><svg class="home"><use xlink:href="/templates/system/svg/sprite.svg#home"></use></svg></a> <svg><use xlink:href="/templates/system/svg/sprite.svg#arrow_right_1"></use></svg> <a href="/system/catalog">Каталог</a> <svg><use xlink:href="/templates/system/svg/sprite.svg#arrow_right_1"></use></svg> <span>Настройки</span> </div> <form method="post" action="/system/catalog/cat/settings_update/''' + SITE.p[ 3] + '''"> <div class="tc_container"> <div class="flex_row p_5_20"> '<textarea class="input" name="settings" style="width:100%; height:200px;">''' + catalog[ 'settings'] + '''</textarea>'
def name_list(SITE): print('FUNCTION -> system-> calalog -> char -> list') SITE.addHeadFile('/templates/system/char/list.css') SITE.addHeadFile('/templates/system/char/list.js') SITE.addHeadFile('/lib/DRAG_N_DROP/DRAG_DROP.css') SITE.addHeadFile('/lib/DRAG_N_DROP/DRAG_DROP.js') catalog_id = SITE.p[2] CATALOG = Catalog(SITE) CHAR = Char(SITE) catalog = CATALOG.getItem(catalog_id) chars = CHAR.getNameList(catalog_id) char_type = { 'string': 'строка', 'number': 'число', 'date': 'дата', 'color': 'цвет' } char_out = '' if (chars): i = 1 for char in chars: char_out += f'''<table class="drag_drop" data-id="{ char['id'] }"> <tr> <td>{ char['id'] }</td> <td> <div class="flex_row contextmenu_wrap"><svg class="drag_drop_ico" title="Перетащить" data-id="{ char['id'] }" data-target-id="drag_target" data-class="drag_drop" data-f="SYSTEM.chars.drag_drop"><use xlink:href="/templates/system/svg/sprite.svg#cursor24"></use></svg></div> </td> <td><a href="/system/catalog/char/edit/{ char['id'] }">{ char['name'] } ({ char['unit'] })</a></td> <td>{ char_type[char['type']] }</td> <td> <svg class="catalog_char_delete" data-id="{ char['id'] }"><use xlink:href="/templates/system/svg/sprite.svg#delete"></use></svg> </td> </tr> </table>''' SITE.content += f'''<div class="bg_gray">
def sec_list(SITE): print('FUNCTION -> system_> calalog -> cat -> sec_list') catalog_id = SITE.p[2] SITE.addHeadFile('/templates/system/catalog/cat/sec.js') CATALOG = Catalog(SITE) catalog = CATALOG.getItem(catalog_id) SECTION = Section(SITE) rows = SECTION.tree(catalog_id) row_out = '' i = 1 if (rows): for row in rows: level = ' - ' * row['level'] status_tr_class = '' if row['status'] == 0: status_tr_class = 'class="admin_table_tr_unpub"' row_out += f'''<tr { status_tr_class }> <td>{ i }</td> <td> <div class="flex_row contextmenu_wrap"> <svg class="contextmenu_ico" title="Действия" data-id="{ row['id'] }"> <use xlink:href="/templates/system/svg/sprite.svg#menu_3"></use> </svg> </div> </td> <td> <a href="/system/catalog/section/{ row['id'] }">{ level }{ row['name'] }</a> </td> </tr> ''' i += 1 SITE.content += f'''<div class="bg_gray">
def update(SITE): print('FUNCTION -> system-> calalog -> cat -> update') if 'cancel' in SITE.post: return {'redirect': '/system/catalog/cat'} CATALOG = Catalog(SITE) catalog = CATALOG.getItem(SITE.p[3]) # Получаем текущий элемент if CATALOG.checkUrl(SITE.post['url'], catalog['url']) is not None: SITE.content += '<div class="bg_gray"><h1>Ошибка</h1><div>url <b>' + \ SITE.post['url'] + '</b> - занят!</div></div>' return CATALOG.update({ 'url': SITE.post['url'], 'name': SITE.post['name'], 'ordering': SITE.post['ordering'], 'id': SITE.p[3] }) return {'redirect': '/system/catalog/cat'}
def edit(SITE): print('PATH -> system/catalog/char/edit') CATALOG = Catalog(SITE) CHAR = Char(SITE) if SITE.p[2] == 'edit': char_id = SITE.p[3] char = CHAR.getName(char_id) catalog_id = char['catalog_id'] title = 'Редактировать характеристику' action = 'update/' + char_id else: catalog_id = SITE.p[3] title = 'Добавить характеристику' action = 'insert' ordering = CHAR.getNameMaxOrdering(catalog_id) + 1 char = { 'id': 0, 'name': '', 'unit': '', 'type': 'string', 'ordering': ordering } catalog = CATALOG.getItem(catalog_id) char_type_select = {'string': '', 'number': '', 'date': '', 'color': ''} char_type_select[char['type']] = 'selected' SITE.content += '''<div class="bg_gray"> <h1>''' + title + '''</h1> <div class="breadcrumbs"> <a href="/system/"><svg class="home"><use xlink:href="/templates/system/svg/sprite.svg#home"></use></svg></a> <svg><use xlink:href="/templates/system/svg/sprite.svg#arrow_right_1"></use></svg> <a href="/system/catalog/cat">Каталог</a> <svg><use xlink:href="/templates/system/svg/sprite.svg#arrow_right_1"></use></svg> <span>''' + title + '''</span> </div> <form method="post" action="/system/catalog/char/''' + action + '''"> <div class="tc_container"> <div class="flex_row p_5_20"> <div class="tc_item_l">Наименование</div> <div class="tc_item_r flex_grow"> <input class="input input_long" name="name" required value="''' + char[ 'name'] + '''"> </div> </div> <div class="flex_row p_5_20"> <div class="tc_item_l">Единица измерения</div> <div class="tc_item_r flex_grow"> <input class="input" name="unit" value="''' + char['unit'] + '''"> </div> </div> <div class="flex_row p_5_20"> <div class="tc_item_l">Тип</div> <div class="tc_item_r flex_grow"> <select class="input" name="type"> <option value="string" ''' + char_type_select[ 'string'] + '''>Строка</option> <option value="number" ''' + char_type_select[ 'number'] + '''>Число</option> <option value="date" ''' + char_type_select[ 'date'] + '''>Дата</option> <option value="color" ''' + char_type_select[ 'color'] + '''>Цвет</option> </select> </div> </div> <div class="flex_row p_5_20"> <div class="tc_item_l">Порядок следования</div> <div class="tc_item_r flex_grow"> <input class="input" name="ordering" type="number" value="''' + str( char['ordering']) + '''"> </div> </div> <div class="flex_row p_5_20"> <div class="tc_item_l"><input class="button_green" type="submit" name="submit" value="Сохранить"></div> <div class="tc_item_r flex_grow"><input class="button_white" type="submit" name="cancel" value="Отменить"></div> </div> </div> <input class="input" name="catalog_id" type="hidden" value="''' + str( catalog_id) + '''">