Improved html title management, added browser tests.

This commit is contained in:
Martin Edenhofer 2013-06-18 22:58:29 +02:00
parent 954e6994e5
commit 2954685696
6 changed files with 68 additions and 60 deletions

View file

@ -71,7 +71,6 @@ class App.TicketCreate extends App.Controller
activate: => activate: =>
@navupdate '#' @navupdate '#'
@title @meta().title
changed: => changed: =>
formCurrent = @formParam( @el.find('.ticket-create') ) formCurrent = @formParam( @el.find('.ticket-create') )

View file

@ -69,13 +69,15 @@ class App.TaskWidget extends App.Controller
meta = worker.meta() meta = worker.meta()
if meta if meta
data = meta data = meta
data.title = App.i18n.escape( data.title )
data.head = App.i18n.escape( data.head )
item = {} item = {}
item.task = task item.task = task
item.data = data item.data = data
item_list.push item item_list.push item
# set title
if task.active
@title data.title
@html App.view('task_widget')( @html App.view('task_widget')(
item_list: item_list item_list: item_list
taskBarActions: @_getTaskActions() taskBarActions: @_getTaskActions()

View file

@ -35,10 +35,6 @@ class App.TicketZoom extends App.Controller
activate: => activate: =>
@navupdate '#' @navupdate '#'
if @ticket
@title App.i18n.translateInline('Ticket Zoom') + ' ' + @ticket.number + ' ' + @ticket.title
else
@title App.i18n.translateInline('Loading...')
changed: => changed: =>
formCurrent = @formParam( @el.find('.ticket-update') ) formCurrent = @formParam( @el.find('.ticket-update') )
@ -76,8 +72,8 @@ class App.TicketZoom extends App.Controller
success: (data, status, xhr) => success: (data, status, xhr) =>
if @dataLastCall && !force if @dataLastCall && !force
# # return if ticket hasnt changed # return if ticket hasnt changed
# return if _.isEqual( @dataLastCall.ticket, data.ticket ) return if _.isEqual( @dataLastCall.ticket, data.ticket )
# return if ticket changed by my self # return if ticket changed by my self
return if data.ticket.updated_by_id is @Session.all().id return if data.ticket.updated_by_id is @Session.all().id
@ -87,13 +83,8 @@ class App.TicketZoom extends App.Controller
console.log('diff', diff) console.log('diff', diff)
if !_.isEmpty(diff) if !_.isEmpty(diff)
App.TaskManager.notify( @task_key ) App.TaskManager.notify( @task_key )
# if $('[name="body"]').val()
# App.Event.trigger 'notify', { # remember current data
# type: 'success'
# msg: App.i18n.translateInline('Ticket has changed!')
# timeout: 30000
# }
# return
@dataLastCall = data @dataLastCall = data
@load(data, force) @load(data, force)
@ -119,7 +110,6 @@ class App.TicketZoom extends App.Controller
# reset old indexes # reset old indexes
@ticket = undefined @ticket = undefined
@articles = undefined
# get edit form attributes # get edit form attributes
@edit_form = data.edit_form @edit_form = data.edit_form
@ -144,11 +134,6 @@ class App.TicketZoom extends App.Controller
# get data # get data
if !@ticket if !@ticket
@ticket = App.Collection.find( 'Ticket', @ticket_id ) @ticket = App.Collection.find( 'Ticket', @ticket_id )
if !@articles
@articles = []
for article_id in @ticket.article_ids
article = App.Collection.find( 'TicketArticle', article_id )
@articles.push article
# update taskbar with new meta data # update taskbar with new meta data
App.Event.trigger 'task:render' App.Event.trigger 'task:render'
@ -157,7 +142,6 @@ class App.TicketZoom extends App.Controller
@renderDone = true @renderDone = true
@html App.view('ticket_zoom')( @html App.view('ticket_zoom')(
ticket: @ticket ticket: @ticket
articles: @articles
nav: @nav nav: @nav
isCustomer: @isRole('Customer') isCustomer: @isRole('Customer')
) )
@ -185,7 +169,6 @@ class App.TicketZoom extends App.Controller
TicketTitle: => TicketTitle: =>
# show ticket title # show ticket title
new TicketTitle( new TicketTitle(
articles: @articles
ticket: @ticket ticket: @ticket
el: @el.find('.ticket-title') el: @el.find('.ticket-title')
) )
@ -193,7 +176,6 @@ class App.TicketZoom extends App.Controller
TicketInfo: => TicketInfo: =>
# show ticket info # show ticket info
new TicketInfo( new TicketInfo(
articles: @articles
ticket: @ticket ticket: @ticket
el: @el.find('.ticket-info') el: @el.find('.ticket-info')
) )
@ -201,7 +183,6 @@ class App.TicketZoom extends App.Controller
ArticleView: => ArticleView: =>
# show article # show article
new ArticleView( new ArticleView(
articles: @articles
ticket: @ticket ticket: @ticket
el: @el.find('.article-view') el: @el.find('.article-view')
ui: @ ui: @
@ -210,7 +191,6 @@ class App.TicketZoom extends App.Controller
Edit: => Edit: =>
# show edit # show edit
new Edit( new Edit(
articles: @articles
ticket: @ticket ticket: @ticket
el: @el.find('.edit') el: @el.find('.edit')
form_state: @form_state form_state: @form_state
@ -222,7 +202,6 @@ class App.TicketZoom extends App.Controller
TicketAction: => TicketAction: =>
# show ticket action row # show ticket action row
new TicketAction( new TicketAction(
articles: @articles
ticket: @ticket ticket: @ticket
el: @el.find('.ticket-action') el: @el.find('.ticket-action')
ui: @ ui: @
@ -238,8 +217,7 @@ class TicketTitle extends App.Controller
render: -> render: ->
@html App.view('ticket_zoom/ticket_title')( @html App.view('ticket_zoom/ticket_title')(
ticket: @ticket ticket: @ticket
articles: @articles
) )
update: (e) => update: (e) =>
@ -254,9 +232,12 @@ class TicketTitle extends App.Controller
.replace(/>/g, '>') .replace(/>/g, '>')
if title is '-' if title is '-'
title = '' title = ''
@ticket.title = title
@ticket.load( title: title ) # update title
@ticket.save() ticket = App.Collection.find( 'Ticket', @ticket.id )
ticket.title = title
ticket.load( 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'
@ -269,8 +250,7 @@ class TicketInfo extends App.Controller
render: -> render: ->
@html App.view('ticket_zoom/ticket_info')( @html App.view('ticket_zoom/ticket_info')(
ticket: @ticket ticket: @ticket
articles: @articles
) )
class TicketAction extends App.Controller class TicketAction extends App.Controller
@ -333,9 +313,10 @@ class Edit extends App.Controller
render: -> render: ->
ticket = App.Collection.find( 'Ticket', @ticket.id )
@html App.view('ticket_zoom/edit')( @html App.view('ticket_zoom/edit')(
ticket: @ticket ticket: ticket
articles: @articles
isCustomer: @isRole('Customer') isCustomer: @isRole('Customer')
) )
@ -370,13 +351,13 @@ class Edit extends App.Controller
] ]
@form_id = App.ControllerForm.formId() @form_id = App.ControllerForm.formId()
defaults = @form_state || @ticket defaults = @form_state || ticket
new App.ControllerForm( new App.ControllerForm(
el: @el.find('.form-ticket-update') el: @el.find('.form-ticket-update')
form_id: @form_id form_id: @form_id
model: model:
configure_attributes: @configure_attributes_ticket configure_attributes: @configure_attributes_ticket
className: 'update_ticket_' + @ticket.id className: 'update_ticket_' + ticket.id
params: defaults params: defaults
form_data: @edit_form form_data: @edit_form
) )
@ -386,7 +367,7 @@ class Edit extends App.Controller
form_id: @form_id form_id: @form_id
model: model:
configure_attributes: @configure_attributes_article configure_attributes: @configure_attributes_article
className: 'update_ticket_' + @ticket.id className: 'update_ticket_' + ticket.id
form_data: @edit_form form_data: @edit_form
params: defaults params: defaults
dependency: [ dependency: [
@ -426,7 +407,10 @@ class Edit extends App.Controller
update: (e) => update: (e) =>
e.preventDefault() e.preventDefault()
params = @formParam(e.target) params = @formParam(e.target)
@log 'TicketZoom', 'notice', 'update', params, @ticket
ticket = App.Collection.find( 'Ticket', @ticket.id )
@log 'TicketZoom', 'notice', 'update', params, ticket
article_type = App.Collection.find( 'TicketArticleType', params['ticket_article_type_id'] ) article_type = App.Collection.find( 'TicketArticleType', params['ticket_article_type_id'] )
# update ticket # update ticket
@ -440,7 +424,7 @@ class Edit extends App.Controller
ticket_update['owner_id'] = 1 ticket_update['owner_id'] = 1
# check if title exists # check if title exists
if !ticket_update['title'] && !@ticket.title if !ticket_update['title'] && !ticket.title
alert( App.i18n.translateContent('Title needed') ) alert( App.i18n.translateContent('Title needed') )
return return
@ -463,25 +447,25 @@ class Edit extends App.Controller
if params['body'].match(/attachment/i) || params['body'].match( attachmentTranslatedRegExp ) if params['body'].match(/attachment/i) || params['body'].match( attachmentTranslatedRegExp )
return if !confirm( App.i18n.translateContent('You use attachment in text but no attachment is attached. Do you want to continue?') ) return if !confirm( App.i18n.translateContent('You use attachment in text but no attachment is attached. Do you want to continue?') )
@ticket.load( ticket_update ) ticket.load( ticket_update )
@log 'TicketZoom', 'notice', 'update ticket', ticket_update, @ticket @log 'TicketZoom', 'notice', 'update ticket', ticket_update, ticket
# disable form # disable form
@formDisable(e) @formDisable(e)
errors = @ticket.validate() errors = ticket.validate()
if errors if errors
@log 'TicketZoom', 'error', 'update', errors @log 'TicketZoom', 'error', 'update', errors
@formEnable(e) @formEnable(e)
@ticket.save( ticket.save(
success: (r) => success: (r) =>
# create article # create article
if params['body'] if params['body']
article = new App.TicketArticle article = new App.TicketArticle
params.from = @Session.get( 'firstname' ) + ' ' + @Session.get( 'lastname' ) params.from = @Session.get( 'firstname' ) + ' ' + @Session.get( 'lastname' )
params.ticket_id = @ticket.id params.ticket_id = ticket.id
params.form_id = @form_id params.form_id = @form_id
if !params['internal'] if !params['internal']
@ -502,12 +486,12 @@ class Edit extends App.Controller
@log 'TicketZoom', 'error', 'update article', errors @log 'TicketZoom', 'error', 'update article', errors
article.save( article.save(
success: (r) => success: (r) =>
@ui.fetch( @ticket.id, true ) @ui.fetch( ticket.id, true )
error: (r) => error: (r) =>
@log 'TicketZoom', 'error', 'update article', r @log 'TicketZoom', 'error', 'update article', r
) )
else else
@ui.fetch( @ticket.id, true ) @ui.fetch( ticket.id, true )
# reset form after save # reset form after save
App.TaskManager.update( @task_key, { 'state': undefined }) App.TaskManager.update( @task_key, { 'state': undefined })
@ -534,6 +518,12 @@ class ArticleView extends App.Controller
render: -> render: ->
# get all articles
@articles = []
for article_id in @ticket.article_ids
article = App.Collection.find( 'TicketArticle', article_id )
@articles.push article
# rework articles # rework articles
for article in @articles for article in @articles
new Article( article: article ) new Article( article: article )

View file

@ -63,6 +63,7 @@ class _Singleton extends App.Controller
@include App.Log @include App.Log
constructor: -> constructor: ->
super
@workers = {} @workers = {}
@workersStarted = {} @workersStarted = {}
@activeTask = undefined @activeTask = undefined
@ -136,7 +137,8 @@ class _Singleton extends App.Controller
if task.key isnt key if task.key isnt key
if task.active if task.active
task.active = false task.active = false
task.save() if !task.isNew()
task.save()
else else
changed = false changed = false
if !task.active if !task.active
@ -146,13 +148,15 @@ class _Singleton extends App.Controller
changed = true changed = true
task.notify = false task.notify = false
if changed if changed
task.save() if !task.isNew()
task.save()
else else
for task in tasks for task in tasks
if @activeTask isnt task.key if @activeTask isnt task.key
if task.active if task.active
task.active = false task.active = false
task.save() if !task.isNew()
task.save()
# start worker for task if not exists # start worker for task if not exists
@startController(key, callback, params, state, to_not_show) @startController(key, callback, params, state, to_not_show)
@ -169,7 +173,7 @@ class _Singleton extends App.Controller
if worker && worker.activate if worker && worker.activate
worker.activate() worker.activate()
# return if controller is alreary started # return if controller is already started
return if @workersStarted[key] return if @workersStarted[key]
@workersStarted[key] = true @workersStarted[key] = true
@ -207,9 +211,9 @@ class _Singleton extends App.Controller
task = @get( key ) task = @get( key )
if !task if !task
throw "No such task with '#{key}' to update" throw "No such task with '#{key}' to update"
for item, value of params return if task.isNew()
task.updateAttribute(item, value) for item, value of params
# task.save() task.updateAttribute(item, value)
App.Event.trigger 'task:render' App.Event.trigger 'task:render'
remove: ( key, to_not_show = false ) => remove: ( key, to_not_show = false ) =>
@ -229,7 +233,8 @@ class _Singleton extends App.Controller
if !task if !task
throw "No such task with '#{key}' to notify" throw "No such task with '#{key}' to notify"
task.notify = true task.notify = true
task.save() if !task.isNew()
task.save()
App.Event.trigger 'task:render' App.Event.trigger 'task:render'
reorder: ( order ) => reorder: ( order ) =>
@ -241,7 +246,8 @@ class _Singleton extends App.Controller
prio++ prio++
if task.prio isnt prio if task.prio isnt prio
task.prio = prio task.prio = prio
task.save() if !task.isNew()
task.save()
reset: => reset: =>
App.Taskbar.deleteAll() App.Taskbar.deleteAll()
@ -280,7 +286,7 @@ class _Singleton extends App.Controller
=> =>
task = tasks.shift() task = tasks.shift()
@add(task.key, task.callback, task.params, true, task.state) @add(task.key, task.callback, task.params, true, task.state)
task_count * 500 task_count * 350
) )
App.Event.trigger 'taskbar:ready' App.Event.trigger 'taskbar:ready'

View file

@ -1,6 +1,6 @@
<div class="well taskbar"> <div class="well taskbar">
<% for item in @item_list: %> <% for item in @item_list: %>
<a href="<%- item.data.url %>" title="<%= item.data.title %>" class="btn btn-mini <% if item.task.active: %>active btn-success<% else if item.task.notify: %>active btn-warning<% else: %>btn-default<% end %>" data-key="<%- item.task.key %>"><span class="task"><%- item.data.head %></span><span data-type="close" class="icon-remove-circle" title="<%- @T('close') %>"></a> <a href="<%- item.data.url %>" title="<%= item.data.title %>" class="btn btn-mini <% if item.task.active: %>active btn-success<% else if item.task.notify: %>active btn-warning<% else: %>btn-default<% end %>" data-key="<%- item.task.key %>"><span class="task"><%= item.data.head %></span><span data-type="close" class="icon-remove-circle" title="<%- @T('close') %>"></a>
<% end %> <% end %>
<% if !_.isEmpty( @taskBarActions ): %> <% if !_.isEmpty( @taskBarActions ): %>
<div class="taskbar-new"> <div class="taskbar-new">

View file

@ -162,6 +162,9 @@ class TestCase < Test::Unit::TestCase
def browser_element_action(test, action, instance) def browser_element_action(test, action, instance)
#puts "NOTICE: " + action.inspect #puts "NOTICE: " + action.inspect
if action[:css] if action[:css]
if action[:css].match '###stack###'
action[:css].gsub! '###stack###', @stack
end
begin begin
if action[:range] == 'all' if action[:range] == 'all'
element = instance.find_elements( { :css => action[:css] } ) element = instance.find_elements( { :css => action[:css] } )
@ -200,6 +203,13 @@ class TestCase < Test::Unit::TestCase
end end
elsif action[:execute] == 'navigate' elsif action[:execute] == 'navigate'
instance.navigate.to( action[:to] ) instance.navigate.to( action[:to] )
elsif action[:execute] == 'reload'
instance.navigate.refresh
elsif action[:link]
if action[:link].match '###stack###'
action[:link].gsub! '###stack###', @stack
end
element = instance.find_element( { :partial_link_text => action[:link] } )
else else
assert( false, "(#{test[:name]}) unknow selector for '#{action[:element]}'" ) assert( false, "(#{test[:name]}) unknow selector for '#{action[:element]}'" )
end end
@ -292,6 +302,7 @@ class TestCase < Test::Unit::TestCase
elsif action[:execute] == 'check' elsif action[:execute] == 'check'
elsif action[:execute] == 'close_all_tasks' elsif action[:execute] == 'close_all_tasks'
elsif action[:execute] == 'navigate' elsif action[:execute] == 'navigate'
elsif action[:execute] == 'reload'
else else
assert( false, "(#{test[:name]}) unknow action '#{action[:execute]}'" ) assert( false, "(#{test[:name]}) unknow action '#{action[:execute]}'" )
end end