Permalink
Browse files

Merge branch 'master' of git@github.com:Smudge/newstc

  • Loading branch information...
2 parents 4e6cc6b + 3ee302d commit 5dc8a2d59cdfa63b325abfb8c6b22ca37c106f69 @rofreg rofreg committed Jul 2, 2009
@@ -47,7 +47,7 @@ def current_user
# current_department is suitable to those methods that skip_before_filter load_department
def current_department
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
@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?
@@ -1,5 +1,6 @@
class NoticesController < ApplicationController
-
+ layout "application"
+# layout "new_notice", :only => :new
before_filter :fetch_loc_groups
def index
@@ -16,22 +17,24 @@ def show
def new
@notice = Notice.new
+ render :action => "new", :layout => 'new_notice'
end
def edit
@notice = Notice.find(params[:id])
end
def create
+ params.to_yaml
@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.department = @department
@notice.start_time = Time.now if @notice.is_sticky
@notice.end_time = nil if params[:indefinite] || @notice.is_sticky
if @notice.save
set_sources
- if @notice.save
+ if @notice.saveNo
flash[:notice] = 'Notice was successfully created.'
redirect_to @notice
else
@@ -74,7 +77,7 @@ def destroy
end
end
- protected
+ protected
def fetch_loc_groups
@loc_groups = @department.loc_groups.all
@@ -90,7 +93,7 @@ def set_sources(update = false)
end
@notice.user_sources << @department if params[:department_wide_viewers] && !@notice.is_sticky
@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]
params[:for_locations].each do |loc|
@notice.location_sources << Location.find_by_id(loc)
@@ -19,7 +19,7 @@ def early_late_info(start)
def return_to_shift_report_if_needed
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
@@ -1,16 +1,20 @@
module NoticesHelper
- def show_notice_archive
- if params[:show_inactive].nil?
- link_to "Show Inactive Notices", :show_inactive => true
+
+ def locations_check(location)
+ @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
- link_to "Hide Inactive Notices", notices_path
- unless Notice.inactive.empty?
- concat('<fieldset class ="index">')
- concat('<legend>Inactive Notices</legend>')
- render(:partial => 'notice', :collection => Notice.inactive)
- concat("<fieldset>")
- end
+ @notice.departments.loc_groups.include?(loc_group)
end
end
+
+ def dept_check
+ @notice.departments.include?(current_department)
+ end
+
end
View
@@ -27,7 +27,7 @@ def locations
[self]
end
- def notices
+ def find_notices
Notice.active.select {|n| n.display_locations.include?(self)}
end
View
@@ -104,8 +104,8 @@ def can_signup?(loc_group)
end
# check for admin permission given a dept, location group, or location
- def is_admin_of?(thing)
- self.is_superuser? || (permission_list.include?(thing.admin_permission) && self.is_active?(thing))
+ def is_admin_of?(dept)
+ self.is_superuser? || (permission_list.include?(dept.admin_permission) && self.is_active?(dept))
end
# see list of superusers defined in config/initializers/superuser_list.rb
@@ -174,3 +174,4 @@ def create_user_config
UserConfig.new({:user_id => self.id}).save
end
end
+
@@ -11,7 +11,6 @@
<fieldset class = "index">
<legend>Current shifts</legend>
<%= return_to_shift_report_if_needed %>
- <br/>
<% if current_user.punch_clock %>
<%= link_to "Clock out?", current_user.punch_clock,
:confirm => "Are you sure",
@@ -11,7 +11,7 @@
<h4 id="subtitle"><%=h yield(:subtitle) %></h4>
<%- end -%>
<!-- Main Content -->
- <%= yield(:body) || yield %>
+ <%= yield(:body) || yield %>
</div>
<div id="pageAnchor">
<a href="#top_of_page">
@@ -29,3 +29,4 @@
<div id="pageboxBottom"/> <!-- do not remove this -->
</body>
</html>
+
@@ -6,7 +6,7 @@
<li class="<%= tab('departments') %>"><%= link_to "Departments", departments_path %></li>
<% end -%>
<% 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>
<% end -%>
<% if current_user.departments.include?(current_department) || current_user.is_superuser? %>
@@ -1,7 +1,4 @@
-<% javascript 'jrails', 'jquery', 'jquery-ui', 'jquery.tokeninput', 'thickbox-compressed' %>
-<% stylesheet 'tokeninput-facebook' %>
-
-<fieldset>
+<fieldset class = "index">
<% form_for(@notice) do |f| %>
<%= f.error_messages %>
<% if current_user.is_admin_of?(@department) %>
@@ -32,15 +29,15 @@
<%= tokenized_users_autocomplete(@notice, "user_sources", "for_users") %>
<p>
For locations: <br />
- <% if current_user.is_admin_of?(@department) %>
- <%= check_box_tag :department_wide_locations %><%= @department.name %> (all locations)<br />
+ <% if current_user.is_admin_of?(current_department) %>
+ <%= check_box_tag :department_wide_locations, 1, dept_check, :disabled => dept_check %><%= current_department.name %> (all locations)<br />
<% end %>
<% for loc_group in @loc_groups do %>
&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 %>
<% 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 %>
<%= check_box_tag "for_locations[]", location.id, false, :disabled => false %>
<% end %>
@@ -54,14 +51,10 @@
</fieldset>
<p>
- <%= f.submit 'Create/Update' %>
+ <%= f.submit 'Save',:onclick => 'self.parent.tb_remove()' %>
</p>
<% end %>
-<!--
- document.observe('dom:loaded',function(){ $('checkbox_div').hide(); });
- document.observe('dom:loaded',function(){ $('pref_link').show(); });
--->
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){$("#advanced").hide();})
@@ -1,28 +1,38 @@
<% stylesheet 'thickbox' %>
<% 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? %>
<fieldset class ="index">
<legend>For you</legend>
<%= render :partial => 'for_you' %>
</fieldset>
<br />
<% end %>
-
-
-<% @department.locations.each do |loc| %>
- <% unless loc.notices.empty? %>
+</div>
+<div id = "location_notices">
+<% current_department.locations.each do |loc| %>
+ <% unless loc.find_notices.empty? %>
<fieldset class ="index">
<legend><%= loc.name %></legend>
- <%= render :partial => 'notice', :collection => loc.notices %>
+ <%= render :partial => 'notice', :collection => loc.find_notices%>
</fieldset>
<br/>
<% end %>
<% end %>
+</div>
<% if current_user.is_admin_of?(@department) %>
<%= link_to 'Notice archive', 'notices/archive' %>
<% 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>
@@ -32,10 +32,17 @@
<b>People who see this:</b> <br />
<%= (@notice.viewers.collect {|v| v.name}).join("<br />")%>
</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>
<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>
@@ -1,6 +1,7 @@
fieldset.index {
width: 75%;
padding: 5px;
+ background-color:#DDDDFF
}
fieldset.sticky {

0 comments on commit 5dc8a2d

Please sign in to comment.