Skip to content

Commit

Permalink
Added ajax pagination, ajax search & ajax initials search for users a…
Browse files Browse the repository at this point in the history
…nd groups. Added a cloud tag dummy for groups index
  • Loading branch information
VictorSB committed Feb 24, 2011
2 parents 7816dae + 4e4f02a commit c5c162e
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 48 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -4,3 +4,5 @@ pkg/*gem
Gemfile.lock
.idea
nbproject
.loadpath
.project
22 changes: 22 additions & 0 deletions app/models/profile.rb
@@ -1,3 +1,25 @@
class Profile < ActiveRecord::Base
belongs_to :actor

validates_format_of :mobile, :phone, :fax,
:allow_nil => true,
:with => /(^$)|(((\((\+?)\d+\))?|(\+\d+)?)[ ]*-?(\d+[ ]*\-?[ ]*\d*)+$)/,
:message => "has a invalid format"

validates_format_of :website,
:allow_nil => true,
:with => /(^$)|((https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$)/ ,
:message => "has a invalid format"

def birthday=(value)
@birthday_formatted_invalid = false
super Date.parse(value)
rescue ArgumentError
@birthday_formatted_invalid = true
end

def validate
errors.add(:birthday, "is invalid. Please, use \"month/day/year\" format and make sure you choose a valid date" ) if @birthday_formatted_invalid || birthday > Date.today
end

end
67 changes: 59 additions & 8 deletions app/views/users/_profile.html.erb
Expand Up @@ -3,8 +3,6 @@

<div class="future_conference" id="personal_info" >
<div class="future_header">

<br/><br/>
<div class="title_section">
Personal Information
</div>
Expand All @@ -15,6 +13,7 @@
</div>
</div>
<div class="post_future_conference" >
<% if @user.profile.organization? %>
<div class="info_post">
<div class="info_left">
Organization:
Expand All @@ -23,12 +22,14 @@
<%=h @user.profile.organization %>
</div>
</div>
<%end%>
<% if @user.profile.birthday? %>
<div class="info_post">
<div class="info_left">
BirthDay:
</div>
<div class="info_right">
<%=h @user.profile.birthday.to_s() %>
<%=h I18n.l @user.profile.birthday, :format => :long %>
</div>
</div>
<div class="info_post">
Expand All @@ -39,15 +40,21 @@
<%=h @user.age %>
</div>
</div>
<%end%>
<% if @user.profile.city? %>
<div class="info_post">
<div class="info_left">
Actual City:
</div>
<div class="info_right">
<%=h @user.profile.city %>,
<%=h @user.profile.country %>
<%=h @user.profile.city %>
<% if @user.profile.country? %>
, <%=@user.profile.country%>
<%end%>
</div>
</div>
<%end%>
<% if @user.profile.description? %>
<div class="info_post">
<div class="info_left">
About me:
Expand All @@ -56,6 +63,7 @@
<%=h @user.profile.description %>
</div>
</div>
<%end%>
</div>
</div>

Expand All @@ -70,19 +78,62 @@
</div>
<div class="post_future_conference">
<div class="future_content">
<% if @user.profile.phone? %>
<div class="info_post">
<div class="info_left">
Phone
</div>
<div class="info_right">
<%=h @user.profile.phone %>
</div>
</div>
<%end%>
<% if @user.profile.mobile? %>
<div class="info_post">
<div class="info_left">
Mobile
</div>
<div class="info_right">
<%=h @user.profile.mobile %>
</div>
</div>
<%end%>
<% if @user.profile.fax? %>
<div class="info_post">
<div class="info_left">
Fax
</div>
<div class="info_right">
<%=h @user.profile.fax %>
</div>
</div>
<%end%>
<% if @user.profile.address? %>
<div class="info_post">
<div class="info_left">
Address
</div>
<div class="info_right">
<%=h @user.profile.address %>
</div>
</div>
<%end%>
<% if @user.profile.website? %>
<div class="info_post">
<div>
<div class="info_left">
Website
</div>
<div class="contact_link">
<a href="<%=h @user.profile.website %>"><%=h @user.profile.website %></a>
</div>
</div>
<%end%>
<div class="info_post">
<div>
<div class="info_left">
E-mail
</div>
<div class="contact_link">
<div class="info_right">
<%=h @user.email %>
</div>
</div>
Expand Down
25 changes: 14 additions & 11 deletions app/views/users/edit.html.erb
Expand Up @@ -11,7 +11,7 @@
<%= form_for(@user, :remote => true) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %>prohibited this user from being saved:</h2>
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li>
Expand Down Expand Up @@ -47,6 +47,7 @@
<%= f.text_field :name, :class => "required" %>

<br/>

<script type="text/javascript">

$(function() {
Expand All @@ -60,20 +61,22 @@

</script>
<%= f.fields_for :profile do |profile_form| %>

<div class="editField">
<%= profile_form.label :birthday %>
<%= profile_form.label :organization %>
<br/>
</div>
<%= profile_form.text_field :birthday , :class => "date" %>
</div>
<%= profile_form.text_field :organization %>
<br/>


<div class="editField">
<%= profile_form.label :organization %>
<%= profile_form.label :birthday %>
<br/>
</div>
<%= profile_form.text_field :organization %>
<%= profile_form.text_field( :birthday , :class => "date") %>
<br/>



<div class="editField">
<%= profile_form.label :city %>
<br/>
Expand Down Expand Up @@ -114,19 +117,19 @@
<%= profile_form.label :phone %>
<br/>
</div>
<%= profile_form.text_field :phone, :class => "digits" %>
<%= profile_form.text_field :phone, :class => "phone" %>
<br/>
<div class="editField">
<%= profile_form.label :mobile %>
<br/>
</div>
<%= profile_form.text_field :mobile, :class => "digits" %>
<%= profile_form.text_field :mobile, :class => "phone" %>
<br/>
<div class="editField">
<%= profile_form.label :fax %>
<br/>
</div>
<%= profile_form.text_field :fax, :class => "digits" %>
<%= profile_form.text_field :fax, :class => "phone" %>
<br/>
<div class="editField">
<%= profile_form.label :address %>
Expand Down
23 changes: 13 additions & 10 deletions app/views/users/update.js.erb
@@ -1,19 +1,22 @@

<% if @user.valid? %>


if ($("#notice").length == 0){

$("#content").prepend('<div id="notice"></div>');

}
$("#notice").html("<h2>Form Submitted!</h2>");

$("#content").prepend('<div id="notice"></div>');

}

<% if @user.valid? %>

$("#notice").html("<h2>Form Submitted!</h2><br/>");
$("#notice").removeClass('error_explanation');
$("#notice").addClass('confirmed');
$("#middleContent").replaceWith("<%= escape_javascript(render(:partial => 'middle_show'))%>");

<% else %>

$("#flash_error").html("<h2>Fail!</h2>");
$("#notice").html("<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>"
+"<ul><% @user.errors.full_messages.each do |msg| %><li><%= msg %></li><% end %></ul><br/>");
$("#notice").removeClass('confirmed');
$("#notice").addClass('error_explanation');

<% end %>

Expand Down
Expand Up @@ -13,6 +13,10 @@
* http://www.gnu.org/licenses/gpl.html
*/

/*
* This have been modified: added telephone number validation
*/

(function($) {

$.extend($.fn, {
Expand Down Expand Up @@ -235,25 +239,26 @@ $.extend($.validator, {
},

messages: {
required: "This field is required.",
remote: "Please fix this field.",
email: "Please enter a valid email address.",
url: "Please enter a valid URL.",
date: "Please enter a valid date.",
dateISO: "Please enter a valid date (ISO).",
dateDE: "Bitte geben Sie ein gültiges Datum ein.",
number: "Please enter a valid number.",
numberDE: "Bitte geben Sie eine Nummer ein.",
digits: "Please enter only digits",
creditcard: "Please enter a valid credit card number.",
equalTo: "Please enter the same value again.",
accept: "Please enter a value with a valid extension.",
maxlength: $.format("Please enter no more than {0} characters."),
minlength: $.format("Please enter at least {0} characters."),
rangelength: $.format("Please enter a value between {0} and {1} characters long."),
range: $.format("Please enter a value between {0} and {1}."),
max: $.format("Please enter a value less than or equal to {0}."),
min: $.format("Please enter a value greater than or equal to {0}.")
required: " This field is required.",
remote: " Please fix this field.",
email: " Please enter a valid email address.",
url: " Please enter a valid URL.",
date: " Please enter a valid date.",
dateISO: " Please enter a valid date (ISO).",
dateDE: " Bitte geben Sie ein gültiges Datum ein.",
number: " Please enter a valid number.",
numberDE: " Bitte geben Sie eine Nummer ein.",
digits: " Please enter only digits",
phone: " Please enter a valid telephone number",
creditcard: " Please enter a valid credit card number.",
equalTo: " Please enter the same value again.",
accept: " Please enter a value with a valid extension.",
maxlength: $.format(" Please enter no more than {0} characters."),
minlength: $.format(" Please enter at least {0} characters."),
rangelength: $.format(" Please enter a value between {0} and {1} characters long."),
range: $.format(" Please enter a value between {0} and {1}."),
max: $.format(" Please enter a value less than or equal to {0}."),
min: $.format(" Please enter a value greater than or equal to {0}.")
},

autoCreateRanges: false,
Expand Down Expand Up @@ -719,6 +724,8 @@ $.extend($.validator, {
number: {number: true},
numberDE: {numberDE: true},
digits: {digits: true},
//Added
phone: {phone: true},
creditcard: {creditcard: true}
},

Expand Down Expand Up @@ -1001,6 +1008,11 @@ $.extend($.validator, {
digits: function(value, element) {
return this.optional(element) || /^\d+$/.test(value);
},

// Added
phone: function(value, element) {
return this.optional(element) || /^((\((\+?)\d+\))?|(\+\d+)?)[ ]*-?(\d+[ ]*\-?[ ]*\d*)+$/.test(value);
},

// http://docs.jquery.com/Plugins/Validation/Methods/creditcard
// based on http://en.wikipedia.org/wiki/Luhn
Expand Down
Expand Up @@ -30,9 +30,21 @@
}

/*Edit*/
.confirmed{
color: #009933;
padding-left: 5%;
}
.editField{
padding-top: 5px;
}
.error{
color: #A2042B;
font-weight: bold;
}
.error_explanation{
color: #A2042B;
padding-left: 5%;
}
.section_highlight{
border-left: none;
border-bottom: thin solid #D4E4EA;
Expand Down

0 comments on commit c5c162e

Please sign in to comment.