{"action":"created","comment":{"url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments/37292314","id":37292314,"diff_hunk":"@@ -48,71 +48,64 @@ define(\n                     return this;\n                 }\n \n-                if (0 === this.versions.length) {\n-                    this.refreshHistory();\n+                if (this.getFormData().meta) {\n+                    this.getVersions()\n+                        .then(function (versions) {\n+                            this.$el.html(\n+                                this.template({\n+                                    versions: versions,\n+                                    expanded: this.getParent().getParent().isFullPanel(),\n+                                    hasAction: this.actions\n+                                })\n+                            );\n \n-                    return this;\n-                }\n+                            if (this.getParent().getParent().isFullPanel() && this.actions) {\n+                                _.each(this.$el.find('td.actions'), function (element) {\n+                                    _.each(this.actions, function (action) {\n+                                        $(element).append(action.clone(true));\n+                                    }.bind(this));\n+                                }.bind(this));\n+                            }\n \n-                if (this.getFormData().meta) {\n-                    this.$el.html(\n-                        this.template({\n-                            versions: this.versions,\n-                            expanded: this.getParent().getParent().state.get('fullPanel'),\n-                            hasAction: this.actions\n-                        })\n-                    );\n+                            this.delegateEvents();\n+                            this.renderExtensions();\n+                            this.getParent().resize();\n \n-                    if (this.getParent().getParent().state.get('fullPanel') && this.actions) {\n-                        _.each(this.$el.find('td.actions'), function (element) {\n-                            _.each(this.actions, function (action) {\n-                                $(element).append(action.clone(true));\n-                            }.bind(this));\n+                            this.delegateEvents();\n                         }.bind(this));\n-                    }\n \n-                    this.delegateEvents();\n-                    this.renderExtensions();\n-                    this.getParent().resize();\n                 }\n \n                 return this;\n             },\n-            refreshHistory: function () {\n-                if (this.loading) {\n-                    return;\n-                }\n \n-                this.loading = true;\n+            /**\n+             * Update the history by fetching it from the backend\n+             */\n+            update: function () {\n                 if (this.getFormData().meta) {\n-                    $.getJSON(\n-                        Routing.generate(\n-                            'pim_enrich_product_history_rest_get',\n-                            {\n-                                entityId: this.getFormData().meta.id\n-                            }\n-                        )\n-                    ).done(function (versions) {\n-                        this.prepareVersions(versions).done(function (versions) {\n-                            this.versions = versions;\n-                            this.render();\n-                            this.loading = false;\n-                        }.bind(this));\n-                    }.bind(this));\n+                    FetcherRegistry.getFetcher('product-history').clear(this.getFormData().meta.id);\n                 }\n+\n+                this.render();\n             },\n-            prepareVersions: function (versions) {\n-                return FetcherRegistry.getFetcher('attribute').fetchAll().then(function (attributes) {\n-                    _.each(versions, function (version) {\n-                        _.each(version.changeset, function (data, index) {\n-                            var code = index.split('-').shift();\n-                            var attribute = _.findWhere(attributes, { code: code });\n-                            data.label = attribute ? this.getAttributeLabel(attribute, index) : index;\n+            getVersions: function () {\n+                return FetcherRegistry.getFetcher('product-history').fetch(\n+                        this.getFormData().meta.id,\n+                        {entityId: this.getFormData().meta.id}\n+                    ).then(function (versions) {\n+                        return FetcherRegistry.getFetcher('attribute').fetchAll().then(function (attributes) {\n+                            _.each(versions, function (version) {\n+                                _.each(version.changeset, function (data, index) {\n+                                    var code = index.split('-').shift();\n+                                    var attribute = _.findWhere(attributes, { code: code });\n+                                    data.label = attribute ? this.getAttributeLabel(attribute, index) : index;","path":"src/Pim/Bundle/EnrichBundle/Resources/public/js/product/form/panel/history.js","position":111,"original_position":111,"commit_id":"7224ab7630d2273f5605b67f5f7aa62001c34703","original_commit_id":"8d2ba9caab9017fe5b73685d8d7561090a14ea87","user":{"login":"phaseinducer","id":659491,"avatar_url":"https://avatars.githubusercontent.com/u/659491?v=3","gravatar_id":"","url":"https://api.github.com/users/phaseinducer","html_url":"https://github.com/phaseinducer","followers_url":"https://api.github.com/users/phaseinducer/followers","following_url":"https://api.github.com/users/phaseinducer/following{/other_user}","gists_url":"https://api.github.com/users/phaseinducer/gists{/gist_id}","starred_url":"https://api.github.com/users/phaseinducer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phaseinducer/subscriptions","organizations_url":"https://api.github.com/users/phaseinducer/orgs","repos_url":"https://api.github.com/users/phaseinducer/repos","events_url":"https://api.github.com/users/phaseinducer/events{/privacy}","received_events_url":"https://api.github.com/users/phaseinducer/received_events","type":"User","site_admin":false},"body":"Is it possible to extract that in another method ? It's really hard to read. : /","created_at":"2015-08-18T12:32:24Z","updated_at":"2015-08-18T12:32:24Z","html_url":"https://github.com/akeneo/pim-community-dev/pull/3137#discussion_r37292314","pull_request_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/3137","_links":{"self":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments/37292314"},"html":{"href":"https://github.com/akeneo/pim-community-dev/pull/3137#discussion_r37292314"},"pull_request":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/3137"}}},"pull_request":{"url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/3137","id":42690359,"html_url":"https://github.com/akeneo/pim-community-dev/pull/3137","diff_url":"https://github.com/akeneo/pim-community-dev/pull/3137.diff","patch_url":"https://github.com/akeneo/pim-community-dev/pull/3137.patch","issue_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/3137","number":3137,"state":"open","locked":false,"title":"PIM-4765: rework history panel","user":{"login":"sumbobyboys","id":1117272,"avatar_url":"https://avatars.githubusercontent.com/u/1117272?v=3","gravatar_id":"","url":"https://api.github.com/users/sumbobyboys","html_url":"https://github.com/sumbobyboys","followers_url":"https://api.github.com/users/sumbobyboys/followers","following_url":"https://api.github.com/users/sumbobyboys/following{/other_user}","gists_url":"https://api.github.com/users/sumbobyboys/gists{/gist_id}","starred_url":"https://api.github.com/users/sumbobyboys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sumbobyboys/subscriptions","organizations_url":"https://api.github.com/users/sumbobyboys/orgs","repos_url":"https://api.github.com/users/sumbobyboys/repos","events_url":"https://api.github.com/users/sumbobyboys/events{/privacy}","received_events_url":"https://api.github.com/users/sumbobyboys/received_events","type":"User","site_admin":false},"body":"| Q                  | A\r\n| ------------------ | ---\r\n| Migration script?  | N\r\n| Behats             | ?\r\n| Specs & Static     | ?\r\n| Changelog updated  |","created_at":"2015-08-18T12:01:04Z","updated_at":"2015-08-18T12:32:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2ad9350a057533f7a081429f6339097de8dded5a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/3137/commits","review_comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/3137/comments","review_comment_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments{/number}","comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/3137/comments","statuses_url":"https://api.github.com/repos/akeneo/pim-community-dev/statuses/7224ab7630d2273f5605b67f5f7aa62001c34703","head":{"label":"akeneo:PIM-4765","ref":"PIM-4765","sha":"7224ab7630d2273f5605b67f5f7aa62001c34703","user":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.githubusercontent.com/u/2510186?v=3","gravatar_id":"","url":"https://api.github.com/users/akeneo","html_url":"https://github.com/akeneo","followers_url":"https://api.github.com/users/akeneo/followers","following_url":"https://api.github.com/users/akeneo/following{/other_user}","gists_url":"https://api.github.com/users/akeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/akeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akeneo/subscriptions","organizations_url":"https://api.github.com/users/akeneo/orgs","repos_url":"https://api.github.com/users/akeneo/repos","events_url":"https://api.github.com/users/akeneo/events{/privacy}","received_events_url":"https://api.github.com/users/akeneo/received_events","type":"Organization","site_admin":false},"repo":{"id":5367323,"name":"pim-community-dev","full_name":"akeneo/pim-community-dev","owner":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.githubusercontent.com/u/2510186?v=3","gravatar_id":"","url":"https://api.github.com/users/akeneo","html_url":"https://github.com/akeneo","followers_url":"https://api.github.com/users/akeneo/followers","following_url":"https://api.github.com/users/akeneo/following{/other_user}","gists_url":"https://api.github.com/users/akeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/akeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akeneo/subscriptions","organizations_url":"https://api.github.com/users/akeneo/orgs","repos_url":"https://api.github.com/users/akeneo/repos","events_url":"https://api.github.com/users/akeneo/events{/privacy}","received_events_url":"https://api.github.com/users/akeneo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/akeneo/pim-community-dev","description":"Akeneo PIM development repository","fork":false,"url":"https://api.github.com/repos/akeneo/pim-community-dev","forks_url":"https://api.github.com/repos/akeneo/pim-community-dev/forks","keys_url":"https://api.github.com/repos/akeneo/pim-community-dev/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akeneo/pim-community-dev/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akeneo/pim-community-dev/teams","hooks_url":"https://api.github.com/repos/akeneo/pim-community-dev/hooks","issue_events_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/events{/number}","events_url":"https://api.github.com/repos/akeneo/pim-community-dev/events","assignees_url":"https://api.github.com/repos/akeneo/pim-community-dev/assignees{/user}","branches_url":"https://api.github.com/repos/akeneo/pim-community-dev/branches{/branch}","tags_url":"https://api.github.com/repos/akeneo/pim-community-dev/tags","blobs_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/refs{/sha}","trees_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akeneo/pim-community-dev/statuses/{sha}","languages_url":"https://api.github.com/repos/akeneo/pim-community-dev/languages","stargazers_url":"https://api.github.com/repos/akeneo/pim-community-dev/stargazers","contributors_url":"https://api.github.com/repos/akeneo/pim-community-dev/contributors","subscribers_url":"https://api.github.com/repos/akeneo/pim-community-dev/subscribers","subscription_url":"https://api.github.com/repos/akeneo/pim-community-dev/subscription","commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/commits{/sha}","git_commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/commits{/sha}","comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/comments{/number}","issue_comment_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/comments{/number}","contents_url":"https://api.github.com/repos/akeneo/pim-community-dev/contents/{+path}","compare_url":"https://api.github.com/repos/akeneo/pim-community-dev/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akeneo/pim-community-dev/merges","archive_url":"https://api.github.com/repos/akeneo/pim-community-dev/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akeneo/pim-community-dev/downloads","issues_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues{/number}","pulls_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls{/number}","milestones_url":"https://api.github.com/repos/akeneo/pim-community-dev/milestones{/number}","notifications_url":"https://api.github.com/repos/akeneo/pim-community-dev/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akeneo/pim-community-dev/labels{/name}","releases_url":"https://api.github.com/repos/akeneo/pim-community-dev/releases{/id}","created_at":"2012-08-10T09:27:26Z","updated_at":"2015-08-16T15:29:29Z","pushed_at":"2015-08-18T12:20:36Z","git_url":"git://github.com/akeneo/pim-community-dev.git","ssh_url":"git@github.com:akeneo/pim-community-dev.git","clone_url":"https://github.com/akeneo/pim-community-dev.git","svn_url":"https://github.com/akeneo/pim-community-dev","homepage":"http://akeneo.com","size":165078,"stargazers_count":239,"watchers_count":239,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":119,"mirror_url":null,"open_issues_count":60,"forks":119,"open_issues":60,"watchers":239,"default_branch":"master"}},"base":{"label":"akeneo:master","ref":"master","sha":"cc5ff0f6d75b4f714dac77931f9de99788fb8500","user":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.githubusercontent.com/u/2510186?v=3","gravatar_id":"","url":"https://api.github.com/users/akeneo","html_url":"https://github.com/akeneo","followers_url":"https://api.github.com/users/akeneo/followers","following_url":"https://api.github.com/users/akeneo/following{/other_user}","gists_url":"https://api.github.com/users/akeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/akeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akeneo/subscriptions","organizations_url":"https://api.github.com/users/akeneo/orgs","repos_url":"https://api.github.com/users/akeneo/repos","events_url":"https://api.github.com/users/akeneo/events{/privacy}","received_events_url":"https://api.github.com/users/akeneo/received_events","type":"Organization","site_admin":false},"repo":{"id":5367323,"name":"pim-community-dev","full_name":"akeneo/pim-community-dev","owner":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.githubusercontent.com/u/2510186?v=3","gravatar_id":"","url":"https://api.github.com/users/akeneo","html_url":"https://github.com/akeneo","followers_url":"https://api.github.com/users/akeneo/followers","following_url":"https://api.github.com/users/akeneo/following{/other_user}","gists_url":"https://api.github.com/users/akeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/akeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akeneo/subscriptions","organizations_url":"https://api.github.com/users/akeneo/orgs","repos_url":"https://api.github.com/users/akeneo/repos","events_url":"https://api.github.com/users/akeneo/events{/privacy}","received_events_url":"https://api.github.com/users/akeneo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/akeneo/pim-community-dev","description":"Akeneo PIM development repository","fork":false,"url":"https://api.github.com/repos/akeneo/pim-community-dev","forks_url":"https://api.github.com/repos/akeneo/pim-community-dev/forks","keys_url":"https://api.github.com/repos/akeneo/pim-community-dev/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akeneo/pim-community-dev/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akeneo/pim-community-dev/teams","hooks_url":"https://api.github.com/repos/akeneo/pim-community-dev/hooks","issue_events_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/events{/number}","events_url":"https://api.github.com/repos/akeneo/pim-community-dev/events","assignees_url":"https://api.github.com/repos/akeneo/pim-community-dev/assignees{/user}","branches_url":"https://api.github.com/repos/akeneo/pim-community-dev/branches{/branch}","tags_url":"https://api.github.com/repos/akeneo/pim-community-dev/tags","blobs_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/refs{/sha}","trees_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akeneo/pim-community-dev/statuses/{sha}","languages_url":"https://api.github.com/repos/akeneo/pim-community-dev/languages","stargazers_url":"https://api.github.com/repos/akeneo/pim-community-dev/stargazers","contributors_url":"https://api.github.com/repos/akeneo/pim-community-dev/contributors","subscribers_url":"https://api.github.com/repos/akeneo/pim-community-dev/subscribers","subscription_url":"https://api.github.com/repos/akeneo/pim-community-dev/subscription","commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/commits{/sha}","git_commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/commits{/sha}","comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/comments{/number}","issue_comment_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/comments{/number}","contents_url":"https://api.github.com/repos/akeneo/pim-community-dev/contents/{+path}","compare_url":"https://api.github.com/repos/akeneo/pim-community-dev/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akeneo/pim-community-dev/merges","archive_url":"https://api.github.com/repos/akeneo/pim-community-dev/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akeneo/pim-community-dev/downloads","issues_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues{/number}","pulls_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls{/number}","milestones_url":"https://api.github.com/repos/akeneo/pim-community-dev/milestones{/number}","notifications_url":"https://api.github.com/repos/akeneo/pim-community-dev/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akeneo/pim-community-dev/labels{/name}","releases_url":"https://api.github.com/repos/akeneo/pim-community-dev/releases{/id}","created_at":"2012-08-10T09:27:26Z","updated_at":"2015-08-16T15:29:29Z","pushed_at":"2015-08-18T12:20:36Z","git_url":"git://github.com/akeneo/pim-community-dev.git","ssh_url":"git@github.com:akeneo/pim-community-dev.git","clone_url":"https://github.com/akeneo/pim-community-dev.git","svn_url":"https://github.com/akeneo/pim-community-dev","homepage":"http://akeneo.com","size":165078,"stargazers_count":239,"watchers_count":239,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":119,"mirror_url":null,"open_issues_count":60,"forks":119,"open_issues":60,"watchers":239,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/3137"},"html":{"href":"https://github.com/akeneo/pim-community-dev/pull/3137"},"issue":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/issues/3137"},"comments":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/issues/3137/comments"},"review_comments":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/3137/comments"},"review_comment":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/3137/commits"},"statuses":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/statuses/7224ab7630d2273f5605b67f5f7aa62001c34703"}}}}