diff --git a/app/assets/javascripts/app/models/_application_model.js.coffee b/app/assets/javascripts/app/models/_application_model.js.coffee index a67494ef1..2d4cfca2c 100644 --- a/app/assets/javascripts/app/models/_application_model.js.coffee +++ b/app/assets/javascripts/app/models/_application_model.js.coffee @@ -64,17 +64,47 @@ class App.Model extends Spine.Model return '???' @validate: ( data = {} ) -> - return if !data['model'].configure_attributes + attributes = _.clone( data['model'].configure_attributes ) + return if !attributes + + # check params of screen if screen is requested + if data['screen'] + for attribute in attributes + if attribute.screen + if attribute && attribute.screen && attribute.screen[ data['screen'] ] && !_.isEmpty(attribute.screen[ data['screen'] ]) + for item, value of attribute.screen[ data['screen'] ] + attribute[item] = value + + # check required_if attributes + for attribute in attributes + if attribute['required_if'] + + for key, values of attribute['required_if'] + + localValues = data['params'][key] + if !_.isArray( localValues ) + localValues = [ localValues ] + + match = false + for value in values + if localValues + for localValue in localValues + if value && localValue && value.toString() is localValue.toString() + match = true + if match is true + attribute['null'] = false + else + attribute['null'] = true # check attributes/each attribute of object errors = {} - for attribute in data['model'].configure_attributes + for attribute in attributes # only if attribute is not read only if !attribute.readonly # check required // if null is defined && null is false - if 'null' of attribute && !attribute[null] + if 'null' of attribute && !attribute['null'] # check :: fields parts = attribute.name.split '::' @@ -103,16 +133,17 @@ class App.Model extends Spine.Model # return error object if !_.isEmpty(errors) - console.log 'error', 'validation vailed', errors + console.log 'error', 'validation failed', errors return errors # return no errors return - validate: -> + validate: (params = {}) -> App.Model.validate( - model: @constructor, - params: @, + model: @constructor + params: @ + screen: params.screen ) isOnline: -> diff --git a/app/views/tests/model.html.erb b/app/views/tests/model.html.erb new file mode 100644 index 000000000..ec93fd3aa --- /dev/null +++ b/app/views/tests/model.html.erb @@ -0,0 +1,16 @@ + + + + + + + + + +
+ diff --git a/config/routes/test.rb b/config/routes/test.rb index 55406c6aa..8d2d96363 100644 --- a/config/routes/test.rb +++ b/config/routes/test.rb @@ -1,6 +1,7 @@ Zammad::Application.routes.draw do match '/tests-core', :to => 'tests#core', :via => :get + match '/tests-model', :to => 'tests#model', :via => :get match '/tests-form', :to => 'tests#form', :via => :get match '/tests-table', :to => 'tests#table', :via => :get match '/tests/wait/:sec', :to => 'tests#wait', :via => :get diff --git a/test/browser/aab_unit_test.rb b/test/browser/aab_unit_test.rb index 4446d1346..a5cc28541 100644 --- a/test/browser/aab_unit_test.rb +++ b/test/browser/aab_unit_test.rb @@ -24,6 +24,28 @@ class AAbUnitTest < TestCase ] browser_single_test(tests) end + def test_model + tests = [ + { + :name => 'start', + :instance => browser_instance, + :url => browser_url + '/tests-model', + :action => [ + { + :execute => 'wait', + :value => 8, + }, + { + :execute => 'match', + :css => '.result .failed', + :value => '0', + :match_result => true, + }, + ], + }, + ] + browser_single_test(tests) + end def test_form tests = [ {