Skip to content

Commit

Permalink
saved completed
Browse files Browse the repository at this point in the history
  • Loading branch information
walaamedhat committed Jan 23, 2018
1 parent 2d438d8 commit 48fad7c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 14 deletions.
76 changes: 62 additions & 14 deletions public/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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';
}
Expand All @@ -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';
}
Expand All @@ -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();
}
};
}
},
);
}
8 changes: 8 additions & 0 deletions src/controllers/men.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ exports.get = (req, res) => {
});
});
}
} else {
return res.render('men', {
layout: 'fashion',
menFashion,
style: 'style',
title: 'Men Fashion',
});
}
return null;
});
};
7 changes: 7 additions & 0 deletions src/views/saved.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
<div class="innerbox">
<a class="a" href="#"><img src="./image/{{gender}}/{{img}}" alt="fashion"></a>
</div>
<p class="info">{{price}} NIS <a><i id="{{id}}" class="fa fa-heart" onclick="savedpage({{id}})"></i></a></p>
<div id="myModal" class="modal">
<div class="modal-content">
<span id="close" class="close">&times;</span>
<p id="text"></p>
</div>
</div>
<p>{{title}}</p>
</div>
{{/each}}
Expand Down

0 comments on commit 48fad7c

Please sign in to comment.