From a8cd772ce42b6bad6ae3fd88af2e8dd524531ea2 Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Mon, 27 Jun 2016 18:54:58 +0530 Subject: [PATCH] change document type select field to radio button --- CRM/Admin/Form/MessageTemplates.php | 36 +++++++------------ CRM/Upgrade/Incremental/sql/4.7.10.mysql.tpl | 9 +++++ CRM/Upgrade/Incremental/sql/4.7.9.mysql.tpl | 9 ----- templates/CRM/Admin/Form/MessageTemplates.tpl | 22 ++++-------- 4 files changed, 29 insertions(+), 47 deletions(-) diff --git a/CRM/Admin/Form/MessageTemplates.php b/CRM/Admin/Form/MessageTemplates.php index e5bf6c7902..56f9bfd55d 100644 --- a/CRM/Admin/Form/MessageTemplates.php +++ b/CRM/Admin/Form/MessageTemplates.php @@ -39,8 +39,8 @@ class CRM_Admin_Form_MessageTemplates extends CRM_Admin_Form { // which (and whether) mailing workflow this template belongs to protected $_workflow_id = NULL; - // document ID set during loading default values and later used in formRule - protected $_document_id = NULL; + // Is document file is already loaded as default value? + protected $_is_document = FALSE; public function preProcess() { $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); @@ -65,6 +65,9 @@ class CRM_Admin_Form_MessageTemplates extends CRM_Admin_Form { if (empty($defaults['pdf_format_id'])) { $defaults['pdf_format_id'] = 'null'; } + if (empty($defaults['file_type'])) { + $defaults['file_type'] = 0; + } $this->_workflow_id = CRM_Utils_Array::value('workflow_id', $defaults); $this->assign('workflow_id', $this->_workflow_id); @@ -88,11 +91,8 @@ class CRM_Admin_Form_MessageTemplates extends CRM_Admin_Form { $documentInfo = CRM_Core_BAO_File::getEntityFile('civicrm_msg_template', $this->_id, TRUE); if (!empty($documentInfo)) { - foreach ($documentInfo as &$info) { - $defaults['file_type'] = array_search($info['mime_type'], CRM_Core_SelectValues::documentApplicationType()); - $info['mime_type'] = $defaults['file_type']; - $this->_document_id = $info['fileID']; - } + $defaults['file_type'] = 1; + $this->_is_document = TRUE; $this->assign('attachment', $documentInfo); } @@ -169,7 +169,9 @@ class CRM_Admin_Form_MessageTemplates extends CRM_Admin_Form { $this->applyFilter('__ALL__', 'trim'); $this->add('text', 'msg_title', ts('Message Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_MessageTemplate', 'msg_title'), TRUE); - $this->add('select', 'file_type', ts('File Type'), CRM_Core_SelectValues::documentFormat()); + $options = array(ts('Compose On-screen'), ts('Upload Document')); + $this->addRadio('file_type', ts('Source'), $options); + $this->addElement('file', "file_id", ts('Upload Document'), 'size=30 maxlength=60'); $this->addUploadElement("file_id"); @@ -241,21 +243,9 @@ class CRM_Admin_Form_MessageTemplates extends CRM_Admin_Form { $errors = array(); //empty file upload validation for odt/docx template - if (empty($files['file_id']['tmp_name']) && in_array($params['file_type'], array('odt', 'docx'))) { + if (empty($files['file_id']['tmp_name']) && !empty($params['file_type']) && !$self->_is_document) { //On edit page of docx/odt message template if user changes file type but forgot to upload document - if (!empty($self->_document_id)) { - $fileDAO = new CRM_Core_DAO_File(); - $fileDAO->id = $self->_document_id; - if ($fileDAO->find(TRUE) && - $fileDAO->mime_type != CRM_Utils_Array::value($params['file_type'], CRM_Core_SelectValues::documentApplicationType()) - ) { - $errors['file_id'] = ts('Please upload document'); - } - } - else { - $errors['file_id'] = ts('Please upload document'); - } - + $errors['file_id'] = ts('Please upload document'); } return $errors; @@ -282,7 +272,7 @@ class CRM_Admin_Form_MessageTemplates extends CRM_Admin_Form { $params['id'] = $this->_id; } - if (in_array($params['file_type'], array('odt', 'docx'))) { + if (!empty($params['file_type'])) { unset($params['msg_html']); unset($params['msg_text']); CRM_Utils_File::formatFile($params, 'file_id'); diff --git a/CRM/Upgrade/Incremental/sql/4.7.10.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.7.10.mysql.tpl index a1101ff8a7..d71c82d081 100644 --- a/CRM/Upgrade/Incremental/sql/4.7.10.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.7.10.mysql.tpl @@ -12,3 +12,12 @@ ALTER TABLE civicrm_pledge_block ADD pledge_start_date varchar(64) NULL DEFAULT ALTER TABLE civicrm_pledge_block ADD is_pledge_start_date_visible TINYINT(4) NOT NULL DEFAULT 0 COMMENT 'If true - recurring start date is shown.'; ALTER TABLE civicrm_pledge_block ADD is_pledge_start_date_editable TINYINT(4) NOT NULL DEFAULT 0 COMMENT 'If true - recurring start date is editable.'; ALTER TABLE civicrm_contribution_page ADD adjust_recur_start_date TINYINT(4) NOT NULL DEFAULT 0 COMMENT 'If true - user is able to adjust payment start date.' AFTER is_recur_installments; + +-- CRM-17608 Merge to DOCx or ODT template +SELECT @option_group_id_ext := max(id) from civicrm_option_group where name = 'safe_file_extension'; +SELECT @option_group_id_ext_wt := MAX(weight) FROM civicrm_option_value WHERE option_group_id = @option_group_id_ext; +SELECT @option_group_id_ext_val := MAX(CAST( `value` AS UNSIGNED )) FROM civicrm_option_value WHERE option_group_id = @option_group_id_ext; +INSERT INTO + `civicrm_option_value` (`option_group_id`, {localize field='label'}label{/localize}, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `is_optgroup`, `is_reserved`, `is_active`) +VALUES + (@option_group_id_ext, {localize}'{ts escape="sql"}odt{/ts}'{/localize}, @option_group_id_ext_val+1, 'odt', NULL, 0, 0, @option_group_id_ext_wt+1, 0, 1, 1); diff --git a/CRM/Upgrade/Incremental/sql/4.7.9.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.7.9.mysql.tpl index c2e5cfd4d0..3be47b33cb 100644 --- a/CRM/Upgrade/Incremental/sql/4.7.9.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.7.9.mysql.tpl @@ -7,15 +7,6 @@ UPDATE civicrm_option_value SET {localize field="description"}description = '{ts escape="sql"}Export letters and other printable documents.{/ts}'{/localize} WHERE name = 'Print PDF Letter' AND option_group_id = @option_group_id_act; --- CRM-17608 Merge to DOCx or ODT template -SELECT @option_group_id_ext := max(id) from civicrm_option_group where name = 'safe_file_extension'; -SELECT @option_group_id_ext_wt := MAX(weight) FROM civicrm_option_value WHERE option_group_id = @option_group_id_ext; -SELECT @option_group_id_ext_val := MAX(CAST( `value` AS UNSIGNED )) FROM civicrm_option_value WHERE option_group_id = @option_group_id_ext; -INSERT INTO - `civicrm_option_value` (`option_group_id`, {localize field='label'}label{/localize}, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `is_optgroup`, `is_reserved`, `is_active`) -VALUES -(@option_group_id_ext, {localize}'{ts escape="sql"}odt{/ts}'{/localize}, @option_group_id_ext_val+1, 'odt', NULL, 0, 0, @option_group_id_ext_wt+1, 0, 1, 1); - -- CRM-18699 Fix Wake Island misspelling, was Wake Ialand UPDATE civicrm_state_province SET name="Wake Island" WHERE name="Wake Ialand"; diff --git a/templates/CRM/Admin/Form/MessageTemplates.tpl b/templates/CRM/Admin/Form/MessageTemplates.tpl index ecd834f9c7..ce3d019c56 100644 --- a/templates/CRM/Admin/Form/MessageTemplates.tpl +++ b/templates/CRM/Admin/Form/MessageTemplates.tpl @@ -158,29 +158,21 @@ mimeType = $('a.delete-attachment').data('mimetype'); } - $('#file_type').on('change', function(){ - toggleByFileType(this.value); + showHideUpload($("input[id$='_file_type']:checked").val()); + $("input[id$='_file_type']").on('click', function(){ + showHideUpload(this.value); }); - toggleByFileType($('#file_type').val()); - - function toggleByFileType(type) { - var show = (type == 'odt' || type == 'docx') ? false : true; + function showHideUpload(type) { + var show = (type == 1) ? false : true; $("#msg_html").toggle(show); $("#msg_text, #pdf_format").toggle(show); $("#file_id").parent().parent().toggle(!show); // auto file type validation - if (!show) { - var validType = (type == 'odt') ? 'application/vnd.oasis.opendocument.text' : 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; + if (type) { + var validType = 'application/vnd.oasis.opendocument.text, application/vnd.openxmlformats-officedocument.wordprocessingml.document'; $("#file_id").attr('accept', validType); } - - // when you change file type other than the type of default uploaded document - if (mimeType) { - var hide = (mimeType != type) ? true : false; - $("#file_id").toggle(hide); - $('.crm-attachment-wrapper').toggle(!hide); - } } }); -- 2.25.1