Files
metabuilder/qml/MetaBuilder/AppLogic.js
johndoe6345789 827387d807 style(qt6): enforce 80-character line margin across all QML and JS files
88 files reformatted — zero logic changes:
- All views, components, and JS modules wrapped to 80-char margin
- Long property bindings, ternaries, and strings broken at natural points
- Theme.qml theme definitions expanded to multi-line
- StyleVariables tokens wrapped
- Section comment rulers trimmed to 80 chars

Trade-off: LOC increases from line wrapping (compact single-line properties
now span 2-3 lines). Content unchanged.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 15:20:01 +00:00

90 lines
2.5 KiB
JavaScript

// AppLogic.js — auth + navigation logic for
// App.qml
function loadJson(relativePath) {
var xhr = new XMLHttpRequest()
xhr.open("GET", Qt.resolvedUrl(relativePath),
false)
xhr.send()
return xhr.status === 200
? JSON.parse(xhr.responseText) : null
}
function login(app, username, password) {
for (var i = 0; i < app.users.length; i++) {
if (app.users[i].username === username
&& app.users[i].password
=== password) {
app.currentUser = username
app.currentRole = app.users[i].role
app.currentLevel = app.users[i].level
app.loggedIn = true
app.currentView = "dashboard"
return true
}
}
return false
}
function logout(app, dbalProvider) {
app.currentUser = ""
app.currentRole = "public"
app.currentLevel = 1
app.loggedIn = false
app.authToken = ""
dbalProvider.authToken = ""
app.currentView = "frontpage"
}
function viewIndex(app) {
var view = app.currentView
var staticIdx = app.staticViews.indexOf(view)
if (staticIdx >= 0) return staticIdx
var navPkgs =
PackageLoader.navigablePackages()
for (var i = 0; i < navPkgs.length; i++) {
var pkg = navPkgs[i]
var viewName = packageViewName(pkg)
if (viewName === view
|| pkg.packageId === view)
return app.staticViews.length + i
}
return 0
}
function packageViewName(pkg) {
return pkg.navLabel
? pkg.navLabel.toLowerCase()
.replace(/ /g, "-")
: pkg.packageId
}
function autoLogin(app, dbalProvider) {
app.appConfig = loadJson(
"config/app-config.json")
if (typeof Theme.setTheme === "function")
Theme.setTheme(app.currentTheme)
if (app.authToken !== "") {
dbalProvider.authToken = app.authToken
dbalProvider.execute(
"core/auth/validate",
{ token: app.authToken },
function(result, error) {
if (!error && result
&& result.valid) {
app.currentUser =
result.username || ""
app.currentRole =
result.role || "user"
app.currentLevel =
result.level || 2
app.loggedIn = true
app.currentView = "dashboard"
} else {
app.authToken = ""
dbalProvider.authToken = ""
}
})
}
}