Fakultas Ilmu Komputer UI

detail_materi.html 31.8 KB
Newer Older
1
{% extends 'base.html' %}
2
{% load static %} {% load humanize %}
3
4

{% block header %}
5
<link href="{% static 'css/sb-admin-2.min.css' %}" rel="stylesheet">
6
<link rel="stylesheet" type="text/css" href="{% static 'app/css/detail_materi.css' %}">
7
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,400;0,500;1,100&display=swap" rel="stylesheet">
8
9
<script async defer crossorigin="anonymous"
    src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v6.0"></script>
10
<script src="{% static 'js/detail_materi.js'%}"></script>
11
12
13
14
15
<style>
div.review {
    overflow: auto;
}
</style>
16
17
{% endblock header %}
{% block title %}
18
{{materi_data.title}} | Digipus
19
{% endblock title %}
20
21

{% block content %}
22
23
24
25
{% block verification %} {% endblock verification %}
<div id="fb-root"></div>
<div class="container-fluid p-0 bg detail-materi-color">
    <nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">
26

27
28
        <!-- Sidebar Toggle (Topbar) -->
        <button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
29
            <i class="fa fa-bars" aria-hidden="true"></i>
30
        </button>
31

32
        <div class="sidebar-brand-text mx-3">Diskominfo Kota Depok</div>
33

34
35
        <!-- Topbar Navbar -->
        <ul class="navbar-nav ml-auto">
36
            {% if request.user.is_contributor %}
37
38
39
40
41
42
43
44
45
            {% if materi_data.status == "DISAPPROVE" %}
            <li class="nav-item black-text">
                <a class="nav-link feedback" data-toggle="modal" data-target="#umpanBalikModal">
                    <span class="mr-2 d-none d-lg-inline text-gray-600 small">Umpan Balik Materi</span>
                </a>
                <div class="modal fade" id="umpanBalikModal" tabindex="-1" role="dialog"
                    aria-labelledby="exampleModalLabel" aria-hidden="true">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
46
                            <div class="modal-header">
47
48
49
50
                                <h5 class="modal-title black-text" id="exampleModalLabel">Umpan Balik Materi</h5>
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
51
52
                            </div>
                            <div class="modal-body">
53
                                {% for item in report %}
54
55
                                <p class="black-text">Alasan materi ditolak:</p>
                                <p class="black-text">{{ item.report.feedback }}</p>
56
57
58
                                <p class="black-text">Untuk merevisi materi, sila tekan tombol revisi di halaman riwayat
                                    unggah.</p>
                                {% endfor %}
59
60
                            </div>
                            <div class="modal-footer">
61
                                <button type="button" class="btn btn-danger" data-dismiss="modal">Tutup</button>
62
63
                            </div>
                        </div>
64
65
66
67
                    </div>
                </div>
            </li>
            {% endif %}
68
69
            {% endif %}

70
71
72
73
            <li class="nav-item">
                <a class="nav-link" href="/">
                    <span class="mr-2 d-none d-lg-inline text-gray-600 small">Halaman Katalog</span>
                </a>
74
75
            </li>

76
77
78
79
80
81
82
83
            {% if request.user.is_contributor %}
            <li class="nav-item">
                <a class="nav-link" href="/dashboard/">
                    <span class="mr-2 d-none d-lg-inline text-gray-600 small">Dasbor</span>
                </a>
            </li>
            {% endif %}

84
85
86
            <div class="topbar-divider d-none d-sm-block"></div>

            <!-- Nav Item - User Information -->
87
            {% if request.user.is_authenticated %}
88
            <li class="nav-item dropdown no-arrow">
89
90
91
92
93
94
95
96
97
98
                <a class="nav-link dropdown-toggle" href="/dashboard/">
                    <span class="mr-2 d-none d-lg-inline text-gray-600 small">{{ user.name }}</span>
                    {% if not user.default_profile_picture %}
                    <img class="img-profile rounded-circle" src="https://i.ibb.co/9wgPzyZ/default-image.png"
                        alt="User profile picture">
                    {% else %}
                    <img class="img-profile rounded-circle" src="{{ user.profile_picture.url }}"
                        alt="User profile picture">
                    {% endif %}
                </a>
99
            </li>
100
            {% endif %}
101

102
        </ul>
103

104
105
106
107
108
    </nav>
    <div class="row materi-data mr-4 ml-4 p-3 shadow-sm rounded">
        <div class="col col-3 cover">
            <img src={{materi_data.cover.url}} alt="cover">
        </div>
Anthony Dewa Priyasembada's avatar
Anthony Dewa Priyasembada committed
109
        <div class="col col-8 ml-3 book">
110
111
112
113
114
            <h2>{{materi_data.title}}</h2>
            <div class="category-wrapper">
                {% for category in materi_data.categories.all %}
                <span class="mr-1">#{{category.name}}</span>
                {% endfor %}
115
            </div>
116
117
118
119
120
121
122
123
            <div class="info-wrapper">
                <div class="info" id="1">
                    <dl class="col col-4">
                        <dt class="info-name">Penulis</dt>
                    </dl>
                    <dd>
                        <p class="info-content">{{materi_data.author}}</p>
                    </dd>
124
                </div>
125
126
127
128
129
130
131
                <div class="info" id="1">
                    <dl class="col col-4">
                        <dt class="info-name">Penerbit</dt>
                    </dl>
                    <dd>
                        <p class="info-content">{{materi_data.publisher}}</p>
                    </dd>
132
                </div>
133
134
135
136
137
138
139
140
                <div class="info" id="1">
                    <dl class="col col-4">
                        <dt class="info-name">Tahun Terbit</dt>
                    </dl>
                    <dd>
                        <p class="info-content">{{materi_data.release_year}}</p>
                    </dd>
                </div>
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
                <div class="info" id="1">
                    <dl class="col col-4">
                        <dt class="info-name">Kontributor</dt>
                    </dl>
                    <dd>
                        <a class="info-content"
                            href="{% url 'katalog-per-kontributor' materi_data.uploader.email %}">{{materi_data.uploader.name}}</a>
                    </dd>
                </div>
                <div class="info" id="1">
                    <dl class="col col-4">
                        <dt class="info-name">Jumlah Halaman</dt>
                    </dl>
                    <dd>
                        <p class="info-content">{{materi_data.pages}}</p>
                    </dd>
                </div>
                <div class="info" id="1">
                    <dl class="col col-4">
                        <dt class="info-name">Ukuran File</dt>
                    </dl>
                    <dd>
                        <p class="info-content">{{materi_data.content.size|filesizeformat}}</p>
                    </dd>
                </div>
166
167
168
169
170
171
172
173
                <div class="info" id="1">
                    <dl class="col col-4">
                        <dt class="info-name">Jumlah Like</dt>
                    </dl>
                    <dd>
                        <p class="info-content">{{materi_data.like_count}}</p>
                    </dd>
                </div>
174
175
176
177
178
179
180
181
                <div class="info" id="1">
                    <dl class="col col-4">
                        <dt class="info-name">Jumlah Download</dt>
                    </dl>
                    <dd>
                        <p class="info-content">{{materi_download_count}}</p>
                    </dd>
                </div>
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
            </div>
            <div class="buttons d-flex flex-row bd-highlight mb-1">
                <a href="{% url 'view-materi' materi_data.id %}"
                    class="btn btn-link btn-book shadow-sm p-2 mr-2 bg-white rounded">Baca</a>
                <a href="{% url 'download-materi' materi_data.id %}"
                    class="btn btn-link btn-book shadow-sm p-2 mr-2 bg-white rounded">Unduh</a>
                <div class="dropdown">
                    <button class="btn dropdown-toggle btn-book shadow-sm p-2 mr-2 bg-white rounded" type="button"
                        id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        Bagikan
                    </button>
                    <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                        <div class="fb-share-button" data-href="{% url 'detail-materi' materi_data.id %}"
                            data-layout="button" data-size="small">
                            <a target="_blank"
                                href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdigipus-staging-2.herokuapp.com%2Fmateri%2F{{materi_data.id}}%2F&amp;src=sdkpreparse"
                                class="dropdown-item fb-xfbml-parse-ignore">Facebook</a>
199
                        </div>
200
201
202
203
204
205
206
207
208
209
210
211
                        <a class="twitter-share-button dropdown-item"
                            href="https://twitter.com/intent/tweet?text=Cek%20materi%20ini%20yuk%20https%3A%2F%2Fdigipus-staging-2.herokuapp.com%2Fmateri%2F{{materi_data.id}}%2F"
                            target="_blank" data-size="large">
                            Twitter
                        </a>
                        <a class="dropdown-item"
                            href="whatsapp://send?text=Cek materi ini yuk! https://digipus-staging-2.herokuapp.com{{request.path}}"
                            target="_blank">Whatsapp</a>
                        <a class="dropdown-item"
                            href="https://social-plugins.line.me/lineit/share?url=https%3A%2F%2Fdigipus-staging-2.herokuapp.com%2Fmateri%2F{{materi_data.id}}%2F"
                            target="_blank">Line</a>
                        <p id="url" style="display: none">https://digipus-staging-2.herokuapp.com{{request.path}}</p>
212
213
                        <a class="dropdown-item"
                            href="{% url 'save-to-gdrive' materi_data.id %}">Google Drive</a>
214
                        <button class="dropdown-item btn-book" onclick="copyToClipboard('#url')">Bagikan Tautan</button>
215
216
                    </div>
                </div>
217
218
219
220
221
222
223
224
225
226
227
228
229
230
                <div class="dropdown">
                    <button class="btn dropdown-toggle btn-book shadow-sm p-2 mr-2 bg-white rounded" type="button"
                        id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        Sitasi
                    </button>
                    <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                        <div class="buttons">
                            <button class="dropdown-item" onclick="getCitation('{{citationAPA}}')">Citate APA</button>
                        </div>
                        <div class="buttons">
                            <button class="dropdown-item" onclick="getCitation('{{citationIEEE}}')">Citate IEEE</button>
                        </div>
                    </div>
                </div>
231
232
233
234
                <form action="" method="POST">
                    <input type="hidden" name="action" value="like">
                </form>
                {% if has_liked %}
235
236
                <button id="thumb" class="btn btn-link btn-book shadow-sm p-2 mr-2 bg-white rounded" onClick="postLike()"><i id="thumbIcon"
                        aria-hidden="true" class="fas fa-thumbs-up"></i><span> Disukai</span></button>
237
                {% else %}
238
239
                <button id="thumb" class="btn btn-link btn-book shadow-sm p-2 mr-2 bg-white rounded" onClick="postLike()"><i id="thumbIcon"
                        aria-hidden="true" class="far fa-thumbs-up"></i><span> Sukai</span></button>
240
                {% endif %}
241

242
243
244
245
246
247
248
249
250
251
252
253
254
255
                {% if user.is_authenticated %}
                <div class="dropdown">
                    <button class="btn dropdown-toggle btn-book shadow-sm p-2 mr-2 bg-white rounded align-self-center"
                        type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        <em id="button-rating-star-icon" class="align-self-center far fa-star"></em>
                        <span id="button-rating-text">Beri Rating</span>
                    </button>
                    <div id="star-dropdown" class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                        <div class="text-center btn-book">
                            <em onclick="postAddRating(1)" id="star-1" class="far fa-star fa-lg"></em>
                            <em onclick="postAddRating(2)" id="star-2" class="far fa-star fa-lg"></em>
                            <em onclick="postAddRating(3)" id="star-3" class="far fa-star fa-lg"></em>
                            <em onclick="postAddRating(4)" id="star-4" class="far fa-star fa-lg"></em>
                            <em onclick="postAddRating(5)" id="star-5" class="far fa-star fa-lg"></em>
256
257
258
                        </div>
                    </div>
                </div>
Anthony Dewa Priyasembada's avatar
Anthony Dewa Priyasembada committed
259
260
261
262
263
264
265
266
267
268
269
270
271
272

                    {% if is_in_read_later_list %}
                    <button class="btn btn-book shadow-sm p-2 mr-2 bg-primary text-white rounded align-self-center"
                        type="button" id="readLaterButton" aria-haspopup="true" aria-expanded="false"
                        onclick="postToggleReadLater()">
                        <em class="align-self-center far fa-check-square" id="readLaterText"></em> Baca Nanti
                    </button>
                    {% else %}
                    <button class="btn btn-book shadow-sm p-2 mr-2 bg-white text-primary rounded align-self-center"
                        type="button" id="readLaterButton" aria-haspopup="true" aria-expanded="false"
                        onclick="postToggleReadLater()">
                        <em class="align-self-center far fa-square" id="readLaterText"></em> Baca Nanti
                    </button>
                    {% endif %}
273
274
275
276
277
278
                {% else %}
                <button class="btn dropdown-toggle btn-book shadow-sm p-2 mr-2 bg-white rounded align-self-center"
                    type="button" id="dropdownMenuButton" aria-haspopup="true" aria-expanded="false" data-toggle="modal"
                    data-target="#notLoggedInModal">
                    <em class="align-self-center far fa-star"></em> Beri Rating
                </button>
Anthony Dewa Priyasembada's avatar
Anthony Dewa Priyasembada committed
279
280
281
282
283
284
                
                <button class="btn btn-book shadow-sm p-2 mr-2 bg-white text-primary rounded align-self-center"
                        type="button" id="readLaterButton" aria-haspopup="true" aria-expanded="false"
                        onclick="postToggleReadLater()">
                        <em class="align-self-center far fa-square" id="readLaterText"></em> Baca Nanti
                </button>
285
                {% endif %}
286
287
            </div>
        </div>
288
289
290
291
292
293
294
295
296
297
298
    </div>
    <div class="row menu-wrapper mr-4 ml-4 p-3">
        <nav class="navbar navbar-expand-sm border-top border-bottom p-0 mt-3 mb-3">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link" href="#deskripsi">Deskripsi</a>
                </li>
                {% if materi_data.status == "APPROVE" %}
                <li class="nav-item">
                    <a class="nav-link" href="#komentar">Komentar</a>
                </li>
299
300
301
                <li class="nav-item">
                    <a class="nav-link" href="#review">Review</a>
                </li>
302
303
304
305
306
307
308
                {% endif %}
            </ul>
        </nav>
        <div id="deskripsi" class="container-fluid description-wrapper bg-white shadow-sm rounded p-3">
            <h1>Deskripsi</h1>
            <div class="col col-8 description">
                <p>{{materi_data.descriptions}}</p>
309
310
311
312
313
314
315
316
317
318
                {% if materi_data.yt_video_id %}
                <div style="border-top:1px solid #d4d4d4;text-align:center">
                    <h3>Video</h3>
                    <iframe src="https://www.youtube.com/embed/{{ materi_data.yt_video_id }}"
                    allowfullscreen="allowfullscreen"
                    width="564" height="300">
                        invalid video url
                    </iframe>
                </div>
                {% endif %}
319
            </div>
320
321
322
        </div>
        {% if materi_data.status == "APPROVE" %}
        <div id="komentar" class="container-fluid comments-wrapper p-0">
323
            <h1>Komentar ({{ materi_data.comment_count }})</h1>
324
            {% if is_authenticated %}
325
326
327
328
329
330
331
332
333
            <div class="add-comments col col-8 bg-white shadow-sm rounded p-3 mb-3">
                <form method="POST">
                    {% csrf_token %}
                    <h1>Komentar</h1>
                    <div class="form-group">
                        <textarea placeholder="Beri komentar..." class="form-control" id="exampleFormControlTextarea1"
                            rows="3" name="comment" required></textarea>
                        <button type="submit"
                            class="btn btn-link btn-book shadow-sm p-2 mt-2 bg-white rounded">Kirim</button>
334
                    </div>
335
336
                </form>
            </div>
337
338
339
            {% else %}
                <h3>Login terlebih dahulu untuk berkomentar</h3>
            {% endif %}
340
341
342
343
344
345
346
347
348
349
350
351
            {% for comment in comment_data %}
            <div class="col col-8 comment shadow-sm p-3 mb-1 bg-white rounded">
                <div class="d-flex bd-highlight mb-3 align-items-center user">
                    {% if comment.user != Null %}
                    {% if not user.default_profile_picture %}
                    <img class="profile" src="https://i.ibb.co/9wgPzyZ/default-image.png" alt="profile-picture">
                    {% else %}
                    <img class="profile" src="{{ comment.user.profile_picture.url }}" alt="profile-picture">
                    {% endif %}
                    {% else %}
                    <span style="background-color: #{{comment.profile}}" class="profile p-1 bd-highligh"></span>
                    {% endif %}
352
353
354
355
356
357
358
359
360
                    <div class="d-flex flex-row justify-content-end">
                        <p class="p-1 bd-highligh m-0"><strong>{{comment.user.name}}</strong></p>
                        <p class="p-1 bd-highligh m-0"></p>
                        <p class="timestamp p-1 bd-highligh m-0 text-muted">
                            {{ comment.timestamp|naturaltime }}
                        </p>
                        <div>
                            <button id="thumb-like-comment-{{ comment.id }}" class="btn btn-link btn-book shadow-sm p-2 mr-2 bg-white rounded" onClick="postLikeComment({{ comment.id }})">
                                <div class="d-flex flex-row">
361
                                    {% if has_liked_comment.comment.id %}
362
363
364
365
366
367
368
369
370
                                    <i id="thumb-like-comment-icon-{{ comment.id }}" aria-hidden="true" class="fas fa-thumbs-up"></i>
                                    {% else %}
                                    <i id="thumb-like-comment-icon-{{ comment.id }}" aria-hidden="true" class="far fa-thumbs-up"></i>
                                    {% endif %}
                                    <div id="like-comment-{{ comment.id }}">{{ comment.like_count }}</div>
                                </div
                            </button>
                            <button id="thumb-dislike-comment-{{ comment.id }}" class="btn btn-link btn-book shadow-sm p-2 mr-2 bg-white rounded" onClick="postDislikeComment({{ comment.id }})">
                                <div class="d-flex flex-row">
371
                                    {% if has_disliked_comment.comment.id %}
372
373
374
375
376
377
378
379
380
                                    <i id="thumb-dislike-comment-icon-{{ comment.id }}" aria-hidden="true" class="fas fa-thumbs-down"></i>
                                    {% else %}
                                    <i id="thumb-dislike-comment-icon-{{ comment.id }}" aria-hidden="true" class="far fa-thumbs-down"></i>
                                    {% endif %}
                                    <div id="dislike-comment-{{ comment.id }}">{{ comment.dislike_count }}</div>
                                </div>
                            </button>
                        </div>
                    </div>
381
382
383
384
385
386
                    {% if user.is_admin %}
                    <a class="ml-auto p-1 bd-highlight close"
                        href="{% url 'delete-comment' materi_data.id comment.id %}">
                        <span aria-hidden="true">&times;</span>
                    </a>
                    {% endif %}
387
                </div>
388
389
390
                <p class="text">{{comment.comment}}</p>
            </div>
            {% endfor %}
391
        </div>
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
        
        <div id="review" class="container-fluid comments-wrapper p-0">
            <h1>Review ({{ materi_data.review_count }})</h1>
            {% if is_authenticated %}
            <div class="add-comments col col-8 bg-white shadow-sm rounded p-3 mb-3">
                <form method="POST">
                    {% csrf_token %}
                    <h1>Review</h1>
                    <div class="form-group">
                        <textarea placeholder="Beri Review" class="form-control" id="exampleFormControlTextarea1"
                            rows="10" name="review" required></textarea>
                        <button type="submit"
                            class="btn btn-link btn-book shadow-sm p-2 mt-2 bg-white rounded">Kirim</button>
                    </div>
                </form>
            </div>
            {% else %}
                <h3>Login terlebih dahulu untuk Membuat review</h3>
            {% endif %}
        </div>
        {% for review in review_data %}
            <div class="col col-8 comment shadow-sm p-3 mb-1 bg-white rounded">
                <div class="d-flex bd-highlight mb-3 align-items-center user">
                    {% if review.user != Null %}
                    {% if not user.default_profile_picture %}
                    <img class="profile" src="https://i.ibb.co/9wgPzyZ/default-image.png" alt="profile-picture">
                    {% else %}
                    <img class="profile" src="{{ review.user.profile_picture.url }}" alt="profile-picture">
                    {% endif %}
                    {% else %}
                    <span style="background-color: #{{review.profile}}" class="profile p-1 bd-highligh"></span>
                    {% endif %}
                    <div class="d-flex flex-row justify-content-end">
                        <p class="p-1 bd-highligh m-0"><strong>{{review.user.name}}</strong></p>
                        <p class="p-1 bd-highligh m-0"></p>
                        <p class="timestamp p-1 bd-highligh m-0 text-muted">
                            {{ review.timestamp|naturaltime }}
                        </p>
                    </div>
                </div>
                <div  class = 'review'>
                <p class="paragraph">{{review.review}}</p>
                </div>
            </div>
            {% endfor %}
        </div>
438
        {% endif %}
439
    </div>
440
441
442
443
</div>
<footer class="sticky-footer bg-white p-4">
    <div class="container my-auto">
        <div class="copyright text-center my-auto">
444
445
            <span>Copyright &copy; Diskominfo Kota Depok 2020</span>
        </div>
446
447
    </div>
</footer>
448

449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
<!-- Modal -->
<div class="modal fade" id="notLoggedInModal" tabindex="-1" role="dialog" aria-labelledby="notLoggedInModalLabel"
    aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="notLoggedInModalLabel">Belum Login</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                Login untuk memberikan rating
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Batal</button>
                <button type="button" class="btn btn-primary" onclick="window.location.href = '/login';">Login</button>
466
467
468
            </div>
        </div>
    </div>
469
</div>
470
{% endblock content %}
471
472
473
474
475
{% block extra_scripts %}
<script src="https://kit.fontawesome.com/bc2cedd6b2.js" crossorigin="anonymous"></script>
<script type="text/javascript">
    // using jQuery
    var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502

    let currentRating = {{ materi_rating_score }};
    fillRatingStar(currentRating)

    function changeButtonIntoRated() {
        $('#button-rating-star-icon').addClass('fas');
        $('#button-rating-star-icon').removeClass('far');
        $('#button-rating-text').text("Rating Anda")
    }

    if (currentRating > 0) {
        changeButtonIntoRated()
    }

    $("#star-dropdown").click(function (e) {
        e.stopPropagation();
    });

    function clearRatingStar() {
        for (let i = 1; i <= 5; i++) {
            $('#star-' + i).addClass('far');
            $('#star-' + i).removeClass('fas');
        }
    }

    function fillRatingStar(ratingScore) {
        for (let i = 1; i <= ratingScore; i++) {
503
504
505
            $('#star-' + i).addClass('fas');
            $('#star-' + i).removeClass('far');
        }
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
    }

    function makeHoverStar(starAmount) {
        function hoverStar() {
            clearRatingStar()
            fillRatingStar(starAmount)
        }

        return hoverStar
    }

    function makeUnHoverStar(starAmount) {
        function unHoverStar() {
            clearRatingStar()
            fillRatingStar(currentRating)
        }

        return unHoverStar
    }

    $('#star-1').hover(makeHoverStar(1), makeUnHoverStar(1));
    $('#star-2').hover(makeHoverStar(2), makeUnHoverStar(2));
    $('#star-3').hover(makeHoverStar(3), makeUnHoverStar(3));
    $('#star-4').hover(makeHoverStar(4), makeUnHoverStar(4));
    $('#star-5').hover(makeHoverStar(5), makeUnHoverStar(5));
531
532
533
534
535
536
537
538
</script>
<script>
    function csrfSafeMethod(method) {
        // these HTTP methods do not require CSRF protection
        return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
    }
</script>
<script>
539
    function postLike() {
540
541
542
543
        $.ajaxSetup({
            beforeSend: function (xhr, settings) {
                if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                    xhr.setRequestHeader("X-CSRFToken", csrftoken);
544
                }
545
            }
546
        });
547
548
549
550
551
552
553
554
555
556
        $.ajax({
            type: 'POST',
            url: "{% url 'PostLikeToggle' %}",
            data: {
                'materi_id': "{{ materi_data.id }}",
                'session_id': "{{ session_id }}"
            },
            success: LikePost,
            dataType: 'html'
        });
557
    }
558

559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
    function postLikeComment(comment_id) {
        $.ajaxSetup({
            beforeSend: function (xhr, settings) {
                if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                    xhr.setRequestHeader("X-CSRFToken", csrftoken);
                }
            }
        });
        $.ajax({
            type: 'POST',
            url: "{% url 'comment-like-toggle' %}",
            data: {
                'comment_id': comment_id,
                'session_id': "{{ session_id }}"
            },
            success: likeComment,
            dataType: 'html'
        });
    }

    function postDislikeComment(comment_id) {
        $.ajaxSetup({
            beforeSend: function (xhr, settings) {
                if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                    xhr.setRequestHeader("X-CSRFToken", csrftoken);
                }
            }
        });
        $.ajax({
            type: 'POST',
            url: "{% url 'comment-dislike-toggle' %}",
            data: {
                'comment_id': comment_id,
                'session_id': "{{ session_id }}"
            },
            success: dislikeComment,
            dataType: 'html'
        });
    }

599
600
601
602
603
    function postAddRating(rating_score) {
        $.ajaxSetup({
            beforeSend: function (xhr, settings) {
                if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                    xhr.setRequestHeader("X-CSRFToken", csrftoken);
604
                }
605
            }
606
        });
607

608
609
610
611
612
613
614
615
616
617
618
619
        $.ajax({
            type: 'POST',
            url: "{% url 'rate-materi' %}",
            data: {
                'materi_id': "{{ materi_data.id }}",
                'rating_score': rating_score
            },
            success: function (data) {
                const response = JSON.parse(data)
                currentRating = response.rating_score
                makeUnHoverStar(currentRating)()
                changeButtonIntoRated()
620

621
622
623
624
            },
            dataType: 'html'
        });
    }
625

Anthony Dewa Priyasembada's avatar
Anthony Dewa Priyasembada committed
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
    function postToggleReadLater() {
        $.ajaxSetup({
            beforeSend: function (xhr, settings) {
                if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                    xhr.setRequestHeader("X-CSRFToken", csrftoken);
                }
            }
        });

        $.ajax({
            type: 'POST',
            url: "{% url 'toggle-read-later' %}",
            data: {
                'materi_id': "{{ materi_data.id }}",
            },
            success: changeReadLaterButton,
            dataType: 'html'
        });
    }

    function changeReadLaterButton(data, jqXHR) {
        var data = $.parseJSON(data)
        if (data['read_later_checked']) {
            $('#readLaterButton').removeClass("bg-white text-primary").addClass("bg-primary text-white")
            $('#readLaterText').removeClass("fa-square").addClass("fa-check-square")
        } else {
            $('#readLaterButton').removeClass("bg-primary text-white").addClass("bg-white text-primary")
            $('#readLaterText').removeClass("fa-check-square").addClass("fa-square")
        }
    }

657
658
    function LikePost(data, jqXHR) {
        var data = $.parseJSON(data)
659
        var likeCount = parseInt($('.info-content')[6].textContent)
660
661
        if (data['liked']) {
            $('#thumbIcon').removeClass("fas fa-thumbs-up").addClass('far fa-thumbs-up')
662
663
            $('#thumb>span').text(" Sukai")
            $('.info-content')[6].textContent = likeCount - 1
664
665
        } else {
            $('#thumbIcon').removeClass("far fa-thumbs-up").addClass('fas fa-thumbs-up')
666
667
            $('#thumb>span').text(" Disukai")
            $('.info-content')[6].textContent = likeCount + 1
668
        }
669
    }
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695

    function likeComment(data, jqXHR) {
        var data = $.parseJSON(data)
        likeIcon = $('#thumb-like-comment-icon-' + data['comment_id'])
        likeValue = $('#like-comment-' + data['comment_id'])
        if (data['liked']) {
            likeIcon.removeClass("fas fa-thumbs-up").addClass('far fa-thumbs-up')
            likeValue.text(parseInt(likeValue.text())-1)
        } else {
            likeIcon.removeClass("far fa-thumbs-up").addClass('fas fa-thumbs-up')
            likeValue.text(parseInt(likeValue.text())+1)
        }
    }

    function dislikeComment(data, jqXHR) {
        var data = $.parseJSON(data)
        dislikeIcon = $('#thumb-dislike-comment-icon-' + data['comment_id'])
        dislikeValue = $('#dislike-comment-' + data['comment_id'])
        if (data['disliked']) {
            dislikeIcon.removeClass("fas fa-thumbs-down").addClass('far fa-thumbs-down')
            dislikeValue.text(parseInt(dislikeValue.text())-1)
        } else {
            dislikeIcon.removeClass("far fa-thumbs-down").addClass('fas fa-thumbs-down')
            dislikeValue.text(parseInt(dislikeValue.text())+1)
        }
    }
696
697
698
699
700
701
702
703
704
        
    function getCitation(text){
        var $temp = $("<input>");
        $("body").append($temp);
        $temp.val(text).select();
        document.execCommand("copy");
        $temp.remove();
        window.alert("Hasil sitasi: "+ text + "\n\nBerhasil disalin ke clipboard!");
    }
705
706

        
707
</script>
708
{% endblock extra_scripts %}