ava_rails_generator 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +19 -0
  3. data/Rakefile +54 -0
  4. data/USAGE +27 -0
  5. data/VERSION +1 -0
  6. data/ava_rails_generator.rb +201 -0
  7. data/templates/001_create_sessions.rb +16 -0
  8. data/templates/002_create_users.rb +20 -0
  9. data/templates/action_view_helper.rb +35 -0
  10. data/templates/action_view_ja.yml +115 -0
  11. data/templates/active_record_ja.yml +66 -0
  12. data/templates/active_support_ja.yml +36 -0
  13. data/templates/ann_back.png +0 -0
  14. data/templates/ann_back02.png +0 -0
  15. data/templates/application.html.erb +35 -0
  16. data/templates/application.js +128 -0
  17. data/templates/application_controller.rb +90 -0
  18. data/templates/application_csv.rb +66 -0
  19. data/templates/application_helper.rb +558 -0
  20. data/templates/application_search.rb +74 -0
  21. data/templates/arrow_h.gif +0 -0
  22. data/templates/arrow_l.png +0 -0
  23. data/templates/arrow_n.gif +0 -0
  24. data/templates/arrow_r.png +0 -0
  25. data/templates/arrow_v.gif +0 -0
  26. data/templates/auth_controller.rb +80 -0
  27. data/templates/bak.png +0 -0
  28. data/templates/btn_back.png +0 -0
  29. data/templates/btn_cancel_cre.png +0 -0
  30. data/templates/btn_cancel_upd.png +0 -0
  31. data/templates/btn_clear.png +0 -0
  32. data/templates/btn_close.png +0 -0
  33. data/templates/btn_complete.png +0 -0
  34. data/templates/btn_confirm_cre.png +0 -0
  35. data/templates/btn_confirm_upd.png +0 -0
  36. data/templates/btn_create.png +0 -0
  37. data/templates/btn_csv.png +0 -0
  38. data/templates/btn_delete.png +0 -0
  39. data/templates/btn_login.png +0 -0
  40. data/templates/btn_new.png +0 -0
  41. data/templates/btn_reenter.png +0 -0
  42. data/templates/btn_reload.png +0 -0
  43. data/templates/btn_reply.png +0 -0
  44. data/templates/btn_search.png +0 -0
  45. data/templates/btn_send.png +0 -0
  46. data/templates/btn_sub01.png +0 -0
  47. data/templates/btn_sub02.png +0 -0
  48. data/templates/btn_upd.png +0 -0
  49. data/templates/btn_upd_cancel.png +0 -0
  50. data/templates/btn_update.png +0 -0
  51. data/templates/btn_xml.png +0 -0
  52. data/templates/bubble_ex_g.png +0 -0
  53. data/templates/bubble_ex_p.png +0 -0
  54. data/templates/bubble_minus.gif +0 -0
  55. data/templates/bubble_plus.gif +0 -0
  56. data/templates/builder.js +136 -0
  57. data/templates/calendar.gif +0 -0
  58. data/templates/csv.rb +997 -0
  59. data/templates/default.css +92 -0
  60. data/templates/footer_a_bak.gif +0 -0
  61. data/templates/footer_m_bak.gif +0 -0
  62. data/templates/footer_w_bak.gif +0 -0
  63. data/templates/form.css +105 -0
  64. data/templates/g_navi_bak.gif +0 -0
  65. data/templates/import.css +13 -0
  66. data/templates/index.html.erb +8 -0
  67. data/templates/jquery-1.4.4.min.js +167 -0
  68. data/templates/jquery-ui-1.8.10.custom.css +573 -0
  69. data/templates/jquery-ui-1.8.10.custom.min.js +782 -0
  70. data/templates/jquery.ui.datepicker-ja.js +23 -0
  71. data/templates/layout.css +938 -0
  72. data/templates/link.gif +0 -0
  73. data/templates/link_t.gif +0 -0
  74. data/templates/login.html.erb +64 -0
  75. data/templates/login_back01.png +0 -0
  76. data/templates/logo.png +0 -0
  77. data/templates/mail.png +0 -0
  78. data/templates/menuTabL.gif +0 -0
  79. data/templates/menuTabR.gif +0 -0
  80. data/templates/navis.gif +0 -0
  81. data/templates/pageTitle_bak.png +0 -0
  82. data/templates/page_bak.gif +0 -0
  83. data/templates/password.html.erb +69 -0
  84. data/templates/pop.png +0 -0
  85. data/templates/prototype.js +6081 -0
  86. data/templates/rails.png +0 -0
  87. data/templates/scaffold.css +110 -0
  88. data/templates/scriptaculous.js +68 -0
  89. data/templates/slider.js +275 -0
  90. data/templates/sound.js +59 -0
  91. data/templates/tip.png +0 -0
  92. data/templates/tolist.png +0 -0
  93. data/templates/top_controller.rb +5 -0
  94. data/templates/translation_ja.yml +30 -0
  95. data/templates/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  96. data/templates/ui-bg_flat_55_fbec88_40x100.png +0 -0
  97. data/templates/ui-bg_glass_75_d0e5f5_1x400.png +0 -0
  98. data/templates/ui-bg_glass_85_dfeffc_1x400.png +0 -0
  99. data/templates/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  100. data/templates/ui-bg_gloss-wave_55_5c9ccc_500x100.png +0 -0
  101. data/templates/ui-bg_inset-hard_100_f5f8f9_1x100.png +0 -0
  102. data/templates/ui-bg_inset-hard_100_fcfdfd_1x100.png +0 -0
  103. data/templates/ui-icons_217bc0_256x240.png +0 -0
  104. data/templates/ui-icons_2e83ff_256x240.png +0 -0
  105. data/templates/ui-icons_469bdd_256x240.png +0 -0
  106. data/templates/ui-icons_6da8d5_256x240.png +0 -0
  107. data/templates/ui-icons_cd0a0a_256x240.png +0 -0
  108. data/templates/ui-icons_d8e7f3_256x240.png +0 -0
  109. data/templates/ui-icons_f9bd01_256x240.png +0 -0
  110. data/templates/unittest.js +568 -0
  111. data/templates/user.rb +71 -0
  112. data/templates/user_blue.css +62 -0
  113. data/templates/user_green.css +61 -0
  114. data/templates/user_red.css +61 -0
  115. metadata +254 -0
@@ -0,0 +1,66 @@
1
+ ja:
2
+ activerecord:
3
+ errors:
4
+ # The values :model, :attribute and :value are always available for interpolation
5
+ # The value :count is available when applicable. Can be used for pluralization.
6
+ messages:
7
+ inclusion: "は一覧にありません。"
8
+ exclusion: "は予約されています。"
9
+ invalid: "は不正な値です。"
10
+ confirmation: "が一致しません。"
11
+ accepted: "を受諾してください。"
12
+ empty: "を入力してください。"
13
+ blank: "を入力してください。"
14
+ too_long: "は{{count}}文字以内で入力してください。"
15
+ too_short: "は{{count}}文字以上で入力してください。"
16
+ wrong_length: "は{{count}}文字で入力してください。"
17
+ taken: "はすでに存在します。"
18
+ not_a_number: "は数値で入力してください。"
19
+ greater_than: "は{{count}}より大きい値にしてください。"
20
+ greater_than_or_equal_to: "は{{count}}以上の値にしてください。"
21
+ equal_to: "は{{count}}にしてください。"
22
+ less_than: "は{{count}}より小さい値にしてください。"
23
+ less_than_or_equal_to: "は{{count}}以下の値にしてください。"
24
+ odd: "は奇数にしてください。"
25
+ even: "は偶数にしてください。"
26
+ not_a_zenkaku: "は全角で入力してください。"
27
+ not_a_hankaku: "は半角で入力してください。"
28
+ not_a_email: "はメールアドレス書式(aaa@bbb.ne.jp)で入力してください。"
29
+ not_a_date: "は日付書式(YYYY/MM/DD)で入力してください。"
30
+ not_a_tel: "は電話番号書式(0000-00-0000)で入力してください。"
31
+ not_a_zip: "は数字7桁で入力してください。"
32
+ not_a_password: "は8桁以上、半角英数字の組み合わせで、英字と数字をそれぞれ1つ以上含めてください。"
33
+ file_too_large: "ファイルサイズが大きすぎます。"
34
+
35
+ record_invalid: "バリデーションに失敗しました。{{errors}}"
36
+ # Append your own errors here or at the model/attributes scope.
37
+
38
+ full_messages:
39
+ format: "{{attribute}} {{message}}"
40
+
41
+ # You can define own errors for models or model attributes.
42
+ # The values :model, :attribute and :value are always available for interpolation.
43
+ #
44
+ # For example,
45
+ # models:
46
+ # user:
47
+ # blank: "This is a custom blank message for {{model}}: {{attribute}}"
48
+ # attributes:
49
+ # login:
50
+ # blank: "This is a custom blank message for User login"
51
+ # Will define custom blank validation message for User model and
52
+ # custom blank validation message for login attribute of User model.
53
+ #models:
54
+
55
+ # Translate model names. Used in Model.human_name().
56
+ #models:
57
+ # For example,
58
+ # user: "Dude"
59
+ # will translate User model name to "Dude"
60
+
61
+ # Translate model attribute names. Used in Model.human_attribute_name(attribute).
62
+ #attributes:
63
+ # For example,
64
+ # user:
65
+ # login: "Handle"
66
+ # will translate User attribute "login" as "Handle"
@@ -0,0 +1,36 @@
1
+ ja:
2
+ date:
3
+ formats:
4
+ # Use the strftime parameters for formats.
5
+ # When no format has been given, it uses default.
6
+ # You can provide other formats here if you like!
7
+ default: "%Y/%m/%d"
8
+ short: "%m/%d"
9
+ long: "%Y年%m月%d日(%a)"
10
+
11
+ day_names: [日曜日, 月曜日, 火曜日, 水曜日, 木曜日, 金曜日, 土曜日]
12
+ abbr_day_names: [日, 月, 火, 水, 木, 金, 土]
13
+
14
+ # Don't forget the nil at the beginning; there's no such thing as a 0th month
15
+ month_names: [~, 1月, 2月, 3月, 4月, 5月, 6月, 7月, 8月, 9月, 10月, 11月, 12月]
16
+ abbr_month_names: [~, 1月, 2月, 3月, 4月, 5月, 6月, 7月, 8月, 9月, 10月, 11月, 12月]
17
+ # Used in date_select and datime_select.
18
+ order: [ :year, :month, :day ]
19
+
20
+ time:
21
+ formats:
22
+ default: "%Y/%m/%d %H:%M:%S"
23
+ short: "%y/%m/%d %H:%M"
24
+ long: "%Y年%m月%d日(%a) %H時%M分%S秒 %Z"
25
+ am: "午前"
26
+ pm: "午後"
27
+
28
+ # Used in array.to_sentence.
29
+ support:
30
+ array:
31
+ sentence_connector: "と"
32
+ skip_last_comma: true
33
+ words_connector: "と"
34
+ two_words_connector: "と"
35
+ last_word_connector: "と"
36
+
Binary file
Binary file
@@ -0,0 +1,35 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
7
+ <title><%%=h APP_TITLE %></title>
8
+ <%%= stylesheet_link_tag 'import' , :media => :all %>
9
+ <%%= stylesheet_link_tag 'user_<%= app_color %>', :media => :all unless @display_type == DISPLAY_TYPE_SIMPLE %>
10
+ <%%= stylesheet_link_tag 'scaffold' %>
11
+ <%%= stylesheet_link_tag 'jquery-ui-1.8.10.custom' %>
12
+ <%%= javascript_include_tag 'prototype' %>
13
+ <%%= javascript_include_tag 'jquery-1.4.4.min' %>
14
+ <%%= javascript_include_tag 'jquery-ui-1.8.10.custom.min' %>
15
+ <%%= javascript_include_tag 'jquery.ui.datepicker-ja' %>
16
+ <%%= javascript_include_tag 'scriptaculous' %>
17
+ <%%= javascript_include_tag 'application' %>
18
+ <%% unless @content_for_head.blank? -%>
19
+ <script type="text/javascript">
20
+ <!--
21
+ <%%= yield :head %>
22
+ //-->
23
+ </script>
24
+ <%% end %>
25
+ </head>
26
+ <body>
27
+ <div id="wrapper<%%= "Pop" if @display_type == DISPLAY_TYPE_SIMPLE %>">
28
+ <%%= header unless @display_type == DISPLAY_TYPE_SIMPLE %>
29
+
30
+ <%%= yield %>
31
+
32
+ <%%= footer unless @display_type == DISPLAY_TYPE_SIMPLE %>
33
+ <!--/ #wrapper--></div>
34
+ </body>
35
+ </html>
@@ -0,0 +1,128 @@
1
+ // Place your application-specific JavaScript functions and classes here
2
+ // This file is automatically included by javascript_include_tag :defaults
3
+
4
+ function submit(url, formname, method){
5
+ var form = document.forms[0];
6
+ if (formname != null) {
7
+ form = document.forms[formname];
8
+ }
9
+ if (method == null || method == '') {
10
+ method = 'POST'
11
+ }
12
+ form.action = url;
13
+ form.method = method;
14
+ form.submit();
15
+ }
16
+
17
+ function sort(col, order){
18
+ var formname = 'form_search';
19
+ var form = document.forms[formname];
20
+ document.getElementById('sort' ).value=col;
21
+ document.getElementById('order').value=order;
22
+ submit('', formname, 'GET');
23
+ }
24
+
25
+ function pop(url, h, winName){
26
+ if(h == undefined || h == null){
27
+ h = 300;
28
+ }
29
+ var win = window.open( url, winName, 'width=700, height=' + h + ', menubar=no, toolbar=no, scrollbars=yes, resizable=yes' );
30
+ win.focus();
31
+
32
+ }
33
+
34
+ function windowClose(){
35
+ window.close();
36
+ }
37
+
38
+ function pageTop(targetID){
39
+ if(targetID == undefined || targetID == null){
40
+ targetID = 'header';
41
+ }
42
+ new Effect.ScrollTo(targetID, {fps:60, duration: 0.5});
43
+ }
44
+
45
+ function insertComma(str) {
46
+ var num = new String( str ).replace( /,/g, "" );
47
+ while ( num != ( num = num.replace( /^(-?\d+)(\d{3})/, "$1,$2" ) ) );
48
+ return num;
49
+ }
50
+
51
+ function deleteComma(str){
52
+ var num = new String( str ).replace( /,/g, "" ); return num;
53
+ }
54
+
55
+ function checkNum(val){
56
+ flg = false;
57
+
58
+ if(!isNull(val)){
59
+ if(isNum(val)){
60
+ flg = true;
61
+ }
62
+ }
63
+ return flg;
64
+ }
65
+
66
+ function isNum(elm){
67
+ flg = true;
68
+ var reg = new RegExp(/[^0-9]/);
69
+ if(elm.match(reg)){
70
+ flg = false;
71
+ }
72
+ return flg;
73
+ }
74
+
75
+ function isNull(val){
76
+ if(val == null || val == ''){
77
+ return true;
78
+ }
79
+ return false;
80
+ }
81
+
82
+ /*** jQuery / prototype.js ***/
83
+
84
+ /* prototype.js/jQueryコンフリクト抑制 */
85
+ var $q = jQuery.noConflict(true);
86
+
87
+ function datePick() {
88
+ $q('input:text[class="ymd"]').datepicker({
89
+ showOn: 'both',
90
+ buttonImage: '/images/calendar.gif',
91
+ buttonImageOnly: true
92
+ });
93
+ }
94
+
95
+ function colorRow() {
96
+ $q('.commonList tbody tr:nth-child(even)').addClass('even');
97
+ }
98
+
99
+ $q(function() {
100
+ datePick();
101
+ colorRow();
102
+ });
103
+
104
+ function showMsg(box, btn){
105
+ var item = $(box);
106
+ Effect.toggle(item, 'appear', {duration: 0.17});
107
+
108
+ if ($(btn).hasClassName("msgMinus")) {
109
+ $(btn).removeClassName("msgMinus");
110
+ $(btn).addClassName("msgPlus");
111
+ return 1
112
+ }
113
+ else {
114
+ $(btn).removeClassName("msgPlus");
115
+ $(btn).addClassName("msgMinus");
116
+ return 0
117
+ }
118
+ }
119
+
120
+ function ref(url){
121
+ location.href = url;
122
+ }
123
+
124
+ function showCalClearBtn(obj) {
125
+ var calObj = $(obj).previous('input.ymd');
126
+ $(calObj).clear();
127
+ }
128
+
@@ -0,0 +1,90 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ require 'action_view_helper'
6
+ require 'application_csv'
7
+
8
+ before_filter :authorize
9
+
10
+ helper :all # include all helpers, all the time
11
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
12
+
13
+ # Scrub sensitive parameters from your log
14
+ # filter_parameter_logging :password
15
+
16
+ # rescue_from Exception, :with => :error
17
+
18
+ protected
19
+ def error(e)
20
+ logger.error(e.message);
21
+ flash[:error] = t(:error_default, :message => e)
22
+ begin
23
+ if action_name == :index.to_s
24
+ reset_session
25
+ redirect_to(login_url)
26
+ return
27
+ end
28
+ redirect_to(:action => :index)
29
+ rescue
30
+ redirect_to(top_url)
31
+ end
32
+ end
33
+
34
+ def authorize
35
+ begin
36
+ session_check
37
+ @user = User.find(session_get_user)
38
+ raise unless @user
39
+ @app_search = ApplicationSearch.new(params) if action_name == :index.to_s
40
+ rescue => e
41
+ logger.debug(e.message)
42
+ flash[:notice] = t(:error_authorize)
43
+ redirect_to(root_url)
44
+ end
45
+ end
46
+
47
+ def session_reset
48
+ session[:user_id] = nil
49
+ session[:ids] = nil
50
+ session[:prm] = nil
51
+ session[:msg_opn] = nil
52
+ reset_session
53
+ end
54
+
55
+ def session_check
56
+ raise unless session[:user_id]
57
+ end
58
+
59
+ def session_get_user
60
+ return session[:user_id]
61
+ end
62
+
63
+ def session_get_ids
64
+ return session[:ids]
65
+ end
66
+
67
+ def session_get_prm
68
+ return session[:prm]
69
+ end
70
+
71
+ def session_get_msg_opn
72
+ return session[:msg_opn]
73
+ end
74
+
75
+ def session_set_user(user)
76
+ session[:user_id] = user.id
77
+ end
78
+
79
+ def session_set_ids(objs)
80
+ # return unless params[:format].to_s == :html.to_s
81
+ ids = Array.new(objs.size)
82
+ session[:ids] = ids
83
+ session[:prm] = params
84
+ end
85
+
86
+ def session_set_msg_opn(msg_opn)
87
+ session[:msg_opn] = msg_opn
88
+ end
89
+
90
+ end
@@ -0,0 +1,66 @@
1
+ module ActiveSupport
2
+ module CoreExtensions
3
+ module Array
4
+ module Conversions
5
+
6
+ def to_csv(instance, options = {})
7
+ require 'csv'
8
+ require 'kconv'
9
+
10
+ o_keys = []
11
+ o_names = []
12
+ o_types = []
13
+ instance.columns.each{|column|
14
+ o_keys << column.name
15
+ name = I18n.t(column.name, :scope => [:activerecord, :attributes, instance.table_name.singularize]) #ApplicationController.helpers.hlabel(:order, column.name)
16
+ name = I18n.t(column.name, :scope => [:activerecord, :attributes, :commons]) if name.index("translation missing") && name.index("translation missing").to_i >= 0
17
+ name = column.name if name.index("translation missing") && name.index("translation missing").to_i >= 0
18
+ o_names << name
19
+ o_types << column.type
20
+ }
21
+
22
+ CSV::Writer.generate(output = ""){|csv|
23
+ each_with_index{|all, i|
24
+ if i == 0
25
+ names = o_names unless o_names.blank?
26
+ names = o_keys if names.blank? and !o_keys.blank?
27
+ names = all.attribute_names if names.blank?
28
+ # csv << names
29
+ a0 = []
30
+ names.each_with_index{|name, j|
31
+ begin
32
+ s = Kconv.tosjis(name)
33
+ rescue
34
+ end
35
+ a0 << '"' + s + '"'
36
+ }
37
+ csv << a0
38
+ end
39
+
40
+ keys = o_keys unless o_keys.blank?
41
+ keys = all.attribute_names if keys.blank?
42
+
43
+ a1 = []
44
+ keys.each_with_index{|key,j|
45
+ begin
46
+ s = all.read_attribute(key)
47
+ s = s.gsub(/\r\n|\r|\n/, " ")
48
+ s = Kconv.tosjis(s)
49
+ s = '"' + s + '"' unless o_types[j] == ":integer" || s.index(",") > 0
50
+ rescue
51
+ end
52
+ a1 << s
53
+ }
54
+ csv << a1
55
+ }
56
+ }
57
+ output
58
+ end
59
+
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+
66
+
@@ -0,0 +1,558 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ # 改行⇒<br>
4
+ def hbr(str)
5
+ return if str.blank?
6
+ str = html_escape(str)
7
+ str = hbr_without_escape(str)
8
+ end
9
+
10
+ # 改行⇒<br>
11
+ def hbr_without_escape(str)
12
+ return if str.blank?
13
+ str.gsub(/\r\n|\r|\n/, "<br />\n")
14
+ end
15
+
16
+ # 名称表示
17
+ def hname(obj)
18
+ unless obj.blank?
19
+ begin
20
+ obj.name_with_id
21
+ rescue
22
+ obj.name
23
+ end
24
+ end
25
+ end
26
+
27
+ # 日時表示
28
+ def hdate(obj, options = {})
29
+ format = :default
30
+ format = options[:format] unless options[:format].blank?
31
+ I18n.l obj, :format => format unless obj.blank?
32
+ end
33
+
34
+ # 金額表示
35
+ def hmoney(obj, options = {})
36
+ number_to_currency obj unless obj.blank?
37
+ end
38
+
39
+ # ラベル表示
40
+ def hlabel(obj, method)
41
+ I18n.t(method, :scope => [:activerecord, :attributes, obj])
42
+ end
43
+
44
+ # ラジオ表示
45
+ def hradio_openflag(obj, method, value, datas)
46
+ str = ""
47
+ datas.each {|o|
48
+ str += "<label>" + obj.radio_button(method, o.id, {:checked => (o.id == value)}) + o.name_with_id + "</label>&nbsp;&nbsp;"
49
+ }
50
+ str
51
+ end
52
+
53
+ # 年コンボ表示
54
+ def hselect_year(method)
55
+ thisyear = Date.today()
56
+ fromyear = thisyear << 60
57
+ toyear = thisyear >> 60
58
+
59
+ y = Hash.new()
60
+ (fromyear.year..toyear.year).each do |i|
61
+ y[i] = i;
62
+ end
63
+ year = y.sort
64
+
65
+ value = params[:selectyear]
66
+ str = select_tag(:selectyear, "<option value=''></option>" + options_from_collection_for_select(year, :first, :last , value.to_i), :onchange => "javascript:submit('#{method}', this.form, 'GET')")
67
+ str += "&nbsp;&nbsp;年&nbsp;&nbsp;"
68
+ str
69
+ end
70
+
71
+ # 月コンボ表示
72
+ def hselect_month(method)
73
+ m = Hash.new()
74
+ (1..12).each do |i|
75
+ m[i] = i
76
+ end
77
+ month = m.sort
78
+
79
+ value = params[:selectmonth]
80
+ p value
81
+ str = select_tag(:selectmonth, "<option value=''></option>" + options_from_collection_for_select(month, :first, :last , value.to_i), :onchange => "javascript:submit('#{method}', this.form, 'GET')")
82
+ str += "&nbsp;&nbsp;月&nbsp;&nbsp;"
83
+ str
84
+ end
85
+
86
+ # 時間コンボ表示
87
+ def hselect_hour(obj, method, value)
88
+ h = Hash.new()
89
+ (0..23).each do |i|
90
+ h[i] = i
91
+ end
92
+ hour = h.sort
93
+
94
+ str = obj.select method, hour, {:include_blank => true}
95
+ str += " 時"
96
+ str
97
+ end
98
+
99
+ # Ajax
100
+ def remote(controller, action, options = {})
101
+ position = options[:position] unless options[:position].blank?
102
+ with = options[:with] unless options[:with].blank?
103
+ with = "''" if with.blank?
104
+ js = <<"EOS"
105
+ var with_param = '';
106
+ if(obj != null){
107
+ with_param += 'id=' + obj.options[obj.selectedIndex].value;
108
+ }
109
+ with_param += #{with};
110
+ EOS
111
+ js + remote_function(:url => {:controller => controller, :action => action }, :with => "with_param", :update => (controller.to_s + "_" + action.to_s), :position => position)
112
+ end
113
+
114
+ # 必須
115
+ def required(options = {})
116
+ " <font color=\"red\">*</font> "
117
+ end
118
+
119
+ # 凡例
120
+ def note(text, options = {})
121
+ " [ #{text} ] "
122
+ end
123
+
124
+ # ヘッダ
125
+ def header(options = {})
126
+ login_account = @user.account
127
+ login_name = @user.name
128
+ company = APP_COMPANY
129
+ link_password = '<li>' + link_to("パスワード変更", "javascript:void(0);", :onclick => "javascript:pop('" + url_for(:controller => :auth, :action => :password) + "', '600', 'passwordsetting');") + '</li>'
130
+ link_logout = '<li>' + link_to('ログアウト', :controller => :auth, :action => :logout ) + '</li>'
131
+
132
+ str =<<"EOS"
133
+ <div id="header">
134
+ <a href="/">
135
+ <h1 title="#{APP_TITLE}">TMS</h1></a>
136
+ <div id="hBox">
137
+ <h2 id="hCompany">#{company}</h2>
138
+ <ul id="hNavi">
139
+ #{link_password}
140
+ #{link_logout}
141
+ </ul>
142
+ <ul id="hUser">
143
+ <li>#{login_account} : #{login_name} さん</li>
144
+ </ul>
145
+ <!--/ #hBox--></div>
146
+ <!--/ #header--></div>
147
+ EOS
148
+ return str
149
+ end
150
+
151
+ # フッタ
152
+ def footer(options = {})
153
+ link_pagetop = link_to 'このページのトップへ', "javascript:pageTop()"
154
+
155
+ str =<<"EOS"
156
+ <div id ="footer">
157
+ <div class="pageTop">#{ link_pagetop }</div>
158
+ <!--/ #footer--></div>
159
+ EOS
160
+ return str
161
+ end
162
+
163
+ # ページタイトル
164
+ def pagetitle(options = {})
165
+ title = options[:title] #TODO
166
+
167
+ str =<<"EOS"
168
+ <div class="pageTitle">
169
+ <h2>#{title}</h2>
170
+ </div>
171
+ EOS
172
+ return str
173
+ end
174
+
175
+ # ページサブタイトル
176
+ def pagesubtitle(options = {})
177
+ title = options[:title] #TODO
178
+
179
+ return "<h3>#{title}</h3>"
180
+ end
181
+
182
+ # メッセージ
183
+ def message(options = {})
184
+
185
+ js = remote_function(:url => {:controller => :auth, :action => :open_close }, :with => "'flag=' + flag" , :update => "msgBtn")
186
+ jsstr =<<"EOS"
187
+ function openclose(){
188
+ var flag = showMsg('msgBox','msgBtn');
189
+ #{js}
190
+ }
191
+ EOS
192
+
193
+ content_for :head do
194
+ jsstr
195
+ end
196
+
197
+ msg = "" if msg.blank?
198
+
199
+ (dsp = "block"; cls = "msgMinus")
200
+ (dsp = "none"; cls = "msgPlus") if session[:msg_opn] == "1"
201
+
202
+ str =<<"EOS"
203
+ <div id="msgBox" style="display:#{dsp};">
204
+ <div id="messageArea">
205
+ <div id="messageLeft">
206
+ <div style="width: 100%;">
207
+ <div class="corner">
208
+ <div class="corner1"></div>
209
+ <div class="corner2"></div>
210
+ <div class="corner3"></div>
211
+ <div class="corner4"></div>
212
+ </div>
213
+ <div class="corner5_2">
214
+ <p>
215
+ #{msg}
216
+ </p>
217
+ </div>
218
+ <div class="corner">
219
+ <div class="corner4"></div>
220
+ <div class="corner3"></div>
221
+ <div class="corner2"></div>
222
+ <div class="corner1"></div>
223
+ </div>
224
+ </div>
225
+ </div>
226
+ EOS
227
+
228
+ msglist = "" #TODO
229
+ unless msglist.blank?
230
+ str +=<<"EOS"
231
+ <div id="messageRight">
232
+ <div style="width: 100%;">
233
+ <div class="corner">
234
+ <div class="corner1"></div>
235
+ <div class="corner2"></div>
236
+ <div class="corner3"></div>
237
+ <div class="corner4"></div>
238
+ </div>
239
+ <div class="corner5">
240
+ <ol>
241
+ #{msglist}
242
+ </ol>
243
+ </div>
244
+ <div class="corner">
245
+ <div class="corner4"></div>
246
+ <div class="corner3"></div>
247
+ <div class="corner2"></div>
248
+ <div class="corner1"></div>
249
+ </div>
250
+ </div>
251
+ </div>
252
+ EOS
253
+ end
254
+
255
+ str +=<<"EOS"
256
+ <div id="messageBottom"></div>
257
+ <!--/ #messageArea--></div>
258
+ </div>
259
+ <div style="float: right;">
260
+ <a href="#" onClick="openclose('msgBox','msgBtn');blur();"><div id="msgBtn" class="#{cls}"></div></a>
261
+ </div>
262
+ EOS
263
+
264
+ # str = "" if msglist.blank?
265
+ return str
266
+ end
267
+
268
+ # メニュー
269
+ def menu(options = {})
270
+
271
+ str = "<ul id =\"navi\">\n"
272
+ str = str + "<li>#{link_to(:top, :controller => :top)}</li>\n"
273
+ # str = str + "<li>#{link_to(:top, :controller => :tops)}</li>\n"
274
+ str = str + "</ul>\n"
275
+
276
+ return str
277
+ end
278
+
279
+ # サブメニュー
280
+ def submenu
281
+ str =<<"EOS"
282
+ <div id="sub">
283
+ </div>
284
+ EOS
285
+ return str
286
+ end
287
+
288
+ # タブ
289
+ def tab_tag(objs, selected, form, element)
290
+
291
+ current_path = url_for(:controller => controller_name, :action => action_name)
292
+ jsstr =<<"EOS"
293
+ function change_tab(val){
294
+ document.getElementById('#{element}').value=val;
295
+ submit('#{current_path}', '#{form}', 'GET');
296
+ }
297
+ EOS
298
+
299
+ content_for :head do
300
+ jsstr
301
+ end
302
+
303
+ str = "<div id=\"tab\"><ul>"
304
+
305
+ objs.each{|obj|
306
+ selected = "" if selected.blank?
307
+ current = ""
308
+ current = "current" if obj.id.to_s == selected
309
+ path = link_to("<span>" + obj.name.to_s + "</span>", "javascript:change_tab('" + obj.id.to_s + "');")
310
+ str += "<li class=\"" + current + "\">" + path + "</li>"
311
+ }
312
+
313
+ str += "</ul></div>"
314
+
315
+ return str
316
+ end
317
+
318
+ # 必須入力メッセージ文言
319
+ def required_notice_tag(options = {})
320
+ " <p>#{required}印のついた項目は、必ず入力してください。</p> "
321
+ end
322
+
323
+ # フラッシュ
324
+ def flash_tag
325
+ e = "<div id=\"errorExplanation\" class=\"errorExplanation\"><h2>#{hbr(flash[:error])}</h2></div>" unless flash[:error].blank?
326
+ n = "<div id=\"actionMessage\" class=\"actionMessage\">#{hbr(flash[:notice])}</div>" unless flash[:notice].blank?
327
+ flash.clear
328
+ e.to_s + n.to_s
329
+ end
330
+
331
+ # 検索
332
+ def search_tag(options = {})
333
+ text_keyword = text_field_tag(:keyword, params[:keyword])
334
+ hidden_sort = hidden_field_tag(:sort, params[:sort])
335
+ hidden_order = hidden_field_tag(:order, params[:order])
336
+ other_tag = options[:other] unless options[:other].blank?
337
+ tab_tag = options[:tab] unless options[:tab].blank?
338
+
339
+ controller = controller_name
340
+ controller = options[:controller] unless options[:controller].blank?
341
+ action = :index
342
+ action = options[:action] unless options[:action].blank?
343
+
344
+ search_form = 'form_search'
345
+ search_path = url_for(:controller => controller, :action => action)
346
+ search_button = link_to image_tag('/images/btn_search.png', :alt => '検索', :style => 'vertical-align: middle;'), "javascript:submit('#{search_path}', '#{search_form}', 'GET')"
347
+
348
+ str =<<"EOS"
349
+ <form name=\"#{search_form}\">
350
+ <div style=\"clear: both;\">
351
+ #{tab_tag}
352
+ </div>
353
+ <div style=\"clear: both;\">
354
+ #{text_keyword}
355
+ #{hidden_sort}
356
+ #{hidden_order}
357
+ #{search_button}
358
+ #{refrech_button_tag}
359
+ #{other_tag}
360
+ </div>
361
+ </form>
362
+ EOS
363
+ return str
364
+ end
365
+
366
+ # ソート
367
+ def sort_tag(key)
368
+ asc = ! (!@app_search.blank? && @app_search.tag_sort == key && @app_search.tag_order == 'asc' )
369
+ desc = ! (!@app_search.blank? && @app_search.tag_sort == key && @app_search.tag_order == 'desc')
370
+ sort_asc = link_to_if asc, '▲', "javascript:sort('#{key}','asc' );"
371
+ sort_desc = link_to_if desc, '▼', "javascript:sort('#{key}','desc');"
372
+ sort_asc + ' ' + sort_desc
373
+ end
374
+
375
+ # 総件数
376
+ def counter_tag(options = {})
377
+ size = options[:size] unless options[:size].blank?
378
+ size = session[:ids].size if options[:size].blank?
379
+
380
+ str = <<"EOS"
381
+ <div style="float: right;" class="pagination">#{size}件</div>
382
+ EOS
383
+ end
384
+
385
+ # 前へ次へボタン
386
+ def prevnext_tag
387
+ ids = session[:ids]
388
+ now = params[:id]
389
+ prv = nxt = nil
390
+ ids.each_with_index{|id,i|
391
+ prv = nxt = nil
392
+ prv = ids[i-1] if (i > 0 && ids[i-1])
393
+ nxt = ids[i+1] if (i < ids.size && ids[i+1])
394
+ break if now.to_s == id.to_s
395
+ }
396
+
397
+ params = session[:prm]
398
+ params.delete(:controller)
399
+ params.delete(:action)
400
+ params.delete(:format)
401
+
402
+ button_prev = link_to image_tag('/images/arrow_l.png', :alt => '前へ'), {:controller => controller_name, :action => action_name, :id => prv} unless prv.blank?
403
+ button_next = link_to image_tag('/images/arrow_r.png', :alt => '次へ'), {:controller => controller_name, :action => action_name, :id => nxt} unless nxt.blank?
404
+ button_index = link_to image_tag('/images/tolist.png', :alt => '一覧へ'), {:controller => controller_name, :action => :index, :params => params}
405
+
406
+ str =<<"EOS"
407
+ <div class="leftBox">
408
+ <ul class="prevnxt">
409
+ <li class="prevnxt">#{button_prev}</li>
410
+ <li class="prevnxt">#{button_index}</li>
411
+ <li class="prevnxt">#{button_next}</li>
412
+ </ul>
413
+ </div>
414
+ EOS
415
+ end
416
+
417
+ # 新規作成ボタン
418
+ def new_button_tag
419
+ link_to image_tag('/images/btn_new.png', :alt => '新規作成', :style => 'vertical-align: middle;'), {:controller => controller_name, :action => :new}
420
+ end
421
+
422
+ # 最新に更新ボタン
423
+ def refrech_button_tag
424
+ link_to image_tag('/images/btn_reload.png', :alt => '最新に更新', :style => 'vertical-align: middle;'), {:controller => controller_name, :action => :index}
425
+ end
426
+
427
+ # 修正ボタン
428
+ def edit_button_tag
429
+ link_to image_tag('/images/btn_upd.png', :alt => '修正' ), {:controller => controller_name, :action => :edit, :id => params[:id]}
430
+ end
431
+
432
+ # 削除ボタン
433
+ def delete_button_tag(obj, options = {})
434
+ conf = ''
435
+ conf = options[:conf] unless options[:conf].blank?
436
+ conf = '削除してもよろしいですか?' if conf.blank?
437
+
438
+ link_to image_tag('/images/btn_delete.png', :alt => '削除', :style => 'float: right;'), obj, {:controller => controller_name, :confirm => conf, :method => :delete}
439
+ end
440
+
441
+ # 一覧ボタン
442
+ def index_button_tag(options = {})
443
+ if action_name == :show.to_s
444
+ params = session[:prm]
445
+ params.delete(:controller)
446
+ params.delete(:action)
447
+ params.delete(:format)
448
+ end
449
+
450
+ value = '/images/btn_back.png' if action_name == :show.to_s
451
+ value = '/images/btn_back.png' if action_name == :destroy.to_s
452
+ value = '/images/btn_cancel_cre.png' if action_name == :new.to_s
453
+ value = '/images/btn_cancel_cre.png' if action_name == :create.to_s
454
+ value = '/images/btn_cancel_cre.png' if action_name == :check.to_s
455
+ value = '/images/btn_cancel_cre.png' if action_name == :copy.to_s
456
+ value = '/images/btn_cancel_upd.png' if action_name == :edit.to_s
457
+ value = '/images/btn_cancel_upd.png' if action_name == :update.to_s
458
+ value = '/images/btn_cancel_upd.png' if action_name == :confirm.to_s
459
+ value = options[:value] unless options[:value].blank?
460
+ value = '/images/btn_back.png' if value.blank?
461
+
462
+ action = :index
463
+ action = options[:action] unless options[:action].blank?
464
+
465
+ alt = '一覧へ'
466
+ alt = options[:alt] unless options[:alt].blank?
467
+
468
+ link_to image_tag(value, :alt => alt), {:controller => controller_name, :action => action, :params => params}, {:confirm => options[:confirm]}
469
+ end
470
+
471
+ # 送信ボタン
472
+ def submit_button_tag(f, options = {})
473
+ value = '/images/btn_create.png' if action_name == :check.to_s
474
+ value = '/images/btn_update.png' if action_name == :confirm.to_s
475
+ value = "/images/btn_confirm_cre.png" if action_name == :new.to_s
476
+ value = '/images/btn_confirm_cre.png' if action_name == :create.to_s
477
+ value = '/images/btn_confirm_cre.png' if action_name == :check.to_s && f.error_messages.size > 0
478
+ value = '/images/btn_confirm_cre.png' if action_name == :copy.to_s
479
+ value = '/images/btn_confirm_upd.png' if action_name == :edit.to_s
480
+ value = '/images/btn_confirm_upd.png' if action_name == :update.to_s
481
+ value = '/images/btn_confirm_upd.png' if action_name == :confirm.to_s && f.error_messages.size > 0
482
+ value = options[:value] unless options[:value].blank?
483
+ value = '/images/btn_update.png' if value.blank?
484
+
485
+ image_submit_tag value, :confirm => options[:confirm], :onclick => options[:onclick]
486
+ end
487
+
488
+ # ポップ
489
+ def pop_button_tag(path, size, elm, type, options = {})
490
+ link_to("検索", "javascript:popSearch('" + path + "','" + size.to_s + "','" + elm + "','','" + type + "');")
491
+ end
492
+
493
+ # 検索ポップアップ
494
+ def pop_search_tag(elm, type)
495
+ pop_button_tag('/search', 750, elm, type)
496
+ end
497
+
498
+ # 戻るボタン
499
+ def back_button_tag(options = {})
500
+ value = '/images/btn_reenter.png'
501
+ value = options[:value] unless options[:value].blank?
502
+
503
+ action = :new if action_name == :check.to_s
504
+ action = :edit if action_name == :confirm.to_s
505
+ path = url_for(:controller => controller_name, :action => action, :id => params[:id])
506
+
507
+ link_to image_tag(value), "javascript:submit('#{path}')", {:confirm => options[:confirm]}
508
+ end
509
+
510
+ # トップへ戻るボタン
511
+ def top_button_tag(options = {})
512
+ value = '/images/btn_back.png'
513
+ alt = '戻る'
514
+ alt = options[:alt] unless options[:alt].blank?
515
+ link_to image_tag(value, :alt => alt), {:controller => :top, :action => :index}
516
+ end
517
+
518
+ # CSV出力ボタン
519
+ def csv_button_tag(options = {})
520
+ out = false
521
+ return unless options[:out].blank?
522
+ style = 'vertical-align: middle;'
523
+ style = '' if action_name == :show.to_s
524
+ url = url_for(params.merge(params))
525
+ url = url_for(params.merge(:format => :csv))
526
+ link_to image_tag('/images/btn_csv.png', :alt => 'CSV出力', :style => style), url, {:confirm => 'CSVを出力しますか?', :target => '_blank'}
527
+ end
528
+
529
+ # コピーボタン
530
+ def copy_button_tag(options = {})
531
+ value = '/images/btn_copy.png'
532
+ value = options[:value] unless options[:value].blank?
533
+ alt = '流用作成'
534
+ alt = options[:alt] unless options[:alt].blank?
535
+ controller = controller_name
536
+ controller = options[:controller] unless options[:controller].blank?
537
+ action = :copy
538
+ action = options[:action] unless options[:action].blank?
539
+ path = url_for(:controller => controller, :action => action)
540
+ link_to image_tag(value, :alt => alt), "javascript:submit('#{path}')"
541
+ end
542
+
543
+ # クリアボタン
544
+ def clear_button_tag(options = {})
545
+ # link_to image_tag('/images/btn_clear.png', :alt => 'クリア'), {:confirm => options[:confirm]}
546
+ end
547
+
548
+ # 閉じるボタン
549
+ def close_button_tag(options = {})
550
+ link_to image_tag('/images/btn_close.png', :alt => '閉じる'), "javascript:windowClose()"
551
+ end
552
+
553
+ # カレンダー選択値クリアボタン
554
+ def clear_cal_button_tag(options = {})
555
+ button_to_function("クリア", "showCalClearBtn(this)", :class => "clearCalBtn")
556
+ end
557
+
558
+ end