Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:Smudge/newstc
Browse files Browse the repository at this point in the history
  • Loading branch information
rofreg committed Jul 2, 2009
2 parents 4e6cc6b + 3ee302d commit 5dc8a2d
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 45 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Expand Up @@ -47,7 +47,7 @@ def current_user
# current_department is suitable to those methods that skip_before_filter load_department # current_department is suitable to those methods that skip_before_filter load_department
def current_department def current_department
if params[:department_id] or session[:department_id] if params[:department_id] or session[:department_id]
@department ||= Department.find(params[:department_id] || session[:department_id]) @department ||= Department.find(params[:department_id] || session[:department_id])
elsif current_user and current_user.departments elsif current_user and current_user.departments
@department = current_user.user_config.default_dept ? Department.find(current_user.user_config.default_dept) : current_user.departments[0] @department = current_user.user_config.default_dept ? Department.find(current_user.user_config.default_dept) : current_user.departments[0]
elsif current_user and current_user.is_superuser? elsif current_user and current_user.is_superuser?
Expand Down
13 changes: 8 additions & 5 deletions app/controllers/notices_controller.rb
@@ -1,5 +1,6 @@
class NoticesController < ApplicationController class NoticesController < ApplicationController

layout "application"
# layout "new_notice", :only => :new
before_filter :fetch_loc_groups before_filter :fetch_loc_groups


def index def index
Expand All @@ -16,22 +17,24 @@ def show


def new def new
@notice = Notice.new @notice = Notice.new
render :action => "new", :layout => 'new_notice'
end end


def edit def edit
@notice = Notice.find(params[:id]) @notice = Notice.find(params[:id])
end end


def create def create
params.to_yaml
@notice = Notice.new(params[:notice]) @notice = Notice.new(params[:notice])
@notice.is_sticky = true unless current_user.is_admin_of?(@department) @notice.is_sticky = true unless current_user.is_admin_of?(current_department)
@notice.author = current_user @notice.author = current_user
@notice.department = @department @notice.department = @department
@notice.start_time = Time.now if @notice.is_sticky @notice.start_time = Time.now if @notice.is_sticky
@notice.end_time = nil if params[:indefinite] || @notice.is_sticky @notice.end_time = nil if params[:indefinite] || @notice.is_sticky
if @notice.save if @notice.save
set_sources set_sources
if @notice.save if @notice.saveNo
flash[:notice] = 'Notice was successfully created.' flash[:notice] = 'Notice was successfully created.'
redirect_to @notice redirect_to @notice
else else
Expand Down Expand Up @@ -74,7 +77,7 @@ def destroy
end end
end end


protected protected


def fetch_loc_groups def fetch_loc_groups
@loc_groups = @department.loc_groups.all @loc_groups = @department.loc_groups.all
Expand All @@ -90,7 +93,7 @@ def set_sources(update = false)
end end
@notice.user_sources << @department if params[:department_wide_viewers] && !@notice.is_sticky @notice.user_sources << @department if params[:department_wide_viewers] && !@notice.is_sticky
@notice.location_sources = [] if update @notice.location_sources = [] if update
@notice.location_sources << @department if params[:department_wide_locations] && current_user.is_admin_of?(@department) @notice.departments << @department if params[:department_wide_locations] && current_user.is_admin_of?(@department)
if params[:for_locations] if params[:for_locations]
params[:for_locations].each do |loc| params[:for_locations].each do |loc|
@notice.location_sources << Location.find_by_id(loc) @notice.location_sources << Location.find_by_id(loc)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Expand Up @@ -19,7 +19,7 @@ def early_late_info(start)


def return_to_shift_report_if_needed def return_to_shift_report_if_needed
if current_user.current_shift if current_user.current_shift
link_to "Return to your current report", {:controller => "report", :action => "index"} link_to "Return to your current report", {:controller => "report", :action => "index"} + concat("<br/>")
end end
end end


Expand Down
24 changes: 14 additions & 10 deletions app/helpers/notices_helper.rb
@@ -1,16 +1,20 @@
module NoticesHelper module NoticesHelper
def show_notice_archive
if params[:show_inactive].nil? def locations_check(location)
link_to "Show Inactive Notices", :show_inactive => true @notice.departments.locations.include?(location) or current_user.current_shift.location == location or @notice.locations.include?(location) or loc_group.locations.include?(location)
end

def loc_group_check(loc_group)
if @notice.departments.empty?
@notice.loc_groups.include?(loc_group)
else else
link_to "Hide Inactive Notices", notices_path @notice.departments.loc_groups.include?(loc_group)
unless Notice.inactive.empty?
concat('<fieldset class ="index">')
concat('<legend>Inactive Notices</legend>')
render(:partial => 'notice', :collection => Notice.inactive)
concat("<fieldset>")
end
end end
end end

def dept_check
@notice.departments.include?(current_department)
end

end end


2 changes: 1 addition & 1 deletion app/models/location.rb
Expand Up @@ -27,7 +27,7 @@ def locations
[self] [self]
end end


def notices def find_notices
Notice.active.select {|n| n.display_locations.include?(self)} Notice.active.select {|n| n.display_locations.include?(self)}
end end


Expand Down
5 changes: 3 additions & 2 deletions app/models/user.rb
Expand Up @@ -104,8 +104,8 @@ def can_signup?(loc_group)
end end


# check for admin permission given a dept, location group, or location # check for admin permission given a dept, location group, or location
def is_admin_of?(thing) def is_admin_of?(dept)
self.is_superuser? || (permission_list.include?(thing.admin_permission) && self.is_active?(thing)) self.is_superuser? || (permission_list.include?(dept.admin_permission) && self.is_active?(dept))
end end


# see list of superusers defined in config/initializers/superuser_list.rb # see list of superusers defined in config/initializers/superuser_list.rb
Expand Down Expand Up @@ -174,3 +174,4 @@ def create_user_config
UserConfig.new({:user_id => self.id}).save UserConfig.new({:user_id => self.id}).save
end end
end end

1 change: 0 additions & 1 deletion app/views/dashboard/index.html.erb
Expand Up @@ -11,7 +11,6 @@
<fieldset class = "index"> <fieldset class = "index">
<legend>Current shifts</legend> <legend>Current shifts</legend>
<%= return_to_shift_report_if_needed %> <%= return_to_shift_report_if_needed %>
<br/>
<% if current_user.punch_clock %> <% if current_user.punch_clock %>
<%= link_to "Clock out?", current_user.punch_clock, <%= link_to "Clock out?", current_user.punch_clock,
:confirm => "Are you sure", :confirm => "Are you sure",
Expand Down
3 changes: 2 additions & 1 deletion app/views/layouts/application.html.erb
Expand Up @@ -11,7 +11,7 @@
<h4 id="subtitle"><%=h yield(:subtitle) %></h4> <h4 id="subtitle"><%=h yield(:subtitle) %></h4>
<%- end -%> <%- end -%>
<!-- Main Content --> <!-- Main Content -->
<%= yield(:body) || yield %> <%= yield(:body) || yield %>
</div> </div>
<div id="pageAnchor"> <div id="pageAnchor">
<a href="#top_of_page"> <a href="#top_of_page">
Expand All @@ -29,3 +29,4 @@
<div id="pageboxBottom"/> <!-- do not remove this --> <div id="pageboxBottom"/> <!-- do not remove this -->
</body> </body>
</html> </html>

2 changes: 1 addition & 1 deletion app/views/layouts/include/_nav.html.erb
Expand Up @@ -6,7 +6,7 @@
<li class="<%= tab('departments') %>"><%= link_to "Departments", departments_path %></li> <li class="<%= tab('departments') %>"><%= link_to "Departments", departments_path %></li>
<% end -%> <% end -%>
<% if !current_user.new_record? && !current_department.new_record? %> <% if !current_user.new_record? && !current_department.new_record? %>
<% if (current_user.is_admin_of?(current_department)) -%> <% if (current_user.is_admin_of?(@department)) -%>
<li class="<%= tab('users') %>"><%= link_to "Users", department_users_path(current_department) %></li> <li class="<%= tab('users') %>"><%= link_to "Users", department_users_path(current_department) %></li>
<% end -%> <% end -%>
<% if current_user.departments.include?(current_department) || current_user.is_superuser? %> <% if current_user.departments.include?(current_department) || current_user.is_superuser? %>
Expand Down
19 changes: 6 additions & 13 deletions app/views/notices/_form.html.erb
@@ -1,7 +1,4 @@
<% javascript 'jrails', 'jquery', 'jquery-ui', 'jquery.tokeninput', 'thickbox-compressed' %> <fieldset class = "index">
<% stylesheet 'tokeninput-facebook' %>

<fieldset>
<% form_for(@notice) do |f| %> <% form_for(@notice) do |f| %>
<%= f.error_messages %> <%= f.error_messages %>
<% if current_user.is_admin_of?(@department) %> <% if current_user.is_admin_of?(@department) %>
Expand Down Expand Up @@ -32,15 +29,15 @@
<%= tokenized_users_autocomplete(@notice, "user_sources", "for_users") %> <%= tokenized_users_autocomplete(@notice, "user_sources", "for_users") %>
<p> <p>
For locations: <br /> For locations: <br />
<% if current_user.is_admin_of?(@department) %> <% if current_user.is_admin_of?(current_department) %>
<%= check_box_tag :department_wide_locations %><%= @department.name %> (all locations)<br /> <%= check_box_tag :department_wide_locations, 1, dept_check, :disabled => dept_check %><%= current_department.name %> (all locations)<br />
<% end %> <% end %>
<% for loc_group in @loc_groups do %> <% for loc_group in @loc_groups do %>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
<%= check_box_tag "for_location_groups[]", loc_group.id, false, :disabled => false %><%= loc_group.name %>: <%= check_box_tag "for_location_groups[]", loc_group.id, loc_group_check(loc_group), :disabled => loc_group_check(loc_group)%><%= loc_group.name %>:
<% for location in loc_group.locations do %> <% for location in loc_group.locations do %>
<% if current_user.current_shift %> <% if current_user.current_shift %>
<%= check_box_tag "for_locations[]", location.id, current_user.current_shift.location == location, :disabled => false %> <%= check_box_tag "for_locations[]", location.id, locations_check(location), :disabled => locations_check(location) %>
<% else %> <% else %>
<%= check_box_tag "for_locations[]", location.id, false, :disabled => false %> <%= check_box_tag "for_locations[]", location.id, false, :disabled => false %>
<% end %> <% end %>
Expand All @@ -54,14 +51,10 @@
</fieldset> </fieldset>


<p> <p>
<%= f.submit 'Create/Update' %> <%= f.submit 'Save',:onclick => 'self.parent.tb_remove()' %>
</p> </p>


<% end %> <% end %>
<!--
document.observe('dom:loaded',function(){ $('checkbox_div').hide(); });
document.observe('dom:loaded',function(){ $('pref_link').show(); });
-->


<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
$(document).ready(function(){$("#advanced").hide();}) $(document).ready(function(){$("#advanced").hide();})
Expand Down
24 changes: 17 additions & 7 deletions app/views/notices/index.html.erb
@@ -1,28 +1,38 @@
<% stylesheet 'thickbox' %> <% stylesheet 'thickbox' %>
<% javascript 'jrails', 'jquery', 'jquery-ui', 'thickbox-compressed' %> <% javascript 'jrails', 'jquery', 'jquery-ui', 'thickbox-compressed' %>


<h1 id="page_title"><%=h "Notices - " %><font size = -2><%= link_to 'Post a new notice', new_notice_path, :class => "thickbox" %></font></h1> <h1 id="page_title">

Notices -
<font size = -2>
<%= link_to 'Post a new notice', {:action => 'new', :TB_iframe => true}, :class => "thickbox" %>
</font>
</h1>
<div id = "for_you">
<% unless current_user.notices.empty? %> <% unless current_user.notices.empty? %>
<fieldset class ="index"> <fieldset class ="index">
<legend>For you</legend> <legend>For you</legend>
<%= render :partial => 'for_you' %> <%= render :partial => 'for_you' %>
</fieldset> </fieldset>
<br /> <br />
<% end %> <% end %>
</div>
<div id = "location_notices">
<% @department.locations.each do |loc| %> <% current_department.locations.each do |loc| %>
<% unless loc.notices.empty? %> <% unless loc.find_notices.empty? %>
<fieldset class ="index"> <fieldset class ="index">
<legend><%= loc.name %></legend> <legend><%= loc.name %></legend>
<%= render :partial => 'notice', :collection => loc.notices %> <%= render :partial => 'notice', :collection => loc.find_notices%>
</fieldset> </fieldset>
<br/> <br/>
<% end %> <% end %>
<% end %> <% end %>
</div>


<% if current_user.is_admin_of?(@department) %> <% if current_user.is_admin_of?(@department) %>
<%= link_to 'Notice archive', 'notices/archive' %> <%= link_to 'Notice archive', 'notices/archive' %>
<% end %> <% end %>
<script type="text/javascript" charset="utf-8">
page.replace_html("for_you", :partial => "for_you" );
page.replace_html("location_notices", :partial => "notice", :collection => "loc.notices" );
</script>


11 changes: 9 additions & 2 deletions app/views/notices/show.html.erb
Expand Up @@ -32,10 +32,17 @@
<b>People who see this:</b> <br /> <b>People who see this:</b> <br />
<%= (@notice.viewers.collect {|v| v.name}).join("<br />")%> <%= (@notice.viewers.collect {|v| v.name}).join("<br />")%>
</p> </p>

<p>
<b>Display in these departments:</b> <br />
<%= (@notice.departments.collect {|d| d.name}).join("<br />") %>
</p>
<p>
<b>Display in these location groups:</b> <br />
<%= (@notice.loc_groups.collect {|lg| lg.name}).join("<br />") %>
</p>
<p> <p>
<b>Display in these locations:</b> <br /> <b>Display in these locations:</b> <br />
<%= (@notice.display_locations.collect {|v| v.name}).join("<br />") %> <%= (@notice.display_locations.collect {|l| l.name}).join("<br />") %>
</p> </p>




Expand Down
1 change: 1 addition & 0 deletions public/stylesheets/notice.css
@@ -1,6 +1,7 @@
fieldset.index { fieldset.index {
width: 75%; width: 75%;
padding: 5px; padding: 5px;
background-color:#DDDDFF
} }


fieldset.sticky { fieldset.sticky {
Expand Down

0 comments on commit 5dc8a2d

Please sign in to comment.