From: Kurund Jalmi Date: Sun, 30 Jun 2013 14:37:16 +0000 (+0530) Subject: CRM-12965, worked on form building and postprocess X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=636f1cbeb0dcad800a25d1c0e6b6f385452c813e;p=civicrm-core.git CRM-12965, worked on form building and postprocess --- diff --git a/CRM/Badge/BAO/Layout.php b/CRM/Badge/BAO/Layout.php index b5357fe7f0..f7c5fc1d7b 100644 --- a/CRM/Badge/BAO/Layout.php +++ b/CRM/Badge/BAO/Layout.php @@ -94,6 +94,20 @@ class CRM_Badge_BAO_Layout extends CRM_Core_DAO_PrintLabel { $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE); $params['is_reserved'] = CRM_Utils_Array::value('is_reserved', $params, FALSE); + $params['label_type_id'] = CRM_Core_OptionGroup::getValue('label_type', 'Event Badge', 'name'); + + // check if new layout is create, if so set the created_id (if not set) + if (empty($params['id'])) { + if (empty($params['created_id'])) { + $session = CRM_Core_Session::singleton(); + $params['created_id'] = $session->get('userID'); + } + } + + if (!isset($params['id']) && !isset($params['name'])) { + $params['name'] = CRM_Utils_String::munge($params['title'], '_', 64); + } + // action is taken depending upon the mode $printLabel = new CRM_Core_DAO_PrintLabel(); $printLabel->copyValues($params); diff --git a/CRM/Badge/Form/Layout.php b/CRM/Badge/Form/Layout.php index 485610e290..12a0282b75 100644 --- a/CRM/Badge/Form/Layout.php +++ b/CRM/Badge/Form/Layout.php @@ -54,30 +54,82 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form { } $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('text', 'title', ts('Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title'), true); + + $labelStyle = CRM_Core_PseudoConstant::get('CRM_Core_DAO_PrintLabel', 'label_format_id'); + $this->add('select', 'label_format_id', ts('Label Style'), array('' => ts('- select -')) + $labelStyle, TRUE); + + $this->add('text', 'description', ts('Description'), + CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'description')); + + // get the tokens + $tokens = CRM_Core_SelectValues::contactTokens(); + asort($tokens); + + $fontSizes = CRM_Core_BAO_LabelFormat::getFontSizes(); + $fontNames = CRM_Core_BAO_LabelFormat::getFontNames('name_badge'); + $textAlignment = CRM_Core_BAO_LabelFormat::getTextAlignments(); + + $rowCount = 3; + for ( $i =1; $i <= $rowCount; $i++ ) { + $this->add('select', "token[$i]", ts('Token'), array('' => ts('- none -')) + $tokens); + $this->add('select', "font_name[$i]", ts('Font Name'), $fontNames); + $this->add('select', "font_size[$i]", ts('Font Size'), $fontSizes); + $this->add('select', "text_alignment[$i]", ts('Alignment'), $textAlignment); + } + $rowCount++; + $this->assign('rowCount', $rowCount); + + $this->add('checkbox', 'add_barcode', ts('Barcode?')); + unset($textAlignment['J']); + $this->add('select', "barcode_alignment", ts('Alignment'), $textAlignment); + $this->add('checkbox', 'is_default', ts('Default?')); + $this->add('checkbox', 'is_active', ts('Enabled?')); + $this->add('checkbox', 'is_reserved', ts('Reserved?')); 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')); + $this->freeze(array('title', 'description', 'is_active')); + } + } + + /** + * This function sets the default values for the form. MobileProvider that in edit/view mode + * the default values are retrieved from the database + * + * @access public + * + * @return None + */ + function setDefaultValues() { + if (isset($this->_id) && empty($this->_values)) { + $this->_values = array(); + $params = array('id' => $this->_id); + CRM_Badge_BAO_Layout::retrieve($params, $this->_values ); + } + + $defaults = $this->_values; + + $data = get_object_vars(json_decode($this->_values['data'])); + + $specialFields = array('token', 'font_name', 'font_size', 'text_alignment'); + foreach($specialFields as $field) { + $defaults[$field] = get_object_vars($data[$field]); } + + $defaults['add_barcode'] = $data['add_barcode']; + $defaults['barcode_alignment'] = $data['barcode_alignment']; + $defaults['label_format_id'] = $data['label_format_id']; + + if ($this->_action == CRM_Core_Action::DELETE && isset($defaults['title'])) { + $this->assign('delName', $defaults['title']); + } + + // its ok if there is no element called is_active + $defaults['is_active'] = ($this->_id) ? CRM_Utils_Array::value('is_active', $defaults) : 1; + + return $defaults; } /** @@ -88,41 +140,26 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form { * @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'); - */ + if ($this->_action & CRM_Core_Action::DELETE) { + CRM_Badge_BAO_Layout::del($this->_id); + CRM_Core_Session::setStatus(ts('Selected badge layout has been deleted.'), ts('Record Deleted'), 'success'); + return; + } + + $params = $data = $this->controller->exportValues($this->_name); + + unset($data['qfKey']); + $params['data'] = json_encode($data); + + if ($this->_id) { + $params['id'] = $this->_id; + } + + // store the submitted values in an array + CRM_Badge_BAO_Layout::create($params); + + CRM_Core_Session::setStatus(ts("The badge layout '%1' has been saved.", + array(1 => $params['title']) + ), ts('Saved'), 'success'); } } diff --git a/CRM/Core/BAO/LabelFormat.php b/CRM/Core/BAO/LabelFormat.php index c1d62ab64d..3b16781c2a 100644 --- a/CRM/Core/BAO/LabelFormat.php +++ b/CRM/Core/BAO/LabelFormat.php @@ -226,6 +226,23 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue { ); } + /** + * Get text alignment recognized by the TCPDF package used to create PDF labels. + * + * @param void + * + * @return array array of alignments + * @access public + * @static + */ + public static function getTextAlignments() { + return array( + 'R' => ts('Right'), + 'L' => ts('Left'), + 'J' => ts('Justify'), + ); + } + /** * Get Option Group ID for Label Formats * diff --git a/templates/CRM/Badge/Form/Layout.tpl b/templates/CRM/Badge/Form/Layout.tpl index c3734ae4c6..34ec4568c5 100644 --- a/templates/CRM/Badge/Form/Layout.tpl +++ b/templates/CRM/Badge/Form/Layout.tpl @@ -30,24 +30,55 @@ {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} + {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} - + + + + + + + + + + + + + + + diff --git a/templates/CRM/Badge/Page/Layout.tpl b/templates/CRM/Badge/Page/Layout.tpl index 1c3d2e9a80..75df9831a2 100644 --- a/templates/CRM/Badge/Page/Layout.tpl +++ b/templates/CRM/Badge/Page/Layout.tpl @@ -24,7 +24,7 @@ +--------------------------------------------------------------------+ *}
- {ts}Badge Layout.{/ts} + {ts}Badge Layout screen for creating custom labels{/ts}
{if $action eq 1 or $action eq 2 or $action eq 8} diff --git a/xml/schema/Core/PrintLabel.xml b/xml/schema/Core/PrintLabel.xml index 6a79f1ab43..c511b690e9 100644 --- a/xml/schema/Core/PrintLabel.xml +++ b/xml/schema/Core/PrintLabel.xml @@ -41,12 +41,18 @@ label_format_id int unsigned - Implicit FK to civicrm_option_value row in label_format option group + + name_badge + + Implicit FK to civicrm_option_value row in name_badge option group 4.4 label_type_id int unsigned + + label_type + Implicit FK to civicrm_option_value row in NEW label_type option group 4.4
{$form.title.label} {$form.title.html}
{$form.label_format_id.label}{$form.label_format_id.html}
{$form.description.label} {$form.description.html}
{ts}Elements{/ts} + + + + + + + + + {section name='i' start=1 loop=$rowCount} + {assign var='rowNumber' value=$smarty.section.i.index} + + + + + + + + {/section} +
{ts}Row{/ts}{ts}Label{/ts}{ts}Font{/ts}{ts}Size{/ts}{ts}Alignment{/ts}
#{$rowNumber}{$form.token.$rowNumber.html|crmAddClass:twenty}{$form.font_name.$rowNumber.html}{$form.font_size.$rowNumber.html}{$form.text_alignment.$rowNumber.html}
+
+ +
{$form.add_barcode.label}{$form.add_barcode.html}   {ts}on{/ts}   {$form.barcode_alignment.html}
{$form.is_active.label} {$form.is_active.html}