Permalink
Browse files

Merge branch 'master' of git@github.com:Smudge/newstc into mass-data

  • Loading branch information...
Wei Yan
Wei Yan committed Jun 23, 2009
2 parents 18be2e0 + 6142039 commit 3f61cb825aee741bb452677fe35e753e7e6bf273
@@ -108,15 +108,21 @@ def fetch_loc_groups
def set_sources(update = false)
@notice.remove_all_viewer_sources if update
if params[:for_users]
- params[:for_users].split(",").map(&:strip).each do |login_or_name|
- viewer = User.search(login_or_name)
- if viewer
- @notice.add_viewer_source(viewer)
- else
- @notice.errors.add_to_base "\'#{login_or_name}\' is not a valid name or NetID." unless login_or_name.blank?
- end
+ # params[:for_users].split(",").map(&:strip).each do |login_or_name|
+ # viewer = User.search(login_or_name)
+ # if viewer
+ # @notice.add_viewer_source(viewer)
+ # else
+ # @notice.errors.add_to_base "\'#{login_or_name}\' is not a valid name or NetID." unless login_or_name.blank?
+ # end
+ # end
+ #parse autocomplete
+ params[:for_users].split(",").each do |l|
+ l = l.split("||")
+ @notice.add_viewer_source(l[0].constantize.find(l[1])) if l.length == 2
end
end
+ @notice.add_viewer_source(@department) if params[:department_wide_viewers] && !@notice.is_sticky
@notice.remove_all_display_location_sources if update
@notice.add_display_location_source(@department) if params[:department_wide_locations] && current_user.is_admin_of?(@department)
if params[:for_locations]
@@ -39,11 +39,17 @@ def edit
# POST /sub_requests
# POST /sub_requests.xml
- def create
+ def create
@sub_request = SubRequest.new(params[:sub_request])
@sub_request.shift = Shift.find(params[:shift_id])
- params[:list_of_logins].split(/\W+/).each do |l|
- @sub_request.add_substitute_source(User.find_by_login(l))
+ # params[:list_of_logins].split(/\W+/).each do |l|
+ # @sub_request.add_substitute_source(User.find_by_login(l))
+ # end
+
+ #parse autocomplete
+ params[:list_of_logins].split(",").each do |l|
+ l = l.split("||")
+ @sub_request.add_substitute_source(l[0].constantize.find(l[1])) if l.length == 2
end
@@ -66,9 +72,13 @@ def update
#TODO This should probably be in a transaction, so that
#if the update fails all sub sources don't get deleted...
@sub_request.remove_all_substitute_sources
- params[:list_of_logins].split(/\W+/).each do |l|
- @sub_request.add_substitute_source(User.find_by_login(l))
+
+ #parse autocomplete
+ params[:list_of_logins].split(",").each do |l|
+ l = l.split("||")
+ @sub_request.add_substitute_source(l[0].constantize.find(l[1])) if l.length == 2
end
+
respond_to do |format|
if @sub_request.update_attributes(params[:sub_request])
flash[:notice] = 'SubRequest was successfully updated.'
@@ -9,6 +9,17 @@ def index
else
@users = @department.users.select{|user| user.is_active?(@department)}
end
+
+ #filter results if we are searching
+ if params[:search]
+ @search_result = []
+ @users.each do |user|
+ if user.login.downcase.include?(params[:search]) or user.name.downcase.include?(params[:search])
+ @search_result << user
+ end
+ end
+ @users = @search_result
+ end
end
def show
@@ -130,4 +141,46 @@ def mass_create
end
redirect_to department_users_path
end
+
+ def autocomplete
+ departments = current_user.departments
+ users = Department.find(params[:department_id]).users
+ roles = Department.find(params[:department_id]).roles
+
+ @list = []
+ users.each do |user|
+ if user.login.downcase.include?(params[:q]) or user.name.downcase.include?(params[:q])
+ #if (user.login and user.login.include?(params[:q])) or (user.name and user.name.include?(params[:q]))
+ @list << {:id => "User||#{user.id}", :name => "#{user.name} (#{user.login})"}
+ end
+ end
+ departments.each do |department|
+ if department.name.downcase.include?(params[:q])
+ #if (user.login and user.login.include?(params[:q])) or (user.name and user.name.include?(params[:q]))
+ @list << {:id => "Department||#{department.id}", :name => "Department: #{department.name}"}
+ end
+ end
+ roles.each do |role|
+ if role.name.downcase.include?(params[:q])
+ #if (user.login and user.login.include?(params[:q])) or (user.name and user.name.include?(params[:q]))
+ @list << {:id => "Role||#{role.id}", :name => "Role: #{role.name}"}
+ end
+ end
+
+ #@users = @users.collect{|user| :id => user.id, :name => user.name}
+ render :layout => false
+ end
+
+ def search
+ @all_users = Department.find(params[:department_id]).users
+ unless @all_users.nil?
+ @users = []
+ @all_users.each do |user|
+ if user.login.downcase.include?(params[:search]) or user.name.downcase.include?(params[:search])
+ #if (user.login and user.login.include?(params[:q])) or (user.name and user.name.include?(params[:q]))
+ @users << user
+ end
+ end
+ end
+ end
end
@@ -10,5 +10,34 @@ def link_toggle(id, name, speed = "medium")
link_to_function name, "$('##{id}').slideToggle('#{speed}')"
# link_to_function name, "Effect.toggle('#{id}', 'appear', { duration: 0.3 });"
end
+
+ def tokenized_users_autocomplete(object, field, id)
+ json_string = ""
+ unless object.nil?
+ object.send(field).each do |user_source|
+ json_string += "{name: '#{user_source.name}', id: '#{user_source.class}||#{user_source.id}'},\n"
+ end
+ end
+
+ '<script type="text/javascript">
+ $(document).ready(function() {
+ $("#'+id+'").tokenInput("'+autocomplete_department_users_path(current_department)+'", {
+ prePopulate: ['+json_string+'],
+ classes: {
+ tokenList: "token-input-list-facebook",
+ token: "token-input-token-facebook",
+ tokenDelete: "token-input-delete-token-facebook",
+ selectedToken: "token-input-selected-token-facebook",
+ highlightedToken: "token-input-highlighted-token-facebook",
+ dropdown: "token-input-dropdown-facebook",
+ dropdownItem: "token-input-dropdown-item-facebook",
+ dropdownItem2: "token-input-dropdown-item2-facebook",
+ selectedDropdownItem: "token-input-selected-dropdown-item-facebook",
+ inputToken: "token-input-input-token-facebook"
+ }
+ });
+ });
+ </script>' + text_field_tag(id)
+ end
end
View
@@ -89,6 +89,10 @@ def add_viewer_source(source)
def viewers
self.viewer_links.collect{|l| l.user_source.users}.flatten.uniq
end
+
+ def viewer_sources
+ self.viewer_links.collect{|l| l.user_source}
+ end
def remove_all_viewer_sources
UserSourceLink.delete_all(:user_sink_id => self.id)
View
@@ -10,3 +10,4 @@ def get_notices
all_notices.uniq
end
end
+
View
@@ -80,9 +80,9 @@ def self.search(search_string)
def permission_list
roles.collect { |r| r.permissions }.flatten
end
-
+
def current_shift
- self.shifts.select{|shift| shift.signed_in? and !shift.submitted?}
+ self.shifts.select{|shift| shift.signed_in? and !shift.submitted?}[0]
end
# check if a user can see locations and shifts under this loc group
@@ -4,7 +4,7 @@
<head>
<title><%= h(yield(:title) || 'Student Technology Collaborative') %></title>
<%= stylesheet_link_tag 'application', 'nav' %>
- <%= javascript_include_tag 'application' %>
+ <%= javascript_include_tag 'application', 'jrails', 'jquery' %>
<%= yield(:head) %>
</head>
<body>
@@ -1,22 +1,19 @@
<fieldset class="announcement", title= "<%= "Posted on #{announcement.start_time.to_date} at #{announcement.start_time.to_s(:am_pm)}" %>" >
<% if current_user.is_admin_of?(@department) %>
- <div class="right">
- <%= link_to '[x]', { :controller => 'notices', :action => 'destroy', :id => announcement },
- :confirm => "Are you sure you want to remove this announcement?",
- :method => :delete %>
- </div>
- <div class="grayright">
- <%= link_to 'Edit', edit_notice_path(announcement) %>
- </div>
+ <div class="right">
+ <%= link_to '[x]', { :controller => 'notices', :action => 'destroy', :id => announcement },
+ :confirm => "Are you sure you want to remove this announcement?",
+ :method => :delete %>
+ </div>
+ <div class="grayright">
+ <%= link_to 'Edit', edit_notice_path(announcement) %>
+ </div>
<% end %>
- <%= announcement.content %>
-<br />
-<div class="grayleft">
+ <%= announcement.content %> <br />
+
+ <div class="grayleft">
<%= "by #{(announcement.author.name )}" -%>
-</div>
- <div class="grayright">
- <%= announcement.display_for %>
</div>
- </fieldset>
+</fieldset>
@@ -1,32 +1,33 @@
+<% javascript 'jrails', 'jquery', 'jquery-ui', 'jquery.tokeninput' %>
+<% stylesheet 'tokeninput-facebook' %>
+
<fieldset>
<% form_for(@notice) do |f| %>
<%= f.error_messages %>
-
<% if current_user.is_admin_of?(@department) %>
- <p>
- Post as sticky? (start/end time preferences will be ignored)
- <%= f.check_box :is_sticky %>
- </p>
<p>
- Specify a start time<br />
- <%= f.datetime_select :start_time %>
- </p>
- <p>
- Specify an end time<br />
- <%= f.datetime_select :end_time %> <br /> or check here to make it indefinite:
-
- <%= check_box_tag :indefinite -%>
+ Post as sticky? (start/end time preferences will be ignored)
+ <%= f.check_box :is_sticky %>
+ </p>
+ <p>
+ Specify a start time<br />
+ <%= f.datetime_select :start_time %>
+ </p>
+ <p>
+ Specify an end time<br />
+ <%= f.datetime_select :end_time %> <br /> or check here to make it indefinite:
+ <%= check_box_tag :indefinite -%>
</p>
<% end %>
<p>
<%= f.label :content %><br />
<%= f.text_area :content %>
</p>
-
+<-- everything below should be invisible by default -->
<p>
<%= label_tag :for_users %><br />
- <%= text_field_tag :for_users %>
+ <%= tokenized_users_autocomplete(@notice, "viewer_sources", "for_users") %>
</p>
For locations: <br />
<% if current_user.is_admin_of?(@department) %>
@@ -39,12 +40,17 @@
<% for location in loc_group.locations do %>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
- <%= check_box_tag "for_locations[]", location.id, false, :disabled => false %><%= location.name %><br />
+ <% if current_user.current_shift %>
+ <%= check_box_tag "for_locations[]", location.id, current_user.current_shift.location == location, :disabled => false %>
+ <% else %>
+ <%= check_box_tag "for_locations[]", location.id, false, :disabled => false %>
+ <% end %>
+ <%= location.name %><br />
<% end %>
<% end %>
- </fieldset>
- <p>
- <%= f.submit 'Create/Edit' %>
- </p>
+</fieldset>
+<p>
+ <%= f.submit 'Create/Update' %>
+</p>
<% end %>
@@ -1,7 +1,7 @@
-<% stylesheet 'notice', 'message_center' %>
+<% stylesheet 'notice' %>
<% if notice.is_sticky %>
-<%= render :partial => 'notices/sticky', :collection => [notice] %>
+ <%= render :partial => 'notices/sticky', :collection => [notice] %>
<% else %>
-<%= render :partial => 'notices/announcement', :collection => [notice] %>
+ <%= render :partial => 'notices/announcement', :collection => [notice] %>
<% end %>
@@ -1,16 +1,16 @@
- <fieldset class="sticky", title= "<%= "Posted on #{sticky.start_time.to_date} at #{sticky.start_time.to_s(:am_pm)}" %>" >
- <div class="right">
- <%= link_to '[x]', { :controller => 'notices', :action => 'destroy', :id => sticky },
- :confirm => "Are you sure you want to remove this notice? It will be removed for all users and all locations.",
- :method => :delete %>
- </div>
- <%= sticky.content %>
- <br />
+<fieldset class="sticky", title= "<%= "Posted on #{sticky.start_time.to_date} at #{sticky.start_time.to_s(:am_pm)}" %>" >
+ <div class="right">
+ <%= link_to '[x]', { :controller => 'notices', :action => 'destroy', :id => sticky },
+ :confirm => "Are you sure you want to remove this notice? It will be removed for all users and all locations.",
+ :method => :delete %>
+ </div>
+ <%= sticky.content %>
+ <br />
<div class="grayleft">
- <%= "by #{(sticky.author.name )} #{distance_of_time_in_words(sticky.start_time, Time.now, true)} ago" %>
+ <%= "by #{sticky.author.name} #{distance_of_time_in_words(sticky.start_time, Time.now, true)} ago" %>
</div>
<div class="grayright">
<%= sticky.display_for %>
</div>
- </fieldset>
+</fieldset>
@@ -1,7 +1,7 @@
<h1 id="page_title"><%=h "Notices - " %><font size = -2><%= link_to 'Post a new notice', {:action => 'new'} %></font></h1>
<% unless current_user.notices.empty? %>
- <fieldset>
+ <fieldset class ="index">
<legend>For you</legend>
<%= render :partial => 'notice', :collection => current_user.notices if current_user.notices%>
</fieldset>
@@ -10,7 +10,7 @@
<% @department.locations.each do |loc| %>
<% unless loc.notices.empty? %>
- <fieldset>
+ <fieldset class ="index">
<legend><%= loc.name %></legend>
<%= render :partial => 'notice', :collection => loc.notices %>
</fieldset>
@@ -20,7 +20,7 @@
<% if current_user.is_admin_of?(@department) %>
<% unless Notice.inactive.empty? %>
-<fieldset>
+<fieldset class ="index">
<legend>Inactive Notices</legend>
<%= render :partial => 'notice', :collection => Notice.inactive %>
</fieldset>
@@ -1,3 +1,6 @@
+<% javascript 'jrails', 'jquery', 'jquery-ui', 'jquery.tokeninput' %>
+<% stylesheet 'tokeninput-facebook' %>
+
<% form_for (params[:id] ? @sub_request : [:shift, @sub_request]) do |f| %>
<%= f.error_messages %>
@@ -20,8 +23,8 @@
<%= f.datetime_select :end, :default => @sub_request.shift.end %>
</p>
<p>
- <%= label_tag "List of logins that can take sub" %><br />
- <%= text_field_tag :list_of_logins %>
+ <%= label_tag "People/groups eligible for this sub" %><br />
+ <%= tokenized_users_autocomplete(@sub_request, "user_sources", "list_of_logins") %>
</p>
<p>
<%= f.label :reason %><br />
@@ -0,0 +1 @@
+<%= @list.to_json %>
Oops, something went wrong.

0 comments on commit 3f61cb8

Please sign in to comment.