Have got first run working and publishing to Netlify
This commit is contained in:
parent
b7e0269e9d
commit
30d99eeb9e
22 changed files with 472 additions and 47 deletions
66
assets/js/controllers/firstrun.js
Normal file
66
assets/js/controllers/firstrun.js
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import { Controller } from "@hotwired/stimulus"
|
||||
import { showToast } from "../services/toast";
|
||||
|
||||
export default class FirstRunController extends Controller {
|
||||
static targets = ['pages'];
|
||||
|
||||
connect() {
|
||||
this.pagesTargets.forEach((x) => x.classList.add('d-none'));
|
||||
this.pagesTargets[0].classList.remove('d-none');
|
||||
this.element.querySelector('input[name="username"]').focus();
|
||||
}
|
||||
|
||||
nextPage(ev) {
|
||||
ev.preventDefault();
|
||||
|
||||
const currentIndex = this.pagesTargets.findIndex(x => !x.classList.contains('d-none'));
|
||||
if (currentIndex === -1) {
|
||||
return;
|
||||
}
|
||||
if (!this._validate(currentIndex)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let nextPage = currentIndex + 1;
|
||||
if (nextPage >= this.pagesTargets.length) {
|
||||
this.element.querySelector('form').submit();
|
||||
return;
|
||||
}
|
||||
|
||||
this.pagesTargets[currentIndex].classList.add('d-none');
|
||||
this.pagesTargets[nextPage].classList.remove('d-none');
|
||||
|
||||
if (nextPage === 1) {
|
||||
this.element.querySelector('input[name="siteName"]').focus();
|
||||
}
|
||||
}
|
||||
|
||||
_validate(pageNumber) {
|
||||
let newUsername = this.element.querySelector('input[name="username"]');
|
||||
let newPassword1 = this.element.querySelector('input[name="password1"]');
|
||||
let newPassword2 = this.element.querySelector('input[name="password2"]');
|
||||
|
||||
if (newUsername.value === '') {
|
||||
alert('Please enter a username');
|
||||
newUsername.focus();
|
||||
return false;
|
||||
}
|
||||
if (!newUsername.value.match(/^[a-zA-Z0-9_-]+$/)) {
|
||||
alert('Please enter a username with letters, numbers, underscores, and dashes only');
|
||||
newUsername.focus();
|
||||
newUsername.select();
|
||||
return false;
|
||||
}
|
||||
if (newPassword1.value === '') {
|
||||
alert('Please enter a password');
|
||||
newPassword1.focus();
|
||||
return false;
|
||||
}
|
||||
if (newPassword2.value !== newPassword1.value) {
|
||||
alert('Passwords do not match');
|
||||
newPassword2.focus();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,9 +4,11 @@ import ToastController from "./controllers/toast";
|
|||
import PostlistController from "./controllers/postlist";
|
||||
import PosteditController from "./controllers/postedit";
|
||||
import LogoutController from "./controllers/logout";
|
||||
import FirstRunController from "./controllers/firstrun";
|
||||
|
||||
window.Stimulus = Application.start()
|
||||
Stimulus.register("toast", ToastController);
|
||||
Stimulus.register("postlist", PostlistController);
|
||||
Stimulus.register("postedit", PosteditController);
|
||||
Stimulus.register("logout", LogoutController);
|
||||
Stimulus.register("first-run", FirstRunController);
|
||||
Loading…
Add table
Add a link
Reference in a new issue