From a6cb612d2098b45be8f909c3c1d930b6bbb8ebb4 Mon Sep 17 00:00:00 2001 From: Francis Whittle Date: Wed, 1 Nov 2023 16:55:47 +1100 Subject: [PATCH] CIVIBLD-325 Refactor angular modules to use settingsFactory instead of settings Also avoids some potential function name clashes --- CRM/Civicase/Angular.php | 243 ++++++++++++++++++++++++++++++++++ CRM/Civicase/BaseAngular.php | 248 +++++++++++++++++++++++++++++++++++ ang/civicase-base.ang.php | 221 +------------------------------ ang/civicase.ang.php | 232 +------------------------------- ang/uibTabsetClass.ang.php | 13 +- 5 files changed, 501 insertions(+), 456 deletions(-) create mode 100644 CRM/Civicase/Angular.php create mode 100644 CRM/Civicase/BaseAngular.php diff --git a/CRM/Civicase/Angular.php b/CRM/Civicase/Angular.php new file mode 100644 index 000000000..990f5d7be --- /dev/null +++ b/CRM/Civicase/Angular.php @@ -0,0 +1,243 @@ +get($caseCategoryName); + + // The following changes are only relevant to the full-page app. + if (CRM_Utils_System::currentPath() == 'civicrm/case/a') { + self::adds_shoreditch_css(); + \CRM_Civicase_Helper_CaseCategory::updateBreadcrumbs($caseCategoryId); + } + + self::set_case_actions(); + self::set_contact_tasks(); + + return self::$options; + } + + /** + * Loads Resources. + */ + public static function load_resources() { + Civi::resources() + ->addPermissions([ + 'administer CiviCase', + 'administer CiviCRM', + 'access all cases and activities', + 'add cases', + 'basic case information', + 'access CiviCRM', + 'access my cases and activities', + ]) + ->addScriptFile('org.civicrm.shoreditch', 'base/js/affix.js', 1000, 'html-header') + ->addSetting([ + 'config' => [ + 'enableComponents' => CRM_Core_Config::singleton()->enableComponents, + 'user_contact_id' => (int) CRM_Core_Session::getLoggedInContactID(), + ], + ]); + } + + /** + * Add shoreditch custom css if not already present. + */ + public static function adds_shoreditch_css() { + if (!civicrm_api3('Setting', 'getvalue', ['name' => "customCSSURL"])) { + Civi::resources() + ->addStyleFile('org.civicrm.shoreditch', 'css/custom-civicrm.css', 99, 'html-header'); + } + } + + /** + * Get a list of JS files. + */ + public static function get_js_files() { + return array_merge( + [ + // At the moment, it's safe to include this multiple times. + // deduped by resource manager. + 'assetBuilder://visual-bundle.js', + 'ang/civicase.js', + ], + CRM_Civicase_Helper_GlobRecursive::getRelativeToExtension( + 'uk.co.compucorp.civicase', + 'ang/civicase/*.js' + ) + ); + } + + /** + * Bulk actions for case list. + * + * We put this here so it can be modified by other extensions. + */ + public static function set_case_actions() { + self::$options['caseActions'] = [ + [ + 'title' => ts('Change Case Status'), + 'action' => 'ChangeStatus', + 'icon' => 'fa-pencil-square-o', + 'is_write_action' => TRUE, + ], + [ + 'title' => ts('Edit Tags'), + 'action' => 'EditTags', + 'icon' => 'fa-tags', + 'number' => 1, + 'is_write_action' => TRUE, + ], + [ + 'title' => ts('Print Case'), + 'action' => 'Print', + 'number' => 1, + 'icon' => 'fa-print', + 'is_write_action' => FALSE, + ], + [ + 'title' => ts('Email - send now'), + 'action' => 'Email', + 'icon' => 'fa-envelope-o', + 'is_write_action' => TRUE, + ], + [ + 'title' => ts('Print/Merge Document'), + 'action' => 'PrintMerge', + 'icon' => 'fa-file-pdf-o', + 'is_write_action' => TRUE, + ], + [ + 'title' => ts('Link Cases'), + 'action' => 'LinkCases', + 'number' => 1, + 'icon' => 'fa-link', + 'is_write_action' => TRUE, + ], + [ + 'title' => ts('Link 2 Cases'), + 'action' => 'LinkCases', + 'number' => 2, + 'icon' => 'fa-link', + 'is_write_action' => TRUE, + ], + ]; + if (CRM_Core_Permission::check('administer CiviCase')) { + self::$options['caseActions'][] = [ + 'title' => ts('Merge 2 Cases'), + 'number' => 2, + 'action' => 'MergeCases', + 'icon' => 'fa-compress', + 'is_write_action' => TRUE, + ]; + self::$options['caseActions'][] = [ + 'title' => ts('Lock Case'), + 'action' => 'LockCases', + 'number' => 1, + 'icon' => 'fa-lock', + 'is_write_action' => TRUE, + ]; + } + if (CRM_Core_Permission::check(self::$case_category_permissions['DELETE_IN_CASE_CATEGORY']['name'])) { + self::$options['caseActions'][] = [ + 'title' => ts('Delete Case'), + 'action' => 'DeleteCases', + 'icon' => 'fa-trash', + 'is_write_action' => TRUE, + ]; + } + if (CRM_Core_Permission::check(CRM_Civicase_Hook_Permissions_ExportCasesAndReports::PERMISSION_NAME)) { + self::$options['caseActions'][] = [ + 'title' => ts('Export Cases'), + 'action' => 'ExportCases', + 'icon' => 'fa-file-excel-o', + 'is_write_action' => FALSE, + ]; + } + + self::add_webforms_case_action(); + } + + /** + * Add webforms with cases attached to menu. + */ + public static function add_webforms_case_action() { + $items = []; + + $webformsToDisplay = Civi::settings()->get('civi_drupal_webforms'); + if (isset($webformsToDisplay)) { + $allowedWebforms = []; + foreach ($webformsToDisplay as $webformNode) { + $allowedWebforms[] = $webformNode['nid']; + } + $webforms = civicrm_api3('Case', 'getwebforms'); + if (isset($webforms['values'])) { + foreach ($webforms['values'] as $webform) { + if (!in_array($webform['nid'], $allowedWebforms)) { + continue; + } + + $items[] = [ + 'title' => $webform['title'], + 'action' => 'GoToWebform', + 'path' => $webform['path'], + 'case_type_ids' => $webform['case_type_ids'], + 'clientID' => NULL, + 'is_write_action' => FALSE, + ]; + } + self::$options['caseActions'][] = [ + 'title' => ts('Forms'), + 'action' => 'Forms', + 'icon' => 'fa-file-text-o', + 'items' => $items, + 'is_write_action' => FALSE, + ]; + } + } + } + + /** + * Sets contact tasks. + */ + public static function set_contact_tasks() { + $contactTasks = CRM_Contact_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission()); + self::$options['contactTasks'] = []; + foreach (CRM_Contact_Task::$_tasks as $id => $value) { + if (isset($contactTasks[$id]) && isset($value['url'])) { + self::$options['contactTasks'][$id] = $value; + } + } + } + +} diff --git a/CRM/Civicase/BaseAngular.php b/CRM/Civicase/BaseAngular.php new file mode 100644 index 000000000..75379bb72 --- /dev/null +++ b/CRM/Civicase/BaseAngular.php @@ -0,0 +1,248 @@ + 'activity_type', + 'activityStatuses' => 'activity_status', + 'caseStatuses' => 'case_status', + 'priority' => 'priority', + 'activityCategories' => 'activity_category', + 'caseCategoryInstanceType' => 'case_category_instance_type', + ]; + + CRM_Civicase_Helper_OptionValues::setToJsVariables(self::$options); + CRM_Civicase_Helper_NewCaseWebform::addWebformDataToOptions(self::$options, $caseCategorySetting); + self::set_case_types_to_js_vars(); + self::set_case_category_instance_to_js_vars(); + self::set_relationship_types_to_js_vars(); + self::set_file_categories_to_js_vars(); + self::set_activity_status_types_to_js_vars(); + self::set_custom_fields_info_to_js_vars(); + self::set_tags_to_js_vars(); + self::add_case_type_categories_to_options(); + self::expose_settings([ + 'caseCategoryId' => $caseCategoryId, + ]); + + return self::$options; + } + + /** + * Adds the case type categories and their labels to the given options. + * + * List of options to pass to the front-end. + */ + public static function add_case_type_categories_to_options() { + $caseCategoryCustomFields = new CRM_Civicase_Service_CaseCategoryCustomFieldsSetting(); + $caseCategories = civicrm_api3('OptionValue', 'get', [ + 'is_sequential' => '1', + 'option_group_id' => 'case_type_categories', + 'options' => ['limit' => 0], + ]); + + foreach ($caseCategories['values'] as &$caseCategory) { + $caseCategory['custom_fields'] = $caseCategoryCustomFields->get( + $caseCategory['value'] + ); + } + + self::$options['caseTypeCategories'] = array_column($caseCategories['values'], NULL, 'value'); + } + + /** + * Sets the tags and tagsets to javascript global variable. + */ + public static function set_case_category_instance_to_js_vars() { + $result = civicrm_api3('CaseCategoryInstance', 'get', [ + 'options' => ['limit' => 0], + ])['values']; + self::$options['caseCategoryInstanceMapping'] = $result; + } + + /** + * Expose settings. + * + * The default case category is taken from URL first, + * or uses `case` as the default. + * + * The options that will store the exposed settings. + * + * @param array $defaults + * Default values to use when exposing settings. + */ + public static function expose_settings(array $defaults) { + self::$options['allowMultipleCaseClients'] = (bool) Civi::settings() + ->get('civicaseAllowMultipleClients'); + self::$options['showComingSoonCaseSummaryBlock'] = (bool) Civi::settings() + ->get('civicaseShowComingSoonCaseSummaryBlock'); + self::$options['allowCaseLocks'] = (bool) Civi::settings() + ->get('civicaseAllowCaseLocks'); + self::$options['allowLinkedCasesTab'] = (bool) Civi::settings() + ->get('civicaseAllowLinkedCasesTab'); + self::$options['showWebformsListSeparately'] = (bool) Civi::settings() + ->get('civicaseShowWebformsListSeparately'); + self::$options['webformsDropdownButtonLabel'] = Civi::settings() + ->get('civicaseWebformsDropdownButtonLabel'); + self::$options['showFullContactNameOnActivityFeed'] = (bool) Civi::settings() + ->get('showFullContactNameOnActivityFeed'); + self::$options['includeActivitiesForInvolvedContact'] = (bool) Civi::settings() + ->get('includeActivitiesForInvolvedContact'); + self::$options['civicaseSingleCaseRolePerType'] = (bool) Civi::settings() + ->get('civicaseSingleCaseRolePerType'); + self::$options['caseTypeCategoriesWhereUserCanAccessActivities'] = + CRM_Civicase_Helper_CaseCategory::getWhereUserCanAccessActivities(); + self::$options['currentCaseCategory'] = $defaults['caseCategoryId'] ?: NULL; + } + + /** + * Sets the case types to javascript global variable. + */ + public static function set_case_types_to_js_vars() { + $caseTypes = civicrm_api3('CaseType', 'get', [ + 'return' => [ + 'id', + 'name', + 'title', + 'description', + 'definition', + 'case_type_category', + 'is_active', + ], + 'options' => ['limit' => 0, 'sort' => 'weight'], + ]); + foreach ($caseTypes['values'] as &$item) { + CRM_Utils_Array::remove($item, 'is_forkable', 'is_forked'); + } + self::$options['caseTypes'] = $caseTypes['values']; + } + + /** + * Sets the relationship types to javascript global variable. + */ + public static function set_relationship_types_to_js_vars() { + $result = civicrm_api3('RelationshipType', 'get', [ + 'options' => ['limit' => 0], + ]); + self::$options['relationshipTypes'] = $result['values']; + } + + /** + * Sets the tags and tagsets to javascript global variable. + */ + public static function set_tags_to_js_vars() { + self::$options['tags'] = CRM_Core_BAO_Tag::getColorTags('civicrm_case'); + self::$options['tagsets'] = CRM_Utils_Array::value('values', civicrm_api3('Tag', 'get', [ + 'sequential' => 1, + 'return' => ["id", "name"], + 'used_for' => ['LIKE' => "%civicrm_case%"], + 'is_tagset' => 1, + ])); + } + + /** + * Sets the file categories to javascript global variable. + */ + public static function set_file_categories_to_js_vars() { + self::$options['fileCategories'] = CRM_Civicase_FileCategory::getCategories(); + } + + /** + * Sets the activity status types to javascript global variable. + */ + public static function set_activity_status_types_to_js_vars() { + self::$options['activityStatusTypes'] = [ + 'incomplete' => array_keys(CRM_Activity_BAO_Activity::getStatusesByType(CRM_Activity_BAO_Activity::INCOMPLETE)), + 'completed' => array_keys(CRM_Activity_BAO_Activity::getStatusesByType(CRM_Activity_BAO_Activity::COMPLETED)), + 'cancelled' => array_keys(CRM_Activity_BAO_Activity::getStatusesByType(CRM_Activity_BAO_Activity::CANCELLED)), + ]; + } + + /** + * Sets the custom fields information to javascript global variable. + */ + public static function set_custom_fields_info_to_js_vars() { + $result = civicrm_api3('CustomGroup', 'get', [ + 'sequential' => 1, + 'return' => [ + 'extends_entity_column_value', + 'title', + 'extends', + ], + 'extends' => ['IN' => ['Case', 'Activity']], + 'is_active' => 1, + 'options' => ['sort' => 'weight'], + 'api.CustomField.get' => [ + 'is_active' => 1, + 'is_searchable' => 1, + 'return' => [ + 'label', + 'html_type', + 'data_type', + 'is_search_range', + 'filter', + 'option_group_id', + ], + 'options' => ['sort' => 'weight'], + ], + ]); + self::$options['customSearchFields'] = self::$options['customActivityFields'] = []; + foreach ($result['values'] as $group) { + if (!empty($group['api.CustomField.get']['values'])) { + if ($group['extends'] == 'Case') { + if (!empty($group['extends_entity_column_value'])) { + $group['caseTypes'] = CRM_Utils_Array::collect('name', array_values(array_intersect_key(self::$options['caseTypes'], array_flip($group['extends_entity_column_value'])))); + } + foreach ($group['api.CustomField.get']['values'] as $field) { + $group['fields'][] = Utils::formatCustomSearchField($field); + } + unset($group['api.CustomField.get']); + self::$options['customSearchFields'][] = $group; + } + else { + foreach ($group['api.CustomField.get']['values'] as $field) { + self::$options['customActivityFields'][] = Utils::formatCustomSearchField($field) + ['group' => $group['title']]; + } + } + } + } + } + + /** + * Get a list of JS files. + * + * @return array + * list of js files + */ + public static function get_js_files() { + return array_merge( + [ + 'assetBuilder://visual-bundle.js', + 'ang/civicase-base.js', + ], + CRM_Civicase_Helper_GlobRecursive::getRelativeToExtension( + 'uk.co.compucorp.civicase', + 'ang/civicase-base/*.js' + ) + ); + } + +} diff --git a/ang/civicase-base.ang.php b/ang/civicase-base.ang.php index 6c9873f0a..4269deede 100644 --- a/ang/civicase-base.ang.php +++ b/ang/civicase-base.ang.php @@ -8,226 +8,9 @@ * http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_angularModules. */ -use Civi\CCase\Utils as Utils; -use CRM_Civicase_Helper_OptionValues as OptionValuesHelper; -use CRM_Civicase_Helper_GlobRecursive as GlobRecursive; -use CRM_Civicase_Helper_NewCaseWebform as NewCaseWebform; -use CRM_Civicase_Service_CaseCategoryCustomFieldsSetting as CaseCategoryCustomFieldsSetting; -use CRM_Civicase_Helper_CaseUrl as CaseUrlHelper; - -[$caseCategoryId, $caseCategoryName] = CaseUrlHelper::getCategoryParamsFromUrl(); - -$caseCategorySetting = new CRM_Civicase_Service_CaseCategorySetting(); - -$options = [ - 'activityTypes' => 'activity_type', - 'activityStatuses' => 'activity_status', - 'caseStatuses' => 'case_status', - 'priority' => 'priority', - 'activityCategories' => 'activity_category', - 'caseCategoryInstanceType' => 'case_category_instance_type', -]; - -OptionValuesHelper::setToJsVariables($options); -NewCaseWebform::addWebformDataToOptions($options, $caseCategorySetting); -set_case_types_to_js_vars($options); -set_case_category_instance_to_js_vars($options); -set_relationship_types_to_js_vars($options); -set_file_categories_to_js_vars($options); -set_activity_status_types_to_js_vars($options); -set_custom_fields_info_to_js_vars($options); -set_tags_to_js_vars($options); -add_case_type_categories_to_options($options); -expose_settings($options, [ - 'caseCategoryId' => $caseCategoryId, -]); - -/** - * Adds the case type categories and their labels to the given options. - * - * @param array $options - * List of options to pass to the front-end. - */ -function add_case_type_categories_to_options(array &$options) { - $caseCategoryCustomFields = new CaseCategoryCustomFieldsSetting(); - $caseCategories = civicrm_api3('OptionValue', 'get', [ - 'is_sequential' => '1', - 'option_group_id' => 'case_type_categories', - 'options' => ['limit' => 0], - ]); - - foreach ($caseCategories['values'] as &$caseCategory) { - $caseCategory['custom_fields'] = $caseCategoryCustomFields->get( - $caseCategory['value'] - ); - } - - $options['caseTypeCategories'] = array_column($caseCategories['values'], NULL, 'value'); -} - -/** - * Sets the tags and tagsets to javascript global variable. - */ -function set_case_category_instance_to_js_vars(&$options) { - $result = civicrm_api3('CaseCategoryInstance', 'get', [ - 'options' => ['limit' => 0], - ])['values']; - $options['caseCategoryInstanceMapping'] = $result; -} - -/** - * Expose settings. - * - * The default case category is taken from URL first, - * or uses `case` as the default. - * - * @param array $options - * The options that will store the exposed settings. - * @param array $defaults - * Default values to use when exposing settings. - */ -function expose_settings(array &$options, array $defaults) { - $options['allowMultipleCaseClients'] = (bool) Civi::settings()->get('civicaseAllowMultipleClients'); - $options['showComingSoonCaseSummaryBlock'] = (bool) Civi::settings()->get('civicaseShowComingSoonCaseSummaryBlock'); - $options['allowCaseLocks'] = (bool) Civi::settings()->get('civicaseAllowCaseLocks'); - $options['allowLinkedCasesTab'] = (bool) Civi::settings()->get('civicaseAllowLinkedCasesTab'); - $options['showWebformsListSeparately'] = (bool) Civi::settings()->get('civicaseShowWebformsListSeparately'); - $options['webformsDropdownButtonLabel'] = Civi::settings()->get('civicaseWebformsDropdownButtonLabel'); - $options['showFullContactNameOnActivityFeed'] = (bool) Civi::settings()->get('showFullContactNameOnActivityFeed'); - $options['includeActivitiesForInvolvedContact'] = (bool) Civi::settings()->get('includeActivitiesForInvolvedContact'); - $options['civicaseSingleCaseRolePerType'] = (bool) Civi::settings()->get('civicaseSingleCaseRolePerType'); - $options['caseTypeCategoriesWhereUserCanAccessActivities'] = - CRM_Civicase_Helper_CaseCategory::getWhereUserCanAccessActivities(); - $options['currentCaseCategory'] = $defaults['caseCategoryId'] ?: NULL; -} - -/** - * Get a list of JS files. - * - * @return array - * list of js files - */ -function get_base_js_files() { - return array_merge( - [ - 'assetBuilder://visual-bundle.js', - 'ang/civicase-base.js', - ], - GlobRecursive::getRelativeToExtension( - 'uk.co.compucorp.civicase', - 'ang/civicase-base/*.js' - ) - ); -} - -/** - * Sets the case types to javascript global variable. - */ -function set_case_types_to_js_vars(&$options) { - $caseTypes = civicrm_api3('CaseType', 'get', [ - 'return' => [ - 'id', - 'name', - 'title', - 'description', - 'definition', - 'case_type_category', - 'is_active', - ], - 'options' => ['limit' => 0, 'sort' => 'weight'], - ]); - foreach ($caseTypes['values'] as &$item) { - CRM_Utils_Array::remove($item, 'is_forkable', 'is_forked'); - } - $options['caseTypes'] = $caseTypes['values']; -} - -/** - * Sets the relationship types to javascript global variable. - */ -function set_relationship_types_to_js_vars(&$options) { - $result = civicrm_api3('RelationshipType', 'get', [ - 'options' => ['limit' => 0], - ]); - $options['relationshipTypes'] = $result['values']; -} - -/** - * Sets the tags and tagsets to javascript global variable. - */ -function set_tags_to_js_vars(&$options) { - $options['tags'] = CRM_Core_BAO_Tag::getColorTags('civicrm_case'); - $options['tagsets'] = CRM_Utils_Array::value('values', civicrm_api3('Tag', 'get', [ - 'sequential' => 1, - 'return' => ["id", "name"], - 'used_for' => ['LIKE' => "%civicrm_case%"], - 'is_tagset' => 1, - ])); -} - -/** - * Sets the file categories to javascript global variable. - */ -function set_file_categories_to_js_vars(&$options) { - $options['fileCategories'] = CRM_Civicase_FileCategory::getCategories(); -} - -/** - * Sets the activity status types to javascript global variable. - */ -function set_activity_status_types_to_js_vars(&$options) { - $options['activityStatusTypes'] = [ - 'incomplete' => array_keys(\CRM_Activity_BAO_Activity::getStatusesByType(CRM_Activity_BAO_Activity::INCOMPLETE)), - 'completed' => array_keys(\CRM_Activity_BAO_Activity::getStatusesByType(CRM_Activity_BAO_Activity::COMPLETED)), - 'cancelled' => array_keys(\CRM_Activity_BAO_Activity::getStatusesByType(CRM_Activity_BAO_Activity::CANCELLED)), - ]; -} - -/** - * Sets the custom fields information to javascript global variable. - */ -function set_custom_fields_info_to_js_vars(&$options) { - $result = civicrm_api3('CustomGroup', 'get', [ - 'sequential' => 1, - 'return' => ['extends_entity_column_value', 'title', 'extends'], - 'extends' => ['IN' => ['Case', 'Activity']], - 'is_active' => 1, - 'options' => ['sort' => 'weight'], - 'api.CustomField.get' => [ - 'is_active' => 1, - 'is_searchable' => 1, - 'return' => [ - 'label', 'html_type', 'data_type', 'is_search_range', - 'filter', 'option_group_id', - ], - 'options' => ['sort' => 'weight'], - ], - ]); - $options['customSearchFields'] = $options['customActivityFields'] = []; - foreach ($result['values'] as $group) { - if (!empty($group['api.CustomField.get']['values'])) { - if ($group['extends'] == 'Case') { - if (!empty($group['extends_entity_column_value'])) { - $group['caseTypes'] = CRM_Utils_Array::collect('name', array_values(array_intersect_key($options['caseTypes'], array_flip($group['extends_entity_column_value'])))); - } - foreach ($group['api.CustomField.get']['values'] as $field) { - $group['fields'][] = Utils::formatCustomSearchField($field); - } - unset($group['api.CustomField.get']); - $options['customSearchFields'][] = $group; - } - else { - foreach ($group['api.CustomField.get']['values'] as $field) { - $options['customActivityFields'][] = Utils::formatCustomSearchField($field) + ['group' => $group['title']]; - } - } - } - } -} - return [ - 'js' => get_base_js_files(), - 'settings' => $options, + 'js' => CRM_Civicase_BaseAngular::get_js_files(), + 'settingsFactory' => ['CRM_Civicase_BaseAngular', 'getOptions'], 'requires' => ['crmUtil', 'bw.paging'], 'partials' => [ 'ang/civicase-base', diff --git a/ang/civicase.ang.php b/ang/civicase.ang.php index 2d3188100..a898f384b 100644 --- a/ang/civicase.ang.php +++ b/ang/civicase.ang.php @@ -8,40 +8,6 @@ * http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_angularModules. */ -use CRM_Civicase_Helper_GlobRecursive as GlobRecursive; -use CRM_Civicase_Service_CaseCategoryPermission as CaseCategoryPermission; -use CRM_Civicase_Helper_NewCaseWebform as NewCaseWebform; -use CRM_Civicase_Helper_CaseCategory as CaseCategoryHelper; -use CRM_Civicase_Hook_Permissions_ExportCasesAndReports as ExportCasesAndReports; -use CRM_Civicase_Helper_CaseUrl as CaseUrlHelper; - -load_resources(); -[$caseCategoryId, $caseCategoryName] = CaseUrlHelper::getCategoryParamsFromUrl(); - -// Word replacements are already loaded for the contact tab ContactCaseTab. -if (CRM_Utils_System::currentPath() !== 'civicrm/case/contact-case-tab') { - $notTranslationPath = $caseCategoryName == CaseCategoryHelper::CASE_TYPE_CATEGORY_NAME && CRM_Utils_System::currentPath() != 'civicrm/case/a'; - - if (!$notTranslationPath) { - if (!in_array($caseCategoryName, CaseCategoryHelper::getAccessibleCaseTypeCategories())) { - throw new Exception('Access denied! You are not authorized to access this page.'); - } - - CRM_Civicase_Hook_Helper_CaseTypeCategory::addWordReplacements($caseCategoryName); - } -} - -$permissionService = new CaseCategoryPermission(); -$caseCategoryPermissions = $permissionService->get($caseCategoryName); - -// The following changes are only relevant to the full-page app. -if (CRM_Utils_System::currentPath() == 'civicrm/case/a') { - adds_shoreditch_css(); - CaseCategoryHelper::updateBreadcrumbs($caseCategoryId); -} - -$options = []; - $requires = [ 'crmAttachment', 'crmUi', @@ -56,202 +22,8 @@ ]; $requires = CRM_Civicase_Hook_addDependentAngularModules::invoke($requires); -set_case_actions($options, $caseCategoryPermissions); -set_contact_tasks($options); - -/** - * Loads Resources. - */ -function load_resources() { - Civi::resources() - ->addPermissions([ - 'administer CiviCase', 'administer CiviCRM', - 'access all cases and activities', 'add cases', 'basic case information', - 'access CiviCRM', 'access my cases and activities', - ]) - ->addScriptFile('org.civicrm.shoreditch', 'base/js/affix.js', 1000, 'html-header') - ->addSetting([ - 'config' => [ - 'enableComponents' => CRM_Core_Config::singleton()->enableComponents, - 'user_contact_id' => (int) CRM_Core_Session::getLoggedInContactID(), - ], - ]); -} - -/** - * Add shoreditch custom css if not already present. - */ -function adds_shoreditch_css() { - if (!civicrm_api3('Setting', 'getvalue', ['name' => "customCSSURL"])) { - Civi::resources() - ->addStyleFile('org.civicrm.shoreditch', 'css/custom-civicrm.css', 99, 'html-header'); - } -} - -/** - * Get a list of JS files. - */ -function get_js_files() { - return array_merge( - [ - // At the moment, it's safe to include this multiple times. - // deduped by resource manager. - 'assetBuilder://visual-bundle.js', - 'ang/civicase.js', - ], - GlobRecursive::getRelativeToExtension( - 'uk.co.compucorp.civicase', - 'ang/civicase/*.js' - ) - ); -} - -/** - * Bulk actions for case list. - * - * We put this here so it can be modified by other extensions. - */ -function set_case_actions(&$options, $caseCategoryPermissions) { - $options['caseActions'] = [ - [ - 'title' => ts('Change Case Status'), - 'action' => 'ChangeStatus', - 'icon' => 'fa-pencil-square-o', - 'is_write_action' => TRUE, - ], - [ - 'title' => ts('Edit Tags'), - 'action' => 'EditTags', - 'icon' => 'fa-tags', - 'number' => 1, - 'is_write_action' => TRUE, - ], - [ - 'title' => ts('Print Case'), - 'action' => 'Print', - 'number' => 1, - 'icon' => 'fa-print', - 'is_write_action' => FALSE, - ], - [ - 'title' => ts('Email - send now'), - 'action' => 'Email', - 'icon' => 'fa-envelope-o', - 'is_write_action' => TRUE, - ], - [ - 'title' => ts('Print/Merge Document'), - 'action' => 'PrintMerge', - 'icon' => 'fa-file-pdf-o', - 'is_write_action' => TRUE, - ], - [ - 'title' => ts('Link Cases'), - 'action' => 'LinkCases', - 'number' => 1, - 'icon' => 'fa-link', - 'is_write_action' => TRUE, - ], - [ - 'title' => ts('Link 2 Cases'), - 'action' => 'LinkCases', - 'number' => 2, - 'icon' => 'fa-link', - 'is_write_action' => TRUE, - ], - ]; - if (CRM_Core_Permission::check('administer CiviCase')) { - $options['caseActions'][] = [ - 'title' => ts('Merge 2 Cases'), - 'number' => 2, - 'action' => 'MergeCases', - 'icon' => 'fa-compress', - 'is_write_action' => TRUE, - ]; - $options['caseActions'][] = [ - 'title' => ts('Lock Case'), - 'action' => 'LockCases', - 'number' => 1, - 'icon' => 'fa-lock', - 'is_write_action' => TRUE, - ]; - } - if (CRM_Core_Permission::check($caseCategoryPermissions['DELETE_IN_CASE_CATEGORY']['name'])) { - $options['caseActions'][] = [ - 'title' => ts('Delete Case'), - 'action' => 'DeleteCases', - 'icon' => 'fa-trash', - 'is_write_action' => TRUE, - ]; - } - if (CRM_Core_Permission::check(ExportCasesAndReports::PERMISSION_NAME)) { - $options['caseActions'][] = [ - 'title' => ts('Export Cases'), - 'action' => 'ExportCases', - 'icon' => 'fa-file-excel-o', - 'is_write_action' => FALSE, - ]; - } - - add_webforms_case_action($options); -} - -/** - * Add webforms with cases attached to menu. - */ -function add_webforms_case_action(&$options) { - $items = []; - - $webformsToDisplay = Civi::settings()->get('civi_drupal_webforms'); - if (isset($webformsToDisplay)) { - $allowedWebforms = []; - foreach ($webformsToDisplay as $webformNode) { - $allowedWebforms[] = $webformNode['nid']; - } - $webforms = civicrm_api3('Case', 'getwebforms'); - if (isset($webforms['values'])) { - foreach ($webforms['values'] as $webform) { - if (!in_array($webform['nid'], $allowedWebforms)) { - continue; - } - - $client = NewCaseWebform::getCaseWebformClientId($webform['nid']); - - $items[] = [ - 'title' => $webform['title'], - 'action' => 'GoToWebform', - 'path' => $webform['path'], - 'case_type_ids' => $webform['case_type_ids'], - 'clientID' => $client, - 'is_write_action' => FALSE, - ]; - } - $options['caseActions'][] = [ - 'title' => ts('Webforms'), - 'action' => 'Webforms', - 'icon' => 'fa-file-text-o', - 'items' => $items, - 'is_write_action' => FALSE, - ]; - } - } -} - -/** - * Sets contact tasks. - */ -function set_contact_tasks(&$options) { - $contactTasks = CRM_Contact_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission()); - $options['contactTasks'] = []; - foreach (CRM_Contact_Task::$_tasks as $id => $value) { - if (isset($contactTasks[$id]) && isset($value['url'])) { - $options['contactTasks'][$id] = $value; - } - } -} - return [ - 'js' => get_js_files(), + 'js' => CRM_Civicase_Angular::get_js_files(), 'css' => [ // At the moment, it's safe to include this multiple times. // deduped by resource manager. @@ -261,7 +33,7 @@ function set_contact_tasks(&$options) { 'partials' => [ 'ang/civicase', ], - 'settings' => $options, + 'settingsFactory' => ['CRM_Civicase_Angular', 'getOptions'], 'requires' => $requires, 'basePages' => [], ]; diff --git a/ang/uibTabsetClass.ang.php b/ang/uibTabsetClass.ang.php index eb4af2d10..a984b4e35 100644 --- a/ang/uibTabsetClass.ang.php +++ b/ang/uibTabsetClass.ang.php @@ -3,11 +3,10 @@ // in CiviCRM. See also: // http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_angularModules -return array( - 'js' => array( +return [ + 'js' => [ 'ang/uibTabsetClass.js', - ), - 'settings' => array(), - 'requires' => array('ui.bootstrap'), - 'basePages' => array(), -); + ], + 'requires' => ['ui.bootstrap'], + 'basePages' => [], +];