From f8eca380d74ad1e371fb2e5c4de62a493e9f84f7 Mon Sep 17 00:00:00 2001 From: yasushiito Date: Wed, 23 Oct 2013 08:23:41 +0900 Subject: [PATCH] t#32066:validate_forms --- Gemfile | 1 + app/assets/javascripts/application.js | 3 + app/assets/javascripts/configurations.js.coffee | 1443 +++++++++++++---------- app/assets/javascripts/panels.js.coffee | 64 + app/assets/stylesheets/test.css.scss | 2 + app/helpers/application_helper.rb | 1440 ++++++++++++---------- app/models/panel.rb | 11 +- app/models/speech_balloon.rb | 4 + app/views/home/index.html.erb | 1 - app/views/panels/_element_form.html.erb | 90 +- app/views/panels/_element_tab.html.erb | 2 +- app/views/panels/_form.html.erb | 26 +- lib/element.rb | 20 + 13 files changed, 1830 insertions(+), 1277 deletions(-) diff --git a/Gemfile b/Gemfile index dcd755b5..80208ee9 100644 --- a/Gemfile +++ b/Gemfile @@ -33,6 +33,7 @@ end gem 'jquery-rails' gem 'jquery-ui-rails' +gem "jquery-validation-rails" # To use ActiveModel has_secure_password gem 'bcrypt-ruby', '~> 3.0.0' diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index b61302f8..9dbdb97f 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -7,6 +7,9 @@ //= require jquery //= require jquery_ujs //= require jquery.ui.all +//= require jquery.validate +//= require jquery.validate.additional-methods +//= require jquery.validate.localization/messages_ja //= require textchange //= require configurations //= require pettanr_editor diff --git a/app/assets/javascripts/configurations.js.coffee b/app/assets/javascripts/configurations.js.coffee index ea2884c2..091a42ac 100644 --- a/app/assets/javascripts/configurations.js.coffee +++ b/app/assets/javascripts/configurations.js.coffee @@ -1,5 +1,68 @@ @configurations = { models: { + Panel: 'panel', + panel: { + class_name: 'Panel', + table_name: 'panels', + attributes: { + id: { + type: 'number', + primary_key: 1, + rules : { + number: true, + } + }, + width: { + type: 'number', + rules : { + required: true, + number: true, + min: 1, + } + }, + height: { + type: 'number', + rules : { + required: true, + number: true, + min: 1, + } + }, + border: { + type: 'number', + rules : { + required: true, + number: true, + min: 0, + } + }, + caption: { + type: 'text', + rules : { + } + }, + publish: { + type: 'number', + rules : { + required: true, + number: true, + } + }, + author_id: { + type: 'number', + rules : { + required: true, + number: true, + } + }, + created_at: { + type: 'datetime', + }, + updated_at: { + type: 'datetime', + } + } + }, PanelPicture: 'panel_picture', panel_picture: { class_name: 'PanelPicture', @@ -8,36 +71,77 @@ id: { type: 'number', primary_key: 1, + rules : { + number: true, + } }, panel_id: { type: 'number', + rules : { + number: true, + } }, picture_id: { type: 'number', + rules : { + required: true, + number: true, + } }, caption: { type: 'text', + rules : { + } }, x: { type: 'number', + rules : { + required: true, + number: true, + } }, y: { type: 'number', + rules : { + required: true, + number: true, + } }, width: { type: 'number', + rules : { + required: true, + number: true, + } }, height: { type: 'number', + rules : { + required: true, + number: true, + } }, link: { type: 'text', + rules : { + url: true, + } }, z: { type: 'number', + rules : { + required: true, + number: true, + min: 1, + } }, t: { type: 'number', + rules : { + required: true, + number: true, + min: 0, + } }, created_at: { type: 'datetime', @@ -56,27 +160,54 @@ id: { type: 'number', primary_key: 1, + rules : { + number: true, + } }, panel_id: { type: 'number', + rules : { + number: true, + } }, speech_balloon_template_id: { type: 'number', + rules : { + required: true, + number: true, + } }, classname: { type: 'text', + rules : { + required: true, + } }, z: { type: 'number', + rules : { + required: true, + number: true, + min: 1, + } }, t: { type: 'number', + rules : { + required: true, + number: true, + min: 0, + } }, settings: { type: 'text', + rules : { + } }, caption: { type: 'text', + rules : { + } }, created_at: { type: 'datetime', @@ -94,30 +225,64 @@ id: { type: 'number', primary_key: 1, + rules : { + number: true, + } }, speech_balloon_id: { type: 'number', + rules : { + number: true, + } }, system_picture_id: { type: 'number', + rules : { + required: true, + number: true, + } }, x: { type: 'number', + rules : { + required: true, + number: true, + } }, y: { type: 'number', + rules : { + required: true, + number: true, + } }, width: { type: 'number', + rules : { + required: true, + number: true, + min: 1, + } }, height: { type: 'number', + rules : { + required: true, + number: true, + min: 1, + } }, r: { type: 'number', + rules : { + required: true, + number: true, + } }, settings: { type: 'text', + rules : { + } }, created_at: { type: 'datetime', @@ -135,42 +300,91 @@ id: { type: 'number', primary_key: 1, + rules : { + number: true, + } }, speech_balloon_id: { type: 'number', + rules : { + number: true, + } }, writing_format_id: { type: 'number', + rules : { + required: true, + number: true, + } }, content: { type: 'text', + rules : { + } }, font_size: { type: 'float', + rules : { + required: true, + number: true, + min: 0, + } }, text_align: { type: 'number', + rules : { + required: true, + number: true, + range: [0, 3], + } }, fore_color: { type: 'number', + rules : { + required: true, + number: true, + range: [0, 0xffffff], + } }, x: { type: 'number', + rules : { + required: true, + number: true, + } }, y: { type: 'number', + rules : { + required: true, + number: true, + } }, width: { type: 'number', + rules : { + required: true, + number: true, + min: 1, + } }, height: { type: 'number', + rules : { + required: true, + number: true, + min: 1, + } }, quotes: { type: 'text', + rules : { + } }, settings: { type: 'text', + rules : { + } }, created_at: { type: 'datetime', @@ -188,30 +402,65 @@ id: { type: 'number', primary_key: 1, + rules : { + number: true, + } }, panel_id: { type: 'number', + rules : { + number: true, + } }, picture_id: { type: 'number', + rules : { + required: true, + number: true, + } }, caption: { type: 'text', + rules : { + } }, repeat: { type: 'number', + rules : { + required: true, + number: true, + range: [0, 3], + } }, x: { type: 'number', + rules : { + required: true, + number: true, + } }, y: { type: 'number', + rules : { + required: true, + number: true, + } }, z: { type: 'number', + rules : { + required: true, + number: true, + min: 1, + } }, t: { type: 'number', + rules : { + required: true, + number: true, + min: 0, + } }, created_at: { type: 'datetime', @@ -229,21 +478,44 @@ id: { type: 'number', primary_key: 1, + rules : { + number: true, + } }, panel_id: { type: 'number', + rules : { + number: true, + } }, caption: { type: 'text', + rules : { + } }, code: { type: 'number', + rules : { + required: true, + number: true, + range: [0, 0xffffff], + } }, z: { type: 'number', + rules : { + required: true, + number: true, + min: 1, + } }, t: { type: 'number', + rules : { + required: true, + number: true, + min: 0, + } }, created_at: { type: 'datetime', @@ -261,21 +533,40 @@ id: { type: 'number', primary_key: 1, + rules : { + number: true, + } }, name: { type: 'text', + rules : { + required: true, + } }, classname: { type: 'text', + rules : { + required: true, + } }, caption: { type: 'text', + rules : { + required: true, + } }, system_picture_id: { type: 'number', + rules : { + required: true, + number: true, + } }, settings: { type: 'text', + rules : { + required: true, + } }, created_at: { type: 'datetime', @@ -310,35 +601,123 @@ }, ], forms: { + Panel: 'panel', + panel: { + attributes: { + caption: { + column: 'caption', + type: 'text', + label: { + }, + options: { + row_break: true + } + }, + width: { + column: 'width', + type: 'number', + label: { + }, + options: { + size: 5, + }, + }, + height: { + column: 'height', + type: 'number', + label: { + }, + options: { + size: 5, + row_break: true + }, + }, + border: { + column: 'border', + type: 'number', + label: { + }, + options: { + size: 5, + }, + }, + publish: { + column: 'publish', + type: 'select', + label: { + }, + options: { + source: 'magic_number', + key: 'comic_visible_items', + size: 5, + row_break: true + } + }, + id: { + column: 'id', + type: 'hidden', + label: { + type: 'hidden' + }, + options: { + } + }, + author_id: { + column: 'author_id', + type: 'hidden', + label: { + type: 'hidden' + }, + options: { + } + }, + }, + fields: [ + 'caption', + 'width', + 'height', + 'border', + 'publish', + 'id', + 'author_id', + ] + }, PanelPicture: 'panel_picture', panel_picture: { - fields: [ - { + attributes: { + caption: { column: 'caption', type: 'text', + label: { + }, options: { - label_break: false, row_break: true } }, - { + x: { column: 'x', type: 'number', + label: { + }, options: { size: 5, } }, - { + y: { column: 'y', type: 'number', + label: { + }, options: { size: 5, row_break: true } }, - { + width: { column: 'width', type: 'number', + label: { + }, options: { size: 5, row_break: true @@ -352,9 +731,11 @@ } }, }, - { + height: { column: 'height', type: 'number', + label: { + }, options: { size: 5, row_break: true @@ -368,60 +749,189 @@ } }, }, - { + link: { column: 'link', type: 'text', + label: { + }, options: { row_break: true } }, - { + id: { column: 'id', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, - { + panel_id: { column: 'panel_id', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, - { + picture_id: { column: 'picture_id', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, - { + z: { column: 'z', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, - { + t: { column: 't', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, + }, + fields: [ + 'caption', + 'x', + 'y', + 'width', + 'height', + 'link', + 'id', + 'panel_id', + 'picture_id', + 'z', + 't', ] }, - CircleSpeechBalloon: 'circle_speech_balloon', - circle_speech_balloon: { - base: 'speech_balloon', - fields: [ - { + speech_balloon: { + attributes: { + 'speech_balloon.id': { + column: 'id', + type: 'hidden', + label: { + type: 'hidden' + }, + options: { + } + }, + 'speech_balloon.panel_id': { + column: 'panel_id', + type: 'hidden', + label: { + type: 'hidden' + }, + options: { + } + }, + 'speech_balloon.speech_balloon_template_id': { + column: 'speech_balloon_template_id', + type: 'hidden', + label: { + type: 'hidden' + }, + options: { + } + }, + 'speech_balloon.caption': { column: 'caption', type: 'text', + label: { + }, options: { row_break: true } }, - { + 'speech_balloon.z': { + column: 'z', + type: 'hidden', + label: { + type: 'hidden' + }, + options: { + } + }, + 'speech_balloon.t': { + column: 't', + type: 'hidden', + label: { + type: 'hidden' + }, + options: { + } + }, + 'speech_balloon.classname': { + column: 'classname', + type: 'hidden', + label: { + type: 'hidden' + }, + options: { + } + }, + 'speech_balloon.settings': { + column: 'settings', + type: 'hidden', + label: { + type: 'hidden' + }, + options: { + } + }, + 'balloon.id': { + model: 'balloon', + part: 'balloon', + column: 'id', + type: 'hidden', + label: { + type: 'hidden' + }, + options: { + } + }, + 'balloon.speech_balloon_id': { + model: 'balloon', + part: 'balloon', + column: 'speech_balloon_id', + type: 'hidden', + label: { + type: 'hidden' + }, + options: { + } + }, + 'balloon.system_picture_id': { + model: 'balloon', + part: 'balloon', + column: 'system_picture_id', + type: 'hidden', + label: { + type: 'hidden' + }, + options: { + } + }, + 'balloon.r': { + model: 'balloon', part: 'balloon', column: 'r', type: 'number', + label: { + }, options: { size: 5, row_break: true @@ -434,544 +944,136 @@ } } }, - { + 'balloon.x': { + model: 'balloon', part: 'balloon', column: 'x', type: 'number', + label: { + }, options: { size: 5, } }, - { + 'balloon.y': { + model: 'balloon', part: 'balloon', column: 'y', type: 'number', + label: { + }, options: { size: 5, row_break: true } }, - { + 'balloon.width': { + model: 'balloon', part: 'balloon', column: 'width', type: 'number', + label: { + }, options: { size: 5, } }, - { + 'balloon.height': { + model: 'balloon', part: 'balloon', column: 'height', type: 'number', + label: { + }, options: { size: 5, row_break: true } }, - { + 'balloon.settings': { + model: 'balloon', part: 'balloon', - column: 'id', + column: 'settings', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, - { - part: 'balloon', - column: 'speech_balloon_id', - type: 'hidden', - options: { - } - }, - { - part: 'balloon', - column: 'system_picture_id', - type: 'hidden', - options: { - } - }, - { - part: 'balloon', - column: 'settings', - type: 'hidden', - options: { - } - }, - { - part: 'speech', - column: 'writing_format_id', - type: 'select', - options: { - source: 'model', - model: 'writing_format', - method: 'enable_list', - caption: 'caption' - } - }, - { - part: 'speech', - column: 'font_size', - type: 'select', - options: { - source: 'magic_number', - key: 'speech_font_size_items', - row_break: true - } - }, - { - part: 'speech', - column: 'text_align', - type: 'select', - options: { - source: 'magic_number', - key: 'speech_text_align_items', - } - }, - { - part: 'speech', - column: 'quotes', - type: 'text', - options: { - size: 5, - } - }, - { - part: 'speech', - column: 'content', - type: 'text_area', - options: { - label_break: true, - size: '45x5', - } - }, - { - part: 'speech', - column: 'fore_color', - type: 'hidden', - options: { - label_break: true, - }, - helpers: { - color: { - path: 'panels/color_helper', - options: { - }, - wrapper: 'speech-fore_color-wrap' - } - } - }, - { - part: 'speech', - column: 'id', - type: 'hidden', - options: { - } - }, - { - part: 'speech', - column: 'speech_balloon_id', - type: 'hidden', - options: { - } - }, - { - part: 'speech', - column: 'x', - type: 'hidden', - options: { - } - }, - { - part: 'speech', - column: 'y', - type: 'hidden', - options: { - } - }, - { - part: 'speech', - column: 'width', - type: 'hidden', - options: { - } - }, - { - part: 'speech', - column: 'height', - type: 'hidden', - options: { - } - }, - { - part: 'speech', - column: 'settings', - type: 'hidden', - options: { - } - }, - { - column: 'id', - type: 'hidden', - options: { - } - }, - { - column: 'panel_id', - type: 'hidden', - options: { - } - }, - { - column: 'speech_balloon_template_id', - type: 'hidden', - options: { - } - }, - { - column: 'classname', - type: 'hidden', - options: { - } - }, - { - column: 'z', - type: 'hidden', - options: { - } - }, - { - column: 't', - type: 'hidden', - options: { - } - }, - { - column: 'settings', - type: 'hidden', - options: { - } - } - ] - }, - PlainSpeechBalloon: 'plain_speech_balloon', - plain_speech_balloon: { - base: 'speech_balloon', - fields: [ - { - column: 'caption', - type: 'text', - options: { - row_break: true - } - }, - { - part: 'balloon', - column: 'r', - type: 'hidden', - options: { - }, - }, - { - part: 'balloon', - column: 'x', - type: 'number', - options: { - size: 5, - } - }, - { - part: 'balloon', - column: 'y', - type: 'number', - options: { - size: 5, - row_break: true - } - }, - { - part: 'balloon', - column: 'width', - type: 'number', - options: { - size: 5, - } - }, - { - part: 'balloon', - column: 'height', - type: 'number', - options: { - size: 5, - row_break: true - } - }, - { - part: 'balloon', - column: 'id', - type: 'hidden', - options: { - } - }, - { - part: 'balloon', - column: 'speech_balloon_id', - type: 'hidden', - options: { - } - }, - { - part: 'balloon', - column: 'system_picture_id', - type: 'hidden', - options: { - } - }, - { - part: 'balloon', - column: 'settings', - type: 'hidden', - options: { - } - }, - { - part: 'speech', - column: 'writing_format_id', - type: 'select', - options: { - source: 'model', - model: 'writing_format', - method: 'enable_list', - caption: 'caption' - } - }, - { - part: 'speech', - column: 'font_size', - type: 'select', - options: { - source: 'magic_number', - key: 'speech_font_size_items', - row_break: true - } - }, - { - part: 'speech', - column: 'text_align', - type: 'select', - options: { - source: 'magic_number', - key: 'speech_text_align_items', - } - }, - { - part: 'speech', - column: 'quotes', - type: 'text', - options: { - size: 5, - } - }, - { - part: 'speech', - column: 'content', - type: 'text_area', - options: { - label_break: true, - size: '45x5', - } - }, - { - part: 'speech', - column: 'fore_color', - type: 'hidden', - options: { - label_break: true, - }, - helpers: { - color: { - path: 'panels/color_helper', - options: { - }, - wrapper: 'speech-fore_color-wrap' - } - } - }, - { - part: 'speech', - column: 'id', - type: 'hidden', - options: { - } - }, - { - part: 'speech', - column: 'speech_balloon_id', - type: 'hidden', - options: { - } - }, - { - part: 'speech', - column: 'x', - type: 'hidden', - options: { - } - }, - { - part: 'speech', - column: 'y', - type: 'hidden', - options: { - } - }, - { - part: 'speech', - column: 'width', - type: 'hidden', - options: { - } - }, - { - part: 'speech', - column: 'height', - type: 'hidden', - options: { - } - }, - { - part: 'speech', - column: 'settings', - type: 'hidden', - options: { - } - }, - { + 'speech.id': { + model: 'speech', + part: 'speech', column: 'id', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, - { - column: 'panel_id', - type: 'hidden', - options: { - } - }, - { - column: 'speech_balloon_template_id', - type: 'hidden', - options: { - } - }, - { - column: 'classname', - type: 'hidden', - options: { - } - }, - { - column: 'z', - type: 'hidden', - options: { - } - }, - { - column: 't', - type: 'hidden', - options: { - } - }, - { - column: 'settings', + 'speech.speech_balloon_id': { + model: 'speech', + part: 'speech', + column: 'speech_balloon_id', type: 'hidden', + label: { + type: 'hidden' + }, options: { } - } - ] - }, - SquareSpeechBalloon: 'square_speech_balloon', - square_speech_balloon: { - base: 'speech_balloon', - fields: [ - { - column: 'caption', - type: 'text', - options: { - row_break: true - } }, - { - part: 'balloon', - column: 'r', + 'speech.x': { + model: 'speech', + part: 'speech', + column: 'x', type: 'hidden', - options: { + label: { + type: 'hidden' }, - }, - { - part: 'balloon', - column: 'x', - type: 'number', options: { - size: 5, } }, - { - part: 'balloon', + 'speech.y': { + model: 'speech', + part: 'speech', column: 'y', - type: 'number', - options: { - size: 5, - row_break: true - } - }, - { - part: 'balloon', - column: 'width', - type: 'number', - options: { - size: 5, - } - }, - { - part: 'balloon', - column: 'height', - type: 'number', - options: { - size: 5, - row_break: true - } - }, - { - part: 'balloon', - column: 'id', - type: 'hidden', - options: { - } - }, - { - part: 'balloon', - column: 'speech_balloon_id', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, - { - part: 'balloon', - column: 'system_picture_id', + 'speech.width': { + model: 'speech', + part: 'speech', + column: 'width', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, - { - part: 'balloon', - column: 'settings', + 'speech.height': { + model: 'speech', + part: 'speech', + column: 'height', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, - { + 'speech.writing_format_id': { + model: 'speech', part: 'speech', column: 'writing_format_id', type: 'select', + label: { + }, options: { source: 'model', model: 'writing_format', @@ -979,48 +1081,63 @@ caption: 'caption' } }, - { + 'speech.font_size': { + model: 'speech', part: 'speech', column: 'font_size', type: 'select', + label: { + }, options: { source: 'magic_number', key: 'speech_font_size_items', row_break: true } }, - { + 'speech.text_align': { + model: 'speech', part: 'speech', column: 'text_align', type: 'select', + label: { + }, options: { source: 'magic_number', key: 'speech_text_align_items', } }, - { + 'speech.quotes': { + model: 'speech', part: 'speech', column: 'quotes', type: 'text', + label: { + }, options: { size: 5, } }, - { + 'speech.content': { + model: 'speech', part: 'speech', column: 'content', type: 'text_area', + label: { + row_break: true + }, options: { - label_break: true, size: '45x5', } }, - { + 'speech.fore_color': { + model: 'speech', part: 'speech', column: 'fore_color', type: 'hidden', + label: { + row_break: true + }, options: { - label_break: true, }, helpers: { color: { @@ -1031,180 +1148,292 @@ } } }, - { - part: 'speech', - column: 'id', - type: 'hidden', - options: { - } - }, - { - part: 'speech', - column: 'speech_balloon_id', - type: 'hidden', - options: { - } - }, - { - part: 'speech', - column: 'x', - type: 'hidden', - options: { - } - }, - { - part: 'speech', - column: 'y', - type: 'hidden', - options: { - } - }, - { + 'speech.settings': { + model: 'speech', part: 'speech', - column: 'width', + column: 'settings', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, - { - part: 'speech', - column: 'height', + }, + }, + CircleSpeechBalloon: 'circle_speech_balloon', + circle_speech_balloon: { + base: 'speech_balloon', + attributes: { + }, + fields: [ + 'speech_balloon.caption', + 'balloon.r', + 'balloon.x', + 'balloon.y', + 'balloon.width', + 'balloon.height', + 'balloon.id', + 'balloon.speech_balloon_id', + 'balloon.system_picture_id', + 'balloon.settings', + 'speech.writing_format_id', + 'speech.font_size', + 'speech.text_align', + 'speech.quotes', + 'speech.content', + 'speech.fore_color', + 'speech.id', + 'speech.speech_balloon_id', + 'speech.x', + 'speech.y', + 'speech.width', + 'speech.height', + 'speech.settings', + 'speech_balloon.id', + 'speech_balloon.panel_id', + 'speech_balloon.speech_balloon_template_id', + 'speech_balloon.classname', + 'speech_balloon.z', + 'speech_balloon.t', + 'speech_balloon.settings', + ] + }, + PlainSpeechBalloon: 'plain_speech_balloon', + plain_speech_balloon: { + base: 'speech_balloon', + attributes: { + 'balloon.r': { + model: 'balloon', + part: 'balloon', + column: 'r', type: 'hidden', + label: { + type: 'hidden' + }, options: { - } + }, }, - { - part: 'speech', - column: 'settings', + }, + fields: [ + 'speech_balloon.caption', + 'balloon.r', + 'balloon.x', + 'balloon.y', + 'balloon.width', + 'balloon.height', + 'balloon.id', + 'balloon.speech_balloon_id', + 'balloon.system_picture_id', + 'balloon.settings', + 'speech.writing_format_id', + 'speech.font_size', + 'speech.text_align', + 'speech.quotes', + 'speech.content', + 'speech.fore_color', + 'speech.id', + 'speech.speech_balloon_id', + 'speech.x', + 'speech.y', + 'speech.width', + 'speech.height', + 'speech.settings', + 'speech_balloon.id', + 'speech_balloon.panel_id', + 'speech_balloon.speech_balloon_template_id', + 'speech_balloon.classname', + 'speech_balloon.z', + 'speech_balloon.t', + 'speech_balloon.settings', + ] + }, + SquareSpeechBalloon: 'square_speech_balloon', + square_speech_balloon: { + base: 'speech_balloon', + attributes: { + 'balloon.r': { + model: 'balloon', + part: 'balloon', + column: 'r', type: 'hidden', + label: { + type: 'hidden' + }, options: { - } + }, }, - { + }, + fields: [ + 'speech_balloon.caption', + 'balloon.r', + 'balloon.x', + 'balloon.y', + 'balloon.width', + 'balloon.height', + 'balloon.id', + 'balloon.speech_balloon_id', + 'balloon.system_picture_id', + 'balloon.settings', + 'speech.writing_format_id', + 'speech.font_size', + 'speech.text_align', + 'speech.quotes', + 'speech.content', + 'speech.fore_color', + 'speech.id', + 'speech.speech_balloon_id', + 'speech.x', + 'speech.y', + 'speech.width', + 'speech.height', + 'speech.settings', + 'speech_balloon.id', + 'speech_balloon.panel_id', + 'speech_balloon.speech_balloon_template_id', + 'speech_balloon.classname', + 'speech_balloon.z', + 'speech_balloon.t', + 'speech_balloon.settings', + ] + }, + GroundPicture: 'ground_picture', + ground_picture: { + attributes: { + id: { column: 'id', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, - { + panel_id: { column: 'panel_id', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, - { - column: 'speech_balloon_template_id', - type: 'hidden', - options: { - } - }, - { - column: 'classname', - type: 'hidden', - options: { - } - }, - { - column: 'z', - type: 'hidden', - options: { - } - }, - { - column: 't', + picture_id: { + column: 'picture_id', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, - { - column: 'settings', - type: 'hidden', - options: { - } - } - ] - }, - GroundPicture: 'ground_picture', - ground_picture: { - fields: [ - { + caption: { column: 'caption', type: 'text', + label: { + }, options: { row_break: true } }, - { + repeat: { column: 'repeat', type: 'select', + label: { + }, options: { source: 'magic_number', key: 'ground_picture_repeat_items', row_break: true } }, - { + x: { column: 'x', type: 'number', + label: { + }, options: { size: 5, } }, - { + y: { column: 'y', type: 'number', + label: { + }, options: { size: 5, row_break: true } }, - { + z: { column: 'z', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, - { + t: { column: 't', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, - { + }, + fields: [ + 'caption', + 'repeat', + 'x', + 'y', + 'z', + 't', + 'id', + 'panel_id', + 'picture_id', + ] + }, + GroundColor: 'ground_color', + ground_color: { + attributes: { + id: { column: 'id', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, - { + panel_id: { column: 'panel_id', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, - { - column: 'picture_id', - type: 'hidden', - options: { - } - }, - ] - }, - GroundColor: 'ground_color', - ground_color: { - fields: [ - { + caption: { column: 'caption', type: 'text', + label: { + }, options: { row_break: true } }, - { + code: { column: 'code', type: 'hidden', + label: { + row_break: true + }, options: { - label_break: true, row_break: true } helpers: { @@ -1216,30 +1445,32 @@ } }, }, - { + z: { column: 'z', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, - { + t: { column: 't', type: 'hidden', + label: { + type: 'hidden' + }, options: { } }, - { - column: 'id', - type: 'hidden', - options: { - } - }, - { - column: 'panel_id', - type: 'hidden', - options: { - } - }, + }, + fields: [ + 'id', + 'panel_id', + 'caption', + 'code', + 'z', + 't', ] } }, diff --git a/app/assets/javascripts/panels.js.coffee b/app/assets/javascripts/panels.js.coffee index c2c50e02..40998050 100644 --- a/app/assets/javascripts/panels.js.coffee +++ b/app/assets/javascripts/panels.js.coffee @@ -2,6 +2,7 @@ $ -> confirm_confirm_confirm = () -> confirm( ) editor = window.PettanrEditor + configurations = window.configurations WritingFormat = window.PettanrWritingFormat WritingFormat.load($('#writing_formats')) SpeechBalloonTemplate = window.PettanrSpeechBalloonTemplate @@ -12,6 +13,64 @@ $ -> PictureSizeHelper = window.PettanrPictureSizeHelper ColorHelper = window.PettanrColorHelper + find_configurations = ( hash, key) -> + if typeof(hash[key]) == 'string' + find_configurations(hash, hash[key]) + else + return hash[key] + + set_validates = (form) -> + rules = {} + $('input', form).map -> + model_name = $(@).attr('data-model') + column_name = $(@).attr('column') + name = $(@).attr('name') + if model_name and column_name + model = find_configurations(configurations['models'], model_name) + rule = model['attributes'][column_name]['rules'] + trace = editor.element_tag_id($(@)) + if rule + rules[name] = rule + if Object.keys(rules).length > 0 + v = form.validate({ignore:[],rules: rules}) + + validate_forms = () -> + valid = true + $('form', $('#tabs-1')).map -> + form_name = $(@).attr('data-form-name') + if form_name + if $(@).valid() + bc = '' + else + valid = false + bc = '#ef29ef' + $('a', $('#tabs-1-tab')).map -> + $(@).css('background-color', bc) + invalid_elements = [] + $('form', $('#tabs-2')).map -> + form_name = $(@).attr('data-form-name') + if form_name + if $(@).valid() + bc = '' + else + valid = false + bc = '#ef29ef' + invalid_elements.push form_name + trace = editor.element_tag_id($(@)) + $('.elements-tab', $(trace + 'element_tab')).map -> + $(@).css('background-color', bc) + if invalid_elements.length > 0 + bc = '#ef29ef' + else + bc = '' + $('a', $('#tabs-2-tab')).map -> + $(@).css('background-color', bc) + return valid + $('form').map -> + form_name = $(@).attr('data-form-name') + if form_name + form = $(this) + set_validates(form) $('.panel-editor').map -> if $(@).attr('current') and parseInt($(@).attr('current')) > 0 editor.pettanr_current_panel_id = parseInt($(@).attr('panel_id')) @@ -421,6 +480,11 @@ $ -> $('.edit_panel' ).map -> if $(@).attr('jqform') + $(@).submit -> + if validate_forms() + true + else + false else $(@).submit -> false diff --git a/app/assets/stylesheets/test.css.scss b/app/assets/stylesheets/test.css.scss index a6fdfe87..b3a7462b 100644 --- a/app/assets/stylesheets/test.css.scss +++ b/app/assets/stylesheets/test.css.scss @@ -271,6 +271,8 @@ font-family : monospace; .ui-tabs .ui-tabs-nav li.ui-tabs-active { margin-bottom: 0.2em; } +.element-tab { +} .elements-tab { width: 100%; overflow: hidden; diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index bac1cae5..a63fee45 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -67,6 +67,69 @@ module ApplicationHelper JSON.parse(< true, :numericality => true, :natural_number => true validates :height, :presence => true, :numericality => true, :natural_number => true validates :border, :presence => true, :numericality => {:greater_than_or_equal_to => 0} - validates :x, :numericality => {:allow_blank => true} - validates :y, :numericality => {:allow_blank => true} - validates :z, :numericality => {:allow_blank => true, :greater_than => 0} validates :author_id, :presence => true, :numericality => true, :existence => {:both => false} validates :publish, :presence => true, :numericality => true @@ -85,8 +82,8 @@ class Panel < ActiveRecord::Base self.publish > 0 end - def tag_id - 'panel' + self.tag_panel_id + def tag_id c = nil + 'panel' + self.tag_panel_id + c.to_s end def tag_panel_id @@ -103,11 +100,11 @@ class Panel < ActiveRecord::Base }.merge(opt) end - def select_tag_attributes(selected, column) + def select_tag_attributes(selected, column, opt = {}) [ :last, :first, {:html => {:selected => selected}}, - self.field_tag_attributes(column) + self.field_tag_attributes(column, opt) ] end diff --git a/app/models/speech_balloon.rb b/app/models/speech_balloon.rb index 06e1881f..78772837 100644 --- a/app/models/speech_balloon.rb +++ b/app/models/speech_balloon.rb @@ -47,6 +47,10 @@ class SpeechBalloon < ActiveRecord::Base false end + def extend_column + 'classname' + end + def supply_default if self.panel self.t = self.panel.new_t diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 392ac957..d8653b12 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,5 +1,4 @@

<%= t '.title' -%>

-

<%= link_to h(@author.name), main_app.author_path(@author) -%>

<%= t('.updated_comic') -%>

diff --git a/app/views/panels/_element_form.html.erb b/app/views/panels/_element_form.html.erb index 2ca3be2e..24d49666 100644 --- a/app/views/panels/_element_form.html.erb +++ b/app/views/panels/_element_form.html.erb @@ -1,69 +1,59 @@ -<%= form_for(elm) do |f| %> - <% element_name = elm.class.to_s.underscore %> - <% model = @configurations['models'][element_name] %> - <% view = if model['extend'] %> - <% elm.attributes[model['extend']] %> - <% @configurations['forms'][elm.attributes[model['extend']]] %> - <% else %> - <% @configurations['forms'][element_name] %> - <% end %> - <% form = if view.is_a? String %> - <% @configurations['forms'][view] %> - <% else %> - <% view %> - <% end %> - <% form['fields'].each do |field_conf| %> - <% e = if field_conf['part'] %> - <% @configurations['models'][field_conf['part']] %> - <% else %> - <% model %> - <% end %> - <% column = field_conf['column'] %> - <% primary_key = e['attributes'][column]['primary_key'] %> +<% element_name = elm.element_name %> +<% extend_element_name = elm.extend_element_name %> +<% form_configurations = elm.find_configurations @configurations['forms'], extend_element_name %> +<% base_attributes = if form_configurations['base'] %> + <% @configurations['forms'][form_configurations['base']]['attributes'] %> +<% else %> + <% {} %> +<% end %> +<% extend_attributes = form_configurations['attributes'] || {} %> +<% form_attributes = base_attributes.merge(extend_attributes) %> +<% form_model_name = form_configurations['model'] || form_configurations['base'] || element_name %> +<%= form_for(elm, :html => elm.tag_attributes('form', 'data-form-name' => extend_element_name)) do |f| %> + <% form_configurations['fields'].each do |field_name| %> + <% field_configurations = form_attributes[field_name] || {} %> + <% field_model_name = field_configurations['model'] || form_model_name %> + <% model_configurations = @configurations['models'][field_model_name] %> + <% column = field_configurations['column'] %> + <% model_configurations['attributes'] %> + <% primary_key = model_configurations['attributes'][column]['primary_key'] %> <% next if primary_key and elm.new_record? %> - <% options = field_conf['options'] || {} %> + <% options = field_configurations['options'] || {} %> <% opt = {} %> - <% form_model_name = if form['base'] %> - <% form['base'] %> - <% else %> - <% element_name %> - <% end %> - <% field_model_name = if field_conf['part'] %> - <% field_conf['part'] %> - <% else %> - <% form_model_name %> - <% end %> - <% field_elm = if field_conf['part'] %> - <% elm.__send__ field_conf['part'] %> + <% opt.merge!('data-model' => field_model_name) %> + <% field_element = if field_configurations['part'] %> + <% elm.__send__ field_configurations['part'] %> <% else %> <% elm %> <% end %> - <% name = if field_conf['part'] %> + <% name = if field_configurations['part'] %> <% form_model_name + '[' + field_model_name + '_attributes][' + column + ']' %> <% else %> <% form_model_name + '[' + column + ']' %> <% end %>
- <% unless field_conf['type'] == 'hidden' %> + <% label = field_configurations['label'] || {} %> + <% if label['type'] and label['type'] == 'hidden' %> + <% else %> <%= t 'activerecord.attributes.' + field_model_name + '.' + column %> <% end %> - <% if options['label_break'] %> + <% if label['row_break'] %>
<% end %> - <% case field_conf['type'] %> + <% case field_configurations['type'] %> <% when 'text' %> - <% opt['size'] = field_conf['options']['size'] if field_conf['options']['size'] %> - <%= text_field_tag name, field_elm.attributes[column], field_elm.field_tag_attributes(column, no_attr, opt) %> + <% opt['size'] = field_configurations['options']['size'] if field_configurations['options']['size'] %> + <%= text_field_tag name, field_element.attributes[column], field_element.field_tag_attributes(column, no_attr, opt) %> <% when 'text_area' %> - <% opt['size'] = field_conf['options']['size'] if field_conf['options']['size'] %> - <%= text_area_tag name, field_elm.attributes[column], field_elm.field_tag_attributes(column, no_attr, opt) %> + <% opt['size'] = field_configurations['options']['size'] if field_configurations['options']['size'] %> + <%= text_area_tag name, field_element.attributes[column], field_element.field_tag_attributes(column, no_attr, opt) %> <% when 'number' %> - <% opt['size'] = field_conf['options']['size'] if field_conf['options']['size'] %> - <%= number_field_tag name, field_elm.attributes[column], field_elm.field_tag_attributes(column, no_attr, opt) %> + <% opt['size'] = field_configurations['options']['size'] if field_configurations['options']['size'] %> + <%= number_field_tag name, field_element.attributes[column], field_element.field_tag_attributes(column, no_attr, opt) %> <% when 'hidden' %> - <%= hidden_field_tag name, field_elm.attributes[column], field_elm.field_tag_attributes(column, no_attr, opt) %> + <%= hidden_field_tag name, field_element.attributes[column], field_element.field_tag_attributes(column, no_attr, opt) %> <% when 'select' %> <% items = case options['source'] %> <% when 'model' %> @@ -75,14 +65,14 @@ <% t_select_items(MagicNumber[options['key']]) %> <% else %> <% end %> - <%= select_tag name, options_for_select(items, field_elm.attributes[column]), field_elm.field_tag_attributes(column, no_attr) %> + <%= select_tag name, options_for_select(items, field_element.attributes[column]), field_element.field_tag_attributes(column, no_attr, opt) %> <% end %> - <% if field_conf['helpers'] %> - <% field_conf['helpers'].each do |n, helper| %> + <% if field_configurations['helpers'] %> + <% field_configurations['helpers'].each do |n, helper| %> <% if helper['wrapper'] %>
<% end %> - <%= render helper['path'], :elm => field_elm, :no_attr => no_attr, :opt => helper['options'] %> + <%= render helper['path'], :elm => field_element, :no_attr => no_attr, :opt => helper['options'] %> <% if helper['wrapper'] %>
<% end %> diff --git a/app/views/panels/_element_tab.html.erb b/app/views/panels/_element_tab.html.erb index c56c1ab8..10de5b03 100644 --- a/app/views/panels/_element_tab.html.erb +++ b/app/views/panels/_element_tab.html.erb @@ -1,4 +1,4 @@ -
  • > +
  • >
    <%= render elm.element_face_template, :elm => elm %> diff --git a/app/views/panels/_form.html.erb b/app/views/panels/_form.html.erb index 363a045c..67217dc7 100644 --- a/app/views/panels/_form.html.erb +++ b/app/views/panels/_form.html.erb @@ -1,44 +1,44 @@ <% @configurations = configurations %>
    - <%= form_for(@panel) do |f| %> + <%= form_for(@panel, :html => {:id => @panel.tag_id('form'), 'data-form-name' => 'panel'}) do |f| %> <%= render 'system/error_explanation', :obj => @panel %>
    <%= f.label :caption %> - <%= f.text_field :caption, @panel.field_tag_attributes(:caption) -%> + <%= f.text_field :caption, @panel.field_tag_attributes(:caption, 'data-model' => 'panel') -%>
    <%= f.label :width %> - <%= f.number_field :width, @panel.field_tag_attributes(:width, :size => 5) %> + <%= f.number_field :width, @panel.field_tag_attributes(:width, :size => 5, 'data-model' => 'panel') %>
    <%= f.label :height %> - <%= f.number_field :height, @panel.field_tag_attributes(:height, :size => 5) %> + <%= f.number_field :height, @panel.field_tag_attributes(:height, :size => 5, 'data-model' => 'panel') %>
    <%= f.label :border %> - <%= f.number_field :border, @panel.field_tag_attributes(:border, :size => 5) %> + <%= f.number_field :border, @panel.field_tag_attributes(:border, :size => 5, 'data-model' => 'panel') %>
    <%= f.label :publish %> - <%= f.collection_select :publish, t_select_items(MagicNumber['panel_visible_items']), *@panel.select_tag_attributes(@panel.publish, :publish) %> + <%= f.collection_select :publish, t_select_items(MagicNumber['panel_visible_items']), *@panel.select_tag_attributes(@panel.publish, :publish, 'data-model' => 'panel') %>
    <% unless @panel.new_record? %> - <%= f.hidden_field :id, @panel.field_tag_attributes(:id) %> + <%= f.hidden_field :id, @panel.field_tag_attributes(:id, 'data-model' => 'panel') %> <% end %>
    <%= f.submit 'panels.submit', :class => "submit" %> @@ -180,4 +180,4 @@
    <% end %>
    - <%= text_field_tag "json", '', :id => 'pettanr-configurations' %> + <%# text_field_tag "json", '', :id => 'pettanr-configurations' %> diff --git a/lib/element.rb b/lib/element.rb index dc9b2c6b..a92f430e 100644 --- a/lib/element.rb +++ b/lib/element.rb @@ -48,6 +48,26 @@ module Element self.class.colum_structures[column_name] and self.class.colum_structures[column_name][:helper] end + def element_name + self.class.to_s.underscore + end + + def extend_column + nil + end + + def extend_element_name + self.extend_column ? self.attributes[extend_column] : self.element_name + end + + def find_configurations hash, key + if hash[key].is_a? String + self.find_configurations hash, hash[key] + else + return hash[key] + end + end + def new_index @new_index end -- 2.11.0