Commit a3a11bdf authored by Ozzie Isaacs's avatar Ozzie Isaacs

Changed checkbox states are saved on server

parent 70b503f3
...@@ -269,16 +269,21 @@ def delete_user(): ...@@ -269,16 +269,21 @@ def delete_user():
return return
@admi.route("/axjax/editlistusers/<param>", methods=['POST']) # @admi.route("/ajax/editlistusers/<param>", defaults={"value": 0}, methods=['POST'])
@admi.route("/ajax/editlistusers/<param>", methods=['POST'])
@login_required @login_required
@admin_required @admin_required
def edit_list_user(param): def edit_list_user(param):
vals = request.form.to_dict() vals = request.form.to_dict(flat=False)
all_user = ub.session.query(ub.User) all_user = ub.session.query(ub.User)
if not config.config_anonbrowse: if not config.config_anonbrowse:
all_user = all_user.filter(ub.User.role.op('&')(constants.ROLE_ANONYMOUS) != constants.ROLE_ANONYMOUS) all_user = all_user.filter(ub.User.role.op('&')(constants.ROLE_ANONYMOUS) != constants.ROLE_ANONYMOUS)
# only one user is posted
user = all_user.filter(ub.User.id == vals['pk']).one_or_none() if "pk" in vals:
user = all_user.filter(ub.User.id == vals['pk']).one_or_none()
else:
# ToDo
user = all_user.filter(ub.User.id == vals['pk[]']).all()
if param =='nickname': if param =='nickname':
if not ub.session.query(ub.User).filter(ub.User.nickname == vals['value']).scalar(): if not ub.session.query(ub.User).filter(ub.User.nickname == vals['value']).scalar():
user.nickname = vals['value'] user.nickname = vals['value']
...@@ -294,6 +299,17 @@ def edit_list_user(param): ...@@ -294,6 +299,17 @@ def edit_list_user(param):
return _(u"Found an existing account for this e-mail address."), 400 return _(u"Found an existing account for this e-mail address."), 400
elif param =='kindle_mail': elif param =='kindle_mail':
user.kindle_mail = vals['value'] user.kindle_mail = vals['value']
elif param == 'role':
if vals['value'] == 'true':
user.role |= int(vals['field_index'])
else:
user.role &= ~int(vals['field_index'])
elif param == 'sidebar_view':
if vals['value'] == 'true':
user.sidebar_view |= int(vals['field_index'])
else:
user.sidebar_view &= ~int(vals['field_index'])
ub.session_commit() ub.session_commit()
return "" return ""
......
...@@ -387,7 +387,6 @@ $(function() { ...@@ -387,7 +387,6 @@ $(function() {
return ""; return "";
}, },
onPostBody () { onPostBody () {
// var elements = ;
// Remove all checkboxes from Headers for showing the texts in the column selector // Remove all checkboxes from Headers for showing the texts in the column selector
$('.columns [data-field]').each(function(){ $('.columns [data-field]').each(function(){
var elText = $(this).next().text(); var elText = $(this).next().text();
...@@ -436,6 +435,10 @@ $(function() { ...@@ -436,6 +435,10 @@ $(function() {
}, },
}); });
$("#user_delete_selection").click(function() {
$("#user-table").bootstrapTable("uncheckAll");
});
function user_handle (userId) { function user_handle (userId) {
$.ajax({ $.ajax({
method:"post", method:"post",
...@@ -451,8 +454,6 @@ $(function() { ...@@ -451,8 +454,6 @@ $(function() {
$("#user-table").bootstrapTable("load", data); $("#user-table").bootstrapTable("load", data);
} }
}); });
} }
...@@ -462,7 +463,7 @@ $(function() { ...@@ -462,7 +463,7 @@ $(function() {
} }
}); });
/*$("#user-table").on("check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table", $("#user-table").on("check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table",
function (e, rowsAfter, rowsBefore) { function (e, rowsAfter, rowsBefore) {
var rows = rowsAfter; var rows = rowsAfter;
...@@ -473,7 +474,23 @@ $(function() { ...@@ -473,7 +474,23 @@ $(function() {
var ids = $.map(!$.isArray(rows) ? [rows] : rows, function (row) { var ids = $.map(!$.isArray(rows) ? [rows] : rows, function (row) {
return row.id; return row.id;
}); });
});*/ var func = $.inArray(e.type, ["check", "check-all"]) > -1 ? "union" : "difference";
selections = window._[func](selections, ids);
if (selections.length < 1) {
$("#user_delete_selection").addClass("disabled");
$("#user_delete_selection").attr("aria-disabled", true);
$(".check_head").attr("aria-disabled", true);
$(".check_head").attr("disabled", true);
$(".check_head").prop('checked', false);
} else {
$("#user_delete_selection").removeClass("disabled");
$("#user_delete_selection").attr("aria-disabled", false);
$(".check_head").attr("aria-disabled", false);
$(".check_head").removeAttr("disabled");
}
});
}); });
/* Function for deleting domain restrictions */ /* Function for deleting domain restrictions */
...@@ -528,21 +545,61 @@ function singleUserFormatter(value, row) { ...@@ -528,21 +545,61 @@ function singleUserFormatter(value, row) {
function checkboxFormatter(value, row, index){ function checkboxFormatter(value, row, index){
if(value & this.column) if(value & this.column)
return '<input type="checkbox" class="chk" checked onchange="checkboxChange(this, '+index+')">'; return '<input type="checkbox" class="chk" checked onchange="checkboxChange(this, ' + row.id + ', \'' + this.field + '\', ' + this.column + ')">';
else else
return '<input type="checkbox" class="chk" onchange="checkboxChange(this, '+index+')">'; return '<input type="checkbox" class="chk" onchange="checkboxChange(this, ' + row.id + ', \'' + this.field + '\', ' + this.column + ')">';
} }
function checkboxChange(checkbox, index){ function checkboxChange(checkbox, userId, field, field_index) {
$('#user-table').bootstrapTable('updateCell', { $.ajax({
index: index, method:"post",
field: 'role', url: window.location.pathname + "/../../ajax/editlistusers/" + field,
value: checkbox.checked, data: {"pk":userId, "field_index":field_index, "value": checkbox.checked}
reinit: false });
$.ajax({
method:"get",
url: window.location.pathname + "/../../ajax/listusers",
async: true,
timeout: 900,
success:function(data) {
$("#user-table").bootstrapTable("load", data);
}
}); });
} }
function checkboxHeader(checkbox, field, field_index) {
var result = $('#user-table').bootstrapTable('getSelections').map(a => a.id);
$.ajax({
method:"post",
url: window.location.pathname + "/../../ajax/editlistusers/" + field,
data: {"pk":result, "field_index":field_index, "value": checkbox.checked}
});
$.ajax({
method:"get",
url: window.location.pathname + "/../../ajax/listusers",
async: true,
timeout: 900,
success:function(data) {
$("#user-table").bootstrapTable("load", data);
}
});
}
function user_handle (userId) {
$.ajax({
method:"post",
url: window.location.pathname + "/../../ajax/deleteuser",
data: {"userid":userId}
});
$.ajax({
method:"get",
url: window.location.pathname + "/../../ajax/listusers",
async: true,
timeout: 900,
success:function(data) {
$("#user-table").bootstrapTable("load", data);
}
});
function checkboxHeader(element) {
console.log("hallo");
} }
This diff is collapsed.
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