Added init version of templates.
This commit is contained in:
parent
44f80201ee
commit
682bd223a8
11 changed files with 259 additions and 22 deletions
|
@ -21,6 +21,11 @@ class Index extends App.Controller
|
||||||
|
|
||||||
@edit_form = undefined
|
@edit_form = undefined
|
||||||
|
|
||||||
|
# lisen if view need to be rerendert
|
||||||
|
Spine.bind 'ticket_create_rerender', (defaults) =>
|
||||||
|
@log 'rerender', defaults
|
||||||
|
@render(defaults)
|
||||||
|
|
||||||
fetch: () ->
|
fetch: () ->
|
||||||
# get data
|
# get data
|
||||||
@ajax = new App.Ajax
|
@ajax = new App.Ajax
|
||||||
|
@ -43,22 +48,46 @@ class Index extends App.Controller
|
||||||
@render()
|
@render()
|
||||||
)
|
)
|
||||||
|
|
||||||
render: ->
|
render: (template = {}) ->
|
||||||
|
|
||||||
|
# set defaults
|
||||||
|
defaults = template['options'] || {}
|
||||||
|
if !( 'ticket_state_id' of defaults )
|
||||||
|
defaults['ticket_state_id'] = App.TicketState.findByAttribute( 'name', 'new' )
|
||||||
|
if !( 'ticket_priority_id' of defaults )
|
||||||
|
defaults['ticket_priority_id'] = App.TicketPriority.findByAttribute( 'name', '2 normal' )
|
||||||
|
|
||||||
|
# remember customers
|
||||||
|
defaults['customer_id'] = $('#create_customer_id').val()
|
||||||
|
defaults['customer_id_autocompletion'] = $('#create_customer_id_autocompletion').val()
|
||||||
|
|
||||||
|
# generate form
|
||||||
configure_attributes = [
|
configure_attributes = [
|
||||||
{ name: 'customer_id', display: 'From', tag: 'autocompletion', type: 'text', limit: 100, null: false, relation: 'User', class: 'span7', autocapitalize: false, help: 'Select the customer of the Ticket or create one.', link: '<a href="" class="customer_new">»</a>', callback: @userInfo },
|
{ name: 'customer_id', display: 'From', tag: 'autocompletion', type: 'text', limit: 100, null: false, relation: 'User', class: 'span7', autocapitalize: false, help: 'Select the customer of the Ticket or create one.', link: '<a href="" class="customer_new">»</a>', callback: @userInfo },
|
||||||
{ name: 'group_id', display: 'Group', tag: 'select', multiple: false, null: false, filter: @edit_form, nulloption: true, relation: 'Group', class: 'span7', },
|
{ name: 'group_id', display: 'Group', tag: 'select', multiple: false, null: false, filter: @edit_form, nulloption: true, relation: 'Group', default: defaults['group_id'], class: 'span7', },
|
||||||
{ name: 'owner_id', display: 'Owner', tag: 'select', multiple: false, null: true, filter: @edit_form, nulloption: true, relation: 'User', class: 'span7', },
|
{ name: 'owner_id', display: 'Owner', tag: 'select', multiple: false, null: true, filter: @edit_form, nulloption: true, relation: 'User', default: defaults['owner_id'], class: 'span7', },
|
||||||
{ name: 'subject', display: 'Subject', tag: 'input', type: 'text', limit: 100, null: false, class: 'span7', },
|
{ name: 'subject', display: 'Subject', tag: 'input', type: 'text', limit: 100, null: false, default: defaults['subject'], class: 'span7', },
|
||||||
{ name: 'body', display: 'Text', tag: 'textarea', rows: 6, limit: 100, null: false, class: 'span7', },
|
{ name: 'body', display: 'Text', tag: 'textarea', rows: 6, null: false, default: defaults['body'], class: 'span7', },
|
||||||
{ name: 'ticket_state_id', display: 'State', tag: 'select', multiple: false, null: false, filter: @edit_form, relation: 'TicketState', default: 'new', class: 'medium' },
|
{ name: 'ticket_state_id', display: 'State', tag: 'select', multiple: false, null: false, filter: @edit_form, relation: 'TicketState', default: defaults['ticket_state_id'], class: 'medium' },
|
||||||
{ name: 'ticket_priority_id', display: 'Priority', tag: 'select', multiple: false, null: false, filter: @edit_form, relation: 'TicketPriority', default: '2 normal', class: 'medium' },
|
{ name: 'ticket_priority_id', display: 'Priority', tag: 'select', multiple: false, null: false, filter: @edit_form, relation: 'TicketPriority', default: defaults['ticket_priority_id'], class: 'medium' },
|
||||||
]
|
]
|
||||||
@html App.view('agent_ticket_create')(
|
@html App.view('agent_ticket_create')(
|
||||||
head: 'New Ticket',
|
head: 'New Ticket',
|
||||||
form: @formGen( model: { configure_attributes: configure_attributes, className: 'create' } ),
|
form: @formGen( model: { configure_attributes: configure_attributes, className: 'create' } ),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# start customer info controller
|
||||||
|
if defaults['customer_id']
|
||||||
|
$('#create_customer_id').val( defaults['customer_id'] )
|
||||||
|
$('#create_customer_id_autocompletion').val( defaults['customer_id_autocompletion'] )
|
||||||
|
@userInfo( user_id: defaults['customer_id'] )
|
||||||
|
|
||||||
|
# show template UI
|
||||||
|
new App.TemplateUI(
|
||||||
|
el: @el.find('#ticket_template'),
|
||||||
|
template_id: template['id'],
|
||||||
|
)
|
||||||
|
|
||||||
user_new: (e) =>
|
user_new: (e) =>
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
new UserNew()
|
new UserNew()
|
||||||
|
@ -81,8 +110,8 @@ class Index extends App.Controller
|
||||||
@log 'updateAttributes', params
|
@log 'updateAttributes', params
|
||||||
|
|
||||||
# find sender_id
|
# find sender_id
|
||||||
sender = App.TicketArticleSender.findByAttribute("name", "Customer")
|
sender = App.TicketArticleSender.findByAttribute( 'name', 'Customer' )
|
||||||
type = App.TicketArticleType.findByAttribute("name", "phone")
|
type = App.TicketArticleType.findByAttribute( 'name', 'phone' )
|
||||||
if params.group_id
|
if params.group_id
|
||||||
group = App.Group.find(params.group_id)
|
group = App.Group.find(params.group_id)
|
||||||
|
|
||||||
|
@ -174,8 +203,9 @@ class UserNew extends App.ControllerModal
|
||||||
user.save(
|
user.save(
|
||||||
success: (r) =>
|
success: (r) =>
|
||||||
@modalHide()
|
@modalHide()
|
||||||
|
realname = r.firstname + ' ' + r.lastname
|
||||||
$('#create_customer_id').val(r.id)
|
$('#create_customer_id').val(r.id)
|
||||||
$('#create_customer_id_autocompletion').val(r.firstname)
|
$('#create_customer_id_autocompletion').val(realname)
|
||||||
|
|
||||||
# start customer info controller
|
# start customer info controller
|
||||||
@userInfo( user_id: r.id )
|
@userInfo( user_id: r.id )
|
||||||
|
|
|
@ -168,7 +168,7 @@ class Index extends App.Controller
|
||||||
@start_page = @start_page + 1
|
@start_page = @start_page + 1
|
||||||
@fetch()
|
@fetch()
|
||||||
|
|
||||||
$('footer').waypoint( a, { offset: '140%', triggerOnce: true } )
|
$('footer').waypoint( a, { offset: '150%', triggerOnce: true } )
|
||||||
|
|
||||||
page: (e) =>
|
page: (e) =>
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
98
app/assets/javascripts/app/controllers/template.js.coffee
Normal file
98
app/assets/javascripts/app/controllers/template.js.coffee
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
$ = jQuery.sub()
|
||||||
|
|
||||||
|
class App.TemplateUI extends App.Controller
|
||||||
|
events:
|
||||||
|
'click [data-type=template_save]': 'create',
|
||||||
|
'click [data-type=template_select]': 'select',
|
||||||
|
'click [data-type=template_delete]': 'delete',
|
||||||
|
|
||||||
|
constructor: ->
|
||||||
|
super
|
||||||
|
|
||||||
|
# fetch item on demand
|
||||||
|
fetch_needed = 1
|
||||||
|
# if App.User.exists(@user_id)
|
||||||
|
# @user = App.User.find(@user_id)
|
||||||
|
# @log 'exists', @user
|
||||||
|
# fetch_needed = 0
|
||||||
|
# @render()
|
||||||
|
|
||||||
|
if fetch_needed
|
||||||
|
@reload()
|
||||||
|
|
||||||
|
reload: =>
|
||||||
|
App.Template.bind 'refresh', =>
|
||||||
|
@log 'loading....'
|
||||||
|
@render()
|
||||||
|
App.Template.unbind 'refresh'
|
||||||
|
App.Template.fetch()
|
||||||
|
|
||||||
|
render: =>
|
||||||
|
@configure_attributes = [
|
||||||
|
{ name: 'template_id', display: '', tag: 'select', multiple: false, null: true, nulloption: true, relation: 'Template', class: 'span2', default: @template_id },
|
||||||
|
]
|
||||||
|
form = @formGen( model: { configure_attributes: @configure_attributes, className: '' } )
|
||||||
|
|
||||||
|
template = {}
|
||||||
|
if @template_id
|
||||||
|
template = App.Template.find(@template_id)
|
||||||
|
|
||||||
|
# insert data
|
||||||
|
@html App.view('template')(
|
||||||
|
form: form,
|
||||||
|
template: template,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
delete: (e) =>
|
||||||
|
e.preventDefault()
|
||||||
|
|
||||||
|
# get params
|
||||||
|
params = @formParam(e.target)
|
||||||
|
template = App.Template.find( params['template_id'] )
|
||||||
|
template.destroy()
|
||||||
|
@template_id = undefined
|
||||||
|
@render()
|
||||||
|
|
||||||
|
select: (e) =>
|
||||||
|
e.preventDefault()
|
||||||
|
|
||||||
|
# get params
|
||||||
|
params = @formParam(e.target)
|
||||||
|
|
||||||
|
template = App.Template.find( params['template_id'] )
|
||||||
|
Spine.trigger 'ticket_create_rerender', template.attributes()
|
||||||
|
|
||||||
|
create: (e) =>
|
||||||
|
e.preventDefault()
|
||||||
|
|
||||||
|
# get params
|
||||||
|
params = @formParam(e.target)
|
||||||
|
name = params['template_name']
|
||||||
|
# delete params['template_name']
|
||||||
|
|
||||||
|
template = App.Template.findByAttribute( 'name', name )
|
||||||
|
if !template
|
||||||
|
template = new App.Template
|
||||||
|
|
||||||
|
options = params
|
||||||
|
template.load(
|
||||||
|
name: params['template_name']
|
||||||
|
options: options
|
||||||
|
)
|
||||||
|
|
||||||
|
# validate form
|
||||||
|
errors = template.validate()
|
||||||
|
|
||||||
|
# show errors in form
|
||||||
|
if errors
|
||||||
|
@log 'error new', errors
|
||||||
|
else
|
||||||
|
template.save(
|
||||||
|
success: (r) =>
|
||||||
|
@template_id = r.id
|
||||||
|
@render()
|
||||||
|
|
||||||
|
error: =>
|
||||||
|
@log 'save failed!'
|
||||||
|
)
|
|
@ -160,6 +160,27 @@ class App.Run extends Spine.Controller
|
||||||
# start content
|
# start content
|
||||||
new App.Content( el: @el.find('#content') );
|
new App.Content( el: @el.find('#content') );
|
||||||
|
|
||||||
|
@ws = new WebSocket("ws://localhost:3001/");
|
||||||
|
|
||||||
|
# Set event handlers.
|
||||||
|
@ws.onopen = ->
|
||||||
|
console.log("onopen")
|
||||||
|
|
||||||
|
@ws.onmessage = (e) ->
|
||||||
|
# e.data contains received string.
|
||||||
|
console.log("onmessage: " + e.data)
|
||||||
|
eval e.data
|
||||||
|
|
||||||
|
Spine.bind 'ws:send', (data) =>
|
||||||
|
@log 'ws:send', data
|
||||||
|
@ws.send(data);
|
||||||
|
|
||||||
|
@ws.onclose = ->
|
||||||
|
console.log("onclose")
|
||||||
|
|
||||||
|
@ws.onerror = ->
|
||||||
|
console.log("onerror")
|
||||||
|
|
||||||
class App.Content extends Spine.Controller
|
class App.Content extends Spine.Controller
|
||||||
className: 'container'
|
className: 'container'
|
||||||
|
|
||||||
|
@ -177,6 +198,9 @@ class App.Content extends Spine.Controller
|
||||||
@el.unbind()
|
@el.unbind()
|
||||||
@el.undelegate()
|
@el.undelegate()
|
||||||
|
|
||||||
|
# remove waypoints
|
||||||
|
$('footer').waypoint('remove')
|
||||||
|
|
||||||
params.el = @el
|
params.el = @el
|
||||||
params.auth = @auth
|
params.auth = @auth
|
||||||
new callback( params )
|
new callback( params )
|
||||||
|
|
3
app/assets/javascripts/app/models/template.js.coffee
Normal file
3
app/assets/javascripts/app/models/template.js.coffee
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
class App.Template extends App.Model
|
||||||
|
@configure 'Template', 'name', 'options', 'group_ids', 'user_id'
|
||||||
|
@extend Spine.Model.Ajax
|
|
@ -9,16 +9,10 @@
|
||||||
<!--
|
<!--
|
||||||
<legend>Example form legend</legend>
|
<legend>Example form legend</legend>
|
||||||
-->
|
-->
|
||||||
<!--
|
|
||||||
<div class="clearfix">
|
|
||||||
<label for="fileInput">File input</label>
|
|
||||||
<div class="input">
|
|
||||||
<input class="input-file" id="fileInput" name="fileInput" type="file" />
|
|
||||||
</div>
|
|
||||||
</div><!-- /clearfix -->
|
|
||||||
</div>
|
</div>
|
||||||
<div class="span3">
|
<div class="span3">
|
||||||
<div class="span3" id="customer_info"></div>
|
<div class="span3" id="customer_info"></div>
|
||||||
|
<div class="span3" id="ticket_template"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
|
|
11
app/assets/javascripts/app/views/template.jst.eco
Normal file
11
app/assets/javascripts/app/views/template.jst.eco
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<div class="well">
|
||||||
|
<h3>Templates</h3>
|
||||||
|
<%- @form %>
|
||||||
|
<!--<button type="submit" class="btn" data-type="template_edit">Edit</button>-->
|
||||||
|
<button type="submit" class="btn" data-type="template_delete">Delete</button>
|
||||||
|
<button type="submit" class="btn" data-type="template_select">Apply</button>
|
||||||
|
<hr/>
|
||||||
|
<label class="" for="template_name">Save as Template</label>
|
||||||
|
<input type="text" name="template_name" id="template_name" class="span2" value="<%= @template.name %>"/>
|
||||||
|
<button type="submit" class="btn" data-type="template_save">Save</button>
|
||||||
|
</div>
|
48
app/controllers/templates_controller.rb
Normal file
48
app/controllers/templates_controller.rb
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
class TemplatesController < ApplicationController
|
||||||
|
before_filter :authentication_check
|
||||||
|
|
||||||
|
# GET /templates
|
||||||
|
def index
|
||||||
|
@templates = Template.all
|
||||||
|
|
||||||
|
render :json => @templates
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /templates/1
|
||||||
|
def show
|
||||||
|
@template = Template.find(params[:id])
|
||||||
|
|
||||||
|
render :json => @template
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /templates
|
||||||
|
def create
|
||||||
|
@template = Template.new(params[:template])
|
||||||
|
@template.created_by_id = current_user.id
|
||||||
|
|
||||||
|
if @template.save
|
||||||
|
render :json => @template, :status => :created
|
||||||
|
else
|
||||||
|
render :json => @template.errors, :status => :unprocessable_entity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# PUT /templates/1
|
||||||
|
def update
|
||||||
|
@template = Template.find(params[:id])
|
||||||
|
|
||||||
|
if @template.update_attributes(params[:template])
|
||||||
|
render :json => @template, :status => :ok
|
||||||
|
else
|
||||||
|
render :json => @template.errors, :status => :unprocessable_entity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# DELETE /templates/1
|
||||||
|
def destroy
|
||||||
|
@template = Template.find(params[:id])
|
||||||
|
@template.destroy
|
||||||
|
|
||||||
|
head :ok
|
||||||
|
end
|
||||||
|
end
|
3
app/models/template.rb
Normal file
3
app/models/template.rb
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
class Template < ActiveRecord::Base
|
||||||
|
store :options
|
||||||
|
end
|
|
@ -19,6 +19,7 @@ Zammad::Application.routes.draw do
|
||||||
resources :groups, :only => [:create, :show, :index, :update]
|
resources :groups, :only => [:create, :show, :index, :update]
|
||||||
resources :roles, :only => [:create, :show, :index, :update]
|
resources :roles, :only => [:create, :show, :index, :update]
|
||||||
resources :organizations, :only => [:create, :show, :index, :update]
|
resources :organizations, :only => [:create, :show, :index, :update]
|
||||||
|
resources :templates
|
||||||
|
|
||||||
# overviews
|
# overviews
|
||||||
resources :overviews
|
resources :overviews
|
||||||
|
|
25
db/migrate/20120101000090_create_template.rb
Normal file
25
db/migrate/20120101000090_create_template.rb
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
class CreateTemplate < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
create_table :templates do |t|
|
||||||
|
t.references :user, :null => true
|
||||||
|
t.column :name, :string, :limit => 250, :null => false
|
||||||
|
t.column :options, :string, :limit => 2500, :null => false
|
||||||
|
t.column :created_by_id, :integer, :null => false
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
add_index :templates, [:user_id]
|
||||||
|
add_index :templates, [:name]
|
||||||
|
|
||||||
|
create_table :templates_groups, :id => false do |t|
|
||||||
|
t.integer :template_id
|
||||||
|
t.integer :group_id
|
||||||
|
end
|
||||||
|
add_index :templates_groups, [:template_id]
|
||||||
|
add_index :templates_groups, [:group_id]
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
drop_table :templates_groups
|
||||||
|
drop_table :templates
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue