Bibliotecha/Source
Revision as of 13:41, 5 April 2014 by Andre Castro (talk | contribs) (Created page with "=Upload section= In order to serve the upload page: * Start a server from this directory python serve.py * check if server by going: http://localhost:8000 * go to upload pag...")
Upload section
In order to serve the upload page:
- Start a server from this directory
python serve.py
- check if server by going: http://localhost:8000
- go to upload page http://localhost:8000/book_form.html
FILE TREE
Bibliotecha/ ├── bibliotecha │ ├── book_form.html │ ├── cgi-bin │ │ └── book_get.py │ ├── files │ │ └── book_tmp.pdf │ ├── index.html │ └── jquery-1.10.2.min.js ├── LIBRARIAN_NOTES ├── README_Bibliotecha.txt └── serve.py
upload form - book_form.html
<!DOCTYPE html>
<html xml:lang="en" lang="en">
<head>
<meta charset="UTF-8" />
<script type="text/javascript" src="jquery-1.10.2.min.js"></script>
</head>
<body>
<form class="book" name="book" method="post" enctype="multipart/form-data" action="cgi-bin/book_get.py">
<!-- action -- The URI of a web page that processes the information submitted via the form. -->
<div>
<lable>Authors:</lable>
<input type="text" name="authorone" placeholder="First_Name Surname" id="author_one" />
<input type="text" name="authortwo" placeholder="First_Name Surname" id="author_two" />
<input type="text" name="authorthree" placeholder="First_Name Surname" id="author_three" />
<lable><small>* At least one author must be provided</small></lable>
<br /><br />
<lable>Title:</lable>
<input type="text" name="title" value="" id="title" placeholder="Title"/>
<br /><br />
<lable>Category:</lable>
<select name="tag" id="tag">
<option ></option>
<option value="Media theory">Media theory</option>
<option value="Art">Art</option>
<option value="Music">Music</option>
</select>
<br /><br />
<input type="file" name="book" value="" id="file"/>
<br /><br />
</div>
<br />
<div>
<button id="upload" disabled>Upload book</button>
</div>
</form>
<script type="text/javascript">
// on focus fields
// do check if all the remaining 3 fields are selected
// then enable upload
var fileready = 0;
function checkfields(){
if( $('input#title').val() != '' && $('input#author_one').val() != '' && $('input#file').val() != '' && $('select#tag').val() != '' )
{
// check file
console.log('TITLE');
//if file is there
if (fileready == 1)
{ document.getElementById("upload").disabled=false; }
}
else
{ document.getElementById("upload").disabled=true; }
}
$(document).ready(
function(){
$('select').change(
function(){
checkfields();
}
)
$('input').focusout(
function(){
checkfields();
}
)
$('input#file').focusout(
function(){
var file = document.getElementById('file');
file.onchange = function(e){
var ext = this.value.match(/\.([^\.]+)$/)[1];
switch(ext)
{
// || 'epub'|| 'mobi': //epub, mobi, txt, djvu
case 'pdf':
fileready=1;
break;
case 'mobi':
fileready=1;
break;
case 'epub':
fileready=1;
break;
case 'txt':
fileready=1;
break;
case 'djvu':
fileready=1;
break;
default:
fileready=0;
this.value='';
}
};
}
)
}
)
</script>
</body>
</html>