|
|
@@ -16,14 +16,39 @@ document.head.insertAdjacentHTML('beforeend','<style type="text/tailwindcss" p
|
|
|
## базовой стиль приложения
|
|
|
document.head.insertAdjacentHTML('beforeend','<style type="text/tailwindcss" page="root">'+stylFns['app/temp.styl']+'</style>')
|
|
|
|
|
|
+# Создаем глобальную шину событий
|
|
|
+class AppEventBus
|
|
|
+ constructor: ->
|
|
|
+ @events = {}
|
|
|
+
|
|
|
+ on: (event, callback) ->
|
|
|
+ if !@events[event]
|
|
|
+ @events[event] = []
|
|
|
+ @events[event].push(callback)
|
|
|
+
|
|
|
+ emit: (event, data) ->
|
|
|
+ if @events[event]
|
|
|
+ for callback in @events[event]
|
|
|
+ try
|
|
|
+ callback(data)
|
|
|
+ catch error
|
|
|
+ debug.log "Event bus error: " + error
|
|
|
+
|
|
|
+ off: (event, callback) ->
|
|
|
+ if @events[event]
|
|
|
+ @events[event] = @events[event].filter (cb) -> cb != callback
|
|
|
+
|
|
|
+# Создаем глобально
|
|
|
+globalThis.EventBus = new AppEventBus()
|
|
|
+
|
|
|
# CouchDB сервис
|
|
|
class CouchDBService
|
|
|
constructor: ->
|
|
|
- @baseUrl = 'https://couchdb.favt.ru.net'
|
|
|
+ @baseUrl = 'http://localhost:5984'
|
|
|
@dbName = 'kohi_borbad_events'
|
|
|
@headers =
|
|
|
'Content-Type': 'application/json'
|
|
|
- 'Authorization': 'Basic ' + btoa('oleg:631074')
|
|
|
+ 'Authorization': 'Basic ' + btoa('admin:password')
|
|
|
|
|
|
getAllEvents: ->
|
|
|
try
|
|
|
@@ -62,10 +87,6 @@ class CouchDBService
|
|
|
category: event.category
|
|
|
|
|
|
# Маршруты
|
|
|
-routes = [
|
|
|
- { path: '/', component: require 'app/pages/Home' }
|
|
|
-]
|
|
|
-components = {}
|
|
|
routes = [
|
|
|
{ path: '/', component: require 'app/pages/Home' }
|
|
|
{ path: '/events', component: require 'app/pages/Events' }
|
|
|
@@ -73,17 +94,6 @@ routes = [
|
|
|
{ path: '/contacts', component: require 'app/pages/Contacts' }
|
|
|
]
|
|
|
|
|
|
-components =
|
|
|
- 'themetoggle': require 'app/shared/ThemeToggle'
|
|
|
- 'multilevelmenu': require 'app/shared/MultiLevelMenu'
|
|
|
- 'imageslider': require 'app/shared/ImageSlider'
|
|
|
- 'modalwindow': require 'app/shared/ModalWindow'
|
|
|
- 'formvalidator': require 'app/shared/FormValidator'
|
|
|
- 'filtersort': require 'app/shared/FilterSort'
|
|
|
- 'eventdetailmodal': require 'app/shared/EventDetailModal'
|
|
|
- 'successmodal': require 'app/shared/SuccessModal'
|
|
|
-
|
|
|
-
|
|
|
# Глобальное определение vuejs приложения
|
|
|
app = Vue.createApp
|
|
|
name: 'app'
|
|
|
@@ -118,7 +128,7 @@ app = Vue.createApp
|
|
|
await @loadEventsData()
|
|
|
|
|
|
# Обработчик открытия модальных окон
|
|
|
- EventBus.$on 'open-modal', (config) =>
|
|
|
+ EventBus.on 'open-modal', (config) =>
|
|
|
@modalState.currentModal = config.component
|
|
|
@modalState.modalProps = config.props || {}
|
|
|
methods:
|
|
|
@@ -126,7 +136,6 @@ app = Vue.createApp
|
|
|
@theme = if @theme == 'light' then 'dark' else 'light'
|
|
|
localStorage.setItem 'theme', @theme
|
|
|
document.documentElement.classList.toggle 'dark'
|
|
|
- @$emit 'theme-changed', @theme
|
|
|
|
|
|
loadEventsData: ->
|
|
|
@appState.loading = true
|
|
|
@@ -225,33 +234,15 @@ app = Vue.createApp
|
|
|
closeModal: ->
|
|
|
@modalState.currentModal = null
|
|
|
@modalState.modalProps = {}
|
|
|
- components: components
|
|
|
-
|
|
|
-
|
|
|
-# Создаем глобальную шину событий
|
|
|
-class AppEventBus
|
|
|
- constructor: ->
|
|
|
- @events = {}
|
|
|
-
|
|
|
- on: (event, callback) ->
|
|
|
- if !@events[event]
|
|
|
- @events[event] = []
|
|
|
- @events[event].push(callback)
|
|
|
-
|
|
|
- emit: (event, data) ->
|
|
|
- if @events[event]
|
|
|
- for callback in @events[event]
|
|
|
- try
|
|
|
- callback(data)
|
|
|
- catch error
|
|
|
- debug.log "Event bus error: " + error
|
|
|
-
|
|
|
- off: (event, callback) ->
|
|
|
- if @events[event]
|
|
|
- @events[event] = @events[event].filter (cb) -> cb != callback
|
|
|
-
|
|
|
-# Создаем глобально
|
|
|
-globalThis.EventBus = new AppEventBus()
|
|
|
+ components:
|
|
|
+ 'themetoggle': require 'app/shared/ThemeToggle'
|
|
|
+ 'multilevelmenu': require 'app/shared/MultiLevelMenu'
|
|
|
+ 'imageslider': require 'app/shared/ImageSlider'
|
|
|
+ 'modalwindow': require 'app/shared/ModalWindow'
|
|
|
+ 'formvalidator': require 'app/shared/FormValidator'
|
|
|
+ 'filtersort': require 'app/shared/FilterSort'
|
|
|
+ 'eventdetailmodal': require 'app/shared/EventDetailModal'
|
|
|
+ 'successmodal': require 'app/shared/SuccessModal'
|
|
|
|
|
|
app.use(VueRouter.createRouter({
|
|
|
routes: routes
|
|
|
@@ -265,10 +256,10 @@ app.use(VueRouter.createRouter({
|
|
|
|
|
|
# Глобальные функции для работы с модальными окнами
|
|
|
globalThis.openModal = (component, props = {}) ->
|
|
|
- EventBus.$emit 'open-modal', { component, props }
|
|
|
+ EventBus.emit 'open-modal', { component, props }
|
|
|
|
|
|
globalThis.closeModal = ->
|
|
|
- EventBus.$emit 'close-modal'
|
|
|
+ EventBus.emit 'close-modal'
|
|
|
|
|
|
# подключаем в body ОБЯЗАТЕЛЬНО!!!
|
|
|
app.mount('body')
|