Fixed ticket templates.

This commit is contained in:
Martin Edenhofer 2014-09-17 23:33:47 +02:00
parent 62987c82e8
commit b040a2d2a7
3 changed files with 57 additions and 34 deletions

View file

@ -265,12 +265,6 @@ class App.TicketCreate extends App.Controller
params: params params: params
) )
# show template UI
# new App.WidgetTemplate(
# el: @el.find('.ticket_template')
# template_id: template['id']
# )
# set type selector # set type selector
@setFormTypeInUi( params['formSenderType'] ) @setFormTypeInUi( params['formSenderType'] )
@ -473,12 +467,19 @@ class Sidebar extends App.Controller
callback: showCustomer callback: showCustomer
} }
showTemplates = (el) =>
# show template UI
new App.WidgetTemplate(
el: el
#template_id: template['id']
)
items.push { items.push {
head: 'Templates' head: 'Templates'
name: 'template' name: 'template'
icon: 'templates' icon: 'templates'
#callback: showCustomer callback: showTemplates
} }
new App.Sidebar( new App.Sidebar(

View file

@ -1,8 +1,9 @@
class App.WidgetTemplate extends App.ControllerDrox class App.WidgetTemplate extends App.Controller
events: events:
'click [data-type=template_save]': 'create', 'click [data-type=template_save]': 'create',
'click [data-type=template_select]': 'select', 'click [data-type=template_select]': 'select',
'click [data-type=template_delete]': 'delete', 'click [data-type=template_delete]': 'delete',
'click .templates-welcome .create': 'showManage',
constructor: -> constructor: ->
super super
@ -17,22 +18,37 @@ class App.WidgetTemplate extends App.ControllerDrox
] ]
template = {} template = {}
if @template_id if @template_id && App.Template.exists( @template_id )
template = App.Template.find( @template_id ) template = App.Template.find( @template_id )
# insert data # insert data
@html @template( @html App.view('widget/template')(
file: 'widget/template'
header: 'Select Template:'
params:
template: template template: template
) )
new App.ControllerForm( new App.ControllerForm(
el: @el.find('#form-template') el: @el.find('#form-template')
model: { configure_attributes: @configure_attributes, className: '' } model:
configure_attributes: @configure_attributes
autofocus: false autofocus: false
) )
if App.Template.all().length is 0
@showWelcome()
else
@showManage()
showManage: (e) ->
if e
e.preventDefault()
@el.find('.templates-manage').show()
@el.find('.templates-welcome').hide()
showWelcome: (e) ->
if e
e.preventDefault()
@el.find('.templates-manage').hide()
@el.find('.templates-welcome').show()
delete: (e) => delete: (e) =>
e.preventDefault() e.preventDefault()
@ -40,9 +56,8 @@ class App.WidgetTemplate extends App.ControllerDrox
params = @formParam(e.target) params = @formParam(e.target)
template = App.Template.find( params['template_id'] ) template = App.Template.find( params['template_id'] )
if confirm('Sure?') if confirm('Sure?')
@template_id = false
template.destroy() template.destroy()
@template_id = undefined
@render()
select: (e) => select: (e) =>
e.preventDefault() e.preventDefault()
@ -50,6 +65,7 @@ class App.WidgetTemplate extends App.ControllerDrox
# get params # get params
params = @formParam(e.target) params = @formParam(e.target)
@template_id = params['template_id']
template = App.Template.find( params['template_id'] ) template = App.Template.find( params['template_id'] )
App.Event.trigger 'ticket_create_rerender', template.attributes() App.Event.trigger 'ticket_create_rerender', template.attributes()
@ -60,6 +76,7 @@ class App.WidgetTemplate extends App.ControllerDrox
form = @formParam( $('.ticket-create') ) form = @formParam( $('.ticket-create') )
params = @formParam(e.target) params = @formParam(e.target)
name = params['template_name'] name = params['template_name']
return if !name
# delete params['template_name'] # delete params['template_name']
template = App.Template.findByAttribute( 'name', name ) template = App.Template.findByAttribute( 'name', name )
@ -82,7 +99,6 @@ class App.WidgetTemplate extends App.ControllerDrox
template.save( template.save(
done: -> done: ->
ui.template_id = @.id ui.template_id = @.id
ui.render()
fail: => fail: =>
@log 'error', 'save failed!' @log 'error', 'save failed!'

View file

@ -1,17 +1,23 @@
<!--<form> <div class="templates-manage">
<form>
<label class="" for="template_name"><%- @T( 'Select Template' ) %></label>
<div id="form-template"></div> <div id="form-template"></div>
<button type="submit" class="btn btn-default" data-type="template_delete"><%- @T( 'Delete' ) %></button> <button type="submit" class="btn btn-default" data-type="template_delete"><%- @T( 'Delete' ) %></button>
<button type="submit" class="btn btn-default" data-type="template_select"><%- @T( 'Apply' ) %></button> <button type="submit" class="btn btn-default" data-type="template_select"><%- @T( 'Apply' ) %></button>
</form> </form>
<br> <hr>
<form> <form>
<fieldset> <fieldset>
<label class="" for="template_name"><%- @T( 'Save as Template' ) %></label> <label class="" for="template_name"><%- @T( 'Save as Template' ) %></label>
<input type="text" name="template_name" id="template_name" class="form-control" value="<%= @template.name %>"/> <input type="text" name="template_name" id="template_name" class="form-control" value="<%= @template.name %>"/>
</fieldset> </fieldset>
<button type="submit" class="btn btn-default" data-type="template_save"><%- @T( 'Save' ) %></button> <button type="submit" class="btn btn-default" data-type="template_save"><%- @T( 'Save' ) %></button>
</form>--> </form>
</div>
<div class="templates-welcome">
<p>No template created yet.</p> <p>No template created yet.</p>
<p>With templates you can pre-fill ticket attributes.</p> <p>With templates you can pre-fill ticket attributes.</p>
<p>Choose attributes and then save them as a new template.</p> <p>Choose attributes and then save them as a new template.</p>
<p><a class="create u-clickable">Save new template</a></p> <p><a class="create u-clickable">Save new template</a></p>
</div>