mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-25 01:20:32 +00:00
Changed checkbox states are saved on server
This commit is contained in:
parent
70b503f3d4
commit
a3a11bdf3f
24
cps/admin.py
24
cps/admin.py
@ -269,16 +269,21 @@ def delete_user():
|
||||
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
|
||||
@admin_required
|
||||
def edit_list_user(param):
|
||||
vals = request.form.to_dict()
|
||||
vals = request.form.to_dict(flat=False)
|
||||
all_user = ub.session.query(ub.User)
|
||||
if not config.config_anonbrowse:
|
||||
all_user = all_user.filter(ub.User.role.op('&')(constants.ROLE_ANONYMOUS) != constants.ROLE_ANONYMOUS)
|
||||
|
||||
user = all_user.filter(ub.User.id == vals['pk']).one_or_none()
|
||||
# only one user is posted
|
||||
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 not ub.session.query(ub.User).filter(ub.User.nickname == vals['value']).scalar():
|
||||
user.nickname = vals['value']
|
||||
@ -294,6 +299,17 @@ def edit_list_user(param):
|
||||
return _(u"Found an existing account for this e-mail address."), 400
|
||||
elif param =='kindle_mail':
|
||||
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()
|
||||
return ""
|
||||
|
||||
|
@ -387,7 +387,6 @@ $(function() {
|
||||
return "";
|
||||
},
|
||||
onPostBody () {
|
||||
// var elements = ;
|
||||
// Remove all checkboxes from Headers for showing the texts in the column selector
|
||||
$('.columns [data-field]').each(function(){
|
||||
var elText = $(this).next().text();
|
||||
@ -436,6 +435,10 @@ $(function() {
|
||||
},
|
||||
});
|
||||
|
||||
$("#user_delete_selection").click(function() {
|
||||
$("#user-table").bootstrapTable("uncheckAll");
|
||||
});
|
||||
|
||||
function user_handle (userId) {
|
||||
$.ajax({
|
||||
method:"post",
|
||||
@ -451,8 +454,6 @@ $(function() {
|
||||
$("#user-table").bootstrapTable("load", data);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -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) {
|
||||
var rows = rowsAfter;
|
||||
|
||||
@ -473,7 +474,23 @@ $(function() {
|
||||
var ids = $.map(!$.isArray(rows) ? [rows] : rows, function (row) {
|
||||
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 */
|
||||
@ -528,21 +545,61 @@ function singleUserFormatter(value, row) {
|
||||
|
||||
function checkboxFormatter(value, row, index){
|
||||
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
|
||||
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){
|
||||
$('#user-table').bootstrapTable('updateCell', {
|
||||
index: index,
|
||||
field: 'role',
|
||||
value: checkbox.checked,
|
||||
reinit: false
|
||||
function checkboxChange(checkbox, userId, field, field_index) {
|
||||
$.ajax({
|
||||
method:"post",
|
||||
url: window.location.pathname + "/../../ajax/editlistusers/" + field,
|
||||
data: {"pk":userId, "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 checkboxHeader(element) {
|
||||
console.log("hallo");
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
@ -7,8 +7,28 @@
|
||||
data-editable-url="{{ url_for('admin.edit_list_user', param=parameter)}}"
|
||||
data-editable-title="{{ edit_text }}"
|
||||
data-edit="true"
|
||||
{% if validate %}data-edit-validate="{{ _('This Field is Required') }}" {% endif %}
|
||||
>{{ show_text }}</th>
|
||||
{% if validate %}data-edit-validate="{{ _('This Field is Required') }}" {% endif %}>
|
||||
{{ show_text }}
|
||||
</th>
|
||||
{%- endmacro %}
|
||||
|
||||
{% macro user_checkbox_row(parameter, array_field, show_text, element, value) -%}
|
||||
<th data-name="{{array_field}}" data-field="{{parameter}}"
|
||||
data-visible="{{element.get(array_field)}}"
|
||||
data-column="{{value.get(array_field)}}"
|
||||
data-formatter="checkboxFormatter">
|
||||
<div class="form-check">
|
||||
<label>
|
||||
<input type="radio" class="check_head" name="options_{{array_field}}" onchange="checkboxHeader(this, '{{parameter}}', {{value.get(array_field)}})" disabled>{{_('Deny')}}
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<label>
|
||||
<input type="radio" class="check_head" name="options_{{array_field}}" onchange="checkboxHeader(this, '{{parameter}}', {{value.get(array_field)}})" disabled>{{_('Allow')}}
|
||||
</label>
|
||||
</div>
|
||||
{{show_text}}
|
||||
</th>
|
||||
{%- endmacro %}
|
||||
|
||||
{% block header %}
|
||||
@ -17,8 +37,11 @@
|
||||
{% endblock %}
|
||||
{% block body %}
|
||||
<h2 class="{{page}}">{{_(title)}}</h2>
|
||||
<table>
|
||||
</table>
|
||||
<div class="col-xs-12 col-sm-12">
|
||||
<div class="row">
|
||||
<div class="btn btn-default disabled" id="user_delete_selection" aria-disabled="true">{{_('Remove Selections')}}</div>
|
||||
</div>
|
||||
</div>
|
||||
<table id="user-table" class="table table-no-bordered table-striped"
|
||||
data-url="{{url_for('admin.list_users')}}">
|
||||
<thead>
|
||||
@ -29,32 +52,32 @@
|
||||
{{ user_table_row('nickname', _('Enter Username'), _('Username'), true) }}
|
||||
{{ user_table_row('email', _('Enter E-mail Address'), _('E-mail Address'), true) }}
|
||||
{{ user_table_row('kindle_mail', _('Enter Kindle E-mail Address'), _('Kindle E-mail'), true) }}
|
||||
<th data-name="admin_role" data-field="role" data-visible="{{visiblility.get('admin_role')}}" data-column="{{all_roles.admin_role}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chkhead" onchange="checkboxHeader(this)"><br>{{_('Admin')}}</th>
|
||||
<th data-name="download_role" data-field="role" data-visible="{{visiblility.get('download_role')}}" data-column="{{all_roles.download_role}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chkhead" onchange="checkboxHeader(this)"><br>{{_('Upload')}}</th>
|
||||
<th data-name="upload_role" data-field="role" data-visible="{{visiblility.get('upload_role')}}" data-column="{{all_roles.upload_role}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chkhead" onchange="checkboxHeader(this)"><br>{{_('Download')}}</th>
|
||||
<th data-name="edit_role" data-field="role" data-visible="{{visiblility.get('edit_role')}}" data-column="{{all_roles.edit_role}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chkhead" onchange="checkboxHeader(this)"><br>{{_('Edit')}}</th>
|
||||
<th data-name="passwd_role" data-field="role" data-visible="{{visiblility.get('passwd_role')}}" data-column="{{all_roles.passwd_role}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chkhead" onchange="checkboxHeader(this)"><br>{{_('Change Password')}}</th>
|
||||
<th data-name="edit_shelf_role" data-field="role" data-visible="{{visiblility.get('edit_shelf_role')}}" data-column="{{all_roles.edit_shelf_role}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chkhead" onchange="checkboxHeader(this)"><br>{{_('Edit Public Shelfs')}}</th>
|
||||
<th data-name="delete_role" data-field="role" data-visible="{{visiblility.get('delete_role')}}" data-column="{{all_roles.delete_role}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chkhead" onchange="checkboxHeader(this)"><br>{{_('Delete')}}</th>
|
||||
<th data-name="viewer_role" data-field="role" data-visible="{{visiblility.get('viewer_role')}}" data-column="{{all_roles.viewer_role}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chkhead" onchange="checkboxHeader(this)"><br>{{_('View')}}</th>
|
||||
{{ user_table_row('denied_tags', _("Enter Users's Locale"), _("Users's Locale"), true) }}
|
||||
{{ user_table_row('allowed_tags', _("Enter Users's Locale"), _("Users's Locale"), true) }}
|
||||
{{ user_table_row('allowed_column_value', _("Enter Users's Locale"), _("Users's Locale"), true) }}
|
||||
{{ user_table_row('denied_column_value', _("Enter Users's Locale"), _("Users's Locale"), true) }}
|
||||
<th data-name="detail_random" data-field="sidebar_view" data-visible="{{visiblility.get('detail_random')}}" data-column="{{sidebar_settings.detail_random}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chk" ><br>{{_('Show Random Books in Detail View')}}</th>
|
||||
<th data-name="sidebar_language" data-field="sidebar_view" data-visible="{{visiblility.get('sidebar_language')}}" data-column="{{sidebar_settings.sidebar_language}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chk" ><br>{{_('Show language selection')}}</th>
|
||||
<th data-name="sidebar_series" data-field="sidebar_view" data-visible="{{visiblility.get('sidebar_series')}}" data-column="{{sidebar_settings.sidebar_series}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chk" ><br>{{_('Show series selection')}}</th>
|
||||
<th data-name="sidebar_category" data-field="sidebar_view" data-visible="{{visiblility.get('sidebar_category')}}" data-column="{{sidebar_settings.sidebar_category}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chk" ><br>{{ _('Show category selection')}}</th>
|
||||
<th data-name="sidebar_random" data-field="sidebar_view" data-visible="{{visiblility.get('sidebar_random')}}" data-column="{{sidebar_settings.sidebar_random}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chk" ><br>{{ _('Show random books')}}</th>
|
||||
<th data-name="sidebar_author" data-field="sidebar_view" data-visible="{{visiblility.get('sidebar_author')}}" data-column="{{sidebar_settings.sidebar_author}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chk" ><br>{{_('Show author selection')}}</th>
|
||||
<th data-name="sidebar_best_rated" data-field="sidebar_view" data-visible="{{visiblility.get('sidebar_best_rated')}}" data-column="{{sidebar_settings.sidebar_best_rated}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chk" ><br>{{_('Show Top Rated Books')}}</th>
|
||||
<th data-name="sidebar_read_and_unread" data-field="sidebar_view" data-visible="{{visiblility.get('sidebar_read_and_unread')}}" data-column="{{sidebar_settings.sidebar_read_and_unread}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chk" ><br>{{_('Show random books')}}</th>
|
||||
<th data-name="sidebar_publisher" data-field="sidebar_view" data-visible="{{visiblility.get('sidebar_publisher')}}" data-column="{{sidebar_settings.sidebar_publisher}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chk" ><br>{{_('Show publisher selection')}}</th>
|
||||
<th data-name="sidebar_rating" data-field="sidebar_view" data-visible="{{visiblility.get('sidebar_rating')}}" data-column="{{sidebar_settings.sidebar_rating}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chk" ><br>{{_('Show ratings selection')}}</th>
|
||||
<th data-name="sidebar_format" data-field="sidebar_view" data-visible="{{visiblility.get('sidebar_format')}}" data-column="{{sidebar_settings.sidebar_format}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chk" ><br>{{_('Show file formats selection')}}</th>
|
||||
<th data-name="sidebar_archived" data-field="sidebar_view" data-visible="{{visiblility.get('sidebar_archived')}}" data-column="{{sidebar_settings.sidebar_archived}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chk" ><br>{{_('Show archived books')}}</th>
|
||||
<th data-name="sidebar_download" data-field="sidebar_view" data-visible="{{visiblility.get('sidebar_download')}}" data-column="{{sidebar_settings.sidebar_download}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chk" ><br>{{_('Show Downloaded Books')}}</th>
|
||||
<th data-name="sidebar_list" data-field="sidebar_view" data-visible="{{visiblility.get('sidebar_list')}}" data-column="{{sidebar_settings.sidebar_list}}" data-formatter="checkboxFormatter"><input type="checkbox" class="chk" ><br>{{_('Show Books List')}}</th>
|
||||
{{ user_checkbox_row("role", "admin_role", _('Admin'), visiblility, all_roles)}}
|
||||
{{ user_checkbox_row("role", "download_role",_('Upload'), visiblility, all_roles)}}
|
||||
{{ user_checkbox_row("role", "upload_role", _('Download'), visiblility, all_roles)}}
|
||||
{{ user_checkbox_row("role", "edit_role", _('Edit'), visiblility, all_roles)}}
|
||||
{{ user_checkbox_row("role", "passwd_role", _('Change Password'), visiblility, all_roles)}}
|
||||
{{ user_checkbox_row("role", "edit_shelf_role", _('Edit Public Shelfs'), visiblility, all_roles)}}
|
||||
{{ user_checkbox_row("role", "delete_role", _('Delete'), visiblility, all_roles)}}
|
||||
{{ user_checkbox_row("role", "viewer_role", _('View'), visiblility, all_roles)}}
|
||||
{{ user_table_row('denied_tags', _("Enter Users's Locale"), _("Denied Tags"), true) }}
|
||||
{{ user_table_row('allowed_tags', _("Edit Allowed Tags"), _("Allowed Tags"), true) }}
|
||||
{{ user_table_row('allowed_column_value', _("Edit Allowed Column Values"), _("Allowed Column Values"), true) }}
|
||||
{{ user_table_row('denied_column_value', _("Enter Users's Locale"), _("Denied Columns Values"), true) }}
|
||||
{{ user_checkbox_row("sidebar_view", "detail_random", _('Show Random Books in Detail View'), visiblility, sidebar_settings)}}
|
||||
{{ user_checkbox_row("sidebar_view", "sidebar_language", _('Show language selection'), visiblility, sidebar_settings)}}
|
||||
{{ user_checkbox_row("sidebar_view", "sidebar_series", _('Show series selection'), visiblility, sidebar_settings)}}
|
||||
{{ user_checkbox_row("sidebar_view", "sidebar_category", _('Show category selection'), visiblility, sidebar_settings)}}
|
||||
{{ user_checkbox_row("sidebar_view", "sidebar_random", _('Show random books'), visiblility, sidebar_settings)}}
|
||||
{{ user_checkbox_row("sidebar_view", "sidebar_author", _('Show author selection'), visiblility, sidebar_settings)}}
|
||||
{{ user_checkbox_row("sidebar_view", "sidebar_best_rated", _('Show Top Rated Books'), visiblility, sidebar_settings)}}
|
||||
{{ user_checkbox_row("sidebar_view", "sidebar_read_and_unread", _('Show random books'), visiblility, sidebar_settings)}}
|
||||
{{ user_checkbox_row("sidebar_view", "sidebar_publisher", _('Show publisher selection'), visiblility, sidebar_settings)}}
|
||||
{{ user_checkbox_row("sidebar_view", "sidebar_rating", _('Show ratings selection'), visiblility, sidebar_settings)}}
|
||||
{{ user_checkbox_row("sidebar_view", "sidebar_format", _('Show file formats selection'), visiblility, sidebar_settings)}}
|
||||
{{ user_checkbox_row("sidebar_view", "sidebar_archived", _('Show archived books'), visiblility, sidebar_settings)}}
|
||||
{{ user_checkbox_row("sidebar_view", "sidebar_download", _('Show Downloaded Books'), visiblility, sidebar_settings)}}
|
||||
{{ user_checkbox_row("sidebar_view", "sidebar_list", _('Show Books List'), visiblility, sidebar_settings)}}
|
||||
<th data-align="right" data-formatter="UserActions" data-switchable="false">{{_('Delete User')}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
Loading…
Reference in New Issue
Block a user