001/*
002 * Copyright (c) 2009 The openGion Project.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied. See the License for the specific language
014 * governing permissions and limitations under the License.
015 */
016package org.opengion.plugin.column;
017
018import org.opengion.hayabusa.common.HybsSystem;
019import org.opengion.hayabusa.db.AbstractEditor;
020import org.opengion.hayabusa.db.CellEditor;
021import org.opengion.hayabusa.db.DBColumn;
022import org.opengion.fukurou.util.XHTMLTag;
023import org.opengion.fukurou.util.TagBuffer;
024
025import static org.opengion.fukurou.util.StringUtil.isNull;                              // 6.1.1.0 (2015/01/17)
026
027/**
028 * YMD エディターは、カラムのデータを日付(年/月/日)編集する場合に使用するクラスです。
029 * YMD2はカレンダーのポップアップボタンが付属するタイプです。
030 *
031 * このエディタはeventColumnに対応していません。
032 *
033 *  カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。
034 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。
035 *
036 * @og.rev 3.5.6.2 (2004/07/05) 新規作成
037 * @og.rev 5.4.3.6 (2012/01/19) コメント修正
038 * @og.rev 5.6.5.2 (2013/06/21) ポップアップ変更
039 * @og.rev 5.9.4.0 (2016/01/08) type=button追加,背景色transparent
040 * @og.rev 5.9.4.3 (2016/01/15) buttonのpadding:0
041 *
042 * @og.group データ編集
043 *
044 * @version  4.0
045 * @author   Kazuhiko Hasegawa
046 * @since    JDK5.0,
047 */
048public class Editor_YMD2 extends AbstractEditor {
049        /** このプログラムのVERSION文字列を設定します。   {@value} */
050        private static final String VERSION = "6.9.8.0 (2018/05/28)" ;
051
052        // 5.6.5.2 (2013/06/21) htmlからjspに変更
053        // 6.0.2.5 (2014/10/31) height,width に、"px"を追加
054        // 5.9.4.0 (2016/01/09) type=button追加
055        // 6.5.0.1 (2016/10/21) サイズ変更 '250px','265px' → '265px','260px'
056        // 4.3.6.7 (2009/05/22) FireFox対応
057        // 5.9.4.0 背景色transparent 5.9.4.3 padding
058        // 6.4.2.0 (2016/01/29) alt属性にtitle属性を追記。
059
060        private static final String CAL1 = "<button type=\"button\" onclick=\"ogPopup('../common/calendar.jsp','265px','260px',null,this,new Array('" ;
061        // 6.8.5.0 (2018/01/09)
062        private static final String CAL3 = "<button type=\"button\" onclick=\"ogPopup('../common/calendar_3month.jsp','320px','770px',null,this,new Array('" ;
063
064        // 6.8.5.0 (2018/01/09) とりあえず、CAL1 と CAL3 しかないので、決め打ち
065        // 6.9.8.0 (2018/05/28) キーワード変更(CAL_ST → CAL_STR)
066        private static final String CAL_STR = "CAL1".equals( HybsSystem.sys( "CALENDAR_POPUP_TYPE" ) ) ? CAL1 : CAL3 ;
067
068//      // 6.8.5.0 (2018/01/09) キーワード変更(CAL2 → CAL_END)
069//      private static final String CAL_END = "'),event); return false;\" style=\"background-color:transparent;border:0px;padding:0;\">"
070//                                                                                              + "<img src=\"../image/calendar.gif\" alt=\"Calendar\" title=\"Calendar\"/></button>";
071        // 5.9.32.3command,p_appendの対応
072        // 7.0.1.0 (2018/10/15) XHTML → HTML5 対応(空要素の、"/>" 止めを、">" に変更します)。
073        private static final String CAL_END = "'),'NEW',false,event); return false;\" style=\"background-color:transparent;border:0px;padding:0;\">"
074//                                                                                              + "<img src=\"../image/calendar.gif\" alt=\"Calendar\"/></button>";
075                                                                                                + "<img src=\"../image/calendar.gif\" alt=\"Calendar\"></button>";
076
077        // 6.9.8.0 (2018/05/28) disabled 時に、日付ピッカーを出さない対応
078        private final boolean disabled ;
079
080        /**
081         * デフォルトコンストラクター。
082         * このコンストラクターで、基本オブジェクトを作成します。
083         *
084         * @og.rev 6.9.8.0 (2018/05/28) disabled 時に、日付ピッカーを出さない対応
085         */
086//      public Editor_YMD2() { super(); }               // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
087        public Editor_YMD2() {
088                super();
089                disabled = false;
090        }
091
092        /**
093         * DBColumnオブジェクトを指定したprivateコンストラクター。
094         *
095         * @og.rev 6.9.8.0 (2018/05/28) disabled 時に、日付ピッカーを出さない対応
096         *
097         * @param       clm     DBColumnオブジェクト
098         */
099        private Editor_YMD2( final DBColumn clm ) {
100                super( clm );
101                tagBuffer.add( XHTMLTag.inputAttri( attributes ) );
102
103                disabled = "disabled".equalsIgnoreCase( attributes.get( "disabled" ) );         // 6.9.8.0 (2018/05/28)
104        }
105
106        /**
107         * 各オブジェクトから自分のインスタンスを返します。
108         * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に
109         * まかされます。
110         *
111         * @param       clm     DBColumnオブジェクト
112         *
113         * @return      CellEditorオブジェクト
114         * @og.rtnNotNull
115         */
116        public CellEditor newInstance( final DBColumn clm ) {
117                return new Editor_YMD2( clm );
118        }
119
120        /**
121         * データの編集用文字列を返します。
122         *
123         * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない
124         * @og.rev 6.8.5.0 (2018/01/09) カレンダポップアップで、3ヶ月ピッカー対応
125         * @og.rev 6.9.8.0 (2018/05/28) disabled 時に、日付ピッカーを出さない対応
126         *
127         * @param       value 入力値
128         *
129         * @return      データの編集用文字列
130         * @og.rtnNotNull
131         */
132        @Override
133        public String getValue( final String value ) {
134                // 6.1.1.0 (2015/01/17) TagBufferの連結記述
135                final String tag = new TagBuffer( "input" )
136                                                .add( "name"    , name )
137                                                .add( "id"              , name , isNull( attributes.get( "id" ) ) )             // 4.3.7.2 (2009/06/15)
138                                                .add( "value"   , value )
139                                                .add( "size"    , size1 )
140                                                .add( tagBuffer.makeTag() )
141                                                .makeTag();
142
143//              return tag + CAL_ST + name + CAL_END ;
144                return disabled ? tag                                                                   // 6.9.8.0 (2018/05/28) disabled 時に、日付ピッカーを出さない対応
145                                                : tag + CAL_STR + name + CAL_END ;              // 6.9.8.0 (2018/05/28) 変数名を、CAL_ST → CAL_STR に変更。
146        }
147
148        /**
149         * name属性を変えた、データ表示/編集用のHTML文字列を作成します。
150         * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し,
151         * リクエスト情報を1つ毎のフィールドで処理できます。
152         *
153         * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない
154         * @og.rev 6.8.5.0 (2018/01/09) カレンダポップアップで、3ヶ月ピッカー対応
155         * @og.rev 6.9.8.0 (2018/05/28) disabled 時に、日付ピッカーを出さない対応
156         *
157         * @param       row   行番号
158         * @param       value 入力値
159         *
160         * @return      データ表示/編集用の文字列
161         * @og.rtnNotNull
162         */
163        @Override
164        public String getValue( final int row,final String value ) {
165                final String name2 =  name + HybsSystem.JOINT_STRING + row ;
166
167                // 6.1.1.0 (2015/01/17) TagBufferの連結記述
168                final String tag = new TagBuffer( "input" )
169                                                .add( "name"    , name2 )
170                                                .add( "id"              , name2 , isNull( attributes.get( "id" ) ) )            // 4.3.7.2 (2009/06/15)
171                                                .add( "value"   , value )
172                                                .add( "size"    , size2 )
173                                                .add( tagBuffer.makeTag() )
174                                                .makeTag( row,value );
175
176//              return tag + CAL_ST + name2 + CAL_END ;
177                return disabled ? tag                                                                   // 6.9.8.0 (2018/05/28) disabled 時に、日付ピッカーを出さない対応
178                                                : tag + CAL_STR + name2 + CAL_END ;             // 6.9.8.0 (2018/05/28) 変数名を、CAL_ST → CAL_STR に変更。
179        }
180}