Skip to content
Snippets Groups Projects
Commit 6cd58951 authored by Brian Wood's avatar Brian Wood
Browse files

Complete UI for creating and deleting libraries

parent f24eab18
No related branches found
No related tags found
No related merge requests found
......@@ -16,13 +16,25 @@ def libraries(user = None):
@app.route('/libraries/add', methods=['POST'])
@security('user')
def addLibrary(user = None):
name = request.get['name']
name = request.form['name']
library = Library.objects(user=user,unit='Movie',name=name).first()
if library:
return jsonify(response='error',message='Library with name %s already exists' % library.name),404
library = Library(user=user,unit='Movie',name=name).save()
return jsonify(response='success',type='redirect',path=url_for(endpoint='libraries',_external=True))
@app.route('/libraries/remove', methods=['POST'])
@security('user')
def removeLibrary(user = None):
name = request.form['name']
library = Library.objects(user=user,unit='Movie',name=name).first()
if not library:
return jsonify(response='error',message='Library requested does not exists'),404
if library.name == 'Master' or library.name == 'Borrowed':
return jsonify(response='error',message='Library %s cannot be deleted' % library.name),404
library.delete()
return jsonify(response='success',type='redirect',path=url_for(endpoint='libraries',_external=True))
@app.route('/libraries/<name>')
@security('user')
def library(name,user=None):
......
{% extends "modal_base.html" %}
{% block modal_title %} Add Library {% endblock %}
{% block modal_content %}
<form class="form-horizontal" id="addLibrary" role="form" method="post" action="{{ url_for('addLibrary') }}">
<div class="form-group">
<label for="name" class="col-sm-3 control-label">Name</label>
<div class="col-xs-9 col-md-6">
<input type="text" class="form-control" name="name" placeholder="New Library Name">
</div>
</div>
</form>
{% endblock %}
{% block accept_button_text %}Submit{% endblock %}
{% block ajax_url %}'{{ url_for('addLibrary') }}'{% endblock %}
{% block form_id %}addLibrary{% endblock %}
{% block validation_rules %}
rules: {
name: "required",
}
{% endblock %}
\ No newline at end of file
{% extends "usernav.html" %}
{% block content %}
<div class="col-sm-12">
<div class="col-md-4">
<h3>My Libraries</h3>
</div>
<div class="btn-group pull-right">
<button type="button" class="btn btn-default add-movie" data-toggle="modal" data-target="#addLibrary-form">Add Library</button>
</div>
<table class="table table-striped table-hover">
<thead>
<tr>
......@@ -24,9 +29,7 @@
{{ library.collection|length }}
</td>
<td>
<button class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-pencil"></span> Edit
</button>
<button type="button" class="btn btn-default btn-small remove-library" data-name='{{ library.name }}'>Delete</button>
</td>
</tr>
{% endfor %}
......@@ -35,6 +38,10 @@
</div>
{% endblock %}
{% block modals %}
{% include 'library/addlibrary_modal.html' %}
{% endblock %}
{% block javascript %}
<script>
$(function(){
......@@ -42,7 +49,42 @@
$('.clickable').on('click',function(){
var libname = $(this).data('name');
window.document.location = libraryPath.replace('__lib__',libname);
})
});
var removePath = '{{ url_for("removeLibrary") }}';
$('.remove-library').on('click',function(event){
event.stopPropagation();
event.preventDefault();
var library_name = $(this).data('name');
var message = "Are you sure you want to delete this Library?";
if(library_name == "Master" || library_name == "Borrowed"){
alert("You cannot delete the "+library_name+" library.");
return false;
}
if(confirm(message)){
$.ajax({
url: removePath,
data: {name:library_name},
method: 'POST',
success: function(data,status,jqXHR){
if(data['response'] == 'success'){
if(data['type'] == 'redirect'){
window.document.location = data['path'];
} else if (data['type'] == 'reload') {
window.document.location.reload();
}
}
},
error: function(jqXHR, textStatus, errorThrown){
response = jqXHR.responseJSON;
if('message' in response){
alert(response['message']);
}
}
});
}
});
});
</script>
{% endblock %}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment