mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-26 10:00:37 +00:00
Basic User edit in tables
This commit is contained in:
parent
ff16afbf0b
commit
62447d6b89
58
cps/admin.py
58
cps/admin.py
@ -212,6 +212,64 @@ def view_configuration():
|
|||||||
restrictColumns=restrict_columns,
|
restrictColumns=restrict_columns,
|
||||||
title=_(u"UI Configuration"), page="uiconfig")
|
title=_(u"UI Configuration"), page="uiconfig")
|
||||||
|
|
||||||
|
@admi.route("/admin/usertable")
|
||||||
|
@login_required
|
||||||
|
@admin_required
|
||||||
|
def edit_user_table():
|
||||||
|
visibility = current_user.view_settings.get('useredit', {})
|
||||||
|
allUser = ub.session.query(ub.User).all()
|
||||||
|
return render_title_template("user_table.html", users=allUser, visiblility=visibility,
|
||||||
|
title=_(u"Edit Users"), page="usertable")
|
||||||
|
|
||||||
|
@admi.route("/axjax/listusers")
|
||||||
|
@login_required
|
||||||
|
@admin_required
|
||||||
|
def list_users():
|
||||||
|
off = request.args.get("offset") or 0
|
||||||
|
limit = request.args.get("limit") or 10
|
||||||
|
|
||||||
|
total_count = ub.session.query(ub.User).count()
|
||||||
|
search = request.args.get("search")
|
||||||
|
if search:
|
||||||
|
users = ub.session.query(ub.User).filter().offset(off).limit(limit).all()
|
||||||
|
filtered_count = users.length()
|
||||||
|
# entries, filtered_count, pagination = calibre_db.get_search_results(search, off, order, limit)
|
||||||
|
else:
|
||||||
|
users = ub.session.query(ub.User).offset(off).limit(limit).all()
|
||||||
|
filtered_count = total_count
|
||||||
|
|
||||||
|
table_entries = {'totalNotFiltered': total_count, 'total': filtered_count, "rows": users}
|
||||||
|
js_list = json.dumps(table_entries, cls=db.AlchemyEncoder)
|
||||||
|
|
||||||
|
response = make_response(js_list)
|
||||||
|
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
@admi.route("/axjax/editlistusers/<param>", methods=['POST'])
|
||||||
|
@login_required
|
||||||
|
@admin_required
|
||||||
|
def edit_list_user(param):
|
||||||
|
vals = request.form.to_dict()
|
||||||
|
user = ub.session.query(ub.User).filter(ub.User.id == vals['pk']).one_or_none() # ub.User.query calibre_db.get_book(vals['pk'])
|
||||||
|
if param =='nickname':
|
||||||
|
if not ub.session.query(ub.User).filter(ub.User.nickname == vals['value']).scalar():
|
||||||
|
user.nickname = vals['value']
|
||||||
|
else:
|
||||||
|
log.error(u"This username is already taken")
|
||||||
|
return _(u"This username is already taken"), 400
|
||||||
|
elif param =='email':
|
||||||
|
existing_email = ub.session.query(ub.User).filter(ub.User.email == vals['value'].lower()).first()
|
||||||
|
if not existing_email:
|
||||||
|
user.email = vals['value']
|
||||||
|
else:
|
||||||
|
log.error(u"Found an existing account for this e-mail address.")
|
||||||
|
return _(u"Found an existing account for this e-mail address."), 400
|
||||||
|
elif param =='kindle_mail':
|
||||||
|
user.kindle_mail = vals['value']
|
||||||
|
ub.session_commit()
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
@admi.route("/admin/viewconfig", methods=["POST"])
|
@admi.route("/admin/viewconfig", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -344,6 +344,103 @@ $(function() {
|
|||||||
$("#h3").removeClass("hidden");
|
$("#h3").removeClass("hidden");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// User table handling
|
||||||
|
var user_column = [];
|
||||||
|
$("#user-table > thead > tr > th").each(function() {
|
||||||
|
var element = {};
|
||||||
|
if ($(this).attr("data-edit")) {
|
||||||
|
element = {
|
||||||
|
editable: {
|
||||||
|
mode: "inline",
|
||||||
|
emptytext: "<span class='glyphicon glyphicon-plus'></span>",
|
||||||
|
error: function(response) {
|
||||||
|
return response.responseText;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var validateText = $(this).attr("data-edit-validate");
|
||||||
|
if (validateText) {
|
||||||
|
element.editable.validate = function (value) {
|
||||||
|
if ($.trim(value) === "") return validateText;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
user_column.push(element);
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#user-table").bootstrapTable({
|
||||||
|
sidePagination: "server",
|
||||||
|
pagination: true,
|
||||||
|
paginationLoop: false,
|
||||||
|
paginationDetailHAlign: " hidden",
|
||||||
|
paginationHAlign: "left",
|
||||||
|
idField: "id",
|
||||||
|
uniqueId: "id",
|
||||||
|
search: true,
|
||||||
|
showColumns: true,
|
||||||
|
searchAlign: "left",
|
||||||
|
showSearchButton : false,
|
||||||
|
searchOnEnterKey: true,
|
||||||
|
checkboxHeader: false,
|
||||||
|
maintainMetaData: true,
|
||||||
|
responseHandler: responseHandler,
|
||||||
|
columns: user_column,
|
||||||
|
formatNoMatches: function () {
|
||||||
|
return "";
|
||||||
|
},
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
/*onEditableSave: function (field, row, oldvalue, $el) {
|
||||||
|
if (field === "title" || field === "authors") {
|
||||||
|
$.ajax({
|
||||||
|
method:"get",
|
||||||
|
dataType: "json",
|
||||||
|
url: window.location.pathname + "/../../ajax/sort_value/" + field + "/" + row.id,
|
||||||
|
success: function success(data) {
|
||||||
|
var key = Object.keys(data)[0];
|
||||||
|
$("#books-table").bootstrapTable("updateCellByUniqueId", {
|
||||||
|
id: row.id,
|
||||||
|
field: key,
|
||||||
|
value: data[key]
|
||||||
|
});
|
||||||
|
// console.log(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},*/
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
onColumnSwitch: function (field, checked) {
|
||||||
|
var visible = $("#user-table").bootstrapTable("getVisibleColumns");
|
||||||
|
var hidden = $("#user-table").bootstrapTable("getHiddenColumns");
|
||||||
|
var st = "";
|
||||||
|
visible.forEach(function(item) {
|
||||||
|
st += "\"" + item.field + "\":\"" + "true" + "\",";
|
||||||
|
});
|
||||||
|
hidden.forEach(function(item) {
|
||||||
|
st += "\"" + item.field + "\":\"" + "false" + "\",";
|
||||||
|
});
|
||||||
|
st = st.slice(0, -1);
|
||||||
|
/*$.ajax({
|
||||||
|
method:"post",
|
||||||
|
contentType: "application/json; charset=utf-8",
|
||||||
|
dataType: "json",
|
||||||
|
url: window.location.pathname + "/../../ajax/table_settings",
|
||||||
|
data: "{" + st + "}",
|
||||||
|
});*/
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#user-table").on("check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table",
|
||||||
|
function (e, rowsAfter, rowsBefore) {
|
||||||
|
var rows = rowsAfter;
|
||||||
|
|
||||||
|
if (e.type === "uncheck-all") {
|
||||||
|
rows = rowsBefore;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ids = $.map(!$.isArray(rows) ? [rows] : rows, function (row) {
|
||||||
|
return row.id;
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Function for deleting domain restrictions */
|
/* Function for deleting domain restrictions */
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<h2>{{_('Users')}}</h2>
|
<h2>{{_('Users')}}</h2>
|
||||||
|
{% if allUser.__len__() < 10 %}
|
||||||
<table class="table table-striped" id="table_user">
|
<table class="table table-striped" id="table_user">
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{_('Username')}}</th>
|
<th>{{_('Username')}}</th>
|
||||||
@ -41,6 +42,9 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
{% else %}
|
||||||
|
<div class="btn btn-default" id="admin_user_table"><a href="{{url_for('admin.edit_user_table')}}">{{_('Edit Users')}}</a></div>
|
||||||
|
{% endif %}
|
||||||
<div class="btn btn-default" id="admin_new_user"><a href="{{url_for('admin.new_user')}}">{{_('Add New User')}}</a></div>
|
<div class="btn btn-default" id="admin_new_user"><a href="{{url_for('admin.new_user')}}">{{_('Add New User')}}</a></div>
|
||||||
{% if (config.config_login_type == 1) %}
|
{% if (config.config_login_type == 1) %}
|
||||||
<div class="btn btn-default" id="import_ldap_users" data-toggle="modal" data-target="#StatusDialog">{{_('Import LDAP Users')}}</div>
|
<div class="btn btn-default" id="import_ldap_users" data-toggle="modal" data-target="#StatusDialog">{{_('Import LDAP Users')}}</div>
|
||||||
|
46
cps/templates/user_table.html
Normal file
46
cps/templates/user_table.html
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
{% extends "layout.html" %}
|
||||||
|
{% macro user_table_row(parameter, edit_text, show_text, validate) -%}
|
||||||
|
<th data-field="{{ parameter }}" id="{{ parameter }}" data-sortable="true"
|
||||||
|
data-visible = "{{visiblility.get(parameter)}}"
|
||||||
|
data-editable-type="text"
|
||||||
|
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>
|
||||||
|
{%- endmacro %}
|
||||||
|
|
||||||
|
{% block header %}
|
||||||
|
<link href="{{ url_for('static', filename='css/libs/bootstrap-table.min.css') }}" rel="stylesheet">
|
||||||
|
<link href="{{ url_for('static', filename='css/libs/bootstrap-editable.css') }}" rel="stylesheet">
|
||||||
|
{% endblock %}
|
||||||
|
{% block body %}
|
||||||
|
<h2 class="{{page}}">{{_(title)}}</h2>
|
||||||
|
<table id="user-table" class="table table-no-bordered table-striped"
|
||||||
|
data-url="{{url_for('admin.list_users')}}">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th data-field="state" data-checkbox="true" data-sortable="true"></th>
|
||||||
|
<th data-field="id" id="id" data-visible="false" data-switchable="false"></th>
|
||||||
|
{{ 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-field="admin" data-checkbox="true" data-sortable="true"></th>
|
||||||
|
<th data-field="upload" data-checkbox="true" data-sortable="true"></th>
|
||||||
|
<th data-field="download" data-checkbox="true" data-sortable="true"></th>
|
||||||
|
<th data-field="view_books" data-checkbox="true" data-sortable="true"></th>
|
||||||
|
<th data-field="edit" data-checkbox="true" data-sortable="true"></th>
|
||||||
|
<th data-field="delete" data-checkbox="true" data-sortable="true"></th>
|
||||||
|
<th data-field="public_shelf" data-checkbox="true" data-sortable="true"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
</table>
|
||||||
|
{% endblock %}
|
||||||
|
{% block js %}
|
||||||
|
<script src="{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-table.min.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-table-editable.min.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-editable.min.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/table.js') }}"></script>
|
||||||
|
<script>
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user