Skip to content

Commit

Permalink
48659 Optional writing of tasks in onOffice enterprise with plugin fo…
Browse files Browse the repository at this point in the history
…rms & fields. (#826)

* 48659 update option create task for form

* 48659 add required field

* 48659 refactor code

* 48659 update unit test

* 48659 refactor code

* 48659 update type task callback

* 48659 update unit test

* 48659 update unit test

* 48659 update unit test

* 48659 refactor code

* 48659 update unit test

* update unit test

* 48659 update unit test

---------

Co-authored-by: dai-eastgate <106214469+dai-eastgate@users.noreply.github.com>
Co-authored-by: dai.trinh <dai.trinh@eastgate-software.com>
Co-authored-by: Anja Möller <22166320+andernath@users.noreply.github.com>
  • Loading branch information
4 people authored Oct 29, 2024
1 parent 1843ed7 commit 5ed9e9c
Show file tree
Hide file tree
Showing 34 changed files with 1,189 additions and 18 deletions.
1 change: 1 addition & 0 deletions css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ body #post-head-content p.wp-clearfix:nth-child(1) {
margin-left: 5px;
}

.oo-poststuff .custom-input-field textarea[name=oopluginformtaskconfig-description],
.oo-poststuff .custom-input-field textarea[name=oopluginformactivityconfig-remark] {
min-height: 100px;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/checkbox.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions js/checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,38 @@ onOffice.checkboxAdmin = function() {
{
element: "input[name^=oopluginformfieldconfig-hiddenfield]",
invert: true
],

// view: create new [task] form
"input[name=oopluginformtaskconfig-enablecreatetask]": [
{
element: "select[name=oopluginformtaskconfig-responsibility]",
invert: false
},
{
element: "select[name=oopluginformtaskconfig-processor]",
invert: false
},
{
element: "select[name=oopluginformtaskconfig-type]",
invert: false,
required: true
},
{
element: "select[name=oopluginformtaskconfig-priority]",
invert: false
},
{
element: "input[name=oopluginformtaskconfig-subject]",
invert: false
},
{
element: "textarea[name=oopluginformtaskconfig-description]",
invert: false
},
{
element: "select[name=oopluginformtaskconfig-status]",
invert: false
},
],

Expand Down Expand Up @@ -100,6 +132,7 @@ onOffice.checkboxAdmin.prototype.changeCbStatus = function(topElement) {
var receiver = receivers[i];
var receiverElement = mainElement.parent().parent().find(receiver.element);
var invert = receiver.invert;
let required = receiver.required;

if (receiverElement.length) {
if (mainElement.prop('checked')) {
Expand All @@ -110,13 +143,19 @@ onOffice.checkboxAdmin.prototype.changeCbStatus = function(topElement) {
receiverElement.prop('disabled', 'disabled');
receiverElement.removeAttr('checked');
}
if (required) {
receiverElement.attr('required', 'required');
}
} else {
if (!invert) {
receiverElement.prop('disabled', 'disabled');
receiverElement.removeAttr('checked');
} else {
receiverElement.removeAttr('disabled');
}
if (required) {
receiverElement.attr('required', 'required');
}
}
}
}
Expand Down
88 changes: 88 additions & 0 deletions plugin/DataFormConfiguration/DataFormConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,30 @@ class DataFormConfiguration
/** @var string */
private $_advisorylevel = '';

/** @var bool */
private $_enableCreateTask = false;

/** @var string */
private $_taskResponsibility = '';

/** @var string */
private $_taskProcessor = '';

/** @var int */
private $_taskType = 0;

/** @var string */
private $_taskSubject = '';

/** @var string */
private $_taskDescription = '';

/** @var int */
private $_taskStatus = 0;

/** @var int */
private $_taskPriority = 0;

/**
*
* Override to set default fields for new, empty forms
Expand Down Expand Up @@ -327,4 +351,68 @@ public function getAdvisorylevel(): string
/** @param string $advisorylevel */
public function setAdvisorylevel(string $advisorylevel)
{ $this->_advisorylevel = $advisorylevel; }

/** @return bool */
public function getEnableCreateTask(): bool
{ return $this->_enableCreateTask; }

/** @param bool $enableCreateTask */
public function setEnableCreateTask(bool $enableCreateTask)
{ $this->_enableCreateTask = $enableCreateTask; }

/** @return string */
public function getTaskResponsibility(): string
{ return $this->_taskResponsibility; }

/** @param string $taskResponsibility */
public function setTaskResponsibility(string $taskResponsibility)
{ $this->_taskResponsibility = $taskResponsibility; }

/** @return string */
public function getTaskProcessor(): string
{ return $this->_taskProcessor; }

/** @param string $taskProcessor */
public function setTaskProcessor(string $taskProcessor)
{ $this->_taskProcessor = $taskProcessor; }

/** @return int */
public function getTaskType(): int
{ return $this->_taskType; }

/** @param int $taskType */
public function setTaskType(int $taskType)
{ $this->_taskType = $taskType; }

/** @return int */
public function getTaskPriority(): int
{ return $this->_taskPriority; }

/** @param int $taskPriority */
public function setTaskPriority(int $taskPriority)
{ $this->_taskPriority = $taskPriority; }

/** @return string */
public function getTaskSubject(): string
{ return $this->_taskSubject; }

/** @param string $taskSubject */
public function setTaskSubject(string $taskSubject)
{ $this->_taskSubject = $taskSubject; }

/** @return string */
public function getTaskDescription(): string
{ return $this->_taskDescription; }

/** @param string $taskDescription */
public function setTaskDescription(string $taskDescription)
{ $this->_taskDescription = $taskDescription; }

/** @return int */
public function getTaskStatus(): int
{ return $this->_taskStatus; }

/** @param int $taskStatus */
public function setTaskStatus(int $taskStatus)
{ $this->_taskStatus = $taskStatus; }
}
23 changes: 23 additions & 0 deletions plugin/DataFormConfiguration/DataFormConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ private function createByRow(array $row)
if ($this->_type !== Form::TYPE_APPLICANT_SEARCH){
$rowActivityConfig = $this->_pRecordManagerRead->readActivityConfigByFormId($formId);
$this->configureActivity($pConfig, $rowActivityConfig);
$rowTaskConfig = $this->_pRecordManagerRead->readFormTaskConfigByFormId($formId);
$this->configureTask($pConfig, $rowTaskConfig);
}

foreach ($rowFields as $fieldRow) {
Expand Down Expand Up @@ -291,6 +293,27 @@ private function configureGeoFields(array $result): array
return $result;
}

/**
* @param DataFormConfiguration\DataFormConfiguration $pFormConfiguration
* @param array|null $row
* @return void
*/
private function configureTask(DataFormConfiguration\DataFormConfiguration $pFormConfiguration, array $row = null)
{
if (empty($row)) {
return;
}

$pFormConfiguration->setEnableCreateTask((bool)$row['enable_create_task']);
$pFormConfiguration->setTaskResponsibility($row['responsibility']);
$pFormConfiguration->setTaskProcessor($row['processor']);
$pFormConfiguration->setTaskType($row['type']);
$pFormConfiguration->setTaskPriority($row['priority']);
$pFormConfiguration->setTaskSubject($row['subject']);
$pFormConfiguration->setTaskDescription($row['description']);
$pFormConfiguration->setTaskStatus($row['status']);
}


/**
*
Expand Down
16 changes: 14 additions & 2 deletions plugin/Field/Collection/FieldLoaderSupervisorValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ class FieldLoaderSupervisorValues implements FieldLoader
/** @var SDKWrapper */
private $_pSDKWrapper;

public function __construct(SDKWrapper $_pSDKWrapper)
/** @var bool */
private $_isReturnValueForUserNameElements;

/**
* @param SDKWrapper $_pSDKWrapper
* @param bool $isReturnValueForUserNameElements
*/
public function __construct(SDKWrapper $_pSDKWrapper, bool $isReturnValueForUserNameElements = false)
{
$this->_pSDKWrapper = $_pSDKWrapper;
$this->_isReturnValueForUserNameElements = $isReturnValueForUserNameElements;
}

/**
Expand Down Expand Up @@ -109,7 +117,11 @@ private function getFullNameSupervisor(): array
}
}

$fullNameSupervisor[$value['elements']['id']] = $fullName;
if ($this->_isReturnValueForUserNameElements) {
$fullNameSupervisor[$value['elements']['username']] = $fullName;
} else {
$fullNameSupervisor[$value['elements']['id']] = $fullName;
}
}

return $fullNameSupervisor;
Expand Down
40 changes: 39 additions & 1 deletion plugin/Form/FormAddressCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
use onOffice\WPlugin\API\APIClientActionGeneric;
use onOffice\WPlugin\API\ApiClientException;
use onOffice\WPlugin\Cache\CacheHandler;
use onOffice\WPlugin\DataFormConfiguration\DataFormConfiguration;
use onOffice\WPlugin\Field\Collection\FieldsCollectionBuilderShort;
use onOffice\WPlugin\Field\UnknownFieldException;
use onOffice\WPlugin\FormData;
use onOffice\WPlugin\SDKWrapper;
use onOffice\WPlugin\Types\FieldsCollection;
use onOffice\WPlugin\Types\FieldTypes;
use onOffice\WPlugin\Language;
use onOffice\WPlugin\DataFormConfiguration\DataFormConfiguration;

/**
*
Expand Down Expand Up @@ -409,6 +409,8 @@ private function getAddressDataForReadAddressApiCall(FormData $pFormData): array
* @param DataFormConfiguration $pFormConfig
* @param int $addressId
* @param int|null $estateId
*
* @return void
*/
public function createAgentsLog(DataFormConfiguration $pFormConfig, int $addressId, int $estateId = null)
{
Expand All @@ -434,4 +436,40 @@ public function createAgentsLog(DataFormConfiguration $pFormConfig, int $address
$pApiClientAction->setParameters($requestParams);
$pApiClientAction->addRequestToQueue()->sendRequests();
}

/**
* @param DataFormConfiguration $pFormConfig
* @param int $addressId
* @param int|null $estateId
*
* @return void
*/
public function createTask(DataFormConfiguration $pFormConfig, int $addressId, int $estateId = null)
{
if (empty($pFormConfig->getTaskType()) || empty($pFormConfig->getTaskStatus())) {
return;
}

$requestParams = [
'data' => [
'Prio' => $pFormConfig->getTaskPriority(),
'Verantwortung' => $pFormConfig->getTaskResponsibility(),
'Art' => $pFormConfig->getTaskType(),
'Status' => $pFormConfig->getTaskStatus(),
'Bearbeiter' => $pFormConfig->getTaskProcessor(),
'Betreff' => $pFormConfig->getTaskSubject(),
'Aufgabe' => $pFormConfig->getTaskDescription()
],
'relatedAddressId' => $addressId,
];

if (!empty($estateId)) {
$requestParams['relatedEstateId'] = $estateId;
}

$pApiClientAction = new APIClientActionGeneric
($this->_pSDKWrapper, onOfficeSDK::ACTION_ID_CREATE, 'task');
$pApiClientAction->setParameters($requestParams);
$pApiClientAction->addRequestToQueue()->sendRequests();
}
}
5 changes: 5 additions & 0 deletions plugin/FormPostContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ private function createAddress(FormData $pFormData)
$checkDuplicate = $pFormConfig->getCheckDuplicateOnCreateAddress();
$writeActivity = $pFormConfig->getWriteActivity();
$contactType = $pFormConfig->getContactType();
$enableCreateTask = $pFormConfig->getEnableCreateTask();
$pWPQuery = $this->_pFormPostContactConfiguration->getWPQueryWrapper()->getWPQuery();
$estateId = $pWPQuery->get('estate_id', null);
$latestAddressIdOnEnterPrise = null;
Expand All @@ -161,6 +162,10 @@ private function createAddress(FormData $pFormData)
$this->_pFormPostContactConfiguration->getFormAddressCreator()->createAgentsLog($pFormConfig, $addressId, $estateId);
}

if ($enableCreateTask) {
$this->_pFormPostContactConfiguration->getFormAddressCreator()->createTask($pFormConfig, $addressId, $estateId);
}

if (!$this->_pFormPostContactConfiguration->getNewsletterAccepted()) {
// No subscription for newsletter, which is ok
return;
Expand Down
4 changes: 4 additions & 0 deletions plugin/FormPostInterest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ protected function analyseFormContentByPrefix(FormData $pFormData)
$estateId = $pWPQuery->get('estate_id', null);
$writeActivity = $pFormConfiguration->getWriteActivity();
$latestAddressIdOnEnterPrise = null;
$enableCreateTask = $pFormConfiguration->getEnableCreateTask();
if ($checkDuplicate) {
$latestAddressIdOnEnterPrise = $this->_pFormPostInterestConfiguration->getFormAddressCreator()->getLatestAddressIdInOnOfficeEnterprise();
}
Expand All @@ -103,6 +104,9 @@ protected function analyseFormContentByPrefix(FormData $pFormData)
$this->_pFormPostInterestConfiguration->getFormAddressCreator()->createAgentsLog($pFormConfiguration, $addressId, null);
}
$this->setNewsletter( $addressId );
if ($enableCreateTask) {
$this->_pFormPostInterestConfiguration->getFormAddressCreator()->createTask($pFormConfiguration, $addressId, $estateId);
}
}
} finally {
if ( $recipient != null ) {
Expand Down
4 changes: 4 additions & 0 deletions plugin/FormPostOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ protected function analyseFormContentByPrefix(FormData $pFormData)
if ( $pDataFormConfiguration->getCreateOwner() ) {
$checkDuplicate = $pDataFormConfiguration->getCheckDuplicateOnCreateAddress();
$contactType = $pDataFormConfiguration->getContactType();
$enableCreateTask = $pDataFormConfiguration->getEnableCreateTask();
$pWPQuery = $this->_pFormPostOwnerConfiguration->getWPQueryWrapper()->getWPQuery();
$estateId = $pWPQuery->get('estate_id', null);
$writeActivity = $pDataFormConfiguration->getWriteActivity();
Expand All @@ -122,6 +123,9 @@ protected function analyseFormContentByPrefix(FormData $pFormData)
$this->_pFormPostOwnerConfiguration->getFormAddressCreator()->createAgentsLog($pDataFormConfiguration, $addressId, $estateId);
}
$this->setNewsletter( $addressId );
if ($enableCreateTask) {
$this->_pFormPostOwnerConfiguration->getFormAddressCreator()->createTask($pDataFormConfiguration, $addressId, $estateId);
}
}
} finally {
if ( null != $recipient ) {
Expand Down
Loading

0 comments on commit 5ed9e9c

Please sign in to comment.