diff --git a/app/assets/javascripts/app/controllers/_application_controller.js.coffee b/app/assets/javascripts/app/controllers/_application_controller.js.coffee index 8dfc6e2c5..599f240de 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.js.coffee @@ -143,8 +143,8 @@ class App.Controller extends Spine.Controller ticketTableAttributes: (attributes) => all_attributes = [ - { name: 'number', link: true, title: 'title' }, - { name: 'title', link: true, title: 'title' }, + { name: 'number', type: 'link', title: 'title', dataType: 'edit' }, + { name: 'title', type: 'link', title: 'title', dataType: 'edit' }, { name: 'customer', class: 'user-popover', data: { id: true } }, { name: 'ticket_state', translate: true, title: true }, { name: 'ticket_priority', translate: true, title: true }, diff --git a/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee b/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee index e51b9a2b5..342596e93 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee @@ -60,11 +60,11 @@ class App.ControllerGenericEdit extends App.ControllerModal @html App.view('generic/admin/edit')( head: @pageData.object ) new App.ControllerForm( - el: @el.find('#object_edit'), - model: App[ @genericObject ], - params: @item, - required: @required, - autofocus: true, + el: @el.find('#object_edit') + model: App[ @genericObject ] + params: @item + required: @required + autofocus: true ) @modalShow() @@ -96,7 +96,7 @@ class App.ControllerGenericEdit extends App.ControllerModal ui.modalHide() ) -class App.ControllerGenericIndex extends App.ControllerContent +class App.ControllerGenericIndex extends App.Controller events: 'click [data-type=edit]': 'edit' 'click [data-type=destroy]': 'destroy' @@ -143,25 +143,53 @@ class App.ControllerGenericIndex extends App.ControllerContent ) @html App.view('generic/admin/index')( - head: @pageData.objects, - notes: @pageData.notes, - buttons: @pageData.buttons, - menus: @pageData.menus, + head: @pageData.objects + notes: @pageData.notes + buttons: @pageData.buttons + menus: @pageData.menus ) + # append additional col. link switch to + overview = _.clone( App[ @genericObject ].configure_overview ) + attributes = _.clone( App[ @genericObject ].configure_attributes ) + if @pageData.addCol + for item in @pageData.addCol.overview + overview.push item + for item in @pageData.addCol.attributes + attributes.push item + # append content table new App.ControllerTable( - el: @el.find('.table-overview'), - model: App[ @genericObject ], - objects: objects, + el: @el.find('.table-overview') + model: App[ @genericObject ] + objects: objects + overview: overview + attributes: attributes + ) + + binds = {} + for item in attributes + if item.dataType + if !binds[item.dataType] + callback = item.callback || @edit + @el.on( 'click', "[data-type=#{item.dataType}]", callback ) + binds[item.dataType] = true + + custom: (e) => + e.preventDefault() + item = $(e.target).item( App[ @genericObject ] ) + new App.ControllerGenericEdit( + id: item.id + pageData: @pageData + genericObject: @genericObject ) edit: (e) => e.preventDefault() item = $(e.target).item( App[ @genericObject ] ) new App.ControllerGenericEdit( - id: item.id, - pageData: @pageData, + id: item.id + pageData: @pageData genericObject: @genericObject ) @@ -174,7 +202,7 @@ class App.ControllerGenericIndex extends App.ControllerContent new: (e) -> e.preventDefault() new App.ControllerGenericNew( - pageData: @pageData, + pageData: @pageData genericObject: @genericObject ) @@ -191,8 +219,8 @@ class DestroyConfirm extends App.ControllerModal button: 'Yes' ) @modalShow( - backdrop: true, - keyboard: true, + backdrop: true + keyboard: true ) submit: (e) => @@ -233,10 +261,10 @@ class App.ControllerLevel2 extends App.ControllerContent @navupdate @page.nav @html App.view('generic/admin_level2/index')( - page: @page, - menus: @menu, - type: @type, - target: @target, + page: @page + menus: @menu + type: @type + target: @target ) if !@target @@ -269,7 +297,7 @@ class App.ControllerTabs extends App.Controller render: -> @html App.view('generic/tabs')( - tabs: @tabs, + tabs: @tabs ) @el.find('.nav-tabs li:first').addClass('active') diff --git a/app/assets/javascripts/app/controllers/_application_controller_table.js.coffee b/app/assets/javascripts/app/controllers/_application_controller_table.js.coffee index 3c1c9ff48..2f3e2ae15 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_table.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_table.js.coffee @@ -10,34 +10,34 @@ class App.ControllerTable extends App.Controller ### new App.ControllerTable( - header: ['Host', 'User', 'Adapter', 'Active'], - overview: ['host', 'user', 'adapter', 'active'], - model: App.Channel, - objects: data, - checkbox: false, - radio: false, + header: ['Host', 'User', 'Adapter', 'Active'] + overview: ['host', 'user', 'adapter', 'active'] + model: App.Channel + objects: data + checkbox: false + radio: false ) new App.ControllerTable( overview_extended: [ - { name: 'number', link: true }, - { name: 'title', link: true }, - { name: 'customer', class: 'user-popover', data: { id: true } }, - { name: 'ticket_state', translate: true }, - { name: 'ticket_priority', translate: true }, + { name: 'number', link: true } + { name: 'title', link: true } + { name: 'customer', class: 'user-popover', data: { id: true } } + { name: 'ticket_state', translate: true } + { name: 'ticket_priority', translate: true } { name: 'group' }, - { name: 'owner', class: 'user-popover', data: { id: true } }, - { 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 }, + { name: 'owner', class: 'user-popover', data: { id: true } } + { 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 } ], - model: App.Ticket, - objects: tickets, - checkbox: false, - radio: false, + model: App.Ticket + objects: tickets + checkbox: false + radio: false ) ### @@ -53,7 +53,7 @@ class App.ControllerTable extends App.Controller table = '
-' + App.i18n.translateContent( 'none' ) + '-
' return $(table) - # define normal header + # define table header if header header_new = [] for key in header @@ -64,21 +64,39 @@ class App.ControllerTable extends App.Controller else if !data.overview_extended header = [] for row in overview + found = false if attributes for attribute in attributes if row is attribute.name + found = true header.push attribute else rowWithoutId = row + '_id' if rowWithoutId is attribute.name - header.push attribute + found = true + header.push attribute + if !found + header.push { + name: row + display: row + } + # collect data of col. types dataTypesForCols = [] for row in overview - dataTypesForCols.push { - name: row - link: true - } + if attributes + for attribute in attributes + if row is attribute.name + dataTypesAttribute = _.clone(attribute) + dataTypesAttribute['type'] = 'link' + if !dataTypesAttribute['dataType'] + dataTypesAttribute['dataType'] = 'edit' + dataTypesForCols.push dataTypesAttribute + else + dataTypesForCols.push { + name: row + link: true + } # extended table format if data.overview_extended diff --git a/app/assets/javascripts/app/controllers/users.js.coffee b/app/assets/javascripts/app/controllers/users.js.coffee index aff0e623c..78ddcccdc 100644 --- a/app/assets/javascripts/app/controllers/users.js.coffee +++ b/app/assets/javascripts/app/controllers/users.js.coffee @@ -24,6 +24,22 @@ class Index extends App.Controller # { name: 'List', 'data-type': '', class: 'active' }, { name: 'New User', 'data-type': 'new', class: 'primary' } ] + addCol: + overview: ['switch_to'] + attributes: [ + { + name: 'switch_to' + display: 'Switch to' + type: 'link' + class: 'glyphicon glyphicon-user' + readonly: 1 + dataType: 'switch_to' + callback: (e) -> + e.preventDefault() + user_id = $(e.target).parent().parent().data('id') + window.location = App.Config.get('api_path') + '/sessions/switch/' + user_id + } + ] ) App.Config.set( 'User', { prio: 1000, name: 'Users', parent: '#manage', target: '#manage/users', controller: Index, role: ['Admin'] }, 'NavBarAdmin' ) diff --git a/app/assets/javascripts/app/views/generic/table.jst.eco b/app/assets/javascripts/app/views/generic/table.jst.eco index d37027b98..4bd2a3a0b 100644 --- a/app/assets/javascripts/app/views/generic/table.jst.eco +++ b/app/assets/javascripts/app/views/generic/table.jst.eco @@ -32,10 +32,10 @@ <% position++ %>