Permalink
Browse files

Merge commit 'v1.0.6-rc2'

  • Loading branch information...
2 parents 2ba90eb + eff9643 commit d0af47d42161210dcd97cdb46cbb92eb214c5486 Hugh Cayless committed Aug 9, 2010
@@ -13,7 +13,8 @@ def edit
end
rescue RXSugar::XMLParseError => parse_error
flash.now[:error] = "Error parsing XML at line #{parse_error.line}, column #{parse_error.column}"
- @identifier[:leiden_plus] = parse_error.content
+ new_content = insert_error_here(parse_error.content, parse_error.line, parse_error.column)
+ @identifier[:leiden_plus] = new_content
end
end
@@ -49,15 +50,15 @@ def update
:action => :edit)
rescue RXSugar::NonXMLParseError => parse_error
flash.now[:error] = "Error parsing Leiden+ at line #{parse_error.line}, column #{parse_error.column}. This file was NOT SAVED. "
- @identifier[:leiden_plus] = parse_error.content
+ new_content = insert_error_here(parse_error.content, parse_error.line, parse_error.column)
+ @identifier[:leiden_plus] = new_content
@bad_leiden = true
@original_commit_comment = params[:comment]
render :template => 'ddb_identifiers/edit'
rescue JRubyXML::ParseError => parse_error
flash[:error] = parse_error.to_str +
". This message is because the XML created from Leiden+ below did not pass Relax NG validation. This file was NOT SAVED. "
@identifier[:leiden_plus] = params[:ddb_identifier][:leiden_plus]
- #@identifier[:leiden_plus] = parse_error.message
render :template => 'ddb_identifiers/edit'
end #begin
end #when
@@ -16,21 +16,27 @@ def edit
end
rescue RXSugar::XMLParseError => parse_error
flash.now[:error] = "Error parsing XML at line #{parse_error.line}, column #{parse_error.column}"
- @identifier[:leiden_trans] = parse_error.content
+ new_content = insert_error_here(parse_error.content, parse_error.line, parse_error.column)
+ @identifier[:leiden_trans] = new_content
end
#find text for preview
@identifier[:text_html_preview] = @identifier.related_text.preview
+
end
def add_new_lang_to_xml
- raise "Function needs protection to prevent wipe out of existing data. Nothing happened."
+ # raise "Function needs protection to prevent wipe out of existing data. Nothing happened."
+
find_identifier
#must prevent existing lang from being wiped out
-
- #
+ if @identifier.translation_already_in_language?(params[:lang])
+ flash[:warning] = "Language is already present in translation."
+ redirect_to polymorphic_path([@identifier.publication, @identifier], :action => :edit)
+ return
+ end
@identifier.stub_text_structure(params[:lang])
@identifier.save
redirect_to polymorphic_path([@identifier.publication, @identifier], :action => :edit)
@@ -79,7 +85,8 @@ def update
#non parsing
rescue RXSugar::NonXMLParseError => parse_error
flash.now[:error] = "Error parsing Leiden+ at line #{parse_error.line}, column #{parse_error.column}. This file was NOT SAVED."
- @identifier[:leiden_trans] = parse_error.content
+ new_content = insert_error_here(parse_error.content, parse_error.line, parse_error.column)
+ @identifier[:leiden_trans] = new_content
@bad_leiden = true
@original_commit_comment = params[:comment]
@@ -80,9 +80,40 @@ def updatexml
redirect_to polymorphic_path([@identifier.publication, @identifier],
:action => :editxml) and return
rescue JRubyXML::ParseError => parse_error
- flash.now[:error] = parse_error.to_str + " This file was NOT SAVED."
- @identifier[:xml_content] = xml_content
+ flash.now[:error] = parse_error.to_str + ". This file was NOT SAVED."
+ new_content = insert_error_here(xml_content, parse_error.line, parse_error.column)
+ @identifier[:xml_content] = new_content
render :template => 'identifiers/editxml'
end
end
+
+ protected
+
+ def insert_error_here(content, line, column)
+ # this routine is to place the error message below in the Leiden+ or XML returned when a parse error
+ # occurs by taking the line and column from the message and giving the user the place in the content
+ # the parse error occured in xsugars processing - may or may not be where the real error is depending
+ # on what the error is - this processing is by character because there are multiple byte characters
+ # possible in the text and a way to place msg with taking that into account
+ #
+ # line starts at 1 because first character is on first line before incrementing in loop
+ # same logic for column, already on first character before incrementing in loop
+ # 'col' check has to come before 'new line' check in case error is on last char in the line
+ line_cnt = 1
+ col_cnt = 1
+ content_error_here = ''
+ content.each_char do |i|
+ if line_cnt == line
+ if col_cnt == column
+ content_error_here << "**POSSIBLE ERROR**"
+ end
+ col_cnt += 1
+ end
+ if i == "\n"
+ line_cnt += 1
+ end
+ content_error_here << i
+ end
+ return content_error_here
+ end
end
@@ -122,9 +122,27 @@ def create_from_templates
redirect_to @publication
end
+
+ def is_theirs?
+ return @publication.owner_type == "User" && ( @publication.owner == @current_user )
+ end
+
def submit
@publication = Publication.find(params[:id])
+ #check if it is the owner
+ if ! is_theirs?
+ flash[:error] = 'You do not have permissions to submit this publication.'
+ redirect_to dashboard_url
+ return
+ end
+
+ #prevent resubmitting...most likely by impatient clicking on submit button
+ if ! %w{editing new}.include?(@publication.status)
+ flash[:error] = 'Publication has already been submitted. Did you click "Submit" multiple times?'
+ redirect_to @publication
+ return
+ end
#@comment = Comment.new( {:git_hash => @publication.recent_submit_sha, :publication_id => params[:id], :comment => params[:submit_comment], :reason => "submit", :user_id => @current_user.id } )
#git hash is not yet known, but we need the comment for the publication.submit to add to the changeDesc
@@ -68,6 +68,21 @@ def before_commit(content)
)
end
+ def translation_already_in_language?(lang)
+ lang_path = '/TEI/text/body/div[@type = "translation" and @xml:lang = "' + lang + '"]'
+
+ doc = REXML::Document.new(self.xml_content)
+ result = REXML::XPath.match(doc, lang_path)
+
+ if result.length > 0
+ return true
+ else
+ return false
+ end
+
+ end
+
+
def stub_text_structure(lang)
translation_stub_xsl =
JRubyXML.apply_xsl_transform(
@@ -80,8 +95,11 @@ def stub_text_structure(lang)
JRubyXML.apply_xsl_transform(
JRubyXML.stream_from_string(self.content),
JRubyXML.stream_from_string(translation_stub_xsl),
- :lang => 'en'
+ #:lang => 'en'
+ #assumed that hard coded 'en' is remnant and should be
+ :lang => lang
)
+
self.set_xml_content(rewritten_xml, :comment => "Update translation with stub for @xml:lang='#{lang}'")
end
@@ -1,5 +1,5 @@
-= link_to 'Leiden', edit_polymorphic_path([ddb_identifier.publication, ddb_identifier])
+= link_to 'Leiden+', edit_polymorphic_path([ddb_identifier.publication, ddb_identifier])
= link_to 'XML', editxml_publication_ddb_identifier_path( ddb_identifier.publication, ddb_identifier)
= link_to 'Preview', preview_publication_ddb_identifier_path( ddb_identifier.publication, ddb_identifier)
%br
@@ -170,4 +170,7 @@
%a{ :href => "#"}Try It
%li#8{ :itemType => "separator"}
%p
- %div#menuDiv
+ -if identifier.mutable?
+ %div#menuDiv
+ -else
+ %div#menuDiv{ :style => "display:none"}
@@ -2,7 +2,7 @@
= render :partial => 'identifiers/edit_bar'
.site
= render :partial => 'identifiers/header'
- = render :partial => 'leiden_helpers'
+ = render :partial => 'leiden_helpers', :locals => { :identifier => @identifier}
#edit
- form_for @identifier, :url => { :action => :update }, :html => {:name => 'helper'} do |f|
@@ -41,9 +41,10 @@
%li#103{ :jsFunction => "helpDialogOpen('terms')"}
%a{ :href => "#"} Terms
%li#104{ :itemType => "separator"}
- %li#105{ :jsFunction => "helpDialogOpen('new_lang')"}
+ %li#105
+ -# version using dialog box %li#105{ :jsFunction => "helpDialogOpen('new_lang')"}
%a{ :href => "#"} New Language
- -# commented out until xslt can be reviewed to prevent wiping out of existing langs
+ #comment out this section this to use dialog box version
%ul{ :width => "115"}
%li#10701
%a
@@ -197,4 +198,7 @@
%a{ :href => "#"}Try It
%li#8{ :itemType => "separator"}
%p
- %div#menuDiv
+ -if identifier.mutable?
+ %div#menuDiv
+ -else
+ %div#menuDiv{ :style => "display:none"}
@@ -6,7 +6,7 @@
= render :partial => 'identifiers/edit_bar'
.site
= render :partial => 'identifiers/header'
- = render :partial => 'translation_leiden_helpers'
+ = render :partial => 'translation_leiden_helpers', :locals => { :identifier => @identifier}
-#= stylesheet_link_tag 'hgv_translation'
#edit
@@ -21,7 +21,7 @@
= f.label "Leiden Trans"
= clippy "hgv_trans_identifier_leiden_trans"
%br
- = f.text_area :leiden_trans, :disabled => !@identifier.mutable?, :lang => 'grc', 'xml:lang' => 'grc', :wrap => 'off', :class => 'greek', :onkeyup => 'set_conf_true()'
+ = f.text_area :leiden_trans, :disabled => !@identifier.mutable?, :lang => 'grc', 'xml:lang' => 'grc', :wrap => 'off', :class => 'greek observechange'
= render :partial => 'identifiers/edit_commit', :locals => { :f => f, :identifier => @identifier, :bad_leiden => @bad_leiden, :original_commit_comment => @original_commit_comment }
@@ -3,12 +3,31 @@
%br
-#the save button and comment box styled differently in editor.sass based on different class on top and bottom
-if type == :top
- = text_field_tag :commenttop, defined?(original_commit_comment) ? original_commit_comment : '', :class => :commenttop, :size => '80', :disabled => !identifier.mutable?
+ = text_field_tag :commenttop, defined?(original_commit_comment) ? original_commit_comment : '', :class => 'commenttop observechangecomtop', :size => '80', :disabled => !identifier.mutable?
= f.submit "Save", :class => 'savetop', :disabled => !identifier.mutable?, :onclick => 'set_conf_false()'
- if defined?(bad_leiden) && bad_leiden
= f.submit "Save With Broken Leiden+", :class => 'brokentop', :disabled => !identifier.mutable?, :onclick => 'set_conf_false()'
-else
- = text_field_tag :comment, defined?(original_commit_comment) ? original_commit_comment : '', :class => :comment, :size => '80', :disabled => !identifier.mutable?
+ = text_field_tag :comment, defined?(original_commit_comment) ? original_commit_comment : '', :class => 'comment observechangecomment', :size => '80', :disabled => !identifier.mutable?
= f.submit "Save", :class => 'save', :disabled => !identifier.mutable?, :onclick => 'set_conf_false()'
- if defined?(bad_leiden) && bad_leiden
- = f.submit "Save With Broken Leiden+", :class => 'brokenbottom', :disabled => !identifier.mutable?, :onclick => 'set_conf_false()'
+ = f.submit "Save With Broken Leiden+", :class => 'brokenbottom', :disabled => !identifier.mutable?, :onclick => 'set_conf_false()'
+ :javascript
+ if (document.getElementById('notice_error'))
+ {var forceChangeTrue = true;}
+ else
+ {var forceChangeTrue = false;}
+ -else
+ :javascript
+ // force it to appear change was made when changed XML file was not saved due to parse error
+ err_exist = document.getElementById("notice_error");
+ if (err_exist != null) //if error notice is on page
+ {
+ get_err_msg = document.getElementById("notice_error").innerHTML;
+ if (get_err_msg.match("NOT SAVED"))
+ {var forceChangeTrue = true;}
+ else
+ {var forceChangeTrue = false;}
+ }
+ else // error notice is not on page
+ {var forceChangeTrue = false;}
@@ -16,3 +16,5 @@
= render :partial => 'identifiers/edit_commit', :locals => { :f => f, :identifier => @identifier }
= javascript_include_tag 'confirm'
+:javascript
+ showMatch("#{@identifier.class.to_s.underscore}_xml_content");
@@ -84,9 +84,11 @@
- if %w{editing new}.include?(@publication.status)
- for class_type in @creatable_identifiers
- - create_type = class_type.constantize::FRIENDLY_NAME
- - create_type = 'Create new ' + create_type
- = link_to create_type, :controller => 'identifiers', :action => 'create', :publication_id => @publication.id, :identifier_type => class_type, :method => :post
+ - link_type = class_type.constantize::FRIENDLY_NAME
+ - create_type = 'Create new ' + link_type
+ - newstyle = 'style="color:white; background-color:#005DAA"'
+ = link_to (create_type, options = {:controller => 'identifiers', :action => 'create', :publication_id => @publication.id, :identifier_type => class_type, :method => :post}, html_options = {:id => "#{link_type}", :onclick => "$('#{link_type}').replace('<b #{newstyle}>Creating New #{link_type}...</b>');"})
+
%br
- if @allow_delete
@@ -1,9 +1,9 @@
vendor/plugins/rxsugar:
:type: git
:repository: git://halsted.vis.uky.edu/git/xsugar.git
- :revision: 8adb32f78453ac84060fdef2bbd375e963773920
+ :revision: 32c9d1d65a51c1e8822b666eb8db1ef767b52fa7
data/xslt/epidoc:
:type: subversion
:repository: https://epidoc.svn.sourceforge.net/svnroot/epidoc/trunk/example-p5-xslt/
- :revision: 1206
+ :revision: 1256
@@ -45,7 +45,8 @@
</xsl:template>
<!-- convert <div type='edition' xml:lang='grc'> to <div type='translation' lang='$lang'> -->
- <xsl:template match="tei:div[@type='edition' and @xml:lang='grc']">
+ <!-- <xsl:template match="tei:div[@type='edition' and @xml:lang='grc']"> -->
+ <xsl:template match="tei:div[@type='edition']">
<div type='translation'>
<xslt:attribute name="xml:lang"><xslt:value-of select="$lang"/></xslt:attribute>
<xsl:apply-templates select="node()"/>
@@ -60,7 +61,10 @@
</xsl:element>
</xsl:template>
- <!-- convert <ab> to <p> and copy all children (lb's) -->
+ <!-- convert <ab> to <p> and copy all children (
+ <p>
+ <milestone unit="line" n="2"/>
+ </p>lb's) -->
<xsl:template match="tei:ab">
<xslt:element name="p">
<xsl:apply-templates select="element()"/>
View
@@ -1,6 +1,6 @@
module JRubyXML
class ParseError < ::StandardError
- attr :line, :column
+ attr_accessor :line, :column
def initialize(line, column)
@line = line
@@ -5,6 +5,16 @@
set_conf_true();
});
+ // Add a change observer to commenttop with the observechangecomtop CSS class
+ $$('.observechangecomtop').invoke('observe', 'change', function(event) {
+ document.getElementById("comment").disabled = true;
+ });
+
+ // Add a change observer to comment with the observechangecomment CSS class
+ $$('.observechangecomment').invoke('observe', 'change', function(event) {
+ document.getElementById("commenttop").disabled = true;
+ });
+
window.onbeforeunload = askConfirm;
function askConfirm()
@@ -23,4 +33,36 @@
function set_conf_false() {
needToConfirm = false;
+ }
+
+ function showMatch(elem_id)
+ {
+ // forceChangeTrue is set in identifiers/_edit_commit partial
+ if (forceChangeTrue)
+ {set_conf_true();}
+
+ //this phrase defined in insert_error_here method in identifiers controller
+ phrase = "**POSSIBLE ERROR**";
+
+ if(typeof document.selection != 'undefined') // means IE browser
+ {
+ var range = document.getElementById(elem_id).createTextRange();
+ if(range.findText(phrase))
+ {range.select();}
+ }
+ else
+ {
+ var element = document.getElementById(elem_id);
+ element.focus();
+ if(typeof element.selectionStart != 'undefined') // means Mozilla browser
+ {
+ var oDiv = document.getElementById(elem_id);
+ var t = oDiv.value;
+ var sp = t.split(phrase)[0].length;
+ var ep = sp + String(phrase).length;
+
+ oDiv.selectionStart = sp;
+ oDiv.selectionEnd = ep;
+ }
+ }
}
Oops, something went wrong.

0 comments on commit d0af47d

Please sign in to comment.