var app = new Vue({ el: "#app", data: { darkMode: false, userUsername: "Lvorex", userRank: { title: "Admin", color: "#F34240" }, userIcon: "", userPermissions: undefined, searchValue: "", accountType: "", framework: "", notifyMenu: false, newNotify: false, activeCategory: "all", // all, weapon, useable, craftable, unique toShowJobs: [], allJobs: [], stateJobs: [], corpJobs: [], selectedJob: false, selectedJobInputs: [ { id: 0, label: "Job Label", value: "", inputImage: "img/JobLabelNameTypeInputBg.png" }, { id: 1, label: "Job Name (Command Name)", value: "", inputImage: "img/JobLabelNameTypeInputBg.png" }, { id: 2, label: "Job Type", value: "", inputImage: "img/JobLabelNameTypeInputBg.png" }, { id: 3, label: "Job Grades", value: "", inputImage: "img/JobGradesInputBg.png" }, { id: 4, label: "Job Players", value: "", inputImage: "img/JobPlayersInputBg.png" }, { id: 5, label: "Job's Highest Rank Player", value: "", pIdentifier: "", inputImage: "img/JobHRPInputBg.png" }, { id: 6, label: "Job Payment", value: "", inputImage: "img/JobPaymentInputBg.png" }, ], selectedImageUrl: "", selectedFile: undefined, selectedGrade: undefined, gradePlayers: undefined, rightBoxCategory: "players", // players, grades, gradeplayers popup: undefined }, components : { "m-navbar": navbarComp, "left-navbar": leftNavbarComp }, watch: { searchValue: function(newValue) { this.toShowJobs = this[this.activeCategory+"Jobs"] this.toShowJobs = this.toShowJobs.filter( item => item.label.toLowerCase().includes(newValue.toLowerCase()) || item.code.toLowerCase().includes(newValue.toLowerCase()) ) } }, methods: { inspectPlayer: function(identifier) { if (!identifier) return location.href = `/Panel/Players/Info/#uid=${identifier}` }, triggerFileInput: function() { document.getElementById("vinfo-left-right-realFile").click() }, changeSelectedImage: function(event) { const SentFile = event.target.files[0] const fileReader = new FileReader() let imageUrl = "" const vm = this fileReader.addEventListener("load", () => { imageUrl = fileReader.result vm.selectedFile = SentFile console.log(SentFile.path) vm.selectedImage = imageUrl }) fileReader.readAsDataURL(SentFile) }, openSetJobPopup: function() { this.popup = { grade: "", level: "", type: "setjob" } }, openGradeJobPopup: function(grade, level) { this.popup = { grade, level, type: "setgrade" } }, uploadImage: async function() { if (this.userPermissions["Jobs"][3] === false) { this.newNotify = { desc: "Your rank is not enough.", author: "System" } return } if (this.selectedImageUrl && this.selectedImageUrl.includes(":")) { let result = await fetch(`${location.protocol}//${location.hostname}:${location.port}/changeJobLogoByLink.lvorex`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ key: sha1(sessionStorage.getItem("uid-key")), job: this.selectedJob.job, link: this.selectedImageUrl }) }) result = await result.json() if (result.code !== 200) return console.log(result.message) document.getElementById("vinfo-left-right-file").style.backgroundImage = `url(${this.selectedImageUrl})` this.selectedJob.image = this.selectedImageUrl return } if (!this.selectedImage) return console.log(this.selectedFile) const formData = new FormData() formData.append("file", this.selectedFile) formData.append("key", sha1(sessionStorage.getItem("uid-key"))) formData.append("job", this.selectedJob.code) let result = await fetch(`${location.protocol}//${location.hostname}:${location.port}/changeJobLogo.lvorex`, { method: "POST", body: formData }) result = await result.json() if (result.code !== 200) return console.log(result.message) document.getElementById("vinfo-left-right-file").style.backgroundImage = `url(${this.selectedImage})` this.selectedJob.image = this.selectedImage this.selectedImage = undefined }, clearImage: async function() { if (this.userPermissions["Jobs"][3] === false) { this.newNotify = { desc: "Your rank is not enough.", author: "System" } return } let result = await fetch(`${location.protocol}//${location.hostname}:${location.port}/clearJobLogo.lvorex`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ key: sha1(sessionStorage.getItem("uid-key")), job: this.selectedJob.code }) }) result = await result.json() if (result.code !== 200) return console.log(result.message) document.getElementById("vinfo-left-right-file").style.backgroundImage = "" this.selectedJob.image = "img/DefaultJobIcon.png" this.selectedImage = undefined }, changeCategory: async function(changeto) { this.activeCategory = changeto this.toShowJobs = this[changeto+"Jobs"] }, changeJobType: async function() { if (this.userPermissions["Jobs"][2] === false) { this.newNotify = { desc: "Your rank is not enough.", author: "System" } return } if (this.selectedJob.type === "state") { this.selectedJob.type = "corp" this.selectedJobInputs[2].value = "corp" this.allJobs.find(j => j.code === this.selectedJob.code).type = "corp" } else { this.selectedJob.type = "state" this.selectedJobInputs[2].value = "state" this.allJobs.find(j => j.code === this.selectedJob.code).type = "state" } let result = await fetch(`${location.protocol}//${location.hostname}:${location.port}/changeJobType.lvorex`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ key: sha1(sessionStorage.getItem("uid-key")), job: this.selectedJob.code, type: this.selectedJob.type }) }) result = await result.json() if (result.code !== 200) return console.log(result.message) this.stateJobs = this.allJobs.filter(j => j.type === 'state') this.corpJobs = this.allJobs.filter(j => j.type === 'corp') }, selectItem: function(item) { if (this.userPermissions["Jobs"][1] === false) { this.newNotify = { desc: "Your rank is not enough.", author: "System" } return } this.selectedJob = item this.selectedJobInputs[0].value = item.label this.selectedJobInputs[1].value = item.code this.selectedJobInputs[2].value = item.type this.selectedJobInputs[3].value = Object.entries(item.grades).length+" Grade" this.selectedJobInputs[4].value = item.jobPlayers.length+" Player", this.selectedJobInputs[5].value = item.mostRankedPlayer.name === '' ? 'Not Found.' : item.mostRankedPlayer.name, this.selectedJobInputs[5].pIdentifier = item.mostRankedPlayer.identifier this.selectedJobInputs[6].value = item.payment }, selectGrade: function(grade) { this.gradePlayers = this.selectedJob.jobPlayers.filter(p => Number(p.grade) === Number(grade)) this.selectedGrade = { name: Object.entries(this.selectedJob.grades).find(([k , v]) => k === grade)[1][this.framework.includes("qb") ? "name" : "label"], level: Object.entries(this.selectedJob.grades).find(([k , v]) => k === grade)[0] } this.rightBoxCategory = "gradeplayers" }, autoCompleteWithGradeName: function(event) { const inputElement = event.target if ( inputElement.value === '' || inputElement.value.includes(" ") || isNaN(Number(inputElement.value)) || !this.selectedJob.grades[Number(inputElement.value)] ) return this.popup.level = event.target.value this.popup.grade = this.selectedJob.grades[Number(inputElement.value)][this.framework.includes("qb") ? "name" : "label"] inputElement.disabled = true }, setJobToPlayer: async function() { if (this.userPermissions["Jobs"][4] === false) { this.newNotify = { desc: "Your rank is not enough.", author: "System" } return } let gradeLevel = this.popup.level let pIdentifier = document.getElementById("popupPlayerIdentifier").value if ( !pIdentifier || pIdentifier === "" || pIdentifier.includes(" ") ) return let result = await fetch(`${location.protocol}//${location.hostname}:${location.port}/jobsChangePlayerJob.lvorex`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ key: sha1(sessionStorage.getItem("uid-key")), job: this.selectedJob.code, grade: gradeLevel, pIdentifier: pIdentifier }) }) result = await result.json() if (result.code !== 200) return console.log(result.message) this.popup = undefined }, goBackToGrades: function() { this.gradePlayers = undefined this.selectedGrade = undefined this.rightBoxCategory = "grades" }, goBackToItemsPage: function() { this.selectedJob = false this.selectedJobInputs = [ { id: 0, label: "Job Label", value: "", inputImage: "img/JobLabelNameTypeInputBg.png" }, { id: 1, label: "Job Name (Command Name)", value: "", inputImage: "img/JobLabelNameTypeInputBg.png" }, { id: 2, label: "Job Type", value: "", inputImage: "img/JobLabelNameTypeInputBg.png" }, { id: 3, label: "Job Grades", value: "", inputImage: "img/JobGradesInputBg.png" }, { id: 4, label: "Job Players", value: "", inputImage: "img/JobPlayersInputBg.png" }, { id: 5, label: "Job's Highest Rank Player", value: "", pIdentifier: "", inputImage: "img/JobHRPInputBg.png" }, { id: 6, label: "Job Payment", value: "", inputImage: "img/JobPaymentInputBg.png" }, ] this.rightBoxCategory = "players" this.gradePlayers = undefined this.selectedGrade = undefined } }, mounted: async function() { let result = await fetch(`${location.protocol}//${location.hostname}:${location.port}/controlKeyWithServer.lvorex`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ key: sha1(sessionStorage.getItem("uid-key")) }) }) result = await result.json() if (result.code === 404) { location.href = "/" return } const userDetails = JSON.parse(result.message) const userRankColors = { "Not Authorized": "#9e9e9e", Moderator: "#F34240", Admin: "#F34240", Owner: "#F34240", } this.darkMode = userDetails.darkMode === 1 ? true : false this.userUsername = userDetails.username this.userRank.title = userDetails.rank this.userRank.color = "#F34240" this.userIcon = userDetails.avatar this.accountType = userDetails.accountType this.userPermissions = userDetails.permissions result = await fetch(`${location.protocol}//${location.hostname}:${location.port}/getAllServerJobs.lvorex`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ key: sha1(sessionStorage.getItem("uid-key")) }) }) result = await result.json() console.log(result.message) if (result.code !== 200) return console.log(result.message) this.framework = result.framework this.allJobs = result.message this.toShowJobs = this.allJobs this.stateJobs = this.allJobs.filter(j => j.type === 'state') this.corpJobs = this.allJobs.filter(j => j.type === 'corp') document.getElementById("panel-content").style.backgroundImage = `url(../../img/panel${this.darkMode === true ? "Dark" : "Light"}ModeJobs.png)` document.getElementById("loading-container").style.opacity = 0 } })