123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667 |
- // form
- test('form checks', function() {
- App.TicketPriority.refresh([
- {
- id: 1,
- name: '1 low',
- note: 'some note 1',
- active: true,
- created_at: '2014-06-10T11:17:34.000Z',
- },
- {
- id: 2,
- name: '2 normal',
- note: 'some note 2',
- active: false,
- created_at: '2014-06-10T10:17:34.000Z',
- },
- {
- id: 3,
- name: '3 high',
- note: 'some note 3',
- active: true,
- created_at: '2014-06-10T10:17:44.000Z',
- },
- {
- id: 4,
- name: '4 very high',
- note: 'some note 4',
- active: true,
- created_at: '2014-06-10T10:17:54.000Z',
- },
- {
- id: 5,
- name: '5 xxx very high',
- note: 'some note 5',
- active: false,
- created_at: '2014-06-10T10:17:56.000Z',
- },
- ])
- App.TicketState.refresh([
- {
- id: 1,
- name: 'new',
- note: 'some note 1',
- active: true,
- created_at: '2014-06-10T11:17:34.000Z',
- },
- {
- id: 2,
- name: 'open',
- note: 'some note 2',
- active: true,
- created_at: '2014-06-10T10:17:34.000Z',
- },
- {
- id: 3,
- name: 'should not be shown',
- note: 'some note 3',
- active: false,
- created_at: '2014-06-10T10:17:34.000Z',
- },
- ])
- App.User.refresh([
- {
- id: 47,
- login: 'bod@example.com',
- email: 'bod@example.com',
- firstname: 'Bob',
- lastname: 'Smith',
- active: true,
- created_at: '2014-06-10T11:17:34.000Z',
- },
- ])
- App.Organization.refresh([
- {
- id: 12,
- name: 'Org 1',
- active: true,
- created_at: '2014-06-10T11:19:34.000Z',
- },
- ])
- /* working hours and escalation_times */
- $('#forms').append('<hr><h1>form condition check</h1><form id="form1"></form>')
- var el = $('#form1')
- var defaults = {
- priority1_id: '1',
- priority2_id: ['1', '2'],
- priority3_id: '2',
- working_hours: {
- mon: {
- active: true,
- timeframes: [
- ['09:00','17:00']
- ]
- },
- tue: {
- active: true,
- timeframes: [
- ['00:00','22:00']
- ]
- },
- wed: {
- active: true,
- timeframes: [
- ['09:00','17:00']
- ]
- },
- thu: {
- active: true,
- timeframes: [
- ['09:00','12:00'],
- ['13:00','17:00']
- ]
- },
- fri: {
- active: true,
- timeframes: [
- ['09:00','17:00']
- ]
- },
- sat: {
- active: false,
- timeframes: [
- ['10:00','14:00']
- ]
- },
- sun: {
- active: false,
- timeframes: [
- ['10:00','14:00']
- ]
- },
- },
- first_response_time: 150,
- solution_time: '',
- update_time: 45,
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'priority1_id', display: 'Priroity1', tag: 'select', relation: 'TicketPriority', null: true },
- { name: 'priority2_id', display: 'Priroity2', tag: 'select', multiple: true, relation: 'TicketPriority', null: true },
- { name: 'priority3_id', display: 'Priroity3', tag: 'select', relation: 'TicketPriority', null: true },
- { name: 'escalation_times', display: 'Times', tag: 'sla_times', null: true },
- { name: 'working_hours', display: 'Hours', tag: 'business_hours', null: true },
- ]
- },
- params: defaults,
- autofocus: true
- })
- var params = App.ControllerForm.params(el)
- var test_params = {
- priority1_id: '1',
- priority2_id: ['1', '2'],
- priority3_id: '2',
- first_response_time: '150',
- first_response_time_in_text: '02:30',
- solution_time: '',
- solution_time_in_text: '',
- update_time: '45',
- update_time_in_text: '00:45',
- working_hours: {
- mon: {
- active: true,
- timeframes: [
- ['09:00','17:00']
- ]
- },
- tue: {
- active: true,
- timeframes: [
- ['00:00','22:00']
- ]
- },
- wed: {
- active: true,
- timeframes: [
- ['09:00','17:00']
- ]
- },
- thu: {
- active: true,
- timeframes: [
- ['09:00','12:00'],
- ['13:00','17:00']
- ]
- },
- fri: {
- active: true,
- timeframes: [
- ['09:00','17:00']
- ]
- },
- sat: {
- active: false,
- timeframes: [
- ['10:00','14:00']
- ]
- },
- sun: {
- active: false,
- timeframes: [
- ['10:00','14:00']
- ]
- },
- },
- }
- deepEqual(params, test_params, 'form param check')
- // check possible options
- equal(el.find('[name="priority1_id"] option').length, 3)
- equal(el.find('[name="priority2_id"] option').length, 4)
- equal(el.find('[name="priority3_id"] option').length, 4)
- // change sla times
- el.find('[name="first_response_time_in_text"]').val('0:30').trigger('blur')
- el.find('#update_time').click()
- var params = App.ControllerForm.params(el)
- var test_params = {
- priority1_id: '1',
- priority2_id: ['1', '2'],
- priority3_id: '2',
- working_hours: {
- mon: {
- active: true,
- timeframes: [
- ['09:00','17:00']
- ]
- },
- tue: {
- active: true,
- timeframes: [
- ['00:00','22:00']
- ]
- },
- wed: {
- active: true,
- timeframes: [
- ['09:00','17:00']
- ]
- },
- thu: {
- active: true,
- timeframes: [
- ['09:00','12:00'],
- ['13:00','17:00']
- ]
- },
- fri: {
- active: true,
- timeframes: [
- ['09:00','17:00']
- ]
- },
- sat: {
- active: false,
- timeframes: [
- ['10:00','14:00']
- ]
- },
- sun: {
- active: false,
- timeframes: [
- ['10:00','14:00']
- ]
- },
- },
- first_response_time: '30',
- first_response_time_in_text: '00:30',
- solution_time: '',
- solution_time_in_text: '',
- update_time: '',
- update_time_in_text: '',
- }
- deepEqual(params, test_params, 'form param check')
- /* empty params or defaults */
- $('#forms').append('<hr><h1>form condition check</h1><form id="form2"></form>')
- var el = $('#form2')
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'condition', display: 'Conditions', tag: 'ticket_selector', null: true },
- { name: 'executions', display: 'Executions', tag: 'ticket_perform_action', null: true, notification: true },
- ]
- },
- autofocus: true
- })
- var params = App.ControllerForm.params(el)
- var test_params = {
- condition: {
- 'ticket.state_id': {
- operator: 'is',
- value: '2',
- },
- },
- executions: {
- 'ticket.state_id': {
- value: '2',
- },
- },
- }
- deepEqual(params, test_params, 'form param check');
- /* with params or defaults */
- $('#forms').append('<hr><h1>form 3</h1><form id="form3"></form>')
- var el = $('#form3')
- var defaults = {
- condition: {
- 'ticket.title': {
- operator: 'contains',
- value: 'some title',
- },
- 'ticket.priority_id': {
- operator: 'is',
- value: [1,2,3],
- },
- 'ticket.created_at': {
- operator: 'before (absolute)',
- value: '2015-09-20T03:41:00.000Z',
- },
- 'ticket.updated_at': {
- operator: 'within last (relative)',
- range: 'year',
- value: 2,
- },
- 'ticket.organization_id': {
- operator: 'is not',
- pre_condition: 'specific',
- value: 12,
- },
- 'ticket.owner_id': {
- operator: 'is',
- pre_condition: 'specific',
- value: 47,
- },
- 'ticket.created_by_id': {
- operator: 'is',
- pre_condition: 'current_user.id',
- value: '',
- },
- },
- executions: {
- 'ticket.title': {
- value: 'some title new',
- },
- 'ticket.priority_id': {
- value: 3,
- },
- 'ticket.owner_id': {
- pre_condition: 'specific',
- value: 47,
- },
- 'ticket.tags': {
- operator: 'remove',
- value: 'tag1, tag2',
- },
- 'notification.email': {
- recipient: 'ticket_customer',
- subject: 'some subject',
- body: "some<br>\nbody",
- },
- },
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'condition', display: 'Conditions', tag: 'ticket_selector', null: true },
- { name: 'executions', display: 'Executions', tag: 'ticket_perform_action', null: true, notification: true },
- ]
- },
- params: defaults,
- autofocus: true
- })
- var params = App.ControllerForm.params(el)
- var test_params = {
- condition: {
- 'ticket.title': {
- operator: 'contains',
- value: 'some title',
- },
- 'ticket.priority_id': {
- operator: 'is',
- value: ['1', '2', '3'], // show also invalid proirity, because it's selected
- },
- 'ticket.created_at': {
- operator: 'before (absolute)',
- value: '2015-09-20T03:41:00.000Z',
- },
- 'ticket.updated_at': {
- operator: 'within last (relative)',
- range: 'year',
- value: '2',
- },
- 'ticket.organization_id': {
- operator: 'is not',
- pre_condition: 'specific',
- value: '12',
- },
- 'ticket.owner_id': {
- operator: 'is',
- pre_condition: 'specific',
- value: '47',
- value_completion: 'Bob Smith <bod@example.com>',
- },
- 'ticket.created_by_id': {
- operator: 'is',
- pre_condition: 'current_user.id',
- value: '',
- value_completion: ''
- },
- },
- executions: {
- 'ticket.title': {
- value: 'some title new',
- },
- 'ticket.owner_id': {
- pre_condition: 'specific',
- value: '47',
- value_completion: 'Bob Smith <bod@example.com>'
- },
- 'ticket.priority_id': {
- value: '3',
- },
- 'ticket.tags': {
- operator: 'remove',
- value: 'tag1, tag2',
- },
- 'notification.email': {
- recipient: 'ticket_customer',
- subject: 'some subject',
- body: "some<br>\nbody",
- },
- },
- }
- deepEqual(params, test_params, 'form param check')
- // change selector
- el.find('[name="condition::ticket.priority_id::value"]').closest('.js-filterElement').find('.js-remove').click()
- el.find('[name="executions::ticket.title::value"]').closest('.js-filterElement').find('.js-remove').click()
- var params = App.ControllerForm.params(el)
- var test_params = {
- condition: {
- 'ticket.title': {
- operator: 'contains',
- value: 'some title',
- },
- 'ticket.created_at': {
- operator: 'before (absolute)',
- value: '2015-09-20T03:41:00.000Z',
- },
- 'ticket.updated_at': {
- operator: 'within last (relative)',
- range: 'year',
- value: '2',
- },
- 'ticket.organization_id': {
- operator: 'is not',
- pre_condition: 'specific',
- value: '12',
- },
- 'ticket.owner_id': {
- operator: 'is',
- pre_condition: 'specific',
- value: '47',
- value_completion: 'Bob Smith <bod@example.com>',
- },
- 'ticket.created_by_id': {
- operator: 'is',
- pre_condition: 'current_user.id',
- value: '',
- value_completion: ''
- },
- },
- executions: {
- 'ticket.priority_id': {
- value: '3',
- },
- 'ticket.owner_id': {
- pre_condition: 'specific',
- value: '47',
- value_completion: 'Bob Smith <bod@example.com>'
- },
- 'ticket.tags': {
- operator: 'remove',
- value: 'tag1, tag2',
- },
- 'notification.email': {
- recipient: 'ticket_customer',
- subject: 'some subject',
- body: "some<br>\nbody",
- },
- },
- }
- deepEqual(params, test_params, 'form param check')
- // change selector
- el.find('[name="executions::notification.email::subject"]').closest('.js-filterElement').find('.js-remove').click()
- var params = App.ControllerForm.params(el)
- var test_params = {
- condition: {
- 'ticket.title': {
- operator: 'contains',
- value: 'some title',
- },
- 'ticket.created_at': {
- operator: 'before (absolute)',
- value: '2015-09-20T03:41:00.000Z',
- },
- 'ticket.updated_at': {
- operator: 'within last (relative)',
- range: 'year',
- value: '2',
- },
- 'ticket.organization_id': {
- operator: 'is not',
- pre_condition: 'specific',
- value: '12',
- },
- 'ticket.owner_id': {
- operator: 'is',
- pre_condition: 'specific',
- value: '47',
- value_completion: 'Bob Smith <bod@example.com>',
- },
- 'ticket.created_by_id': {
- operator: 'is',
- pre_condition: 'current_user.id',
- value: '',
- value_completion: ''
- },
- },
- executions: {
- 'ticket.priority_id': {
- value: '3',
- },
- 'ticket.owner_id': {
- pre_condition: 'specific',
- value: '47',
- value_completion: 'Bob Smith <bod@example.com>'
- },
- 'ticket.tags': {
- operator: 'remove',
- value: 'tag1, tag2',
- },
- },
- }
- deepEqual(params, test_params, 'form param check')
- // change selector
- el.find('.js-attributeSelector').last().find('select').val('notification.email').trigger('change')
- el.find('[name="executions::notification.email::subject"]').val('some subject')
- el.find('[data-name="executions::notification.email::body"]').html('lala')
- var params = App.ControllerForm.params(el)
- var test_params = {
- condition: {
- 'ticket.title': {
- operator: 'contains',
- value: 'some title',
- },
- 'ticket.created_at': {
- operator: 'before (absolute)',
- value: '2015-09-20T03:41:00.000Z',
- },
- 'ticket.updated_at': {
- operator: 'within last (relative)',
- range: 'year',
- value: '2',
- },
- 'ticket.organization_id': {
- operator: 'is not',
- pre_condition: 'specific',
- value: '12',
- },
- 'ticket.owner_id': {
- operator: 'is',
- pre_condition: 'specific',
- value: '47',
- value_completion: 'Bob Smith <bod@example.com>',
- },
- 'ticket.created_by_id': {
- operator: 'is',
- pre_condition: 'current_user.id',
- value: '',
- value_completion: ''
- },
- },
- executions: {
- 'ticket.priority_id': {
- value: '3',
- },
- 'ticket.owner_id': {
- pre_condition: 'specific',
- value: '47',
- value_completion: 'Bob Smith <bod@example.com>'
- },
- 'notification.email': {
- recipient: 'ticket_owner',
- subject: 'some subject',
- body: 'lala',
- },
- },
- }
- deepEqual(params, test_params, 'form param check')
- /* with params or defaults */
- $('#forms').append('<hr><h1>form 4</h1><form id="form4"></form>')
- var el = $('#form4')
- var defaults = {
- condition: {
- 'ticket.title': {
- operator: 'contains',
- value: 'some title',
- },
- },
- executions: {
- 'notification.email': {
- recipient: 'ticket_customer',
- subject: 'some subject',
- body: "some<br>\nbody",
- },
- },
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'condition', display: 'Conditions', tag: 'ticket_selector', null: true },
- { name: 'executions', display: 'Executions', tag: 'ticket_perform_action', null: true, notification: true },
- ]
- },
- params: defaults,
- autofocus: true
- })
- var params = App.ControllerForm.params(el)
- var test_params = {
- condition: {
- 'ticket.title': {
- operator: 'contains',
- value: 'some title',
- },
- },
- executions: {
- 'notification.email': {
- recipient: 'ticket_customer',
- subject: 'some subject',
- body: "some<br>\nbody",
- },
- },
- }
- deepEqual(params, test_params, 'form param check')
- });
|