mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-10-04 02:07:13 +00:00
This drops fomantic-ui as css toolkit and introduces tailwindcss. With tailwind there are no predefined components, but it's very easy to create those. So customizing the look&feel is much simpler, most of the time no additional css is needed. This requires a complete rewrite of the markup + styles. Luckily all logic can be kept as is. The now old ui is not removed, it is still available by using a request header `Docspell-Ui` with a value of `1` for the old ui and `2` for the new ui. Another addition is "dev mode", where docspell serves assets with a no-cache header, to disable browser caching. This makes developing a lot easier.
100 lines
3.0 KiB
JavaScript
100 lines
3.0 KiB
JavaScript
/* Docspell JS */
|
|
function forEachIn(obj, fn) {
|
|
var index = 0;
|
|
for (var key in obj) {
|
|
if (obj.hasOwnProperty(key)) {
|
|
fn(obj[key], key, index++);
|
|
}
|
|
}
|
|
}
|
|
|
|
function extend() {
|
|
var result = {};
|
|
for (var i = 0; i < arguments.length; i++) {
|
|
forEachIn(arguments[i],
|
|
function(obj, key) {
|
|
result[key] = obj;
|
|
});
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
var elmApp = Elm.Main.init({
|
|
node: document.getElementById("docspell-app"),
|
|
flags: elmFlags
|
|
});
|
|
|
|
elmApp.ports.internalSetUiTheme.subscribe(function(themeName) {
|
|
var body = document.getElementsByTagName("body");
|
|
if (body && body.length > 0) {
|
|
var bodyClasses = body[0].classList;
|
|
// seems that body attributes cannot be set from inside Elm.
|
|
if (themeName && themeName.toLowerCase() === 'dark') {
|
|
bodyClasses.add("bg-bluegray-800");
|
|
bodyClasses.add("dark");
|
|
} else {
|
|
bodyClasses.remove("bg-bluegray-800");
|
|
bodyClasses.remove("dark");
|
|
}
|
|
}
|
|
});
|
|
|
|
elmApp.ports.setAccount.subscribe(function(authResult) {
|
|
console.log("Add account from local storage");
|
|
localStorage.setItem("account", JSON.stringify(authResult));
|
|
});
|
|
|
|
elmApp.ports.removeAccount.subscribe(function() {
|
|
console.log("Remove account from local storage");
|
|
localStorage.removeItem("account");
|
|
});
|
|
|
|
|
|
elmApp.ports.saveUiSettings.subscribe(function(args) {
|
|
if (Array.isArray(args) && args.length == 2) {
|
|
var authResult = args[0];
|
|
var settings = args[1];
|
|
if (authResult && settings) {
|
|
var key = authResult.collective + "/" + authResult.user + "/uiSettings";
|
|
console.log("Save ui settings to local storage");
|
|
localStorage.setItem(key, JSON.stringify(settings));
|
|
elmApp.ports.receiveUiSettings.send(settings);
|
|
elmApp.ports.uiSettingsSaved.send(null);
|
|
}
|
|
}
|
|
});
|
|
|
|
elmApp.ports.requestUiSettings.subscribe(function(args) {
|
|
console.log("Requesting ui settings");
|
|
if (Array.isArray(args) && args.length == 2) {
|
|
var account = args[0];
|
|
var defaults = args[1];
|
|
var collective = account ? account.collective : null;
|
|
var user = account ? account.user : null;
|
|
if (collective && user) {
|
|
var key = collective + "/" + user + "/uiSettings";
|
|
var settings = localStorage.getItem(key);
|
|
var data = settings ? JSON.parse(settings) : null;
|
|
if (data && defaults) {
|
|
var defaults = extend(defaults, data);
|
|
elmApp.ports.receiveUiSettings.send(defaults);
|
|
} else if (defaults) {
|
|
elmApp.ports.receiveUiSettings.send(defaults);
|
|
}
|
|
} else if (defaults) {
|
|
elmApp.ports.receiveUiSettings.send(defaults);
|
|
}
|
|
}
|
|
});
|
|
|
|
var docspell_clipboards = {};
|
|
|
|
elmApp.ports.initClipboard.subscribe(function(args) {
|
|
var page = args[0];
|
|
if (!docspell_clipboards[page]) {
|
|
var sel = args[1];
|
|
docspell_clipboards[page] = new ClipboardJS(sel);
|
|
}
|
|
});
|