Skip to content
Snippets Groups Projects
Commit 39ca3d5c authored by Peter Rotich's avatar Peter Rotich
Browse files

forms: Internal Forms

Add internal forms for generic object assignment and transfer. This provides
for a consistent action forms across the system.
parent a40a8038
No related branches found
No related tags found
No related merge requests found
......@@ -3201,4 +3201,193 @@ class VisibilityConstraint {
}
}
class AssignmentForm extends Form {
static $id = 'assign';
var $_assignee = null;
function __construct($source=null, $options=array()) {
parent::__construct($source, $options);
}
function getFields() {
if ($this->fields)
return $this->fields;
$fields = array(
'assignee' => new AssigneeField(array(
'id'=>1,
'label' => __('Assignee'),
'flags' => hexdec(0X450F3),
'required' => true,
'validator-error' => __('Assignee selection required'),
)
),
'comments' => new TextareaField(array(
'id' => 2,
'label'=> '',
'required'=>false,
'default'=>'',
'configuration' => array(
'html' => true,
'size' => 'large',
'placeholder' => __('Optional reason for the assignment'),
),
)
),
);
$this->setFields($fields);
return $this->fields;
}
function isValid() {
if (!parent::isValid())
return false;
// Do additional assignment validation
if (!($assignee = $this->getAssignee())) {
$this->getField('assignee')->addError(
__('Unknown assignee'));
} elseif ($assignee instanceof Staff) {
// Make sure the agent is available
if (!$assignee->isAvailable())
$this->getField('assignee')->addError(
__('Agent is unavailable for assignment')
);
}
return !$this->errors();
}
function getClean() {
return parent::getClean();
}
function render($options) {
switch(strtolower($options['template'])) {
case 'simple':
$inc = STAFFINC_DIR . 'templates/dynamic-form-simple.tmpl.php';
break;
default:
throw new Exception(sprintf(__('%s: Unknown template style %s'),
'FormUtils', $options['template']));
}
$form = $this;
include $inc;
}
function getAssignee() {
if (!isset($this->_assignee)) {
$value = $this->getField('assignee')->getClean();
if ($value[0] == 's')
$this->_assignee = Staff::lookup(substr($value, 1));
elseif ($value[0] == 't')
$this->_assignee = Team::lookup(substr($value, 1));
}
return $this->_assignee;
}
function assigneeCriteria() {
$dept = $this->id;
return function () use($dept) {
return array('dept_id' =>$dept);
};
}
}
class TransferForm extends Form {
static $id = 'transfer';
var $_dept = null;
function __construct($source=null, $options=array()) {
parent::__construct($source, $options);
}
function getFields() {
if ($this->fields)
return $this->fields;
$fields = array(
'dept' => new DepartmentField(array(
'id'=>1,
'label' => __('Department'),
'flags' => hexdec(0X450F3),
'required' => true,
'validator-error' => __('Department selection required'),
)
),
'comments' => new TextareaField(array(
'id' => 2,
'label'=> '',
'required'=>false,
'default'=>'',
'configuration' => array(
'html' => true,
'size' => 'large',
'placeholder' => __('Optional reason for the transfer'),
),
)
),
);
$this->setFields($fields);
return $this->fields;
}
function isValid() {
if (!parent::isValid())
return false;
// Do additional validations
if (!($dept = $this->getDept()))
$this->getField('dept')->addError(
__('Unknown department'));
return !$this->errors();
}
function getClean() {
return parent::getClean();
}
function render($options) {
switch(strtolower($options['template'])) {
case 'simple':
$inc = STAFFINC_DIR . 'templates/dynamic-form-simple.tmpl.php';
break;
default:
throw new Exception(sprintf(__('%s: Unknown template style %s'),
get_class(), $options['template']));
}
$form = $this;
include $inc;
}
function getDept() {
if (!isset($this->_dept)) {
if (($id = $this->getField('dept')->getClean()))
$this->_dept = Dept::lookup($id);
}
return $this->_dept;
}
}
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment