Skip to content
Permalink
Browse files

changed all calls from statement node parent to parent node

  • Loading branch information...
HoneyryderChuck committed Apr 27, 2011
1 parent ed77135 commit 6249669e1efed5c5d5f3bad8f07e87784d9ded0b
@@ -16,7 +16,7 @@ module EchoableModule
def echo
begin
return if !@statement_node.echoable?
if !@statement_node.incorporable? or @statement_node.parent.supported?(current_user)
if !@statement_node.incorporable? or @statement_node.parent_node.supported?(current_user)
@statement_node.supported!(current_user)
set_statement_info('discuss.statements.statement_supported')
respond_to_js :redirect_to => statement_node_url(@statement_node), :template_js => 'statements/echo'
@@ -441,7 +441,7 @@ def destroy
@statement_node.destroy
set_statement_info("discuss.messages.deleted")
flash_info
redirect_to(@statement_node.parent ? statement_node_url(@statement_node.parent) : discuss_search_url)
redirect_to(@statement_node.parent_node ? statement_node_url(@statement_node.parent_node) : discuss_search_url)
rescue Exception => e
log_message_error(e, "Error deleting statement node '#{@statement_node.id}'.") do
flash_error and redirect_to_statement
@@ -654,10 +654,10 @@ def redirect_if_approved_or_incorporated
end
respond_to do |format|
flash_info
format.html { redirect_to statement_node_url @statement_node.parent }
format.html { redirect_to statement_node_url @statement_node.parent_node }
format.js do
render :update do |page|
page.redirect_to statement_node_url @statement_node.parent
page.redirect_to statement_node_url @statement_node.parent_node
end
end
end
@@ -721,8 +721,8 @@ def parent
# @bids(String) : breadcrumb keycodes separated by comma
#
def set_parent_breadcrumb
return if @statement_node.parent.nil?
parent_node = @statement_node.parent
return if @statement_node.parent_node.nil?
parent_node = @statement_node.parent_node
statement_document = search_statement_documents(:statement_ids => [parent_node.statement_id])[parent_node.statement_id] ||
parent_node.document_in_original_language
#[id, classes, url, title, label, over]
@@ -911,7 +911,7 @@ def search_statement_documents(opts={})
# @previous_type(String) : type of breadcrumb
#
def load_origin_statement
@previous_node = @statement_node.parent
@previous_node = @statement_node.parent_node
@previous_type = case @statement_node.class.name
when "FollowUpQuestion" then "fq"
end
@@ -4,7 +4,7 @@ module EchoableModuleHelper
# (The support ratio is the calculated ratio for a statement_node,
# representing and visualizing the agreement a statement_node has found within the community.)
def supporter_ratio_bar(statement_node,
previous_statement = statement_node.parent,
previous_statement = statement_node.parent_node,
type = statement_node.class.name)
# TODO:How to spare calculating this label two times (see next method, they're almost always sequencially triggered)
label = supporters_number(statement_node)
@@ -111,7 +111,7 @@ def render_add_new_button(statement_node, origin = nil, bids = nil)
def add_new_sibling_buttons(statement_node, origin = nil, type = dom_class(statement_node))
content = ''
content << content_tag(:div, :class => 'siblings container') do
if statement_node.parent
if statement_node.parent_node
add_new_sibling_button(statement_node)
else
if origin.blank? or %w(ds mi sr).include? origin[0,2] # create new question
@@ -140,7 +140,7 @@ def add_new_sibling_button(statement_node)
statement_node.class.sub_types.map.each do |sub_type|
sub_type = sub_type.to_s.underscore
content << link_to(I18n.t("discuss.statements.types.#{sub_type}"),
new_statement_node_url(statement_node.parent, sub_type),
new_statement_node_url(statement_node.parent_node, sub_type),
:class => "create_#{sub_type}_button_32 resource_link ajax")
end
content
@@ -389,7 +389,7 @@ def siblings_button(statement_node, type, opts={})
if statement_node.parent_id.nil?
question_descendants_url(:origin => origin, :current_node => statement_node)
else
descendants_statement_node_url(statement_node.parent,
descendants_statement_node_url(statement_node.parent_node,
statement_node.class.name_for_siblings,
:current_node => statement_node)
end
@@ -451,7 +451,7 @@ def statement_button(statement_node, title, type, options={})
end

def add_teaser_statement_node_path(statement_node, opts={})
(statement_node.nil? or statement_node.level == 0) ? add_question_teaser_url(opts) : add_teaser_url(statement_node.parent, opts.merge(:type => dom_class(statement_node)))
(statement_node.nil? or statement_node.level == 0) ? add_question_teaser_url(opts) : add_teaser_url(statement_node.parent_node, opts.merge(:type => dom_class(statement_node)))
end

# Loads the link to a given statement, placed in the child panel section
@@ -19,7 +19,7 @@
(!only_header ? 'current' : 'back_to'), :css => 'ajax') %>
<% if statement_node.echoable? %>
<%= supporter_ratio_bar(statement_node,
@previous_node || statement_node.parent,
@previous_node || statement_node.parent_node,
@previous_type || statement_node.class.name) %>
<%= supporters_label(statement_node, !only_header) %>
<% end %>
@@ -11,7 +11,7 @@ if(!window.location.href.match(/\/\d+/)) {
<% if @statement_node.class.is_top_statement? or @statement_node.level == 0 %>
var session_id = 'roots';
<% else %>
var session_id = '<%= dom_class(@statement_node.parent) %>';
var session_id = '<%= dom_class(@statement_node.parent_node) %>';
<% end %>

var session_data = $('div#statements').data(session_id);
@@ -1,4 +1,4 @@
<% level = (@statement_node.parent.nil? or @statement_node.class.is_top_statement?) ? 0 : @statement_node.parent.level + 1 %>
<% level = (@statement_node.parent_node.nil? or @statement_node.class.is_top_statement?) ? 0 : @statement_node.parent_node.level + 1 %>
var element = $("<%= escape_javascript(render :partial => 'statements/new') %>").statement({'level' : <%= level %>});
element.data('api').removeBelow();

@@ -23,9 +23,9 @@ def supported(echoable, user)
user.subscriptions << Subscription.new(:subscriber => user,
:subscribeable => echoable)
end
if echoable.parent && !echoable.parent.subscriptions.find_by_subscriber_id(user.id)
if echoable.parent_node && !echoable.parent_node.subscriptions.find_by_subscriber_id(user.id)
user.subscriptions << Subscription.new(:subscriber => user,
:subscribeable => echoable.parent)
:subscribeable => echoable.parent_node)
end
end

@@ -34,9 +34,9 @@ def unsupported(echoable, user)
subscription = echoable.subscriptions.find_by_subscriber_id(user.id)
echoable.subscriptions.delete(subscription) if subscription

if echoable.parent
if echoable.parent_node
parent_subscription = user.subscriptions.find_by_subscribeable_id(echoable.parent_id)
if (user.subscriptions.map(&:subscribeable_id) & echoable.parent.child_statements.map(&:id)).empty?
if (user.subscriptions.map(&:subscribeable_id) & echoable.parent_node.child_statements.map(&:id)).empty?
user.subscriptions.delete(parent_subscription) if parent_subscription
end
end
@@ -66,17 +66,17 @@ def created_event(node)
event_json = {
:type => node.class.name.underscore,
:id => node.target_id,
:level => node.class.is_top_statement? ? node.parent.level + 1 : node.level,
:level => node.class.is_top_statement? ? node.parent_node.level + 1 : node.level,
:tags => node.filtered_topic_tags,
:documents => set_titles_hash(node.statement_documents),
:parent_documents => node.parent ? set_titles_hash(node.parent.statement_documents) : nil,
:parent_documents => node.parent_node ? set_titles_hash(node.parent_node.statement_documents) : nil,
:parent_id => node.parent_id || -1,
:operation => 'created'
}.to_json

Event.create(:event => event_json,
:operation => 'created',
:subscribeable => node.parent.nil? ? node : node.parent)
:subscribeable => node.parent_node.nil? ? node : node.parent_node)
end

def set_titles_hash(documents)
@@ -4,6 +4,15 @@ module Alternative

def self.included(base)
base.extend(ClassMethods)
base.instance_eval do
include InstanceMethods
end
end

module InstanceMethods
def parent_node
parent
end
end

module ClassMethods
@@ -16,7 +25,7 @@ def acts_as_alternative(*args)
args.flatten! if args
args.compact! if args

belongs_to :hub, :class_name => 'CasHub', :foreign_key => 'parent_id'
belongs_to :hub, :class_name => 'CasHub', :foreign_key => 'parent_id'

#TODO: WHEN RAILS ALLOWS THIS TO WORK, PLEASE ACTIVATE THIS RELSHIP: currently fails because the has many
# through joins the statement nodes table with itself (correct) without alias (false!).
@@ -57,6 +66,10 @@ def alternative_conditions(opts)
end
end

def parent_node
hub.nil? ? parent : hub.parent
end

def paginated_alternatives(page, per_page = nil,opts={})
alternative_statements = hub.nil? ? [] : hub.child_statements(opts.merge({:type => self.class.alternative,
:alternative_ids => alternatives.map(&:id)}))
@@ -74,7 +87,7 @@ def move_to_alternatives_hub(node_id)
hub = alternative.hub
if hub.nil?
hub = CasHub.create(:root_id => alternative.root_id, :parent_id => alternative.parent_id,
:statement => alternative.parent.statement, :creator_id => alternative.parent.creator_id)
:statement => alternative.parent_node.statement, :creator_id => alternative.parent_node.creator_id)
alternative.move_to_child_of hub
end
self.parent_id = hub.id
@@ -98,7 +98,7 @@ def siblings_to_session(opts)
opts[:type] ||= self.class.to_s
sibling_statements(opts).map{|s|s.map(&:id)}.each_with_index do |s, index|
siblings << s + ["/#{self.parent_id.nil? ? '' :
"#{self.parent.target_id}/"}add/#{self.class.sub_types[index].to_s.underscore}"]
"#{self.parent_node.target_id}/"}add/#{self.class.sub_types[index].to_s.underscore}"]
end
#order them properly, as you want them to be navigated
ordered_siblings = self.class.merge_statement_lists(siblings)
@@ -181,7 +181,7 @@ def stage(incorporable)
#
def select_approved(incorporable)
incorporable.reload
if incorporable.parent.approved_children.empty?
if incorporable.parent_node.approved_children.empty?
siblings = incorporable.sibling_statements(:language_ids => [incorporable.drafting_language.id]).select(&:staged?)
approve(siblings.first) if !siblings.empty?
end
@@ -293,7 +293,7 @@ def send_approval_mails(incorporable)
end

# Send approval notification to the rest of the supporters of the proposal
p_recipients = notified_supporters(incorporable.parent) - ip_recipients
p_recipients = notified_supporters(incorporable.parent_node) - ip_recipients
if !p_recipients.blank?
email = DraftingMailer.create_approval_notification(p_recipients, mail_data)
DraftingMailer.deliver(email)
@@ -356,15 +356,15 @@ def send_incorporation_mails(incorporable)

# Thank you mail to the author
ip_recipient = []
draftable_document = incorporable.parent.document_in_drafting_language
draftable_document = incorporable.parent_node.document_in_drafting_language
if draftable_document.author.drafting_notification == 1
ip_recipient << draftable_document.author
email = DraftingMailer.create_incorporated(mail_data)
DraftingMailer.deliver(email)
end

# Notification mail to the rest of the supporters of the proposal
p_recipients = notified_supporters(incorporable.parent) - ip_recipient
p_recipients = notified_supporters(incorporable.parent_node) - ip_recipient
if !p_recipients.blank?
email = DraftingMailer.create_incorporation_notification(p_recipients, mail_data)
DraftingMailer.deliver(email)
@@ -384,9 +384,9 @@ def prepare_mail(incorporable)
# Generating the mail data
{
:incorporable => incorporable,
:draftable => incorporable.parent,
:draftable => incorporable.parent_node,
:incorporable_document => incorporable.document_in_drafting_language,
:draftable_document => incorporable.parent.document_in_drafting_language,
:draftable_document => incorporable.parent_node.document_in_drafting_language,
:language => incorporable.drafting_language.code
}
end
@@ -135,7 +135,7 @@ def ratio(parent_statement = parent, type = self.class.name)

# Records the creator's support for the statement.
def author_support
if (!self.incorporable? or self.parent.supported?(self.creator)) # and self.echoable? SHOULD I????
if (!self.incorporable? or self.parent_node.supported?(self.creator)) # and self.echoable? SHOULD I????
self.supported!(self.creator)
end
end
@@ -32,19 +32,19 @@
end

it "should not save without a valid parent (Question or none)" do
@statement_node.parent = Question.first
@statement_node.parent_node = Question.first
@statement_node.should be_valid
@statement_node.parent = Proposal.first
@statement_node.parent_node = Proposal.first
@statement_node.should_not be_valid
@statement_node.parent = Improvement.first
@statement_node.parent_node = Improvement.first
@statement_node.should_not be_valid
end

it "should not save without a root when it has a parent" do
@statement_node.root_id = nil
@statement_node.parent = nil
@statement_node.parent_node = nil
@statement_node.should be_valid
@statement_node.parent = Question.first
@statement_node.parent_node = Question.first
@statement_node.should_not be_valid
@statement_node.root_id_ = Question.first.id
@statement_node.should be_valid
@@ -68,9 +68,9 @@
end

it "should not save without a valid parent (a question)" do
@statement_node.parent = nil
@statement_node.parent_node = nil
@statement_node.should_not be_valid
@statement_node.parent = Proposal.first
@statement_node.parent_node = Proposal.first
@statement_node.should_not be_valid
end
end
@@ -91,9 +91,9 @@
end

it "should not save without a valid parent (a proposal)" do
@statement_node.parent = nil
@statement_node.parent_node = nil
@statement_node.should_not be_valid
@statement_node.parent = Improvement.first
@statement_node.parent_node = Improvement.first
@statement_node.should_not be_valid
end

0 comments on commit 6249669

Please sign in to comment.
You can’t perform that action at this time.