From 2a815fc7247b4fb84ea9ece794dd070ad3098dc7 Mon Sep 17 00:00:00 2001 From: Kurund Jalmi Date: Wed, 27 Mar 2013 16:46:30 +0530 Subject: [PATCH] worked on CRM-12202, js code cleanup, move js call from php to js file --- CRM/Case/BAO/Case.php | 2 +- .../CRM/Case/Form/ActivityChangeStatus.js | 109 ++++++++++-------- 2 files changed, 62 insertions(+), 49 deletions(-) diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 3ccbff8aa2..181c013dde 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -1287,7 +1287,7 @@ SELECT case_status.label AS case_status, status_id, case_type.label AS case_type } if ($allowEdit) { - $values[$dao->id]['status'] = '' . $values[$dao->id]['status'] . ''; + $values[$dao->id]['status'] = '' . $values[$dao->id]['status'] . ''; } } $dao->free(); diff --git a/templates/CRM/Case/Form/ActivityChangeStatus.js b/templates/CRM/Case/Form/ActivityChangeStatus.js index 2c2dce7230..3273b4905b 100644 --- a/templates/CRM/Case/Form/ActivityChangeStatus.js +++ b/templates/CRM/Case/Form/ActivityChangeStatus.js @@ -1,59 +1,72 @@ // http://civicrm.org/licensing -function changeActivityStatus(activityId, contactId, current_status_id, caseId) { - var data = 'snippet=1&reset=1'; - cj('
') - .load(CRM.url('civicrm/case/changeactivitystatus'), data, function() { - cj("#activity_change_status").val(current_status_id); - }) - .dialog({ - modal: true, - title: ts('Change Activity Status'), - buttons: { - "Ok" : function() { - // update the status - var status_id = cj("#activity_change_status").val( ); +cj(function($) { + $('.crm-container').on('click', 'a.crm-activity-change-status', function() { + changeActivityStatus( + $(this).attr('activity_id'), + $(this).attr('contact_id'), + $(this).attr('current_status'), + $(this).attr('case_id') + ); + return false; + }); - if (status_id === current_status_id) { - return false; - } + function changeActivityStatus(activityId, contactId, current_status_id, caseId) { + var data = 'snippet=1&reset=1'; + $('
') + .load(CRM.url('civicrm/case/changeactivitystatus'), data, function() { + cj("#activity_change_status").val(current_status_id); + }) + .dialog({ + modal: true, + title: ts('Change Activity Status'), + buttons: { + "Ok" : function() { + // update the status + var status_id = $("#activity_change_status").val( ); - 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; - cj.ajax({ - type : "POST", - dataType : "json", - url : dataUrl, - data : data, - success : function( values ) { - if ( values.is_error ) { - // seems to be some discrepancy as to which spelling it should be - var err_msg = values.error_msg ? values.error_msg : values.error_message; - CRM.alert(err_msg, 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'); + if (status_id === current_status_id) { + $(this).dialog('close').remove(); return false; } - }); - cj(this).dialog('close').remove(); + 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 ) { + // seems to be some discrepancy as to which spelling it should be + var err_msg = values.error_msg ? values.error_msg : values.error_message; + CRM.alert(err_msg, 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(); + }, + "Cancel": function() { + $(this).dialog('close').remove(); + } }, - "Cancel": function() { - cj(this).dialog('close').remove(); + beforeClose: function() { + $(this).dialog("destroy"); } - }, - beforeClose: function() { - cj(this).dialog("destroy"); } - } - ); -} + ); + } +}); -- 2.25.1