forked from mrlan/EnglishPal
[REFACTOR] user_service.py: Added id to user name, word and frequency for click to execute AJAX request in JS
parent
b9cf94da74
commit
670e5a2083
|
@ -6,6 +6,8 @@ css:
|
|||
# 全局引入的js文件地址
|
||||
js:
|
||||
head: # 在页面加载之前加载
|
||||
- static/js/jquery.js
|
||||
- static/js/word_operation.js
|
||||
# - static/js/APlayer.js
|
||||
# - static/js/Meting.js
|
||||
bottom: # 在页面加载完之后加载
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,43 @@
|
|||
function familiar(index) {
|
||||
var username = $("#username").text();
|
||||
var word = $("#word_" + index).text();
|
||||
var freq = $("#freq_" + index).text();
|
||||
$.ajax({
|
||||
type:"get",
|
||||
url:"/" + username + "/" + word + "/familiar",
|
||||
success:function(resp){
|
||||
var new_freq = freq - 1;
|
||||
if(new_freq <1) {
|
||||
$("#p_" + index).remove();
|
||||
} else {
|
||||
$("#freq_" + index).text(new_freq);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function unfamiliar(index) {
|
||||
var username = $("#username").text();
|
||||
var word = $("#word_" + index).text();
|
||||
var freq = $("#freq_" + index).text();
|
||||
$.ajax({
|
||||
type:"get",
|
||||
url:"/" + username + "/" + word + "/unfamiliar",
|
||||
success:function(resp){
|
||||
var new_freq = parseInt(freq) + 1;
|
||||
$("#freq_" + index).text(new_freq);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function del_word(index) {
|
||||
var username = $("#username").text();
|
||||
var word = $("#word_" + index).text();
|
||||
$.ajax({
|
||||
type:"get",
|
||||
url:"/" + username + "/" + word + "/del",
|
||||
success:function(resp){
|
||||
$("#p_" + index).remove();
|
||||
}
|
||||
});
|
||||
}
|
|
@ -22,7 +22,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<div class="container-fluid">
|
||||
<p><b>English Pal for <font color="red">{{ username }}</font></b>
|
||||
<p><b>English Pal for <font id="username" color="red">{{ username }}</font></b>
|
||||
<a class="btn btn-secondary" href="/logout" role="button">退出</a>
|
||||
<a class="btn btn-secondary" href="/reset" role="button">重设密码</a>
|
||||
</p>
|
||||
|
@ -57,37 +57,20 @@
|
|||
<p><b>我的生词簿</b></p>
|
||||
{% for x in lst3 %}
|
||||
{% set word = x[0] %}
|
||||
|
||||
{% set freq = x[1] %}
|
||||
{% if session.get('thisWord') == x[0] and session.get('time') == 1 %}
|
||||
<a name="aaa"></a>
|
||||
{% endif %}
|
||||
{% if freq > 1 %}
|
||||
<p class="new-word">
|
||||
<a class="btn btn-light" href='http://youdao.com/w/eng/{{ word }}/#keyfrom=dict2.index'
|
||||
role="button">{{ word }}</a>
|
||||
(
|
||||
<a title="{{ word }}">{{ freq }}</a>
|
||||
)
|
||||
|
||||
<a class="btn btn-success" href={{ username }}/{{ word }}/familiar role="button">熟悉</a>
|
||||
<a class="btn btn-warning" href={{ username }}/{{ word }}/unfamiliar role="button">不熟悉</a>
|
||||
<a class="btn btn-danger" href={{ username }}/{{ word }}/del role="button">删除</a>
|
||||
</p>
|
||||
{% else %}
|
||||
<p class="new-word">
|
||||
<a class="btn btn-light" href='http://youdao.com/w/eng/{{ word }}/#keyfrom=dict2.index'
|
||||
role="button">{{ word }}</a>
|
||||
(
|
||||
<a title="{{ word }}">{{ freq }}</a>
|
||||
)
|
||||
<a class="btn btn-success" href={{ username }}/{{ word }}/familiar role="button">熟悉</a>
|
||||
<a class="btn btn-warning" href={{ username }}/{{ word }}/unfamiliar role="button">不熟悉</a>
|
||||
<a class="btn btn-danger" href={{ username }}/{{ word }}/del role="button">删除</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<a href='http://youdao.com/w/eng/{{ word }}/#keyfrom=dict2.index'>{{ word }}</a>{{ freq }}
|
||||
<p id='p_{{ loop.index0 }}' class="new-word" >
|
||||
<a id="word_{{ loop.index0 }}" class="btn btn-light" href='http://youdao.com/w/eng/{{ word }}/#keyfrom=dict2.index'
|
||||
role="button">{{ word }}</a>
|
||||
(
|
||||
<a id="freq_{{ loop.index0 }}" title="{{ word }}">{{ freq }}</a>
|
||||
)
|
||||
<a class="btn btn-success" onclick="familiar({{ loop.index0 }})" role="button">熟悉</a>
|
||||
<a class="btn btn-warning" onclick="unfamiliar({{ loop.index0 }})" role="button">不熟悉</a>
|
||||
<a class="btn btn-danger" onclick="del_word({{ loop.index0 }})" role="button">删除</a>
|
||||
</p>
|
||||
{% endfor %}
|
||||
<input id="selected-words2" type="hidden" value="{{ words }}">
|
||||
{% endif %}
|
||||
|
|
|
@ -48,7 +48,7 @@ def unfamiliar(username, word):
|
|||
pickle_idea.unfamiliar(user_freq_record, word)
|
||||
session['thisWord'] = word # 1. put a word into session
|
||||
session['time'] = 1
|
||||
return redirect(url_for('user_bp.userpage', username=username))
|
||||
return "success"
|
||||
|
||||
|
||||
@userService.route("/<username>/<word>/familiar", methods=['GET', 'POST'])
|
||||
|
@ -63,7 +63,7 @@ def familiar(username, word):
|
|||
pickle_idea.familiar(user_freq_record, word)
|
||||
session['thisWord'] = word # 1. put a word into session
|
||||
session['time'] = 1
|
||||
return redirect(url_for('user_bp.userpage', username=username))
|
||||
return "success"
|
||||
|
||||
|
||||
@userService.route("/<username>/<word>/del", methods=['GET', 'POST'])
|
||||
|
@ -77,7 +77,7 @@ def deleteword(username, word):
|
|||
user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username)
|
||||
pickle_idea2.deleteRecord(user_freq_record, word)
|
||||
flash(f'<strong>{word}</strong> is no longer in your word list.')
|
||||
return redirect(url_for('user_bp.userpage', username=username))
|
||||
return "success"
|
||||
|
||||
|
||||
@userService.route("/<username>", methods=['GET', 'POST'])
|
||||
|
|
Loading…
Reference in New Issue