now smart seen by works also reply added.

This commit is contained in:
Harry Bomrah 2015-09-04 02:37:56 +08:00
parent 2fe61680e3
commit 7fba2d782d
5 changed files with 117 additions and 19 deletions

View File

@ -0,0 +1,58 @@
/*
* Viewport - jQuery selectors for finding elements in viewport
*
* Copyright (c) 2008-2009 Mika Tuupola
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
* Project home:
* http://www.appelsiini.net/projects/viewport
*
*/
(function($) {
$.belowthefold = function(element, settings) {
var fold = $(window).height() + $(window).scrollTop();
return fold <= $(element).offset().top - settings.threshold;
};
$.abovethetop = function(element, settings) {
var top = $(window).scrollTop();
return top >= $(element).offset().top + $(element).height() - settings.threshold;
};
$.rightofscreen = function(element, settings) {
var fold = $(window).width() + $(window).scrollLeft();
return fold <= $(element).offset().left - settings.threshold;
};
$.leftofscreen = function(element, settings) {
var left = $(window).scrollLeft();
return left >= $(element).offset().left + $(element).width() - settings.threshold;
};
$.inviewport = function(element, settings) {
return !$.rightofscreen(element, settings) && !$.leftofscreen(element, settings) && !$.belowthefold(element, settings) && !$.abovethetop(element, settings);
};
$.extend($.expr[':'], {
"below-the-fold": function(a, i, m) {
return $.belowthefold(a, {threshold : 0});
},
"above-the-top": function(a, i, m) {
return $.abovethetop(a, {threshold : 0});
},
"left-of-screen": function(a, i, m) {
return $.leftofscreen(a, {threshold : 0});
},
"right-of-screen": function(a, i, m) {
return $.rightofscreen(a, {threshold : 0});
},
"in-viewport": function(a, i, m) {
return $.inviewport(a, {threshold : 0});
}
});
})(jQuery);

View File

@ -44,7 +44,7 @@ class Admin::TicketsController < OrbitAdminController
@members = [] @members = []
MemberProfile.all.each do |mp| MemberProfile.all.each do |mp|
user = mp.user rescue nil user = mp.user rescue nil
if !user.nil? && user.id.to_s != current_user.id.to_s && user.user_name != "rulingcom" if !user.nil? && user.id.to_s != current_user.id.to_s
avatar = (mp.avatar.thumb.url == "thumb_person.png" ? "/assets/thumb_person.png" : mp.avatar.thumb.url rescue "/assets/thumb_person.png") avatar = (mp.avatar.thumb.url == "thumb_person.png" ? "/assets/thumb_person.png" : mp.avatar.thumb.url rescue "/assets/thumb_person.png")
@members << { @members << {
"id" => user.id.to_s, "id" => user.id.to_s,

View File

@ -17,7 +17,7 @@
<div class="ticket-internal-response-wrap"> <div class="ticket-internal-response-wrap">
<div class="ticket-internal-response"> <div class="ticket-internal-response">
<input type="hidden" name="ticket_query_id" value="<%= query.id.to_s %>" /> <input type="hidden" name="ticket_query_id" value="<%= query.id.to_s %>" />
<input type="checkbox" name="internal_response" value="1"> <input type="checkbox" checked="checked" name="internal_response" value="1">
<span class="ticket-internal-response">Internal Response</span> <span class="ticket-internal-response">Internal Response</span>
</div> </div>
<div class="ticket-tag-member"> <div class="ticket-tag-member">

View File

@ -1,4 +1,4 @@
<div class="ticket-response-item" data-scroll-id="response_<%= response.id.to_s %>"> <div class="ticket-response-item" data-scroll-id="response_<%= response.id.to_s %>" data-response-by="<%= response.response_by %>">
<div class="ticket-response-meta"> <div class="ticket-response-meta">
<div class="ticket-response-author"> <div class="ticket-response-author">
<% user = User.find(response.response_by) rescue nil %> <% user = User.find(response.response_by) rescue nil %>
@ -14,15 +14,20 @@
<div class="ticket-response-created-date"> <div class="ticket-response-created-date">
<% dt = DateTime.parse(response.created_at.to_s) %> <%= dt.strftime("%d %B %Y - %H:%M") %> <% dt = DateTime.parse(response.created_at.to_s) %> <%= dt.strftime("%d %B %Y - %H:%M") %>
</div> </div>
<% if user.id.to_s == current_user.id.to_s %>
<div class="ticket-response-delete-wrap"> <div class="ticket-response-delete-wrap">
<% if user.id.to_s == current_user.id.to_s %>
<a class="ticket-response-delete" href="/admin/ticket/delete_response" data-response-id="<%= response.id.to_s %>"> <a class="ticket-response-delete" href="/admin/ticket/delete_response" data-response-id="<%= response.id.to_s %>">
<i class="ticket-response-delete-icon fa fa-trash"></i> <i class="ticket-response-delete-icon fa fa-trash"></i>
Delete Delete
</a> </a>
</div>
<% end %> <% end %>
<% if response.user_tags.include?(current_user.id.to_s) %>
<a href="" class="reply-response" data-response-id="<%= response.id.to_s %>">
<i class="fa fa-share"></i>
Reply
</a>
<% end %>
</div>
<div class="ticket-internal-comment-wrap"> <div class="ticket-internal-comment-wrap">
<div class="ticket-internal-wrap"> <div class="ticket-internal-wrap">
<% response.user_tags.each do |u| <% response.user_tags.each do |u|
@ -42,7 +47,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="ticket-response-content <%= response.internal_response ? "in-house" : "" %>"> <div class="ticket-response-content <%= response.internal_response ? "in-house" : "" %>" data-user-tags="<%= response.user_tags.to_s %>" data-response-id="<%= response.id.to_s %>">
<%= response.response.html_safe %> <%= response.response.html_safe %>
</div> </div>
</div> </div>

View File

@ -7,6 +7,7 @@
<%= javascript_include_tag "lib/jquery.form.js" %> <%= javascript_include_tag "lib/jquery.form.js" %>
<%= javascript_include_tag "validator" %> <%= javascript_include_tag "validator" %>
<%= javascript_include_tag "select2/select2.min" %> <%= javascript_include_tag "select2/select2.min" %>
<%= javascript_include_tag "jquery.viewport" %>
<% end %> <% end %>
<% if !@ticket .nil? %> <% if !@ticket .nil? %>
<% case @ticket.status <% case @ticket.status
@ -176,8 +177,11 @@
</div> </div>
<% end %> <% end %>
<script type="text/javascript"> <script type="text/javascript">
var locale = "<%= I18n.locale.to_s %>"; (function(){
var fv = new FormValidator($("#reopen-form")); var locale = "<%= I18n.locale.to_s %>",
fv = new FormValidator($("#reopen-form")),
user_id = "<%= current_user.id.to_s %>";
$("#reopen-form-submit").on("click",function(){ $("#reopen-form-submit").on("click",function(){
for (instance in CKEDITOR.instances) { for (instance in CKEDITOR.instances) {
CKEDITOR.instances[instance].updateElement(); CKEDITOR.instances[instance].updateElement();
@ -245,7 +249,7 @@ $(document).ready(function(){
); );
return $state; return $state;
}, },
placeholder: "Add Members" placeholder: "Tag Members"
}); });
}) })
@ -264,12 +268,11 @@ $(document).ready(function(){
function switchTooltip() { function switchTooltip() {
var $switch = $('.onoffswitch'); var $switch = $('.onoffswitch'),
var $input = $switch.children('input'); $input = $switch.children('input'),
var $tooltip = $switch.find('.ticket-tooltip-wrap'); $tooltip = $switch.find('.ticket-tooltip-wrap');
var activeCls = 'active';
if ($input.hasClass(activeCls)) { if ($input.hasClass("active")) {
$tooltip.text('This ticket is marked urgent, click to unmark'); $tooltip.text('This ticket is marked urgent, click to unmark');
} else { } else {
$tooltip.text('Click to mark this ticket urgent'); $tooltip.text('Click to mark this ticket urgent');
@ -330,4 +333,36 @@ $(document).ready(function(){
return false; return false;
}) })
$("body").on("click",".reply-response",function(){
var el = $(this),
response_id = el.data("response-id");
$(".member_tags").select2("val",[$("div[data-scroll-id=response_" + response_id + "]").data("response-by")]);
$("html, body").animate({ scrollTop: ($("#form_container").offset().top - 50) }, "slow");
return false;
})
var timer = null;
$(document).on("scroll",function(){
clearTimeout(timer);
timer = setTimeout(function(){
var responses_seen = $("div[data-user-tags*=" + user_id + "]:in-viewport");
$.each(responses_seen,function(){
var el = $(this),
avatar = $("div[data-scroll-id=response_" + el.data("response-id") + "]").find("img[data-avatar-id="+ user_id +"]");
if(!avatar.hasClass("read")){
$.ajax({
url : "/admin/comments/read",
dataType : "json",
type : "post",
data : {"response_id" : el.data("response-id")}
}).done(function(data){
if(data.success){
avatar.addClass("read");
}
})
}
})
},1000);
})
})();
</script> </script>