From 48fad7c2f57db955f4fcff2f8d8e5fa447ceeb60 Mon Sep 17 00:00:00 2001 From: walaamedhat Date: Tue, 23 Jan 2018 09:36:16 +0200 Subject: [PATCH] saved completed #27 --- public/js/functions.js | 76 ++++++++++++++++++++++++++++++++++-------- src/controllers/men.js | 8 +++++ src/views/saved.hbs | 7 ++++ 3 files changed, 77 insertions(+), 14 deletions(-) diff --git a/public/js/functions.js b/public/js/functions.js index 22e57f6..aad1610 100644 --- a/public/js/functions.js +++ b/public/js/functions.js @@ -23,13 +23,12 @@ function burgerAction() { } let save; -function btnClick(id, cb) { +function btnClick(id) { const elem = document.getElementById(id); const heart = elem.className; const p = document.getElementById('text'); const modal = document.getElementById('myModal'); const span = document.getElementById('close'); - if (heart === 'fa fa-heart-o') { save = true; elem.classList.remove('fa-heart-o'); @@ -41,20 +40,31 @@ function btnClick(id, cb) { }), (err, result) => { if (err) { - alert('error in database'); + p.textContent = 'Erorr in server'; + modal.style.display = 'block'; } else if (result.status === 401) { - alert("The clothes didn't saved"); - window.location.pathname = '/login'; + p.textContent = 'Login first'; + modal.style.display = 'block'; + span.onclick = () => { + modal.style.display = 'none'; + window.location.pathname = '/login'; + }; + window.onclick = (event) => { + if (event.target == modal) { + modal.style.display = 'none'; + window.location.pathname = '/login'; + } + }; } else { p.textContent = 'Saved successed'; modal.style.display = 'block'; - span.onclick = function () { + span.onclick = () => { modal.style.display = 'none'; p.textContent = 'Unsaved successed'; }; - window.onclick = function (event) { - if (event.target == modal) { + window.onclick = (event) => { + if (event.target === modal) { modal.style.display = 'none'; p.textContent = 'Unsaved successed'; } @@ -73,20 +83,21 @@ function btnClick(id, cb) { }), (err, result) => { if (err) { - alert('error in database'); + p.textContent = 'Erorr in server'; + modal.style.display = 'block'; } else if (result.status === 401) { - alert("The clothes didn't unsaved"); - window.location.pathname = '/login'; + p.textContent = "The clothes didn't un saved"; + modal.style.display = 'block'; } else { p.textContent = 'Unsaved successed'; modal.style.display = 'block'; - span.onclick = function () { + span.onclick = () => { modal.style.display = 'none'; p.textContent = 'Saved successed'; }; - window.onclick = function (event) { - if (event.target == modal) { + window.onclick = (event) => { + if (event.target === modal) { modal.style.display = 'none'; p.textContent = 'Saved successed'; } @@ -96,3 +107,40 @@ function btnClick(id, cb) { ); } } + +function savedpage(id) { + const elem = document.getElementById(id); + const heart = elem.className; + const p = document.getElementById('text'); + const modal = document.getElementById('myModal'); + const span = document.getElementById('close'); + fetchFunction( + '/unsaved', + JSON.stringify({ + clothId: id, + }), + (err, result) => { + if (err) { + p.textContent = 'Erorr in server'; + modal.style.display = 'block'; + } else if (result.status === 401) { + p.textContent = "The clothes didn't un saved"; + modal.style.display = 'block'; + } else { + p.textContent = 'Unsaved successed'; + modal.style.display = 'block'; + span.onclick = () => { + modal.style.display = 'none'; + window.location.reload(); + }; + + window.onclick = (event) => { + if (event.target === modal) { + modal.style.display = 'none'; + window.location.reload(); + } + }; + } + }, + ); +} diff --git a/src/controllers/men.js b/src/controllers/men.js index 6128653..6b89550 100644 --- a/src/controllers/men.js +++ b/src/controllers/men.js @@ -29,6 +29,14 @@ exports.get = (req, res) => { }); }); } + } else { + return res.render('men', { + layout: 'fashion', + menFashion, + style: 'style', + title: 'Men Fashion', + }); } + return null; }); }; diff --git a/src/views/saved.hbs b/src/views/saved.hbs index 11628fd..ec41555 100644 --- a/src/views/saved.hbs +++ b/src/views/saved.hbs @@ -24,6 +24,13 @@
fashion
+

{{price}} NIS

+

{{title}}

{{/each}}