changeset 1052:6674e52e20bf bibplugin_bibtex

outputting error/success messages using the flash div; still not cleaning the messages correctly.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Mon, 19 Nov 2012 11:56:29 +0000
parents ef882e222003
children 80cf86be1611
files vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/app/views/publications/new/_bibtex.html.erb vendor/plugins/redmine_bibliography/app/views/publications/parse_bibtex.rjs
diffstat 3 files changed, 25 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- 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
 
--- 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" -%>
 </div>
 
-<div class="box" id="ieee_prev"></div>
+<div class="box" id="ieee_prev"><h3>Preview</h3></div>
 
--- 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, '<div class="flash notice">Successfully Parsed BibTeX</div>'
+else
+  page.insert_html :top, :content, '<div class="flash error">Error parsing BibTeX.</div>'
+end
 
-page.replace_html :error, flash[:error]
 flash.discard
\ No newline at end of file