80f56fd4db9800cdf52c35173bb4c9492727358b
[living-lab-site.git] / application / views / video / comments_view.php
1 <h4><?php echo $this->lang->line('video_title_comment') ?>: </h4>
2
3 <?php echo form_open("video/comment/$video_id") ?>
4         <textarea name="comment" id="comment" rows="4" cols="56"><?php echo set_value('comment', '') ?></textarea>
5         
6         <div><input type="button" id="button-post" value="<?php echo $this->lang->line('video_submit_post_comment') ?>" />
7                 <span id="comment-chars-left">512</span> <?php echo $this->lang->line('ui_chars_left') ?>
8         </div>
9         <div><?php echo form_error('comment') ?></div>
10 </form>
11
12 <?php if ($comments_count == 0): ?>
13
14 <h4><?php echo $this->lang->line('video_title_no_comments') ?></h4>
15
16 <?php else: ?>
17
18   <?php if ($hottest_comments): ?>
19         <h4><?php echo $this->lang->line('video_title_hottest_comments'). ": " ?></h4>
20
21         <?php foreach ($hottest_comments as $hottest_comment): ?>
22                 <div class="comment-info"><strong class="comment-user"><a href="<?php echo site_url("user/profile/{$hottest_comment['username']}") ?>"><?php echo $hottest_comment['username'] ?></a></strong>
23                         (<span class="comment-time"><?php echo $hottest_comment['local_time'] ?></span>)
24                 </div>
25                 
26                 <div class="comment-content"><?php echo $hottest_comment['content'] ?></div>
27                 
28                 <div class="comment-popularity"><a class="link-vote-video-comment" data-action="like" data-commentid="<?php echo $hottest_comment['id'] ?>" href="#"><?php echo $this->lang->line('video_like') ?></a>
29                         &nbsp;<a class="link-vote-video-comment" data-action="dislike" data-commentid="<?php echo $hottest_comment['id'] ?>" href="#"><?php echo $this->lang->line('video_dislike') ?></a>
30                         &nbsp;&nbsp;&nbsp;&nbsp;<span id="<?php echo "video-comment-{$hottest_comment['id']}-likes" ?>"><?php echo $hottest_comment['likes'] ?></span> <?php
31                                 echo $this->lang->line('ui_likes') ?>,
32                         <span id="<?php echo "video-comment-{$hottest_comment['id']}-dislikes" ?>"><?php echo $hottest_comment['dislikes'] ?></span> <?php
33                                 echo $this->lang->line('ui_dislikes'); ?>
34                 </div>
35         <?php endforeach ?>
36   <?php endif ?>
37
38 <h4><?php echo $this->lang->line('video_title_all_comments'). " ($comments_count): " ?></h4>
39
40 <?php foreach ($comments as $comment): ?>
41         <div class="comment-info"><strong class="comment-user"><a href="<?php echo site_url("user/profile/{$comment['username']}") ?>"><?php echo $comment['username'] ?></a></strong>
42                 (<span class="comment-time"><?php echo $comment['local_time'] ?></span>)
43         </div>
44         
45         <div class="comment-content"><?php echo $comment['content'] ?></div>
46         
47         <div class="comment-popularity"><a class="link-vote-video-comment" data-action="like" data-commentid="<?php echo $comment['id'] ?>" href="#"><?php echo $this->lang->line('video_like') ?></a>
48                 &nbsp;<a class="link-vote-video-comment" data-action="dislike" data-commentid="<?php echo $comment['id'] ?>" href="#"><?php echo $this->lang->line('video_dislike') ?></a>
49                 &nbsp;&nbsp;&nbsp;&nbsp;<span id="<?php echo "video-comment-{$comment['id']}-likes" ?>"><?php echo $comment['likes'] ?></span> <?php
50                         echo $this->lang->line('ui_likes') ?>,
51                 <span id="<?php echo "video-comment-{$comment['id']}-dislikes" ?>"><?php echo $comment['dislikes'] ?></span> <?php
52                         echo $this->lang->line('ui_dislikes'); ?>
53         </div>
54 <?php endforeach ?>
55
56 <?php echo $comments_pagination ?>
57 <?php endif ?>
58
59 <script type="text/javascript">
60
61         function updateCommentCharsLeft($textarea) 
62         {
63                 $('#comment-chars-left').html('' + (512 - $textarea.val().length));
64         }
65         
66         $(function() {
67                 $('#button-post')
68                         .click(function() {
69                                 $.post('<?php echo site_url("video/ajax_comment/$video_id") ?>',
70                                         {comment: $('#comment').val()},
71                                         function(data) {
72                                                 $('#video-comments').html(data);
73                                         });
74                         });
75                 
76                 $('.pagination')
77                         .ajaxLinksMaker({
78                                 linkSelectors: [
79                                         '.pg-first',
80                                         '.pg-prev',
81                                         '.pg-next',
82                                         '.pg-last',
83                                         '.pg-num'
84                                 ],
85                                 target: '#video-comments'
86                         });
87                         
88                 $('.link-vote-video-comment')
89                         .click(function(event) {
90                                 var user_id = "<?php echo $user_id ?>";
91                                 var action, idOutput, commentId;
92                                 commentId = $(this).data('commentid');
93                                 if ($(this).data('action') == 'like')
94                                 {
95                                         var action = 'like';
96                                         var idOutput = '#video-comment-' + commentId + '-likes';
97                                 }
98                                 else
99                                 {
100                                         var action = 'dislike';
101                                         var idOutput = '#video-comment-' + commentId + '-dislikes';
102                                 }
103                                 //alert(action + " " + user_id);
104                                 
105                                 event.preventDefault();
106                                 
107                                 if (user_id.length != 0)
108                                 {
109                                         $.ajax({
110                                                 type: "GET",
111                                                 url: "<?php echo site_url("video/ajax_vote_comment") ?>/"
112                                                         + action
113                                                         + "/" + commentId,
114                                                 data: {t: ""+Math.random()},
115                                                 dataType: "text",
116                                                 success: function(text) {
117                                                         if (text)
118                                                                 $(idOutput).html(text);
119                                                         else
120                                                                 alert('<?php echo $this->lang->line('ui_msg_repeated_action_restriction') ?>');
121                                                 }
122                                         });
123                                 }
124                                 else
125                                         alert('<?php echo $this->lang->line('ui_msg_login_restriction') ?>');
126                         });
127                 
128                 $('#comment')
129                         .keydown(function(event) {
130                                 updateCommentCharsLeft($(this));
131                                 
132                                 if ($(this).val().length == 513)
133                                         $(this).val($(this).val().substring(0, 512));
134                         })
135                         .change(function() {
136                                 updateCommentCharsLeft($(this));
137                         });
138         });
139 </script>