CRM-15932 - Major cleanup of ConfirmRepeatMode
authorColeman Watts <coleman@civicrm.org>
Sun, 1 Mar 2015 22:30:44 +0000 (17:30 -0500)
committerColeman Watts <coleman@civicrm.org>
Mon, 2 Mar 2015 15:55:21 +0000 (10:55 -0500)
CRM/Event/Form/ManageEvent/Repeat.php
css/civicrm.css
templates/CRM/Core/Form/RecurringEntity.tpl
templates/CRM/Event/Form/ManageEvent/ConfirmRepeatMode.tpl

index c5da44b37cd1db6a396fa3e32b67120e07529a8c..8a4bc054800495ac0e793a8eb353a9630852217a 100644 (file)
@@ -84,8 +84,6 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent {
     //Always pass current event's start date by default
     $currentEventStartDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'start_date', 'id');
     list($defaults['repetition_start_date'], $defaults['repetition_start_date_time']) = CRM_Utils_Date::setDateDefaults($currentEventStartDate, 'activityDateTime');
-    $defaults['allowRepeatConfigToSubmit'] = 1;
-    $recurringEntityDefaults = array();
     $recurringEntityDefaults = CRM_Core_Form_RecurringEntity::setDefaultValues();
     $defaults = array_merge($defaults, $recurringEntityDefaults);
     return $defaults;
index 1840e31508aab6c0ba28f1461acfe3b064ad837e..2d1a382ba486d66f32243c33b71b797129a1f663 100644 (file)
@@ -4009,29 +4009,6 @@ span.crm-status-icon {
   background: url("../i/loading-overlay.gif") center center no-repeat white !important;
 }
 
-/* Recurring Dialog */
-.crm-container .recurring-dialog-inner-wrapper {
-  display: inline-block;
-  width: 100%;
-}
-.crm-container .recurring-dialog-inner-left{
-  width: 30%;
-  float: left;
-}
-.crm-container .recurring-dialog-inner-right{
-  width: 70%;
-  float: left;
-}
-.crm-container .recurring-dialog-button{
-  background: #f5f5f5;
-  background-image: -webkit-linear-gradient(top,#f5f5f5,#f1f1f1);
-  border: 1px solid rgba(0,0,0,0.1);
-  padding: 5px 8px;
-  text-align: center;
-  border-radius: 2px;
-  cursor: pointer;
-  font-size: 11px !important;
-}
 .crm-container table.mergecontact thead th {
   width:30%;
 }
index 2e7823d3902e3985be12fa34bda3d88dcdaf4ad1..35cb50eafde1a9280885189d547dc006b9446f00 100644 (file)
@@ -83,9 +83,6 @@
     </div>\r
   </div>\r
 </div>\r
-<div id="preview-dialog" class="hiddenElement">\r
-  <div id="generated_dates" class="show-block"></div>\r
-</div>\r
 {literal}\r
 <script type="text/javascript">\r
   CRM.$(function($) {\r
           });\r
       });\r
 \r
-    //Detect changes in Repeat configuration field\r
-    var unsavedChanges = false;\r
-    $('div.crm-core-form-recurringentity-block').on('change', function() {\r
-      unsavedChanges = true;\r
-    });\r
-\r
     //If there are changes in repeat configuration, enable save button\r
     //Dialog for preview repeat Configuration dates\r
     function previewDialog() {\r
+      $('#allowRepeatConfigToSubmit').val(CRM.utils.initialValueChanged('.crm-core-form-recurringentity-block') ? '1' : '0');\r
       var payload = $form.serialize() + '&entity_table={/literal}{$entityTable}{literal}&entity_id={/literal}{$currentEntityId}{literal}',\r
         settings = CRM.utils.adjustDialogDefaults({\r
           url: CRM.url("civicrm/recurringentity/preview", payload)\r
       e.preventDefault();\r
     });\r
 \r
-    $('#_qf_Activity_upload-top, #_qf_Activity_upload-bottom').click( function () {\r
-      //Process this only when repeat is configured. We need to do this test here as there is a common save for activity.\r
-      var isRepeatConfigured = '{/literal}{$scheduleReminderId}{literal}';\r
-      if (isRepeatConfigured) {\r
-        if (unsavedChanges) {\r
-          $('#allowRepeatConfigToSubmit').val('1');\r
-          //Set this variable to decide which dialog box to show\r
-          $.data( document.body, "preview-dialog", true );\r
-          return previewDialog();\r
-        }\r
-        else {\r
-          $.data( document.body, "preview-dialog", false );\r
-          return false;\r
-        }\r
-      }\r
-      else {\r
-        if (unsavedChanges) {\r
-          $('#allowRepeatConfigToSubmit').val('1');\r
-          return previewDialog();\r
-        }\r
+    $('#_qf_Activity_upload-top, #_qf_Activity_upload-bottom').click( function (e) {\r
+      if (CRM.utils.initialValueChanged('.crm-core-form-recurringentity-block')) {\r
+        e.preventDefault();\r
+        previewDialog();\r
       }\r
     });\r
 \r
index d92c99a48bde59dbc8e95e3315f763505f498188..b20a7e1cc7dcc6a433ae261bd1df6228fd791460 100644 (file)
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |\r
  +--------------------------------------------------------------------+\r
 *}\r
+{if $hasParent || $isRepeatingEntity || $scheduleReminderId}\r
+  <script type="text/template" id="recurring-dialog-tpl">\r
+    <div class="crm-form-block recurring-dialog">\r
+      <h4>{ts}How would you like this change to affect other entities in the repetition set?{/ts}</h4>\r
+      <div class="crm-block">\r
+        <input type="radio" id="recur-only-this-entity" name="recur_mode" value="1">\r
+        <label for="recur-only-this-entity">{ts}Only this entity{/ts}</label>\r
+        <div class="description">{ts}All other entities in the series will remain unchanged.{/ts}</div>\r
 \r
-<div id="recurring-dialog" class="hiddenElement">\r
-    {ts}How would you like this change to affect other entities in the repetition set?{/ts}<br/><br/>\r
-    <div class="show-block">\r
-        <div class="recurring-dialog-inner-wrapper">\r
-            <div class="recurring-dialog-inner-left">\r
-                <button class="recurring-dialog-button only-this-event">{ts}Only this entity{/ts}</button>\r
-            </div>\r
-          <div class="recurring-dialog-inner-right">{ts}All other entities in the series will remain same.{/ts}</div>\r
-        </div>\r
-        <div class="recurring-dialog-inner-wrapper">\r
-            <div class="recurring-dialog-inner-left">\r
-                <button class="recurring-dialog-button this-and-all-following-event">{ts}This and Following entities{/ts}</button>\r
-            </div>\r
-            <div class="recurring-dialog-inner-right">{ts}Change applies to this and all the following entities.{/ts}</div>\r
-        </div>\r
-        <div class="recurring-dialog-inner-wrapper">\r
-            <div class="recurring-dialog-inner-left">\r
-                <button class="recurring-dialog-button all-events">{ts}All the entities{/ts}</button>\r
-            </div>\r
-            <div class="recurring-dialog-inner-right">{ts}Change applies to all the entities in the series.{/ts}</div>\r
-        </div>\r
+        <input type="radio" id="recur-this-and-all-following-entity" name="recur_mode" value="2">\r
+        <label for="recur-this-and-all-following-entity">{ts}This and Following entities{/ts}</label>\r
+        <div class="description">{ts}Change applies to this and all the following entities.{/ts}</div>\r
+\r
+        <input type="radio" id="recur-all-entity" name="recur_mode" value="3">\r
+        <label for="recur-all-entity">{ts}All the entities{/ts}</label>\r
+        <div class="description">{ts}Change applies to all the entities in the series.{/ts}</div>\r
+      </div>\r
+      <div class="status help"><div class="icon ui-icon-lightbulb"></div>{ts}Changes to date or time will NOT be applied to other entities in the series.{/ts}</div>\r
     </div>\r
-    <div class="status"><div class="icon ui-icon-lightbulb"></div> Changes to date or time will NOT be applied to other entities in the series.</div>\r
-</div>\r
-{if $hasParent || $isRepeatingEntity}\r
+  </script>\r
 {literal}\r
   <script type="text/javascript">\r
     CRM.$(function($) {\r
-      var $dialog;\r
-      /** Add your linked entity mapper here **/\r
-      var mapper = {'CRM_Event_Form_ManageEvent_EventInfo': '',\r
-                'CRM_Event_Form_ManageEvent_Location': '',\r
-                'CRM_Event_Form_ManageEvent_Fee': '',\r
-                'CRM_Event_Form_ManageEvent_Registration': '',\r
-                'CRM_Friend_Form_Event': 'civicrm_tell_friend',\r
-                'CRM_PCP_Form_Event': 'civicrm_pcp_block',\r
-                'CRM_Activity_Form_Activity': ''\r
-                };\r
+      var $form, formClass,\r
+        /** Add your linked entity mapper here **/\r
+        mapper = {\r
+          'CRM_Event_Form_ManageEvent_EventInfo': '',\r
+          'CRM_Event_Form_ManageEvent_Location': '',\r
+          'CRM_Event_Form_ManageEvent_Fee': '',\r
+          'CRM_Event_Form_ManageEvent_Registration': '',\r
+          'CRM_Friend_Form_Event': 'civicrm_tell_friend',\r
+          'CRM_PCP_Form_Event': 'civicrm_pcp_block',\r
+          'CRM_Activity_Form_Activity': ''\r
+        };\r
+\r
       function cascadeChangesDialog() {\r
-        $dialog =  $("#recurring-dialog").dialog({\r
-          title: 'How does this change affect other repeating entities in the set?',\r
-          modal: true,\r
-          width: '650',\r
-          buttons: {\r
-            Cancel: function() { //cancel\r
-              $( this ).dialog( "close" );\r
-            }\r
-          }\r
-        }).dialog('open');\r
+        CRM.confirm({\r
+          message: $('#recurring-dialog-tpl').html()\r
+        })\r
+          .on('crmConfirm:yes', updateMode)\r
+          .on('click change', 'input[name=recur_mode]', function() {\r
+            $('button[data-op=yes]').prop('disabled', false);\r
+          })\r
+          .parent().find('button[data-op=yes]').prop('disabled', true)\r
       }\r
-      var form = '';\r
-      $('#crm-main-content-wrapper').on('click', 'div.crm-submit-buttons span.crm-button input[value="Save"], div.crm-submit-buttons span.crm-button input[value="Save and Done"]', function() {\r
-          form = $(this).parents('form:first').attr('class');\r
-          if( form != "" && mapper.hasOwnProperty(form) ){\r
-            cascadeChangesDialog();\r
-            return false;\r
-          }\r
-      });\r
-\r
-      $("#_qf_Activity_upload-top, #_qf_Activity_upload-bottom").click(function() {\r
-          form = $(this).parents('form:first').attr('class');\r
-          if( form != "" && mapper.hasOwnProperty(form) ){\r
-            var showPreviewDialog = $.data( document.body, "preview-dialog");\r
-            if (showPreviewDialog == false) {\r
-              cascadeChangesDialog();\r
-            }\r
-            return false;\r
-          }\r
-      });\r
 \r
-      $(".only-this-event").click(function() {\r
-        updateMode(1);\r
-      });\r
-\r
-      $(".this-and-all-following-event").click(function() {\r
-        updateMode(2);\r
-      });\r
-\r
-      $(".all-events").click(function() {\r
-        updateMode(3);\r
+      $('#crm-main-content-wrapper').on('click', '.crm-form-submit.validate', function(e) {\r
+        $form = $(this).closest('form');\r
+        var className = ($form.attr('class') || '').match(/CRM_\S*/);\r
+        formClass = className && className[0];\r
+        if (formClass && mapper.hasOwnProperty(formClass) &&\r
+            // For activities, only show this if the changes were not made to the recurring settings\r
+          (formClass !== 'CRM_Activity_Form_Activity' || !CRM.utils.initialValueChanged('.crm-core-form-recurringentity-block'))\r
+        ) {\r
+          cascadeChangesDialog();\r
+          e.preventDefault();\r
+        }\r
       });\r
 \r
-      function updateMode(mode) {\r
-        var entityID = parseInt('{/literal}{$entityID}{literal}');\r
-        var entityTable = '{/literal}{$entityTable}{literal}';\r
-        if (entityID != "" && mode && mapper.hasOwnProperty(form) && entityTable !="") {\r
-          var ajaxurl = CRM.url("civicrm/ajax/recurringentity/update-mode");\r
-          var data    = {mode: mode, entityId: entityID, entityTable: entityTable, linkedEntityTable: mapper[form]};\r
-          $.ajax({\r
-            dataType: "json",\r
-            data: data,\r
-            url:  ajaxurl,\r
-            success: function (result) {\r
+      function updateMode() {\r
+        var mode = $('input[name=recur_mode]:checked', this).val(),\r
+          entityID = parseInt('{/literal}{$entityID}{literal}'),\r
+          entityTable = '{/literal}{$entityTable}{literal}';\r
+        if (entityID != "" && mode && mapper.hasOwnProperty(formClass) && entityTable !="") {\r
+          $.getJSON(CRM.url("civicrm/ajax/recurringentity/update-mode",\r
+              {mode: mode, entityId: entityID, entityTable: entityTable, linkedEntityTable: mapper[formClass]})\r
+          ).done(function (result) {\r
               if (result.status != "" && result.status == 'Done') {\r
-                $('#mainTabContainer div:visible Form, form.'+form).submit();\r
-                $dialog.dialog('close');\r
+                $form.submit();\r
               } else if (result.status != "" && result.status == 'Error') {\r
-                var errorBox = confirm(ts("Mode could not be updated, save only this event?"));\r
-                if (errorBox == true) {\r
-                  $('#mainTabContainer div:visible Form, form.'+form).submit();\r
-                  $dialog.dialog('close');\r
-                } else {\r
-                  $dialog.dialog('close');\r
-                  return false;\r
+                if (confirm(ts("Mode could not be updated, save only this event?"))) {\r
+                  $form.submit();\r
                 }\r
               }\r
-            }\r
-          });\r
+            });\r
         }\r
       }\r
     });\r