Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22389469
konwersacje.html
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
konwersacje.html
View Options
<!DOCTYPE html>
<
html
>
<
head
>
<
script
src
=
"/jquery.js"
></
script
>
<
script
src
=
"/authorization.js"
></
script
>
<
meta
charset
=
"utf-8"
>
<
title
>
Lista konwersacji
</
title
>
<
link
rel
=
"stylesheet"
href
=
"/style.css"
>
<
meta
name
=
"viewport"
content
=
"width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1"
>
</
head
>
<
body
>
<
nav
>
<
a
href
=
"/"
>
Menu główne
</
a
>
</
nav
>
<
center
><
h1
>
Lista konwersacji
</
h1
></
center
>
<
ul
id
=
"lista-konwersacji"
>
</
ul
>
<
input
type
=
"text"
placeholder
=
"Tytuł konwersacji"
id
=
"title"
>
<
select
id
=
"user2"
></
select
>
<
button
id
=
"confirm"
onclick
=
"addNewConversation()"
>
Dodaj
</
button
>
</
body
>
<
script
>
Auth
.
redirect_if_not_logged_in
();
var
users
;
var
me
;
function
create_users_array
(
callback
){
$
.
get
(
"/api/v1/users"
,
function
(
data
){
$
.
get
(
"api/v1/users/me"
,
function
(
user_data
){
me
=
user_data
.
user_id
;
for
(
var
i
in
data
){
users
=
data
;
var
entry
=
data
[
i
];
if
(
entry
.
user_id
!=
me
){
$
(
"#user2"
).
append
(
$
(
"<option value='"
+
entry
.
user_id
+
"'>"
+
entry
.
username
+
"</option>"
));
}
}
callback
(
me
);
});
});
}
function
findById
(
users
,
id
){
for
(
var
i
in
users
){
if
(
users
[
i
].
user_id
==
id
){
return
users
[
i
].
username
;
}
}
}
function
readConversations
(){
$
(
"#lista-konwersacji"
).
html
(
""
);
$
.
get
(
"/api/v1/chat/conversation/mine"
,
function
(
data
)
{
data
=
data
[
0
].
concat
(
data
[
1
]);
for
(
var
i
in
data
)
{
var
entry
=
data
[
i
];
var
conversor
;
if
(
me
==
entry
.
user1
){
conversor
=
findById
(
users
,
entry
.
user2
);
}
else
{
conversor
=
findById
(
users
,
entry
.
user1
);
}
var
node
=
$
(
"<li id='"
+
entry
.
id
+
"'><a href='konwersacja.html#"
+
entry
.
id
+
"'>"
+
entry
.
title
+
"</a><i> rozmowa z użytkownikiem: "
+
conversor
+
" </i> <button class='negative' onclick='deleteCoversation("
+
entry
.
id
+
")'>Usuń</button>"
);
var
selectMode
=
$
(
"<select class='access_mode'><option value='private' >Prywatna</option><option value='public'>Publiczna</option></select>"
);
node
.
append
(
selectMode
);
selectMode
.
val
(
entry
.
access_mode
);
$
(
"#lista-konwersacji"
).
append
(
node
);
}
});
}
function
addNewConversation
(){
var
title
=
$
(
"#title"
).
val
();
var
user2
=
$
(
"#user2"
).
val
();
$
.
get
(
"api/v1/users/me"
,
function
(
user_data
){
//me = user_data.user_id;
$
.
post
(
"/api/v1/chat/conversation"
,
{
title
:
title
,
user2
:
user2
,
user1
:
me
},
function
(
result
)
{
if
(
result
){
readConversations
();
}
else
{
document
.
location
.
href
=
"/login.html"
;
}
});
});
}
function
deleteCoversation
(
conversation_id
){
$
.
ajax
({
url
:
'/api/v1/chat/conversation'
,
data
:
{
id
:
conversation_id
},
type
:
'DELETE'
,
success
:
function
(
result
)
{
readConversations
();
}
});
}
function
editAccessMode
(
conversation_id
,
new_access_mode
){
$
.
ajax
({
url
:
'/api/v1/chat/conversation/'
+
conversation_id
+
'/access_mode'
,
data
:
{
access_mode
:
new_access_mode
},
type
:
'PUT'
,
success
:
function
(
result
){
readConversations
();
}
})
}
function
getAccessMode
(
conversation_id
,
callback
){
$
.
get
(
"/api/v1/chat/conversation/"
+
conversation_id
+
"/access_mode"
,
function
(
data
)
{
callback
(
data
);
});
}
$
(
document
).
ready
(
function
(){
$
(
document
).
on
(
"change"
,
"select.access_mode"
,
function
(
e
){
console
.
log
(
"dupa"
);
var
id
=
$
(
this
).
parent
().
attr
(
"id"
);
var
access_mode
=
$
(
this
).
val
();
editAccessMode
(
id
,
access_mode
);
});
});
create_users_array
(
readConversations
);
</
script
>
</
html
>
File Metadata
Details
Attached
Mime Type
text/html
Expires
Fri, Nov 27, 15:15 (21 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1223090
Default Alt Text
konwersacje.html (3 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline