| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- document.head.insertAdjacentHTML('beforeend','<style type="text/tailwindcss">'+stylFns['app/pages/Admin/Settings/index.styl']+'</style>')
- PouchDB = require 'app/utils/pouch'
- module.exports =
- name: 'AdminSettings'
-
- render: (new Function '_ctx', '_cache', renderFns['app/pages/Admin/Settings/index.pug'])()
-
- data: ->
- return {
- activeTab: 'brand'
- tabs: [
- { id: 'brand', name: 'Бренд' }
- { id: 'favicon', name: 'Фавикон' }
- { id: 'domains', name: 'Домены' }
- { id: 'languages', name: 'Языки' }
- ]
- brandSettings: {
- logo: ''
- favicon: ''
- companyName: ''
- description: ''
- email: ''
- phone: ''
- }
- domains: []
- currentDomain: window.location.hostname
- }
-
- methods:
- getTabClass: (tab) ->
- baseClass = 'admin-settings__tab'
- isActive = @activeTab == tab.id
-
- if isActive
- return "#{baseClass} admin-settings__tab--active"
- else
- return "#{baseClass} admin-settings__tab--inactive"
-
- loadBrandSettings: ->
- PouchDB.getDocument("domain_settings:#{@currentDomain}")
- .then (settings) =>
- if settings
- @brandSettings = { ...@brandSettings, ...settings }
- .catch (error) =>
- console.log 'Настройки бренда не найдены'
-
- onLogoUpload: (event) ->
- file = event.target.files[0]
- if file
- # В реальном приложении здесь будет загрузка файла на сервер
- # и получение пути к изображению
- reader = new FileReader()
- reader.onload = (e) =>
- # Временное решение - используем data URL
- # В продакшене нужно загружать на сервер и получать путь /d/[db]/[doc]/[filename]
- @brandSettings.logo = e.target.result
- reader.readAsDataURL(file)
-
- removeLogo: ->
- @brandSettings.logo = ''
-
- onFaviconUpload: (event) ->
- file = event.target.files[0]
- if file
- reader = new FileReader()
- reader.onload = (e) =>
- @brandSettings.favicon = e.target.result
- reader.readAsDataURL(file)
-
- removeFavicon: ->
- @brandSettings.favicon = ''
-
- saveBrandSettings: ->
- domainDoc = {
- _id: "domain_settings:#{@currentDomain}"
- type: 'domain_settings'
- domain: @currentDomain
- ...@brandSettings
- updatedAt: new Date().toISOString()
- }
-
- # Проверяем существование документа
- PouchDB.getDocument(domainDoc._id)
- .then (existingDoc) =>
- domainDoc._rev = existingDoc._rev
- return PouchDB.saveToRemote(domainDoc)
- .catch (error) =>
- if error.status == 404
- return PouchDB.saveToRemote(domainDoc)
- else
- throw error
- .then (result) =>
- @showNotification 'Настройки бренда сохранены'
- # Обновляем данные в главном приложении
- @$root.loadDomainSettings?()
- .catch (error) =>
- console.error 'Ошибка сохранения настроек бренда:', error
- @showNotification 'Ошибка сохранения настроек бренда', 'error'
-
- showNotification: (message, type = 'success') ->
- @$root.showNotification?(message, type) || console.log("#{type}: #{message}")
-
- mounted: ->
- @loadBrandSettings()
|