Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move commenting UI code into an independent .js file #3831

Closed
jywarren opened this issue Oct 29, 2018 · 3 comments
Closed

Move commenting UI code into an independent .js file #3831

jywarren opened this issue Oct 29, 2018 · 3 comments
Labels
fto-candidate issues which are meant to be solved by first timers but aren't well-formatted yet gci-candidate help wanted requires help by anyone willing to contribute HTML JavaScript

Comments

@jywarren
Copy link
Member

This has been marked as a good candidate for becoming a first-timers-only issue like these, meaning that it's simple, self-contained, and with some extra formatting, could be a great entry point for a new contributor. If you're familiar enough with this code, please consider reformatting or reposting it as a first-timers-only issue, and then ping @publiclab/reviewers to get it labelled. Or, if this is not your first time, try to solve it yourself!


Our commenting code is quite long and is placed inline into the comments page. We should include it using a <script> tag, and move it into this folder with other JavaScript code:

https://github.com/publiclab/plots2/blob/f423719cc77948f0e2ceb27e1e0685115841a9a5/app/assets/javascripts/

Here's the segment that should be moved:

$('#text-input').bind('keypress',function(e){
if (e.ctrlKey && e.keyCode == 10) {
$("#comment-form .btn-primary").click();
}
})
$('#comment-form').bind('ajax:beforeSend', function(event){
$("#text-input").prop('disabled',true)
$("#comment-form .btn-primary").button('loading',true);
});
$('#comment-form').bind('ajax:success', function(e, data, status, xhr){
$('#text-input').prop('disabled',false);
$('#text-input').val('');
$('#comments-container').append(xhr.responseText);
$('#comment-count')[0].innerHTML = parseInt($('#comment-count')[0].innerHTML)+1;
$("#comment-form .btn-primary").button('reset');
$('#preview').hide();
$('#text-input').show();
$('#preview-btn').button('toggle');
});
$('#comment-form').bind('ajax:error', function(e,response){
notyNotification('mint', 3000, 'success', 'topRight', 'Some error occured while adding comment');
$('#comment-form .control-group').addClass('has-error')
$('#comment-form .control-group .help-block ').remove()
$('#comment-form .control-group').append('<span class="help-block ">Error: there was a problem.</span>')
});
})();
function insertTitleSuggestionTemplate() {
var element = $('#text-input');
var currentText = $('#text-input').val().trim();
var template = "\n[propose:title]Propose your title here[/propose]";
if(currentText.length == 0)
template = "[propose:title]Propose your title here[/propose]";
var newText = currentText+template;
element.val(newText);
}

Once it's moved into /app/assets/javascripts/comment.js, we can re-include it with this line in the _form.html.erb template:

  <%= javascript_include_tag "comment.js" %>

We'd love help with this one!

@jywarren jywarren added help wanted requires help by anyone willing to contribute JavaScript fto-candidate issues which are meant to be solved by first timers but aren't well-formatted yet HTML gci-candidate labels Oct 29, 2018
@junhouse
Copy link
Contributor

@jywarren I will claim this and work on it - let me know if someone has already claimed it!

@jywarren
Copy link
Member Author

jywarren commented Oct 30, 2018 via email

@junhouse
Copy link
Contributor

@jywarren Thanks! I just passed all the tests and updated the code. Do I need to do anything at this point? I already did the pull-request. Please let me know what to do to move forward.

jywarren pushed a commit that referenced this issue Nov 7, 2018
…3855)

* fix erro #3831 by junhouse

* add junhouse fix 2 for error 3831

* fix 3 junhouse

* add fix 4

* fix 5 with config update
SrinandanPai pushed a commit to SrinandanPai/plots2 that referenced this issue May 5, 2019
…#3831. (publiclab#3855)

* fix erro publiclab#3831 by junhouse

* add junhouse fix 2 for error 3831

* fix 3 junhouse

* add fix 4

* fix 5 with config update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fto-candidate issues which are meant to be solved by first timers but aren't well-formatted yet gci-candidate help wanted requires help by anyone willing to contribute HTML JavaScript
Projects
None yet
Development

No branches or pull requests

2 participants