CRM-13966 - Tagset fixes for files
authorColeman Watts <coleman@civicrm.org>
Thu, 1 May 2014 01:24:31 +0000 (18:24 -0700)
committerColeman Watts <coleman@civicrm.org>
Thu, 1 May 2014 01:24:31 +0000 (18:24 -0700)
CRM/Core/BAO/File.php
CRM/Core/Form.php
CRM/Core/Form/Tag.php
templates/CRM/Form/attachment.tpl
templates/CRM/common/Tagset.tpl

index 8c515cb5f1f9ca2f3db033ef2936e3d435f971c6..1a66be5954f5894353d8b780b31b964b4fb3728e 100644 (file)
          'maxfilesize',
          $maxFileSize * 1024 * 1024
        );
-       $form->addElement('text', "attachDesc_$i", ts('Description'), 'size=40 maxlength=255');
+       $form->addElement('text', "attachDesc_$i", NULL, array('size' => 40, 'maxlength' => 255, 'placeholder' => ts('Description')));
 
        if (!empty($tags)) {
          $form->add('select', "tag_$i", ts('Tags'), $tags, FALSE,
-           array('id' => "tags_$i", 'multiple' => 'multiple', 'class' => 'crm-select2')
+           array('id' => "tags_$i", 'multiple' => 'multiple', 'class' => 'huge crm-select2', 'placeholder' => ts('- none -'))
          );
        }
+       CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_file', NULL, FALSE, TRUE, "file_taglist_$i");
      }
-
-     // build tagset widget
-     CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_file', NULL, TRUE, TRUE);
    }
 
    /**
        $attachName = "attachFile_$i";
        $attachDesc = "attachDesc_$i";
        $attachTags = "tag_$i";
-       $attachFreeTags = "attachment_taglist_$i";
+       $attachFreeTags = "file_taglist_$i";
        if (isset($formValues[$attachName]) && !empty($formValues[$attachName])) {
          // add static tags if selects
          $tagParams = array();
index baffb9a87cee07c34555400648263136db4435b0..d4c07cec6e65ea85d8466a59dd367e8815ced3bb 100644 (file)
@@ -112,8 +112,6 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    */
   public $urlPath = array();
 
-  protected $unsavedWarn;
-
   /**
    * constants for attributes for various form elements
    * attempt to standardize on the number of variations that we
index cbe2f38b965d6fe884f1389010af99b275e6a384..f7ffb32f57adb7825b987843948f000a18ed1e66 100644 (file)
@@ -62,53 +62,30 @@ class CRM_Core_Form_Tag {
     $form->assign("isTagset", FALSE);
     $mode = NULL;
 
-    foreach ($parentNames as & $parentNameItem) {
+    foreach ($parentNames as &$parentNameItem) {
       // get the parent id for tag list input for keyword
       $parentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $parentNameItem, 'id', 'name');
 
       // check if parent exists
       if ($parentId) {
-        $tagsetItem = 'parentId_' . $parentId;
-        $tagset[$tagsetItem]['skipEntityAction'] = $skipEntityAction;
+        $tagsetItem = $tagsetElementName . 'parentId_' . $parentId;
         $tagset[$tagsetItem]['parentID'] = $parentId;
 
-        // Fixme: these 3 variables may be unused
-        $tagset[$tagsetItem]['parentName'] = $parentNameItem;
-        $tagset[$tagsetItem]['entityTable'] = $entityTable;
-        $tagset[$tagsetItem]['skipTagCreate'] = $skipTagCreate;
-
-        switch ($entityTable) {
-          case 'civicrm_activity':
-            $tagsetElementName = "activity_taglist";
-            $mode = 'activity';
-            break;
-
-          case 'civicrm_case':
-            $tagsetElementName = "case_taglist";
-            $mode = 'case';
-            break;
-
-          case 'civicrm_file':
-            $mode = 'attachment';
-            break;
-
-          default:
-            $tagsetElementName = "contact_taglist";
-            $mode = 'contact';
+        list(, $mode) = explode('_', $entityTable);
+        if (!$tagsetElementName) {
+          $tagsetElementName = $mode . "_taglist";
         }
-
         $tagset[$tagsetItem]['tagsetElementName'] = $tagsetElementName;
-        if ($tagsetElementName) {
-          $form->addEntityRef("{$tagsetElementName}[{$parentId}]", $parentNameItem, array(
-            'entity' => 'tag',
-            'multiple' => TRUE,
-            'create' => !$skipTagCreate,
-            'api' => array('params' => array('parent_id' => $parentId)),
-            'data-entity_table' => $entityTable,
-            'data-entity_id' => $entityId,
-            'class' => "crm-$mode-tagset",
-          ));
-        }
+
+        $form->addEntityRef("{$tagsetElementName}[{$parentId}]", $parentNameItem, array(
+          'entity' => 'tag',
+          'multiple' => TRUE,
+          'create' => !$skipTagCreate,
+          'api' => array('params' => array('parent_id' => $parentId)),
+          'data-entity_table' => $entityTable,
+          'data-entity_id' => $entityId,
+          'class' => "crm-$mode-tagset",
+        ));
 
         if ($entityId) {
           $tagset[$tagsetItem]['entityId'] = $entityId;
@@ -120,6 +97,7 @@ class CRM_Core_Form_Tag {
         else {
           $skipEntityAction = TRUE;
         }
+        $tagset[$tagsetItem]['skipEntityAction'] = $skipEntityAction;
       }
     }
 
@@ -127,8 +105,12 @@ class CRM_Core_Form_Tag {
       // assign current tagsets which is used in postProcess
       $form->_tagsetInfo = $tagset;
       $form->assign("tagsetType", $mode);
+      // Merge this tagset info with possibly existing info in the template
       $tagsetInfo = (array) $form->get_template_vars("tagsetInfo");
-      $tagsetInfo[$mode] = $tagset;
+      if (empty($tagsetInfo[$mode])) {
+        $tagsetInfo[$mode] = array();
+      }
+      $tagsetInfo[$mode] = array_merge($tagsetInfo[$mode], $tagset);
       $form->assign("tagsetInfo", $tagsetInfo);
       $form->assign("isTagset", TRUE);
     }
index 9a5877baa4316ea619fb4badcce267c3f86781e4..b59047b4a5039874bff68ffbf57c6fe771d7efc1 100644 (file)
         </tr>
         {if $form.tag_1.html}
           <tr>
-            <td></td>
-            <td><label>{$form.tag_1.label}</label> <div class="crm-select-container crm-attachment-tags">{$form.tag_1.html}</div></td>
+            <td class="label">{$form.tag_1.label}</td>
+            <td><div class="crm-select-container crm-attachment-tags">{$form.tag_1.html}</div></td>
           </tr>
         {/if}
-        {if $tagsetInfo.attachment}
-          <tr><td></td><td>{include file="CRM/common/Tagset.tpl" tagsetType='attachment' tagsetNumber=1 }</td></tr>
+        {if $tagsetInfo.file}
+          <tr>{include file="CRM/common/Tagset.tpl" tagsetType='file' tableLayout=true tagsetElementName="file_taglist_1"}</tr>
         {/if}
         {section name=attachLoop start=2 loop=$numAttachments+1}
           {assign var=index value=$smarty.section.attachLoop.index}
                 <td>{$form.$attachName.html}&nbsp;{$form.$attachDesc.html}<a href="#" class="crm-hover-button" title="{ts}Clear{/ts}" onclick="clearAttachment( '#{$attachName}' ); return false;"><span class="icon close-icon"></span></a></td>
             </tr>
             <tr>
-              <td></td>
-              <td><label>{$form.$tagElement.label}</label> <div class="crm-select-container crm-attachment-tags">{$form.$tagElement.html}</div></td>
+              <td class="label">{$form.$tagElement.label}</td>
+              <td><div class="crm-select-container crm-attachment-tags">{$form.$tagElement.html}</div></td>
             </tr>
-            {if $tagsetInfo.attachment}
-              <tr><td></td><td>{include file="CRM/common/Tagset.tpl" tagsetType='attachment' tagsetNumber=$index}</td></tr>
+            {if $tagsetInfo.file}
+              <tr>{include file="CRM/common/Tagset.tpl" tagsetType='file' tableLayout=true tagsetElementName="file_taglist_$index"}</tr>
             {/if}
         {/section}
 
index e6f8ecc7949e44e959efda24ddd08e3e37a17f18..6cb324312e1eb9669b14c2825fdb75442f05de7d 100644 (file)
 {/if}
 {foreach from=$tagsetInfo.$tagsetType item=tagset}
   {assign var="elemName" value=$tagset.tagsetElementName}
-  {assign var="parID" value=$tagset.parentID}
-  {assign var="skipEntityAction" value=$tagset.skipEntityAction}
-  {if $tableLayout}
-    <td class="label">
-      {$form.$elemName.$parID.label}
-    </td>
-    <td class="{$tagsetType}-tagset {$tagsetType}-tagset-{$tagset.parentID}-section">
-        {$form.$elemName.$parID.html}
-    </td>
-  {else}
-    <div class="crm-section tag-section {$tagsetType}-tagset {$tagsetType}-tagset-{$tagset.parentID}-section">
-      <div class="crm-clearfix">
+  {if empty($tagsetElementName) or $tagsetElementName eq $elemName}
+    {assign var="parID" value=$tagset.parentID}
+    {assign var="skipEntityAction" value=$tagset.skipEntityAction}
+    {if $tableLayout}
+      <td class="label">
         {$form.$elemName.$parID.label}
-        {$form.$elemName.$parID.html}
+      </td>
+      <td class="{$tagsetType}-tagset {$tagsetType}-tagset-{$tagset.parentID}-section">
+          {$form.$elemName.$parID.html}
+      </td>
+    {else}
+      <div class="crm-section tag-section {$tagsetType}-tagset {$tagsetType}-tagset-{$tagset.parentID}-section">
+        <div class="crm-clearfix">
+          {$form.$elemName.$parID.label}
+          {$form.$elemName.$parID.html}
+        </div>
       </div>
-    </div>
+    {/if}
   {/if}
 {/foreach}