Moved ticket title edit to jquery plugin.

This commit is contained in:
Martin Edenhofer 2014-09-27 11:07:29 +02:00
parent 004fc87655
commit 45d9755068
2 changed files with 39 additions and 45 deletions

View file

@ -362,6 +362,9 @@ class App.TicketZoom extends App.Controller
@scrollTo( 0, offset ) @scrollTo( 0, offset )
@delay( scrollTo, 100, false ) @delay( scrollTo, 100, false )
# enable user popups
@userPopups()
@autosaveStart() @autosaveStart()
TicketTitle: => TicketTitle: =>
@ -509,9 +512,15 @@ class App.TicketZoom extends App.Controller
# validate article # validate article
articleParams = @formParam( @$('.article-add') ) articleParams = @formParam( @$('.article-add') )
console.log "submit article", articleParams console.log "submit article", articleParams
return
articleAttributes = App.TicketArticle.attributesGet( 'edit' ) articleAttributes = App.TicketArticle.attributesGet( 'edit' )
if articleParams['body'] || ( articleAttributes['body'] && articleAttributes['body']['null'] is false ) if articleParams['body'] || ( articleAttributes['body'] && articleAttributes['body']['null'] is false )
articleParams.from = @Session.get().displayName()
articleParams.ticket_id = ticket.id
articleParams.form_id = @form_id
if !articleParams['internal']
articleParams['internal'] = false
if @isRole('Customer') if @isRole('Customer')
sender = App.TicketArticleSender.findByAttribute( 'name', 'Customer' ) sender = App.TicketArticleSender.findByAttribute( 'name', 'Customer' )
type = App.TicketArticleType.findByAttribute( 'name', 'web' ) type = App.TicketArticleType.findByAttribute( 'name', 'web' )
@ -519,8 +528,9 @@ class App.TicketZoom extends App.Controller
articleParams.sender_id = sender.id articleParams.sender_id = sender.id
else else
sender = App.TicketArticleSender.findByAttribute( 'name', 'Agent' ) sender = App.TicketArticleSender.findByAttribute( 'name', 'Agent' )
type = App.TicketArticleType.find( params['type_id'] )
articleParams.sender_id = sender.id articleParams.sender_id = sender.id
type = App.TicketArticleType.findByAttribute( 'name', articleParams['type'] )
articleParams.type_id = type.id
article = new App.TicketArticle article = new App.TicketArticle
for key, value of articleParams for key, value of articleParams
@ -548,7 +558,9 @@ class App.TicketZoom extends App.Controller
#@autosaveStart() #@autosaveStart()
return return
article.load(params) console.log "article load", articleParams
#return
article.load(articleParams)
errors = article.validate() errors = article.validate()
if errors if errors
@log 'error', 'update article', errors @log 'error', 'update article', errors
@ -563,18 +575,7 @@ class App.TicketZoom extends App.Controller
ticket.article = article ticket.article = article
console.log('ARR', article) console.log('ARR', article)
return #return
ticket.save(
done: (r) =>
# reset form after save
App.TaskManager.update( @task_key, { 'state': {} })
@ui.fetch( ticket.id, true )
)
# submit changes # submit changes
ticket.save( ticket.save(
done: (r) => done: (r) =>
@ -602,28 +603,25 @@ class TicketTitle extends App.Controller
isCustomer: @isRole('Customer') isCustomer: @isRole('Customer')
) )
@$('.ticket-title-update').ce({
mode: 'textonly'
multiline: false
maxlength: 250
})
# show frontend times # show frontend times
@frontendTimeUpdate() @frontendTimeUpdate()
update: (e) => update: (e) =>
$this = $(e.target) title = $(e.target).ceg({ mode: 'textonly' }) || '-'
title = $this.html()
title = ('' + title)
.replace(/<.+?>/g, '')
title = ('' + title)
.replace(/&nbsp;/g, ' ')
.replace(/&amp;/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
if title is '-'
title = ''
# update title # update title
@ticket.title = title if title isnt @ticket.title
@ticket.save() @ticket.title = title
@ticket.save()
# update taskbar with new meta data # update taskbar with new meta data
App.Event.trigger 'task:render' App.Event.trigger 'task:render'
release: => release: =>
App.Ticket.unsubscribe( @subscribeId ) App.Ticket.unsubscribe( @subscribeId )
@ -646,8 +644,8 @@ class Edit extends App.Controller
'click .submit': 'update' 'click .submit': 'update'
'click [data-type="reset"]': 'reset' 'click [data-type="reset"]': 'reset'
'click .visibility-toggle': 'toggle_visibility' 'click .visibility-toggle': 'toggle_visibility'
'click .pop-selectable': 'select_type' 'click .pop-selectable': 'selectArticleType'
'click .pop-selected': 'show_selectable_types' 'click .pop-selected': 'showSelectableArticleType'
'focus textarea': 'open_textarea' 'focus textarea': 'open_textarea'
'input textarea': 'detect_empty_textarea' 'input textarea': 'detect_empty_textarea'
'click .recipient-picker': 'toggle_recipients' 'click .recipient-picker': 'toggle_recipients'
@ -676,7 +674,7 @@ class Edit extends App.Controller
ticket = App.Ticket.fullLocal( @ticket.id ) ticket = App.Ticket.fullLocal( @ticket.id )
# gets referenced in @set_type # gets referenced in @setArticleType
@type = 'note' @type = 'note'
articleTypes = [ articleTypes = [
{ {
@ -714,7 +712,6 @@ class Edit extends App.Controller
type: @type type: @type
articleTypes: articleTypes articleTypes: articleTypes
isCustomer: @isRole('Customer') isCustomer: @isRole('Customer')
formChanged: !_.isEmpty( App.TaskManager.get(@task_key).state )
) )
@form_id = App.ControllerForm.formId() @form_id = App.ControllerForm.formId()
@ -773,9 +770,6 @@ class Edit extends App.Controller
# start auto save # start auto save
#@autosaveStart() #@autosaveStart()
# enable user popups
@userPopups()
# show text module UI # show text module UI
if !@isRole('Customer') if !@isRole('Customer')
textModule = new App.WidgetTextModule( textModule = new App.WidgetTextModule(
@ -864,24 +858,24 @@ class Edit extends App.Controller
@el.addClass('is-public') @el.addClass('is-public')
@el.removeClass('is-internal') @el.removeClass('is-internal')
show_selectable_types: => showSelectableArticleType: =>
@el.find('.pop-selector').removeClass('hide') @el.find('.pop-selector').removeClass('hide')
@selectTypeCatcher = new App.clickCatcher @selectTypeCatcher = new App.clickCatcher
holder: @el.offsetParent() holder: @el.offsetParent()
callback: @hide_type callback: @hideSelectableArticleType
zIndexScale: 6 zIndexScale: 6
select_type: (e) => selectArticleType: (e) =>
@set_type $(e.target).data('value') @setArticleType $(e.target).data('value')
@hide_type() @hideSelectableArticleType()
@selectTypeCatcher.remove() @selectTypeCatcher.remove()
@selectTypeCatcher = null @selectTypeCatcher = null
hide_type: => hideSelectableArticleType: =>
@el.find('.pop-selector').addClass('hide') @el.find('.pop-selector').addClass('hide')
set_type: (type) -> setArticleType: (type) ->
typeIcon = @el.find('.pop-selected .icon') typeIcon = @el.find('.pop-selected .icon')
if @type if @type
typeIcon.removeClass @type typeIcon.removeClass @type

View file

@ -1,4 +1,4 @@
<h1><span contenteditable="true" class="ticket-title-update inline-edit"><%= @P( @ticket.title ) %></span></h1> <h1><span contenteditable="true" class="ticket-title-update textbox"><%= @P( @ticket.title ) %></span></h1>
<small class="task-subline"> <small class="task-subline">
<%- @C('ticket_hook') %> <span class="ticket-number"><%- @ticket.number %></span> - <%- @T('created') %> <span class="humanTimeFromNow" data-time="<%- @ticket.created_at %>">?</span> <% if !@isCustomer && @ticket.escalation_time: %> - <%- @T('escalation') %> <span class="humanTimeFromNow escalation" data-time="<%- @ticket.escalation_time %>">?</span><% end %> <%- @C('ticket_hook') %> <span class="ticket-number"><%- @ticket.number %></span> - <%- @T('created') %> <span class="humanTimeFromNow" data-time="<%- @ticket.created_at %>">?</span> <% if !@isCustomer && @ticket.escalation_time: %> - <%- @T('escalation') %> <span class="humanTimeFromNow escalation" data-time="<%- @ticket.escalation_time %>">?</span><% end %>