<?php 

class BitwisePosition  {
  private $field;
  private $iterator;
  private $label;
  private $formDefs;
  private $formAlts;
  
  
  public function __construct($field) {

    if (isset($field)) {
      $this->field    = $field->field;
      $this->iterator = $field->iterator;
      $this->label    = $field->label;
      $this->length   = $field->length;
    }
  
 }

  public function outputLayout() {

    $layout = "
<span>
  <label style='vertical-align:middle;padding-top:4px'>$this->label</label>
    " ;
    
    for ($i=0;$i<$this->length;$i++) {
      $layout .= "
  <input type='checkbox' class='pos$this->field' style='vertical-align:middle;'>
      ";
    }

    $layout = "
</span>
    ";
  
 	return $layout;
  }	

  public function outputScript() {

    $script = "

$(document).on('click', '.pos$this->field', function (e) {
//alert ($(this).prop('checked'));
  if ($(this).prop('checked'))
    send$this->field (1, 'Yes');
  else
    send$this->field (0, 'No');
});

function set$this->field (value, text, source) {
  var checked = ((value == 1) ? true : false);
  $('#box$this->field').prop('checked', checked);

  if ('$this->field' == 'chkAwayFromWork')
  document.getElementById('box$this->field').disabled = 
      ((value == 1) ? true : false);
}

multiFunction['set$this->field'] = {
  set$this->field:set$this->field
}; 

function com$this->field (message) {
  var key = Object.keys(message);
logMessage ('<td>com msg</td><td>' + key +  '</td><td>$this->field</td><td>' + message[key][0] + '</td><td>' + message[key][1] + '</td><td>' + message[key][2] + '</td><td>' + message[key][3] + '</td><td>' + message[key][4] + '</td>');  
  if (key == 'selectId') {
    document.getElementById('box$this->field').disabled = 
      ((message[key][0] == 0) ? true : false);
  }  
}  

multiFunction['com$this->field'] = {
  com$this->field:com$this->field
};  


function send$this->field (value, text) {
//alert ('send');
  var msgContent = [];
  msgContent.$this->field = [value, text, 'sequent_ent', '$this->field', 'new field value'];
  newValue$this->iterator (msgContent);
}
    "; 
    
    return $script;
  }
}

?>