<?php 

class InputPassword  {
  private $scope;
  private $dbValue;
  private $dbRowId;
  private $iterator;
  private $label;

  public function __construct($entry) {

    if (isset($entry)) {
      $this->scope    = $entry->scope;
      $this->dbValue  = $entry->dbValue;
      $this->dbRowId  = $entry->dbRowId;
      $this->iterator = $entry->iterator;

      if (isset($entry->placeHolder))
        $this->placeHolder = "placeholder='$entry->placeHolder'";
      else
        $this->placeHolder = "";
              
      if (isset($entry->label))
        $this->label = "<label>$entry->label</label><br>";
      else
        $this->label = "";

    }
    
  }

  public function outputLayout() {


    $layout = "

$this->label
<table><tr>
  <td style='width:75%'>
    <input type='password' id='pwd$this->scope' class='$this->iterator' 
        name='$this->scope' value='$this->dbValue' autocomplete='new-password'
        $this->placeHolder $this->attribute>
  </td>
  <td style='width:25%'>
    <button id='hid$this->scope' class='btn btn-inverse btn-xs' 
        style='width:50px;'>
      Show
    </button>
  </td>
</tr></table> 
";
  
 	return $layout;
  }	

  public function outputScript() {

	$script = "

var state$this->scope = 'hide';

$(document).on('change', '#pwd$this->scope', function (e) {
  send$this->scope ($(this).val(), '');
});

$(document).on('click', '#hid$this->scope', function (e) {
  if (state$this->scope == 'hide') {
    document.getElementById('hid$this->scope').innerHTML = 'Show';
    document.getElementById('pwd$this->scope').setAttribute('type','password')
    state$this->scope = 'show';
  }
  else {
    document.getElementById('hid$this->scope').innerHTML = 'Hide';
    document.getElementById('pwd$this->scope').setAttribute('type','text')  
    state$this->scope = 'hide';
  }
});

function set$this->scope (value, text, source) {
  document.getElementById('pwd$this->scope').value = value;
}

multiFunction['set$this->scope'] = {
  set$this->scope:set$this->scope
};  
	  
function send$this->scope (value, text) {
  var msgContent = [];
  msgContent.$this->scope = [value, text, 'formentry', '$this->scope', 'new field value'];
  newValue$this->iterator (msgContent);
}

    "; 
    return $script;
  }
}

?>