From ae186f9302f0918a7314ab24f2d1c09d937a08b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cankush=5Fm=E2=80=9D?= Date: Wed, 28 Aug 2019 19:35:08 +0530 Subject: [PATCH 1/2] Task #184 feat: Add config in ownership field for cluster awareness and for selecting the user as record owner --- .../com_tjucm/site/models/itemform.php | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/components/com_tjucm/site/models/itemform.php b/src/components/com_tjucm/site/models/itemform.php index 9c9c3aa8..3203a535 100644 --- a/src/components/com_tjucm/site/models/itemform.php +++ b/src/components/com_tjucm/site/models/itemform.php @@ -459,11 +459,19 @@ public function save($data, $extra_jform_data = '') // If there is ownership field in form and the field is assigned some value then update created_by for the record $client = explode(".", $itemDetails->client); - $createdByField = $client[0] . '_' . $client[1] . '_ownershipcreatedby'; + $ownershipField = $client[0] . '_' . $client[1] . '_ownershipcreatedby'; - if (isset($extra_jform_data[$createdByField]) && !empty($extra_jform_data[$createdByField])) + if (isset($extra_jform_data[$ownershipField]) && !empty($extra_jform_data[$ownershipField])) { - $data['created_by'] = $extra_jform_data[$createdByField]; + JLoader::import('components.com_tjfields.tables.field', JPATH_ADMINISTRATOR); + $ownershipFieldData = Table::getInstance('Field', 'TjfieldsTable'); + $ownershipFieldData->load(array('name' => $ownershipField)); + $ownershipFieldParams = json_decode($ownershipFieldData->params); + + if ($ownershipFieldParams->ucmItemOwner == 1) + { + $data['created_by'] = $extra_jform_data[$ownershipField]; + } } else { @@ -819,20 +827,25 @@ public function allowedToAddTypeData($userId, $client, $allowedCount) */ public function setClusterData(&$validData, $data) { - $clusterField = $createdByField = ''; + $clusterField = $ownershipField = ''; // To get type of UCM if (!empty($this->client)) { $client = explode(".", $this->client); $clusterField = $client[0] . '_' . $client[1] . '_clusterclusterid'; - $createdByField = $client[0] . '_' . $client[1] . '_ownershipcreatedby'; + $ownershipField = $client[0] . '_' . $client[1] . '_ownershipcreatedby'; } + JLoader::import('components.com_tjfields.tables.field', JPATH_ADMINISTRATOR); + $ownershipFieldData = Table::getInstance('Field', 'TjfieldsTable'); + $ownershipFieldData->load(array('name' => $ownershipField)); + $ownershipFieldParams = json_decode($ownershipFieldData->params); + // Save created_by field by ownership user field (To save form on behalf of someone) - if (!empty($data[$createdByField]) && empty($data[$clusterField])) + if (!empty($data[$ownershipField]) && empty($data[$clusterField]) && ($ownershipFieldParams->ucmItemOwner == 1)) { - $validData['created_by'] = $data[$createdByField]; + $validData['created_by'] = $data[$ownershipField]; } // Cluster Id store in UCM data @@ -861,7 +874,7 @@ public function setClusterData(&$validData, $data) { $validData['cluster_id'] = $data[$clusterField]; - if (!empty($data[$createdByField])) + if (!empty($data[$ownershipField])) { $clusterUsers = array(); @@ -870,9 +883,9 @@ public function setClusterData(&$validData, $data) $clusterUsers[] = $cluster->user_id; } - if (in_array($data[$createdByField], $clusterUsers)) + if (in_array($data[$ownershipField], $clusterUsers) && ($ownershipFieldParams->ucmItemOwner == 1)) { - $validData['created_by'] = $data[$createdByField]; + $validData['created_by'] = $data[$ownershipField]; } } } From 747185383a798eee2967a6438e05f37e372902e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cankush=5Fm=E2=80=9D?= Date: Wed, 28 Aug 2019 19:46:38 +0530 Subject: [PATCH 2/2] Task #184 feat: Add config in ownership field for cluster awareness and for selecting the user as record owner --- .../com_tjucm/administrator/assets/js/tjucm_ajaxForm_save.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/com_tjucm/administrator/assets/js/tjucm_ajaxForm_save.js b/src/components/com_tjucm/administrator/assets/js/tjucm_ajaxForm_save.js index a5c88610..f3c72d7f 100644 --- a/src/components/com_tjucm/administrator/assets/js/tjucm_ajaxForm_save.js +++ b/src/components/com_tjucm/administrator/assets/js/tjucm_ajaxForm_save.js @@ -122,6 +122,7 @@ function steppedFormSave(form_id, status, showDraftSuccessMsg) if (returnedData.data !== null) { jQuery('#item-form').removeClass('dirty'); + jQuery("#recordId").val(returnedData.data.id); if ('save' == status) { @@ -133,7 +134,6 @@ function steppedFormSave(form_id, status, showDraftSuccessMsg) } else { - jQuery("#recordId").val(returnedData.data.id); promise = true; if (showDraftSuccessMsg === "1")