diff --git a/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee index 6dbdb7f49..2dfc3b78d 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee @@ -265,12 +265,6 @@ class App.TicketCreate extends App.Controller params: params ) - # show template UI - # new App.WidgetTemplate( - # el: @el.find('.ticket_template') - # template_id: template['id'] - # ) - # set type selector @setFormTypeInUi( params['formSenderType'] ) @@ -473,12 +467,19 @@ class Sidebar extends App.Controller callback: showCustomer } + showTemplates = (el) => + + # show template UI + new App.WidgetTemplate( + el: el + #template_id: template['id'] + ) items.push { head: 'Templates' name: 'template' icon: 'templates' - #callback: showCustomer + callback: showTemplates } new App.Sidebar( diff --git a/app/assets/javascripts/app/controllers/widget/template.js.coffee b/app/assets/javascripts/app/controllers/widget/template.js.coffee index 7c12c8109..dd7e89f33 100644 --- a/app/assets/javascripts/app/controllers/widget/template.js.coffee +++ b/app/assets/javascripts/app/controllers/widget/template.js.coffee @@ -1,8 +1,9 @@ -class App.WidgetTemplate extends App.ControllerDrox +class App.WidgetTemplate extends App.Controller events: 'click [data-type=template_save]': 'create', 'click [data-type=template_select]': 'select', 'click [data-type=template_delete]': 'delete', + 'click .templates-welcome .create': 'showManage', constructor: -> super @@ -17,22 +18,37 @@ class App.WidgetTemplate extends App.ControllerDrox ] template = {} - if @template_id + if @template_id && App.Template.exists( @template_id ) template = App.Template.find( @template_id ) # insert data - @html @template( - file: 'widget/template' - header: 'Select Template:' - params: - template: template + @html App.view('widget/template')( + template: template ) new App.ControllerForm( el: @el.find('#form-template') - model: { configure_attributes: @configure_attributes, className: '' } + model: + configure_attributes: @configure_attributes 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) => e.preventDefault() @@ -40,9 +56,8 @@ class App.WidgetTemplate extends App.ControllerDrox params = @formParam(e.target) template = App.Template.find( params['template_id'] ) if confirm('Sure?') + @template_id = false template.destroy() - @template_id = undefined - @render() select: (e) => e.preventDefault() @@ -50,6 +65,7 @@ class App.WidgetTemplate extends App.ControllerDrox # get params params = @formParam(e.target) + @template_id = params['template_id'] template = App.Template.find( params['template_id'] ) App.Event.trigger 'ticket_create_rerender', template.attributes() @@ -60,6 +76,7 @@ class App.WidgetTemplate extends App.ControllerDrox form = @formParam( $('.ticket-create') ) params = @formParam(e.target) name = params['template_name'] + return if !name # delete params['template_name'] template = App.Template.findByAttribute( 'name', name ) @@ -82,7 +99,6 @@ class App.WidgetTemplate extends App.ControllerDrox template.save( done: -> ui.template_id = @.id - ui.render() fail: => @log 'error', 'save failed!' diff --git a/app/assets/javascripts/app/views/widget/template.jst.eco b/app/assets/javascripts/app/views/widget/template.jst.eco index 3b3461bad..cb50f3696 100644 --- a/app/assets/javascripts/app/views/widget/template.jst.eco +++ b/app/assets/javascripts/app/views/widget/template.jst.eco @@ -1,17 +1,23 @@ - -
No template created yet.
-With templates you can pre-fill ticket attributes.
-Choose attributes and then save them as a new template.
- \ No newline at end of file + + +No template created yet.
+With templates you can pre-fill ticket attributes.
+Choose attributes and then save them as a new template.
+ +