Skip to content

Commit

Permalink
Added javascript needed to rename from all recordings (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
farhatahmad authored and jfederico committed Mar 5, 2019
1 parent ef8fc2c commit ab66555
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
26 changes: 16 additions & 10 deletions app/assets/javascripts/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $(document).on('turbolinks:load', function(){
var controller = $("body").data('controller');
var action = $("body").data('action');

if(controller == "rooms" && action == "show" || controller == "rooms" && action == "update"){
if(controller == "rooms" && action == "show" || controller == "rooms" && action == "update" || controller == "users" && action == "recordings"){

// Set a room header rename event
var configure_room_header = function(room_title){
Expand Down Expand Up @@ -117,14 +117,7 @@ $(document).on('turbolinks:load', function(){

// Apply ajax request depending on the element that triggered the event
var submit_rename_request = function(element){
if(element.data('room-uid')){
submit_update_request({
setting: "rename_block",
room_block_uid: element.data('room-uid'),
room_name: element.find('#room-name-editable-input').val(),
});
}
else if(element.is('#room-title')){
if(element.is('#room-title')){
submit_update_request({
setting: "rename_header",
room_name: element.find('#user-text').text(),
Expand All @@ -135,15 +128,28 @@ $(document).on('turbolinks:load', function(){
setting: "rename_recording",
record_id: element.data('recordid'),
record_name: element.find('text').text(),
room_uid: element.data('room-uid'),
});
}
}

// Helper for submitting ajax requests
var submit_update_request = function(data){
var update_path = window.location.pathname

if ('room_uid' in data) {
update_path = $("body").data('relative-root')

if (!update_path.endsWith("/")) {
update_path += "/"
}

update_path += data.room_uid
}

// Send ajax request for update
$.ajax({
url: window.location.pathname,
url: update_path,
type: "PATCH",
data: data,
});
Expand Down
5 changes: 1 addition & 4 deletions app/assets/javascripts/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ $(document).on('turbolinks:load', function(){
// Display and update all fields related to creating a room in the createRoomModal
$("#create-room").click(function(){
$("#create-room-name").val("")

var relative_url_root = window.location.pathname.split("/")[1];

$("#createRoomModal form").attr("action", "/" + relative_url_root)
$("#createRoomModal form").attr("action", $("body").data('relative-root'))
updateDropdown($(".dropdown-item[value='default']"))
$("#room_mute_on_join").prop("checked", false)

Expand Down
7 changes: 6 additions & 1 deletion app/controllers/rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ def update
elsif params[:setting] == "rename_recording"
@room.update_recording(params[:record_id], "meta_name" => params[:record_name])
end
redirect_to room_path

if request.referrer
redirect_to request.referrer
else
redirect_to room_path
end
end

# POST /:room_uid
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>

<body class="app-background" data-controller="<%= params[:controller] %>" data-action="<%= params[:action] %>">
<body class="app-background" data-controller="<%= params[:controller] %>" data-action="<%= params[:action] %>" data-relative-root="<%= Rails.configuration.relative_url_root || "/" %>">
<%= render "shared/header" %>

<div class="wrapper">
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/components/_recording_row.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<tr>
<td>
<div id="recording-title" class="form-inline edit_hover_class" data-recordid="<%= recording[:recordID] %>">
<div id="recording-title" class="form-inline edit_hover_class" data-recordid="<%= recording[:recordID] %>" data-room-uid="<%= recording[:room_uid] %>">
<text id='recording-text'>
<% if recording[:metadata][:name] %>
<%= recording[:metadata][:name] %>
Expand Down

0 comments on commit ab66555

Please sign in to comment.