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: =>
@navupdate '#'
@title @meta().title
changed: =>
formCurrent = @formParam( @el.find('.ticket-create') )

View file

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

View file

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

View file

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

View file

@ -1,6 +1,6 @@
<div class="well taskbar">
<% 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 %>
<% if !_.isEmpty( @taskBarActions ): %>
<div class="taskbar-new">

View file

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