Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
a3a11bdf
Commit
a3a11bdf
authored
Feb 14, 2021
by
Ozzie Isaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed checkbox states are saved on server
parent
70b503f3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
145 additions
and
49 deletions
+145
-49
admin.py
cps/admin.py
+20
-4
table.js
cps/static/js/table.js
+72
-15
user_table.html
cps/templates/user_table.html
+53
-30
No files found.
cps/admin.py
View file @
a3a11bdf
...
...
@@ -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
""
...
...
cps/static/js/table.js
View file @
a3a11bdf
...
...
@@ -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
(
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"
);
}
cps/templates/user_table.html
View file @
a3a11bdf
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment