Skip to content

Commit

Permalink
Delete or change the audio file through UI is done. Add the links rel…
Browse files Browse the repository at this point in the history
…ated logos in footer.
  • Loading branch information
Sanghapal committed Sep 5, 2013
1 parent 9046b61 commit 6cd82ba
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 47 deletions.
1 change: 0 additions & 1 deletion app/assets/stylesheets/_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ padding-bottom:150px; /* this needs to be bigger than footer height*/
margin-top: -150px; /* negative value of footer height */
height: 60px;
clear:both;
padding-top:20px;
color:#fff;
}

Expand Down
16 changes: 13 additions & 3 deletions app/controllers/topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ def show
def new
@level = Level.find(params[:level_id])
@topic = @level.topics.build
@content = @topic.contents.build
question = @content.questions.build
question.options.build
render layout: 'admin'
end

Expand Down Expand Up @@ -65,6 +62,19 @@ def destroy
redirect_to level_topics_path(@level)
end

def remove_uploaded_file
content = Content.find(params[:content_id])
topic = content.topic
level = Level.find(params[:level_id])
if content.topic_content != nil
content.topic_content.clear
content.save
render :js => "window.location.pathname = '#{edit_level_topic_path(level, topic)}'"
else
render :action => :edit
end
end

private
def load_topic
@topic = Topic.find(params[:id])
Expand Down
5 changes: 4 additions & 1 deletion app/models/content.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
class Content
include Mongoid::Document
include Mongoid::Slug
include Mongoid::Paperclip
has_mongoid_attached_file :topic_content


field :title, type: String
field :content_body, type: String
field :sq_no, type: Integer
Expand All @@ -15,5 +17,6 @@ class Content
#validations
validates :title, :content_body, :sq_no, :topic_id, :presence => true
validates :sq_no, :numericality => {:only_integer => true}
validates_attachment :topic_content, :presence => true
#validates_attachment :topic_content, :presence => true

end
9 changes: 6 additions & 3 deletions app/views/application/_footer.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
.span6.pull-left
%ul.nav
%li
%img{:src =>'/images/Josh.svg', :alt => 'Josh software logo', :width => "100px"}
%a{:href => "http://joshsoftware.com"}
%img{:src =>'/images/Josh.svg', :alt => 'Josh software logo', :width => "100px"}
%li
%p Knowledge Partner
.span6.pull-middle
%ul.nav
%li
%img{:src =>'/images/techvision4.jpg', :alt => 'TechVision logo', :width => "125px"}
%a{:href => "http://techvision.net.in"}
%img{:src =>'/images/techvision4.jpg', :alt => 'TechVision logo', :width => "125px"}
%li
%p Develop by
.span3.pull-right
%ul.nav
%li
%img{:src =>'/images/Rackspace_Cloud_Company_Logo_clr_300x109.jpg', :alt => 'Rackspace logo', :width => "100px"}
%a{:href => "http://www.rackspace.com/"}
%img{:src =>'/images/Rackspace_Cloud_Company_Logo_clr_300x109.jpg', :alt => 'Rackspace logo', :width => "100px"}
%li
%p Hosting Partner

Expand Down
2 changes: 1 addition & 1 deletion app/views/application/_header.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
%li
- if current_user.roles == "Admin"
= link_to "Level", levels_list_path
.span5.pull-right
.span7.pull-right
%ul.nav.pull-right
%li
= link_to "Nominate", nominate_path
Expand Down
77 changes: 39 additions & 38 deletions app/views/topics/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
= simple_nested_form_for [@level, @topic], html: {:class => 'form-horizontal'} do |f|
= simple_nested_form_for [@level, @topic], html: {:class => 'form-horizontal'} do |f|
= @topic.errors.full_messages.to_sentence
.form-inputs
= f.hidden_field :level_id
= f.input :title
= f.input :description, as: :text, :input_html => {:rows => 2}
%hr
%ul.nav.nav-tabs
%li.active
%a{ href: "#content", 'data-toggle' => "tab"}Content
.tab-content.topic-form
.tab-pane.active#content
= f.simple_fields_for :contents do |content|
%h6
New Content
= content.input :title, :label => "Content title"
= content.input :content_body, as: :text
= content.input :sq_no, :label => "Sequence number"
%label.control-label Upload Audio File
.controls= content.file_field :topic_content
%br
= content.input :transcript, as: :ckeditor, :input_html => {:ckeditor => {:toolbar => 'mini'}}
= f.simple_fields_for :contents do |content|
%h6
New Content
= content.input :title, :label => "Content title"
= content.input :content_body, as: :text
= content.input :sq_no, :label => "Sequence number"
-if params[:controller] == "topics" && params[:action] == "edit"
= content.input :topic_content_file_name, :label => "Audio file name" do
= content.input_field :topic_content_file_name, :readonly => true
= link_to 'Delete', remove_uploaded_file_path(@level, content.object.id), method: :put, data: { confirm: 'Are you sure to remove audio file?' }, class: "btn", :remote => true
= content.input_field :topic_content
-else
%label.control-label Upload Audio File
.controls= content.file_field :topic_content
%br
= content.input :transcript, as: :ckeditor, :input_html => {:ckeditor => {:toolbar => 'mini'}}
%br
%hr
= content.simple_fields_for :questions do |question|
%h6 New Question
NOTE: minimum 3 options required
= question.input :question_type, :collection => ["Simple", "Medium", "Hard"],
:prompt => "Select question type",
:input_html => {:id => "ddr_question_type"}
= question.input :sq_no, :label => "Sequence number"
= question.input :query
= question.simple_fields_for :options do |option|
%h6 Option
= option.input :label
= option.input :is_valid, as: :boolean
%br
.pull-right= option.link_to_remove "Remove this option"
%hr
= content.simple_fields_for :questions do |question|
%h6 New Question
NOTE: minimum 3 options required
= question.input :question_type, :collection => ["Simple", "Medium", "Hard"],
:prompt => "Select question type",
:input_html => {:id => "ddr_question_type"}
= question.input :sq_no, :label => "Sequence number"
= question.input :query
= question.simple_fields_for :options do |option|
%h6 Option
= option.input :label
= option.input :is_valid, as: :boolean
%br
.pull-right= option.link_to_remove "Remove this option"
%hr
= question.link_to_add question.object.options.count > 0? "Add More Options" :"Add Option", :options, :class => 'pull-right more_options'
%br
.pull-right= question.link_to_remove "Remove this question"
%hr
= content.link_to_add content.object.questions.count > 0? "Add More Questions" :"Add questions", :questions, :class => 'btn btn-info more_question'
.pull-right= content.link_to_remove "Remove this content"
= f.link_to_add f.object.contents.count > 0 ? "Add More Content" : "Add Content", :contents, :class => 'btn btn-info more_content'
= question.link_to_add question.object.options.count > 0? "Add More Options" :"Add Option", :options, :class => 'pull-right more_options'
%br
.pull-right= question.link_to_remove "Remove this question"
%hr
= content.link_to_add content.object.questions.count > 0? "Add More Questions" :"Add questions", :questions, :class => 'btn btn-info more_question'
.pull-right= content.link_to_remove "Remove this content"
= f.link_to_add f.object.contents.count > 0 ? "Add More Content" : "Add Content", :contents, :class => 'btn btn-info more_content'

.form-actions
= f.button :submit, class: 'btn btn-large btn-success'
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
match 'nominate_list' => 'home#nominate_list', :via => :get, as: :nominate_list
match '/feedback' => 'home#feedback', :via => [:get, :post], as: :feedback
match '/feedback_list' => 'home#feedback_list', :via => :get, as: :feedback_list
put '/levels/:level_id/content/:content_id' => 'topics#remove_uploaded_file', as: :remove_uploaded_file

# The priority is based upon order of creation:
# first created -> highest priority.
Expand Down

0 comments on commit 6cd82ba

Please sign in to comment.