mirror of
https://github.com/Blair-SGA-Dev-Team/blazerapp.git
synced 2024-11-22 04:51:15 -05:00
js
This commit is contained in:
parent
1a51323c03
commit
c3144df7c7
|
@ -26,7 +26,6 @@ pub mod defs {
|
|||
use chrono::naive::{NaiveDate, NaiveTime};
|
||||
use rocket::{http::RawStr, request::FromFormValue};
|
||||
use std::ops::Deref;
|
||||
use rocket::response::NamedFile;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DateForm(NaiveDate);
|
||||
|
@ -74,6 +73,8 @@ pub mod defs {
|
|||
Ok(n) => n,
|
||||
Err(_) => return Err(()),
|
||||
};
|
||||
// 3:15 PM
|
||||
// 5:18 AM
|
||||
let naivedate = NaiveTime::parse_from_str(&value_uri[..], "%I:%M %p");
|
||||
match naivedate {
|
||||
Ok(n) => Ok(TimeForm(n)),
|
||||
|
@ -132,7 +133,7 @@ pub mod defs {
|
|||
Ok(Image(String::from("pepega")))
|
||||
*/
|
||||
|
||||
let mut value_uri = match value.url_decode() {
|
||||
let value_uri = match value.url_decode() {
|
||||
Ok(n) => n,
|
||||
Err(_) => return Err(()),
|
||||
};
|
||||
|
|
2
cms/static/jquery.min.js
vendored
Normal file
2
cms/static/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
39
cms/static/utils.js
Normal file
39
cms/static/utils.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
|
||||
function forwardForImage(id, postloc) {
|
||||
console.log("askldjf");
|
||||
let form_elem = document.getElementById(id).children;
|
||||
let data = [];
|
||||
for (i = 0; i < form_elem.length; i++) {
|
||||
console.log(form_elem[i]);
|
||||
if (form_elem[i].type == "text") {
|
||||
data.push(form_elem[i].name + "=" + encodeURIComponent(form_elem[i].value));
|
||||
}
|
||||
if (form_elem[i].type == "select-one") {
|
||||
data.push(form_elem[i].name + "=" + encodeURIComponent(form_elem[i].value));
|
||||
}
|
||||
if (form_elem[i].type == "file") {
|
||||
var file = document.getElementById(form_elem[i].id).files[0];
|
||||
getBase64(file, form_elem, i, data, (form_elem, i, data, res) => {
|
||||
data.push(form_elem[i].name + "=" + res);
|
||||
});
|
||||
}
|
||||
}
|
||||
console.log(data);
|
||||
var params = data.join("&");
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", postloc, true);
|
||||
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
xhr.send(params);
|
||||
}
|
||||
|
||||
function getBase64(file, form_elem, i, data, callback) {
|
||||
var reader = new FileReader();
|
||||
reader.readAsDataURL(file);
|
||||
reader.onload = function () {
|
||||
callback(form_elem, i, data, reader.result);
|
||||
};
|
||||
reader.onerror = function (error) {
|
||||
console.log('Error: ', error);
|
||||
};
|
||||
}
|
||||
|
|
@ -5,14 +5,17 @@
|
|||
<link rel="stylesheet" href="/static/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<p>add</p>
|
||||
<form action="new/add" method="post">
|
||||
<input type="text", id="lang", name="lang">
|
||||
<form onsubmit="forwardForImage('new_f', 'new/add')" id="new_f" name="new_f">
|
||||
<select name="lang", id="lang">
|
||||
<option value="en">en</option>
|
||||
<option value="es">es</option>
|
||||
</select>
|
||||
<input type="file" name="image", id="image", accept="image/png">
|
||||
<input type="text", id="name", name="name">
|
||||
<input type="text", id="new_date", name="new_date">
|
||||
<input type="submit", value="Submit">
|
||||
</form>
|
||||
</body>
|
||||
</head>
|
||||
<!-- <script src="/static/jquery.min.js"></script> -->
|
||||
<script src="/static/utils.js"></script>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue
Block a user