scinote-web/app/javascript/packs/vue/navigation/navigator.js

78 lines
2.6 KiB
JavaScript
Raw Normal View History

2023-10-24 18:54:58 +08:00
import PerfectScrollbar from 'vue3-perfect-scrollbar';
import { createApp } from 'vue/dist/vue.esm-bundler.js';
import 'vue3-perfect-scrollbar/dist/vue3-perfect-scrollbar.css';
import NavigatorContainer from '../../../vue/navigation/navigator.vue';
function addNavigationNavigatorContainer() {
2023-10-24 18:54:58 +08:00
const app = createApp({
data() {
return {
2023-04-26 16:24:50 +08:00
reloadCurrentLevel: false,
reloadChildrenLevel: false,
reloadExpandedChildrenLevel: false
}
},
created() {
2023-04-26 16:24:50 +08:00
$(document).on('inlineEditing:fieldUpdated', '.title-row .inline-editing-container', () => {
this.reloadCurrentLevel = true;
})
},
methods: {
2023-08-02 23:02:11 +08:00
toggleNavigatorState: function(newNavigatorState) {
let stateUrl = $('#sciNavigationNavigatorContainer').attr('data-navigator-state-url');
2023-08-21 15:09:40 +08:00
$.post(stateUrl, { state: newNavigatorState ? 'collapsed' : 'open' });
$('.sci--layout').attr('data-navigator-collapsed', newNavigatorState);
$('body').toggleClass('navigator-collapsed', newNavigatorState);
// refresh action toolbar width on navigator toggle, take into account transition time of .4s
if (window.actionToolbarComponent) setTimeout(window.actionToolbarComponent.setWidth, 401);
// set navigator state in table.
if (window.resetGridColumns) window.resetGridColumns(newNavigatorState);
},
reloadNavigator(withExpandedChildren = false) {
this.reloadCurrentLevel = true;
if (withExpandedChildren) {
this.reloadExpandedChildrenLevel = true;
} else {
this.reloadChildrenLevel = true;
}
}
},
watch: {
2023-04-26 16:24:50 +08:00
reloadCurrentLevel: function () {
if (this.reloadCurrentLevel) {
this.$nextTick(() => {
this.reloadCurrentLevel = false;
});
}
},
reloadChildrenLevel: function () {
if (this.reloadChildrenLevel) {
this.$nextTick(() => {
this.reloadChildrenLevel = false;
});
}
},
reloadExpandedChildrenLevel() {
if (this.reloadExpandedChildrenLevel) {
this.$nextTick(() => {
this.reloadExpandedChildrenLevel = false;
});
}
}
2023-08-02 23:02:11 +08:00
}
});
2023-10-24 18:54:58 +08:00
app.component('NavigatorContainer', NavigatorContainer);
app.use(PerfectScrollbar);
app.config.globalProperties.i18n = window.I18n;
2023-11-09 19:40:06 +08:00
window.navigatorContainer = app.mount('#sciNavigationNavigatorContainer');
}
if (document.readyState !== 'loading') {
addNavigationNavigatorContainer();
} else {
window.addEventListener('DOMContentLoaded', () => {
addNavigationNavigatorContainer();
});
}