Skip to content

Commit

Permalink
......
Browse files Browse the repository at this point in the history
  • Loading branch information
universac committed Jun 28, 2010
1 parent fe21814 commit ef44c45
Show file tree
Hide file tree
Showing 980 changed files with 928 additions and 392 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified README
100644 → 100755
Empty file.
Empty file modified Rakefile
100644 → 100755
Empty file.
Empty file modified app/controllers/accounts_controller.rb
100644 → 100755
Empty file.
Empty file modified app/controllers/admin/accounts_controller.rb
100644 → 100755
Empty file.
Empty file modified app/controllers/admin/educatees_controller.rb
100644 → 100755
Empty file.
Empty file modified app/controllers/admin/educators_controller.rb
100644 → 100755
Empty file.
Empty file modified app/controllers/admin/elements_controller.rb
100644 → 100755
Empty file.
Empty file modified app/controllers/admin/operators_controller.rb
100644 → 100755
Empty file.
Empty file modified app/controllers/admin/pages_controller.rb
100644 → 100755
Empty file.
Empty file modified app/controllers/admin/profiles_controller.rb
100644 → 100755
Empty file.
Empty file modified app/controllers/admin/system_configs_controller.rb
100644 → 100755
Empty file.
Empty file modified app/controllers/admin/typus_users_controller.rb
100644 → 100755
Empty file.
Empty file modified app/controllers/admin/valeurs_controller.rb
100644 → 100755
Empty file.
Empty file modified app/controllers/application_controller.rb
100644 → 100755
Empty file.
Empty file modified app/controllers/educatee/dashboards_controller.rb
100644 → 100755
Empty file.
91 changes: 78 additions & 13 deletions app/controllers/educatee/profiles_controller.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
require 'prawn/core'
Mime::Type.register 'application/pdf', :pdf

class Educatee::ProfilesController < ApplicationController
before_filter :educatee_required
before_filter :role_required
before_filter :find_profile, :except => [:index]

def index
end

def show
@profile = current_educatee.profile
respond_to do |format|
format.html
format.pdf do

template = File.join(RAILS_ROOT, "public", SystemConfig.profile_pdf_template_file)

pdf = Prawn::Document.new(:template => template)

font_zh = File.join(RAILS_ROOT, "simhei.ttf")
font_ja = File.join(RAILS_ROOT, "ipag.ttf")

Element.all.each do |element|
script = element.prawn_output_script
value = @profile.send(element.key)
eval(script) if script && value
end

send_data pdf.render

end
end
end

def edit
begin
@profile = current_educatee.profile

begin
@page = Page.find(params[:page])
@submit_path = educatee_profile_path
@elements = @page.elements
Expand All @@ -18,7 +43,6 @@ def edit
end

def submit
@profile = current_educatee.profile
if @profile.submit && @profile.save
flash[:notice] = "Your profile was submitted. We will confirm it."
else
Expand All @@ -29,24 +53,65 @@ def submit


def update
@profile = current_educatee.profile

@page = Page.find(params[:page_id])
@submit_path = educatee_profile_path
@elements = @page.elements

safe = multi_check_safe(params[:profile], params)
safe = multi_attribute_as_date(safe)

safe.merge!(:current_page_id => @page.id)

if @profile.update_attributes(safe)
flash[:notice] = "Profile updated."
redirect_to educatee_dashboard_path
else
logger.debug @profile.errors.inspect
flash[:errors] = "There are errors."
render :action => "edit"
end

end

def print


def freeze
if @profile.freeze && @profile.save
flash[:notice] = "This Profile was frozen. The educatee can not edit this profile any more."
else
flash[:error] = "We can not freeze this profile."
end

redirect_to :back
end

def unfreeze
if @profile.unfreeze && @profile.save
flash[:notice] = "This Profile was unfrozen. The educatee can edit this profile now."
else
flash[:error] = "We can not unfreeze this profile."
end

redirect_to :back
end


def archive
if @profile.archive && @profile.save
flash[:notice] = "This Profile was archived."
else
flash[:error] = "We can not archive this profile."
end

redirect_to :back
end

protected

def role_required
educatee_required
end

private
def find_profile
@profile = current_educatee.profile
end

def multi_check_safe(profile, params)
safe = {}
Expand Down
Empty file modified app/controllers/educator/dashboards_controller.rb
100644 → 100755
Empty file.
Empty file modified app/controllers/educator/denies_controller.rb
100644 → 100755
Empty file.
Empty file modified app/controllers/educator/educators_controller.rb
100644 → 100755
Empty file.
83 changes: 24 additions & 59 deletions app/controllers/educator/profiles_controller.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,43 +1,17 @@
require 'prawn/core'
Mime::Type.register 'application/pdf', :pdf

class Educator::ProfilesController < ApplicationController
before_filter :educator_required
class Educator::ProfilesController < Educatee::ProfilesController




def index
@profiles = Profile.all
end

def show
@profile = Profile.find(params[:id])

respond_to do |format|
format.html
format.pdf do

template = File.join(RAILS_ROOT, "public", SystemConfig.profile_pdf_template_file)

pdf = Prawn::Document.new(:template => template)

font_zh = File.join(RAILS_ROOT, "simhei.ttf")
font_ja = File.join(RAILS_ROOT, "ipag.ttf")

Element.all.each do |element|
script = element.prawn_output_script
value = @profile.send(element.key)
eval(script) if script && value
end

send_data pdf.render

end
end

end

def edit
begin
@profile = Profile.find(params[:id])
@page = Page.find(params[:page])
@submit_path = educator_profile_path(@profile)
@elements = @page.elements
Expand All @@ -46,40 +20,31 @@ def edit
end
end

def print
@profile = Profile.find(params[:id])

template = File.join(RAILS_ROOT, "public", SystemConfig.profile_pdf_template_file)
outputfile = "profile_#{@profile.id}"

pdf = Prawn::Document.new(:template => template)
pdf.fill_color "ff0000"
pdf.text "Baby, comes to me"
pdf.render_file outputfile
send_data pdf.render
end
def update
@page = Page.find(params[:page_id])
@submit_path = educatee_profile_path
@elements = @page.elements

def update
end
safe = multi_check_safe(params[:profile], params)
safe = multi_attribute_as_date(safe)
safe.merge!(:current_page_id => @page.id)

def accept
@profile = Profile.find(params[:id])
if @profile.accept && @profile.save
flash[:notice] = "The profile was acceptd."
if @profile.update_attributes(safe)
flash[:notice] = "Profile updated."
redirect_to educator_profile_path(@profile) + "#page_#{@page.id}"
else
flash[:error] = "Can not accept this profile."
flash[:errors] = "There are errors."
render :action => "edit"
end
redirect_to :back

end

def deny
@profile = Profile.find(params[:id])
if @profile.deny && @profile.save
flash[:notice] = "The profile was denied."
else
flash[:error] = "Can not deny this profile."
protected
def role_required
educator_required
end
redirect_to :back
end


def find_profile
@profile = Profile.find(params[:id])
end
end
Empty file modified app/controllers/sessions_controller.rb
100644 → 100755
Empty file.
Empty file modified app/helpers/accounts_helper.rb
100644 → 100755
Empty file.
Empty file modified app/helpers/admin/educators_helper.rb
100644 → 100755
Empty file.
Empty file modified app/helpers/admin/operators_helper.rb
100644 → 100755
Empty file.
Empty file modified app/helpers/admin/pages_helper.rb
100644 → 100755
Empty file.
Empty file modified app/helpers/application_helper.rb
100644 → 100755
Empty file.
Empty file modified app/helpers/educatee/dashboards_helper.rb
100644 → 100755
Empty file.
Empty file modified app/helpers/educatee/profiles_helper.rb
100644 → 100755
Empty file.
Empty file modified app/helpers/educator/dashboards_helper.rb
100644 → 100755
Empty file.
Empty file modified app/helpers/educator/denies_helper.rb
100644 → 100755
Empty file.
Empty file modified app/helpers/educator/educators_helper.rb
100644 → 100755
Empty file.
21 changes: 15 additions & 6 deletions app/helpers/educator/profiles_helper.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,25 @@ def profile_message_for_educator(profile)
end
end

def profile_avoid_actions(profile)
def profile_valid_actions(profile)

returning(Array.new) do |html|

#if current_educator && profile.can_edit_by_educator
# html << link_to("Edit this profile", edit_educator_profile_path(@profile), :class => "button right")
#end

returning(Array.new) do |html|
@profile.aasm_events_for_current_state.each do |event|

case event
when :accept
html << link_to('Accept', accept_educator_profile_path(@profile), :method => :post, :class => "button")
when :deny
html << link_to('Deny', educator_profile_deny_path(@profile), :class => "button")
when :freeze
html << link_to("Freeze", freeze_educator_profile_path(@profile), :method => :post, :class => "button")
when :unfreeze
html << link_to("Unfreeze", unfreeze_educator_profile_path(@profile), :method => :post, :class => "button")
when :archive
html << link_to("Archive", archive_educator_profile_path(@profile), :method => :post, :class => "button")
end

end
end
end
Expand Down
Empty file modified app/helpers/sessions_helper.rb
100644 → 100755
Empty file.
Empty file modified app/models/account.rb
100644 → 100755
Empty file.
Empty file modified app/models/account_mailer.rb
100644 → 100755
Empty file.
Empty file modified app/models/account_observer.rb
100644 → 100755
Empty file.
Empty file modified app/models/deny.rb
100644 → 100755
Empty file.
Empty file modified app/models/educatee.rb
100644 → 100755
Empty file.
Empty file modified app/models/educator.rb
100644 → 100755
Empty file.
6 changes: 6 additions & 0 deletions app/models/element.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class Element < ActiveRecord::Base
belongs_to :page

has_many :valeurs, :dependent => :destroy

validates_uniqueness_of :key
validates_presence_of :key

Expand All @@ -10,4 +12,8 @@ class Element < ActiveRecord::Base


named_scope :display_columns, { :conditions => ["display_index > 0 or is_title = ?", true], :order => "is_title desc, display_index" }

def typus_name
self.key
end
end
Empty file modified app/models/operator.rb
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions app/models/page.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
class Page < ActiveRecord::Base
has_many :elements, :dependent => :destroy

def typus_name
self.title
end

end
67 changes: 53 additions & 14 deletions app/models/profile.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,54 @@ class Profile < ActiveRecord::Base

aasm_column :status
aasm_initial_state :new

aasm_state :new
aasm_state :submitted
aasm_state :accepted
aasm_state :denied
aasm_state :editing
#aasm_state :submitted
aasm_state :frozen
aasm_state :archived

#aasm_state :accepted
#aasm_state :denied

aasm_event :start_edit do
transitions :to => :editing, :from => [:new]
end

#aasm_event :submit do
# transitions :to => :submitted, :from => [:new, :editing], :guard => :profile_check
#end

aasm_event :submit do
transitions :to => :submitted, :from => [:new, :editing], :guard => :profile_check
aasm_event :freeze do
transitions :to => :frozen, :from => [:new, :editing]
end

aasm_event :accept do
transitions :to => :accepted, :from => [:submitted]
aasm_event :unfreeze do
transitions :to => :editing, :from => [:frozen]
end

aasm_event :deny do
transitions :to => :denied, :from => [:submitted]
aasm_event :archive do
transitions :to => :archived, :from => [:frozen]
end


#aasm_event :accept do
# transitions :to => :accepted, :from => [:submitted]
#end

#aasm_event :deny do
# transitions :to => :denied, :from => [:submitted]
#end

def can_edit_by_educatee
[:new, :denied].include?(self.aasm_current_state)
end

def can_edit_by_educator
[:submitted].include?(self.aasm_current_state)
end

def profile_check
#[:new, :editing, :frozen ].include?(self.aasm_current_state)
true
end


def title
title_element = Element.find_by_is_title(true)
return "(No title element defined)" if title_element.nil?
Expand All @@ -49,6 +67,27 @@ def title
(title.nil? || title.blank?) ? "(No title)" : title
end


attr_accessor :current_page_id

def validate_on_update
return if current_page_id.nil? or current_page_id.blank?
@page = Page.find(current_page_id)
return if @page.nil?

@page.elements.each do |element|
value = self.send(element.key)
profile = self
script = element.validation_script
errors = self.errors

eval(script) if script && profile
end
end




Element.find(:all).each do |element|
attr_accessor element.key.intern
end
Expand Down
Empty file modified app/models/system_config.rb
100644 → 100755
Empty file.
Empty file modified app/models/valeur.rb
100644 → 100755
Empty file.
Empty file modified app/stylesheets/ie.scss
100644 → 100755
Empty file.
Empty file modified app/stylesheets/partials/_base.sass.rm
100644 → 100755
Empty file.
Empty file modified app/stylesheets/partials/_base.scss
100644 → 100755
Empty file.
Empty file modified app/stylesheets/print.scss
100644 → 100755
Empty file.
Empty file modified app/stylesheets/screen.scss
100644 → 100755
Empty file.
Loading

0 comments on commit ef44c45

Please sign in to comment.