Class | Item |
In: |
app/models/item.rb
|
Parent: | ActiveRecord::Base |
画面の項目のモデル。
LABEL_ALIGN | = | [ [N_("Item|align|Left"), "left"], [N_("Item|align|Right"), "right"], [N_("Item|align|Center"), "center"], ] |
LABEL_DECORATOR | = | [ [N_("Item|decorator|None"), "none"], [N_("Item|decorator|Front"), "front"], [N_("Item|decorator|Back"), "back"], [N_("Item|decorator|Currency"), "currency"], [N_("Item|decorator|Convert line break"), "nl2br"], ] |
LABEL_CONDITION_PATTERN | = | [ [N_("Item|condition_pattern|None"), "none"], [N_("Item|condition_pattern|Equal"), "eq"], [N_("Item|condition_pattern|Not Equal"), "neq"], [N_("Item|condition_pattern|Matched with Head"), "head"], [N_("Item|condition_pattern|Matched with Tail"), "tail"], [N_("Item|condition_pattern|Include"), "include"], [N_("Item|condition_pattern|Exclude"), "exclude"], [N_("Item|condition_pattern|Null"), "null"], [N_("Item|condition_pattern|Not Null"), "not-null"], [N_("Item|condition_pattern|Greater than or Equal"), "ge"], [N_("Item|condition_pattern|Less than or Equal"), "le"], [N_("Item|condition_pattern|Greater thanl"), "gt"], [N_("Item|condition_pattern|Less than"), "lt"], ] |
LABEL_DIRECTION | = | [ [N_("Item|direction|NONE"), "NONE"], [N_("Item|direction|ASC"), "ASC"], [N_("Item|direction|DESC"), "DESC"], ] |
LABEL_CONTROL | = | [ [N_("Item|control|Available Freely"), "free"], [N_("Item|control|According to Permission"), "permission"], [N_("Item|control|Administrator Only"), "admin"], ] |
LABEL_INPUT_TYPE | = | [ [N_("Item|input_type|Text Field"), "text"], [N_("Item|input_type|Text Area"), "textarea"], [N_("Item|input_type|Radio Button"), "radio"], [N_("Item|input_type|Check Box"), "checkbox"], [N_("Item|input_type|Combo Box"), "select"], [N_("Item|input_type|Picker"), "picker"], ] |
LABEL_INPUT_INITIALIZER | = | [ [N_("Item|input_initializer|None"), ""], [N_("Item|input_initializer|Person Name"), "person"], [N_("Item|input_initializer|Company Name"), "company"], [N_("Item|input_initializer|Organization Name"), "organization"], [N_("Item|input_initializer|Today's Date"), "today"], [N_("Item|input_initializer|Counter"), "counter"], [N_("Item|input_initializer|Use the specified value"), "custom"] |
LABEL_SEARCH | = | [ [N_("Item|search|On"), true], [N_("Item|search|Off"), false], ] |
LABEL_LINKED | = | [ [N_("Item|linked|Linked"), true], [N_("Item|linked|Unlinked"), false], ] |
LABEL_ORDERED | = | [ [N_("Item|ordered|On"), true], [N_("Item|ordered|Off"), false], ] |
LABEL_SELECTED | = | [ [N_("Item|selected|On"), true], [N_("Item|selected|Off"), false], ] |
VALIDATES_COLUMN_NAME | = | %w[ presence non_negative_integer integer non_negative_float float zero upper_case lower_case alphabetic alphanumeric halfwidth_katakana fullwidth fullwidth_katakana inclusion_chars minimum_length maximum_length integral_length fractional_length year year_month year_month_day hour hour_minute postal_code phone_number email url minimum_number period future_date past_date uniqueness row ].map {|x| "validates_#{x}"} |
VALIDATES_COLUMN_PARAMETER_COUNT | = | { :validates_inclusion_chars => 1, :validates_minimum_length => 1, :validates_maximum_length => 1, :validates_integral_length => 2, :validates_fractional_length => 2, :validates_minimum_number => 1, :validates_period => 2, :validates_row => 2, } |
# File app/models/item.rb, line 278 278: def apply_validations(it) 279: validations.reverse_each do |args| 280: it.__send__(*args) 281: end 282: end
レイアウトのアルファベット部分を返す。
# File app/models/item.rb, line 330 330: def coordinate_alphabet 331: return coordinates && coordinates.sub(/\d+\z/, "") 332: end
レイアウトの番号部分を返す。
# File app/models/item.rb, line 335 335: def coordinate_number 336: return coordinates && coordinates.sub(/\A[A-Z]+/, "").to_i 337: end
レイアウトの名前を返す。
# File app/models/item.rb, line 324 324: def coordinates 325: option = InputOption.find_by_category_and_value(display.is_a?(DisplayToList) ? "item_layout_list" : "item_layout_show", layout.to_s) 326: return option && option.name 327: end
# File app/models/item.rb, line 238 238: def detail? 239: model_class != display.model_class 240: end
it を初期化する。
# File app/models/item.rb, line 295 295: def initialize_column_of(it) 296: return unless writable? 297: return if input_initializer.blank? 298: case input_initializer 299: when "person" 300: it[column_name] = User.current.person_id 301: when "company" 302: record = User.current.person.company_members.find(:first, :select => "DISTINCT company_id") 303: if record 304: it[column_name] = record.company_id 305: end 306: when "organization" 307: record = User.current.person.organization_members.find(:first, :select => "DISTINCT organization_id") 308: if record 309: it[column_name] = record.organization_id 310: end 311: when "today" 312: it[column_name] = Time.now.strftime("%Y/%m/%d") 313: when "counter" 314: args = input_initial_value.split(',') 315: it[column_name] = Counter.format(*args) 316: when "custom" 317: it[column_name] = input_initial_value 318: else 319: logger.warn("WARN: invalid input_initializer: #{input_initializer}") 320: end 321: end
リンクが有効ならばその URL、無効ならば false を返す。
# File app/models/item.rb, line 382 382: def link_url(it) 383: linked? && link_parameter % {:id => it.id, :class => it.class, :data => to_data(it)} 384: end
モデルのクラスを返す。
# File app/models/item.rb, line 234 234: def model_class 235: @model_class ||= model_name.constantize 236: end
個人利用のためのコピーを返す。
# File app/models/item.rb, line 387 387: def private_copy(display_id) 388: item = self.class.new 389: item.attributes = attributes 390: message_source = PoMessageSingular.find(name_po) 391: message_copy = message_source.private_copy 392: item.name_po = message_copy.id 393: item.display_id = display_id 394: item.save! 395: return item 396: end
読み取り権限があるかどうかを判定する。
# File app/models/item.rb, line 285 285: def readable? 286: @readable ||= controlled? "visible", "full" 287: end
入力フィールドの size 属性の値を返す。
# File app/models/item.rb, line 350 350: def size_for_input_field 351: case input_type 352: when "textarea" 353: return field_size.blank? ? "30x5" : field_size 354: else 355: return field_size.blank? ? 30 : field_size.to_i 356: end 357: end
選択肢を返す、もしくは block に渡す。
# File app/models/item.rb, line 360 360: def split_into_input_options(&block) 361: case input_parameter 362: when /,/ 363: input_parameter.split(",").map do |pair| 364: value, text = pair.split(":", 2) 365: block_given? ? yield(text, value) : [text, value] 366: end 367: when /#/ 368: model_name, method_name = input_parameter.split("#", 2) 369: model_name.classify.constantize.find(:all).map do |x| 370: name = x.__send__(method_name) 371: value = x.id 372: block_given? ? yield(name, value) : [name, value] 373: end 374: else 375: InputOption.options_for_select(input_parameter).map do |name, value| 376: block_given? ? yield(name, value) : [name, value] 377: end 378: end 379: end
検証項目の一覧を返す。
# File app/models/item.rb, line 243 243: def validations 244: @validations ||= Item::VALIDATES_COLUMN_NAME.map do |validation| 245: if __send__("#{validation}?") 246: case validation 247: when "validates_inclusion_chars" 248: [:validates_inclusion_chars_of, column_name, {:chars => validates_inclusion_chars_1, :if => proc_filled?}] 249: when "validates_minimum_length" 250: [:validates_length_of, column_name, {:minimum => validates_minimum_length_1.to_i, :if => proc_filled?}] 251: when "validates_maximum_length" 252: [:validates_length_of, column_name, {:maximum => validates_maximum_length_1.to_i, :if => proc_filled?}] 253: when "validates_integral_length" 254: [:validates_integral_length_of, column_name, option_for_range(validates_integral_length_1.to_i, validates_integral_length_2.to_i, 0)] 255: when "validates_fractional_length" 256: [:validates_fractional_length_of, column_name, option_for_range(validates_fractional_length_1.to_i, validates_fractional_length_2.to_i, 0)] 257: when "validates_minimum_number" 258: [:validates_minimum_number_of, column_name, {:minimum => validates_minimum_number_1.to_i, :if => proc_filled?}] 259: when "validates_period" 260: [:validates_period_of, column_name, option_for_range(validates_period_1, validates_period_2, "")] 261: when "validates_future_date" 262: [:validates_later_date_of, column_name, {:than => Clock.now.strftime("%Y%m%d"), :if => proc_filled?}] 263: when "validates_past_date" 264: [:validates_earlier_date_of, column_name, {:than => Clock.now.strftime("%Y%m%d"), :if => proc_filled?}] 265: when "validates_row" 266: [:validates_row_of, column_name, {:table => validates_row_1, :column => validates_row_2}] 267: when "validates_presence" 268: [:validates_presence_of, column_name] 269: else 270: ["#{validation}_of", column_name, {:if => proc_filled?}] 271: end 272: end 273: end.compact 274: return @validations 275: end