From b518c5d2b8389c9d57568a7cb4b4bd16a187a39c Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 7 Feb 2015 23:54:54 +0100 Subject: [PATCH] Improved @P(), small bugfixes. --- app/assets/javascripts/app/index.js.coffee | 13 ++++++++++--- public/assets/tests/model-ui.js | 8 ++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/app/index.js.coffee b/app/assets/javascripts/app/index.js.coffee index 3e9458097..98dce1d1e 100644 --- a/app/assets/javascripts/app/index.js.coffee +++ b/app/assets/javascripts/app/index.js.coffee @@ -80,9 +80,14 @@ class App extends Spine.Controller result = attribute_config.callback( result, attribute_config ) # text2html in textarea view + isHtmlEscape = false if attribute_config.tag is 'textarea' + isHtmlEscape = true result = App.Utils.text2html( result ) + else if attribute_config.tag is 'richtext' + isHtmlEscape = true + # fillup options if !_.isEmpty(attribute_config.options) if attribute_config.options[result] @@ -92,20 +97,22 @@ class App extends Spine.Controller isTranslated = false if attribute_config.translate || ( isObject && item.translate && item.translate() ) isTranslated = true + isHtmlEscape = true result = App.i18n.translateContent( result ) # transform date if attribute_config.tag is 'date' + isHtmlEscape = true result = App.i18n.translateDate(result) # use pretty time for datetime else if attribute_config.tag is 'datetime' + isHtmlEscape = true result = "?" #result = App.i18n.translateTimestamp(result) - else if !isTranslated - if typeof result is 'string' - result = App.Utils.htmlEscape(result) + if !isHtmlEscape && typeof result is 'string' + result = App.Utils.htmlEscape(result) result diff --git a/public/assets/tests/model-ui.js b/public/assets/tests/model-ui.js index 6bb8cf20a..54decbf5b 100644 --- a/public/assets/tests/model-ui.js +++ b/public/assets/tests/model-ui.js @@ -23,6 +23,10 @@ test( "model ui basic tests", function() { name: 'date', display: 'date 1', tag: 'date', null: true }; App.Ticket.configure_attributes.push( attribute1 ) + var attribute2 = { + name: 'textarea', display: 'textarea 1', tag: 'textarea', null: true + }; + App.Ticket.configure_attributes.push( attribute2 ) var ticket = new App.Ticket() ticket.load({ @@ -31,6 +35,7 @@ test( "model ui basic tests", function() { state_id: 2, updated_at: '2014-11-07T23:43:08.000Z', date: '2015-02-07', + textarea: "some new\nline" }) App.i18n.set('en') @@ -41,6 +46,7 @@ test( "model ui basic tests", function() { equal( App.viewPrint( ticket, 'not_existing' ), '-') equal( App.viewPrint( ticket, 'updated_at' ), "?") equal( App.viewPrint( ticket, 'date' ), '2015-02-07') + equal( App.viewPrint( ticket, 'textarea' ), '
some new
line
') App.i18n.set('de') @@ -51,6 +57,8 @@ test( "model ui basic tests", function() { equal( App.viewPrint( ticket, 'not_existing' ), '-') equal( App.viewPrint( ticket, 'updated_at' ), "?") equal( App.viewPrint( ticket, 'date' ), '07.02.2015') + equal( App.viewPrint( ticket, 'textarea' ), '
some new
line
') + App.i18n.set('en') ticket.state_id = 3