OpenID login and comment improoved
[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                 
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                                 $('#comment').val('');
75                         });
76                 
77                 $('.pagination')
78                         .ajaxLinksMaker({
79                                 linkSelectors: [
80                                         '.pg-first',
81                                         '.pg-prev',
82                                         '.pg-next',
83                                         '.pg-last',
84                                         '.pg-num'
85                                 ],
86                                 target: '#video-comments'
87                         });
88                         
89                 $('.link-vote-video-comment')
90                         .click(function(event) {
91                                 var user_id = "<?php echo $user_id ?>";
92                                 var action, idOutput, commentId;
93                                 commentId = $(this).data('commentid');
94                                 if ($(this).data('action') == 'like')
95                                 {
96                                         var action = 'like';
97                                         var idOutput = '#video-comment-' + commentId + '-likes';
98                                 }
99                                 else
100                                 {
101                                         var action = 'dislike';
102                                         var idOutput = '#video-comment-' + commentId + '-dislikes';
103                                 }
104                                 //alert(action + " " + user_id);
105                                 
106                                 event.preventDefault();
107                                 
108                                 if (user_id.length != 0)
109                                 {
110                                         $.ajax({
111                                                 type: "GET",
112                                                 url: "<?php echo site_url("video/ajax_vote_comment") ?>/"
113                                                         + action
114                                                         + "/" + commentId,
115                                                 data: {t: ""+Math.random()},
116                                                 dataType: "text",
117                                                 success: function(text) {
118                                                         if (text)
119                                                                 $(idOutput).html(text);
120                                                         else
121                                                                 alert('<?php echo $this->lang->line('ui_msg_repeated_action_restriction') ?>');
122                                                 }
123                                         });
124                                 }
125                                 else
126                                         alert('<?php echo $this->lang->line('ui_msg_login_restriction') ?>');
127                         });
128                 
129                 $('#comment')
130                         .bind('keyup paste drop change', function(event) {
131                                 $textarea = $(this);
132                                 
133                                 if ($textarea.val().length >= 513)
134                                         $textarea.val($textarea.val().substring(0, 512));
135
136                                 $('#comment-chars-left').html('' + (512 - $textarea.val().length));
137                                 console.log(event.type);
138                         });
139         });
140 </script>