Add frontend for updating transactions
This commit is contained in:
parent
12e7dbcc93
commit
9e544ec64a
8
.vscode/launch.json
vendored
8
.vscode/launch.json
vendored
@ -20,6 +20,14 @@
|
||||
"program": "database.py",
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true
|
||||
},
|
||||
{
|
||||
"name": "Flask",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "app.py",
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true
|
||||
}
|
||||
]
|
||||
}
|
127
app.py
Executable file
127
app.py
Executable file
@ -0,0 +1,127 @@
|
||||
from datetime import datetime
|
||||
|
||||
from flask import Flask, render_template, request, abort
|
||||
import peewee
|
||||
from playhouse.shortcuts import model_to_dict
|
||||
|
||||
import database
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config["DEBUG"] = True
|
||||
|
||||
@app.before_request
|
||||
def before_request():
|
||||
database.instance.connect()
|
||||
|
||||
@app.after_request
|
||||
def after_request(response):
|
||||
database.instance.close()
|
||||
return response
|
||||
|
||||
@app.route("/")
|
||||
def home():
|
||||
puppies = ['hollie', 'grace', 'loki']
|
||||
return render_template('index.html', puppies=puppies)
|
||||
|
||||
@app.route("/users")
|
||||
def users():
|
||||
args = request.args.to_dict()
|
||||
if 'username' not in args:
|
||||
abort(400)
|
||||
|
||||
username = args['username'].strip()
|
||||
try:
|
||||
return model_to_dict(database.User.get(database.User.username == username))
|
||||
except peewee.DoesNotExist:
|
||||
abort(404)
|
||||
except:
|
||||
abort(500)
|
||||
|
||||
@app.route("/transactions", methods=["GET", "POST"])
|
||||
def transactions():
|
||||
if request.method == "GET":
|
||||
args = request.args.to_dict()
|
||||
if 'user_id' not in args:
|
||||
abort(400)
|
||||
|
||||
user_id = args['user_id'].strip()
|
||||
try:
|
||||
july_2022 = datetime(2022, 7, 1, 0)
|
||||
transactions = database.Transaction.select().where(
|
||||
(database.Transaction.user == user_id) &
|
||||
(database.Transaction.transaction_date > july_2022)
|
||||
)
|
||||
return [model_to_dict(t) for t in transactions]
|
||||
except peewee.DoesNotExist:
|
||||
abort(404)
|
||||
except:
|
||||
abort(500)
|
||||
|
||||
if request.method == "POST":
|
||||
body = request.get_json()
|
||||
try:
|
||||
user = database.User.get(database.User.uuid == body['user_id'])
|
||||
category = database.TransactionCategory.get(database.TransactionCategory.name == body['category'])
|
||||
database.Transaction.create(
|
||||
user=user,
|
||||
subcategory=category,
|
||||
transaction_date=body['transaction_date'],
|
||||
description=body['description'],
|
||||
amount=body['amount'],
|
||||
type=body['type'],
|
||||
notes=body['notes']
|
||||
)
|
||||
return ('', 200)
|
||||
except peewee.DoesNotExist:
|
||||
abort(404)
|
||||
except KeyError:
|
||||
abort(400)
|
||||
|
||||
# Default if no method is hit
|
||||
abort(400)
|
||||
|
||||
@app.route("/transactions/<uuid>", methods=["PUT"])
|
||||
def transaction(uuid=None):
|
||||
if request.method == "PUT":
|
||||
if not uuid:
|
||||
abort(400)
|
||||
|
||||
body = request.get_json()
|
||||
if 'category' not in body or 'notes' not in body:
|
||||
abort(400)
|
||||
|
||||
try:
|
||||
category = database.TransactionCategory.get(database.TransactionCategory.name == body['category'])
|
||||
transaction = database.Transaction.get(database.Transaction.primary_key == uuid)
|
||||
transaction.subcategory = category
|
||||
transaction.notes = body['notes']
|
||||
transaction.save()
|
||||
return ('', 200)
|
||||
except peewee.DoesNotExist:
|
||||
abort(404)
|
||||
except:
|
||||
abort(500)
|
||||
|
||||
# Default if no method is hit
|
||||
abort(400)
|
||||
|
||||
@app.route("/categories")
|
||||
def categories():
|
||||
try:
|
||||
raw_categories = database.TransactionCategory.select()
|
||||
categories = {}
|
||||
for category in raw_categories:
|
||||
if not category.parent:
|
||||
categories[category.name] = []
|
||||
|
||||
for category in raw_categories:
|
||||
if category.parent:
|
||||
categories[category.parent.name].append(category.name)
|
||||
|
||||
return categories
|
||||
except peewee.DoesNotExist:
|
||||
abort(404)
|
||||
except:
|
||||
abort(500)
|
||||
|
||||
app.run()
|
16
database.py
16
database.py
@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
import uuid
|
||||
from peewee import *
|
||||
|
||||
DATABASE = 'budget.db'
|
||||
@ -7,7 +8,7 @@ instance = SqliteDatabase(DATABASE, pragmas=[('foreign_keys', 'on')])
|
||||
def create_tables():
|
||||
"""Helper function to create database tables. Should be called manually."""
|
||||
with instance:
|
||||
instance.create_tables([User, TransactionCategory, Transaction, Source])
|
||||
instance.create_tables([User, TransactionCategory, Transaction])
|
||||
|
||||
def add_user():
|
||||
# Make my user.
|
||||
@ -45,24 +46,20 @@ class BaseModel(Model):
|
||||
database = instance
|
||||
|
||||
class User(BaseModel):
|
||||
username = CharField(unique=True, primary_key=True)
|
||||
uuid = UUIDField(unique=True, primary_key=True, default=uuid.uuid4())
|
||||
username = CharField(unique=True)
|
||||
|
||||
class TransactionCategory(BaseModel):
|
||||
primary_key = AutoField(primary_key=True)
|
||||
name = CharField(unique=True)
|
||||
parent = ForeignKeyField('self', null=True, backref='children')
|
||||
|
||||
class Source(BaseModel):
|
||||
filename=CharField(unique=True, primary_key=True)
|
||||
type = IntegerField()
|
||||
created_date = DateTimeField(default=datetime.datetime.now)
|
||||
user = ForeignKeyField(User, backref='transactions')
|
||||
|
||||
class Transaction(BaseModel):
|
||||
# Metadata
|
||||
primary_key = AutoField(primary_key=True)
|
||||
source = ForeignKeyField(Source, backref='transactions')
|
||||
created_date = DateTimeField(default=datetime.datetime.now)
|
||||
source_file=CharField(null=True)
|
||||
type = IntegerField()
|
||||
user = ForeignKeyField(User, backref='transactions')
|
||||
|
||||
# Real data
|
||||
@ -70,6 +67,7 @@ class Transaction(BaseModel):
|
||||
description = CharField()
|
||||
amount = FloatField()
|
||||
subcategory = ForeignKeyField(TransactionCategory, backref='+', null=True)
|
||||
notes = CharField(null=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
create_tables()
|
||||
|
18
main.py
18
main.py
@ -9,10 +9,14 @@ parser = argparse.ArgumentParser(prog="BudgetBear", description="Calculate a bud
|
||||
parser.add_argument('files', type=str, nargs='+', help='File to parse transactions from.')
|
||||
args = parser.parse_args()
|
||||
|
||||
username = 'ciphercules'
|
||||
# Get my user.
|
||||
database.instance.connect()
|
||||
user = database.User.select().where(database.User.username == 'ciphercules').get()
|
||||
database.instance.close()
|
||||
|
||||
file_parsers = [capital_one.Parser()]
|
||||
for f in args.files:
|
||||
filename=os.path.basename(f),
|
||||
for file_parser in file_parsers:
|
||||
# Use the first successful parser.
|
||||
transactions = file_parser.parse(f)
|
||||
@ -22,22 +26,16 @@ for f in args.files:
|
||||
# Add to database
|
||||
database.instance.connect()
|
||||
with database.instance.atomic():
|
||||
# Add source file first.
|
||||
source = database.Source.create(
|
||||
filename=os.path.basename(f),
|
||||
type=file_parser.source,
|
||||
user=username
|
||||
)
|
||||
|
||||
# Add each transaction
|
||||
for transaction in transactions:
|
||||
date, description, amount = transaction
|
||||
database.Transaction.create(
|
||||
user=username,
|
||||
user=user,
|
||||
transaction_date=date,
|
||||
description=description,
|
||||
amount=amount,
|
||||
source=source
|
||||
source_filename=filename,
|
||||
type=file_parser.source
|
||||
)
|
||||
database.instance.close()
|
||||
|
||||
|
4
model.py
4
model.py
@ -11,4 +11,6 @@ class BaseParser:
|
||||
|
||||
class TransactionSource:
|
||||
"""Enum of possible transaction sources"""
|
||||
CAPITAL_ONE = 1
|
||||
CAPITAL_ONE = 1
|
||||
SPLITWISE = 2
|
||||
COMPANY = 3
|
455
templates/index.html
Executable file
455
templates/index.html
Executable file
@ -0,0 +1,455 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>BudgetBear</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style>
|
||||
body {font-family: Arial, Helvetica, sans-serif;}
|
||||
/* The Modal (background) */
|
||||
.modal {
|
||||
display: none; /* Hidden by default */
|
||||
position: fixed; /* Stay in place */
|
||||
z-index: 1; /* Sit on top */
|
||||
padding-top: 50px; /* Location of the box */
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%; /* Full width */
|
||||
height: 100%; /* Full height */
|
||||
overflow: auto; /* Enable scroll if needed */
|
||||
background-color: rgb(0,0,0); /* Fallback color */
|
||||
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
|
||||
}
|
||||
|
||||
/* Modal Content */
|
||||
.modal-content {
|
||||
background-color: #fefefe;
|
||||
margin: auto;
|
||||
padding: 30px;
|
||||
border: 1px solid #888;
|
||||
width: 40%;
|
||||
}
|
||||
|
||||
/* The Close Button */
|
||||
.close {
|
||||
float: left;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
/* The Next Button */
|
||||
.next {
|
||||
float: right;
|
||||
margin: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>BudgetBear</h1>
|
||||
<p>The app for bears on a budget</p>
|
||||
<div id="login_form">
|
||||
<label for="login_input">Login: </label>
|
||||
<input id="login_input" name="login">
|
||||
<input id="login_submit" type="submit" value="Submit">
|
||||
</div>
|
||||
<div id="login_success" style="display:none">
|
||||
<p>Logged in as: <span id="login_username"></span></p>
|
||||
</div>
|
||||
<div id="login_error" style="display:none">
|
||||
<p style="color:red">Failed to login</p>
|
||||
</div>
|
||||
<h2>Transactions</h2>
|
||||
<input id="transactions_refresh" type="submit" value="Refresh" disabled>
|
||||
<!-- Transaction Modal -->
|
||||
<button id="transaction_modal_btn">Let's Process!</button>
|
||||
<div id="transaction_error" style="display:none">
|
||||
<p style="color:blue">No transactions to process!</p>
|
||||
</div>
|
||||
<div id="transaction_modal" class="modal">
|
||||
<div class="modal-content">
|
||||
<h3>Transaction ID <span id="transaction_id"></span></h3>
|
||||
<p><b>Remaining:</b> <span id="transactions_unprocessed"></span></p>
|
||||
<p><b>Transaction date:</b> <span id="transaction_date"></span></p>
|
||||
<p><b>Description:</b> <span id="transaction_description"></span></p>
|
||||
<p><b>Amount:</b> $<span id="transaction_amount"></span></p>
|
||||
<label for="transaction_category">Category</label>
|
||||
<select id="transaction_category"></select>
|
||||
<label for="transaction_subcategory">Subcategory</label>
|
||||
<select id="transaction_subcategory" disabled></select>
|
||||
<br><br>
|
||||
<label for="transaction_notes">Notes:</label>
|
||||
<textarea id="transaction_notes" rows="4" cols="50"></textarea>
|
||||
<br><br>
|
||||
<label for="transaction_split">Split with others?</label>
|
||||
<input type="checkbox" id="transaction_split" value="true">
|
||||
<br><br>
|
||||
<div id="transaction_split_content" style="display:none">
|
||||
<h3>Split Transaction</h3>
|
||||
<label for="transaction_split_amount">Amount reimbursed:</label>
|
||||
<input type="number" id="transaction_split_amount">
|
||||
<br><br>
|
||||
<label for="transaction_split_type">Type: </label>
|
||||
<select id="transaction_split_type">
|
||||
<option value="2">Splitwise</option>
|
||||
<option value="3">SpaceX</option>
|
||||
</select>
|
||||
<br><br>
|
||||
<label for="transaction_split_notes">Notes: </label>
|
||||
<textarea id="transaction_split_notes" rows="4" cols="50"></textarea>
|
||||
<br><br>
|
||||
</div>
|
||||
<button id="modal_close" class="close">Exit</button>
|
||||
<button id="modal_next" class="next">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Transaction Modal End -->
|
||||
</body>
|
||||
<script>
|
||||
// Login HTML elements.
|
||||
const login =
|
||||
{
|
||||
form : document.getElementById('login_form'),
|
||||
input : document.getElementById('login_input'),
|
||||
submit : document.getElementById('login_submit'),
|
||||
success : document.getElementById('login_success'),
|
||||
error : document.getElementById('login_error'),
|
||||
username : document.getElementById('login_username'),
|
||||
};
|
||||
|
||||
// Transaction HTML elements.
|
||||
const x_action =
|
||||
{
|
||||
refresh : document.getElementById('transactions_refresh'),
|
||||
modal_btn : document.getElementById('transaction_modal_btn'),
|
||||
error : document.getElementById('transaction_error'),
|
||||
modal : document.getElementById('transaction_modal'),
|
||||
id : document.getElementById('transaction_id'),
|
||||
exit: document.getElementById('modal_close'),
|
||||
submit: document.getElementById('modal_next'),
|
||||
unprocessed : document.getElementById('transactions_unprocessed'),
|
||||
date: document.getElementById('transaction_date'),
|
||||
description: document.getElementById('transaction_description'),
|
||||
amount: document.getElementById('transaction_amount'),
|
||||
category: document.getElementById('transaction_category'),
|
||||
subcategory: document.getElementById('transaction_subcategory'),
|
||||
notes: document.getElementById('transaction_notes'),
|
||||
split:
|
||||
{
|
||||
enabled: document.getElementById('transaction_split'),
|
||||
container: document.getElementById('transaction_split_content'),
|
||||
notes: document.getElementById('transaction_split_notes'),
|
||||
amount: document.getElementById('transaction_split_amount'),
|
||||
type: document.getElementById('transaction_split_type'),
|
||||
|
||||
},
|
||||
};
|
||||
|
||||
// Global variables.
|
||||
const global_data =
|
||||
{
|
||||
current_user: null,
|
||||
transaction:
|
||||
{
|
||||
unprocessed_indices: [],
|
||||
list: [],
|
||||
process_index: 0,
|
||||
unprocessed_cnt: function()
|
||||
{
|
||||
return this.unprocessed_indices.length;
|
||||
},
|
||||
get_current: function()
|
||||
{
|
||||
if (this.process_index < this.unprocessed_indices.length)
|
||||
{
|
||||
return this.list[this.unprocessed_indices[this.process_index]]
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
},
|
||||
categories: {},
|
||||
update: function()
|
||||
{
|
||||
let new_indices = []
|
||||
for (let i = 0; i < this.transaction.list.length; i++)
|
||||
{
|
||||
if (this.transaction.list[i].subcategory === null)
|
||||
{
|
||||
// Save index of first unprocessed transaction.
|
||||
new_indices.push(i);
|
||||
}
|
||||
}
|
||||
this.transaction.unprocessed_indices = new_indices;
|
||||
}
|
||||
};
|
||||
|
||||
login.input.onkeypress = function(event) {
|
||||
if (event.key === "Enter")
|
||||
{
|
||||
event.preventDefault();
|
||||
login.submit.click();
|
||||
}
|
||||
};
|
||||
|
||||
login.submit.onclick = function(_) {
|
||||
const username = login.input.value;
|
||||
const request_url = "/users?username=" + username;
|
||||
const handler =
|
||||
{
|
||||
success: function (data) {
|
||||
// Cache data in browser.
|
||||
global_data.current_user = data;
|
||||
|
||||
// Retrieve transactions.
|
||||
get_transactions(global_data.current_user.uuid);
|
||||
|
||||
// Update UI.
|
||||
login.form.style.display = 'none';
|
||||
login.error.style.display = 'none';
|
||||
login.username.innerText = data.username;
|
||||
login.success.style.display = 'block';
|
||||
},
|
||||
error: function () {
|
||||
// Update UI.
|
||||
login.error.style.display = 'block';
|
||||
}
|
||||
};
|
||||
http_request(request_url, handler);
|
||||
};
|
||||
|
||||
x_action.refresh.onclick = function() {
|
||||
get_transactions(global_data.current_user.uuid);
|
||||
}
|
||||
|
||||
x_action.modal_btn.onclick = function() {
|
||||
if (global_data.transaction.unprocessed_cnt() === 0)
|
||||
{
|
||||
x_action.error.style.display = "block";
|
||||
}
|
||||
else
|
||||
{
|
||||
update_transaction_ui(global_data.transaction.get_current());
|
||||
x_action.error.style.display = "none";
|
||||
x_action.modal.style.display = "block";
|
||||
}
|
||||
}
|
||||
|
||||
x_action.exit.onclick = function()
|
||||
{
|
||||
reset_transaction_ui();
|
||||
}
|
||||
|
||||
x_action.submit.onclick = function()
|
||||
{
|
||||
const body = {}
|
||||
if (x_action.subcategory.value !== "")
|
||||
{
|
||||
body.category = x_action.subcategory.value;
|
||||
}
|
||||
else
|
||||
{
|
||||
body.category = x_action.category.value;
|
||||
}
|
||||
body.notes = x_action.notes.value;
|
||||
const transaction = global_data.transaction.get_current()
|
||||
const url = "/transactions/" + transaction.primary_key;
|
||||
const handler =
|
||||
{
|
||||
success: function() {
|
||||
console.log("Updated transaction successfully!");
|
||||
},
|
||||
error: function() {
|
||||
alert("Failed to update transaction");
|
||||
}
|
||||
}
|
||||
http_request(url, handler, "PUT", body);
|
||||
|
||||
const is_split = x_action.split.enabled.checked;
|
||||
if (is_split)
|
||||
{
|
||||
const split_body = {}
|
||||
split_body.category = body.category;
|
||||
split_body.notes = x_action.split.notes.value;
|
||||
split_body.amount = -1 * parseFloat(x_action.split.amount.value);
|
||||
split_body.type = parseInt(x_action.split.type.value);
|
||||
split_body.transaction_date = transaction.transaction_date;
|
||||
split_body.description = transaction.description;
|
||||
split_body.user_id = global_data.current_user.uuid;
|
||||
|
||||
const url = "/transactions";
|
||||
const handler =
|
||||
{
|
||||
success: function() {
|
||||
},
|
||||
error: function() {
|
||||
alert("Failed to add split transaction");
|
||||
}
|
||||
}
|
||||
http_request(url, handler, "POST", split_body);
|
||||
}
|
||||
|
||||
global_data.transaction.process_index++;
|
||||
if (global_data.transaction.get_current() !== null)
|
||||
{
|
||||
update_transaction_ui(global_data.transaction.get_current());
|
||||
}
|
||||
else
|
||||
{
|
||||
reset_transaction_ui();
|
||||
}
|
||||
}
|
||||
|
||||
x_action.split.enabled.onclick = function()
|
||||
{
|
||||
if (x_action.split.enabled.checked == true)
|
||||
{
|
||||
x_action.split.container.style.display = 'block';
|
||||
const transaction = global_data.transaction.get_current();
|
||||
x_action.split.amount.value = transaction.amount / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
x_action.split.container.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
x_action.split.type.onchange = function()
|
||||
{
|
||||
const selected = x_action.split.type.value;
|
||||
const transaction = global_data.transaction.get_current();
|
||||
if (selected == "Splitwise")
|
||||
{
|
||||
x_action.split.amount.value = transaction.amount / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
x_action.split.amount.value = transaction.amount;
|
||||
}
|
||||
}
|
||||
|
||||
x_action.category.onchange = function()
|
||||
{
|
||||
x_action.subcategory.innerHTML = '';
|
||||
const selected = x_action.category.value;
|
||||
const subcategories = global_data.categories[selected]
|
||||
if (subcategories.length == 0)
|
||||
{
|
||||
x_action.subcategory.disabled = true
|
||||
}
|
||||
else
|
||||
{
|
||||
x_action.subcategory.disabled = undefined
|
||||
for (let i = 0; i < subcategories.length; i++)
|
||||
{
|
||||
const opt = document.createElement("option");
|
||||
opt.value = subcategories[i];
|
||||
opt.innerText = subcategories[i];
|
||||
|
||||
x_action.subcategory.appendChild(opt);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function reset_transaction_ui(close_modal=true)
|
||||
{
|
||||
// Reset all stateful inputs.
|
||||
if (close_modal)
|
||||
{
|
||||
x_action.modal.style.display = "none";
|
||||
}
|
||||
|
||||
x_action.split.container.style.display = 'none';
|
||||
x_action.split.enabled.checked = false;
|
||||
x_action.category.innerHTML = "";
|
||||
x_action.subcategory.innerHTML = "";
|
||||
x_action.subcategory.disabled = "true";
|
||||
x_action.notes.value = "";
|
||||
}
|
||||
function update_transaction_ui(transaction)
|
||||
{
|
||||
// Reset old state.
|
||||
reset_transaction_ui(false);
|
||||
|
||||
// Global updates first.
|
||||
x_action.unprocessed.innerText = global_data.transaction.unprocessed_cnt();
|
||||
for (key in global_data.categories)
|
||||
{
|
||||
const opt = document.createElement("option");
|
||||
opt.value = key;
|
||||
opt.innerText = key;
|
||||
|
||||
x_action.category.appendChild(opt);
|
||||
}
|
||||
|
||||
// Transaction specific updates.
|
||||
x_action.id.innerText = transaction.primary_key;
|
||||
x_action.date.innerText = transaction.transaction_date;
|
||||
x_action.description.innerText = transaction.description;
|
||||
x_action.amount.innerText = transaction.amount;
|
||||
}
|
||||
|
||||
function get_transactions(uuid) {
|
||||
const request_url = "/transactions?user_id=" + uuid;
|
||||
const handler =
|
||||
{
|
||||
success: function(data) {
|
||||
global_data.transaction.list = data;
|
||||
x_action.refresh.disabled = undefined;
|
||||
},
|
||||
error: function() {
|
||||
console.error("Failed to get transactions");
|
||||
}
|
||||
}
|
||||
http_request(request_url, handler);
|
||||
}
|
||||
|
||||
function get_categories() {
|
||||
const request_url = "/categories";
|
||||
const handler =
|
||||
{
|
||||
success: function(data) {
|
||||
global_data.categories = data
|
||||
},
|
||||
error: function() {
|
||||
console.error("Failed to get categories");
|
||||
}
|
||||
}
|
||||
http_request(request_url, handler);
|
||||
}
|
||||
|
||||
function http_request(url, response_handler, method="GET", body=null)
|
||||
{
|
||||
let request = new XMLHttpRequest();
|
||||
request.addEventListener("load", function(){
|
||||
if (request.status !== 200)
|
||||
{
|
||||
response_handler.error();
|
||||
}
|
||||
else
|
||||
{
|
||||
let response_body = ""
|
||||
if (request.responseText !== "")
|
||||
{
|
||||
response_body = JSON.parse(request.responseText);
|
||||
}
|
||||
response_handler.success(response_body);
|
||||
global_data.update();
|
||||
}
|
||||
})
|
||||
|
||||
const async = true;
|
||||
request.open(method, url, async);
|
||||
if (method == "POST" || method == "PUT")
|
||||
{
|
||||
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
request.send(JSON.stringify(body));
|
||||
}
|
||||
else
|
||||
{
|
||||
request.send(null);
|
||||
}
|
||||
}
|
||||
|
||||
// Do every page load.
|
||||
get_categories();
|
||||
</script>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user