diff --git a/app/assets/javascripts/app/controllers/object_manager.coffee b/app/assets/javascripts/app/controllers/object_manager.coffee index f3f8e03a2..8582f8c4d 100644 --- a/app/assets/javascripts/app/controllers/object_manager.coffee +++ b/app/assets/javascripts/app/controllers/object_manager.coffee @@ -247,8 +247,6 @@ class Edit extends App.ControllerGenericEdit #if attribute.name is 'data_type' # attribute.disabled = true - console.log('configure_attributes', configure_attributes) - @controller = new App.ControllerForm( model: configure_attributes: configure_attributes diff --git a/app/assets/javascripts/app/models/_application_model.coffee b/app/assets/javascripts/app/models/_application_model.coffee index 78782a842..455bb381d 100644 --- a/app/assets/javascripts/app/models/_application_model.coffee +++ b/app/assets/javascripts/app/models/_application_model.coffee @@ -916,20 +916,25 @@ set new attributes of model (remove already available attributes) # use jquery instead of ._clone() because we need a deep copy of the obj @org_configure_attributes = $.extend(true, [], @configure_attributes) + configure_attributes = $.extend(true, [], @configure_attributes) + allAttributes = [] for attribute in attributes @attributes.push attribute.name found = false - for attribute_model, index in @configure_attributes + for attribute_model, index in configure_attributes continue if attribute_model.name != attribute.name - @configure_attributes[index] = _.extend(attribute_model, attribute) + allAttributes.push $.extend(true, attribute_model, attribute) + configure_attributes.splice(index, 1) # remove found attribute found = true break if !found - @configure_attributes.push attribute + allAttributes.push $.extend(true, {}, attribute) + + @configure_attributes = $.extend(true, [], allAttributes.concat(configure_attributes)) @resetAttributes: -> return if _.isEmpty(@org_configure_attributes) diff --git a/db/migrate/20211026000001_object_manager_ticket_object_update.rb b/db/migrate/20211026000001_object_manager_ticket_object_update.rb new file mode 100644 index 000000000..93e26d7a9 --- /dev/null +++ b/db/migrate/20211026000001_object_manager_ticket_object_update.rb @@ -0,0 +1,94 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + +class ObjectManagerTicketObjectUpdate < ActiveRecord::Migration[4.2] + def up + + # return if it's a new setup + return if !Setting.exists?(name: 'system_init_done') + + UserInfo.current_user_id = 1 + ObjectManager::Attribute.add( + force: true, + object: 'Ticket', + name: 'number', + display: '#', + data_type: 'input', + data_option: { + type: 'text', + readonly: 1, + null: true, + maxlength: 60, + width: '68px', + }, + editable: false, + active: true, + screens: { + create_top: {}, + edit: {}, + }, + to_create: false, + to_migrate: false, + to_delete: false, + position: 5, + ) + + ObjectManager::Attribute.add( + force: true, + object: 'Ticket', + name: 'title', + display: 'Title', + data_type: 'input', + data_option: { + type: 'text', + maxlength: 200, + null: false, + translate: false, + }, + editable: false, + active: true, + screens: { + create_top: { + '-all-' => { + null: false, + }, + }, + edit: {}, + }, + to_create: false, + to_migrate: false, + to_delete: false, + position: 8, + ) + + ObjectManager::Attribute.add( + force: true, + object: 'Ticket', + name: 'organization_id', + display: 'Organization', + data_type: 'autocompletion_ajax', + data_option: { + relation: 'Organization', + autocapitalize: false, + multiple: false, + null: true, + translate: false, + permission: ['ticket.agent'], + readonly: 1, + }, + editable: false, + active: true, + screens: { + create_top: { + '-all-' => { + null: false, + }, + }, + edit: {}, + }, + to_create: false, + to_migrate: false, + to_delete: false, + position: 12, + ) + end +end diff --git a/db/seeds/object_manager_attributes.rb b/db/seeds/object_manager_attributes.rb index af7971427..1bd83f14a 100644 --- a/db/seeds/object_manager_attributes.rb +++ b/db/seeds/object_manager_attributes.rb @@ -1,5 +1,30 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ +ObjectManager::Attribute.add( + force: true, + object: 'Ticket', + name: 'number', + display: '#', + data_type: 'input', + data_option: { + type: 'text', + readonly: 1, + null: true, + maxlength: 60, + width: '68px', + }, + editable: false, + active: true, + screens: { + create_top: {}, + edit: {}, + }, + to_create: false, + to_migrate: false, + to_delete: false, + position: 5, +) + ObjectManager::Attribute.add( force: true, object: 'Ticket', @@ -25,7 +50,7 @@ ObjectManager::Attribute.add( to_create: false, to_migrate: false, to_delete: false, - position: 15, + position: 8, ) ObjectManager::Attribute.add( @@ -61,6 +86,38 @@ ObjectManager::Attribute.add( to_delete: false, position: 10, ) + +ObjectManager::Attribute.add( + force: true, + object: 'Ticket', + name: 'organization_id', + display: 'Organization', + data_type: 'autocompletion_ajax', + data_option: { + relation: 'Organization', + autocapitalize: false, + multiple: false, + null: true, + translate: false, + permission: ['ticket.agent'], + readonly: 1, + }, + editable: false, + active: true, + screens: { + create_top: { + '-all-' => { + null: false, + }, + }, + edit: {}, + }, + to_create: false, + to_migrate: false, + to_delete: false, + position: 12, +) + ObjectManager::Attribute.add( force: true, object: 'Ticket', diff --git a/public/assets/tests/qunit/model.js b/public/assets/tests/qunit/model.js index d129c56df..2a390ce31 100644 --- a/public/assets/tests/qunit/model.js +++ b/public/assets/tests/qunit/model.js @@ -227,8 +227,9 @@ QUnit.test("updateAttributes will change existing attributes and add new ones", var attributesAfterUpdate = _.clone(App.Ticket.configure_attributes); assert.equal(attributesAfterUpdate.length, attributesBefore.length + 1, 'new attributes list contains 1 more elements') - assert.equal(attributesAfterUpdate[attributesAfterUpdate.length - 1]['name'], 'new_attribute_1010101', 'new attributes list contains the new element') - assert.equal(attributesAfterUpdate[0]['new_option_1239393'], 1, 'first element of the new attributes got updated with the new option') + assert.equal(attributesAfterUpdate[0]['new_option_1239393'], 1, 'first element of the new attributes is number') + assert.equal(attributesAfterUpdate[0]['name'], 'number', 'first element of the new attributes got updated with the new option') + assert.equal(attributesAfterUpdate[1]['name'], 'new_attribute_1010101', 'new attributes list contains the new element') App.Ticket.resetAttributes(); var attributesAfterReset = _.clone(App.Ticket.configure_attributes); diff --git a/spec/models/object_manager/attribute_spec.rb b/spec/models/object_manager/attribute_spec.rb index c98d7dcde..80293fb34 100644 --- a/spec/models/object_manager/attribute_spec.rb +++ b/spec/models/object_manager/attribute_spec.rb @@ -76,7 +76,7 @@ RSpec.describe ObjectManager::Attribute, type: :model do end end - %w[title tags].each do |not_editable_attribute| + %w[title tags number].each do |not_editable_attribute| it "rejects '#{not_editable_attribute}' which is used" do expect do described_class.add attributes_for :object_manager_attribute_text, name: not_editable_attribute @@ -84,7 +84,7 @@ RSpec.describe ObjectManager::Attribute, type: :model do end end - %w[priority state note number].each do |existing_attribute| + %w[priority state note].each do |existing_attribute| it "rejects '#{existing_attribute}' which is used" do expect do described_class.add attributes_for :object_manager_attribute_text, name: existing_attribute