Permalink
Browse files

Refactoring of perform/set attributes in trigger and postmaster filte…

…r ui (now use clean template - not side effects regarding autocompletion and tags).
  • Loading branch information...
martini committed Jul 11, 2018
1 parent 370b1a2 commit ae3e2141b130db03e2414376d0895a8b4822a09e
@@ -72,10 +72,7 @@ class App.UiElement.postmaster_set
elements = {}
for groupKey, groupMeta of groups
if !App[groupMeta.model]
elements["#{groupKey}.email"] = { name: 'email', display: 'Email' }
else
if groupMeta.model && App[groupMeta.model]
for row in App[groupMeta.model].configure_attributes
# ignore passwords and relations
@@ -117,32 +114,39 @@ class App.UiElement.postmaster_set
[elements, groups]
@placeholder: (elementFull, attribute, params = {}, groups) ->
item = $( App.view('generic/postmaster_set_row')( attribute: attribute ) )
selector = @buildAttributeSelector(elementFull, groups, attribute, item)
item.find('.js-attributeSelector').prepend(selector)
item
@render: (attribute, params = {}) ->
[elements, groups] = @defaults()
selector = @buildAttributeSelector(groups, attribute)
# scaffold of match elements
item = $( App.view('generic/postmaster_set')( attribute: attribute ) )
item.find('.js-attributeSelector').prepend(selector)
# add filter
item.find('.js-add').bind('click', (e) ->
item.on('click', '.js-add', (e) =>
element = $(e.target).closest('.js-filterElement')
elementClone = element.clone(true)
element.after(elementClone)
elementClone.find('.js-attributeSelector select').trigger('change')
placeholder = @placeholder(item, attribute, params, groups)
if element.get(0)
element.after(placeholder)
else
item.append(placeholder)
placeholder.find('.js-attributeSelector select').trigger('change')
)
# remove filter
item.find('.js-remove').bind('click', (e) =>
item.on('click', '.js-remove', (e) =>
return if $(e.currentTarget).hasClass('is-disabled')
$(e.target).closest('.js-filterElement').remove()
@rebuildAttributeSelectors(item)
)
# change attribute selector
item.find('.js-attributeSelector select').bind('change', (e) =>
item.on('change', '.js-attributeSelector select', (e) =>
key = $(e.target).find('option:selected').attr('value')
elementRow = $(e.target).closest('.js-filterElement')
groupAndAttribute = elementRow.find('.js-attributeSelector option:selected').attr('value')
@@ -152,27 +156,20 @@ class App.UiElement.postmaster_set
)
# build inital params
if !_.isEmpty(params[attribute.name])
selectorExists = false
for key, meta of params[attribute.name]
selectorExists = true
operator = meta.operator
value = meta.value
if _.isEmpty(params[attribute.name])
item.append(@placeholder(item, attribute, params, groups))
return item
# get selector rows
elementFirst = item.find('.js-filterElement').first()
elementLast = item.find('.js-filterElement').last()
for key, meta of params[attribute.name]
operator = meta.operator
value = meta.value
# clone, rebuild and append
elementClone = elementFirst.clone(true)
@rebuildAttributeSelectors(item, elementClone, key, attribute)
@buildValue(item, elementClone, key, groups, value, operator, attribute)
elementLast.after(elementClone)
# build and append
element = @placeholder(item, attribute, params, groups)
@rebuildAttributeSelectors(item, element, key, attribute)
@buildValue(item, element, key, groups, value, operator, attribute)
# remove first dummy row
if selectorExists
item.find('.js-filterElement').first().remove()
item.append(element)
item
@@ -197,15 +194,26 @@ class App.UiElement.postmaster_set
item = App.UiElement[config.tag].render(config, {})
elementRow.find('.js-value').html(item)
@buildAttributeSelector: (groups, attribute) ->
@buildAttributeSelector: (elementFull, groups, attribute) ->
# find first possible attribute
selectedValue = ''
elementFull.find('.js-attributeSelector select option').each(->
if !selectedValue && !$(@).prop('disabled')
selectedValue = $(@).val()
)
selection = $('<select class="form-control"></select>')
for groupKey, groupMeta of groups
displayName = App.i18n.translateInline(groupMeta.name)
selection.closest('select').append("<optgroup label=\"#{displayName}\" class=\"js-#{groupKey}\"></optgroup>")
optgroup = selection.find("optgroup.js-#{groupKey}")
for entry in groupMeta.options
displayName = App.i18n.translateInline(entry.name)
optgroup.append("<option value=\"#{entry.value}\">#{displayName}</option>")
selected = ''
if entry.value is selectedValue
selected = 'selected="selected"'
optgroup.append("<option value=\"#{entry.value}\" #{selected}>#{displayName}</option>")
selection
@rebuildAttributeSelectors: (elementFull, elementRow, key, attribute) ->
@@ -240,11 +248,11 @@ class App.UiElement.postmaster_set
selection = $("<select class=\"form-control\" name=\"#{name}\"></select>")
attributeConfig = elements[groupAndAttribute]
if !attributeConfig.operator
if !attributeConfig || !attributeConfig.operator
elementRow.find('.js-operator').addClass('hide')
else
elementRow.find('.js-operator').removeClass('hide')
if attributeConfig.operator
if attributeConfig && attributeConfig.operator
for operator in attributeConfig.operator
operatorName = App.i18n.translateInline(operator)
selected = ''
@@ -16,7 +16,7 @@ class App.UiElement.ticket_perform_action
# megre config
elements = {}
for groupKey, groupMeta of groups
if !App[groupMeta.model]
if !groupMeta.model || !App[groupMeta.model]
elements["#{groupKey}.email"] = { name: 'email', display: 'Email' }
else
@@ -45,92 +45,82 @@ class App.UiElement.ticket_perform_action
[defaults, groups, elements]
@placeholder: (elementFull, attribute, params, groups, elements) ->
item = $( App.view('generic/ticket_perform_action/row')( attribute: attribute ) )
selector = @buildAttributeSelector(elementFull, groups, elements)
item.find('.js-attributeSelector').prepend(selector)
item
@render: (attribute, params = {}) ->
[defaults, groups, elements] = @defaults(attribute)
selector = @buildAttributeSelector(groups, elements)
# return item
item = $( App.view('generic/ticket_perform_action/index')( attribute: attribute ) )
item.find('.js-attributeSelector').prepend(selector)
# add filter
item.find('.js-add').bind('click', (e) =>
item.on('click', '.js-add', (e) =>
element = $(e.target).closest('.js-filterElement')
elementClone = element.clone(true)
element.after(elementClone)
elementClone.find('.js-attributeSelector select').trigger('change')
placeholder = @placeholder(item, attribute, params, groups, elements)
if element.get(0)
element.after(placeholder)
else
item.append(placeholder)
placeholder.find('.js-attributeSelector select').trigger('change')
@updateAttributeSelectors(item)
)
# remove filter
item.find('.js-remove').bind('click', (e) =>
item.on('click', '.js-remove', (e) =>
return if $(e.currentTarget).hasClass('is-disabled')
$(e.target).closest('.js-filterElement').remove()
@updateAttributeSelectors(item)
)
# change attribute selector
item.find('.js-attributeSelector select').bind('change', (e) =>
item.on('change', '.js-attributeSelector select', (e) =>
elementRow = $(e.target).closest('.js-filterElement')
groupAndAttribute = elementRow.find('.js-attributeSelector option:selected').attr('value')
@rebuildAttributeSelectors(item, elementRow, groupAndAttribute, elements, {}, attribute)
@updateAttributeSelectors(item)
)
# build inital params
if !_.isEmpty(params[attribute.name])
selectorExists = false
for groupAndAttribute, meta of params[attribute.name]
selectorExists = true
# get selector rows
elementFirst = item.find('.js-filterElement').first()
elementLast = item.find('.js-filterElement').last()
# clone, rebuild and append
elementClone = elementFirst.clone(true)
@rebuildAttributeSelectors(item, elementClone, groupAndAttribute, elements, meta, attribute)
elementLast.after(elementClone)
# change operator selector
item.on('change', '.js-operator select', (e) =>
elementRow = $(e.target).closest('.js-filterElement')
groupAndAttribute = elementRow.find('.js-attributeSelector option:selected').attr('value')
@buildOperator(item, elementRow, groupAndAttribute, elements, {}, attribute)
)
# remove first dummy row
if selectorExists
item.find('.js-filterElement').first().remove()
# build inital params
if _.isEmpty(params[attribute.name])
else
for groupAndAttribute in defaults
# get selector rows
elementFirst = item.find('.js-filterElement').first()
elementLast = item.find('.js-filterElement').last()
# build and append
element = @placeholder(item, attribute, params, groups, elements)
item.append(element)
@rebuildAttributeSelectors(item, element, groupAndAttribute, elements, {}, attribute)
# clone, rebuild and append
elementClone = elementFirst.clone(true)
@rebuildAttributeSelectors(item, elementClone, groupAndAttribute, elements, {}, attribute)
return item
elementLast.after(elementClone)
item.find('.js-filterElement').first().remove()
for groupAndAttribute, meta of params[attribute.name]
# change attribute selector
item.find('.js-attributeSelector select').bind('change', (e) =>
elementRow = $(e.target).closest('.js-filterElement')
groupAndAttribute = elementRow.find('.js-attributeSelector option:selected').attr('value')
@rebuildAttributeSelectors(item, elementRow, groupAndAttribute, elements, {}, attribute)
@updateAttributeSelectors(item)
)
# build and append
element = @placeholder(item, attribute, params, groups, elements)
@rebuildAttributeSelectors(item, element, groupAndAttribute, elements, meta, attribute)
item.append(element)
item
# change operator selector
item.on('change', '.js-operator select', (e) =>
elementRow = $(e.target).closest('.js-filterElement')
groupAndAttribute = elementRow.find('.js-attributeSelector option:selected').attr('value')
@buildOperator(item, elementRow, groupAndAttribute, elements, {}, attribute)
)
@buildAttributeSelector: (elementFull, groups, elements) ->
item
# find first possible attribute
selectedValue = ''
elementFull.find('.js-attributeSelector select option').each(->
if !selectedValue && !$(@).prop('disabled')
selectedValue = $(@).val()
)
@buildAttributeSelector: (groups, elements) ->
selection = $('<select class="form-control"></select>')
for groupKey, groupMeta of groups
displayName = App.i18n.translateInline(groupMeta.name)
@@ -141,7 +131,11 @@ class App.UiElement.ticket_perform_action
if spacer[0] is groupKey
attributeConfig = elements[elementKey]
displayName = App.i18n.translateInline(attributeConfig.display)
optgroup.append("<option value=\"#{elementKey}\">#{displayName}</option>")
selected = ''
if elementKey is selectedValue
selected = 'selected="selected"'
optgroup.append("<option value=\"#{elementKey}\" #{selected}>#{displayName}</option>")
selection
@updateAttributeSelectors: (elementFull) ->
@@ -191,11 +185,11 @@ class App.UiElement.ticket_perform_action
selection = $("<select class=\"form-control\" name=\"#{name}\"></select>")
attributeConfig = elements[groupAndAttribute]
if !attributeConfig.operator
if !attributeConfig || !attributeConfig.operator
elementRow.find('.js-operator').addClass('hide')
else
elementRow.find('.js-operator').removeClass('hide')
if attributeConfig.operator
if attributeConfig && attributeConfig.operator
for operator in attributeConfig.operator
operatorName = App.i18n.translateInline(operator)
selected = ''
@@ -1,26 +1 @@
<div class="horizontal-filters">
<div class="horizontal-filter js-filterElement">
<div class="horizontal-filter-body">
<div class="controls">
<div class="u-positionOrigin js-attributeSelector">
<%- @Icon('arrow-down', 'dropdown-arrow') %>
</div>
</div>
<div class="controls">
<div class="u-positionOrigin js-operator">
<select></select>
<%- @Icon('arrow-down') %>
</div>
</div>
<div class="controls js-value"></div>
</div>
<div class="filter-controls">
<div class="filter-control filter-control-remove js-remove" title="<%- @T('Remote') %>">
<%- @Icon('minus-small') %>
</div>
<div class="filter-control filter-control-add js-add" title="<%- @T('Add') %>">
<%- @Icon('plus-small') %>
</div>
</div>
</div>
</div>
<div class="horizontal-filters"></div>
@@ -0,0 +1,24 @@
<div class="horizontal-filter js-filterElement">
<div class="horizontal-filter-body">
<div class="controls">
<div class="u-positionOrigin js-attributeSelector">
<%- @Icon('arrow-down', 'dropdown-arrow') %>
</div>
</div>
<div class="controls">
<div class="u-positionOrigin js-operator">
<select></select>
<%- @Icon('arrow-down') %>
</div>
</div>
<div class="controls js-value"></div>
</div>
<div class="filter-controls">
<div class="filter-control filter-control-remove js-remove" title="<%- @T('Remote') %>">
<%- @Icon('minus-small') %>
</div>
<div class="filter-control filter-control-add js-add" title="<%- @T('Add') %>">
<%- @Icon('plus-small') %>
</div>
</div>
</div>
@@ -1,21 +1 @@
<div class="horizontal-filters">
<div class="horizontal-filter js-filterElement">
<div class="horizontal-filter-body">
<div class="controls">
<div class="u-positionOrigin js-attributeSelector">
<%- @Icon('arrow-down', 'dropdown-arrow') %>
</div>
</div>
<div class="js-setAttribute"></div>
<div class="js-setNotification flex"></div>
</div>
<div class="filter-controls">
<div class="filter-control filter-control-remove js-remove" title="<%- @Ti('Remote') %>">
<%- @Icon('minus-small') %>
</div>
<div class="filter-control filter-control-add js-add" title="<%- @Ti('Add') %>">
<%- @Icon('plus-small') %>
</div>
</div>
</div>
</div>
<div class="horizontal-filters"></div>
Oops, something went wrong.

0 comments on commit ae3e214

Please sign in to comment.