Init version of ticket search.
This commit is contained in:
parent
7c996c72ca
commit
a1ffce58c3
6 changed files with 172 additions and 13 deletions
|
@ -51,12 +51,87 @@ class App.Navigation extends App.Controller
|
|||
active_tab[href] = true
|
||||
)
|
||||
|
||||
search = @el.find('#global-search').val()
|
||||
@html App.view('navigation')(
|
||||
navbar_left: nav_left,
|
||||
navbar_right: nav_right,
|
||||
open_tab: open_tab,
|
||||
active_tab: active_tab,
|
||||
user: user,
|
||||
navbar_left: nav_left
|
||||
navbar_right: nav_right
|
||||
open_tab: open_tab
|
||||
active_tab: active_tab
|
||||
user: user
|
||||
tickets: @tickets || []
|
||||
search: search
|
||||
)
|
||||
|
||||
# set focus to search box
|
||||
if @searchFocus
|
||||
@searchFocusSet = true
|
||||
App.ClipBoard.setPosition( 'global-search', search.length )
|
||||
|
||||
else
|
||||
@searchFocusSet = false
|
||||
|
||||
searchFunction = =>
|
||||
App.Com.ajax(
|
||||
id: 'ticket_search'
|
||||
type: 'GET'
|
||||
url: '/api/tickets/search'
|
||||
data:
|
||||
term: @term
|
||||
processData: true,
|
||||
success: (data, status, xhr) =>
|
||||
console.log data
|
||||
|
||||
# load user collection
|
||||
if data.users
|
||||
App.Collection.load( type: 'User', data: data.users )
|
||||
|
||||
# load ticket collection
|
||||
if data.tickets
|
||||
App.Collection.load( type: 'Ticket', data: data.tickets )
|
||||
|
||||
@tickets = []
|
||||
|
||||
for ticket_raw in data.tickets
|
||||
ticket = App.Collection.find( 'Ticket', ticket_raw.id )
|
||||
@tickets.push ticket
|
||||
@render(user)
|
||||
)
|
||||
|
||||
# observer search box
|
||||
@el.find('#global-search').bind( 'focusin', (e) =>
|
||||
|
||||
# remember to set search box
|
||||
@searchFocus = true
|
||||
|
||||
# check if search is needed
|
||||
@term = @el.find('#global-search').val()
|
||||
return if @searchFocusSet
|
||||
return if !@term
|
||||
@delay( searchFunction, 200, 'search' )
|
||||
)
|
||||
|
||||
# remove search result
|
||||
@el.find('#global-search').bind( 'focusout', (e) =>
|
||||
@delay(
|
||||
=>
|
||||
@searchFocus = false
|
||||
@tickets = []
|
||||
@render(user)
|
||||
320
|
||||
)
|
||||
)
|
||||
|
||||
# prevent submit of search box
|
||||
@el.find('#global-search').parent().bind( 'submit', (e) =>
|
||||
e.preventDefault()
|
||||
)
|
||||
|
||||
# start search
|
||||
@el.find('#global-search').bind( 'keyup', (e) =>
|
||||
@term = @el.find('#global-search').val()
|
||||
return if !@term
|
||||
return if @term is search
|
||||
@delay( searchFunction, 200, 'search' )
|
||||
)
|
||||
|
||||
getItems: (data) ->
|
||||
|
|
|
@ -16,6 +16,16 @@ class App.ClipBoard
|
|||
_instance ?= new _Singleton
|
||||
_instance.getSelectedLast()
|
||||
|
||||
@getPosition: (el) ->
|
||||
if _instance == undefined
|
||||
_instance ?= new _Singleton
|
||||
_instance.getPosition(el)
|
||||
|
||||
@setPosition: ( el, pos ) ->
|
||||
if _instance == undefined
|
||||
_instance ?= new _Singleton
|
||||
_instance.setPosition( el, pos )
|
||||
|
||||
@keycode: (code) ->
|
||||
if _instance == undefined
|
||||
_instance ?= new _Singleton
|
||||
|
@ -71,6 +81,38 @@ class _Singleton
|
|||
getSelectedLast: ->
|
||||
@selectionLast
|
||||
|
||||
getPosition: (el) ->
|
||||
pos = 0
|
||||
el = document.getElementById(el)
|
||||
|
||||
# IE Support
|
||||
if document.selection
|
||||
el.focus()
|
||||
Sel = document.selection.createRange()
|
||||
Sel.moveStart( 'character', -el.value.length )
|
||||
pos = Sel.text.length
|
||||
|
||||
# Firefox support
|
||||
else if (el.selectionStart || el.selectionStart == '0')
|
||||
pos = el.selectionStart
|
||||
return pos
|
||||
|
||||
setPosition: (el, pos) ->
|
||||
el = document.getElementById(el)
|
||||
|
||||
# IE Support
|
||||
if el.setSelectionRange
|
||||
el.focus()
|
||||
el.setSelectionRange( pos, pos )
|
||||
|
||||
# Firefox support
|
||||
else if el.createTextRange
|
||||
range = el.createTextRange()
|
||||
range.collapse(true)
|
||||
range.moveEnd( 'character', pos )
|
||||
range.moveStart('character', pos)
|
||||
range.select()
|
||||
|
||||
keycode: (code) ->
|
||||
for key, value of @keycodesTable()
|
||||
if value.toString() is code.toString()
|
||||
|
|
|
@ -23,10 +23,17 @@
|
|||
<li class="<% if @active_tab[item.target] : %>active<% end %>"><a href="<%= item.target %>"><%- @T( item.name ) %></a></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<li class="dropdown <% if @tickets[0] : %>open<% end %>">
|
||||
<form class="navbar-search">
|
||||
<input id="global-search" class="search-query" type="search" value="<%= @search %>" placeholder="<%- @Ti( 'Search' ) %>" autocomplete="off"/>
|
||||
</form>
|
||||
<ul class="dropdown-menu">
|
||||
<% for ticket in @tickets: %>
|
||||
<li><a href="#ticket/zoom/<%= ticket.id %>"><%= ticket.title %> - Ticket#<%= ticket.number %></a></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<form class="navbar-search pull-left">
|
||||
<input class="search-query" type="search" value="" placeholder="<%- @Ti( 'Search' ) %>"/>
|
||||
</form>
|
||||
<div class="spinner"/>
|
||||
<% if @user: %>
|
||||
<ul class="nav pull-right">
|
||||
|
|
|
@ -455,4 +455,38 @@ class TicketsController < ApplicationController
|
|||
}
|
||||
end
|
||||
|
||||
# GET /api/tickets/search
|
||||
def search
|
||||
|
||||
# get params
|
||||
query = params[:term]
|
||||
limit = params[:limit] || 15
|
||||
|
||||
# do query
|
||||
tickets_all = Ticket.find(
|
||||
:all,
|
||||
:limit => limit,
|
||||
:conditions => ['title LIKE ? OR number LIKE ?', "%#{query}%", "%#{query}%" ],
|
||||
:order => 'created_at'
|
||||
)
|
||||
|
||||
# build result list
|
||||
tickets = []
|
||||
users = {}
|
||||
tickets_all.each do |ticket|
|
||||
ticket_tmp = Ticket.full_data(ticket.id)
|
||||
tickets.push ticket_tmp
|
||||
users[ ticket['owner_id'] ] = User.user_data_full( ticket['owner_id'] )
|
||||
users[ ticket['customer_id'] ] = User.user_data_full( ticket['customer_id'] )
|
||||
users[ ticket['created_by_id'] ] = User.user_data_full( ticket['created_by_id'] )
|
||||
end
|
||||
|
||||
# return result
|
||||
render :json => {
|
||||
:tickets => tickets,
|
||||
:users => users,
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -216,12 +216,12 @@ curl http://localhost/api/users/2.json -v -u #{login}:#{password} -H "Content-Ty
|
|||
end
|
||||
end
|
||||
|
||||
# DELETE /users/1
|
||||
# DELETE /api/users/1
|
||||
def destroy
|
||||
model_destory_render(User, params)
|
||||
end
|
||||
|
||||
# GET /user/search
|
||||
# GET /api/users/search
|
||||
def search
|
||||
|
||||
# get params
|
||||
|
|
|
@ -2,6 +2,7 @@ module ExtraRoutes
|
|||
def add(map)
|
||||
|
||||
# tickets
|
||||
map.match '/api/tickets/search', :to => 'tickets#search', :via => [:get, :post]
|
||||
map.match '/api/tickets', :to => 'tickets#index', :via => :get
|
||||
map.match '/api/tickets/:id', :to => 'tickets#show', :via => :get
|
||||
map.match '/api/tickets', :to => 'tickets#create', :via => :post
|
||||
|
|
Loading…
Reference in a new issue