Commit 14c67729 authored by mattwire's avatar mattwire

Convert Survey/Petition to standard customData template

parent 7bce01cc
......@@ -42,6 +42,22 @@ class CRM_Campaign_Form_Petition extends CRM_Core_Form {
*/
public $_surveyId;
/**
* Explicitly declare the entity api name.
*/
public function getDefaultEntity() {
return 'Survey';
}
/**
* Get the entity id being edited.
*
* @return int|null
*/
public function getEntityId() {
return $this->_surveyId;
}
public function preProcess() {
if (!CRM_Campaign_BAO_Campaign::accessCampaign()) {
CRM_Utils_System::permissionDenied();
......@@ -64,14 +80,8 @@ class CRM_Campaign_Form_Petition extends CRM_Core_Form {
}
}
// when custom data is included in this page
if (!empty($_POST['hidden_custom'])) {
$this->set('type', 'Event');
$this->set('entityId', $this->_surveyId);
CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'Survey', $this->_surveyId);
CRM_Custom_Form_CustomData::buildQuickForm($this);
CRM_Custom_Form_CustomData::setDefaultValues($this);
}
// Add custom data to form
CRM_Custom_Form_CustomData::addToForm($this);
$session = CRM_Core_Session::singleton();
$url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey');
......@@ -90,8 +100,6 @@ class CRM_Campaign_Form_Petition extends CRM_Core_Form {
$this->assign('action', $this->_action);
$this->assign('surveyId', $this->_surveyId);
// for custom data
$this->assign('entityID', $this->_surveyId);
if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::DELETE)) {
$this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
......@@ -321,11 +329,7 @@ WHERE $whereClause
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0);
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0);
$customFields = CRM_Core_BAO_CustomField::getFields('Survey');
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params,
$this->_surveyId,
'Survey'
);
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->getEntityId(), $this->getDefaultEntity());
$surveyId = CRM_Campaign_BAO_Survey::create($params);
......
......@@ -57,6 +57,22 @@ class CRM_Campaign_Form_Survey extends CRM_Core_Form {
*/
protected $_surveyTitle;
/**
* Explicitly declare the entity api name.
*/
public function getDefaultEntity() {
return 'Survey';
}
/**
* Get the entity id being edited.
*
* @return int|null
*/
public function getEntityId() {
return $this->_surveyId;
}
public function preProcess() {
if (!CRM_Campaign_BAO_Campaign::accessCampaign()) {
CRM_Utils_System::permissionDenied();
......@@ -78,14 +94,8 @@ class CRM_Campaign_Form_Survey extends CRM_Core_Form {
$this->assign('action', $this->_action);
$this->assign('surveyId', $this->_surveyId);
// when custom data is included in this page
if (!empty($_POST['hidden_custom'])) {
$this->set('type', 'Survey');
$this->set('entityId', $this->_surveyId);
CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'Survey', $this->_surveyId);
CRM_Custom_Form_CustomData::buildQuickForm($this);
CRM_Custom_Form_CustomData::setDefaultValues($this);
}
// Add custom data to form
CRM_Custom_Form_CustomData::addToForm($this);
// CRM-11480, CRM-11682
// Preload libraries required by the "Questions" tab
......
......@@ -50,13 +50,6 @@ class CRM_Campaign_Form_Survey_Main extends CRM_Campaign_Form_Survey {
*/
protected $_context;
/**
* Explicitly declare the entity api name.
*/
public function getDefaultEntity() {
return 'Survey';
}
public function preProcess() {
parent::preProcess();
......@@ -70,11 +63,8 @@ class CRM_Campaign_Form_Survey_Main extends CRM_Campaign_Form_Survey {
CRM_Utils_System::setTitle(ts('Configure Survey') . ' - ' . $this->_surveyTitle);
}
// when custom data is included in this page
if (!empty($_POST['hidden_custom'])) {
CRM_Custom_Form_CustomData::preProcess($this);
CRM_Custom_Form_CustomData::buildQuickForm($this);
}
// Add custom data to form
CRM_Custom_Form_CustomData::addToForm($this);
if ($this->_name != 'Petition') {
$url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey');
......@@ -93,8 +83,6 @@ class CRM_Campaign_Form_Survey_Main extends CRM_Campaign_Form_Survey {
$this->assign('action', $this->_action);
$this->assign('surveyId', $this->_surveyId);
// for custom data
$this->assign('entityID', $this->_surveyId);
}
/**
......@@ -195,10 +183,8 @@ class CRM_Campaign_Form_Survey_Main extends CRM_Campaign_Form_Survey {
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0);
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0);
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params,
$this->_surveyId,
'Survey'
);
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->getEntityId(), $this->getDefaultEntity());
$survey = CRM_Campaign_BAO_Survey::create($params);
$this->_surveyId = $survey->id;
......
......@@ -95,26 +95,10 @@
</tr>
</table>
<div id="customData"></div>
{include file="CRM/common/customDataBlock.tpl"}
{/if}
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="bottom"}
</div>
</div>
{* include custom data js *}
{include file="CRM/common/customData.tpl"}
{literal}
<script type="text/javascript">
CRM.$(function($) {
{/literal}{if $customDataSubType}
CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
{else}
CRM.buildCustomData( '{$customDataType}' );
{/if}
{literal}
});
</script>
{/literal}
......@@ -117,18 +117,7 @@
</td>
</tr>
</table>
<div id="customData"></div>
{*include custom data js file*}
{include file="CRM/common/customData.tpl"}
{literal}
<script type="text/javascript">
CRM.$(function($) {
{/literal}
CRM.buildCustomData( 'Survey' );
{literal}
});
</script>
{/literal}
{include file="CRM/common/customDataBlock.tpl"}
{/if}
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
</div>
......
......@@ -79,22 +79,10 @@
</tr>
<tr class="crm-campaign-form-block-custom_data">
<td colspan="2">
<div id="customData"></div>
{include file="CRM/common/customDataBlock.tpl"}
</td>
</tr>
</table>
<div id="customData"></div>
{*include custom data js file*}
{include file="CRM/common/customData.tpl"}
{literal}
<script type="text/javascript">
CRM.$(function($) {
{/literal}
CRM.buildCustomData( 'Survey' );
{literal}
});
</script>
{/literal}
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
</div>
......@@ -116,12 +104,3 @@
});
</script>
{/literal}
{literal}
<script type="text/javascript">
CRM.$(function($) {
{/literal}
CRM.buildCustomData( 'Survey' );
{literal}
});
</script>
{/literal}
{* Edit custom data on Edit entity forms *}
{* Requires <div id="customData"></div> on the form *}
{*include custom data js file*}
{include file="CRM/common/customData.tpl"}
{literal}
<script type="text/javascript">
CRM.$(function($) {
{/literal}
CRM.buildCustomData( '{$customDataType}' );
{if $customDataSubType}
CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
{/if}
{literal}
});
</script>
{/literal}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment