# HG changeset patch # User luisf # Date 1353326189 0 # Node ID 6674e52e20bfc55ca1d0ae7b10f5782ebbc2231a # Parent ef882e2220037ad2de693bcb65990632acf33f81 outputting error/success messages using the flash div; still not cleaning the messages correctly. diff -r ef882e222003 -r 6674e52e20bf vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Fri Nov 16 19:05:01 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Mon Nov 19 11:56:29 2012 +0000 @@ -24,27 +24,31 @@ def parse_bibtex find_project_by_project_id + @bibtex_parse_success = true - bibtex_paste = params[:bibtex_paste] - bib = BibTeX.parse(bibtex_paste) + begin + bibtex_paste = params[:bibtex_paste] + bib = BibTeX.parse(bibtex_paste) + rescue + # todo: output errors to user + # bib.errors.present? + @bibtex_parse_success = false + # @bibtex_parsing_error = bib.errors[0].trace[4] + # logger.error { "BibTex Parsing Error: #{@bibtex_parsing_error}" } + logger.error { "BibTex Parsing Error" } + end respond_to do |format| - if bib.errors.present? or bib[0].class == NilClass - # todo: response for HTML format.html{} - # todo: better error handling - biberror = bib.errors[0].trace[4] - logger.error { "BibTex Parsing Error: #{biberror}" } - flash[:error] = "BibTex Parsing Error: #{biberror}" - #raise BibtexParsingError, "Bibtex Parsing Error: biberror}" + if @bibtex_parse_success + @ieee_prev = CiteProc.process bib.to_citeproc, :style => :ieee, :format => :html + end + format.js - else - @ieee_prev = CiteProc.process bib.to_citeproc, :style => :ieee, :format => :html - flash['notice'] = "OK!" - format.js - end + + end end diff -r ef882e222003 -r 6674e52e20bf vendor/plugins/redmine_bibliography/app/views/publications/new/_bibtex.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/new/_bibtex.html.erb Fri Nov 16 19:05:01 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/new/_bibtex.html.erb Mon Nov 19 11:56:29 2012 +0000 @@ -8,5 +8,5 @@ <%= link_to_remote "Parse BiBTeX", :url => { :project_id => @project, :action => :parse_bibtex}, :with => "'bibtex_paste=' + $('bibtex_paste').value" -%> -
+

Preview

diff -r ef882e222003 -r 6674e52e20bf vendor/plugins/redmine_bibliography/app/views/publications/parse_bibtex.rjs --- a/vendor/plugins/redmine_bibliography/app/views/publications/parse_bibtex.rjs Fri Nov 16 19:05:01 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/parse_bibtex.rjs Mon Nov 19 11:56:29 2012 +0000 @@ -1,4 +1,8 @@ -page.replace_html :ieee_prev, @ieee_prev +if @bibtex_parse_success + page.insert_html :bottom, :ieee_prev, @ieee_prev + page.insert_html :top, :content, '
Successfully Parsed BibTeX
' +else + page.insert_html :top, :content, '
Error parsing BibTeX.
' +end -page.replace_html :error, flash[:error] flash.discard \ No newline at end of file