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.8.5.0 (2018/01/09)" ;
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        // 6.8.5.0 (2018/01/09) とりあえず、CAL1 と CAL3 しかないので、決め打ち
064        private static final String CAL_ST = "CAL1".equals( HybsSystem.sys( "CALENDAR_POPUP_TYPE" ) ) ? CAL1 : CAL3 ;
065
066        // 6.8.5.0 (2018/01/09) キーワード変更(CAL2 → CAL_END)
067        private static final String CAL_END = "'),event); return false;\" style=\"background-color:transparent;border:0px;padding:0;\">"
068                                                                                                + "<img src=\"../image/calendar.gif\" alt=\"Calendar\" title=\"Calendar\"/></button>";
069
070        /**
071         * デフォルトコンストラクター。
072         * このコンストラクターで、基本オブジェクトを作成します。
073         *
074         */
075        public Editor_YMD2() { super(); }               // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
076
077        /**
078         * コンストラクター。
079         *
080         * @param       clm     DBColumnオブジェクト
081         */
082        private Editor_YMD2( final DBColumn clm ) {
083                super( clm );
084                tagBuffer.add( XHTMLTag.inputAttri( attributes ) );
085        }
086
087        /**
088         * 各オブジェクトから自分のインスタンスを返します。
089         * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に
090         * まかされます。
091         *
092         * @param       clm     DBColumnオブジェクト
093         *
094         * @return      CellEditorオブジェクト
095         * @og.rtnNotNull
096         */
097        public CellEditor newInstance( final DBColumn clm ) {
098                return new Editor_YMD2( clm );
099        }
100
101        /**
102         * データの編集用文字列を返します。
103         *
104         * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない
105         * @og.rev 6.8.5.0 (2018/01/09) カレンダポップアップで、3ヶ月ピッカー対応
106         *
107         * @param       value 入力値
108         *
109         * @return      データの編集用文字列
110         * @og.rtnNotNull
111         */
112        @Override
113        public String getValue( final String value ) {
114                // 6.1.1.0 (2015/01/17) TagBufferの連結記述
115                final String tag = new TagBuffer( "input" )
116                                                .add( "name"    , name )
117                                                .add( "id"              , name , isNull( attributes.get( "id" ) ) )             // 4.3.7.2 (2009/06/15)
118                                                .add( "value"   , value )
119                                                .add( "size"    , size1 )
120                                                .add( tagBuffer.makeTag() )
121                                                .makeTag();
122
123                return tag + CAL_ST + name + CAL_END ;
124        }
125
126        /**
127         * name属性を変えた、データ表示/編集用のHTML文字列を作成します。
128         * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し,
129         * リクエスト情報を1つ毎のフィールドで処理できます。
130         *
131         * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない
132         * @og.rev 6.8.5.0 (2018/01/09) カレンダポップアップで、3ヶ月ピッカー対応
133         *
134         * @param       row   行番号
135         * @param       value 入力値
136         *
137         * @return      データ表示/編集用の文字列
138         * @og.rtnNotNull
139         */
140        @Override
141        public String getValue( final int row,final String value ) {
142                final String name2 =  name + HybsSystem.JOINT_STRING + row ;
143
144                // 6.1.1.0 (2015/01/17) TagBufferの連結記述
145                final String tag = new TagBuffer( "input" )
146                                                .add( "name"    , name2 )
147                                                .add( "id"              , name2 , isNull( attributes.get( "id" ) ) )            // 4.3.7.2 (2009/06/15)
148                                                .add( "value"   , value )
149                                                .add( "size"    , size2 )
150                                                .add( tagBuffer.makeTag() )
151                                                .makeTag( row,value );
152
153                return tag + CAL_ST + name2 + CAL_END ;
154        }
155}