Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
TDT4242 Spring 2021 – T17
tdt4242-T17
Commits
33c643a3
Commit
33c643a3
authored
Apr 15, 2021
by
Erlend Ydse
Browse files
Extract logic for hiding or showing elements and for displaying profile rows
parent
30002907
Pipeline
#128439
passed with stage
in 1 minute and 11 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
frontend/www/scripts/profile.js
View file @
33c643a3
/**
*
* @param {string} elementID The ID of the element to show
*/
function
showElement
(
elementID
)
{
document
.
getElementById
(
elementID
).
classList
.
remove
(
"
hide
"
);
}
/**
*
* @param {string} elementID The ID of the element to hide
*/
function
hideElement
(
elementID
)
{
document
.
getElementById
(
elementID
).
classList
.
add
(
"
hide
"
);
}
/**
*
* @param {string} textID
* @param {string} rowID
* @param {string} value
*/
function
displayRow
(
textID
,
rowID
,
value
)
{
if
(
value
)
{
document
.
getElementById
(
textID
).
textContent
=
value
;
showElement
(
rowID
);
}
}
/**
*
* @param {{username: String, id: Number, url: String, email: String, phone_number: String, country: String, city: String, street_address: String, bio: String, athletes: []}} profile
...
...
@@ -8,22 +37,10 @@ function renderProfileDetails(profile) {
}
document
.
getElementById
(
"
username
"
).
textContent
=
profile
.
username
;
document
.
getElementById
(
"
email
"
).
textContent
=
profile
.
email
;
if
(
profile
.
phone_number
)
{
document
.
getElementById
(
"
phone
"
).
textContent
=
profile
.
phone_number
;
document
.
getElementById
(
"
phone-row
"
).
classList
.
remove
(
"
hide
"
);
}
if
(
profile
.
country
)
{
document
.
getElementById
(
"
country
"
).
textContent
=
profile
.
country
;
document
.
getElementById
(
"
country-row
"
).
classList
.
remove
(
"
hide
"
);
}
if
(
profile
.
city
)
{
document
.
getElementById
(
"
city
"
).
textContent
=
profile
.
city
;
document
.
getElementById
(
"
city-row
"
).
classList
.
remove
(
"
hide
"
);
}
if
(
profile
.
street_address
)
{
document
.
getElementById
(
"
address
"
).
textContent
=
profile
.
street_address
;
document
.
getElementById
(
"
address-row
"
).
classList
.
remove
(
"
hide
"
);
}
displayRow
(
"
phone
"
,
"
phone-row
"
,
profile
.
phone_number
);
displayRow
(
"
country
"
,
"
country-row
"
,
profile
.
country
);
displayRow
(
"
city
"
,
"
city-row
"
,
profile
.
city
);
displayRow
(
"
address
"
,
"
address-row
"
,
profile
.
street_address
);
document
.
getElementById
(
"
bio
"
).
textContent
=
profile
.
bio
;
}
...
...
@@ -34,22 +51,22 @@ function switchToEditBio(profile) {
const
bioEdit
=
document
.
getElementById
(
"
bio-edit
"
);
bioEdit
.
value
=
profile
.
bio
;
bioEdit
.
classList
.
remove
(
"
hide
"
);
document
.
get
Element
ById
(
"
bio-display
"
)
.
classList
.
add
(
"
hide
"
)
;
hide
Element
(
"
bio-display
"
);
}
function
switchToDisplayBio
()
{
document
.
get
Element
ById
(
"
bio-edit
"
)
.
classList
.
add
(
"
hide
"
)
;
document
.
get
Element
ById
(
"
bio-display
"
)
.
classList
.
remove
(
"
hide
"
)
;
hide
Element
(
"
bio-edit
"
);
show
Element
(
"
bio-display
"
);
}
function
editImage
()
{
document
.
getElementById
(
"
div-image-edit
"
).
classList
.
remove
(
"
hide
"
);
document
.
getElementById
(
"
btn-image-edit
"
).
classList
.
add
(
"
hide
"
);
hideElement
(
"
btn-image-edit
"
);
showElement
(
"
div-image-edit
"
);
}
function
displayImage
()
{
document
.
get
Element
ById
(
"
div-image-edit
"
)
.
classList
.
add
(
"
hide
"
)
;
document
.
get
Element
ById
(
"
btn-image-edit
"
)
.
classList
.
remove
(
"
hide
"
)
;
hide
Element
(
"
div-image-edit
"
);
show
Element
(
"
btn-image-edit
"
);
}
/**
...
...
Write
Preview
Supports
Markdown
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