Fixed form initialisation with empty model/attributes.

This commit is contained in:
Martin Edenhofer 2016-02-23 11:54:35 +01:00
parent cca9740465
commit 34e92456f7
4 changed files with 28 additions and 12 deletions

View file

@ -9,6 +9,11 @@ class App.ControllerForm extends App.Controller
@handlers.push @showHideToggle @handlers.push @showHideToggle
@handlers.push @requiredMandantoryToggle @handlers.push @requiredMandantoryToggle
if !@model
@model = {}
if !@attributes
@attributes = []
# set empty class attributes if needed # set empty class attributes if needed
if !@form if !@form
@form = @formGen() @form = @formGen()
@ -16,11 +21,6 @@ class App.ControllerForm extends App.Controller
# add alert placeholder # add alert placeholder
@form.prepend('<div class="alert alert--danger js-alert hide" role="alert"></div>') @form.prepend('<div class="alert alert--danger js-alert hide" role="alert"></div>')
if !@model
@model = {}
if !@attributes
@attributes = []
# if element is given, prepend form to it # if element is given, prepend form to it
if @el if @el
@el.prepend(@form) @el.prepend(@form)
@ -46,7 +46,7 @@ class App.ControllerForm extends App.Controller
html: => html: =>
@form.html() @form.html()
formGen: -> formGen: =>
App.Log.debug 'ControllerForm', 'formGen', @model.configure_attributes App.Log.debug 'ControllerForm', 'formGen', @model.configure_attributes
# check if own fieldset should be generated # check if own fieldset should be generated
@ -55,6 +55,8 @@ class App.ControllerForm extends App.Controller
else else
fieldset = $('<fieldset></fieldset>') fieldset = $('<fieldset></fieldset>')
return fieldset if _.isEmpty(@model)
# collect form attributes # collect form attributes
@attributes = [] @attributes = []
if @model.attributesGet if @model.attributesGet

View file

@ -0,0 +1,5 @@
class AppVersionForNewMessages < ActiveRecord::Migration
def up
AppVersion.set(true)
end
end

View file

@ -27,6 +27,7 @@ set new app version and if browser reload is required
=end =end
def self.set(reload_required = false) def self.set(reload_required = false)
return false if !Setting.find_by(name: 'app_version')
version = "#{Time.zone.now.strftime('%Y%m%d%H%M%S')}:#{reload_required}" version = "#{Time.zone.now.strftime('%Y%m%d%H%M%S')}:#{reload_required}"
Setting.set('app_version', version) Setting.set('app_version', version)

View file

@ -1,5 +1,13 @@
// form // form
test( "form without @el", function() {
var form = new App.ControllerForm()
equal($(form.html()).is('div'), true)
equal($(form.html()).hasClass('alert'), true)
equal($(form.html()).hasClass('hide'), true)
})
test( "form elements check", function() { test( "form elements check", function() {
// deepEqual( item, test.value, 'group set/get tests' ); // deepEqual( item, test.value, 'group set/get tests' );
$('#forms').append('<hr><h1>form elements check</h1><form id="form1"></form>') $('#forms').append('<hr><h1>form elements check</h1><form id="form1"></form>')