Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F/display edit custom data #523

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions CRM/Volunteer/BAO/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@

class CRM_Volunteer_BAO_Project extends CRM_Volunteer_DAO_Project {

/**
* Static field for all the case information that we can potentially export.
*
* @var array
*/
public static $_exportableFields = NULL;

/**
* Array of attributes on the related entity, translated to a common vocabulary.
*
Expand Down Expand Up @@ -362,7 +369,7 @@ public static function create(array $params) {
*
* @see CRM_Volunteer_BAO_Assignment::setActivityDefaults()
*/
public function updateAssociatedActivities () {
public function updateAssociatedActivities() {
$activities = CRM_Volunteer_BAO_Assignment::retrieve(array(
'project_id' => $this->id,
));
Expand Down Expand Up @@ -688,7 +695,7 @@ public function getEntityAttributes() {
* @param int $project_id
* @return mixed Integer on success, else NULL
*/
public static function getFlexibleNeedID ($project_id) {
public static function getFlexibleNeedID($project_id) {
$result = NULL;

if (is_int($project_id) || ctype_digit($project_id)) {
Expand Down Expand Up @@ -833,8 +840,7 @@ public static function getDefaultProjectContacts() {
*
* @var array
*/
public static function getProjectProfileAudienceTypes()
{
public static function getProjectProfileAudienceTypes() {
return array(
"primary" => array(
"type" => "primary",
Expand All @@ -853,6 +859,29 @@ public static function getProjectProfileAudienceTypes()
),
);
}

/**
* Combine all the exportable fields from the lower levels object.
*
* @return array
* array of exportable Fields
*/
public static function &exportableFields() {
if (!self::$_exportableFields) {
if (!self::$_exportableFields) {
self::$_exportableFields = array();
}

$fields = CRM_Volunteer_DAO_Project::export();

// add custom data for volunteer projects
$fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('VolunteerProject'));

self::$_exportableFields = $fields;
}
return self::$_exportableFields;
}

/**
* Sets and returns the start date of the entity associated with this Project
*
Expand Down Expand Up @@ -957,7 +986,6 @@ private function _get_roles() {
return $this->roles;
}


/**
* Sets and returns $this->open_needs. Delegate of __get().
*
Expand Down
147 changes: 147 additions & 0 deletions CRM/Volunteer/Form/CustomData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2019
*/

/**
* This class generates form components for custom data
*
* It delegates the work to lower level subclasses and integrates the changes
* back in. It also uses a lot of functionality with the CRM API's, so any change
* made here could potentially affect the API etc. Be careful, be aware, use unit tests.
*/
class CRM_Volunteer_Form_CustomData extends CRM_Core_Form {

/**
* Entity name (e.g. VolunteerProject).
*
* @var string
*/
protected $_entityName;

/**
* The entity id, used when editing/creating custom data
*
* @var int
*/
protected $_entityID;

// /**
// * Entity sub type of the table id.
// *
// * @var string
// */
// protected $_subTypeID;

/**
* Pre processing work done here.
*
* gets session variables for table name, id of entity in table, type of entity and stores them.
*/
public function preProcess() {
$this->_entityName = CRM_Utils_Request::retrieve('entityName', 'String', $this, TRUE);
$this->_entityID = CRM_Utils_Request::retrieve('entityID', 'Positive', $this, TRUE);
$this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, FALSE);
// $this->_subTypeID = CRM_Utils_Request::retrieve('subType', 'Positive', $this, TRUE);

if (!in_array($this->_entityName, ['VolunteerProject'])) {
$this->_entityName = 'VolunteerProject';
}

$groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_entityName,
NULL,
$this->_entityID,
$this->_groupID,
NULL // $this->_subTypeID
);
// simplified formatted groupTree
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this);
// Array contains only one item
foreach ($groupTree as $groupValues) {
$this->_customTitle = $groupValues['title'];
CRM_Utils_System::setTitle(ts('Edit %1', [1 => $groupValues['title']]));
}

$this->_defaults = [];
CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $this->_defaults);
$this->setDefaults($this->_defaults);

CRM_Core_BAO_CustomGroup::buildQuickForm($this, $groupTree);

//need to assign custom data type and subtype to the template
$this->assign('entityName', $this->_entityName);
$this->assign('entityID', $this->_entityID);
$this->assign('groupID', $this->_groupID);
// $this->assign('subType', $this->_subTypeID);
}

/**
* Build the form object.
*/
public function buildQuickForm() {
// make this form an upload since we dont know if the custom data injected dynamically
// is of type file etc
$this->addButtons([
[
'type' => 'upload',
'name' => ts('Save'),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]);
}

/**
* Process the user submitted custom data values.
*/
public function postProcess() {
$params = $this->controller->exportValues($this->_name);

$transaction = new CRM_Core_Transaction();

$entityTable = 'civicrm_volunteer_project';

CRM_Core_BAO_CustomValueTable::postProcess($params,
$entityTable,
$this->_entityID,
$this->_entityName
);

$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/vol', "#/volunteer/manage/{$this->_entityID}"));

$transaction->commit();
}

}
32 changes: 32 additions & 0 deletions ang/volunteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,38 @@
};
})

// Editable custom data blocks
.directive('volunteerEditCustomData', function($timeout) {
return {
restrict: 'A',
link: function (scope, elem, attrs) {
elem
.addClass('crm-editable-enabled')
.on('click', function(e) {
var url = CRM.url('civicrm/volunteer/cd/edit', {
action: 'update',
reset: 1,
entityName: 'VolunteerProject',
entityID: scope.project.id,
groupID: scope.customGroup.id,
// subType: scope.item.case_type_id,
});

var settings = {
dialog: {
width: "85%",
height:"80%",
},
};
CRM
.loadForm(url, settings)
.on('crmFormSuccess', function(e, data) {
scope.refreshCustomData();
});
});
}
};
})

/**
* This is a service for loading the backbone-based volunteer UIs (and their
Expand Down
9 changes: 9 additions & 0 deletions ang/volunteer/CustomData.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<fieldset class="crm-collapsible" ng-class="::{ collapsed: customGroup.collapse_display }">
<legend class="collapsible-title" ng-click="customGroup.collapse_display = !customGroup.collapse_display">{{ ::customGroup.title }}</legend>
<div volunteer-edit-custom-data>
<div ng-repeat="field in customGroup.fields">
<strong>{{ field.label }}:</strong>
{{ field.value.display }}
</div>
</div>
</fieldset>
7 changes: 6 additions & 1 deletion ang/volunteer/Project.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,15 @@
</div>
</div>


<div class="crm-vol-is_active" crm-ui-field="{name: 'projectForm.is_active', title: ts('Is this Project Active?')}">
<input type="checkbox" crm-ui-id="projectForm.is_active" ng-model="project.is_active" />
</div>

<div class="crm-vol-custom-data" ng-if="project.customData.length > 0">
<div class="crm-vol-custom-data-first" ng-repeat="(index, customGroup) in project.customData" ng-include="'~/volunteer/CustomData.html'"></div>
<br />
</div>

</fieldset>

<fieldset class="crm-vol-relationships" ng-if="showRelationshipBlock" crm-ui-id-scope>
Expand Down
Loading