{"action":"created","comment":{"url":"https://api.github.com/repos/compucorp/civihr/pulls/comments/202993350","pull_request_review_id":137791676,"id":202993350,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwMjk5MzM1MA==","diff_hunk":"@@ -100,19 +99,20 @@\n       </table>\n     </div>\n   {/section}\n-  {literal}\n-    <script type=\"text/javascript\">\n-      CRM.$(function($) {\n-        var form = new CRM.HRLeaveAndAbsencesApp.Form.WorkPattern({/literal}'{$delete_url}'{literal});\n+  <script type=\"text/javascript\">\n+    {literal}\n+      CRM.$(document).on('CRMWorkPatternFormScriptIsReady', function () {","path":"uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Form/WorkPattern/Calendar.tpl","position":20,"original_position":20,"commit_id":"9efa0971536b97c55b70ea128236fc7c2086573f","original_commit_id":"9efa0971536b97c55b70ea128236fc7c2086573f","user":{"login":"tunbola","id":6951813,"node_id":"MDQ6VXNlcjY5NTE4MTM=","avatar_url":"https://avatars1.githubusercontent.com/u/6951813?v=4","gravatar_id":"","url":"https://api.github.com/users/tunbola","html_url":"https://github.com/tunbola","followers_url":"https://api.github.com/users/tunbola/followers","following_url":"https://api.github.com/users/tunbola/following{/other_user}","gists_url":"https://api.github.com/users/tunbola/gists{/gist_id}","starred_url":"https://api.github.com/users/tunbola/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tunbola/subscriptions","organizations_url":"https://api.github.com/users/tunbola/orgs","repos_url":"https://api.github.com/users/tunbola/repos","events_url":"https://api.github.com/users/tunbola/events{/privacy}","received_events_url":"https://api.github.com/users/tunbola/received_events","type":"User","site_admin":false},"body":"Is this `CRMWorkPatternFormScriptIsReady` generated by Civi automatically?","created_at":"2018-07-17T12:00:38Z","updated_at":"2018-07-17T12:01:35Z","html_url":"https://github.com/compucorp/civihr/pull/2766#discussion_r202993350","pull_request_url":"https://api.github.com/repos/compucorp/civihr/pulls/2766","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/compucorp/civihr/pulls/comments/202993350"},"html":{"href":"https://github.com/compucorp/civihr/pull/2766#discussion_r202993350"},"pull_request":{"href":"https://api.github.com/repos/compucorp/civihr/pulls/2766"}}},"pull_request":{"url":"https://api.github.com/repos/compucorp/civihr/pulls/2766","id":201894173,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAxODk0MTcz","html_url":"https://github.com/compucorp/civihr/pull/2766","diff_url":"https://github.com/compucorp/civihr/pull/2766.diff","patch_url":"https://github.com/compucorp/civihr/pull/2766.patch","issue_url":"https://api.github.com/repos/compucorp/civihr/issues/2766","number":2766,"state":"open","locked":false,"title":"PCHR-3962: Transform L&A CRM JS files to AMD modules","user":{"login":"igorpavlov","id":3973243,"node_id":"MDQ6VXNlcjM5NzMyNDM=","avatar_url":"https://avatars1.githubusercontent.com/u/3973243?v=4","gravatar_id":"","url":"https://api.github.com/users/igorpavlov","html_url":"https://github.com/igorpavlov","followers_url":"https://api.github.com/users/igorpavlov/followers","following_url":"https://api.github.com/users/igorpavlov/following{/other_user}","gists_url":"https://api.github.com/users/igorpavlov/gists{/gist_id}","starred_url":"https://api.github.com/users/igorpavlov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/igorpavlov/subscriptions","organizations_url":"https://api.github.com/users/igorpavlov/orgs","repos_url":"https://api.github.com/users/igorpavlov/repos","events_url":"https://api.github.com/users/igorpavlov/events{/privacy}","received_events_url":"https://api.github.com/users/igorpavlov/received_events","type":"User","site_admin":false},"body":"## Overview\r\n\r\nThis PR transforms the JS files in the L&A `/js/crm` folder to AMD modules and moves all these modules to the `js/src/leave-absences` folder for consistency.\r\n\r\n## Before\r\n\r\nPlain JS files that are injected as-is to the page.\r\n\r\n![image](https://user-images.githubusercontent.com/3973243/42814134-2ef6ce28-89bb-11e8-98c2-b79d309f425b.png)\r\n\r\n```php\r\nCRM_Core_Resources::singleton()->\r\n  addScriptFile('uk.co.compucorp.civicrm.hrleaveandabsences',\r\n    'js/crm/hrleaveandabsences.js', CRM_Core_Resources::DEFAULT_WEIGHT, 'html-header');\r\n```\r\n\r\n## After\r\n\r\nThe AMD modules that are built into a distributive and then injected onto pages:\r\n\r\n![image](https://user-images.githubusercontent.com/3973243/42814239-88ce70d6-89bb-11e8-85a8-e8a50947665d.png)\r\n\r\n```php\r\nCRM_Core_Resources::singleton()->\r\n  addScriptFile('uk.co.compucorp.civicrm.hrleaveandabsences',\r\n    'js/dist/crm-hrleaveandabsences.min.js', 1001);\r\n```\r\n\r\n\r\n## Technical Details\r\n\r\n### Basic details\r\n\r\nA goal is to provide more consistency across the FE code. The objectives are:\r\n- Make AMD modules from the files inside the `js/crm` folder to allow to inject each other when needed\r\n- Specify dependencies inside AMD and avoid injecting them directly into the browser via the `<script> tag\r\n- Minify distributive files that are injected\r\n\r\nThe distributive files are created as usual, at first, the `build.js` specifies which distributive files are needed:\r\n\r\n```js\r\n/* eslint-disable */\r\n\r\n({\r\n  // ...\r\n  modules: [\r\n    // ...\r\n    { name: 'crm-list-absenceperiod' },\r\n    { name: 'crm-hrleaveandabsences' },\r\n    { name: 'crm-form-manage-entitlements' },\r\n    { name: 'crm-form-absenceperiod' },\r\n    { name: 'crm-form-workpattern' },\r\n    { name: 'spectrum' } // needs to be included without any additional code\r\n```\r\n\r\nThen original files were wrapped with AMD (eg. the Work Pattern Form file `js/src/leave-absences/crm/form-workpattern.js`):\r\n\r\n```js\r\ndefine([\r\n  'leave-absences/crm/includes/hrleaveandabsences-init', // main app initiator\r\n  'leave-absences/crm/vendor/inputmask/inputmask.numeric.extensions.min' // dependencies\r\n], function (HRLeaveAndAbsencesApp) {\r\n```\r\nThis allows to avoid separate dependencies inclusion like this:\r\n\r\n```php\r\nCRM_Core_Resources::singleton()->\r\n  addScriptFile('uk.co.compucorp.civicrm.hrleaveandabsences',\r\n    'js/dist/crm-form-workpattern.min.js', 1001);\r\n```\r\n\r\nInstead of:\r\n\r\n```php\r\n...'js/crm/vendor/inputmask.min.js'\r\n...'js/crm/vendor/inputmask.numeric.extensions.min.js');\r\n...'js/crm/hrleaveandabsences.form.workpattern.js');\r\n```\r\n\r\n### Main init file\r\n\r\n```js\r\n/* eslint-env amd */\r\ndefine([], function () {\r\n  // Initialises needed properties\r\n  CRM.HRLeaveAndAbsencesApp = CRM.HRLeaveAndAbsencesApp || {};\r\n  CRM.HRLeaveAndAbsencesApp.Form = CRM.HRLeaveAndAbsencesApp.Form || {};\r\n  CRM.HRLeaveAndAbsencesApp.List = CRM.HRLeaveAndAbsencesApp.List || {};\r\n\r\n  // Returns the app object to avoid using too much `CRM` variable in the app modules\r\n  return CRM.HRLeaveAndAbsencesApp;\r\n});\r\n```\r\n\r\nThis also removes duplicating code from the app modules.\r\n\r\n\r\n## Comments\r\n\r\nSome code was refactored apart from the satisfying Semistandard.\r\n\r\n### {literal} and <script>\r\n\r\nThere is no need to escape the `<script>` tag, just the code inside:\r\n\r\n```html\r\n<!-- No -->\r\n{literal}<script> /* code */ </script>{/literal}\r\n<!-- Yes -->\r\n<script>{literal} /* code */ {/literal}</script>\r\n```\r\n\r\nYou may also notice that even Github likes that more and highlights the JS and HTML (same for Atom editor).\r\n\r\n### Indentation\r\n\r\nInstead of:\r\n\r\n```html\r\n<div>\r\n<script>\r\n{literal}\r\n/* code */\r\n{/literal}\r\n</script>\r\n</div>\r\n```\r\nWe now have:\r\n\r\n```html\r\n<div>\r\n  <script>\r\n    {literal}\r\n      /* code */\r\n    {/literal}\r\n  </script>\r\n</div>\r\n```\r\nThis is better for readability of nested elements.\r\n\r\n-------\r\n\r\n✅Manual Tests - passed\r\n⏹Jasmine Tests - no coverage\r\n✅JS distributive files - included\r\n⏹CSS distributive files - not needed\r\n⏹Backstop tests - not needed\r\n⏹PHP Unit Tests - not needed","created_at":"2018-07-17T10:25:43Z","updated_at":"2018-07-17T12:01:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6888e9b649861ee593a28a4539d205a33fdf898c","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":39820927,"node_id":"MDU6TGFiZWwzOTgyMDkyNw==","url":"https://api.github.com/repos/compucorp/civihr/labels/enhancement","name":"enhancement","color":"84b6eb","default":true},{"id":712229315,"node_id":"MDU6TGFiZWw3MTIyMjkzMTU=","url":"https://api.github.com/repos/compucorp/civihr/labels/ready%20to%20test","name":"ready to test","color":"0052cc","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/compucorp/civihr/pulls/2766/commits","review_comments_url":"https://api.github.com/repos/compucorp/civihr/pulls/2766/comments","review_comment_url":"https://api.github.com/repos/compucorp/civihr/pulls/comments{/number}","comments_url":"https://api.github.com/repos/compucorp/civihr/issues/2766/comments","statuses_url":"https://api.github.com/repos/compucorp/civihr/statuses/9efa0971536b97c55b70ea128236fc7c2086573f","head":{"label":"compucorp:PCHR-3962-requirejs-la-crm-folder","ref":"PCHR-3962-requirejs-la-crm-folder","sha":"9efa0971536b97c55b70ea128236fc7c2086573f","user":{"login":"compucorp","id":2040164,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIwNDAxNjQ=","avatar_url":"https://avatars3.githubusercontent.com/u/2040164?v=4","gravatar_id":"","url":"https://api.github.com/users/compucorp","html_url":"https://github.com/compucorp","followers_url":"https://api.github.com/users/compucorp/followers","following_url":"https://api.github.com/users/compucorp/following{/other_user}","gists_url":"https://api.github.com/users/compucorp/gists{/gist_id}","starred_url":"https://api.github.com/users/compucorp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/compucorp/subscriptions","organizations_url":"https://api.github.com/users/compucorp/orgs","repos_url":"https://api.github.com/users/compucorp/repos","events_url":"https://api.github.com/users/compucorp/events{/privacy}","received_events_url":"https://api.github.com/users/compucorp/received_events","type":"Organization","site_admin":false},"repo":{"id":10086903,"node_id":"MDEwOlJlcG9zaXRvcnkxMDA4NjkwMw==","name":"civihr","full_name":"compucorp/civihr","owner":{"login":"compucorp","id":2040164,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIwNDAxNjQ=","avatar_url":"https://avatars3.githubusercontent.com/u/2040164?v=4","gravatar_id":"","url":"https://api.github.com/users/compucorp","html_url":"https://github.com/compucorp","followers_url":"https://api.github.com/users/compucorp/followers","following_url":"https://api.github.com/users/compucorp/following{/other_user}","gists_url":"https://api.github.com/users/compucorp/gists{/gist_id}","starred_url":"https://api.github.com/users/compucorp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/compucorp/subscriptions","organizations_url":"https://api.github.com/users/compucorp/orgs","repos_url":"https://api.github.com/users/compucorp/repos","events_url":"https://api.github.com/users/compucorp/events{/privacy}","received_events_url":"https://api.github.com/users/compucorp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/compucorp/civihr","description":"CiviHR","fork":false,"url":"https://api.github.com/repos/compucorp/civihr","forks_url":"https://api.github.com/repos/compucorp/civihr/forks","keys_url":"https://api.github.com/repos/compucorp/civihr/keys{/key_id}","collaborators_url":"https://api.github.com/repos/compucorp/civihr/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/compucorp/civihr/teams","hooks_url":"https://api.github.com/repos/compucorp/civihr/hooks","issue_events_url":"https://api.github.com/repos/compucorp/civihr/issues/events{/number}","events_url":"https://api.github.com/repos/compucorp/civihr/events","assignees_url":"https://api.github.com/repos/compucorp/civihr/assignees{/user}","branches_url":"https://api.github.com/repos/compucorp/civihr/branches{/branch}","tags_url":"https://api.github.com/repos/compucorp/civihr/tags","blobs_url":"https://api.github.com/repos/compucorp/civihr/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/compucorp/civihr/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/compucorp/civihr/git/refs{/sha}","trees_url":"https://api.github.com/repos/compucorp/civihr/git/trees{/sha}","statuses_url":"https://api.github.com/repos/compucorp/civihr/statuses/{sha}","languages_url":"https://api.github.com/repos/compucorp/civihr/languages","stargazers_url":"https://api.github.com/repos/compucorp/civihr/stargazers","contributors_url":"https://api.github.com/repos/compucorp/civihr/contributors","subscribers_url":"https://api.github.com/repos/compucorp/civihr/subscribers","subscription_url":"https://api.github.com/repos/compucorp/civihr/subscription","commits_url":"https://api.github.com/repos/compucorp/civihr/commits{/sha}","git_commits_url":"https://api.github.com/repos/compucorp/civihr/git/commits{/sha}","comments_url":"https://api.github.com/repos/compucorp/civihr/comments{/number}","issue_comment_url":"https://api.github.com/repos/compucorp/civihr/issues/comments{/number}","contents_url":"https://api.github.com/repos/compucorp/civihr/contents/{+path}","compare_url":"https://api.github.com/repos/compucorp/civihr/compare/{base}...{head}","merges_url":"https://api.github.com/repos/compucorp/civihr/merges","archive_url":"https://api.github.com/repos/compucorp/civihr/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/compucorp/civihr/downloads","issues_url":"https://api.github.com/repos/compucorp/civihr/issues{/number}","pulls_url":"https://api.github.com/repos/compucorp/civihr/pulls{/number}","milestones_url":"https://api.github.com/repos/compucorp/civihr/milestones{/number}","notifications_url":"https://api.github.com/repos/compucorp/civihr/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/compucorp/civihr/labels{/name}","releases_url":"https://api.github.com/repos/compucorp/civihr/releases{/id}","deployments_url":"https://api.github.com/repos/compucorp/civihr/deployments","created_at":"2013-05-15T20:06:06Z","updated_at":"2018-07-17T09:29:41Z","pushed_at":"2018-07-17T10:57:19Z","git_url":"git://github.com/compucorp/civihr.git","ssh_url":"git@github.com:compucorp/civihr.git","clone_url":"https://github.com/compucorp/civihr.git","svn_url":"https://github.com/compucorp/civihr","homepage":null,"size":65884,"stargazers_count":30,"watchers_count":30,"language":"PHP","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":42,"mirror_url":null,"archived":false,"open_issues_count":6,"license":null,"forks":42,"open_issues":6,"watchers":30,"default_branch":"staging"}},"base":{"label":"compucorp:staging","ref":"staging","sha":"7eed24a491d8fc4f3c1dadebbcfa177f04542282","user":{"login":"compucorp","id":2040164,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIwNDAxNjQ=","avatar_url":"https://avatars3.githubusercontent.com/u/2040164?v=4","gravatar_id":"","url":"https://api.github.com/users/compucorp","html_url":"https://github.com/compucorp","followers_url":"https://api.github.com/users/compucorp/followers","following_url":"https://api.github.com/users/compucorp/following{/other_user}","gists_url":"https://api.github.com/users/compucorp/gists{/gist_id}","starred_url":"https://api.github.com/users/compucorp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/compucorp/subscriptions","organizations_url":"https://api.github.com/users/compucorp/orgs","repos_url":"https://api.github.com/users/compucorp/repos","events_url":"https://api.github.com/users/compucorp/events{/privacy}","received_events_url":"https://api.github.com/users/compucorp/received_events","type":"Organization","site_admin":false},"repo":{"id":10086903,"node_id":"MDEwOlJlcG9zaXRvcnkxMDA4NjkwMw==","name":"civihr","full_name":"compucorp/civihr","owner":{"login":"compucorp","id":2040164,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIwNDAxNjQ=","avatar_url":"https://avatars3.githubusercontent.com/u/2040164?v=4","gravatar_id":"","url":"https://api.github.com/users/compucorp","html_url":"https://github.com/compucorp","followers_url":"https://api.github.com/users/compucorp/followers","following_url":"https://api.github.com/users/compucorp/following{/other_user}","gists_url":"https://api.github.com/users/compucorp/gists{/gist_id}","starred_url":"https://api.github.com/users/compucorp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/compucorp/subscriptions","organizations_url":"https://api.github.com/users/compucorp/orgs","repos_url":"https://api.github.com/users/compucorp/repos","events_url":"https://api.github.com/users/compucorp/events{/privacy}","received_events_url":"https://api.github.com/users/compucorp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/compucorp/civihr","description":"CiviHR","fork":false,"url":"https://api.github.com/repos/compucorp/civihr","forks_url":"https://api.github.com/repos/compucorp/civihr/forks","keys_url":"https://api.github.com/repos/compucorp/civihr/keys{/key_id}","collaborators_url":"https://api.github.com/repos/compucorp/civihr/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/compucorp/civihr/teams","hooks_url":"https://api.github.com/repos/compucorp/civihr/hooks","issue_events_url":"https://api.github.com/repos/compucorp/civihr/issues/events{/number}","events_url":"https://api.github.com/repos/compucorp/civihr/events","assignees_url":"https://api.github.com/repos/compucorp/civihr/assignees{/user}","branches_url":"https://api.github.com/repos/compucorp/civihr/branches{/branch}","tags_url":"https://api.github.com/repos/compucorp/civihr/tags","blobs_url":"https://api.github.com/repos/compucorp/civihr/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/compucorp/civihr/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/compucorp/civihr/git/refs{/sha}","trees_url":"https://api.github.com/repos/compucorp/civihr/git/trees{/sha}","statuses_url":"https://api.github.com/repos/compucorp/civihr/statuses/{sha}","languages_url":"https://api.github.com/repos/compucorp/civihr/languages","stargazers_url":"https://api.github.com/repos/compucorp/civihr/stargazers","contributors_url":"https://api.github.com/repos/compucorp/civihr/contributors","subscribers_url":"https://api.github.com/repos/compucorp/civihr/subscribers","subscription_url":"https://api.github.com/repos/compucorp/civihr/subscription","commits_url":"https://api.github.com/repos/compucorp/civihr/commits{/sha}","git_commits_url":"https://api.github.com/repos/compucorp/civihr/git/commits{/sha}","comments_url":"https://api.github.com/repos/compucorp/civihr/comments{/number}","issue_comment_url":"https://api.github.com/repos/compucorp/civihr/issues/comments{/number}","contents_url":"https://api.github.com/repos/compucorp/civihr/contents/{+path}","compare_url":"https://api.github.com/repos/compucorp/civihr/compare/{base}...{head}","merges_url":"https://api.github.com/repos/compucorp/civihr/merges","archive_url":"https://api.github.com/repos/compucorp/civihr/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/compucorp/civihr/downloads","issues_url":"https://api.github.com/repos/compucorp/civihr/issues{/number}","pulls_url":"https://api.github.com/repos/compucorp/civihr/pulls{/number}","milestones_url":"https://api.github.com/repos/compucorp/civihr/milestones{/number}","notifications_url":"https://api.github.com/repos/compucorp/civihr/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/compucorp/civihr/labels{/name}","releases_url":"https://api.github.com/repos/compucorp/civihr/releases{/id}","deployments_url":"https://api.github.com/repos/compucorp/civihr/deployments","created_at":"2013-05-15T20:06:06Z","updated_at":"2018-07-17T09:29:41Z","pushed_at":"2018-07-17T10:57:19Z","git_url":"git://github.com/compucorp/civihr.git","ssh_url":"git@github.com:compucorp/civihr.git","clone_url":"https://github.com/compucorp/civihr.git","svn_url":"https://github.com/compucorp/civihr","homepage":null,"size":65884,"stargazers_count":30,"watchers_count":30,"language":"PHP","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":42,"mirror_url":null,"archived":false,"open_issues_count":6,"license":null,"forks":42,"open_issues":6,"watchers":30,"default_branch":"staging"}},"_links":{"self":{"href":"https://api.github.com/repos/compucorp/civihr/pulls/2766"},"html":{"href":"https://github.com/compucorp/civihr/pull/2766"},"issue":{"href":"https://api.github.com/repos/compucorp/civihr/issues/2766"},"comments":{"href":"https://api.github.com/repos/compucorp/civihr/issues/2766/comments"},"review_comments":{"href":"https://api.github.com/repos/compucorp/civihr/pulls/2766/comments"},"review_comment":{"href":"https://api.github.com/repos/compucorp/civihr/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/compucorp/civihr/pulls/2766/commits"},"statuses":{"href":"https://api.github.com/repos/compucorp/civihr/statuses/9efa0971536b97c55b70ea128236fc7c2086573f"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"tunbola"}}