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

Post.js #3996

Closed
wants to merge 13 commits into from
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require typeahead.js/dist/typeahead.jquery.js
//= require jquery
//= require jquery_ujs
//= require bootstrap/dist/js/bootstrap.min.js
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/post.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//=require typeahead.js/dist/typeahead.jquery.js
jQuery(document).ready(function() {

$('.datepicker').datepicker()
Expand Down
1 change: 1 addition & 0 deletions app/views/editor/rich.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<link href="/lib/bootstrap-tokenfield/dist/css/bootstrap-tokenfield.min.css" rel="stylesheet">

<!-- required for TagsModule -->
<script src="../app/assets/javascript/post.js"></script>
<script src="/lib/typeahead.js/dist/typeahead.jquery.js"></script>
<script src="/lib/typeahead.js/dist/bloodhound.js"></script>
<script src="/lib/bootstrap-tokenfield/dist/bootstrap-tokenfield.js"></script>
Expand Down
202 changes: 97 additions & 105 deletions app/views/users/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,178 +1,170 @@
<%= form_for @user, :url => {:controller => 'users', :action => @action}, :html => {:class => "row"} do |f| %>

<% if f.error_messages != "" %><div class="alert alert-danger"><%= f.error_messages %></div><% end %>
<% if f.error_messages != "" %>
<div class="alert alert-danger"><%= f.error_messages %></div>
<% end %>

<div class="col-lg-8 col-md-10 col-sm-10">
<% if params[:controller] == "users" && @action == "create" %>
<div class='col-lg-10 col-md-10 col-sm-10' style="display:flex; justify-content: center;">
<h3> Sign up with </h3>
</div>
<% if Rails.env == "production" %>
<div class='col-lg-10 col-md-10 col-sm-10' style="display:flex; justify-content: center;">
<%= render :partial => "layouts/social_icons" %>
<% end %>
<h3> Sign up with </h3>
</div>

<div class='col-lg-10 col-md-10 col-sm-10' style="display:flex; justify-content: center;">
<h3> OR</h3>

</div>
<br style="clear:both;"/>
<div class="form-group">

<label for="username"><%= t('users._form.username') %></label>
<%= f.text_field :username, { tabindex: 1, class: 'form-control', id: 'username' } %>
<% if Rails.env == "production" %>
<div class='col-lg-10 col-md-10 col-sm-10' style="display:flex; justify-content: center;">
<%= render :partial => "layouts/social_icons" %>
</div>
<% end %>

<input type="hidden" name="id" value="<%= @user.username %>" />
<div class='col-lg-10 col-md-10 col-sm-10' style="display:flex; justify-content: center;">
<h3> OR</h3>
</div>

<% end %>
<br style="clear:both;"/>

<div class="form-group">
<% if Rails.env == "production" %>
<% if params[:controller] == "users" && params[:action] == "edit" %>
<div class='col-lg-8 col-md-10 col-sm-10' style="display:flex; justify-content: flex-start; padding: 0;">
<label> Link your Public Lab account to providers </label>
</div>
<div class='col-lg-8 col-md-10 col-sm-10' style="display:flex; justify-content: flex-start; padding: 0; margin-bottom: 10px;">
<%= render :partial => "layouts/social_icons" %>
</div>
<% end %>
<div class="form-group">
<label for="username"><%= t('users._form.username') %></label>
<%= f.text_field :username, {tabindex: 1, class: 'form-control', id: 'username'} %>
<input type="hidden" name="id" value="<%= @user.username %>"/>
</div>
<% end %>
<br style="clear:both;"/>

<div class="form-group">
<% if Rails.env == "production" %>
<% if params[:controller] == "users" && params[:action] == "edit" %>
<div class='col-lg-8 col-md-10 col-sm-10' style="display:flex; justify-content: flex-start; padding: 0;">
<label> Link your Public Lab account to providers </label>
</div>
<div class='col-lg-8 col-md-10 col-sm-10' style="display:flex; justify-content: flex-start; padding: 0; margin-bottom: 10px;">
<%= render :partial => "layouts/social_icons" %>
</div>
<% end %>
<% end %>

<label for="email"><%= t('users._form.email') %></label>
<%= f.text_field :email, { tabindex: 3, placeholder: "[email protected]", class: 'form-control', id: 'email' } %>
<br style="clear:both;"/>

<label for="email"><%= t('users._form.email') %></label>
<%= f.text_field :email, {tabindex: 3, placeholder: "[email protected]", class: 'form-control', id: 'email'} %>
</div>


<div class="form-group">
<% if @user.crypted_password.nil? %>
<label for="password"><%= t('users._form.create_password') %></label>
<% else %>
<label for="password"><%= t('users._form.change_password') %></label>
<% end %>
<%= f.password_field :password, { placeholder: I18n.t('users._form.password'),
tabindex: 4,
class: 'form-control',
id: 'password' }
<%= f.password_field :password, {placeholder: I18n.t('users._form.password'),
tabindex: 4,
class: 'form-control',
id: 'password'}
%>
</div>

<div class="form-group">
<label for="password_confirmation"><%= t('users._form.confirmation') %></label>
<%= f.password_field :password_confirmation, { placeholder: I18n.t('users._form.confirm_password'),
tabindex: 5,
class: 'form-control',
id: 'password-confirmation' }
<%= f.password_field :password_confirmation, {placeholder: I18n.t('users._form.confirm_password'),
tabindex: 5,
class: 'form-control',
id: 'password-confirmation'}
%>
</div>


<div class="form-group">
<label for="user_bio"><%= t('users._form.bio') %></label>
<%= f.text_area :bio, { placeholder: I18n.t('users._form.add_bio'),
rows: 8,
class: 'form-control',
tabindex: 6 }
<%= f.text_area :bio, {placeholder: I18n.t('users._form.add_bio'),
rows: 8,
class: 'form-control',
tabindex: 6}
%>
</div>


<% if params[:controller] == "users" && (params[:action] == "new" || params[:action] == "create") %>

<% if Rails.env == "production" && !params[:spamaway] %>

<%= recaptcha_tags %>

<% else %>

<%= fields_for @spamaway do |spam| %>

<div class="form-group spamaway">

<label for="spamaway_follow_instructions">
<%= t('users._form.are_you_human') %>
</label>
<p>
<%= t('users._form.spam_filtering') %>
</p>

<% vars = [:statement1, :statement2, :statement3, :statement4] %>
<% turingtest = Spamaway.get_pairs vars.length %>
<% turingtest.each_index do |i| %>

<div class="btn-group btn-group-justified" role="group">
<% [0,1].each_with_index do |s, j| %><% statement = turingtest[i][s] %>
<div class="btn-group" role="group">
<button type="button" class="col-xs-5 btn btn-default" style="text-align:left;<% if i.odd? %> background:#eef;<% end %>" id="spamaway-<%= i.to_s + j.to_s %>">
<%= spam.radio_button vars[i], statement %> <%= statement %>
</button>
</div>
<% end %>
</div>
<br />

<div class="btn-group btn-group-justified" role="group">
<% [0, 1].each_with_index do |s, j| %>
<% statement = turingtest[i][s] %>
<div class="btn-group" role="group">
<button type="button" class="col-xs-5 btn btn-default" style="text-align:left;<% if i.odd? %> background:#eef;
<% end %>" id="spamaway-<%= i.to_s + j.to_s %>">
<%= spam.radio_button vars[i], statement %> <%= statement %>
</button>
</div>
<% end %>
</div>
<br/>
<% end %>

</div>

<div class="form-group">

<%= spam.text_area :follow_instructions, { class: "form-control col-md-6",
rows: 8,
tabindex: 7,
placeholder: I18n.t('users._form.dont_write_here') }
<%= spam.text_area :follow_instructions, {class: "form-control col-md-6",
rows: 8,
tabindex: 7,
placeholder: I18n.t('users._form.dont_write_here')}
%>

</div>

<% end %>

<% end %>

<script>
(function() {
$('.spamaway button').click(function(e) {
$(this).find('input').prop('checked', true);
})
})();
(function () {
$('.spamaway button').click(function (e) {
$(this).find('input').prop('checked', true);
})
})();
</script>

<% end %>

<div class="form-group form-inline" style="clear:both;padding-top:10px;">

<% if params[:controller] == "users" && (params[:action] == "new" || params[:action] == "create") %>

<!-- button for creating new users -->
<button class="btn btn-lg btn-primary btn-save" type="submit" tabindex="7"><%= t('users._form.sign_up') %></button>
<button onclick="checkInput()" class="btn btn-lg btn-primary btn-save" type="submit" tabindex="7"><%= t('users._form.sign_up') %></button>
<a class="btn btn-lg btn-default" href="/login"><%= t('users._form.log_in') %></a>

<% elsif params[:controller] == "users" && params[:action] == "edit" %>

<!-- button for saving edits for existing users -->
<button class="btn btn-lg btn-primary btn-save" type="submit" tabindex="7"><%= t('users._form.save') %></button>

<% end %>

<script>
(function() {
$('.btn-save').click(function onClick(e) {
$(this).addClass("disabled") // disable the button after it is clicked
.html("<i class='fa fa-spinner fa-spin'></i>"); // make a spinner that spins when clicked
})
})();
(function () {
$('.btn-save').click(function onClick(e) {

})
})();

function checkInput() {
var username = document.getElementById("username").value;
var email = document.getElementById("email").value;
var password = document.getElementById("password").value;
var password_conf = document.getElementById("password-confirmation").value;
var input_fields = [username, email, password, password_conf];
var fields = ["Username", "Email", "Password", "Password-confirmation"];

var emptyFields = [];
var errors = 0;
for (var i = 0; i < input_fields.length; i++) {
if (input_fields[i] === "") {
errors++;
emptyFields.push(fields[i]);
}
}
if (errors > 0) {
notyNotification('sunset', 10000, 'error', 'topRight', "Please complete the following fields: " + emptyFields);
}
else {
$(this).addClass("disabled")
.html("<i class='fa fa-spinner fa-spin'></i>");
}
}
</script>

</div>

</div>

<div class="col-md-2">
<%= render :partial => 'users/photo' %>
</div>

<% end %>