JsSelectToInput.php
Go to the documentation of this file.00001 <?php
00013 class JsSelectToInput {
00015 protected $targetId;
00017 protected $sourceId;
00018
00022 protected $select;
00023
00025 protected $buttonId;
00026
00030 protected $msg = 'translate-jssti-add';
00031
00032 public function __construct( XmlSelect $select = null ) {
00033 $this->select = $select;
00034 }
00035
00040 public function setSourceId( $id ) {
00041 $this->sourceId = $id;
00042 }
00043
00045 public function getSourceId() {
00046 return $this->sourceId;
00047 }
00048
00053 public function setTargetId( $id ) {
00054 $this->targetId = $id;
00055 }
00056
00060 public function getTargetId() {
00061 return $this->targetId;
00062 }
00063
00068 public function setMessage( $message ) {
00069 $this->msg = $message;
00070 }
00071
00073 public function getMessage() {
00074 return $this->msg;
00075 }
00076
00082 public function getHtmlAndPrepareJS() {
00083 if ( $this->sourceId === false ) {
00084 if ( is_callable( array( $this->select, 'getAttribute' ) ) ) {
00085 $this->sourceId = $this->select->getAttribute['id'];
00086 }
00087
00088 if ( !$this->sourceId ) {
00089 throw new MWException( "ID needs to be specified for the selector" );
00090 }
00091 }
00092
00093 self::injectJs();
00094 $html = $this->select->getHtml();
00095 $html .= $this->getButton( $this->msg, $this->sourceId, $this->targetId );
00096
00097 return $html;
00098 }
00099
00107 protected function getButton( $msg, $source, $target ) {
00108 $source = Xml::escapeJsString( $source );
00109 $target = Xml::escapeJsString( $target );
00110 $html = Xml::element( 'input', array(
00111 'type' => 'button',
00112 'value' => wfMessage( $msg )->text(),
00113 'onclick' => "appendFromSelect( '$source', '$target' );"
00114 ) );
00115
00116 return $html;
00117 }
00118
00120 public static function injectJs() {
00121 static $done = false;
00122 if ( $done ) {
00123 return;
00124 }
00125
00126 RequestContext::getMain()->getOutput()->addModules( 'ext.translate.selecttoinput' );
00127 }
00128 }