diff --git a/app/assets/javascripts/app/controllers/_application_controller_form.coffee b/app/assets/javascripts/app/controllers/_application_controller_form.coffee index 5e0c39982..2771d92b1 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_form.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_form.coffee @@ -360,11 +360,16 @@ class App.ControllerForm extends App.Controller return item else + placeholderObjects = {} + if @model.className && !_.isEmpty(attribute.linktemplate) && !_.isEmpty(@params[attribute.name]) + placeholderObjects = { attribute: attribute, user: App.Session.get(), config: App.Config.all() } + placeholderObjects[@model.className.toLowerCase()] = @params fullItem = $( App.view('generic/attribute')( attribute: attribute, item: '', bookmarkable: @bookmarkable + placeholderObjects: placeholderObjects ) ) fullItem.find('.controls').prepend(item) diff --git a/app/assets/javascripts/app/controllers/_ui_element/object_manager_attribute.coffee b/app/assets/javascripts/app/controllers/_ui_element/object_manager_attribute.coffee index 76eec780d..149c78caf 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/object_manager_attribute.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/object_manager_attribute.coffee @@ -194,9 +194,21 @@ class App.UiElement.object_manager_attribute extends App.UiElement.ApplicationUi noFieldset: true params: params ) + configureAttributes = [ + # coffeelint: disable=no_interpolation_in_single_quotes + { name: 'data_option::linktemplate', display: 'Link-Template', tag: 'input', type: 'text', null: true, default: '', placeholder: 'https://example.com/?q=#{object.attribute_name} - use ticket, user or organization as object' }, + # coffeelint: enable=no_interpolation_in_single_quotes + ] + inputLinkTemplate = new App.ControllerForm( + model: + configure_attributes: configureAttributes + noFieldset: true + params: params + ) item.find('.js-inputDefault').html(inputDefault.form) item.find('.js-inputType').html(inputType.form) item.find('.js-inputMaxlength').html(inputMaxlength.form) + item.find('.js-inputLinkTemplate').html(inputLinkTemplate.form) @datetime: (item, localParams, params) -> configureAttributes = [ @@ -311,6 +323,18 @@ class App.UiElement.object_manager_attribute extends App.UiElement.ApplicationUi return lastSelected = value ) + configureAttributes = [ + # coffeelint: disable=no_interpolation_in_single_quotes + { name: 'data_option::linktemplate', display: 'Link-Template', tag: 'input', type: 'text', null: true, default: '', placeholder: 'https://example.com/?q=#{ticket.attribute_name}' }, + # coffeelint: enable=no_interpolation_in_single_quotes + ] + inputLinkTemplate = new App.ControllerForm( + model: + configure_attributes: configureAttributes + noFieldset: true + params: params + ) + item.find('.js-inputLinkTemplate').html(inputLinkTemplate.form) @buildRow: (element, child, level = 0, parentElement) -> newRow = element.find('.js-template').clone().removeClass('js-template') diff --git a/app/assets/javascripts/app/index.coffee b/app/assets/javascripts/app/index.coffee index 4ec67da63..786d7846f 100644 --- a/app/assets/javascripts/app/index.coffee +++ b/app/assets/javascripts/app/index.coffee @@ -46,10 +46,10 @@ class App extends Spine.Controller if object[attributeNameWithoutRef] valueRef = object[attributeNameWithoutRef] - @viewPrintItem(value, attributeConfig, valueRef, table) + @viewPrintItem(value, attributeConfig, valueRef, table, object) # define print name helper - @viewPrintItem: (item, attributeConfig = {}, valueRef, table) -> + @viewPrintItem: (item, attributeConfig = {}, valueRef, table, object) -> return '-' if item is undefined return '-' if item is '' return item if item is null @@ -107,18 +107,23 @@ class App extends Spine.Controller # translate content if attributeConfig.translate || (isObject && item.translate && item.translate()) isHtmlEscape = true - resultLocal = App.i18n.translateContent(resultLocal) + resultLocal = App.i18n.translateContent(resultLocal) # transform date if attributeConfig.tag is 'date' isHtmlEscape = true resultLocal = App.i18n.translateDate(resultLocal) + linktemplate = @_placeholderReplacement(object, attributeConfig, resultLocal) + if linktemplate && isHtmlEscape is false + resultLocal = linktemplate + isHtmlEscape = true + # transform input tel|url to make it clickable - if attributeConfig.tag is 'input' + if attributeConfig.tag is 'input' && !linktemplate if attributeConfig.type is 'tel' resultLocal = "#{App.Utils.htmlEscape(resultLocal)}" - else if attributeConfig.type is 'url' + else if attributeConfig.type is 'url' && !linktemplate resultLocal = App.Utils.linkify(resultLocal) else resultLocal = App.Utils.htmlEscape(resultLocal) @@ -146,6 +151,17 @@ class App extends Spine.Controller result + @_placeholderReplacement: (object, attributeConfig, resultLocal) -> + return if !object + return if !attributeConfig + return if _.isEmpty(attributeConfig.linktemplate) + return if !object.constructor + return if !object.constructor.className + return if _.isEmpty(object[attributeConfig.name]) + placeholderObjects = { attribute: attributeConfig, user: App.Session.get(), config: App.Config.all() } + placeholderObjects[object.constructor.className.toLowerCase()] = object + "#{App.Utils.htmlEscape(resultLocal)}" + @view: (name) -> template = (params = {}) -> JST["app/views/#{name}"](_.extend(params, App.ViewHelpers)) diff --git a/app/assets/javascripts/app/lib/app_post/utils.coffee b/app/assets/javascripts/app/lib/app_post/utils.coffee index f29dbdfa6..4efc203b1 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.coffee @@ -704,7 +704,7 @@ class App.Utils res.join('') # textReplaced = App.Utils.replaceTags( template, { user: { firstname: 'Bob', lastname: 'Smith' } } ) - @replaceTags: (template, objects) -> + @replaceTags: (template, objects, encodeLink = false) -> template = template.replace( /#\{\s{0,2}(.+?)\s{0,2}\}/g, (index, key) -> key = key.replace(/<.+?>/g, '') levels = key.split(/\./) @@ -744,6 +744,7 @@ class App.Utils else value = '' value = '-' if value is '' + value = encodeURIComponent(value) if encodeLink value ) diff --git a/app/assets/javascripts/app/lib/mixins/view_helpers.coffee b/app/assets/javascripts/app/lib/mixins/view_helpers.coffee index ea09574f9..e10f34de9 100644 --- a/app/assets/javascripts/app/lib/mixins/view_helpers.coffee +++ b/app/assets/javascripts/app/lib/mixins/view_helpers.coffee @@ -228,3 +228,6 @@ App.ViewHelpers = className: params.className iconset: params.iconset ) + + replacePlaceholder: (template, items, encodeLink = false) -> + App.Utils.replaceTags(template, items, encodeLink) diff --git a/app/assets/javascripts/app/views/generic/attribute.jst.eco b/app/assets/javascripts/app/views/generic/attribute.jst.eco index 4954cb96b..d039fec18 100644 --- a/app/assets/javascripts/app/views/generic/attribute.jst.eco +++ b/app/assets/javascripts/app/views/generic/attribute.jst.eco @@ -20,9 +20,12 @@
<% if @attribute.help: %><%- @T(@attribute.help) %><% end %><%- @attribute.helpLink %>
<% end %> -