Commit 8a5f8adc authored by buttle's avatar buttle

Added field addtion to data table display

parent db58dbc2
......@@ -31,7 +31,7 @@ babel = Babel(app)
csrf = CSRFProtect()
csrf.init_app(app)
app.config['APP_VERSION'] = 24
app.config['APP_VERSION'] = 25
app.config['SCHEMA_VERSION'] = 12
app.config['RESERVED_SLUGS'] = ['static', 'admin', 'admins', 'user', 'users', 'form', 'forms', 'site', 'sites', 'update']
......
......@@ -493,7 +493,7 @@ class Form(object):
def deleteEntries(self):
self.form["entries"]=[]
mongo.db.forms.update({"_id": self.form["_id"]}, {"$set": {"entries":[] }})
def isAuthor(self, user):
return True if self.author == str(user._id) else False
......
......@@ -61,6 +61,7 @@ hr { margin-top: 5px }
padding: 0.5em 0 0.5em 0;
}
/* ######### Entries table ######### */
.delete-row {
font-weight: bold !important;
color: #d9534f;
......@@ -74,6 +75,26 @@ hr { margin-top: 5px }
.deleted-row {
background-color: #FAAFBE;
text-decoration: line-through;
cursor: auto;
}
#entriesTable td:not(.deleted-row):not(:nth-child(-n+2)):not(.cellEditionMode):hover {
background-color: #ffffcc;
cursor: pointer;
}
.cellEditionMode {
cursor: auto;
}
.saveCellEdition {
font-size: 1.25em !important;
color: #5cb85c;
cursor: pointer;
padding-left: 0.27em;
}
.cancelCellEdition {
font-size: 1.25em !important;
color: #d9534f;
cursor: pointer;
padding-left: 0.27em;
}
/* ######### formBuilder fixes ######### */
input[type="date"], input[type="number"] {
......
......@@ -228,31 +228,33 @@ document.getElementById('toggle_enabled').addEventListener('click', function(evt
}
});
});
document.getElementById('toggle_dataConsent').addEventListener('click', function(evt){
$.ajax({
url : "/form/toggle-data-consent/{{ form._id }}",
type: "POST",
dataType: "json",
beforeSend: function(xhr, settings) {
if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type)) {
xhr.setRequestHeader("X-CSRFToken", csrftoken)
}
},
success: function(data, textStatus, jqXHR)
{
if (data.consent == true) {
$('#dataConsent_true').addClass('btn-success');
$('#dataConsent_false').removeClass('btn-primary');
$('#dataConsent').show();
}
else if (data.consent == false) {
$('#dataConsent_true').removeClass('btn-success');
$('#dataConsent_false').addClass('btn-primary');
$('#dataConsent').hide();
{% if form.site.isPersonalDataConsentEnabled() %}
document.getElementById('toggle_dataConsent').addEventListener('click', function(evt){
$.ajax({
url : "/form/toggle-data-consent/{{ form._id }}",
type: "POST",
dataType: "json",
beforeSend: function(xhr, settings) {
if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type)) {
xhr.setRequestHeader("X-CSRFToken", csrftoken)
}
},
success: function(data, textStatus, jqXHR)
{
if (data.consent == true) {
$('#dataConsent_true').addClass('btn-success');
$('#dataConsent_false').removeClass('btn-primary');
$('#dataConsent').show();
}
else if (data.consent == false) {
$('#dataConsent_true').removeClass('btn-success');
$('#dataConsent_false').addClass('btn-primary');
$('#dataConsent').hide();
}
}
}
});
});
});
{% endif %}
{% endif %}
function addRequiredMsg(){
if ($('#fb-render').find("span.fb-required").length) {
......
......@@ -37,7 +37,7 @@
<p>&nbsp;</p>
<table id="formEntries" style="display:none" class="table table-striped table-condensed">
<table id="entriesTable" style="display:none" class="table table-striped table-condensed">
<thead>
<tr>
<th></th>
......@@ -51,7 +51,7 @@
{% for entry in form.entries %}
<tr>
<td style="border-right: 1px solid #ccc; border-left: 1px solid #ccc;">
<i class="fa fa-ban delete-row" aria-hidden="true"></i>
<i class="fa fa-minus-circle delete-row" aria-hidden="true"></i>
</td>
{% for field in fieldIndex %}
<td style="border-right: 1px solid #ccc;">{{ entry[field['name']] }}</td>
......@@ -84,12 +84,12 @@ function getRowData($row) {
return rowData;
}
$(document).ready(function() {
$('#formEntries').DataTable({
$('#entriesTable').DataTable({
"language": {
"url": "/static/dataTables-languages/{{g.current_user.language}}.js"
},
"initComplete": function(settings, json) {
$("#formEntries").show();
$("#entriesTable").show();
},
"order": [[1, 'desc']],
"columnDefs": [
......@@ -98,8 +98,54 @@ $(document).ready(function() {
});
$('.delete-row').attr('title', "{%trans%}Delete entry{%endtrans%}");
});
$('#formEntries tbody').on('click', '.delete-row', function () {
// Edit cell
$('#entriesTable tbody').on('click', "td:not(.deleted-row):not(:nth-child(1)):not(:nth-child(2)):not(.cellEditionMode)", function () {
$(this).addClass('cellEditionMode');
var cellValue = $(this).html();
var $editor = $("<div style='white-space:nowrap;' initial_value=\""+ cellValue +"\"></div>");
$editor.append("<input style='width:70%' type='text' value=\""+ cellValue +"\" />");
$editor.append('<i class="fa fa-check-circle saveCellEdition" aria-hidden="true"></i>');
$editor.append('<i class="fa fa-times-circle cancelCellEdition" aria-hidden="true"></i>');
$(this).html($editor);
});
// Cancel edition
$('#entriesTable tbody').on('click', '.cancelCellEdition', function () {
$(this).parents("td").removeClass('cellEditionMode');
var initialValue = $(this).parent("div").attr("initial_value")
$(this).parents("td").html(initialValue);
});
// Save edition
$('#entriesTable tbody').on('click', '.saveCellEdition', function () {
var initialValue = $(this).parent("div").attr("initial_value");
var newValue = $(this).parent("div").find('input').val();
var $row = $(this).parents('tr');
var $cell = $(this).parents("td");
$cell.html(newValue);
$.ajax({
url : "/forms/change-entry-field-value/{{ form._id }}",
type: "POST",
dataType: "json",
contentType: 'application/json;charset=UTF-8',
data: JSON.stringify(getRowData($row)),
beforeSend: function(xhr, settings) {
if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type)) {
xhr.setRequestHeader("X-CSRFToken", csrftoken)
}
},
success: function(data, textStatus, jqXHR)
{
$cell.removeClass('cellEditionMode');
if (data.saved != true) {
$cell.html(initialValue);
}
}
});
});
$('#entriesTable tbody').on('click', '.delete-row', function () {
var $row=$(this).parents('tr');
if ($row.find(".cellEditionMode").length == 1){
return
}
$.ajax({
url : "/forms/delete-entry/{{ form._id }}",
type: "POST",
......@@ -120,7 +166,7 @@ $('#formEntries tbody').on('click', '.delete-row', function () {
}
});
});
$('#formEntries tbody').on('click', '.undo-delete-row', function () {
$('#entriesTable tbody').on('click', '.undo-delete-row', function () {
var $row = $(this).parents('tr');
$.ajax({
url : "/forms/undo-delete-entry/{{ form._id }}",
......@@ -137,7 +183,7 @@ $('#formEntries tbody').on('click', '.undo-delete-row', function () {
{
if (data.undone == true) {
$row.children(':not(:first-child)').removeClass('deleted-row');
$row.children('td').eq(0).html('<i class="fa fa-ban delete-row" aria-hidden="true"></i>');
$row.children('td').eq(0).html('<i class="fa fa-minus-circle delete-row" aria-hidden="true"></i>');
}
}
});
......
......@@ -712,9 +712,45 @@ def undo_delete_entry(_id):
queriedForm.entries.append(entry)
queriedForm.expired = queriedForm.hasExpired()
queriedForm.save()
queriedForm.addLog(gettext("Undeleted and entry"))
queriedForm.addLog(gettext("Undeleted an entry"))
return json.dumps({'undone': True})
@app.route('/forms/change-entry-field-value/<string:_id>', methods=['POST'])
@enabled_user_required
def change_entry(_id):
queriedForm=Form(_id=_id, editor=str(g.current_user._id))
if not queriedForm:
return json.dumps({'saved': False})
# get the 'created' field position
created_pos=next((i for i,field in enumerate(request.json) if "name" in field and field["name"] == "created"), None)
if not isinstance(created_pos, int):
return json.dumps({'saved': False})
foundEntries = [entry for entry in queriedForm.entries if entry['created'] == request.json[created_pos]["value"]]
if not foundEntries or len(foundEntries) > 1:
""" If there are two entries with the same 'created' value, we don't change anything """
print("not foubnd")
return json.dumps({'saved': False})
try:
entry_pos = [pos for pos, entry in enumerate(queriedForm.entries) if entry == foundEntries[0]][0]
except:
return json.dumps({'saved': False})
modifiedEntry={}
for field in request.json:
try:
modifiedEntry[field["name"]]=field["value"]
except:
return json.dumps({'saved': False})
del queriedForm.entries[entry_pos]
queriedForm.entries.insert(entry_pos, modifiedEntry)
queriedForm.expired = queriedForm.hasExpired()
queriedForm.save()
queriedForm.addLog(gettext("Modified an entry"))
return json.dumps({'saved': True})
@app.route('/forms/delete-entries/<string:_id>', methods=['GET', 'POST'])
@enabled_user_required
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment