Skip to content

Commit

Permalink
habit 이름 수정 기능
Browse files Browse the repository at this point in the history
  • Loading branch information
TIAHWANG committed Apr 23, 2020
1 parent 3c594d9 commit 674e8c0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app.py
Expand Up @@ -15,6 +15,7 @@
def home():
return render_template('index.html')


@app.route('/habits', methods=['GET'])
def listing():
current_email = request.args.get('email')
Expand Down Expand Up @@ -46,6 +47,17 @@ def saving():
return jsonify({'result': 'success', 'current_email': current_email})


@app.route('/habits-edit', methods=['POST'])
def editName():
name_receive = request.form['title']
edited_name_receive = request.form['newTitle']

db.habits.update({'habit': name_receive}, {'$set': {'habit': edited_name_receive}})
db.calendars.update({'title': name_receive}, {'$set': {'title': edited_name_receive}}, upsert=True, multi=True)

return jsonify({'result': 'success'})


@app.route('/habits-date', methods=['GET'])
def listingEvents():
events_list = list(db.calendars.aggregate([{
Expand Down
28 changes: 28 additions & 0 deletions templates/habits.html
Expand Up @@ -116,6 +116,34 @@ <h2>한달에 이만큼 했네요 😄</h2>
</div>

<script>
$("#external-events div").click((e) => {
let targetName = e.target.innerHTML;
const editMsg = prompt(`선택된 습관: ${targetName}🥰 변경하고 싶은 이름을 적어주세요`);
if (editMsg) {
let newName = editMsg;
// console.log(newName);
e.target.innerHTML = newName;

$.ajax({
type: "POST",
url: "/habits-edit",
data: {
title: targetName,
newTitle: newName,
},
dataType: "json",
success: function (response) {
if (response["result"] == "success") {
alert("변경 성공!");
window.location.reload();
} else {
alert("서버 오류!");
}
},
});
}
});

function openChartModal() {
$("#chart__container").show();
}
Expand Down
6 changes: 5 additions & 1 deletion templates/index.html
Expand Up @@ -63,7 +63,11 @@
},
success: function (response) {
if (response["result"] == "success") {
alert("등록 성공!");
if (habit1 === "" || habit2 == "") {
alert("로그인 성공");
} else {
alert("등록 성공!");
}
window.location.href = "/habits?email=" + response["current_email"];
} else {
alert("서버 오류!");
Expand Down

0 comments on commit 674e8c0

Please sign in to comment.