CRM-11864 CRM-10693 - Improve multistep forms and menus in popup context
authorColeman Watts <coleman@civicrm.org>
Mon, 2 Dec 2013 22:17:52 +0000 (14:17 -0800)
committerColeman Watts <coleman@civicrm.org>
Mon, 2 Dec 2013 22:17:52 +0000 (14:17 -0800)
CRM/Custom/Form/Field.php
CRM/Custom/Page/Field.php
css/civicrm.css
css/crm.designer.css
js/Common.js
js/view/crm.designer.js
templates/CRM/Custom/Page/Option.tpl

index e4e6a8e13477f814d9a25ce638c15b8f1b7f9df1..b573587d9fccfdacf48309540f44c99fe7825f6e 100644 (file)
@@ -276,6 +276,7 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
     if ($this->_gid) {
       $this->_title = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'title');
       CRM_Utils_System::setTitle($this->_title . ' - ' . ($this->_id ? ts('Edit Field') : ts('Add Field')));
+      $this->assign('gid', $this->_gid);
     }
 
     // lets trim all the whitespace
index cadb99ddce8496bf4a06f31c330b408f5d7e58be..06aa1cbc529a5e0d41a489ed11405c92582f3d1c 100644 (file)
@@ -230,11 +230,22 @@ class CRM_Custom_Page_Field extends CRM_Core_Page {
    */
   function run() {
 
-    // get the group id
-    $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive',
-      $this
+
+    $id = CRM_Utils_Request::retrieve('id', 'Positive',
+      $this, FALSE, 0
     );
 
+    if ($id) {
+      $values = civicrm_api3('custom_field', 'getsingle', array('id' => $id));
+      $this->_gid = $values['custom_group_id'];
+    }
+    // get the group id
+    else {
+      $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive',
+        $this
+      );
+    }
+
     if ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_reserved', 'id')) {
       CRM_Core_Error::fatal("You cannot add or edit fields in a reserved custom field-set.");
     }
@@ -270,10 +281,6 @@ class CRM_Custom_Page_Field extends CRM_Core_Page {
     // assign vars to templates
     $this->assign('action', $action);
 
-    $id = CRM_Utils_Request::retrieve('id', 'Positive',
-      $this, FALSE, 0
-    );
-
     // what action to take ?
     if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
       // no browse for edit/update/view
index 277cf5a81d534c7307921d9c102a934cecde220b..86a0a28ecfc4c812941b048c22c12563c4038f5c 100644 (file)
@@ -1708,6 +1708,25 @@ editor specific classes
   border-left: none;
   /* last action item should not have right hand border */}
 
+
+/* theming for panel and context menus */
+.crm-container td ul.panel li {
+  background-color: #2F2F2E;
+}
+
+.crm-container .panel li a {
+  color: #DFDFDF;
+}
+
+.crm-container .panel li a:hover,
+.crm-container .crm-participant-list-inner li a:hover,
+.crm-container .crm-event-links-list-inner li a:hover,
+.crm-container .crm-contribpage-links-list-inner li a:hover {
+  color: #3e3e3e;
+  background-color: #F5F6F1;
+  text-decoration: none;
+}
+
 .crm-container .panel {
   display: none;
   z-index: 9999;
@@ -3372,24 +3391,6 @@ div.m ul#civicrm-menu,
   background: white url('../i/loading.gif') no-repeat right center;
 }
 
-/* theming for panel and context menus */
-#crm-container td ul.panel li {
-  background-color: #2F2F2E;
-}
-
-#crm-container .panel li a {
-  color: #DFDFDF;
-}
-
-#crm-container .panel li a:hover,
-#crm-container .crm-participant-list-inner li a:hover,
-#crm-container .crm-event-links-list-inner li a:hover,
-#crm-container .crm-contribpage-links-list-inner li a:hover {
-  color: #3e3e3e;
-  background-color: #F5F6F1;
-  text-decoration: none;
-}
-
 /* Special styling for specific form buttons */
 #crm-container span.crm-button_qf_Main_upload input,
 #crm-container span.crm-button_qf_Confirm_next input,
index 3afec0358f93f441b55ad7f96f0696047dc9604e..1b997689c7c224eb07e6297298a02f8fcf8ef496 100644 (file)
   box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
 }
 
-.crm-designer .crm-designer-palette-add button {
+.crm-designer .crm-designer-palette-tree button {
   font-size: .8em;
 }
 
   right: 5px;
   top: 35px;
   font-size: .8em;
+  border: 1px solid #CFCEC3;
 }
 
 button#crm-designer-add-custom-set {
@@ -191,7 +192,7 @@ button#crm-designer-add-custom-set {
 }
 
 .crm-designer-row-label {
-  padding: 0.5em 0px;
+  padding: 0.5em 0;
 }
 
 .crm-designer-label {
@@ -204,7 +205,7 @@ button#crm-designer-add-custom-set {
 }
 
 .crm-designer-dialog .description {
-  margin: 0px 2em 0px 0px;
+  margin: 0 2em 0 0;
 }
 
 .crm-designer-dialog .disabled .description {
index 0db84030dd033793be9b34459cd301191c0e831e..27aa8aab0f98082177203a117189eac2cbab2b42 100644 (file)
@@ -521,7 +521,7 @@ CRM.validate = CRM.validate || {
       }
       target.toggleClass('crm-row-selected', $(this).is(':checked'));
     });
-    $('#crm-container').live('click', function (event) {
+    $('body').live('click', function (event) {
       if ($(event.target).is('.btn-slide')) {
         var currentActive = $('#crm-container .btn-slide-active');
         currentActive.children().hide();
@@ -826,12 +826,36 @@ CRM.validate = CRM.validate || {
       block: true,
       crmForm: null
     },
+    _originalUrl: null,
+    isOriginalUrl: function() {
+      var args = {}, same = true;
+      // Compare path
+      if (this.options.url.split('?')[0] !== this._originalUrl.split('?')[0]) {
+        return false;
+      }
+      // Compare arguments
+      $.each(this.options.url.split('?')[1].split('&'), function(k, v) {
+        var arg = v.split('=');
+        args[arg[0]] = arg[1];
+      });
+      $.each(this._originalUrl.split('?')[1].split('&'), function(k, v) {
+        var arg = v.split('=');
+        if (args[arg[0]] !== undefined && arg[1] !== args[arg[0]]) {
+          same = false;
+        }
+      });
+      return same;
+    },
+    resetUrl: function() {
+      this.options.url = this._originalUrl;
+    },
     _create: function() {
       this.element.addClass('crm-ajax-container');
       if (!this.element.is('.crm-container *')) {
         this.element.addClass('crm-container');
       }
       this.options.url ? this.refresh() : this.options.url = document.location.href;
+      this._originalUrl = this.options.url;
     },
     _onFailure: function(data) {
       this.options.block && this.element.unblock();
@@ -931,26 +955,29 @@ CRM.validate = CRM.validate || {
         var returnVal = settings.onCancel.call($el, event);
         if (returnVal !== false) {
           $el.trigger('crmFormCancel', event);
-          $el.data('dialog') && settings.autoClose && $el.dialog('close');
+          if ($el.data('dialog') && settings.autoClose) {
+            $el.dialog('close');
+          }
+          else if (!settings.autoClose) {
+            $el.crmSnippet('resetUrl').crmSnippet('refresh');
+          }
         }
         return returnVal === false;
       });
-      settings.openInline && $(settings.openInline, this).click(function(event) {
-        $el.crmSnippet('option', 'url', this.href).crmSnippet('refresh');
-        return false;
-      });
       if (settings.validate) {
         $("form", this).validate(typeof(settings.validate) == 'object' ? settings.validate : CRM.validate.params);
       }
       $("form", this).ajaxForm($.extend({
-        url: data.url,
+        url: data.url.replace(/reset=1[&]?/, ''),
         dataType: 'json',
         success: function(response) {
           if (response.status == 'success') {
             $el.crmSnippet('option', 'block') && $el.unblock();
             $el.trigger('crmFormSuccess', response);
             // Reset form for e.g. "save and new"
-            if (settings.refreshAction && $.inArray(response.buttonName, settings.refreshAction) >= 0) {
+            if (response.userContext && (!settings.autoClose ||
+              (settings.refreshAction && $.inArray(response.buttonName, settings.refreshAction) >= 0)))
+            {
               $el.crmSnippet('option', 'url', response.userContext).crmSnippet('refresh');
             }
             else if ($el.data('dialog') && settings.autoClose) {
@@ -966,6 +993,13 @@ CRM.validate = CRM.validate || {
           $el.trigger('crmFormSubmit', submission);
         }
       }, settings.ajaxForm));
+      if (settings.openInline) {
+        settings.autoClose = $el.crmSnippet('isOriginalUrl');
+        $(settings.openInline, this).click(function(event) {
+          $el.crmSnippet('option', 'url', $(this).attr('href')).crmSnippet('refresh');
+          return false;
+        });
+      }
     });
     return widget;
   };
index 1a1c372f60e8a7a55dc318b714325f0aa0b63453..9009f8074cab927fbf86b5be77fefb0d1c5b4dd7 100644 (file)
           }
         });
         if (this.model.get('field_name').split('_')[0] == 'custom') {
-          this.$('.crm-designer-field-summary > div').append('<button class="crm-designer-edit-custom">' + ts('Edit Custom Field') + '</button>');
-          this.$('button.crm-designer-edit-custom').button();
+          this.$('.crm-designer-field-summary > div').append('<button class="crm-designer-edit-custom">&raquo; ' + ts('Edit Custom Field') + '</button>');
+          this.$('button.crm-designer-edit-custom').button().attr('title', ts('Edit global settings for this custom field.'));
         }
       }
     },
     doEditCustomField: function() {
-      CRM.loadForm(CRM.url('civicrm/admin/custom/group/field/update', {
+      var url = CRM.url('civicrm/admin/custom/group/field/update', {
         action: 'update',
         reset: 1,
         id: this.model.get('field_name').split('_')[1]
-      })).on('crmFormLoad', function() {
+      });
+      var form1 = CRM.loadForm(url, {openInline: '.crm-custom-field-form-block-data_type a'})
+        .on('crmFormLoad', function() {
           $(this).prepend('<div class="messages status"><div class="icon inform-icon"></div>' + ts('Note: This will modify the field system-wide, not just in this profile form.') + '</div>');
-        });
+          var $link = $('.action-link a', this);
+          if ($link.length) {
+            $link.detach();
+            var buttons = {};
+            buttons[$link.text()] = function() {
+              var form2 = CRM.loadForm($link.attr('href'), {
+                cancelButton: '.cancel.form-submit, #done',
+                openInline: 'a.action-item:not(".enable-action, .disable-action")',
+                dialog: {
+                  width: '60%',
+                  height: parseInt($(window).height() * .8)
+                }
+              }).on('crmLoad', function() {
+                  $('#done', this).removeAttr('onclick');
+                });
+            }
+            $(this).dialog('option', 'buttons', buttons);
+          }
+        })
       return false;
     },
     onChangeIsDuplicate: function(model, value, options) {
index 57a09723fb25259d50a5c15e41a3d2ef5a04a775..0626703a3307207d616448022cfba67be83fe41d 100644 (file)
@@ -63,7 +63,7 @@
         {/strip}
 
         <div class="action-link">
-            <a href="{crmURL q="reset=1&action=add&fid=$fid&gid=$gid"}" class="button"><span><div class="icon add-icon"></div> {ts 1=$fieldTitle}Add Option for '%1'{/ts}</span></a>
+            <a href="{crmURL q="reset=1&action=add&fid=$fid&gid=$gid"}" class="button action-item"><span><div class="icon add-icon"></div> {ts 1=$fieldTitle}Add Option for '%1'{/ts}</span></a>
         </div>
       </div>
     </div>
@@ -72,7 +72,7 @@
     {if $action eq 16}
         <div class="messages status no-popup">
            <img src="{$config->resourceBase}i/Inform.gif" alt="{ts}status{/ts}"/>
-           {capture assign=crmURL}{crmURL p='civicrm/admin/custom/group/field/option' q="action=add&fid=$fid&gid=$gid"}{/capture}{ts 1=$fieldTitle 2=$crmURL}There are no multiple choice options for the custom field '%1', <a href='%2'>add one</a>.{/ts}
+           {capture assign=crmURL}{crmURL p='civicrm/admin/custom/group/field/option' q="action=add&fid=$fid&gid=$gid"}{/capture}{ts 1=$fieldTitle 2=$crmURL}There are no multiple choice options for the custom field '%1', <a href='%2' class="action-item">add one</a>.{/ts}
         </div>
     {/if}
 {/if}