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 018// import org.opengion.fukurou.util.Attributes; 019// import org.opengion.fukurou.util.StringUtil; 020// import org.opengion.fukurou.util.TagBuffer; 021// import org.opengion.fukurou.util.XHTMLTag; 022import org.opengion.hayabusa.common.HybsSystem; 023// import org.opengion.hayabusa.db.AbstractEditor; 024import org.opengion.hayabusa.db.CellEditor; 025import org.opengion.hayabusa.db.DBColumn; 026 027import static org.opengion.fukurou.util.StringUtil.nval; 028 029/** 030 * TEXTRICH エディターは、カラムのデータをリッチテキストで編集する場合に 031 * 使用するクラスです。 032 * サイズ指定はsize1,size2で高さ,幅がpxで設定されます。 033 * 初期値は250,600です。 034 * 035 * optionAttibutes属性にcleditorの設定が可能です。 036 * 詳細は下記ページを参照してください。 037 * http://www.premiumsoftware.net/cleditor/gettingstarted 038 * 039 * @og.rev 5.9.32.0 (2018/05/02) 新規作成 040 * @og.rev 5.10.1.0 (2018/06/29) クリアボタンとエラー画面からの戻る場合の対応 041 * @og.group データ編集 042 * 043 * @version 5 044 * @author T.OTA 045 * @since JDK5.0, 046 */ 047public class Editor_RICHTEXT extends Editor_TEXTAREA { 048 /** このプログラムのVERSION文字列を設定します。 {@value} */ 049 private static final String VERSION = "8.4.3.0 (2023/04/07)" ; 050 051 /** 052 * デフォルトコンストラクター。 053 * このコンストラクターで、基本オブジェクトを作成します。 054 */ 055 public Editor_RICHTEXT() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 056 057// // デフォルトの値設定 058// private void defaultSet() { 059// size1 = "250"; 060// size2 = "600"; 061// } 062 063 /** 064 * DBColumnオブジェクトを指定したprivateコンストラクター。 065 * 066 * @og.rev 5.10.1.0 (2018/06/29) クリアボタンとエラー画面からの戻る場合の対応 067 * 068 * @param clm DBColumnオブジェクト 069 */ 070 private Editor_RICHTEXT( final DBColumn clm ) { 071 super( clm ); 072 073 // size に、"height,width" を指定できるように変更 074 // 2018/06/29 MODIFY size(ViewLength)のみ取得するように変更 075 // String param = StringUtil.nval( clm.getEditorParam(),clm.getViewLength() ); 076 final String param = clm.getViewLength(); 077 if( param != null && param.length() != 0 ) { 078 final int st = param.indexOf( ',' ); 079 if( st > 0 ) { 080 cols1 = param.substring( 0, st ); 081 cols2 = param.substring( st + 1); 082 } 083 } 084 085 // ※ 超絶特殊。未設定時は、super で、size1,2 に設定されているので、その値で判定します。 086// if( cols1 == size1 ) { cols1 = "250"; } 087// if( cols2 == size2 ) { cols2 = "600"; } 088 if( cols1 == null || cols1.equals( size1 ) ) { cols1 = "250"; } // 6.9.8.0 (2018/05/28) FindBugs: String オブジェクトを == や != を使用して比較している 089 if( cols2 == null || cols2.equals( size2 ) ) { cols2 = "600"; } // 6.9.8.0 (2018/05/28) FindBugs: String オブジェクトを == や != を使用して比較している 090 091// String disabled = clm.isWritable() ? null : "disabled" ; 092// 093// // size に、"height,width" を指定できるように変更 094// String param = StringUtil.nval( clm.getEditorParam(),clm.getViewLength() ); 095// if( param != null && param.length() != 0 ) { 096// int st = param.indexOf( ',' ); 097// if( st > 0 ) { 098// size1 = param.substring( 0, st ); 099// size2 = param.substring( st + 1); 100// }else { 101// defaultSet(); 102// } 103// }else { 104// defaultSet(); 105// } 106// 107// attributes = new Attributes(); 108// attributes.addAttributes( clm.getEditorAttributes() ); 109// tagBuffer.add( XHTMLTag.textareaAttri( attributes ) ); 110 } 111 112 /** 113 * 各オブジェクトから自分のインスタンスを返します。 114 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 115 * まかされます。 116 * 117 * @param clm DBColumnオブジェクト 118 * 119 * @return CellEditorオブジェクト 120 */ 121 @Override 122 public CellEditor newInstance( final DBColumn clm ) { 123 return new Editor_RICHTEXT( clm ); 124 } 125 126 /** 127 * データの編集用文字列を返します。 128 * 129 * @param value 入力値 130 * 131 * @return データの編集用文字列 132 */ 133 @Override 134 public String getValue( final String value ) { 135 final String id = nval( attributes.get( "id" ) , name ); 136 137 return super.getValue( value ) + createCLEditorSc( id ); 138 139// String id = ""; 140// 141// TagBuffer tag = new TagBuffer( "textarea" ); 142// tag.add( "name" , name ); 143// 144// id = attributes.get( "id" ); 145// optAttr = attributes.get( "optionAttributes" ); 146// if( id == null || id.length() == 0 ) { 147// tag.add( "id" , name ); 148// id = name; 149// } 150// tag.add( tagBuffer.makeTag() ); 151// tag.add( optAttr ); 152// tag.addBody( value ); 153// 154// return tag.makeTag() + createCLEditorSc(id); 155 } 156 157 /** 158 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 159 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し, 160 * リクエスト情報を1つ毎のフィールドで処理できます。 161 * 162 * @param row 行番号 163 * @param value 入力値 164 * 165 * @return データ表示/編集用の文字列 166 */ 167 @Override 168 public String getValue( final int row,final String value ) { 169 final String newName = name + HybsSystem.JOINT_STRING + row; 170 final String id = nval( attributes.get( "id" ) , newName ); 171 172 return super.getValue( row,value ) + createCLEditorSc( id ); 173 174// String id = ""; 175// 176// TagBuffer tag = new TagBuffer( "textarea" ); 177// String newName = name + HybsSystem.JOINT_STRING + row; 178// tag.add( "name" , newName ); 179// id = attributes.get( "id" ); 180// if( id == null || id.length() == 0 ) { 181// tag.add( "id" , newName ); 182// id = newName; 183// } 184// 185// tag.add( tagBuffer.makeTag() ); 186// tag.add( optAttr ); 187// tag.addBody( value ); 188// 189// return tag.makeTag( row,value ) + createCLEditorSc(id); 190 } 191 192 /** 193 * CLEditorスクリプトを生成します。 194 * 195 * @og.rev 5.10.1.0 (2018/06/29) クリアボタンとエラー画面からの戻る場合の対応 196 * @og.rev 8.4.3.0 (2023/04/07) jQuery .click(…) ⇒ .on('click',…) に置き換え 197 * 198 * @param id ID値 199 * 200 * @return CLEditorスクリプト 201 */ 202 private String createCLEditorSc( final String id ) { 203 204 final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE ) 205 // 8.1.0.0 (2021/12/28) HTML5 準拠に見直し(<script> type属性削除) 206// .append( "<script type='text/javascript'>" ) 207 .append( "<script>" ) 208 .append( "var trg = $('#" ).append( id ).append( "').cleditor({" ) 209 .append( "bodyStyle:''" ) 210 .append( ",height:" ).append( cols1 ) 211 .append( ",width:" ).append( cols2 ) 212 .append( ",controls: 'bold size | color highlight | removeformat | link unlink | undo redo'" ); 213 214 final String attr = attributes.get( "optionAttributes" ); 215 if( attr != null && attr.length() > 0 ) { 216 buf.append( ',' ).append( attr ); 217 } 218 buf.append( "})[0];" ) 219 // editorをtextareaに反映(この処理で更新なしの場合も、><の文字ががエンコードされる。) 220 .append( "trg.updateTextArea();" ); 221 // readonly属性が設定されている場合は、変更不可。 222 if( "readonly".equals( attributes.get( "readonly" ) ) ) { 223 buf.append( "trg.disable('true');" ) 224 // linkは新規ウィンドウに表示 225 .append( "$('#" ).append( id ).append( "').next('iframe').contents().find('a').attr('target','_blank');" ); 226 } 227 // 2018/06/29 ADD START 228 // クリアボタン押下時の動作(textareaの値をiframeに反映して、初期状態に戻す) 229 // reset後に反映するために、setTimeoutで遅延 230// buf.append("$('input[type=reset]').click(function(){setTimeout(function(){trg.updateFrame()},10);});") 231 buf.append("$('input[type=reset]').on('click',function(){setTimeout(function(){trg.updateFrame()},10);});") // 8.4.3.0 (2023/04/07) 232 // エラー画面からの戻る対応。textareaの値をiframeに反映する。 233 .append("$(function(){trg.updateFrame();});") 234 // 2018/06/29 ADD END 235 .append( "</script>" ); 236 237 return buf.toString(); 238 239// StringBuilder js = new StringBuilder(); 240// js.append("<script type='text/javascript'>"); 241// js.append("var trg = $('#").append(id).append("').cleditor({"); 242// js.append("bodyStyle:''"); 243// js.append(",height:").append(size1); 244// js.append(",width:").append(size2); 245// js.append(",controls: 'bold size | color highlight | removeformat | link unlink | undo redo'"); 246// String attr = attributes.get( "optionAttributes" ); 247// if(attr != null && attr.length() > 0) { 248// js.append(",").append(attr); 249// } 250// js.append("})[0];"); 251// // editorをtextareaに反映(この処理で更新なしの場合も、><の文字ががエンコードされる。) 252// js.append("trg.updateTextArea();"); 253// // readonly属性が設定されている場合は、変更不可。 254// if("readonly".equals(attributes.get("readonly"))) { 255// js.append("trg.disable('true');"); 256// // linkは新規ウィンドウに表示 257// js.append("$('#").append(id).append("').next('iframe').contents().find('a').attr('target','_blank');"); 258// } 259// js.append("</script>"); 260// 261// return js.toString(); 262 } 263}