Some small bug fixed, improved error handling.

This commit is contained in:
Martin Edenhofer 2014-10-04 00:38:56 +02:00
parent fdbceaf39e
commit 511aa44b7d
9 changed files with 108 additions and 38 deletions

View file

@ -707,7 +707,7 @@ class App.ControllerForm extends App.Controller
# richtext # richtext
else if attribute.tag is 'richtext' else if attribute.tag is 'richtext'
item = $( App.view('generic/richtext')( attribute: attribute ) ) item = $( App.view('generic/richtext')( attribute: attribute ) )
item.ce( item.find('[contenteditable]').ce(
mode: attribute.type mode: attribute.type
maxlength: attribute.maxlength maxlength: attribute.maxlength
) )

View file

@ -2,12 +2,12 @@ class App.clickCatcher extends Spine.Controller
# clickCatcher has no template because it's a plain <div> # clickCatcher has no template because it's a plain <div>
className: 'clickCatcher' className: 'clickCatcher'
constructor: (holder, callback, zIndexScale) -> constructor: ->
super super
@render() if @callback and @holder @render() if @callback and @holder
triggerCallback: (event) => triggerCallback: (e) =>
event.stopPropagation() e.stopPropagation()
@callback() @callback()
@remove() @remove()

View file

@ -272,7 +272,7 @@ class App.TicketCreate extends App.Controller
# show text module UI # show text module UI
@textModule = new App.WidgetTextModule( @textModule = new App.WidgetTextModule(
el: @el.find('[data-name="body"]') el: @el.find('[data-name="body"]').parent()
) )
new Sidebar( new Sidebar(

View file

@ -594,6 +594,7 @@ class App.TicketZoom extends App.Controller
) )
taskGet: (area) => taskGet: (area) =>
return {} if !App.TaskManager.get(@task_key)
@localTaskData = App.TaskManager.get(@task_key).state || {} @localTaskData = App.TaskManager.get(@task_key).state || {}
if area if area
if !@localTaskData[area] if !@localTaskData[area]
@ -967,7 +968,8 @@ class Edit extends App.Controller
options: options:
duration: duration duration: duration
add_textarea_catcher: -> add_textarea_catcher: =>
if @ticketEdit.is(':visible')
@textareaCatcher = new App.clickCatcher @textareaCatcher = new App.clickCatcher
holder: @ticketEdit.offsetParent() holder: @ticketEdit.offsetParent()
callback: @close_textarea callback: @close_textarea

View file

@ -1,10 +1,12 @@
class App.UserOrganizationAutocompletion extends App.Controller class App.UserOrganizationAutocompletion extends App.Controller
className: 'dropdown js-recipientDropdown zIndex-2'
events: events:
'hide.bs.dropdown .js-recipientDropdown': 'hideOrganisationMembers' 'hide.bs.dropdown .js-recipientDropdown': 'hideOrganisationMembers'
'click .js-organisation': 'showOrganisationMembers' 'click .js-organisation': 'showOrganisationMembers'
'click .js-back': 'hideOrganisationMembers' 'click .js-back': 'hideOrganisationMembers'
'click .js-user': 'selectUser' 'click .js-user': 'selectUser'
'click .js-user-new': 'newUser' 'click .js-user-new': 'newUser'
'focus input': 'open'
constructor: (params) -> constructor: (params) ->
super super
@ -18,14 +20,29 @@ class App.UserOrganizationAutocompletion extends App.Controller
element: => element: =>
@el @el
open: =>
@el.addClass('open')
@catcher = new App.clickCatcher
holder: @el.offsetParent()
callback: @close
zIndexScale: 1
close: =>
@el.removeClass('open')
if @catcher
@catcher.remove()
selectUser: (e) -> selectUser: (e) ->
userId = $(e.target).parents('.recipientList-entry').data('user-id') userId = $(e.target).parents('.recipientList-entry').data('user-id')
if !userId if !userId
userId = $(e.target).data('user-id') userId = $(e.target).data('user-id')
@setUser(userId)
@close()
setUser: (userId) =>
@el.find('[name="' + @attribute.name + '"]').val( userId ).trigger('change') @el.find('[name="' + @attribute.name + '"]').val( userId ).trigger('change')
setUser: -> executeCallback: ->
userId = @el.find('[name="' + @attribute.name + '"]').val() userId = @el.find('[name="' + @attribute.name + '"]').val()
return if !userId return if !userId
return if !App.User.exists(userId) return if !App.User.exists(userId)
@ -63,14 +80,17 @@ class App.UserOrganizationAutocompletion extends App.Controller
@el.html App.view('generic/user_search/input')( @el.html App.view('generic/user_search/input')(
attribute: @attribute attribute: @attribute
) )
if !@attribute.disableCreateUser
@el.find('.recipientList').append( @buildUserNew() )
@el.find('[name="' + @attribute.name + '"]').on( @el.find('[name="' + @attribute.name + '"]').on(
'change', 'change',
(e) => (e) =>
@setUser() @executeCallback()
) )
@el.find('[name="' + @attribute.name + '_completion"]').on( @el.find('[name="' + @attribute.name + '_completion"]').on(
'keyup', 'keydown',
(e) => (e) =>
item = $(e.target).val().trim() item = $(e.target).val().trim()
@ -78,14 +98,61 @@ class App.UserOrganizationAutocompletion extends App.Controller
# clean input field on ESC # clean input field on ESC
if e.keyCode is 27 if e.keyCode is 27
# if org member selection is shwon, go back to member list
if @$('.recipientList-backClickArea').is(':visible')
@$('.recipientList-backClickArea').click()
return
# empty user selection and close
$(e.target).val('') $(e.target).val('')
item = '' item = ''
@close()
# ignore arrow keys # ignore arrow keys
return if e.keyCode is 37 if e.keyCode is 37
return if e.keyCode is 38 return
return if e.keyCode is 39
return if e.keyCode is 40 if e.keyCode is 39
return
# up / select upper item
if e.keyCode is 38
e.preventDefault()
recipientList = @$('.recipientList')
if recipientList.find('li.is-active').length is 0
recipientList.find('li').last().addClass('is-active')
else
if recipientList.find('li.is-active').prev().length isnt 0
recipientList.find('li.is-active').removeClass('is-active').prev().addClass('is-active')
return
# down / select lower item
if e.keyCode is 40
e.preventDefault()
recipientList = @$('.recipientList')
if recipientList.find('li.is-active').length is 0
recipientList.find('li').first().addClass('is-active')
else
if recipientList.find('li.is-active').next().length isnt 0
recipientList.find('li.is-active').removeClass('is-active').next().addClass('is-active')
return
# enter / take item
if e.keyCode is 13
e.preventDefault()
userId = @$('.recipientList').find('li.is-active').data('user-id')
if !userId
organisationId = @$('.recipientList').find('li.is-active').data('organisation-id')
if organisationId
@showOrganisationMembers(undefined, @$('.recipientList').find('li.is-active'))
return
if userId is 'new'
@newUser()
else
@setUser(userId)
@close()
return
# ignore shift # ignore shift
return if e.keyCode is 16 return if e.keyCode is 16
@ -97,10 +164,10 @@ class App.UserOrganizationAutocompletion extends App.Controller
return if e.keyCode is 18 return if e.keyCode is 18
# hide dropdown # hide dropdown
@el.find('.recipientList').html('') @$('.recipientList').empty()
@el.find('.recipientList-organisationMembers').remove() @$('.recipientList-organisationMembers').remove()
if !item && !@attribute.disableCreateUser if !item && !@attribute.disableCreateUser
@el.find('.recipientList').append( @buildUserNew() ) @$('.recipientList').append( @buildUserNew() )
# show dropdown # show dropdown
if item && ( !@attribute.minLengt || @attribute.minLengt <= item.length ) if item && ( !@attribute.minLengt || @attribute.minLengt <= item.length )
@ -142,10 +209,11 @@ class App.UserOrganizationAutocompletion extends App.Controller
@el.find('.recipientList').append( @buildUserNew() ) @el.find('.recipientList').append( @buildUserNew() )
) )
showOrganisationMembers: (e) => showOrganisationMembers: (e,listEntry) =>
if e
e.stopPropagation() e.stopPropagation()
listEntry = $(e.currentTarget) listEntry = $(e.currentTarget)
organisationId = listEntry.data('organisation-id') organisationId = listEntry.data('organisation-id')
@recipientList = @$('.recipientList') @recipientList = @$('.recipientList')
@ -195,6 +263,7 @@ class App.UserOrganizationAutocompletion extends App.Controller
complete: => @organisationList.addClass('hide') complete: => @organisationList.addClass('hide')
newUser: (e) => newUser: (e) =>
if e
e.preventDefault() e.preventDefault()
new UserNew( new UserNew(
parent: @ parent: @
@ -249,6 +318,7 @@ class UserNew extends App.ControllerModal
# force to reload object # force to reload object
callbackReload = (user) -> callbackReload = (user) ->
ui.parent.el.find('[name=customer_id]').val( user.id ).trigger('change') ui.parent.el.find('[name=customer_id]').val( user.id ).trigger('change')
ui.parent.close()
# start customer info controller # start customer info controller
ui.hide() ui.hide()

View file

@ -1 +1,3 @@
<div contenteditable="true" id="<%= @attribute.id %>" data-name="<%= @attribute.name %>" class="form-control <%= @attribute.class %>"><%= @attribute.value %></div> <div class="richtext">
<div contenteditable="true" id="<%= @attribute.id %>" data-name="<%= @attribute.name %>" class="form-control <%= @attribute.class %>"><%= @attribute.value %></div>
</div>

View file

@ -1,12 +1,8 @@
<div class="dropdown js-recipientDropdown"> <div class="u-positionOrigin">
<div class="dropdown-toggle u-positionOrigin" data-toggle="dropdown">
<input type="hidden" name="<%- @attribute.name %>" value="<%= @attribute.value %>"> <input type="hidden" name="<%- @attribute.name %>" value="<%= @attribute.value %>">
<input name="<%- @attribute.name %>_completion" class="ui-autocomplete-input form-control" autocapitalize="off" placeholder="<%- @attribute.placeholder %>" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true"> <input name="<%- @attribute.name %>_completion" class="ui-autocomplete-input form-control" autocapitalize="off" placeholder="<%- @attribute.placeholder %>" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">
</div> </div>
<div class="dropdown-menu" aria-labelledby="customer_id"> <div class="dropdown-menu" aria-labelledby="customer_id">
<ul class="recipientList" role="menu"></ul> <ul class="recipientList" role="menu"></ul>
</div>
</div> </div>

View file

@ -1,4 +1,4 @@
<li class="recipientList-entry recipientList-new u-clickable horizontal center js-user-new"> <li class="recipientList-entry recipientList-new u-clickable horizontal center js-user-new" data-user-id="new">
<div class="recipientList-iconSpacer centered"> <div class="recipientList-iconSpacer centered">
<div class="white plus icon"></div> <div class="white plus icon"></div>
</div> </div>

View file

@ -442,7 +442,7 @@ label {
margin-top: 0; margin-top: 0;
} }
.form-group .controls { .form-group .controls .richtext {
position: relative; position: relative;
} }