44
55
66use Ajax \JsUtils ;
7+ use Ajax \semantic \html \collections \form \HtmlFormField ;
8+ use Ajax \semantic \html \collections \form \HtmlForm ;
79class HtmlDoubleElement extends HtmlSingleElement {
810 /**
911 *
@@ -12,6 +14,7 @@ class HtmlDoubleElement extends HtmlSingleElement {
1214 protected $ content ;
1315 protected $ wrapContentBefore ="" ;
1416 protected $ wrapContentAfter ="" ;
17+ protected $ _editableContent ;
1518
1619 public function __construct ($ identifier , $ tagName ="p " ) {
1720 parent ::__construct ($ identifier , $ tagName );
@@ -103,4 +106,40 @@ public function getTextContent(){
103106 }
104107 return strip_tags ($ this ->content );
105108 }
109+
110+ public function asEditable (HtmlFormField $ field ,$ asForm =false ,$ setValueProperty ="val() " ){
111+ $ idF =$ field ->getIdentifier ();
112+ $ idE =$ idF ;
113+ if ($ asForm ){
114+ $ frm =new HtmlForm ("frm- " .$ field ->getIdentifier ());
115+ $ frm ->setProperty ("onsubmit " , "return false; " );
116+ $ fields =$ frm ->addFields ();
117+ $ idE =$ frm ->getIdentifier ();
118+ $ fields ->addItem ($ field );
119+ $ fields ->addButtonIcon ("bt-okay " , "check " ,"green mini " ,"\$('# " .$ idE ."').trigger('validate',{value: $('#'+idF+' input').val()}); " );
120+ $ fields ->addButtonIcon ("bt-cancel " , "close " ,"mini " ,"\$('# " .$ idE ."').trigger('endEdit'); " );
121+ $ this ->_editableContent =$ frm ;
122+ $ keypress ="" ;
123+ $ focusOut ="" ;
124+ }else {
125+ $ focusOut ="if(e.relatedTarget==null)elm.trigger('endEdit'); " ;
126+ $ this ->_editableContent =$ field ;
127+ $ keypress ="$('# " .$ idF ."').keyup(function(e){if(e.which == 13) { \$('# " .$ idE ."').trigger('validate',{value: $('#'+idF+' input').val()});}if(e.keyCode===27) { \$('# " .$ idE ."').trigger('endEdit');}}); " ;
128+ }
129+ $ this ->_editableContent ->setProperty ("style " , "display:none; " );
130+ $ this ->onCreate ("let idF=' " .$ idF ."';let idE=' " .$ idE ."';let elm=$('#'+idE);let self=$('# " .$ this ->getIdentifier ()."'); " .$ keypress ."elm.on('validate',function(){self.html($('#'+idE+' input'). " .$ setValueProperty .");elm.trigger('endEdit');});elm.on('endEdit',function(){self.show();$(this).hide();});elm.focusout(function(e){ " .$ focusOut ."}); " );
131+ $ this ->onClick ("let self=$(this);self.hide(); " .$ field ->setJsContent ("self.html() " ).";$('# " .$ idF ." input').trigger('change');elm.show();$('#'+idE+' input').focus(); " );
132+ }
133+ /**
134+ * {@inheritDoc}
135+ * @see \Ajax\common\html\BaseHtml::compile_once()
136+ */
137+ protected function compile_once (\Ajax \JsUtils $ js = NULL , &$ view = NULL ) {
138+ if (!$ this ->_compiled && isset ($ this ->_editableContent )){
139+ $ this ->wrap ("" ,$ this ->_editableContent );
140+ }
141+ parent ::compile_once ($ js ,$ view );
142+
143+ }
144+
106145}
0 commit comments