change document type select field to radio button
authordeb.monish <monish.deb@webaccessglobal.com>
Mon, 27 Jun 2016 13:24:58 +0000 (18:54 +0530)
committerdeb.monish <monish.deb@webaccessglobal.com>
Thu, 14 Jul 2016 18:05:43 +0000 (23:35 +0530)
CRM/Admin/Form/MessageTemplates.php
CRM/Upgrade/Incremental/sql/4.7.10.mysql.tpl
CRM/Upgrade/Incremental/sql/4.7.9.mysql.tpl
templates/CRM/Admin/Form/MessageTemplates.tpl

index e5bf6c79029cb5c4c59b000b03bd815c31c14ed3..56f9bfd55de20f58afc12f54e2921a49dd5deeaa 100644 (file)
@@ -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');
index a1101ff8a7da541b6e69a638eaa10ff5f6435926..d71c82d0813e234d3a5f8cb486e92c82bf25256c 100644 (file)
@@ -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);
index c2e5cfd4d085e4e0631cc06fc76be162acdce06c..3be47b33cb8cb7c58a1467b34defa973c08fc571 100644 (file)
@@ -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";
 
index ecd834f9c7be1b793ebac6cd83946a4789690485..ce3d019c563bb81145dc373f7a843754db6bb728 100644 (file)
         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);
-        }
       }
     });
   </script>