diff --git a/app/assets/javascripts/app/controllers/_application_controller.js.coffee b/app/assets/javascripts/app/controllers/_application_controller.js.coffee index 6022c60a7..1fa1cb4e6 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.js.coffee @@ -85,7 +85,7 @@ class App.Controller extends Spine.Controller objects = _.clone( data.objects ) for object in objects for row in data_types - + # check if data is a object if typeof object[row.name] is 'object' if !object[row.name] @@ -95,8 +95,8 @@ class App.Controller extends Spine.Controller # if no content exists, try firstname/lastname if !object[row.name]['name'] - if object[row.name]['firstname'] || object[row.name]['lastname'] - object[row.name]['name'] = (object[row.name]['firstname'] || '') + ' ' + (object[row.name]['lastname'] || '') + if object[row.name]['realname'] + object[row.name]['name'] = object[row.name]['realname'] # if it isnt a object, create one else if typeof object[row.name] isnt 'object' @@ -112,7 +112,7 @@ class App.Controller extends Spine.Controller # execute callback on content if row.callback - object[row.name]['name'] = row.callback(object[row.name]['name']) + object[row.name]['name'] = row.callback( object[row.name]['name'] ) # lookup relation if !object[row.name]['name'] @@ -120,7 +120,7 @@ class App.Controller extends Spine.Controller for attribute in attributes if rowWithoutId is attribute.name if attribute.relation && App[attribute.relation] - record = App[attribute.relation].find( object[rowWithoutId] ) + record = App.Collection.find( attribute.relation, object[rowWithoutId] ) object[row.name]['name'] = record.name # @log 'table', 'header', header, 'overview', data_types, 'objects', objects @@ -158,12 +158,12 @@ class App.Controller extends Spine.Controller { name: 'ticket_priority', translate: true }, { name: 'group' }, { name: 'owner', class: 'user-data', data: { id: true } }, - { name: 'created_at', callback: @humanTime }, - { name: 'last_contact', callback: @humanTime }, - { name: 'last_contact_agent', callback: @humanTime }, - { name: 'last_contact_customer', callback: @humanTime }, - { name: 'first_response', callback: @humanTime }, - { name: 'close_time', callback: @humanTime }, + { name: 'created_at', callback: @frontendTime }, + { name: 'last_contact', callback: @frontendTime }, + { name: 'last_contact_agent', callback: @frontendTime }, + { name: 'last_contact_customer', callback: @frontendTime }, + { name: 'first_response', callback: @frontendTime }, + { name: 'close_time', callback: @frontendTime }, ] shown_all_attributes = [] for all_attribute in all_attributes @@ -190,25 +190,38 @@ class App.Controller extends Spine.Controller humanTime: (time) => current = new Date() created = new Date(time) - diff = (current - created) / 1000 + string = '' + diff = ( current - created ) / 1000 if diff >= 86400 - unit = Math.round( (diff / 86400) ) - if unit > 1 - return unit + ' ' + T('days') - else - return unit + ' ' + T('day') + unit = Math.round( ( diff / 86400 ) ) +# if unit > 1 +# return unit + ' ' + T('days') +# else +# return unit + ' ' + T('day') + string = unit + ' ' + T('d') if diff >= 3600 - unit = Math.round( (diff / 3600) ) - if unit > 1 - return unit + ' ' + T('hours') + unit = Math.round( ( diff / 3600 ) % 24 ) +# if unit > 1 +# return unit + ' ' + T('hours') +# else +# return unit + ' ' + T('hour') + if string isnt '' + string = string + ' ' + unit + ' ' + T('h') + return string else - return unit + ' ' + T('hour') - if diff <= 3600 - unit = Math.round( (diff / 60) ) - if unit > 1 - return unit + ' ' + T('minutes') + string = unit + ' ' + T('h') + if diff <= 86400 + unit = Math.round( ( diff / 60 ) % 60 ) +# if unit > 1 +# return unit + ' ' + T('minutes') +# else +# return unit + ' ' + T('minute') + if string isnt '' + string = string + ' ' + unit + ' ' + T('m') + return string else - return unit + ' ' + T('minute') + string = unit + ' ' + T('m') + return string userInfo: (data) => # start customer info controller @@ -230,6 +243,21 @@ class App.Controller extends Spine.Controller @navigate '#login' return false + frontendTime: (timestamp) -> + '?' + + frontendTimeUpdate: -> + update = => + ui = @ + $('.humanTimeFromNow').each( -> +# console.log('rewrite frontendTimeUpdate', this) + timestamp = $(this).data('time') + time = ui.humanTime( timestamp ) + $(this).attr( 'title', Ts(timestamp) ) + $(this).text( time ) + ) + @interval( update, 30000, 'frontendTimeUpdate' ) + clearInterval: (interval_id) => # check global var if !@intervalID @@ -237,13 +265,13 @@ class App.Controller extends Spine.Controller clearInterval( @intervalID[interval_id] ) if @intervalID[interval_id] - interval: (action, interval, interval_id) => + interval: (callback, interval, interval_id) => # check global var if !@intervalID @intervalID = {} - action() + callback() # auto save every = (ms, cb) -> setInterval cb, ms @@ -253,7 +281,7 @@ class App.Controller extends Spine.Controller # request new data @intervalID[interval_id] = every interval, () => - action() + callback() userPopups: (position = 'right') -> @@ -267,11 +295,11 @@ class App.Controller extends Spine.Controller placement: position, title: -> user_id = $(@).data('id') - user = App.User.find(user_id) - (user.firstname || '') + ' ' + (user.lastname || '') + user = App.Collection.find( 'User', user_id ) + user.realname content: -> user_id = $(@).data('id') - user = App.User.find(user_id) + user = App.Collection.find( 'User', user_id ) # get display data data = [] @@ -322,9 +350,8 @@ class App.Controller extends Spine.Controller type = $(@).filter('[data-type]').data('type') data = tickets[type] || [] + # set human time for ticket in data - - # set human time ticket.humanTime = controller.humanTime(ticket.created_at) # insert data @@ -333,129 +360,6 @@ class App.Controller extends Spine.Controller ) ) - loadCollection: (params) -> - - # remember in store if not already requested - if !params.localStorage - if params.type == 'User' - for user_id, user of params.data - data = {} - data[params.type] = {} - data[params.type][ user_id ] = user - App.Store.write( 'collection::' + params.type + '::' + user_id, { type: params.type, localStorage: true, collections: data } ) - else - for object in params.data - data = {} - data[params.type] = [ object ] - App.Store.write( 'collection::' + params.type + '::' + object.id, { type: params.type, localStorage: true, collections: data } ) - - # users - if params.type == 'User' - for user_id, user of params.data - - # set socal media links - if user['accounts'] - for account of user['accounts'] - if account == 'twitter' - user['accounts'][account]['link'] = 'http://twitter.com/' + user['accounts'][account]['username'] - if account == 'facebook' - user['accounts'][account]['link'] = 'https://www.facebook.com/profile.php?id=' + user['accounts'][account]['uid'] - - # set image url - if user && !user['image'] - user['image'] = 'http://placehold.it/48x48' - - # set realname - user['realname'] = '' - if user['firstname'] - user['realname'] = user['firstname'] - if user['lastname'] - if user['realname'] isnt '' - user['realname'] = user['realname'] + ' ' - user['realname'] = user['realname'] + user['lastname'] - - # load in collection if needed - if !params.collection - App.User.refresh( user, options: { clear: true } ) - - # tickets - else if params.type == 'Ticket' - for ticket in params.data - - # set human time - ticket.humanTime = @humanTime(ticket.created_at) - - # priority - ticket.ticket_priority = App.TicketPriority.find(ticket.ticket_priority_id) - - # state - ticket.ticket_state = App.TicketState.find(ticket.ticket_state_id) - - # group - ticket.group = App.Group.find(ticket.group_id) - - # customer - if ticket.customer_id and App.User.exists(ticket.customer_id) - user = App.User.find(ticket.customer_id) - ticket.customer = user - - # owner - if ticket.owner_id and App.User.exists(ticket.owner_id) - user = App.User.find(ticket.owner_id) - ticket.owner = user - - # load in collection if needed - if !params.collection - App.Ticket.refresh( ticket, options: { clear: true } ) - - # articles - else if params.type == 'TicketArticle' - for article in params.data - - # add user - article.created_by = App.User.find(article.created_by_id) - - # set human time - article.humanTime = @humanTime(article.created_at) - - # add possible actions - article.article_type = App.TicketArticleType.find( article.ticket_article_type_id ) - article.article_sender = App.TicketArticleSender.find( article.ticket_article_sender_id ) - - # load in collection if needed - if !params.collection - App.TicketArticle.refresh( article, options: { clear: true } ) - - # history - else if params.type == 'History' - for histroy in params.data - - # add user - histroy.created_by = App.User.find(histroy.created_by_id) - - # set human time - histroy.humanTime = @humanTime(histroy.created_at) - - # add possible actions - if histroy.history_attribute_id - histroy.attribute = App.HistoryAttribute.find( histroy.history_attribute_id ) - if histroy.history_type_id - histroy.type = App.HistoryType.find( histroy.history_type_id ) - if histroy.history_object_id - histroy.object = App.HistoryObject.find( histroy.history_object_id ) - - # load in collection if needed - if !params.collection - App.History.refresh( histroy, options: { clear: true } ) - - # all the rest - else - for object in params.data - - # load in collection if needed - if !params.collection - App[params.type].refresh( object, options: { clear: true } ) - ws_send: (data) -> Spine.trigger( 'ws:send', JSON.stringify(data) ) diff --git a/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee b/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee index b1aa2b112..e1f99e7bb 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee @@ -418,7 +418,8 @@ class App.ControllerForm extends App.Controller # if record.name.toString() is attribute.value.toString() # record.selected = 'selected' # record.checked = 'checked' - if ( attribute.value && record.value && _.include(attribute.value, record.value) ) || ( attribute.value && record.name && _.include(attribute.value, record.name) ) + + else if ( attribute.value && record.value && _.include(attribute.value, record.value) ) || ( attribute.value && record.name && _.include(attribute.value, record.name) ) record.selected = 'selected' record.checked = 'checked' diff --git a/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee b/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee index eb47b32be..bc344828f 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee @@ -32,18 +32,18 @@ class App.DashboardActivityStream extends App.Controller # processData: true, # success: @load # ) - + load: (data) => items = data.activity_stream # load user collection - @loadCollection( type: 'User', data: data.users ) + App.Collection.load( type: 'User', data: data.users ) # load ticket collection - @loadCollection( type: 'Ticket', data: data.tickets ) + App.Collection.load( type: 'Ticket', data: data.tickets ) # load article collection - @loadCollection( type: 'TicketArticle', data: data.articles ) + App.Collection.load( type: 'TicketArticle', data: data.articles ) @render(items) @@ -51,26 +51,26 @@ class App.DashboardActivityStream extends App.Controller # load user data for item in items - item.created_by = App.User.find( item.created_by_id ) - + item.created_by = App.Collection.find( 'User', item.created_by_id ) + # load ticket data for item in items item.data = {} if item.history_object is 'Ticket' - item.data.title = App.Ticket.find( item.o_id ).title + item.data.title = App.Collection.find( 'Ticket', item.o_id ).title if item.history_object is 'Ticket::Article' - article = App.TicketArticle.find( item.o_id ) + article = App.Collection.find( 'TicketArticle', item.o_id ) item.history_object = 'Article' item.sub_o_id = article.id item.o_id = article.ticket_id item.data.title = article.subject - + html = App.view('dashboard/activity_stream')( head: 'Activity Stream', items: items ) html = $(html) - + @html html # start user popups diff --git a/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee b/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee index 0a2404abc..6c24fd11f 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee @@ -24,10 +24,10 @@ class App.DashboardRecentViewed extends App.Controller @items = data.recent_viewed # load user collection - @loadCollection( type: 'User', data: data.users ) + App.Collection.load( type: 'User', data: data.users ) # load ticket collection - @loadCollection( type: 'Ticket', data: data.tickets ) + App.Collection.load( type: 'Ticket', data: data.tickets ) @render() ) @@ -36,13 +36,11 @@ class App.DashboardRecentViewed extends App.Controller # load user data for item in @items -# @log 'load', item.created_by_id - item.created_by = App.User.find(item.created_by_id) - + item.created_by = App.Collection.find( 'User', item.created_by_id ) + # load ticket data for item in @items -# @log 'load', item.o_id - item.ticket = App.Ticket.find(item.o_id) + item.ticket = App.Collection.find( 'User', item.o_id ) html = App.view('dashboard/recent_viewed')( head: 'Recent Viewed', diff --git a/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee b/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee index 6accc701d..cadd7690d 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee @@ -84,7 +84,7 @@ class App.DashboardTicket extends App.Controller while i < end i = i + 1 if @ticket_list[ i - 1 ] - @tickets_in_table.push App.Ticket.find( @ticket_list[ i - 1 ] ) + @tickets_in_table.push App.Collection.find( 'Ticket', @ticket_list[ i - 1 ] ) shown_all_attributes = @ticketTableAttributes( App.Overview.find(@overview.id).view.d.overview ) table = @table( @@ -102,6 +102,9 @@ class App.DashboardTicket extends App.Controller html.find('.table-overview').append(table) @html html + # show frontend times + @frontendTimeUpdate() + # start user popups @userPopups() 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 af6435efd..230e7687d 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee @@ -37,7 +37,7 @@ class Index extends App.Controller @edit_form = cache.edit_form # load user collection - @loadCollection( type: 'User', data: cache.users ) + App.Collection.load( type: 'User', data: cache.users ) @render() else @@ -59,19 +59,19 @@ class Index extends App.Controller @edit_form = data.edit_form # load user collection - @loadCollection( type: 'User', data: data.users ) + App.Collection.load( type: 'User', data: data.users ) # load ticket collection if data.ticket && data.articles - @loadCollection( type: 'Ticket', data: [data.ticket] ) + App.Collection.load( type: 'Ticket', data: [data.ticket] ) # load article collections - @loadCollection( type: 'TicketArticle', data: data.articles || [] ) + App.Collection.load( type: 'TicketArticle', data: data.articles || [] ) # render page - t = App.Ticket.find(params.ticket_id).attributes() - a = App.TicketArticle.find(params.article_id) - + t = App.Collection.find( 'Ticket', params.ticket_id ).attributes() + a = App.Collection.find( 'TicketArticle', params.article_id ) + # reset owner t.owner_id = 0 t.customer_id_autocompletion = a.from @@ -86,9 +86,9 @@ class Index extends App.Controller # set defaults defaults = template['options'] || {} if !( 'ticket_state_id' of defaults ) - defaults['ticket_state_id'] = App.TicketState.findByAttribute( 'name', 'new' ).id + defaults['ticket_state_id'] = App.Collection.findByAttribute( 'TicketState', 'name', 'new' ).id if !( 'ticket_priority_id' of defaults ) - defaults['ticket_priority_id'] = App.TicketPriority.findByAttribute( 'name', '2 normal' ).id + defaults['ticket_priority_id'] = App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' ).id # remember customers if $('#create_customer_id').val() @@ -163,10 +163,10 @@ class Index extends App.Controller @log 'updateAttributes', params # find sender_id - sender = App.TicketArticleSender.findByAttribute( 'name', 'Customer' ) - type = App.TicketArticleType.findByAttribute( 'name', 'phone' ) + sender = App.Collection.findByAttribute( 'TicketArticleSender', 'name', 'Customer' ) + type = App.Collection.findByAttribute( 'TicketArticleType', 'name', 'phone' ) if params.group_id - group = App.Group.find(params.group_id) + group = App.Collection.find( 'Group', params.group_id ) # create article params['article'] = { @@ -248,7 +248,7 @@ class UserNew extends App.ControllerModal user = new App.User # find role_id - role = App.Role.findByAttribute( 'name', 'Customer' ) + role = App.Collection.findByAttribute( 'Role', 'name', 'Customer' ) params.role_ids = role.id @log 'updateAttributes', params user.load(params) diff --git a/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee index 0a6fca357..791f74584 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee @@ -14,23 +14,23 @@ class App.TicketHistory extends App.ControllerModal @ticket = data.ticket # load user collection - @loadCollection( type: 'User', data: data.users ) + App.Collection.load( type: 'User', data: data.users ) # load ticket collection - @loadCollection( type: 'Ticket', data: [data.ticket] ) + App.Collection.load( type: 'Ticket', data: [data.ticket] ) # load history_type collections - @loadCollection( type: 'HistoryType', data: data.history_types ) + App.Collection.load( type: 'HistoryType', data: data.history_types ) # load history_object collections - @loadCollection( type: 'HistoryObject', data: data.history_objects ) + App.Collection.load( type: 'HistoryObject', data: data.history_objects ) # load history_attributes collections - @loadCollection( type: 'HistoryAttribute', data: data.history_attributes ) + App.Collection.load( type: 'HistoryAttribute', data: data.history_attributes ) # load history collections - App.History.deleteAll() - @loadCollection( type: 'History', data: data.history ) + App.Collection.deleteAll( 'History' ) + App.Collection.load( type: 'History', data: data.history ) # render page @render() @@ -39,7 +39,7 @@ class App.TicketHistory extends App.ControllerModal render: -> @html App.view('agent_ticket_history')( - objects: App.History.all(), + objects: App.Collection.all( 'History' ), ) @modalShow() diff --git a/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee index 4ddc3760e..bb469524a 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee @@ -9,9 +9,9 @@ class App.TicketMerge extends App.ControllerModal submit: (e) => e.preventDefault() - + params = @formParam(e.target) - + # merge tickets App.Com.ajax( id: 'ticket_merge', @@ -22,15 +22,18 @@ class App.TicketMerge extends App.ControllerModal } processData: true, success: (data, status, xhr) => - - if data['result'] is 'success' - @loadCollection( type: 'Ticket', data: [data.master_ticket] ) - @loadCollection( type: 'Ticket', data: [data.slave_ticket] ) + if data['result'] is 'success' + + # update collection + App.Collection.load( type: 'Ticket', data: [data.master_ticket] ) + App.Collection.load( type: 'Ticket', data: [data.slave_ticket] ) + + # hide dialog @modalHide() # view ticket - @log 'nav...', App.Ticket.find( data.master_ticket['id'] ) + @log 'nav...', App.Collection.find( 'Ticket', data.master_ticket['id'] ) @navigate '#ticket/zoom/' + data.master_ticket['id'] # notify UI diff --git a/app/assets/javascripts/app/controllers/agent_ticket_view.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_view.js.coffee index 8dade4ad8..ebdcf644b 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_view.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_view.js.coffee @@ -77,7 +77,7 @@ class Index extends App.Controller @ticket_list_show = [] for ticket_id in @ticket_list - @ticket_list_show.push App.Ticket.find(ticket_id) + @ticket_list_show.push App.Collection.find( 'Ticket', ticket_id ) # remeber bulk attributes @bulk = data.bulk @@ -159,6 +159,9 @@ class Index extends App.Controller # start user popups @userPopups() + # show frontend times + @frontendTimeUpdate() + # start bulk action observ @el.find('.bulk-action').append( @bulk_form() ) diff --git a/app/assets/javascripts/app/controllers/agent_ticket_zoom.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_zoom.js.coffee index 85b8e0663..f8a0ba8ce 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_zoom.js.coffee @@ -54,28 +54,26 @@ class Index extends App.Controller @edit_form = data.edit_form # load user collection - @loadCollection( type: 'User', data: data.users ) + App.Collection.load( type: 'User', data: data.users ) # load ticket collection - @loadCollection( type: 'Ticket', data: [data.ticket] ) + App.Collection.load( type: 'Ticket', data: [data.ticket] ) # load article collections - @loadCollection( type: 'TicketArticle', data: data.articles || [] ) + App.Collection.load( type: 'TicketArticle', data: data.articles ) # render page @render() render: => - return if !App.Ticket.exists(@ticket_id) - # get data if !@ticket - @ticket = App.Ticket.find(@ticket_id) + @ticket = App.Collection.find( 'Ticket', @ticket_id ) if !@articles @articles = [] for article_id in @ticket.article_ids - article = App.TicketArticle.find(article_id) + article = App.Collection.find( 'TicketArticle', article_id ) @articles.push article # rework articles @@ -146,6 +144,9 @@ class Index extends App.Controller # show ticket action row @ticket_action_row() + # show frontend times + @frontendTimeUpdate() + # scrall to article if given if @article_id offset = document.getElementById( 'article-' + @article_id ).offsetTop @@ -345,11 +346,11 @@ class Index extends App.Controller # find sender_id if @isRole('Customer') - sender = App.TicketArticleSender.findByAttribute( 'name', 'Customer' ) - type = App.TicketArticleType.findByAttribute( 'name', 'web' ) + sender = App.Collection.findByAttribute( 'TicketArticleSender', 'name', 'Customer' ) + type = App.Collection.findByAttribute( 'TicketArticleType', 'name', 'web' ) params['ticket_article_type_id'] = type.id else - sender = App.TicketArticleSender.findByAttribute( 'name', 'Agent' ) + sender = App.Collection.findByAttribute( 'TicketArticleSender', 'name', 'Agent' ) params.ticket_article_sender_id = sender.id @log 'updateAttributes', params, sender, sender.id article.load(params) diff --git a/app/assets/javascripts/app/controllers/customer_ticket_new.js.coffee b/app/assets/javascripts/app/controllers/customer_ticket_new.js.coffee index d27369246..dbec75586 100644 --- a/app/assets/javascripts/app/controllers/customer_ticket_new.js.coffee +++ b/app/assets/javascripts/app/controllers/customer_ticket_new.js.coffee @@ -31,7 +31,7 @@ class Index extends App.Controller @edit_form = cache.edit_form # load user collection - @loadCollection( type: 'User', data: cache.users ) + App.Collection.load( type: 'User', data: cache.users ) @render() else @@ -53,19 +53,19 @@ class Index extends App.Controller @edit_form = data.edit_form # load user collection - @loadCollection( type: 'User', data: data.users ) + App.Collection.load( type: 'User', data: data.users ) # load ticket collection if data.ticket && data.articles - @loadCollection( type: 'Ticket', data: [data.ticket] ) + App.Collection.load( type: 'Ticket', data: [data.ticket] ) # load article collections - @loadCollection( type: 'TicketArticle', data: data.articles || [] ) + App.Collection.load( type: 'TicketArticle', data: data.articles || [] ) # render page - t = App.Ticket.find(params.ticket_id).attributes() - a = App.TicketArticle.find(params.article_id) - + t = App.Collection.find( 'Ticket', params.ticket_id ).attributes() + a = App.Collection.find( 'TicketArticle', params.article_id ) + # reset owner t.owner_id = 0 t.customer_id_autocompletion = a.from @@ -80,9 +80,9 @@ class Index extends App.Controller # set defaults defaults = template['options'] || {} if !( 'ticket_state_id' of defaults ) - defaults['ticket_state_id'] = App.TicketState.findByAttribute( 'name', 'new' ) + defaults['ticket_state_id'] = App.Collection.findByAttribute( 'TicketState', 'name', 'new' ) if !( 'ticket_priority_id' of defaults ) - defaults['ticket_priority_id'] = App.TicketPriority.findByAttribute( 'name', '2 normal' ) + defaults['ticket_priority_id'] = App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' ) # generate form configure_attributes = [ @@ -126,11 +126,11 @@ class Index extends App.Controller params.customer_id = Session['id'] # set prio - priority = App.TicketPriority.findByAttribute( 'name', '2 normal' ) + priority = App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' ) params.ticket_state_id = priority.id # set state - state = App.TicketState.findByAttribute( 'name', 'new' ) + state = App.Collection.findByAttribute( 'TicketState', 'name', 'new' ) params.ticket_priority_id = state.id # fillup params @@ -142,10 +142,10 @@ class Index extends App.Controller @log 'updateAttributes', params # find sender_id - sender = App.TicketArticleSender.findByAttribute( 'name', 'Customer' ) - type = App.TicketArticleType.findByAttribute( 'name', 'web' ) + sender = App.Collection.findByAttribute( 'TicketArticleSender', 'name', 'Customer' ) + type = App.Collection.findByAttribute( 'TicketArticleType', 'name', 'web' ) if params.group_id - group = App.Group.find(params.group_id) + group = App.Collection.find( 'Group', params.group_id ) # create article params['article'] = { diff --git a/app/assets/javascripts/app/controllers/getting_started.js.coffee b/app/assets/javascripts/app/controllers/getting_started.js.coffee index b8d42cf60..f0bfc94db 100644 --- a/app/assets/javascripts/app/controllers/getting_started.js.coffee +++ b/app/assets/javascripts/app/controllers/getting_started.js.coffee @@ -35,7 +35,7 @@ class Index extends App.Controller @master_user = data.master_user # load group collection - @loadCollection( type: 'Group', data: data.groups ) + App.Collection.load( type: 'Group', data: data.groups ) # render page @render() @@ -80,7 +80,7 @@ class Index extends App.Controller @params.invite = true # find agent role - role = App.Role.findByAttribute('name', 'Agent') + role = App.Collection.findByAttribute( 'Role', 'name', 'Agent' ) if role @params.role_ids = role.id else diff --git a/app/assets/javascripts/app/controllers/link_info.js.coffee b/app/assets/javascripts/app/controllers/link_info.js.coffee index e39a19cbf..32275ba99 100644 --- a/app/assets/javascripts/app/controllers/link_info.js.coffee +++ b/app/assets/javascripts/app/controllers/link_info.js.coffee @@ -26,10 +26,10 @@ class App.LinkInfo extends App.Controller @links = data.links # load user collection - @loadCollection( type: 'User', data: data.users ) + App.Collection.load( type: 'User', data: data.users ) # load ticket collection - @loadCollection( type: 'Ticket', data: data.tickets ) + App.Collection.load( type: 'Ticket', data: data.tickets ) @render() ) @@ -42,7 +42,7 @@ class App.LinkInfo extends App.Controller list[ item['link_type'] ] = [] if item['link_object'] is 'Ticket' - ticket = App.Ticket.find( item['link_object_value'] ) + ticket = App.Collection.find( 'Ticket', item['link_object_value'] ) if ticket.ticket_state.name is 'merged' ticket.css = 'merged' list[ item['link_type'] ].push ticket diff --git a/app/assets/javascripts/app/controllers/navigation.js.coffee b/app/assets/javascripts/app/controllers/navigation.js.coffee index b38f3c7ce..58cd1f0e5 100644 --- a/app/assets/javascripts/app/controllers/navigation.js.coffee +++ b/app/assets/javascripts/app/controllers/navigation.js.coffee @@ -170,10 +170,10 @@ class App.Navigation extends App.Controller items = data.recent_viewed # load user collection - @loadCollection( type: 'User', data: data.users ) + App.Collection.load( type: 'User', data: data.users ) # load ticket collection - @loadCollection( type: 'Ticket', data: data.tickets ) + App.Collection.load( type: 'Ticket', data: data.tickets ) # remove old views for key of Config.NavBarRight @@ -190,7 +190,7 @@ class App.Navigation extends App.Controller if prio is 8000 divider = true navheader = 'Recent Viewed' - ticket = App.Ticket.find(item.o_id) + ticket = App.Collection.find( 'Ticket', item.o_id ) prio++ Config.NavBarRight['RecendViewed::' + ticket.id + '-' + prio ] = { prio: prio, diff --git a/app/assets/javascripts/app/controllers/template.js.coffee b/app/assets/javascripts/app/controllers/template.js.coffee index 6f6c3b673..599832162 100644 --- a/app/assets/javascripts/app/controllers/template.js.coffee +++ b/app/assets/javascripts/app/controllers/template.js.coffee @@ -11,7 +11,7 @@ class App.TemplateUI extends App.Controller # fetch item on demand fetch_needed = 1 - if App.Template.count() > 0 + if App.Collection.count( 'Template' ) > 0 fetch_needed = 0 @render() @@ -23,7 +23,7 @@ class App.TemplateUI extends App.Controller @log 'loading....' @render() App.Template.unbind 'refresh' - App.Template.fetch() + App.Collection.fetch( 'Template' ) render: => @configure_attributes = [ @@ -32,7 +32,7 @@ class App.TemplateUI extends App.Controller template = {} if @template_id - template = App.Template.find(@template_id) + template = App.Collection.find( 'Template', @template_id ) # insert data @html App.view('template')( @@ -49,7 +49,7 @@ class App.TemplateUI extends App.Controller # get params params = @formParam(e.target) - template = App.Template.find( params['template_id'] ) + template = App.Collection.find( 'Template', params['template_id'] ) if confirm('Sure?') template.destroy() @template_id = undefined @@ -61,7 +61,7 @@ class App.TemplateUI extends App.Controller # get params params = @formParam(e.target) - template = App.Template.find( params['template_id'] ) + template = App.Collection.find( 'Template', params['template_id'] ) Spine.trigger 'ticket_create_rerender', template.attributes() create: (e) => @@ -72,7 +72,7 @@ class App.TemplateUI extends App.Controller name = params['template_name'] # delete params['template_name'] - template = App.Template.findByAttribute( 'name', name ) + template = App.Collection.findByAttribute( 'Template', 'name', name ) if !template template = new App.Template diff --git a/app/assets/javascripts/app/controllers/user_info.js.coffee b/app/assets/javascripts/app/controllers/user_info.js.coffee index 11bf1a91c..79d3ec689 100644 --- a/app/assets/javascripts/app/controllers/user_info.js.coffee +++ b/app/assets/javascripts/app/controllers/user_info.js.coffee @@ -6,29 +6,9 @@ class App.UserInfo extends App.Controller constructor: -> super + App.Collection.find( 'User', @user_id, @render ) - # fetch item on demand - fetch_needed = 1 - if App.User.exists(@user_id) - @log 'exists.user...', @user_id - fetch_needed = 0 - @render(@user_id) - - if fetch_needed - @reload(@user_id) - - reload: (user_id) => - App.User.bind 'refresh', => - @log 'loading.user...', user_id - App.User.unbind 'refresh' - @render(user_id) - App.User.fetch( id: user_id ) - - render: (user_id) -> - - # load user collection - user = App.User.find(user_id) - @loadCollection( type: 'User', data: { new: user }, collection: true ) + render: (user) => # get display data data = [] @@ -39,20 +19,20 @@ class App.UserInfo extends App.Controller # insert data @html App.view('user_info')( - user: App.User.find(user_id), + user: user, data: data, ) @userTicketPopups( selector: '.user-tickets', - user_id: user_id, + user_id: user.id, ) update: (e) => # update changes note = $(e.target).parent().find('[data-type=edit]').val() - user = App.User.find(@user_id) + user = App.Collection.find( 'User', @user_id ) if user.note isnt note user.updateAttributes( note: note ) @log 'update', e, note, user diff --git a/app/assets/javascripts/app/index.js.coffee b/app/assets/javascripts/app/index.js.coffee index 38e38cef2..552669b61 100644 --- a/app/assets/javascripts/app/index.js.coffee +++ b/app/assets/javascripts/app/index.js.coffee @@ -13,7 +13,7 @@ #= require ./lib/bootstrap-tab.js #= require ./lib/bootstrap-transition.js -#= require ./lib/underscore.coffee +#= require ./lib/underscore-1.3.3.js #= require ./lib/ba-linkify.js #= require ./lib/jquery.tagsinput.js #= require ./lib/jquery.noty.js @@ -28,6 +28,7 @@ #= require ./lib/auth.js.coffee #= require ./lib/i18n.js.coffee #= require ./lib/store.js.coffee +#= require ./lib/collection.js.coffee #= require_tree ./models #= require_tree ./controllers #= require_tree ./views diff --git a/app/assets/javascripts/app/lib/auth.js.coffee b/app/assets/javascripts/app/lib/auth.js.coffee index 63b5d80ca..6db8e4618 100644 --- a/app/assets/javascripts/app/lib/auth.js.coffee +++ b/app/assets/javascripts/app/lib/auth.js.coffee @@ -65,9 +65,8 @@ class App.Auth App.WebSocket.auth() # refresh/load default collections - controller = new App.Controller for key, value of data.default_collections - controller.loadCollection( type: key, data: value ) + App.Collection.load( type: key, data: value ) # rebuild navbar with new navbar items Spine.trigger 'navrebuild', data.session diff --git a/app/assets/javascripts/app/lib/collection.js.coffee b/app/assets/javascripts/app/lib/collection.js.coffee new file mode 100644 index 000000000..30df82bff --- /dev/null +++ b/app/assets/javascripts/app/lib/collection.js.coffee @@ -0,0 +1,222 @@ +class App.Collection + _instance = undefined + + @init: -> + _instance = new _Singleton + + @load: ( args ) -> + if _instance == undefined + _instance ?= new _Singleton + _instance.load( args ) + + @find: ( type, id, callback ) -> + if _instance == undefined + _instance ?= new _Singleton + _instance.find( type, id, callback ) + + @get: ( args ) -> + if _instance == undefined + _instance ?= new _Singleton + _instance.get( args ) + + @all: ( type ) -> + if _instance == undefined + _instance ?= new _Singleton + _instance.all( type ) + + @deleteAll: ( type ) -> + if _instance == undefined + _instance ?= new _Singleton + _instance.deleteAll( type ) + + @findByAttribute: ( type, key, value ) -> + if _instance == undefined + _instance ?= new _Singleton + _instance.findByAttribute( type, key, value ) + + @count: ( type ) -> + if _instance == undefined + _instance ?= new _Singleton + _instance.count( type ) + + @fetch: ( type ) -> + if _instance == undefined + _instance ?= new _Singleton + _instance.fetch( type ) + +class _Singleton + + constructor: (@args) -> + + # add trigger - bind new events + Spine.bind 'loadCollection', (data) => + + # load collections + if data.collections + for type of data.collections + + console.log 'loadCollection:trigger', type, data.collections[type] + @load( localStorage: data.localStorage, type: type, data: data.collections[type] ) + + # find collections to load + @_loadCollectionAll() + + _loadCollectionAll: -> + list = App.Store.list() + for key in list + parts = key.split('::') + if parts[0] is 'collection' + data = App.Store.get( key ) + if data && data.localStorage + console.log('load INIT', data) + @load( data ) + + load: (params) -> + console.log( 'load', params ) + + return if _.isEmpty( params.data ) + + if _.isArray( params.data ) + for object in params.data + console.log( 'load ARRAY', object) + App[params.type].refresh( object, options: { clear: true } ) + + # remember in store if not already requested from local storage + if !params.localStorage + App.Store.write( 'collection::' + params.type + '::' + object.id, { type: params.type, localStorage: true, data: [ object ] } ) + return + +# if _.isObject( params.data ) + for key, object of params.data + console.log( 'load OB', object) + App[params.type].refresh( object, options: { clear: true } ) + + # remember in store if not already requested from local storage + if !params.localStorage + App.Store.write( 'collection::' + params.type + '::' + object.id, { type: params.type, localStorage: true, data: [ object ] } ) + + find: ( type, id, callback ) -> + + console.log( 'find', type, id ) +# if App[type].exists( id ) && !callback + if App[type].exists( id ) + console.log( 'find exists', type, id ) + data = App[type].find( id ) + if callback + callback( data ) + else + console.log( 'find not loaded!', type, id ) + if callback + App[type].bind 'refresh', -> + console.log 'loaded..' + type + '..', id + App[type].unbind 'refresh' + data = App.Collection.find( type, id ) + callback( data ) + console.log 'loading..' + type + '..', id + App[type].fetch( id: id ) + return true + return false + + # users + if type == 'User' + + # set socal media links + if data['accounts'] + for account of data['accounts'] + if account == 'twitter' + data['accounts'][account]['link'] = 'http://twitter.com/' + data['accounts'][account]['username'] + if account == 'facebook' + data['accounts'][account]['link'] = 'https://www.facebook.com/profile.php?id=' + data['accounts'][account]['uid'] + + # set image url + if data && !data['image'] + data['image'] = 'http://placehold.it/48x48' + + # set realname + data['realname'] = '' + if data['firstname'] + data['realname'] = data['firstname'] + if data['lastname'] + if data['realname'] isnt '' + data['realname'] = data['realname'] + ' ' + data['realname'] = data['realname'] + data['lastname'] + + return data + + # tickets + else if type == 'Ticket' + + # priority + data.ticket_priority = @find( 'TicketPriority', data.ticket_priority_id ) + + # state + data.ticket_state = @find( 'TicketState', data.ticket_state_id ) + + # group + data.group = @find( 'Group', data.group_id ) + + # customer + if data.customer_id + data.customer = @find( 'User', data.customer_id ) + + # owner + if data.owner_id + data.owner = @find( 'User', data.owner_id ) + + # add created & updated + if data.created_by_id + data.created_by = @find( 'User', data.created_by_id ) + if data.updated_by_id + data.updated_by = @find( 'User', data.updated_by_id ) + + return data + + # articles + else if type == 'TicketArticle' + + # add created & updated + data.created_by = @find( 'User', data.created_by_id ) + + # add possible actions + data.article_type = @find( 'TicketArticleType', data.ticket_article_type_id ) + data.article_sender = @find( 'TicketArticleSender', data.ticket_article_sender_id ) + + return data + + # history + else if type == 'History' + + # add user + data.created_by = @find( 'User', data.created_by_id ) + + # add possible actions + if data.history_attribute_id + data.attribute = @find( 'HistoryAttribute', data.history_attribute_id ) + if data.history_type_id + data.type = @find( 'HistoryType', data.history_type_id ) + if data.history_object_id + data.object = @find( 'HistoryObject', data.history_object_id ) + + return data + + else + return data + + get: (params) -> + console.log('get') + App[params.type].refresh( object, options: { clear: true } ) + + all: (type) -> + App[type].all() + + deleteAll: (type) -> + App[type].deleteAll() + + findByAttribute: ( type, key, value ) -> + App[type].findByAttribute( key, value ) + + count: ( type ) -> + App[type].count() + + fetch: ( type ) -> + App[type].fetch() diff --git a/app/assets/javascripts/app/lib/interface_handle.js.coffee b/app/assets/javascripts/app/lib/interface_handle.js.coffee index 87933712d..db60d3e7b 100644 --- a/app/assets/javascripts/app/lib/interface_handle.js.coffee +++ b/app/assets/javascripts/app/lib/interface_handle.js.coffee @@ -5,36 +5,26 @@ class App.Run extends App.Controller @log 'RUN app' @el = $('#app') + # init collections + App.Collection.init() + # create web socket connection App.WebSocket.connect() # init of i18n new App.i18n - # bind new events - Spine.bind 'loadCollection', (data) => - - # load collections - if data.collections - for key of data.collections - - @log 'loadCollection', key, data.collections[key] - @loadCollection( localStorage: data.localStorage, type: key, data: data.collections[key] ) - - # load collections - App.Store.load() - # start navigation controller - new App.Navigation( el: @el.find('#navigation') ); + new App.Navigation( el: @el.find('#navigation') ) # check if session already exists/try to get session data from server App.Auth.loginCheck() # start notify controller - new App.Notify( el: @el.find('#notify') ); + new App.Notify( el: @el.find('#notify') ) # start content - new App.Content( el: @el.find('#content') ); + new App.Content( el: @el.find('#content') ) # bind to fill selected text into $(@el).bind('mouseup', => diff --git a/app/assets/javascripts/app/lib/store.js.coffee b/app/assets/javascripts/app/lib/store.js.coffee index 854a9dd79..3507d5ead 100644 --- a/app/assets/javascripts/app/lib/store.js.coffee +++ b/app/assets/javascripts/app/lib/store.js.coffee @@ -3,10 +3,6 @@ class App.Store @renew: -> _instance = new _Singleton - @load: -> - if _instance == undefined - _instance ?= new _Singleton - @write: (key, value) -> if _instance == undefined _instance ?= new _Singleton @@ -22,10 +18,10 @@ class App.Store _instance ?= new _Singleton _instance.delete(args) - @clear: (args) -> + @clear: -> if _instance == undefined _instance ?= new _Singleton - _instance.clear(args) + _instance.clear() @list: () -> if _instance == undefined @@ -34,94 +30,32 @@ class App.Store # The actual Singleton class class _Singleton - store: {} - constructor: (@args) -> + # write to local storage + write: (key, value) -> + localStorage.setItem( key, JSON.stringify( value ) ) - # find collections to load - @_loadCollectionAll() - @_loadCollectionType('TicketPriority') - @_loadCollectionType('TicketStateType') - @_loadCollectionType('TicketState') - @_loadCollectionType('TicketArticleSender') - @_loadCollectionType('TicketArticleType') - @_loadCollectionType('Group') - @_loadCollectionType('Role') - @_loadCollectionType('Organization') - @_loadCollectionType('User') - @_loadCollectionType() + # get item + get: (key) -> + value = localStorage.getItem( key ) + return if !value + object = JSON.parse( value ) + return object - _loadCollectionAll: -> - @all = {} - @rest = {} + # delete item + delete: (key) -> + localStorage.removeItem( key ) + + # clear local storage + clear: -> + localStorage.clear() + + # return list of all keys + list: -> + list = [] logLength = localStorage.length-1; for count in [0..logLength] key = localStorage.key( count ) if key - value = localStorage.getItem( key ) - data = JSON.parse( value ) - @all[key] = data - - _loadCollectionType: (type) -> -# console.log('STORE NEW' + logLength) - toGo = @all - if !_.isEmpty( @rest ) - toGo = _.clone( @rest ) - @rest = {} - for key, data of toGo -# console.log('STORE NEW' + count + '-' + key, data) - if data['collections'] - data['localStorage'] = true - - if type - if data['type'] is type - @_loadCollection(data) - else - @rest[key] = data - else - @_loadCollection(data) - - _loadCollection: (data) -> - console.log('fire', 'loadCollection', data ) - Spine.trigger( 'loadCollection', data ) - - write: (key, value) -> - - # write to instance - @store[ key ] = value - - # write to local storage - localStorage.setItem( key, JSON.stringify( value ) ) - - get: (key) -> - - # return from instance - return @store[ key ] if @store[ key ] - - # if not, return from local storage - value = localStorage.getItem( key ) - object = JSON.parse( value ) - return object if object - - # return undefined if not in storage - return undefined - - delete: (key) -> - delete @store[ key ] - - clear: (action) -> - - console.log 'Store:clear', action - - # clear instance data - @store = {} - - # clear local storage - if action is 'all' - localStorage.clear() - - list: () -> - list = [] - for key of @store - list.push key + list.push key list \ No newline at end of file diff --git a/app/assets/javascripts/app/lib/underscore-1.3.3.js b/app/assets/javascripts/app/lib/underscore-1.3.3.js new file mode 100644 index 000000000..e85bfc04c --- /dev/null +++ b/app/assets/javascripts/app/lib/underscore-1.3.3.js @@ -0,0 +1,1059 @@ +// Underscore.js 1.3.3 +// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. +// Underscore may be freely distributed under the MIT license. +// Portions of Underscore are inspired or borrowed from Prototype, +// Oliver Steele's Functional, and John Resig's Micro-Templating. +// For all details and documentation: +// http://documentcloud.github.com/underscore + +(function() { + + // Baseline setup + // -------------- + + // Establish the root object, `window` in the browser, or `global` on the server. + var root = this; + + // Save the previous value of the `_` variable. + var previousUnderscore = root._; + + // Establish the object that gets returned to break out of a loop iteration. + var breaker = {}; + + // Save bytes in the minified (but not gzipped) version: + var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype; + + // Create quick reference variables for speed access to core prototypes. + var slice = ArrayProto.slice, + unshift = ArrayProto.unshift, + toString = ObjProto.toString, + hasOwnProperty = ObjProto.hasOwnProperty; + + // All **ECMAScript 5** native function implementations that we hope to use + // are declared here. + var + nativeForEach = ArrayProto.forEach, + nativeMap = ArrayProto.map, + nativeReduce = ArrayProto.reduce, + nativeReduceRight = ArrayProto.reduceRight, + nativeFilter = ArrayProto.filter, + nativeEvery = ArrayProto.every, + nativeSome = ArrayProto.some, + nativeIndexOf = ArrayProto.indexOf, + nativeLastIndexOf = ArrayProto.lastIndexOf, + nativeIsArray = Array.isArray, + nativeKeys = Object.keys, + nativeBind = FuncProto.bind; + + // Create a safe reference to the Underscore object for use below. + var _ = function(obj) { return new wrapper(obj); }; + + // Export the Underscore object for **Node.js**, with + // backwards-compatibility for the old `require()` API. If we're in + // the browser, add `_` as a global object via a string identifier, + // for Closure Compiler "advanced" mode. + if (typeof exports !== 'undefined') { + if (typeof module !== 'undefined' && module.exports) { + exports = module.exports = _; + } + exports._ = _; + } else { + root['_'] = _; + } + + // Current version. + _.VERSION = '1.3.3'; + + // Collection Functions + // -------------------- + + // The cornerstone, an `each` implementation, aka `forEach`. + // Handles objects with the built-in `forEach`, arrays, and raw objects. + // Delegates to **ECMAScript 5**'s native `forEach` if available. + var each = _.each = _.forEach = function(obj, iterator, context) { + if (obj == null) return; + if (nativeForEach && obj.forEach === nativeForEach) { + obj.forEach(iterator, context); + } else if (obj.length === +obj.length) { + for (var i = 0, l = obj.length; i < l; i++) { + if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) return; + } + } else { + for (var key in obj) { + if (_.has(obj, key)) { + if (iterator.call(context, obj[key], key, obj) === breaker) return; + } + } + } + }; + + // Return the results of applying the iterator to each element. + // Delegates to **ECMAScript 5**'s native `map` if available. + _.map = _.collect = function(obj, iterator, context) { + var results = []; + if (obj == null) return results; + if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context); + each(obj, function(value, index, list) { + results[results.length] = iterator.call(context, value, index, list); + }); + if (obj.length === +obj.length) results.length = obj.length; + return results; + }; + + // **Reduce** builds up a single result from a list of values, aka `inject`, + // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available. + _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) { + var initial = arguments.length > 2; + if (obj == null) obj = []; + if (nativeReduce && obj.reduce === nativeReduce) { + if (context) iterator = _.bind(iterator, context); + return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator); + } + each(obj, function(value, index, list) { + if (!initial) { + memo = value; + initial = true; + } else { + memo = iterator.call(context, memo, value, index, list); + } + }); + if (!initial) throw new TypeError('Reduce of empty array with no initial value'); + return memo; + }; + + // The right-associative version of reduce, also known as `foldr`. + // Delegates to **ECMAScript 5**'s native `reduceRight` if available. + _.reduceRight = _.foldr = function(obj, iterator, memo, context) { + var initial = arguments.length > 2; + if (obj == null) obj = []; + if (nativeReduceRight && obj.reduceRight === nativeReduceRight) { + if (context) iterator = _.bind(iterator, context); + return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator); + } + var reversed = _.toArray(obj).reverse(); + if (context && !initial) iterator = _.bind(iterator, context); + return initial ? _.reduce(reversed, iterator, memo, context) : _.reduce(reversed, iterator); + }; + + // Return the first value which passes a truth test. Aliased as `detect`. + _.find = _.detect = function(obj, iterator, context) { + var result; + any(obj, function(value, index, list) { + if (iterator.call(context, value, index, list)) { + result = value; + return true; + } + }); + return result; + }; + + // Return all the elements that pass a truth test. + // Delegates to **ECMAScript 5**'s native `filter` if available. + // Aliased as `select`. + _.filter = _.select = function(obj, iterator, context) { + var results = []; + if (obj == null) return results; + if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context); + each(obj, function(value, index, list) { + if (iterator.call(context, value, index, list)) results[results.length] = value; + }); + return results; + }; + + // Return all the elements for which a truth test fails. + _.reject = function(obj, iterator, context) { + var results = []; + if (obj == null) return results; + each(obj, function(value, index, list) { + if (!iterator.call(context, value, index, list)) results[results.length] = value; + }); + return results; + }; + + // Determine whether all of the elements match a truth test. + // Delegates to **ECMAScript 5**'s native `every` if available. + // Aliased as `all`. + _.every = _.all = function(obj, iterator, context) { + var result = true; + if (obj == null) return result; + if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context); + each(obj, function(value, index, list) { + if (!(result = result && iterator.call(context, value, index, list))) return breaker; + }); + return !!result; + }; + + // Determine if at least one element in the object matches a truth test. + // Delegates to **ECMAScript 5**'s native `some` if available. + // Aliased as `any`. + var any = _.some = _.any = function(obj, iterator, context) { + iterator || (iterator = _.identity); + var result = false; + if (obj == null) return result; + if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context); + each(obj, function(value, index, list) { + if (result || (result = iterator.call(context, value, index, list))) return breaker; + }); + return !!result; + }; + + // Determine if a given value is included in the array or object using `===`. + // Aliased as `contains`. + _.include = _.contains = function(obj, target) { + var found = false; + if (obj == null) return found; + if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1; + found = any(obj, function(value) { + return value === target; + }); + return found; + }; + + // Invoke a method (with arguments) on every item in a collection. + _.invoke = function(obj, method) { + var args = slice.call(arguments, 2); + return _.map(obj, function(value) { + return (_.isFunction(method) ? method || value : value[method]).apply(value, args); + }); + }; + + // Convenience version of a common use case of `map`: fetching a property. + _.pluck = function(obj, key) { + return _.map(obj, function(value){ return value[key]; }); + }; + + // Return the maximum element or (element-based computation). + _.max = function(obj, iterator, context) { + if (!iterator && _.isArray(obj) && obj[0] === +obj[0]) return Math.max.apply(Math, obj); + if (!iterator && _.isEmpty(obj)) return -Infinity; + var result = {computed : -Infinity}; + each(obj, function(value, index, list) { + var computed = iterator ? iterator.call(context, value, index, list) : value; + computed >= result.computed && (result = {value : value, computed : computed}); + }); + return result.value; + }; + + // Return the minimum element (or element-based computation). + _.min = function(obj, iterator, context) { + if (!iterator && _.isArray(obj) && obj[0] === +obj[0]) return Math.min.apply(Math, obj); + if (!iterator && _.isEmpty(obj)) return Infinity; + var result = {computed : Infinity}; + each(obj, function(value, index, list) { + var computed = iterator ? iterator.call(context, value, index, list) : value; + computed < result.computed && (result = {value : value, computed : computed}); + }); + return result.value; + }; + + // Shuffle an array. + _.shuffle = function(obj) { + var shuffled = [], rand; + each(obj, function(value, index, list) { + rand = Math.floor(Math.random() * (index + 1)); + shuffled[index] = shuffled[rand]; + shuffled[rand] = value; + }); + return shuffled; + }; + + // Sort the object's values by a criterion produced by an iterator. + _.sortBy = function(obj, val, context) { + var iterator = _.isFunction(val) ? val : function(obj) { return obj[val]; }; + return _.pluck(_.map(obj, function(value, index, list) { + return { + value : value, + criteria : iterator.call(context, value, index, list) + }; + }).sort(function(left, right) { + var a = left.criteria, b = right.criteria; + if (a === void 0) return 1; + if (b === void 0) return -1; + return a < b ? -1 : a > b ? 1 : 0; + }), 'value'); + }; + + // Groups the object's values by a criterion. Pass either a string attribute + // to group by, or a function that returns the criterion. + _.groupBy = function(obj, val) { + var result = {}; + var iterator = _.isFunction(val) ? val : function(obj) { return obj[val]; }; + each(obj, function(value, index) { + var key = iterator(value, index); + (result[key] || (result[key] = [])).push(value); + }); + return result; + }; + + // Use a comparator function to figure out at what index an object should + // be inserted so as to maintain order. Uses binary search. + _.sortedIndex = function(array, obj, iterator) { + iterator || (iterator = _.identity); + var low = 0, high = array.length; + while (low < high) { + var mid = (low + high) >> 1; + iterator(array[mid]) < iterator(obj) ? low = mid + 1 : high = mid; + } + return low; + }; + + // Safely convert anything iterable into a real, live array. + _.toArray = function(obj) { + if (!obj) return []; + if (_.isArray(obj)) return slice.call(obj); + if (_.isArguments(obj)) return slice.call(obj); + if (obj.toArray && _.isFunction(obj.toArray)) return obj.toArray(); + return _.values(obj); + }; + + // Return the number of elements in an object. + _.size = function(obj) { + return _.isArray(obj) ? obj.length : _.keys(obj).length; + }; + + // Array Functions + // --------------- + + // Get the first element of an array. Passing **n** will return the first N + // values in the array. Aliased as `head` and `take`. The **guard** check + // allows it to work with `_.map`. + _.first = _.head = _.take = function(array, n, guard) { + return (n != null) && !guard ? slice.call(array, 0, n) : array[0]; + }; + + // Returns everything but the last entry of the array. Especcialy useful on + // the arguments object. Passing **n** will return all the values in + // the array, excluding the last N. The **guard** check allows it to work with + // `_.map`. + _.initial = function(array, n, guard) { + return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n)); + }; + + // Get the last element of an array. Passing **n** will return the last N + // values in the array. The **guard** check allows it to work with `_.map`. + _.last = function(array, n, guard) { + if ((n != null) && !guard) { + return slice.call(array, Math.max(array.length - n, 0)); + } else { + return array[array.length - 1]; + } + }; + + // Returns everything but the first entry of the array. Aliased as `tail`. + // Especially useful on the arguments object. Passing an **index** will return + // the rest of the values in the array from that index onward. The **guard** + // check allows it to work with `_.map`. + _.rest = _.tail = function(array, index, guard) { + return slice.call(array, (index == null) || guard ? 1 : index); + }; + + // Trim out all falsy values from an array. + _.compact = function(array) { + return _.filter(array, function(value){ return !!value; }); + }; + + // Return a completely flattened version of an array. + _.flatten = function(array, shallow) { + return _.reduce(array, function(memo, value) { + if (_.isArray(value)) return memo.concat(shallow ? value : _.flatten(value)); + memo[memo.length] = value; + return memo; + }, []); + }; + + // Return a version of the array that does not contain the specified value(s). + _.without = function(array) { + return _.difference(array, slice.call(arguments, 1)); + }; + + // Produce a duplicate-free version of the array. If the array has already + // been sorted, you have the option of using a faster algorithm. + // Aliased as `unique`. + _.uniq = _.unique = function(array, isSorted, iterator) { + var initial = iterator ? _.map(array, iterator) : array; + var results = []; + // The `isSorted` flag is irrelevant if the array only contains two elements. + if (array.length < 3) isSorted = true; + _.reduce(initial, function (memo, value, index) { + if (isSorted ? _.last(memo) !== value || !memo.length : !_.include(memo, value)) { + memo.push(value); + results.push(array[index]); + } + return memo; + }, []); + return results; + }; + + // Produce an array that contains the union: each distinct element from all of + // the passed-in arrays. + _.union = function() { + return _.uniq(_.flatten(arguments, true)); + }; + + // Produce an array that contains every item shared between all the + // passed-in arrays. (Aliased as "intersect" for back-compat.) + _.intersection = _.intersect = function(array) { + var rest = slice.call(arguments, 1); + return _.filter(_.uniq(array), function(item) { + return _.every(rest, function(other) { + return _.indexOf(other, item) >= 0; + }); + }); + }; + + // Take the difference between one array and a number of other arrays. + // Only the elements present in just the first array will remain. + _.difference = function(array) { + var rest = _.flatten(slice.call(arguments, 1), true); + return _.filter(array, function(value){ return !_.include(rest, value); }); + }; + + // Zip together multiple lists into a single array -- elements that share + // an index go together. + _.zip = function() { + var args = slice.call(arguments); + var length = _.max(_.pluck(args, 'length')); + var results = new Array(length); + for (var i = 0; i < length; i++) results[i] = _.pluck(args, "" + i); + return results; + }; + + // If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**), + // we need this function. Return the position of the first occurrence of an + // item in an array, or -1 if the item is not included in the array. + // Delegates to **ECMAScript 5**'s native `indexOf` if available. + // If the array is large and already in sort order, pass `true` + // for **isSorted** to use binary search. + _.indexOf = function(array, item, isSorted) { + if (array == null) return -1; + var i, l; + if (isSorted) { + i = _.sortedIndex(array, item); + return array[i] === item ? i : -1; + } + if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item); + for (i = 0, l = array.length; i < l; i++) if (i in array && array[i] === item) return i; + return -1; + }; + + // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available. + _.lastIndexOf = function(array, item) { + if (array == null) return -1; + if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) return array.lastIndexOf(item); + var i = array.length; + while (i--) if (i in array && array[i] === item) return i; + return -1; + }; + + // Generate an integer Array containing an arithmetic progression. A port of + // the native Python `range()` function. See + // [the Python documentation](http://docs.python.org/library/functions.html#range). + _.range = function(start, stop, step) { + if (arguments.length <= 1) { + stop = start || 0; + start = 0; + } + step = arguments[2] || 1; + + var len = Math.max(Math.ceil((stop - start) / step), 0); + var idx = 0; + var range = new Array(len); + + while(idx < len) { + range[idx++] = start; + start += step; + } + + return range; + }; + + // Function (ahem) Functions + // ------------------ + + // Reusable constructor function for prototype setting. + var ctor = function(){}; + + // Create a function bound to a given object (assigning `this`, and arguments, + // optionally). Binding with arguments is also known as `curry`. + // Delegates to **ECMAScript 5**'s native `Function.bind` if available. + // We check for `func.bind` first, to fail fast when `func` is undefined. + _.bind = function bind(func, context) { + var bound, args; + if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1)); + if (!_.isFunction(func)) throw new TypeError; + args = slice.call(arguments, 2); + return bound = function() { + if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments))); + ctor.prototype = func.prototype; + var self = new ctor; + var result = func.apply(self, args.concat(slice.call(arguments))); + if (Object(result) === result) return result; + return self; + }; + }; + + // Bind all of an object's methods to that object. Useful for ensuring that + // all callbacks defined on an object belong to it. + _.bindAll = function(obj) { + var funcs = slice.call(arguments, 1); + if (funcs.length == 0) funcs = _.functions(obj); + each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); }); + return obj; + }; + + // Memoize an expensive function by storing its results. + _.memoize = function(func, hasher) { + var memo = {}; + hasher || (hasher = _.identity); + return function() { + var key = hasher.apply(this, arguments); + return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments)); + }; + }; + + // Delays a function for the given number of milliseconds, and then calls + // it with the arguments supplied. + _.delay = function(func, wait) { + var args = slice.call(arguments, 2); + return setTimeout(function(){ return func.apply(null, args); }, wait); + }; + + // Defers a function, scheduling it to run after the current call stack has + // cleared. + _.defer = function(func) { + return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1))); + }; + + // Returns a function, that, when invoked, will only be triggered at most once + // during a given window of time. + _.throttle = function(func, wait) { + var context, args, timeout, throttling, more, result; + var whenDone = _.debounce(function(){ more = throttling = false; }, wait); + return function() { + context = this; args = arguments; + var later = function() { + timeout = null; + if (more) func.apply(context, args); + whenDone(); + }; + if (!timeout) timeout = setTimeout(later, wait); + if (throttling) { + more = true; + } else { + result = func.apply(context, args); + } + whenDone(); + throttling = true; + return result; + }; + }; + + // Returns a function, that, as long as it continues to be invoked, will not + // be triggered. The function will be called after it stops being called for + // N milliseconds. If `immediate` is passed, trigger the function on the + // leading edge, instead of the trailing. + _.debounce = function(func, wait, immediate) { + var timeout; + return function() { + var context = this, args = arguments; + var later = function() { + timeout = null; + if (!immediate) func.apply(context, args); + }; + if (immediate && !timeout) func.apply(context, args); + clearTimeout(timeout); + timeout = setTimeout(later, wait); + }; + }; + + // Returns a function that will be executed at most one time, no matter how + // often you call it. Useful for lazy initialization. + _.once = function(func) { + var ran = false, memo; + return function() { + if (ran) return memo; + ran = true; + return memo = func.apply(this, arguments); + }; + }; + + // Returns the first function passed as an argument to the second, + // allowing you to adjust arguments, run code before and after, and + // conditionally execute the original function. + _.wrap = function(func, wrapper) { + return function() { + var args = [func].concat(slice.call(arguments, 0)); + return wrapper.apply(this, args); + }; + }; + + // Returns a function that is the composition of a list of functions, each + // consuming the return value of the function that follows. + _.compose = function() { + var funcs = arguments; + return function() { + var args = arguments; + for (var i = funcs.length - 1; i >= 0; i--) { + args = [funcs[i].apply(this, args)]; + } + return args[0]; + }; + }; + + // Returns a function that will only be executed after being called N times. + _.after = function(times, func) { + if (times <= 0) return func(); + return function() { + if (--times < 1) { return func.apply(this, arguments); } + }; + }; + + // Object Functions + // ---------------- + + // Retrieve the names of an object's properties. + // Delegates to **ECMAScript 5**'s native `Object.keys` + _.keys = nativeKeys || function(obj) { + if (obj !== Object(obj)) throw new TypeError('Invalid object'); + var keys = []; + for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key; + return keys; + }; + + // Retrieve the values of an object's properties. + _.values = function(obj) { + return _.map(obj, _.identity); + }; + + // Return a sorted list of the function names available on the object. + // Aliased as `methods` + _.functions = _.methods = function(obj) { + var names = []; + for (var key in obj) { + if (_.isFunction(obj[key])) names.push(key); + } + return names.sort(); + }; + + // Extend a given object with all the properties in passed-in object(s). + _.extend = function(obj) { + each(slice.call(arguments, 1), function(source) { + for (var prop in source) { + obj[prop] = source[prop]; + } + }); + return obj; + }; + + // Return a copy of the object only containing the whitelisted properties. + _.pick = function(obj) { + var result = {}; + each(_.flatten(slice.call(arguments, 1)), function(key) { + if (key in obj) result[key] = obj[key]; + }); + return result; + }; + + // Fill in a given object with default properties. + _.defaults = function(obj) { + each(slice.call(arguments, 1), function(source) { + for (var prop in source) { + if (obj[prop] == null) obj[prop] = source[prop]; + } + }); + return obj; + }; + + // Create a (shallow-cloned) duplicate of an object. + _.clone = function(obj) { + if (!_.isObject(obj)) return obj; + return _.isArray(obj) ? obj.slice() : _.extend({}, obj); + }; + + // Invokes interceptor with the obj, and then returns obj. + // The primary purpose of this method is to "tap into" a method chain, in + // order to perform operations on intermediate results within the chain. + _.tap = function(obj, interceptor) { + interceptor(obj); + return obj; + }; + + // Internal recursive comparison function. + function eq(a, b, stack) { + // Identical objects are equal. `0 === -0`, but they aren't identical. + // See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal. + if (a === b) return a !== 0 || 1 / a == 1 / b; + // A strict comparison is necessary because `null == undefined`. + if (a == null || b == null) return a === b; + // Unwrap any wrapped objects. + if (a._chain) a = a._wrapped; + if (b._chain) b = b._wrapped; + // Invoke a custom `isEqual` method if one is provided. + if (a.isEqual && _.isFunction(a.isEqual)) return a.isEqual(b); + if (b.isEqual && _.isFunction(b.isEqual)) return b.isEqual(a); + // Compare `[[Class]]` names. + var className = toString.call(a); + if (className != toString.call(b)) return false; + switch (className) { + // Strings, numbers, dates, and booleans are compared by value. + case '[object String]': + // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is + // equivalent to `new String("5")`. + return a == String(b); + case '[object Number]': + // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for + // other numeric values. + return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b); + case '[object Date]': + case '[object Boolean]': + // Coerce dates and booleans to numeric primitive values. Dates are compared by their + // millisecond representations. Note that invalid dates with millisecond representations + // of `NaN` are not equivalent. + return +a == +b; + // RegExps are compared by their source patterns and flags. + case '[object RegExp]': + return a.source == b.source && + a.global == b.global && + a.multiline == b.multiline && + a.ignoreCase == b.ignoreCase; + } + if (typeof a != 'object' || typeof b != 'object') return false; + // Assume equality for cyclic structures. The algorithm for detecting cyclic + // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`. + var length = stack.length; + while (length--) { + // Linear search. Performance is inversely proportional to the number of + // unique nested structures. + if (stack[length] == a) return true; + } + // Add the first object to the stack of traversed objects. + stack.push(a); + var size = 0, result = true; + // Recursively compare objects and arrays. + if (className == '[object Array]') { + // Compare array lengths to determine if a deep comparison is necessary. + size = a.length; + result = size == b.length; + if (result) { + // Deep compare the contents, ignoring non-numeric properties. + while (size--) { + // Ensure commutative equality for sparse arrays. + if (!(result = size in a == size in b && eq(a[size], b[size], stack))) break; + } + } + } else { + // Objects with different constructors are not equivalent. + if ('constructor' in a != 'constructor' in b || a.constructor != b.constructor) return false; + // Deep compare objects. + for (var key in a) { + if (_.has(a, key)) { + // Count the expected number of properties. + size++; + // Deep compare each member. + if (!(result = _.has(b, key) && eq(a[key], b[key], stack))) break; + } + } + // Ensure that both objects contain the same number of properties. + if (result) { + for (key in b) { + if (_.has(b, key) && !(size--)) break; + } + result = !size; + } + } + // Remove the first object from the stack of traversed objects. + stack.pop(); + return result; + } + + // Perform a deep comparison to check if two objects are equal. + _.isEqual = function(a, b) { + return eq(a, b, []); + }; + + // Is a given array, string, or object empty? + // An "empty" object has no enumerable own-properties. + _.isEmpty = function(obj) { + if (obj == null) return true; + if (_.isArray(obj) || _.isString(obj)) return obj.length === 0; + for (var key in obj) if (_.has(obj, key)) return false; + return true; + }; + + // Is a given value a DOM element? + _.isElement = function(obj) { + return !!(obj && obj.nodeType == 1); + }; + + // Is a given value an array? + // Delegates to ECMA5's native Array.isArray + _.isArray = nativeIsArray || function(obj) { + return toString.call(obj) == '[object Array]'; + }; + + // Is a given variable an object? + _.isObject = function(obj) { + return obj === Object(obj); + }; + + // Is a given variable an arguments object? + _.isArguments = function(obj) { + return toString.call(obj) == '[object Arguments]'; + }; + if (!_.isArguments(arguments)) { + _.isArguments = function(obj) { + return !!(obj && _.has(obj, 'callee')); + }; + } + + // Is a given value a function? + _.isFunction = function(obj) { + return toString.call(obj) == '[object Function]'; + }; + + // Is a given value a string? + _.isString = function(obj) { + return toString.call(obj) == '[object String]'; + }; + + // Is a given value a number? + _.isNumber = function(obj) { + return toString.call(obj) == '[object Number]'; + }; + + // Is a given object a finite number? + _.isFinite = function(obj) { + return _.isNumber(obj) && isFinite(obj); + }; + + // Is the given value `NaN`? + _.isNaN = function(obj) { + // `NaN` is the only value for which `===` is not reflexive. + return obj !== obj; + }; + + // Is a given value a boolean? + _.isBoolean = function(obj) { + return obj === true || obj === false || toString.call(obj) == '[object Boolean]'; + }; + + // Is a given value a date? + _.isDate = function(obj) { + return toString.call(obj) == '[object Date]'; + }; + + // Is the given value a regular expression? + _.isRegExp = function(obj) { + return toString.call(obj) == '[object RegExp]'; + }; + + // Is a given value equal to null? + _.isNull = function(obj) { + return obj === null; + }; + + // Is a given variable undefined? + _.isUndefined = function(obj) { + return obj === void 0; + }; + + // Has own property? + _.has = function(obj, key) { + return hasOwnProperty.call(obj, key); + }; + + // Utility Functions + // ----------------- + + // Run Underscore.js in *noConflict* mode, returning the `_` variable to its + // previous owner. Returns a reference to the Underscore object. + _.noConflict = function() { + root._ = previousUnderscore; + return this; + }; + + // Keep the identity function around for default iterators. + _.identity = function(value) { + return value; + }; + + // Run a function **n** times. + _.times = function (n, iterator, context) { + for (var i = 0; i < n; i++) iterator.call(context, i); + }; + + // Escape a string for HTML interpolation. + _.escape = function(string) { + return (''+string).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g,'/'); + }; + + // If the value of the named property is a function then invoke it; + // otherwise, return it. + _.result = function(object, property) { + if (object == null) return null; + var value = object[property]; + return _.isFunction(value) ? value.call(object) : value; + }; + + // Add your own custom functions to the Underscore object, ensuring that + // they're correctly added to the OOP wrapper as well. + _.mixin = function(obj) { + each(_.functions(obj), function(name){ + addToWrapper(name, _[name] = obj[name]); + }); + }; + + // Generate a unique integer id (unique within the entire client session). + // Useful for temporary DOM ids. + var idCounter = 0; + _.uniqueId = function(prefix) { + var id = idCounter++; + return prefix ? prefix + id : id; + }; + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /.^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + '\\': '\\', + "'": "'", + 'r': '\r', + 'n': '\n', + 't': '\t', + 'u2028': '\u2028', + 'u2029': '\u2029' + }; + + for (var p in escapes) escapes[escapes[p]] = p; + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + var unescaper = /\\(\\|'|r|n|t|u2028|u2029)/g; + + // Within an interpolation, evaluation, or escaping, remove HTML escaping + // that had been previously added. + var unescape = function(code) { + return code.replace(unescaper, function(match, escape) { + return escapes[escape]; + }); + }; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + settings = _.defaults(settings || {}, _.templateSettings); + + // Compile the template source, taking care to escape characters that + // cannot be included in a string literal and then unescape them in code + // blocks. + var source = "__p+='" + text + .replace(escaper, function(match) { + return '\\' + escapes[match]; + }) + .replace(settings.escape || noMatch, function(match, code) { + return "'+\n_.escape(" + unescape(code) + ")+\n'"; + }) + .replace(settings.interpolate || noMatch, function(match, code) { + return "'+\n(" + unescape(code) + ")+\n'"; + }) + .replace(settings.evaluate || noMatch, function(match, code) { + return "';\n" + unescape(code) + "\n;__p+='"; + }) + "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __p='';" + + "var print=function(){__p+=Array.prototype.join.call(arguments, '')};\n" + + source + "return __p;\n"; + + var render = new Function(settings.variable || 'obj', '_', source); + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for build time + // precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + + source + '}'; + + return template; + }; + + // Add a "chain" function, which will delegate to the wrapper. + _.chain = function(obj) { + return _(obj).chain(); + }; + + // The OOP Wrapper + // --------------- + + // If Underscore is called as a function, it returns a wrapped object that + // can be used OO-style. This wrapper holds altered versions of all the + // underscore functions. Wrapped objects may be chained. + var wrapper = function(obj) { this._wrapped = obj; }; + + // Expose `wrapper.prototype` as `_.prototype` + _.prototype = wrapper.prototype; + + // Helper function to continue chaining intermediate results. + var result = function(obj, chain) { + return chain ? _(obj).chain() : obj; + }; + + // A method to easily add functions to the OOP wrapper. + var addToWrapper = function(name, func) { + wrapper.prototype[name] = function() { + var args = slice.call(arguments); + unshift.call(args, this._wrapped); + return result(func.apply(_, args), this._chain); + }; + }; + + // Add all of the Underscore functions to the wrapper object. + _.mixin(_); + + // Add all mutator Array functions to the wrapper. + each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) { + var method = ArrayProto[name]; + wrapper.prototype[name] = function() { + var wrapped = this._wrapped; + method.apply(wrapped, arguments); + var length = wrapped.length; + if ((name == 'shift' || name == 'splice') && length === 0) delete wrapped[0]; + return result(wrapped, this._chain); + }; + }); + + // Add all accessor Array functions to the wrapper. + each(['concat', 'join', 'slice'], function(name) { + var method = ArrayProto[name]; + wrapper.prototype[name] = function() { + return result(method.apply(this._wrapped, arguments), this._chain); + }; + }); + + // Start chaining a wrapped Underscore object. + wrapper.prototype.chain = function() { + this._chain = true; + return this; + }; + + // Extracts the result from a wrapped and chained object. + wrapper.prototype.value = function() { + return this._wrapped; + }; + +}).call(this); diff --git a/app/assets/javascripts/app/lib/underscore.coffee b/app/assets/javascripts/app/lib/underscore.coffee deleted file mode 100644 index 302913cdd..000000000 --- a/app/assets/javascripts/app/lib/underscore.coffee +++ /dev/null @@ -1,682 +0,0 @@ -# **Underscore.coffee -# (c) 2011 Jeremy Ashkenas, DocumentCloud Inc.** -# Underscore is freely distributable under the terms of the -# [MIT license](http://en.wikipedia.org/wiki/MIT_License). -# Portions of Underscore are inspired by or borrowed from -# [Prototype.js](http://prototypejs.org/api), Oliver Steele's -# [Functional](http://osteele.com), and John Resig's -# [Micro-Templating](http://ejohn.org). -# For all details and documentation: -# http://documentcloud.github.com/underscore/ - - -# Baseline setup -# -------------- - -# Establish the root object, `window` in the browser, or `global` on the server. -root = this - - -# Save the previous value of the `_` variable. -previousUnderscore = root._ - - -# Establish the object that gets thrown to break out of a loop iteration. -# `StopIteration` is SOP on Mozilla. -breaker = if typeof(StopIteration) is 'undefined' then '__break__' else StopIteration - - -# Helper function to escape **RegExp** contents, because JS doesn't have one. -escapeRegExp = (string) -> string.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1') - - -# Save bytes in the minified (but not gzipped) version: -ArrayProto = Array.prototype -ObjProto = Object.prototype - - -# Create quick reference variables for speed access to core prototypes. -slice = ArrayProto.slice -unshift = ArrayProto.unshift -toString = ObjProto.toString -hasOwnProperty = ObjProto.hasOwnProperty -propertyIsEnumerable = ObjProto.propertyIsEnumerable - - -# All **ECMA5** native implementations we hope to use are declared here. -nativeForEach = ArrayProto.forEach -nativeMap = ArrayProto.map -nativeReduce = ArrayProto.reduce -nativeReduceRight = ArrayProto.reduceRight -nativeFilter = ArrayProto.filter -nativeEvery = ArrayProto.every -nativeSome = ArrayProto.some -nativeIndexOf = ArrayProto.indexOf -nativeLastIndexOf = ArrayProto.lastIndexOf -nativeIsArray = Array.isArray -nativeKeys = Object.keys - - -# Create a safe reference to the Underscore object for use below. -_ = (obj) -> new wrapper(obj) - - -# Export the Underscore object for **CommonJS**. -if typeof(exports) != 'undefined' then exports._ = _ - - -# Export Underscore to global scope. -root._ = _ - - -# Current version. -_.VERSION = '1.1.0' - - -# Collection Functions -# -------------------- - -# The cornerstone, an **each** implementation. -# Handles objects implementing **forEach**, arrays, and raw objects. -_.each = (obj, iterator, context) -> - try - if nativeForEach and obj.forEach is nativeForEach - obj.forEach iterator, context - else if _.isNumber obj.length - iterator.call context, obj[i], i, obj for i in [0...obj.length] - else - iterator.call context, val, key, obj for own key, val of obj - catch e - throw e if e isnt breaker - obj - - -# Return the results of applying the iterator to each element. Use JavaScript -# 1.6's version of **map**, if possible. -_.map = (obj, iterator, context) -> - return obj.map(iterator, context) if nativeMap and obj.map is nativeMap - results = [] - _.each obj, (value, index, list) -> - results.push iterator.call context, value, index, list - results - - -# **Reduce** builds up a single result from a list of values. Also known as -# **inject**, or **foldl**. Uses JavaScript 1.8's version of **reduce**, if possible. -_.reduce = (obj, iterator, memo, context) -> - if nativeReduce and obj.reduce is nativeReduce - iterator = _.bind iterator, context if context - return obj.reduce iterator, memo - _.each obj, (value, index, list) -> - memo = iterator.call context, memo, value, index, list - memo - - -# The right-associative version of **reduce**, also known as **foldr**. Uses -# JavaScript 1.8's version of **reduceRight**, if available. -_.reduceRight = (obj, iterator, memo, context) -> - if nativeReduceRight and obj.reduceRight is nativeReduceRight - iterator = _.bind iterator, context if context - return obj.reduceRight iterator, memo - reversed = _.clone(_.toArray(obj)).reverse() - _.reduce reversed, iterator, memo, context - - -# Return the first value which passes a truth test. -_.detect = (obj, iterator, context) -> - result = null - _.each obj, (value, index, list) -> - if iterator.call context, value, index, list - result = value - _.breakLoop() - result - - -# Return all the elements that pass a truth test. Use JavaScript 1.6's -# **filter**, if it exists. -_.filter = (obj, iterator, context) -> - return obj.filter iterator, context if nativeFilter and obj.filter is nativeFilter - results = [] - _.each obj, (value, index, list) -> - results.push value if iterator.call context, value, index, list - results - - -# Return all the elements for which a truth test fails. -_.reject = (obj, iterator, context) -> - results = [] - _.each obj, (value, index, list) -> - results.push value if not iterator.call context, value, index, list - results - - -# Determine whether all of the elements match a truth test. Delegate to -# JavaScript 1.6's **every**, if it is present. -_.every = (obj, iterator, context) -> - iterator ||= _.identity - return obj.every iterator, context if nativeEvery and obj.every is nativeEvery - result = true - _.each obj, (value, index, list) -> - _.breakLoop() unless (result = result and iterator.call(context, value, index, list)) - result - - -# Determine if at least one element in the object matches a truth test. Use -# JavaScript 1.6's **some**, if it exists. -_.some = (obj, iterator, context) -> - iterator ||= _.identity - return obj.some iterator, context if nativeSome and obj.some is nativeSome - result = false - _.each obj, (value, index, list) -> - _.breakLoop() if (result = iterator.call(context, value, index, list)) - result - - -# Determine if a given value is included in the array or object, -# based on `===`. -_.include = (obj, target) -> - return _.indexOf(obj, target) isnt -1 if nativeIndexOf and obj.indexOf is nativeIndexOf - return true for own key, val of obj when val is target - false - - -# Invoke a method with arguments on every item in a collection. -_.invoke = (obj, method) -> - args = _.rest arguments, 2 - (if method then val[method] else val).apply(val, args) for val in obj - - -# Convenience version of a common use case of **map**: fetching a property. -_.pluck = (obj, key) -> - _.map(obj, (val) -> val[key]) - - -# Return the maximum item or (item-based computation). -_.max = (obj, iterator, context) -> - return Math.max.apply(Math, obj) if not iterator and _.isArray(obj) - result = computed: -Infinity - _.each obj, (value, index, list) -> - computed = if iterator then iterator.call(context, value, index, list) else value - computed >= result.computed and (result = {value: value, computed: computed}) - result.value - - -# Return the minimum element (or element-based computation). -_.min = (obj, iterator, context) -> - return Math.min.apply(Math, obj) if not iterator and _.isArray(obj) - result = computed: Infinity - _.each obj, (value, index, list) -> - computed = if iterator then iterator.call(context, value, index, list) else value - computed < result.computed and (result = {value: value, computed: computed}) - result.value - - -# Sort the object's values by a criterion produced by an iterator. -_.sortBy = (obj, iterator, context) -> - _.pluck(((_.map obj, (value, index, list) -> - {value: value, criteria: iterator.call(context, value, index, list)} - ).sort((left, right) -> - a = left.criteria; b = right.criteria - if a < b then -1 else if a > b then 1 else 0 - )), 'value') - - -# Use a comparator function to figure out at what index an object should -# be inserted so as to maintain order. Uses binary search. -_.sortedIndex = (array, obj, iterator) -> - iterator ||= _.identity - low = 0 - high = array.length - while low < high - mid = (low + high) >> 1 - if iterator(array[mid]) < iterator(obj) then low = mid + 1 else high = mid - low - - -# Convert anything iterable into a real, live array. -_.toArray = (iterable) -> - return [] if (!iterable) - return iterable.toArray() if (iterable.toArray) - return iterable if (_.isArray(iterable)) - return slice.call(iterable) if (_.isArguments(iterable)) - _.values(iterable) - - -# Return the number of elements in an object. -_.size = (obj) -> _.toArray(obj).length - - -# Array Functions -# --------------- - -# Get the first element of an array. Passing `n` will return the first N -# values in the array. Aliased as **head**. The `guard` check allows it to work -# with **map**. -_.first = (array, n, guard) -> - if n and not guard then slice.call(array, 0, n) else array[0] - - -# Returns everything but the first entry of the array. Aliased as **tail**. -# Especially useful on the arguments object. Passing an `index` will return -# the rest of the values in the array from that index onward. The `guard` -# check allows it to work with **map**. -_.rest = (array, index, guard) -> - slice.call(array, if _.isUndefined(index) or guard then 1 else index) - - -# Get the last element of an array. -_.last = (array) -> array[array.length - 1] - - -# Trim out all falsy values from an array. -_.compact = (array) -> item for item in array when item - - -# Return a completely flattened version of an array. -_.flatten = (array) -> - _.reduce array, (memo, value) -> - return memo.concat(_.flatten(value)) if _.isArray value - memo.push value - memo - , [] - - -# Return a version of the array that does not contain the specified value(s). -_.without = (array) -> - values = _.rest arguments - val for val in _.toArray(array) when not _.include values, val - - -# Produce a duplicate-free version of the array. If the array has already -# been sorted, you have the option of using a faster algorithm. -_.uniq = (array, isSorted) -> - memo = [] - for el, i in _.toArray array - memo.push el if i is 0 || (if isSorted is true then _.last(memo) isnt el else not _.include(memo, el)) - memo - - -# Produce an array that contains every item shared between all the -# passed-in arrays. -_.intersect = (array) -> - rest = _.rest arguments - _.select _.uniq(array), (item) -> - _.all rest, (other) -> - _.indexOf(other, item) >= 0 - - -# Zip together multiple lists into a single array -- elements that share -# an index go together. -_.zip = -> - length = _.max _.pluck arguments, 'length' - results = new Array length - for i in [0...length] - results[i] = _.pluck arguments, String i - results - - -# If the browser doesn't supply us with **indexOf** (I'm looking at you, MSIE), -# we need this function. Return the position of the first occurrence of an -# item in an array, or -1 if the item is not included in the array. -_.indexOf = (array, item) -> - return array.indexOf item if nativeIndexOf and array.indexOf is nativeIndexOf - i = 0; l = array.length - while l - i - if array[i] is item then return i else i++ - -1 - - -# Provide JavaScript 1.6's **lastIndexOf**, delegating to the native function, -# if possible. -_.lastIndexOf = (array, item) -> - return array.lastIndexOf(item) if nativeLastIndexOf and array.lastIndexOf is nativeLastIndexOf - i = array.length - while i - if array[i] is item then return i else i-- - -1 - - -# Generate an integer Array containing an arithmetic progression. A port of -# [the native Python **range** function](http://docs.python.org/library/functions.html#range). -_.range = (start, stop, step) -> - a = arguments - solo = a.length <= 1 - i = start = if solo then 0 else a[0] - stop = if solo then a[0] else a[1] - step = a[2] or 1 - len = Math.ceil((stop - start) / step) - return [] if len <= 0 - range = new Array len - idx = 0 - loop - return range if (if step > 0 then i - stop else stop - i) >= 0 - range[idx] = i - idx++ - i+= step - - -# Function Functions -# ------------------ - -# Create a function bound to a given object (assigning `this`, and arguments, -# optionally). Binding with arguments is also known as **curry**. -_.bind = (func, obj) -> - args = _.rest arguments, 2 - -> func.apply obj or root, args.concat arguments - - -# Bind all of an object's methods to that object. Useful for ensuring that -# all callbacks defined on an object belong to it. -_.bindAll = (obj) -> - funcs = if arguments.length > 1 then _.rest(arguments) else _.functions(obj) - _.each funcs, (f) -> obj[f] = _.bind obj[f], obj - obj - - -# Delays a function for the given number of milliseconds, and then calls -# it with the arguments supplied. -_.delay = (func, wait) -> - args = _.rest arguments, 2 - setTimeout((-> func.apply(func, args)), wait) - - -# Memoize an expensive function by storing its results. -_.memoize = (func, hasher) -> - memo = {} - hasher or= _.identity - -> - key = hasher.apply this, arguments - return memo[key] if key of memo - memo[key] = func.apply this, arguments - - -# Defers a function, scheduling it to run after the current call stack has -# cleared. -_.defer = (func) -> - _.delay.apply _, [func, 1].concat _.rest arguments - - -# Returns the first function passed as an argument to the second, -# allowing you to adjust arguments, run code before and after, and -# conditionally execute the original function. -_.wrap = (func, wrapper) -> - -> wrapper.apply wrapper, [func].concat arguments - - -# Returns a function that is the composition of a list of functions, each -# consuming the return value of the function that follows. -_.compose = -> - funcs = arguments - -> - args = arguments - for i in [funcs.length - 1..0] by -1 - args = [funcs[i].apply(this, args)] - args[0] - - -# Object Functions -# ---------------- - -# Retrieve the names of an object's properties. -_.keys = nativeKeys or (obj) -> - return _.range 0, obj.length if _.isArray(obj) - key for key, val of obj - - -# Retrieve the values of an object's properties. -_.values = (obj) -> - _.map obj, _.identity - - -# Return a sorted list of the function names available in Underscore. -_.functions = (obj) -> - _.filter(_.keys(obj), (key) -> _.isFunction(obj[key])).sort() - - -# Extend a given object with all of the properties in a source object. -_.extend = (obj) -> - for source in _.rest(arguments) - obj[key] = val for key, val of source - obj - - -# Create a (shallow-cloned) duplicate of an object. -_.clone = (obj) -> - return obj.slice 0 if _.isArray obj - _.extend {}, obj - - -# Invokes interceptor with the obj, and then returns obj. -# The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. -_.tap = (obj, interceptor) -> - interceptor obj - obj - - -# Perform a deep comparison to check if two objects are equal. -_.isEqual = (a, b) -> - # Check object identity. - return true if a is b - # Different types? - atype = typeof(a); btype = typeof(b) - return false if atype isnt btype - # Basic equality test (watch out for coercions). - return true if `a == b` - # One is falsy and the other truthy. - return false if (!a and b) or (a and !b) - # One of them implements an `isEqual()`? - return a.isEqual(b) if a.isEqual - # Check dates' integer values. - return a.getTime() is b.getTime() if _.isDate(a) and _.isDate(b) - # Both are NaN? - return false if _.isNaN(a) and _.isNaN(b) - # Compare regular expressions. - if _.isRegExp(a) and _.isRegExp(b) - return a.source is b.source and - a.global is b.global and - a.ignoreCase is b.ignoreCase and - a.multiline is b.multiline - # If a is not an object by this point, we can't handle it. - return false if atype isnt 'object' - # Check for different array lengths before comparing contents. - return false if a.length and (a.length isnt b.length) - # Nothing else worked, deep compare the contents. - aKeys = _.keys(a); bKeys = _.keys(b) - # Different object sizes? - return false if aKeys.length isnt bKeys.length - # Recursive comparison of contents. - return false for key, val of a when !(key of b) or !_.isEqual(val, b[key]) - true - - -# Is a given array or object empty? -_.isEmpty = (obj) -> - return obj.length is 0 if _.isArray(obj) or _.isString(obj) - return false for own key of obj - true - - -# Is a given value a DOM element? -_.isElement = (obj) -> obj and obj.nodeType is 1 - - -# Is a given value an array? -_.isArray = nativeIsArray or (obj) -> !!(obj and obj.concat and obj.unshift and not obj.callee) - - -# Is a given variable an arguments object? -_.isArguments = (obj) -> obj and obj.callee - - -# Is the given value a function? -_.isFunction = (obj) -> !!(obj and obj.constructor and obj.call and obj.apply) - - -# Is the given value a string? -_.isString = (obj) -> !!(obj is '' or (obj and obj.charCodeAt and obj.substr)) - - -# Is a given value a number? -_.isNumber = (obj) -> (obj is +obj) or toString.call(obj) is '[object Number]' - - -# Is a given value a boolean? -_.isBoolean = (obj) -> obj is true or obj is false - - -# Is a given value a Date? -_.isDate = (obj) -> !!(obj and obj.getTimezoneOffset and obj.setUTCFullYear) - - -# Is the given value a regular expression? -_.isRegExp = (obj) -> !!(obj and obj.exec and (obj.ignoreCase or obj.ignoreCase is false)) - - -# Is the given value NaN -- this one is interesting. `NaN != NaN`, and -# `isNaN(undefined) == true`, so we make sure it's a number first. -_.isNaN = (obj) -> _.isNumber(obj) and window.isNaN(obj) - - -# Is a given value equal to null? -_.isNull = (obj) -> obj is null - - -# Is a given variable undefined? -_.isUndefined = (obj) -> typeof obj is 'undefined' - - -# Utility Functions -# ----------------- - -# Run Underscore.js in noConflict mode, returning the `_` variable to its -# previous owner. Returns a reference to the Underscore object. -_.noConflict = -> - root._ = previousUnderscore - this - - -# Keep the identity function around for default iterators. -_.identity = (value) -> value - - -# Run a function `n` times. -_.times = (n, iterator, context) -> - iterator.call context, i for i in [0...n] - - -# Break out of the middle of an iteration. -_.breakLoop = -> throw breaker - - -# Add your own custom functions to the Underscore object, ensuring that -# they're correctly added to the OOP wrapper as well. -_.mixin = (obj) -> - for name in _.functions(obj) - addToWrapper name, _[name] = obj[name] - - -# Generate a unique integer id (unique within the entire client session). -# Useful for temporary DOM ids. -idCounter = 0 -_.uniqueId = (prefix) -> - (prefix or '') + idCounter++ - - -# By default, Underscore uses **ERB**-style template delimiters, change the -# following template settings to use alternative delimiters. -_.templateSettings = { - start: '<%' - end: '%>' - interpolate: /<%=(.+?)%>/g -} - - -# JavaScript templating a-la **ERB**, pilfered from John Resig's -# *Secrets of the JavaScript Ninja*, page 83. -# Single-quote fix from Rick Strahl. -# With alterations for arbitrary delimiters, and to preserve whitespace. -_.template = (str, data) -> - c = _.templateSettings - endMatch = new RegExp("'(?=[^"+c.end.substr(0, 1)+"]*"+escapeRegExp(c.end)+")","g") - fn = new Function 'obj', - 'var p=[],print=function(){p.push.apply(p,arguments);};' + - 'with(obj||{}){p.push(\'' + - str.replace(/\r/g, '\\r') - .replace(/\n/g, '\\n') - .replace(/\t/g, '\\t') - .replace(endMatch,"✄") - .split("'").join("\\'") - .split("✄").join("'") - .replace(c.interpolate, "',$1,'") - .split(c.start).join("');") - .split(c.end).join("p.push('") + - "');}return p.join('');" - if data then fn(data) else fn - - -# Aliases -# ------- - -_.forEach = _.each -_.foldl = _.inject = _.reduce -_.foldr = _.reduceRight -_.select = _.filter -_.all = _.every -_.any = _.some -_.contains = _.include -_.head = _.first -_.tail = _.rest -_.methods = _.functions - - -# Setup the OOP Wrapper -# --------------------- - -# If Underscore is called as a function, it returns a wrapped object that -# can be used OO-style. This wrapper holds altered versions of all the -# underscore functions. Wrapped objects may be chained. -wrapper = (obj) -> - this._wrapped = obj - this - - -# Helper function to continue chaining intermediate results. -result = (obj, chain) -> - if chain then _(obj).chain() else obj - - -# A method to easily add functions to the OOP wrapper. -addToWrapper = (name, func) -> - wrapper.prototype[name] = -> - args = _.toArray arguments - unshift.call args, this._wrapped - result func.apply(_, args), this._chain - - -# Add all ofthe Underscore functions to the wrapper object. -_.mixin _ - - -# Add all mutator Array functions to the wrapper. -_.each ['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], (name) -> - method = Array.prototype[name] - wrapper.prototype[name] = -> - method.apply(this._wrapped, arguments) - result(this._wrapped, this._chain) - - -# Add all accessor Array functions to the wrapper. -_.each ['concat', 'join', 'slice'], (name) -> - method = Array.prototype[name] - wrapper.prototype[name] = -> - result(method.apply(this._wrapped, arguments), this._chain) - - -# Start chaining a wrapped Underscore object. -wrapper::chain = -> - this._chain = true - this - - -# Extracts the result from a wrapped and chained object. -wrapper::value = -> this._wrapped diff --git a/app/assets/javascripts/app/views/agent_ticket_zoom.jst.eco b/app/assets/javascripts/app/views/agent_ticket_zoom.jst.eco index 6d1bec49e..942757811 100644 --- a/app/assets/javascripts/app/views/agent_ticket_zoom.jst.eco +++ b/app/assets/javascripts/app/views/agent_ticket_zoom.jst.eco @@ -21,7 +21,7 @@ <%= @ticket.group.name %> - <%- T(@ticket.ticket_state.name) %> - <%- T(@ticket.ticket_priority.name) %> - - <%- @ticket.humanTime %> + ? @@ -48,7 +48,7 @@ <%= T(action.name) %> <% end %> <% end %> - - <%- article.humanTime %> <%- T('ago') %> + - ? <% end %> <% if article.to: %> diff --git a/app/assets/javascripts/app/views/user_ticket_info_small.jst.eco b/app/assets/javascripts/app/views/user_ticket_info_small.jst.eco index ae25ffead..90a0835f8 100644 --- a/app/assets/javascripts/app/views/user_ticket_info_small.jst.eco +++ b/app/assets/javascripts/app/views/user_ticket_info_small.jst.eco @@ -1,5 +1,5 @@ <% for ticket in @tickets: %>
-
T:<%= ticket.number %> <%= ticket.humanTime %>
<%= ticket.title %>
+
T:<%= ticket.number %> <%= ticket.humanTime %>
<%= ticket.title %>
<% end %>