Skip to content

Commit

Permalink
Merge branch 'main' into edit-form-JS-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
noi5e authored Jan 26, 2021
2 parents 4abe44f + 7b4bc4d commit 90282b2
Show file tree
Hide file tree
Showing 13 changed files with 295 additions and 229 deletions.
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gem 'activerecord-session_store'
gem "authlogic", "4.4.2"
gem 'authlogic-oid'
gem "composite_primary_keys"
gem 'figaro'
gem 'figaro' # To easily test OAuth providers in the development mode
gem 'friendly_id'
gem 'gemoji'
gem 'geocoder'
Expand All @@ -25,7 +25,7 @@ gem 'grape-swagger-ui'
gem 'http_accept_language'
gem "i18n-js", ">= 3.0.0.rc11"
gem 'impressionist'
gem 'jbuilder', '~> 2.10'
gem 'jbuilder', '~> 2.11'
gem 'jquery-rails'
gem 'mocha', '~> 1.12'
gem 'mustermann' , '1.1.1'
Expand Down Expand Up @@ -115,7 +115,7 @@ group :test, :development do
gem 'jasmine-jquery-rails'
gem 'jasmine-rails'
gem 'json_expressions'
gem 'minitest-reporters', '~> 1.4.2'
gem 'minitest-reporters', '~> 1.4.3'
gem 'openssl', '~> 2.2.0'
gem 'phantomjs'
gem 'puma', '~> 5.1'
Expand Down
16 changes: 8 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ GEM
buftok (0.2.0)
builder (3.2.4)
byebug (11.1.3)
capybara (3.34.0)
capybara (3.35.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (~> 1.5)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
childprocess (3.0.0)
chronic (0.10.2)
Expand All @@ -94,7 +94,7 @@ GEM
coffee-script-source (1.12.2)
composite_primary_keys (11.2.0)
activerecord (~> 5.2.1)
concurrent-ruby (1.1.7)
concurrent-ruby (1.1.8)
connection_pool (2.2.3)
crack (0.4.5)
rexml
Expand Down Expand Up @@ -238,7 +238,7 @@ GEM
phantomjs (>= 1.9)
railties (>= 3.2.0)
sprockets-rails
jbuilder (2.10.1)
jbuilder (2.11.1)
activesupport (>= 5.0.0)
jquery-atwho-rails (1.5.4)
jquery-datatables (1.10.20)
Expand Down Expand Up @@ -285,7 +285,7 @@ GEM
mini_mime (1.0.2)
mini_portile2 (2.5.0)
minitest (5.14.3)
minitest-reporters (1.4.2)
minitest-reporters (1.4.3)
ansi
builder
minitest (>= 5.0)
Expand Down Expand Up @@ -420,7 +420,7 @@ GEM
recaptcha (4.14.0)
json
redis (4.1.4)
regexp_parser (1.8.2)
regexp_parser (2.0.3)
representable (3.0.4)
declarative (< 0.1.0)
declarative-option (< 0.2.0)
Expand Down Expand Up @@ -608,7 +608,7 @@ DEPENDENCIES
impressionist
jasmine-jquery-rails
jasmine-rails
jbuilder (~> 2.10)
jbuilder (~> 2.11)
jquery-atwho-rails
jquery-datatables
jquery-rails
Expand All @@ -619,7 +619,7 @@ DEPENDENCIES
listen (~> 3.4.1)
loadcss-rails (~> 2.0.1)
mailman
minitest-reporters (~> 1.4.2)
minitest-reporters (~> 1.4.3)
mocha (~> 1.12)
mustermann (= 1.1.1)
mysql2 (>= 0.4.4)
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $E = {
}
});
},
setState: function(textarea = 'text-input', preview = 'preview-main', title = 'title') {
setState: function(textarea = 'text-input', preview = 'comment-preview-main', title = 'title') {
$E.title = $('#' + title + 'title'); // not sure why this exists? seems like $E.title is always #title
$E.textarea = $('#' + textarea);
$E.textarea.bind('input propertychange', $E.save);
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/editorToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const getEditorParams = (targetDiv) => {
// #text-input ID should be unique, and the only comment form on /wiki/new & /wiki/edit
params['textarea'] = 'text-input';
// #preview-main should be unique as well
params['preview'] = 'preview-main';
params['preview'] = 'comment-preview-main';
}
return params;
};
Expand Down
18 changes: 3 additions & 15 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ def feature_node(title)
def get_comment_form_id(location, reply_to)
case location
when :main
'-main'
'main'
when :reply
'-reply-' + reply_to.to_s
'reply-' + reply_to.to_s
when :responses
'-responses'
'responses'
end
end

Expand All @@ -91,18 +91,6 @@ def get_toolbar_element_id(location, reply_to, comment_id)
end
end

# used in views/comments/_form.html.erb
def get_textarea_id(location, reply_to)
case location
when :main
'text-input'
when :reply
'text-input-reply-' + reply_to.to_s
when :responses
'text-input-responses'
end
end

def locale_name_pairs
I18n.available_locales.map do |locale|
[I18n.t('language', locale: locale), locale]
Expand Down
203 changes: 138 additions & 65 deletions app/views/comments/_edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,75 +1,148 @@
<div class="comment-form-wrapper">
<div class="card card-body bg-light">
<form method="post" id="c<%= comment.id %>edit" style="display:none;" class="well" <% if comment.is_a?Answer %> action= "/answers/update/<%= comment.id %>" <% else %> action="/comment/update/<%= comment.id %>" <% end %>>
<div class="card card-body bg-light comment-form-wrapper">
<form method="post" id="comment-form-edit-<%= comment.id %>" style="display:none;" class="well" <% if comment.is_a?Answer %> action= "/answers/update/<%= comment.id %>" <% else %> action="/comment/update/<%= comment.id %>" <% end %>>

<h4 style="margin-top:0;"><%= title %></h4>
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>">
<h4 style="margin-top:0;"><%= title %></h4>
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>">

<style>
#imagebar {width:100%;}
</style>
<style>
#imagebar {width:100%;}
</style>

<!-- toolbar needs location & comment_id to make unique element IDs -->
<%= render :partial => "editor/toolbar", :locals => { :comment_id => comment.id.to_s, :location => :edit } %>
<div id="c<%= comment.id%>div" class="form-group dropzone">
<textarea aria-label="Edit Comment" onFocus="editing=true" name="body" class="form-control" id="text-input-edit-<%= comment.id%>" rows="6" cols="40" placeholder="<%= placeholder %>"><%= !(comment.is_a?Answer) ? comment.comment : comment.content %></textarea>
<div class="imagebar">
<div id="c<%= comment.id%>progress" style="display:none;" class="progress progress-bar-container active pull-right">
<div id="c<%= comment.id%>progress-bar" class="progress-bar progress-bar-striped progress-bar-animated" style="width: 0%;"></div>
</div>
<p>
<span id="c<%= comment.id%>uploading" class="uploading uploading-text" style="display:none;">
<%= translation('comments._edit.uploading') %>
</span>
<span id="c<%= comment.id%>prompt" class="prompt choose-one-prompt-text">
<span style="padding-right:4px;float:left;" class="hidden-xs">
<!-- toolbar needs location & comment_id to make unique element IDs -->
<%= render :partial => "editor/toolbar", :locals => { :comment_id => comment.id.to_s, :location => :edit } %>

<div id="c<%= comment.id%>div" class="form-group dropzone">
<textarea aria-label="Edit Comment" onFocus="editing=true" name="body" class="form-control" id="text-input-edit-<%= comment.id%>" rows="6" cols="40" placeholder="<%= placeholder %>"><%= !(comment.is_a?Answer) ? comment.comment : comment.content %></textarea>
<div class="imagebar">
<div id="c<%= comment.id%>progress" style="display:none;" class="progress progress-bar-container active pull-right">
<div id="c<%= comment.id%>progress-bar" class="progress-bar progress-bar-striped progress-bar-animated" style="width: 0%;"></div>
</div>
<p>
<span id="c<%= comment.id%>uploading" class="uploading uploading-text" style="display:none;">
<%= translation('comments._edit.uploading') %>
</span>
<span id="c<%= comment.id%>prompt" class="prompt choose-one-prompt-text">
<span style="padding-right:4px;float:left;" class="hidden-xs">
<%= raw translation('comments._edit.drag_and_drop') %>
</span>
<label id="c<%= comment.id%>input_label" for="c<%= comment.id%>input">
<input id="c<%= comment.id%>input" type="file" name="image[photo]" style="display:none;" />
<a class="hidden-xs"><%= translation('comments._edit.choose_one') %></a>
<span class="visible-xs">
<i class="fa fa-upload"></i>
<a><%= translation('comments._edit.upload_image') %></a>
</span>
</label>
</span>
</p>
</div>
</div>
<div class="comment-preview well col-md-11" id="comment-preview-edit-<%= comment.id %>" style="background:white;display: none">
</div>
<label id="c<%= comment.id%>input_label" for="c<%= comment.id%>input">
<input id="c<%= comment.id%>input" type="file" name="image[photo]" style="display:none;" />
<a class="hidden-xs"><%= translation('comments._edit.choose_one') %></a>
<span class="visible-xs">
<i class="fa fa-upload"></i>
<a><%= translation('comments._edit.upload_image') %></a>
</span>
</label>
</span>
</p>
</div>
</div>
<script type="application/javascript">
// function setInit(id) {
// const textArea = 'c'+id+'text';
// const preview = 'c'+id+'preview';
// $E.setState(textArea, preview);
// }

<div class="control-group">
<button type="submit" class="btn btn-primary"><%= translation('comments._edit.publish') %></button>
<a
class="btn btn-default preview-btn"
data-previewing-text="Hide Preview"
onClick="
$E.setState(
'text-input-edit-<%= comment.id%>',
'comment-preview-edit-<%= comment.id %>'
);
$E.toggle_preview();
"
>
Preview
</a>
<a class="btn btn-default" onClick="$('#c<%= comment.id %>show').toggle();$('#c<%= comment.id %>edit').toggle()">
Cancel
</a>
// $('#c<%= comment.id%>div').on('dragover',function(e) {
// e.preventDefault();
// $('#c<%= comment.id%>div').addClass('hover');
// });

<span class="form-grey"> &nbsp;
<br class="visible-xs" /><%= raw translation('comments._edit.logged_in', :username => current_user.username) %> |
<a target="_blank" href="/wiki/authoring-help#Formatting"><%= translation('comments._edit.formatting') %></a> |
<a onClick="$('#who-is-notified').toggle()"><%= translation('comments._edit.notifications') %></a>
</span>
</div>
// $('#c<%= comment.id%>div').on('dragout',function(e) {
// $('#c<%= comment.id%>div').removeClass('hover');
// });

<p id="who-is-notified" style="display:none;color:#888;">
<%= translation('comments._edit.email_notifications') %>
</p>
</form>
// $('#c<%= comment.id%>div').on('drop',function(e) {
// e.preventDefault();
// $D.selected = $(e.target).closest('div.comment-form-wrapper').eq(0);
// setInit(<%= comment.id %>);
// });

// $('#c<%= comment.id%>div').fileupload({
// url: "/images",
// paramName: "image[photo]",
// dropZone: $('#c<%= comment.id%>div'),
// dataType: 'json',
// formData: {
// 'uid':<%= current_user.uid %>,
// 'nid':<%= comment.uid %>
// },
// start: function(e) {
// $('#c<%= comment.id%>progress').show()
// $('#c<%= comment.id%>uploading').show()
// $('#c<%= comment.id%>prompt').hide()
// $('#c<%= comment.id%>div').removeClass('hover');
// },
// done: function (e, data) {
// $('#c<%= comment.id%>progress').hide()
// $('#c<%= comment.id%>progress #c<%= comment.id%>progress-bar').css('width', 0);
// $('#c<%= comment.id%>uploading').hide()
// $('#c<%= comment.id%>prompt').show()
// var is_image = false
// if (data.result['filename'].substr(-3,3) == "jpg") is_image = true
// if (data.result['filename'].substr(-4,4) == "jpeg") is_image = true
// if (data.result['filename'].substr(-3,3) == "png") is_image = true
// if (data.result['filename'].substr(-3,3) == "gif") is_image = true
// if (data.result['filename'].substr(-3,3) == "JPG") is_image = true
// if (data.result['filename'].substr(-4,4) == "JPEG") is_image = true
// if (data.result['filename'].substr(-3,3) == "PNG") is_image = true
// if (data.result['filename'].substr(-3,3) == "GIF") is_image = true

// if (is_image) {
// image_url = data.result.url.split('?')[0];
// orig_image_url = image_url.replace('medium','original');
// $E.wrap('[![',']('+image_url+')]('+orig_image_url+')', {'newline': true, 'fallback': data.result['filename']});
// } else {
// $E.wrap('<a href="'+data.result.url.split('?')[0]+'"><i class="fa fa-file"></i> ','</a>', {'newline': true, 'fallback': data.result['filename']});
// }

// if ($('#node_images').val() && $('#node_images').val().split(',').length > 1) $('#node_images').val([$('#node_images').val(),data.result.id].join(','));
// else $('#node_images').val(data.result.id)
// },

// // fileuploadfail: function(e,data) {},
// progressall: function (e, data) {
// var progress = parseInt(data.loaded / data.total * 100, 10);
// $('#c<%= comment.id%>progress #c<%= comment.id%>progress-bar').css(
// 'width',
// progress + '%'
// );
// }
// });
</script>

<div class="comment-preview well col-md-11" id="comment-preview-edit-<%= comment.id %>" style="background: white; display: none">
</div>

<div class="control-group">
<button type="submit" class="btn btn-primary"><%= translation('comments._edit.publish') %></button>
<a
class="btn btn-default preview-btn"
data-previewing-text="Hide Preview"
onClick="
$E.setState(
'text-input-edit-<%= comment.id%>',
'comment-preview-edit-<%= comment.id %>'
);
$E.toggle_preview();
"
>
Preview
</a>
<a class="btn btn-default" onClick="$('#c<%= comment.id %>show').toggle();$('#comment-form-edit-<%= comment.id %>').toggle()">
Cancel
</a>

<span class="form-grey"> &nbsp;
<br class="visible-xs" /><%= raw translation('comments._edit.logged_in', :username => current_user.username) %> |
<a target="_blank" href="/wiki/authoring-help#Formatting"><%= translation('comments._edit.formatting') %></a> |
<a onClick="$('#who-is-notified').toggle()"><%= translation('comments._edit.notifications') %></a>
</span>
</div>

<p id="who-is-notified" style="display:none;color:#888;">
<%= translation('comments._edit.email_notifications') %>
</p>
</form>
</div>
Loading

0 comments on commit 90282b2

Please sign in to comment.