Skip to content

Commit

Permalink
Have added error links in topic form
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitin Dhaware committed Sep 10, 2013
1 parent 6cd82ba commit b2842b9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 44 deletions.
17 changes: 13 additions & 4 deletions app/assets/javascripts/topics.js.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
$(document).ready ->

$(document).ready ->
errorElements = $('.content').find('.help-inline').prev()
ul = $('<ul id="errorlist"></ul>')
errorElements.each (i) ->
span = $(this).next()
labelText = $(this).parent().parent().find('label')
$(' <li> <a href="#' + $(this).attr('id') + '" class="errorlink" >' + labelText.text() + ' ' + '(' + span.text() + ')' + '</a></li>').appendTo(ul)
$('#errorcontainer').html(ul)
$('.errorlink').bind 'click', (e)->
sid = $(this).attr('href').substr(1, $(this).attr('href').length-1)
e.stopPropagation
$('input[id="' + sid + '"]').focus()

window.nestedFormEvents.insertFields = (content, assoc, link) ->
$(content).insertBefore(link)
if assoc == "contents"
Expand All @@ -21,5 +32,3 @@
error: (e) ->
console.log 'Error'
)


81 changes: 41 additions & 40 deletions app/views/topics/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
= simple_nested_form_for [@level, @topic], html: {:class => 'form-horizontal'} do |f|
= @topic.errors.full_messages.to_sentence
= simple_nested_form_for [@level, @topic], html: {:class => 'form-horizontal'} do |f|
= @topic.errors.full_messages
- if !@topic.errors.empty?
%p#errorcontainer
.form-inputs
= f.hidden_field :level_id
= f.input :title
= f.input :description, as: :text, :input_html => {:rows => 2}
%hr
= 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
%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'}}
%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'
= 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'

.form-actions
= f.button :submit, class: 'btn btn-large btn-success'
Expand Down

0 comments on commit b2842b9

Please sign in to comment.