From 509981258c9da63fadeb3036dadd548954bee640 Mon Sep 17 00:00:00 2001 From: Kurund Jalmi Date: Sat, 29 Jun 2013 01:18:41 +0530 Subject: [PATCH] more work on CRM-12965, added basic form and page structure --- CRM/Badge/Form/Layout.php | 128 ++++++++++++++++++++++++++++ CRM/Badge/Page/Layout.php | 122 ++++++++++++++++++++++++++ CRM/Core/xml/Menu/Admin.xml | 11 +++ templates/CRM/Badge/Form/Layout.tpl | 66 ++++++++++++++ templates/CRM/Badge/Page/Layout.tpl | 83 ++++++++++++++++++ 5 files changed, 410 insertions(+) create mode 100644 CRM/Badge/Form/Layout.php create mode 100644 CRM/Badge/Page/Layout.php create mode 100644 templates/CRM/Badge/Form/Layout.tpl create mode 100644 templates/CRM/Badge/Page/Layout.tpl diff --git a/CRM/Badge/Form/Layout.php b/CRM/Badge/Form/Layout.php new file mode 100644 index 0000000000..485610e290 --- /dev/null +++ b/CRM/Badge/Form/Layout.php @@ -0,0 +1,128 @@ +_action & CRM_Core_Action::DELETE) { + return; + } + + $this->applyFilter('__ALL__', 'trim'); + $this->add('text', + 'name', + ts('Name'), + CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'name'), + TRUE + ); + $this->addRule('name', + ts('Name already exists in Database.'), + 'objectExists', + array('CRM_Core_DAO_PrintLabel', $this->_id) + ); + $this->addRule('name', + ts('Name can only consist of alpha-numeric characters'), + 'variable' + ); + + $this->add('text', 'title', ts('Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'display_name')); + $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'description')); + $this->add('checkbox', 'is_active', ts('Enabled?')); + $this->add('checkbox', 'is_default', ts('Default?')); + + if ($this->_action == CRM_Core_Action::UPDATE && CRM_Core_DAO::getFieldValue('CRM_Core_DAO_PrintLabel', $this->_id, 'is_reserved')) { + $this->freeze(array('name', 'description', 'is_active')); + } + } + + /** + * Function to process the form + * + * @access public + * + * @return None + */ + public function postProcess() { + /* + if ($this->_action & CRM_Core_Action::DELETE) { + CRM_Core_BAO_LocationType::del($this->_id); + CRM_Core_Session::setStatus(ts('Selected Location type has been deleted.'), ts('Record Deleted'), 'success'); + return; + } + + // store the submitted values in an array + $params = $this->exportValues(); + $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); + $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE); + + // action is taken depending upon the mode + $locationType = new CRM_Core_DAO_PrintLabel(); + $locationType->name = $params['name']; + $locationType->display_name = $params['display_name']; + $locationType->vcard_name = $params['vcard_name']; + $locationType->description = $params['description']; + $locationType->is_active = $params['is_active']; + $locationType->is_default = $params['is_default']; + + if ($params['is_default']) { + $query = "UPDATE civicrm_location_type SET is_default = 0"; + CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); + } + + if ($this->_action & CRM_Core_Action::UPDATE) { + $locationType->id = $this->_id; + } + + $locationType->save(); + + CRM_Core_Session::setStatus(ts("The location type '%1' has been saved.", + array(1 => $locationType->name) + ), ts('Saved'), 'success'); + */ + } +} diff --git a/CRM/Badge/Page/Layout.php b/CRM/Badge/Page/Layout.php new file mode 100644 index 0000000000..062d89dd03 --- /dev/null +++ b/CRM/Badge/Page/Layout.php @@ -0,0 +1,122 @@ + array( + 'name' => ts('Edit'), + 'url' => 'civicrm/admin/badgelayout', + 'qs' => 'action=update&id=%%id%%&reset=1', + 'title' => ts('Edit Badge Layout'), + ), + CRM_Core_Action::DISABLE => array( + 'name' => ts('Disable'), + 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Core_DAO_PrintLabel' . '\',\'' . 'enable-disable' . '\' );"', + 'ref' => 'disable-action', + 'title' => ts('Disable Badge Layout'), + ), + CRM_Core_Action::ENABLE => array( + 'name' => ts('Enable'), + 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Core_DAO_PrintLabel' . '\',\'' . 'disable-enable' . '\' );"', + 'ref' => 'enable-action', + 'title' => ts('Enable Badge Layout'), + ), + CRM_Core_Action::DELETE => array( + 'name' => ts('Delete'), + 'url' => 'civicrm/admin/badgelayout', + 'qs' => 'action=delete&id=%%id%%', + 'title' => ts('Delete Badge Layout'), + ), + ); + } + return self::$_links; + } + + /** + * Get name of edit form + * + * @return string Classname of edit form. + */ + function editForm() { + return 'CRM_Badge_Form_Layout'; + } + + /** + * Get edit form name + * + * @return string name of this page. + */ + function editName() { + return 'Badge Layout'; + } + + /** + * Get user context. + * + * @return string user context. + */ + function userContext($mode = NULL) { + return 'civicrm/admin/badgelayout'; + } +} + diff --git a/CRM/Core/xml/Menu/Admin.xml b/CRM/Core/xml/Menu/Admin.xml index c622cb4494..dddc1db5d0 100644 --- a/CRM/Core/xml/Menu/Admin.xml +++ b/CRM/Core/xml/Menu/Admin.xml @@ -763,4 +763,15 @@ CRM_SMS_Page_Callback 1 + + civicrm/admin/badgelayout + Badge Layout + CRM_Badge_Page_Layout + administer CiviCRM,access CiviEvent + + + civicrm/admin/badgelayout/add + CRM_Badge_Form_Layout + administer CiviCRM,access CiviEvent + diff --git a/templates/CRM/Badge/Form/Layout.tpl b/templates/CRM/Badge/Form/Layout.tpl new file mode 100644 index 0000000000..c3734ae4c6 --- /dev/null +++ b/templates/CRM/Badge/Form/Layout.tpl @@ -0,0 +1,66 @@ +{* + +--------------------------------------------------------------------+ + | CiviCRM version 4.3 | + +--------------------------------------------------------------------+ + | Copyright CiviCRM LLC (c) 2004-2013 | + +--------------------------------------------------------------------+ + | 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 | + +--------------------------------------------------------------------+ +*} +{* this template is used for adding/editing badge layouts *} +

{if $action eq 1}{ts}New Badge Layout{/ts}{elseif $action eq 2}{ts}Edit Badge Layout{/ts}{else}{ts}Delete Badge Layout{/ts}{/if}

+
+
{include file="CRM/common/formButtons.tpl" location="top"}
+ {if $action eq 8} +
+
+ {ts}WARNING: Deleting this option will result in the loss of all location type records which use the option.{/ts} {ts}This may mean the loss of a substantial amount of data, and the action cannot be undone.{/ts} {ts}Do you want to continue?{/ts} +
+ {else} + + + + + + + + + + + + + + + + + + + + + + +
{$form.title.label}{$form.title.html}
{$form.description.label}{$form.description.html}
{$form.is_active.label}{$form.is_active.html}
{$form.is_default.label}{$form.is_default.html}
{$form.is_reserved.label}{$form.is_reserved.html}
+ {/if} +
{include file="CRM/common/formButtons.tpl" location="bottom"}
+
diff --git a/templates/CRM/Badge/Page/Layout.tpl b/templates/CRM/Badge/Page/Layout.tpl new file mode 100644 index 0000000000..1c3d2e9a80 --- /dev/null +++ b/templates/CRM/Badge/Page/Layout.tpl @@ -0,0 +1,83 @@ +{* + +--------------------------------------------------------------------+ + | CiviCRM version 4.3 | + +--------------------------------------------------------------------+ + | Copyright CiviCRM LLC (c) 2004-2013 | + +--------------------------------------------------------------------+ + | 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 | + +--------------------------------------------------------------------+ +*} +
+ {ts}Badge Layout.{/ts} +
+ +{if $action eq 1 or $action eq 2 or $action eq 8} + {include file="CRM/Badge/Form/Layout.tpl"} +{else} + + {if $rows} +
+ {strip} + {* handle enable/disable actions*} + {include file="CRM/common/enableDisable.tpl"} + {include file="CRM/common/jsortable.tpl"} + + + + + + + + + + + {foreach from=$rows item=row} + + + + + + + + {/foreach} +
{ts}Title{/ts}{ts}Description{/ts}{ts}Enabled?{/ts}{ts}Default?{/ts}
{$row.title}{$row.description} + {if $row.is_active eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if} + + {if $row.is_default eq 1} + {ts}Default{/ts} + {/if}  + {$row.action|replace:'xx':$row.id}
+ {/strip} + + {if $action ne 1 and $action ne 2} + + {/if} +
+ {else} +
+ {ts}status{/ts} + {capture assign=crmURL}{crmURL p='civicrm/admin/badgelayout' q="action=add&reset=1"}{/capture} + {ts 1=$crmURL}There are no Badge Layout entered for this Contact. You canadd one.{/ts} +
+ {/if} +{/if} -- 2.25.1