diff --git a/cps/admin.py b/cps/admin.py index 30b268cb..03f83d5a 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -269,16 +269,21 @@ def delete_user(): return -@admi.route("/axjax/editlistusers/", methods=['POST']) +# @admi.route("/ajax/editlistusers/", defaults={"value": 0}, methods=['POST']) +@admi.route("/ajax/editlistusers/", 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 "" diff --git a/cps/static/js/table.js b/cps/static/js/table.js index b857fc95..46502d69 100644 --- a/cps/static/js/table.js +++ b/cps/static/js/table.js @@ -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 ''; + return ''; else - return ''; + return ''; } -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(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"); } diff --git a/cps/templates/user_table.html b/cps/templates/user_table.html index 3c6d4ed5..e2ac62e5 100644 --- a/cps/templates/user_table.html +++ b/cps/templates/user_table.html @@ -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 }} + {% if validate %}data-edit-validate="{{ _('This Field is Required') }}" {% endif %}> + {{ show_text }} + +{%- endmacro %} + +{% macro user_checkbox_row(parameter, array_field, show_text, element, value) -%} + +
+ +
+
+ +
+ {{show_text}} + {%- endmacro %} {% block header %} @@ -17,8 +37,11 @@ {% endblock %} {% block body %}

{{_(title)}}

- -
+
+
+
{{_('Remove Selections')}}
+
+
@@ -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) }} - - - - - - - - - {{ 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) }} - - - - - - - - - - - - - - + {{ 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)}}

{{_('Admin')}}

{{_('Upload')}}

{{_('Download')}}

{{_('Edit')}}

{{_('Change Password')}}

{{_('Edit Public Shelfs')}}

{{_('Delete')}}

{{_('View')}}

{{_('Show Random Books in Detail View')}}

{{_('Show language selection')}}

{{_('Show series selection')}}

{{ _('Show category selection')}}

{{ _('Show random books')}}

{{_('Show author selection')}}

{{_('Show Top Rated Books')}}

{{_('Show random books')}}

{{_('Show publisher selection')}}

{{_('Show ratings selection')}}

{{_('Show file formats selection')}}

{{_('Show archived books')}}

{{_('Show Downloaded Books')}}

{{_('Show Books List')}}
{{_('Delete User')}}