attachments and media comments for new conversations
Change-Id: Ie3c9a16a78747a58504d5279a6a996c2a150d567 Reviewed-on: https://gerrit.instructure.com/5010 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com>
This commit is contained in:
parent
c16ef14d2e
commit
839755146e
|
@ -525,12 +525,15 @@ I18n.scoped 'conversations', (I18n) ->
|
|||
$form.attr action: $selected_conversation.find('a.details_link').attr('add_url')
|
||||
|
||||
reset_message_form()
|
||||
inbox_resize()
|
||||
$form.show().find(':input:visible:first').focus()
|
||||
|
||||
reset_message_form = ->
|
||||
$form.find('.audience').html $selected_conversation.find('.audience').html() if $selected_conversation?
|
||||
$form.find('input, textarea').val('').change()
|
||||
$form.find('input[name!=authenticity_token], textarea').val('').change()
|
||||
$form.find(".attachment:visible").remove()
|
||||
$form.find(".media_comment").hide()
|
||||
$form.find("#action_media_comment").show()
|
||||
inbox_resize()
|
||||
|
||||
parse_query_string = (query_string = window.location.search.substr(1)) ->
|
||||
hash = {}
|
||||
|
@ -632,8 +635,36 @@ I18n.scoped 'conversations', (I18n) ->
|
|||
for submessage in data.forwarded_messages
|
||||
$ul.append build_message(submessage)
|
||||
$message.append $ul
|
||||
|
||||
$ul = $message.find('ul.message_attachments').detach()
|
||||
$media_object_blank = $ul.find('.media_object_blank').detach()
|
||||
$attachment_blank = $ul.find('.attachment_blank').detach()
|
||||
if data.media_objects?.length or data.attachments?.length
|
||||
$message.append $ul
|
||||
if data.media_objects?
|
||||
for media_object in data.media_objects
|
||||
$ul.append build_media_object($media_object_blank, media_object)
|
||||
if data.attachments?
|
||||
for attachment in data.attachments
|
||||
$ul.append build_attachment($attachment_blank, attachment)
|
||||
|
||||
$message
|
||||
|
||||
build_media_object = (blank, data) ->
|
||||
$media_object = blank.clone(true).attr('id', 'media_object_' + data.id)
|
||||
$media_object.data('id', data.id)
|
||||
$media_object.find('span.title').html $.h(data.title)
|
||||
$media_object.find('span.media_comment_id').html $.h(data.media_id)
|
||||
$media_object
|
||||
|
||||
build_attachment = (blank, data) ->
|
||||
$attachment = blank.clone(true).attr('id', 'attachment_' + data.id)
|
||||
$attachment.data('id', data.id)
|
||||
$attachment.find('span.title').html $.h(data.display_name)
|
||||
$link = $attachment.find('a')
|
||||
$link.attr('href', $.replaceTags($.replaceTags($link.attr('href'), 'id', data.id), 'uuid', data.uuid))
|
||||
$attachment
|
||||
|
||||
inbox_action_url_for = ($action, $conversation) ->
|
||||
$.replaceTags $action.attr('href'), 'id', $conversation.data('id')
|
||||
|
||||
|
@ -813,6 +844,8 @@ I18n.scoped 'conversations', (I18n) ->
|
|||
e.stopImmediatePropagation() unless valid
|
||||
valid
|
||||
$form.formSubmit
|
||||
fileUpload: ->
|
||||
return $(this).find(".file_input:visible").length > 0
|
||||
beforeSubmit: ->
|
||||
$(this).loadingImage()
|
||||
success: (data) ->
|
||||
|
@ -850,12 +883,17 @@ I18n.scoped 'conversations', (I18n) ->
|
|||
|
||||
|
||||
$message_list.click (e) ->
|
||||
$message = $(e.target).closest('#messages > ul > li')
|
||||
unless $message.hasClass('generated')
|
||||
$selected_conversation?.addClass('inactive')
|
||||
$message.toggleClass('selected')
|
||||
$message.find('> :checkbox').attr('checked', $message.hasClass('selected'))
|
||||
toggle_message_actions()
|
||||
if $(e.target).closest('a.instructure_inline_media_comment').length
|
||||
# a.instructure_inline_media_comment clicks have to propagate to the
|
||||
# top due to "live" handling; if it's one of those, it's not really
|
||||
# intended for us, just let it go
|
||||
else
|
||||
$message = $(e.target).closest('#messages > ul > li')
|
||||
unless $message.hasClass('generated')
|
||||
$selected_conversation?.addClass('inactive')
|
||||
$message.toggleClass('selected')
|
||||
$message.find('> :checkbox').attr('checked', $message.hasClass('selected'))
|
||||
toggle_message_actions()
|
||||
|
||||
$('.menus > li > a').click (e) ->
|
||||
e.preventDefault()
|
||||
|
@ -948,7 +986,7 @@ I18n.scoped 'conversations', (I18n) ->
|
|||
token_input = $('#add_recipients').data('token_input')
|
||||
token_input.base_exclude = ($(node).data('id') for node in $selected_conversation.find('.participant'))
|
||||
token_input.resize()
|
||||
$(this).find("input").val('').change().last().focus()
|
||||
$(this).find("input[name!=authenticity_token]").val('').change().last().focus()
|
||||
close: ->
|
||||
$('#add_recipients').data('token_input').input.blur()
|
||||
|
||||
|
@ -1002,7 +1040,7 @@ I18n.scoped 'conversations', (I18n) ->
|
|||
open: ->
|
||||
token_input = $('#forward_recipients').data('token_input')
|
||||
token_input.resize()
|
||||
$(this).find("input").val('').change().last().focus()
|
||||
$(this).find("input[name!=authenticity_token]").val('').change().last().focus()
|
||||
$preview = $(this).find('ul.messages').first()
|
||||
$preview.html('')
|
||||
$preview.html($message_list.find('> li.selected').clone(true).removeAttr('id').removeClass('self'))
|
||||
|
@ -1052,6 +1090,39 @@ I18n.scoped 'conversations', (I18n) ->
|
|||
e.preventDefault()
|
||||
return false
|
||||
|
||||
nextAttachmentIndex = 0
|
||||
$('#action_add_attachment').click (e) ->
|
||||
e.preventDefault()
|
||||
$attachment = $("#attachment_blank").clone(true)
|
||||
$attachment.attr('id', null)
|
||||
$attachment.find("input[type='file']").attr('name', 'attachments[' + (nextAttachmentIndex++) + ']')
|
||||
$('#attachment_list').append($attachment)
|
||||
$attachment.slideDown "fast", ->
|
||||
inbox_resize()
|
||||
return false
|
||||
|
||||
$("#attachment_blank a.remove_link").click (e) ->
|
||||
e.preventDefault()
|
||||
$(this).parents(".attachment").slideUp "fast", ->
|
||||
inbox_resize()
|
||||
$(this).remove()
|
||||
return false
|
||||
|
||||
$('#action_media_comment').click (e) ->
|
||||
e.preventDefault()
|
||||
$("#create_message_form .media_comment").mediaComment 'create', 'audio', (id, type) ->
|
||||
$("#media_comment_id").val(id)
|
||||
$("#media_comment_type").val(type)
|
||||
$("#create_message_form .media_comment").show()
|
||||
$("#action_media_comment").hide()
|
||||
|
||||
$('#create_message_form .media_comment a.remove_link').click (e) ->
|
||||
e.preventDefault()
|
||||
$("#media_comment_id").val('')
|
||||
$("#media_comment_type").val('')
|
||||
$("#create_message_form .media_comment").hide()
|
||||
$("#action_media_comment").show()
|
||||
|
||||
for conversation in MessageInbox.initial_conversations
|
||||
add_conversation conversation, true
|
||||
$('#no_messages').showIf !$conversation_list.find('li').length
|
||||
|
|
|
@ -63,8 +63,7 @@ class ConversationsController < ApplicationController
|
|||
def create
|
||||
if @recipient_ids.present? && params[:body].present?
|
||||
@conversation = @current_user.initiate_conversation(@recipient_ids)
|
||||
message = @conversation.add_message(params[:body], params[:forwarded_message_ids])
|
||||
message.generate_user_note if params[:user_note]
|
||||
message = create_message_on_conversation
|
||||
render :json => {:participants => jsonify_users(@conversation.participants(true, true)),
|
||||
:conversation => jsonify_conversation(@conversation.reload),
|
||||
:message => message}
|
||||
|
@ -77,7 +76,7 @@ class ConversationsController < ApplicationController
|
|||
if @recipient_ids.present? && params[:body].present?
|
||||
@recipient_ids.each do |recipient_id|
|
||||
conversation = @current_user.initiate_conversation([recipient_id], true)
|
||||
message = conversation.add_message(params[:body])
|
||||
message = create_message_on_conversation(conversation)
|
||||
end
|
||||
render :json => {}, :status => :ok
|
||||
else
|
||||
|
@ -131,8 +130,7 @@ class ConversationsController < ApplicationController
|
|||
|
||||
def add_message
|
||||
if params[:body].present?
|
||||
message = @conversation.add_message(params[:body])
|
||||
message.generate_user_note if params[:user_note]
|
||||
message = create_message_on_conversation
|
||||
render :json => {:conversation => jsonify_conversation(@conversation.reload), :message => message}
|
||||
else
|
||||
render :json => {}, :status => :bad_request
|
||||
|
@ -231,6 +229,25 @@ class ConversationsController < ApplicationController
|
|||
@conversation = @current_user.conversations.find_by_conversation_id(params[:id] || params[:conversation_id] || 0)
|
||||
end
|
||||
|
||||
def create_message_on_conversation(conversation=@conversation)
|
||||
message = conversation.add_message(params[:body], params[:forwarded_message_ids]) do |m|
|
||||
if params[:attachments]
|
||||
params[:attachments].sort_by{ |k,v| k.to_i }.each do |k,v|
|
||||
m.attachments.create(:uploaded_data => v) if v.present?
|
||||
end
|
||||
end
|
||||
|
||||
media_id = params[:media_comment_id]
|
||||
media_type = params[:media_comment_type]
|
||||
if media_id.present? && media_type.present?
|
||||
media_object = MediaObject.find_by_media_id_and_media_type(media_id, media_type)
|
||||
m.media_objects << media_object if media_object
|
||||
end
|
||||
end
|
||||
message.generate_user_note if params[:user_note]
|
||||
message
|
||||
end
|
||||
|
||||
def jsonify_conversation(conversation)
|
||||
hash = {:audience => formatted_audience(conversation, 3)}
|
||||
hash[:avatar_url] = avatar_url_for(conversation)
|
||||
|
|
|
@ -44,11 +44,15 @@ class Attachment < ActiveRecord::Base
|
|||
before_validation :assert_attachment
|
||||
before_destroy :delete_scribd_doc
|
||||
acts_as_list :scope => :folder
|
||||
after_save :touch_context
|
||||
after_save :touch_context_if_appropriate
|
||||
after_create :build_media_object
|
||||
|
||||
attr_accessor :podcast_associated_asset
|
||||
|
||||
def touch_context_if_appropriate
|
||||
touch_context unless context_type == 'ConversationMessage'
|
||||
end
|
||||
|
||||
# this is a magic method that gets run by attachment-fu after it is done sending to s3,
|
||||
# that is the moment that we also want to submit it to scribd.
|
||||
# note, that the time it takes to send to s3 is the bad guy.
|
||||
|
|
|
@ -120,8 +120,7 @@ class Conversation < ActiveRecord::Base
|
|||
end
|
||||
message.save!
|
||||
|
||||
# TODO: attachments and media comments
|
||||
|
||||
yield message if block_given?
|
||||
|
||||
connection.execute(<<-SQL)
|
||||
INSERT INTO conversation_message_participants(conversation_message_id, conversation_participant_id)
|
||||
|
@ -161,8 +160,18 @@ class Conversation < ActiveRecord::Base
|
|||
["user_id = ?", current_user.id]
|
||||
)
|
||||
|
||||
conversation_participants.update_all({:has_attachments => true}, "NOT has_attachments") if message.attachments.present?
|
||||
conversation_participants.update_all({:has_media_objects => true}, "NOT has_media_objects") if message.media_objects.present?
|
||||
updated = false
|
||||
if message.attachments.present?
|
||||
self.has_attachments = true
|
||||
conversation_participants.update_all({:has_attachments => true}, "NOT has_attachments")
|
||||
updated = true
|
||||
end
|
||||
if message.media_objects.present?
|
||||
self.has_media_objects = true
|
||||
conversation_participants.update_all({:has_media_objects => true}, "NOT has_media_objects")
|
||||
updated = true
|
||||
end
|
||||
self.save if updated
|
||||
end
|
||||
|
||||
message
|
||||
|
|
|
@ -22,7 +22,7 @@ class ConversationMessage < ActiveRecord::Base
|
|||
belongs_to :conversation
|
||||
belongs_to :author, :class_name => 'User'
|
||||
has_many :conversation_message_participants
|
||||
has_many :attachments, :as => :context
|
||||
has_many :attachments, :as => :context, :order => 'created_at, id'
|
||||
has_many :media_objects, :as => :context
|
||||
delegate :participants, :to => :conversation
|
||||
delegate :subscribed_participants, :to => :conversation
|
||||
|
@ -113,7 +113,9 @@ class ConversationMessage < ActiveRecord::Base
|
|||
|
||||
def as_json(options = {})
|
||||
super(options)['conversation_message'].merge({
|
||||
'forwarded_messages' => forwarded_messages
|
||||
'forwarded_messages' => forwarded_messages,
|
||||
'attachments' => attachments.map{ |a| a.as_json['attachment'].merge({'uuid' => a.uuid}) },
|
||||
'media_objects' => media_objects.map{ |o| o.as_json['media_object'] }
|
||||
})
|
||||
end
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ class ConversationParticipant < ActiveRecord::Base
|
|||
EXISTS (
|
||||
SELECT 1
|
||||
FROM conversation_message_participants
|
||||
WHERE conversation_participant_id = \#{user_id}
|
||||
WHERE conversation_participant_id = \#{id}
|
||||
AND conversation_message_id = conversation_messages.id
|
||||
)
|
||||
SQL
|
||||
|
@ -127,8 +127,8 @@ class ConversationParticipant < ActiveRecord::Base
|
|||
conversation.add_participants(user, user_ids)
|
||||
end
|
||||
|
||||
def add_message(body, forwarded_message_ids = [])
|
||||
conversation.add_message(user, body, false, forwarded_message_ids)
|
||||
def add_message(body, forwarded_message_ids = [], &blk)
|
||||
conversation.add_message(user, body, false, forwarded_message_ids, &blk)
|
||||
end
|
||||
|
||||
def remove_messages(*to_delete)
|
||||
|
|
|
@ -23,7 +23,6 @@ class MediaObject < ActiveRecord::Base
|
|||
belongs_to :attachment
|
||||
belongs_to :root_account, :class_name => 'Account'
|
||||
validates_presence_of :media_id, :context_id, :context_type
|
||||
before_save :infer_defaults
|
||||
after_create :retrieve_details_later
|
||||
after_save :update_title_on_kaltura_later
|
||||
serialize :data
|
||||
|
@ -32,11 +31,6 @@ class MediaObject < ActiveRecord::Base
|
|||
|
||||
attr_accessor :podcast_associated_asset
|
||||
|
||||
def infer_defaults
|
||||
self.user_type = "admin" if self.user && self.cached_context_grants_right?(self.user, nil, :manage_content)
|
||||
self.user_type ||= "student"
|
||||
end
|
||||
|
||||
def user_entered_title=(val)
|
||||
@push_user_title = true
|
||||
write_attribute(:user_entered_title, val)
|
||||
|
|
|
@ -291,6 +291,21 @@ ul.messages
|
|||
.audience
|
||||
color: #636363
|
||||
|
||||
ul.messages
|
||||
li
|
||||
.message_attachments
|
||||
padding-top: 0.5em
|
||||
margin-left: 0
|
||||
padding-left: 1em
|
||||
border-top: 1px solid #cccccc
|
||||
list-style: none
|
||||
li.self
|
||||
.message_attachments
|
||||
border-top-color: #bcbcbc
|
||||
li.selected
|
||||
.message_attachments
|
||||
border-top-color: #b7c2cc
|
||||
|
||||
ul.messages li.other:hover
|
||||
.actions
|
||||
margin-left: 1em
|
||||
|
@ -302,6 +317,7 @@ ul.messages li.other:hover
|
|||
padding-left: 20px
|
||||
.send_private_message:hover
|
||||
background-position: 0 -18px
|
||||
|
||||
ul.messages, ul.messages.private, ul.messages.private li:hover
|
||||
.actions
|
||||
display: none
|
||||
|
@ -766,6 +782,8 @@ li.purple .label_icon, .purple.label_icon
|
|||
font-size: 1.1em
|
||||
#action_add_recipients:hover
|
||||
background-position: 0 -18px
|
||||
#action_add_attachment, #action_media_comment
|
||||
padding-right: 1em
|
||||
ul.conversations
|
||||
overflow: visible
|
||||
border: 0
|
||||
|
@ -774,6 +792,22 @@ li.purple .label_icon, .purple.label_icon
|
|||
> li
|
||||
padding: 0
|
||||
border: 0
|
||||
#attachment_list
|
||||
overflow: visible
|
||||
border: 0
|
||||
padding: 0
|
||||
margin: 0
|
||||
list-style-type: none
|
||||
input
|
||||
width: 90%
|
||||
> li
|
||||
padding: 0 0 5px 0
|
||||
border: 0
|
||||
.media_comment
|
||||
overflow: visible
|
||||
border: 0
|
||||
padding: 0 0 5px 0
|
||||
margin: 0
|
||||
+box-shadow( rgba(0,0,0,0.25), 0, 0, 6px, 3px)
|
||||
#create_message_form.new
|
||||
.audience
|
||||
|
|
|
@ -62,11 +62,38 @@
|
|||
<table>
|
||||
<tr id="recipient_info"><th><%= label_tag :recipients, :to, :en => "To", :before => true %></th><td><%= text_field_tag :recipients, nil, :finder_url => conversations_find_recipients_url, :class => "recipients" %></td></tr>
|
||||
<tr><th><%= label_tag :body, :message, :en => "Message", :before => true %></th><td><%= text_area_tag :body %></td></tr>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<td>
|
||||
<% if feature_enabled?(:kaltura) %>
|
||||
<div class="media_comment" style="display: none;" title="<%= t('titles.audio_comment', "Recorded audio comment") %>">
|
||||
<%= image_tag "messages/audio-gray.png" %>
|
||||
<%= t('audio_comment', %{Audio Comment}) %>
|
||||
<a href="#" class="remove_link" style="float: right;" title="<%= t('titles.remove_audio_comment', "Remove audio comment") %>"><%= image_tag "delete_circle.png" %></a>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
<input type="hidden" name="media_comment_id" id="media_comment_id">
|
||||
<input type="hidden" name="media_comment_type" id="media_comment_type">
|
||||
<% end %>
|
||||
<ul id="attachment_list">
|
||||
<li id="attachment_blank" class="attachment" style="display: none;" title="<%= t('titles.attachment', "File to attach") %>">
|
||||
<%= image_tag "messages/attach-gray.png" %>
|
||||
<input type="file" class="file_input"/>
|
||||
<a href="#" class="remove_link" style="float: right;" title="<%= t('titles.remove_attachment', "Remove attachment") %>"><%= image_tag "delete_circle.png" %></a>
|
||||
<div class="clear"></div>
|
||||
</li>
|
||||
</ul>
|
||||
<a id="action_add_attachment" href="#" title="<%= t('titles.add_attachment', "Add an attachment") %>"><%= image_tag "messages/attach-blue.png" %> <%= t('links.add_attachment', %{Attach}) %></a>
|
||||
<% if feature_enabled?(:kaltura) %>
|
||||
<a id="action_media_comment" href="#" title="<%= t('titles.record_audio_comment', "Record an audio comment") %>"><%= image_tag "messages/audio-blue.png" %> <%= t('links.audio_comment', %{Record}) %></a>
|
||||
<% end %>
|
||||
<div style="float: right">
|
||||
<input type="hidden" name="from_conversation_id" id="from_conversation_id">
|
||||
<button type="submit" class="button"><%= t('buttons.send_message', 'Send') %></button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div style="text-align:right">
|
||||
<input type="hidden" name="from_conversation_id" id="from_conversation_id">
|
||||
<button type="submit" class="button"><%= t('buttons.send_message', 'Send') %></button>
|
||||
</div>
|
||||
<% end %>
|
||||
<ul class="messages">
|
||||
</ul>
|
||||
|
@ -80,7 +107,7 @@
|
|||
<%= link_to t('inbox_actions.mark_as_read', "Mark as Read"), conversation_mark_as_read_url('{{ id }}'), :title => t('inbox_actions.mark_as_read', "Mark as Read"), :class => :action_mark_as_read %>
|
||||
<span class="date"></span>
|
||||
<img class="attachments" src="/images/messages/attach-gray.png" title="<%= t('has_attachments', 'This conversation has one or more attachments') %>">
|
||||
<img class="media_objects" src="/images/messages/media.png" title="<%= t('has_audio', 'This conversation has one or more audio comments') %>">
|
||||
<img class="media_objects" src="/images/messages/audio-gray.png" title="<%= t('has_audio', 'This conversation has one or more audio comments') %>">
|
||||
<span class="audience"></span>
|
||||
<span class="count"></span>
|
||||
<p></p>
|
||||
|
@ -93,6 +120,21 @@
|
|||
<span class="actions"><a href="#/conversations?user_id={{ user_id }}&user_name={{ user_name }}&from_conversation_id={{ from_conversation_id }}" class="send_private_message"><%= t :send_private_message, "New message..." %></a></span>
|
||||
<p></p>
|
||||
<input type="checkbox" />
|
||||
<ul class='message_attachments'>
|
||||
<li class='media_object_blank'>
|
||||
<a href="#" class="instructure_inline_media_comment audio_comment no-underline" title="<%= t('titles.play_audio_comment', "Play audio comment") %>">
|
||||
<%= image_tag "messages/audio-gray.png" %>
|
||||
<span class="media_comment_id" style="display: none;"></span>
|
||||
<span class='title'></span>
|
||||
</a>
|
||||
</li>
|
||||
<li class='attachment_blank'>
|
||||
<a href="<%= file_download_path('{{ id }}', :verifier => '{{ uuid }}') %>" title="<%= t('titles.download_attachment', "Download attachment") %>">
|
||||
<%= image_tag "messages/attach-gray.png" %>
|
||||
<span class='title'></span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<div id="conversation_actions">
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
class ConversationsHasAttachmentsNotNull < ActiveRecord::Migration
|
||||
def self.up
|
||||
[:conversations, :conversation_participants].each do |table|
|
||||
[:has_attachments, :has_media_objects].each do |column|
|
||||
change_column_null table, column, false, false
|
||||
change_column_default table, column, false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
[:conversations, :conversation_participants].each do |table|
|
||||
[:has_attachments, :has_media_objects].each do |column|
|
||||
change_column_null table, column, true
|
||||
change_column_default table, column, nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Binary file not shown.
After Width: | Height: | Size: 740 B |
Binary file not shown.
After Width: | Height: | Size: 744 B |
Binary file not shown.
After Width: | Height: | Size: 365 B |
Binary file not shown.
After Width: | Height: | Size: 314 B |
|
@ -677,7 +677,7 @@
|
|||
}
|
||||
};
|
||||
I18n.scoped('conversations', function(I18n) {
|
||||
var add_conversation, build_message, close_menus, html_name_for_user, inbox_action, inbox_action_url_for, inbox_resize, is_selected, open_conversation_menu, open_menu, parse_query_string, remove_conversation, reposition_conversation, reset_message_form, select_conversation, set_conversation_state, set_last_label, show_message_form, toggle_message_actions, update_conversation;
|
||||
var add_conversation, build_attachment, build_media_object, build_message, close_menus, html_name_for_user, inbox_action, inbox_action_url_for, inbox_resize, is_selected, open_conversation_menu, open_menu, parse_query_string, remove_conversation, reposition_conversation, reset_message_form, select_conversation, set_conversation_state, set_last_label, show_message_form, toggle_message_actions, update_conversation;
|
||||
show_message_form = function() {
|
||||
var newMessage;
|
||||
newMessage = !($selected_conversation != null);
|
||||
|
@ -699,14 +699,17 @@
|
|||
});
|
||||
}
|
||||
reset_message_form();
|
||||
inbox_resize();
|
||||
return $form.show().find(':input:visible:first').focus();
|
||||
};
|
||||
reset_message_form = function() {
|
||||
if ($selected_conversation != null) {
|
||||
$form.find('.audience').html($selected_conversation.find('.audience').html());
|
||||
}
|
||||
return $form.find('input, textarea').val('').change();
|
||||
$form.find('input[name!=authenticity_token], textarea').val('').change();
|
||||
$form.find(".attachment:visible").remove();
|
||||
$form.find(".media_comment").hide();
|
||||
$form.find("#action_media_comment").show();
|
||||
return inbox_resize();
|
||||
};
|
||||
parse_query_string = function(query_string) {
|
||||
var hash, key, parts, value, _i, _len, _ref, _ref2;
|
||||
|
@ -833,7 +836,7 @@
|
|||
return $.htmlEscape(user.name) + (shared_contexts.length ? " <em>" + $.htmlEscape(shared_contexts) + "</em>" : '');
|
||||
};
|
||||
build_message = function(data) {
|
||||
var $message, $pm_action, $ul, avatar, pm_url, submessage, user, user_name, _i, _len, _ref, _ref2, _ref3, _ref4;
|
||||
var $attachment_blank, $media_object_blank, $message, $pm_action, $ul, attachment, avatar, media_object, pm_url, submessage, user, user_name, _i, _j, _k, _len, _len2, _len3, _ref, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
|
||||
$message = $("#message_blank").clone(true).attr('id', 'message_' + data.id);
|
||||
$message.data('id', data.id);
|
||||
$message.addClass(data.generated ? 'generated' : data.author_id === MessageInbox.user_id ? 'self' : 'other');
|
||||
|
@ -868,8 +871,45 @@
|
|||
}
|
||||
$message.append($ul);
|
||||
}
|
||||
$ul = $message.find('ul.message_attachments').detach();
|
||||
$media_object_blank = $ul.find('.media_object_blank').detach();
|
||||
$attachment_blank = $ul.find('.attachment_blank').detach();
|
||||
if (((_ref5 = data.media_objects) != null ? _ref5.length : void 0) || ((_ref6 = data.attachments) != null ? _ref6.length : void 0)) {
|
||||
$message.append($ul);
|
||||
if (data.media_objects != null) {
|
||||
_ref7 = data.media_objects;
|
||||
for (_j = 0, _len2 = _ref7.length; _j < _len2; _j++) {
|
||||
media_object = _ref7[_j];
|
||||
$ul.append(build_media_object($media_object_blank, media_object));
|
||||
}
|
||||
}
|
||||
if (data.attachments != null) {
|
||||
_ref8 = data.attachments;
|
||||
for (_k = 0, _len3 = _ref8.length; _k < _len3; _k++) {
|
||||
attachment = _ref8[_k];
|
||||
$ul.append(build_attachment($attachment_blank, attachment));
|
||||
}
|
||||
}
|
||||
}
|
||||
return $message;
|
||||
};
|
||||
build_media_object = function(blank, data) {
|
||||
var $media_object;
|
||||
$media_object = blank.clone(true).attr('id', 'media_object_' + data.id);
|
||||
$media_object.data('id', data.id);
|
||||
$media_object.find('span.title').html($.h(data.title));
|
||||
$media_object.find('span.media_comment_id').html($.h(data.media_id));
|
||||
return $media_object;
|
||||
};
|
||||
build_attachment = function(blank, data) {
|
||||
var $attachment, $link;
|
||||
$attachment = blank.clone(true).attr('id', 'attachment_' + data.id);
|
||||
$attachment.data('id', data.id);
|
||||
$attachment.find('span.title').html($.h(data.display_name));
|
||||
$link = $attachment.find('a');
|
||||
$link.attr('href', $.replaceTags($.replaceTags($link.attr('href'), 'id', data.id), 'uuid', data.uuid));
|
||||
return $attachment;
|
||||
};
|
||||
inbox_action_url_for = function($action, $conversation) {
|
||||
return $.replaceTags($action.attr('href'), 'id', $conversation.data('id'));
|
||||
};
|
||||
|
@ -1095,7 +1135,7 @@
|
|||
MessageInbox: MessageInbox
|
||||
});
|
||||
return $(document).ready(function() {
|
||||
var conversation, _i, _len, _ref, _ref2;
|
||||
var conversation, nextAttachmentIndex, _i, _len, _ref, _ref2;
|
||||
$conversations = $('#conversations');
|
||||
$conversation_list = $conversations.find("ul.conversations");
|
||||
set_last_label((_ref = $.cookie('last_label')) != null ? _ref : 'red');
|
||||
|
@ -1112,6 +1152,9 @@
|
|||
return valid;
|
||||
});
|
||||
$form.formSubmit({
|
||||
fileUpload: function() {
|
||||
return $(this).find(".file_input:visible").length > 0;
|
||||
},
|
||||
beforeSubmit: function() {
|
||||
return $(this).loadingImage();
|
||||
},
|
||||
|
@ -1164,15 +1207,19 @@
|
|||
});
|
||||
$message_list.click(function(e) {
|
||||
var $message;
|
||||
$message = $(e.target).closest('#messages > ul > li');
|
||||
if (!$message.hasClass('generated')) {
|
||||
if ($selected_conversation != null) {
|
||||
$selected_conversation.addClass('inactive');
|
||||
if ($(e.target).closest('a.instructure_inline_media_comment').length) {
|
||||
;
|
||||
} else {
|
||||
$message = $(e.target).closest('#messages > ul > li');
|
||||
if (!$message.hasClass('generated')) {
|
||||
if ($selected_conversation != null) {
|
||||
$selected_conversation.addClass('inactive');
|
||||
}
|
||||
$message.toggleClass('selected');
|
||||
$message.find('> :checkbox').attr('checked', $message.hasClass('selected'));
|
||||
}
|
||||
$message.toggleClass('selected');
|
||||
$message.find('> :checkbox').attr('checked', $message.hasClass('selected'));
|
||||
return toggle_message_actions();
|
||||
}
|
||||
return toggle_message_actions();
|
||||
});
|
||||
$('.menus > li > a').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
@ -1310,7 +1357,7 @@
|
|||
return _results;
|
||||
})();
|
||||
token_input.resize();
|
||||
return $(this).find("input").val('').change().last().focus();
|
||||
return $(this).find("input[name!=authenticity_token]").val('').change().last().focus();
|
||||
},
|
||||
close: function() {
|
||||
return $('#add_recipients').data('token_input').input.blur();
|
||||
|
@ -1393,7 +1440,7 @@
|
|||
var $preview, token_input;
|
||||
token_input = $('#forward_recipients').data('token_input');
|
||||
token_input.resize();
|
||||
$(this).find("input").val('').change().last().focus();
|
||||
$(this).find("input[name!=authenticity_token]").val('').change().last().focus();
|
||||
$preview = $(this).find('ul.messages').first();
|
||||
$preview.html('');
|
||||
$preview.html($message_list.find('> li.selected').clone(true).removeAttr('id').removeClass('self'));
|
||||
|
@ -1455,6 +1502,43 @@
|
|||
return false;
|
||||
}
|
||||
});
|
||||
nextAttachmentIndex = 0;
|
||||
$('#action_add_attachment').click(function(e) {
|
||||
var $attachment;
|
||||
e.preventDefault();
|
||||
$attachment = $("#attachment_blank").clone(true);
|
||||
$attachment.attr('id', null);
|
||||
$attachment.find("input[type='file']").attr('name', 'attachments[' + (nextAttachmentIndex++) + ']');
|
||||
$('#attachment_list').append($attachment);
|
||||
$attachment.slideDown("fast", function() {
|
||||
return inbox_resize();
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$("#attachment_blank a.remove_link").click(function(e) {
|
||||
e.preventDefault();
|
||||
$(this).parents(".attachment").slideUp("fast", function() {
|
||||
inbox_resize();
|
||||
return $(this).remove();
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$('#action_media_comment').click(function(e) {
|
||||
e.preventDefault();
|
||||
return $("#create_message_form .media_comment").mediaComment('create', 'audio', function(id, type) {
|
||||
$("#media_comment_id").val(id);
|
||||
$("#media_comment_type").val(type);
|
||||
$("#create_message_form .media_comment").show();
|
||||
return $("#action_media_comment").hide();
|
||||
});
|
||||
});
|
||||
$('#create_message_form .media_comment a.remove_link').click(function(e) {
|
||||
e.preventDefault();
|
||||
$("#media_comment_id").val('');
|
||||
$("#media_comment_type").val('');
|
||||
$("#create_message_form .media_comment").hide();
|
||||
return $("#action_media_comment").show();
|
||||
});
|
||||
_ref2 = MessageInbox.initial_conversations;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
conversation = _ref2[_i];
|
||||
|
|
|
@ -361,9 +361,10 @@ def get_file(filename)
|
|||
fullpath = @file.path
|
||||
filename = File.basename(@file.path)
|
||||
else
|
||||
@file = nil
|
||||
fullpath = "C:\\testfiles\\#{filename}"
|
||||
end
|
||||
[filename, fullpath, data]
|
||||
[filename, fullpath, data, @file]
|
||||
end
|
||||
|
||||
shared_examples_for "in-process server selenium tests" do
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/common')
|
||||
|
||||
shared_examples_for "conversations selenium tests" do
|
||||
it_should_behave_like "in-process server selenium tests"
|
||||
|
||||
context "attachments" do
|
||||
def new_conversation
|
||||
get "/conversations"
|
||||
keep_trying_until{ driver.find_element(:id, "create_message_form") }
|
||||
end
|
||||
|
||||
def submit_message_form(opts={})
|
||||
opts[:message] ||= "Test Message"
|
||||
opts[:attachments] ||= []
|
||||
|
||||
if browser = find_with_jquery("#create_message_form .browser:visible")
|
||||
browser.click
|
||||
keep_trying_until{ find_with_jquery('.selectable:visible').click }
|
||||
end
|
||||
|
||||
find_with_jquery("#create_message_form textarea").send_keys(opts[:message])
|
||||
|
||||
opts[:attachments].each do |fullpath|
|
||||
driver.find_element(:id, "action_add_attachment").click
|
||||
find_all_with_jquery("#create_message_form .file_input:visible").last.send_keys(fullpath)
|
||||
end
|
||||
|
||||
old_count = ConversationMessage.count
|
||||
find_with_jquery("#create_message_form button[type='submit']").click
|
||||
wait_for_ajax_requests
|
||||
|
||||
ConversationMessage.count.should == old_count + 1
|
||||
message = ConversationMessage.last
|
||||
driver.find_element(:id, "message_#{message.id}").should_not be_nil
|
||||
message
|
||||
end
|
||||
|
||||
it "should be able to add an attachment to the message form" do
|
||||
course_with_teacher_logged_in
|
||||
new_conversation
|
||||
|
||||
add_attachment_link = driver.find_element(:id, "action_add_attachment")
|
||||
add_attachment_link.should_not be_nil
|
||||
find_all_with_jquery("#attachment_list > .attachment:visible").should be_empty
|
||||
add_attachment_link.click
|
||||
find_all_with_jquery("#attachment_list > .attachment:visible").should_not be_empty
|
||||
end
|
||||
|
||||
it "should be able to add multiple attachments to the message form" do
|
||||
course_with_teacher_logged_in
|
||||
new_conversation
|
||||
|
||||
add_attachment_link = driver.find_element(:id, "action_add_attachment")
|
||||
add_attachment_link.click
|
||||
add_attachment_link.click
|
||||
add_attachment_link.click
|
||||
find_all_with_jquery("#attachment_list > .attachment:visible").size.should == 3
|
||||
end
|
||||
|
||||
it "should be able to remove attachments from the message form" do
|
||||
course_with_teacher_logged_in
|
||||
new_conversation
|
||||
|
||||
add_attachment_link = driver.find_element(:id, "action_add_attachment")
|
||||
add_attachment_link.click
|
||||
add_attachment_link.click
|
||||
find_with_jquery("#attachment_list > .attachment:visible .remove_link").click
|
||||
keep_trying_until{ find_all_with_jquery("#attachment_list > .attachment:visible").size.should == 1 }
|
||||
end
|
||||
|
||||
it "should save attachments on initial messages on new conversations" do
|
||||
course_with_teacher_logged_in
|
||||
student_in_course
|
||||
filename, fullpath, data = get_file("testfile1.txt")
|
||||
|
||||
new_conversation
|
||||
message = submit_message_form(:attachments => [fullpath])
|
||||
message = "#message_#{message.id}"
|
||||
|
||||
find_all_with_jquery("#{message} .message_attachments li").size.should == 1
|
||||
find_with_jquery("#{message} .message_attachments li a .title").text.should == filename
|
||||
find_with_jquery("#{message} .message_attachments li a").click
|
||||
driver.page_source.should match data
|
||||
end
|
||||
|
||||
it "should save attachments on new messages on existing conversations" do
|
||||
course_with_teacher_logged_in
|
||||
student_in_course
|
||||
filename, fullpath, data = get_file("testfile1.txt")
|
||||
|
||||
new_conversation
|
||||
submit_message_form
|
||||
|
||||
message = submit_message_form(:attachments => [fullpath])
|
||||
message = "#message_#{message.id}"
|
||||
|
||||
find_all_with_jquery("#{message} .message_attachments li").size.should == 1
|
||||
end
|
||||
|
||||
it "should save multiple attachments" do
|
||||
course_with_teacher_logged_in
|
||||
student_in_course
|
||||
file1 = get_file("testfile1.txt")
|
||||
file2 = get_file("testfile2.txt")
|
||||
|
||||
new_conversation
|
||||
message = submit_message_form(:attachments => [file1[1], file2[1]])
|
||||
message = "#message_#{message.id}"
|
||||
|
||||
find_all_with_jquery("#{message} .message_attachments li").size.should == 2
|
||||
find_with_jquery("#{message} .message_attachments li:first a .title").text.should == file1[0]
|
||||
find_with_jquery("#{message} .message_attachments li:last a .title").text.should == file2[0]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "conversations Windows-Firefox-Tests" do
|
||||
it_should_behave_like "conversations selenium tests"
|
||||
prepend_before(:each) {
|
||||
Setting.set("file_storage_test_override", "local")
|
||||
}
|
||||
prepend_before(:all) {
|
||||
Setting.set("file_storage_test_override", "local")
|
||||
}
|
||||
end
|
Loading…
Reference in New Issue