worked on CRM-12202, reuse existing CRM.confirm(), more code cleanup
authorKurund Jalmi <kurund@civicrm.org>
Thu, 28 Mar 2013 11:52:18 +0000 (17:22 +0530)
committerKurund Jalmi <kurund@civicrm.org>
Thu, 28 Mar 2013 11:52:18 +0000 (17:22 +0530)
templates/CRM/Case/Form/ActivityChangeStatus.js

index 7421776de120ee9d4f868041c0a47ea590e838b4..77e077fadf9139162e720f37e56ef793e7905011 100644 (file)
@@ -10,63 +10,49 @@ cj(function($) {
   });
 
   function changeActivityStatus(activityId, current_status_id, caseId) {
-    var buttons = {};
-    buttons[ts('Ok')] = function() {
-      // update the status
-      var status_id = $("#activity_change_status").val( );
-      if (status_id === current_status_id) {
-        $(this).dialog('close').remove();
-        return false;
-      }
-
-      var dataUrl = CRM.url('civicrm/ajax/rest');
-      var data = 'json=1&version=3&entity=Activity&action=update&id=' + activityId + '&status_id=' + status_id
-        + '&case_id=' + caseId;
-      $.ajax({
-        type     : 'POST',
-        dataType : 'json',
-        url      : dataUrl,
-        data     : data,
-        success  : function(values) {
-          if (values.is_error) {
-            CRM.alert(values.error_message, ts('Unable to change status'), 'error');
-            return false;
-          }
-          else {
-            // just reload the page on success
-            window.location.reload();
-          }
-        },
-        error : function(jqXHR, textStatus) {
-          CRM.alert(jqXHR.responseText, jqXHR.statusText, 'error');
-          return false;
-        }
-      });
-
-      $(this).dialog('close').remove();
-    };
-
-    buttons[ts('Cancel')] = function() {
-      $(this).dialog('close').remove();
-    };
-
-    var data = 'snippet=1&reset=1';
-
     var o = $('<div class="crm-container crm-activity_change_status"></div>');
     addCiviOverlay(o);
 
+    var data = 'snippet=1&reset=1';
     o.load(CRM.url('civicrm/case/changeactivitystatus'), data, function() {
       removeCiviOverlay(o);
       cj("#activity_change_status").val(current_status_id);
-    })
-      .dialog({
-        modal: true,
-        title: ts('Change Activity Status'),
-        resizable: false,
-        buttons: buttons,
-        beforeClose: function() {
-          $(this).dialog("destroy");
+    });
+
+    CRM.confirm(function() {
+        // update the status
+        var status_id = $("#activity_change_status").val( );
+        if (status_id === current_status_id) {
+          return false;
         }
+
+        var dataUrl = CRM.url('civicrm/ajax/rest');
+        var data = 'json=1&version=3&entity=Activity&action=update&id=' + activityId + '&status_id=' + status_id
+          + '&case_id=' + caseId;
+        $.ajax({
+          type     : 'POST',
+          dataType : 'json',
+          url      : dataUrl,
+          data     : data,
+          success  : function(values) {
+            if (values.is_error) {
+              CRM.alert(values.error_message, ts('Unable to change status'), 'error');
+              return false;
+            }
+            else {
+              // just reload the page on success
+              window.location.reload();
+            }
+          },
+          error : function(jqXHR) {
+            CRM.alert(jqXHR.responseText, jqXHR.statusText, 'error');
+            return false;
+          }
+        });
+      }
+      ,{
+        title: ts('Change Activity Status'),
+        message: o
       }
     );
   }