{"action":"created","comment":{"url":"https://api.github.com/repos/odoo/odoo/pulls/comments/34874330","id":34874330,"diff_hunk":"@@ -0,0 +1,158 @@\n+odoo.define('web.BarcodeEvents', function(require) {\n+\"use strict\";\n+\n+var core = require('web.core');\n+var mixins = core.mixins;\n+\n+var BarcodeEvents = core.Class.extend(mixins.PropertiesMixin, {\n+    timeout: null,\n+    key_pressed: {},\n+    buffered_key_events: [],\n+    // Regexp to match a barcode input and extract its payload\n+    // Note: to build in init() if prefix/suffix can be configured\n+    regexp: /(.{3,})[\\n\\r\\t]+/,\n+    // By knowing the terminal character we can interpret buffered keys\n+    // as a barcode as soon as it's encountered (instead of waiting x ms)\n+    suffix: /[\\n\\r\\t]+/,\n+    // Keys from a barcode scanner are usually processed as quick as possible,\n+    // but some scanners can use an intercharacter delay (we support <= 50 ms)\n+    max_time_between_keys_in_ms: 55,\n+\n+    init: function(parent) {\n+        mixins.PropertiesMixin.init.call(this);\n+        this.setParent(parent);\n+        // Keep a reference of the handler functions to use when adding and removing event listeners\n+        this.__keydown_handler = this.keydown_handler.bind(this);\n+        this.__keyup_handler = this.keyup_handler.bind(this);\n+        this.__handler = this.handler.bind(this);\n+        // Bind event handler once the DOM is loaded\n+        $(this.start.bind(this));\n+    },\n+\n+    handle_buffered_keys: function() {\n+        var str = this.buffered_key_events.reduce(function(memo, e) { return memo + String.fromCharCode(e.which) }, '');\n+        var match = str.match(this.regexp);\n+\n+        if (match) {\n+            var barcode = match[1];\n+\n+            core.bus.trigger('barcode_scanned', barcode);\n+\n+            // Dispatch a barcode_scanned DOM event to elements that have barcode_events=\"true\" set.\n+            if (this.buffered_key_events[0].target.getAttribute(\"barcode_events\") === \"true\")\n+                $(this.buffered_key_events[0].target).trigger('barcode_scanned', barcode);\n+        } else {\n+            this.resend_buffered_keys();\n+        }\n+\n+        this.buffered_key_events = [];\n+    },\n+\n+    resend_buffered_keys: function() {\n+        for(var i = 0; i < this.buffered_key_events.length; i++) {\n+            var old_event = this.buffered_key_events[i];","path":"addons/barcodes/static/src/js/barcode_events.js","position":53,"original_position":53,"commit_id":"0f7f49439613e597e1aaec32c6369b0d8d72812c","original_commit_id":"0f7f49439613e597e1aaec32c6369b0d8d72812c","user":{"login":"ged-odoo","id":7579538,"avatar_url":"https://avatars.githubusercontent.com/u/7579538?v=3","gravatar_id":"","url":"https://api.github.com/users/ged-odoo","html_url":"https://github.com/ged-odoo","followers_url":"https://api.github.com/users/ged-odoo/followers","following_url":"https://api.github.com/users/ged-odoo/following{/other_user}","gists_url":"https://api.github.com/users/ged-odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/ged-odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ged-odoo/subscriptions","organizations_url":"https://api.github.com/users/ged-odoo/orgs","repos_url":"https://api.github.com/users/ged-odoo/repos","events_url":"https://api.github.com/users/ged-odoo/events{/privacy}","received_events_url":"https://api.github.com/users/ged-odoo/received_events","type":"User","site_admin":false},"body":"it does not matter for performance, obviously.  The problem is that the scope of that variable is the whole function (funnily enough, not enough people knows this), but it looks like it is local to the loop (it would be if the keyword \"let\" was used instead, and that we were using ES2015).   So, the variable is actually defined outside of the for loop.  And bad things happens (because we have bad programmers, and we don't use linters)","created_at":"2015-07-17T09:21:10Z","updated_at":"2015-07-17T09:21:10Z","html_url":"https://github.com/odoo/odoo/pull/7540#discussion_r34874330","pull_request_url":"https://api.github.com/repos/odoo/odoo/pulls/7540","_links":{"self":{"href":"https://api.github.com/repos/odoo/odoo/pulls/comments/34874330"},"html":{"href":"https://github.com/odoo/odoo/pull/7540#discussion_r34874330"},"pull_request":{"href":"https://api.github.com/repos/odoo/odoo/pulls/7540"}}},"pull_request":{"url":"https://api.github.com/repos/odoo/odoo/pulls/7540","id":39564184,"html_url":"https://github.com/odoo/odoo/pull/7540","diff_url":"https://github.com/odoo/odoo/pull/7540.diff","patch_url":"https://github.com/odoo/odoo/pull/7540.patch","issue_url":"https://api.github.com/repos/odoo/odoo/issues/7540","number":7540,"state":"open","locked":false,"title":"[IMP] web barcodes scanning","user":{"login":"Whisno","id":6009089,"avatar_url":"https://avatars.githubusercontent.com/u/6009089?v=3","gravatar_id":"","url":"https://api.github.com/users/Whisno","html_url":"https://github.com/Whisno","followers_url":"https://api.github.com/users/Whisno/followers","following_url":"https://api.github.com/users/Whisno/following{/other_user}","gists_url":"https://api.github.com/users/Whisno/gists{/gist_id}","starred_url":"https://api.github.com/users/Whisno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Whisno/subscriptions","organizations_url":"https://api.github.com/users/Whisno/orgs","repos_url":"https://api.github.com/users/Whisno/repos","events_url":"https://api.github.com/users/Whisno/events{/privacy}","received_events_url":"https://api.github.com/users/Whisno/received_events","type":"User","site_admin":false},"body":"A BarcodeEvents singleton that tries to interpret keypresses as barcodes is instanciated when module barcodes is installed. It broadcasts 'barcode_scanned' events on core.bus.","created_at":"2015-07-09T09:32:54Z","updated_at":"2015-07-17T09:21:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"00fb5b772e7eee0d043489cfe0c9f83332b6f46e","assignee":{"login":"ged-odoo","id":7579538,"avatar_url":"https://avatars.githubusercontent.com/u/7579538?v=3","gravatar_id":"","url":"https://api.github.com/users/ged-odoo","html_url":"https://github.com/ged-odoo","followers_url":"https://api.github.com/users/ged-odoo/followers","following_url":"https://api.github.com/users/ged-odoo/following{/other_user}","gists_url":"https://api.github.com/users/ged-odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/ged-odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ged-odoo/subscriptions","organizations_url":"https://api.github.com/users/ged-odoo/orgs","repos_url":"https://api.github.com/users/ged-odoo/repos","events_url":"https://api.github.com/users/ged-odoo/events{/privacy}","received_events_url":"https://api.github.com/users/ged-odoo/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/odoo/odoo/pulls/7540/commits","review_comments_url":"https://api.github.com/repos/odoo/odoo/pulls/7540/comments","review_comment_url":"https://api.github.com/repos/odoo/odoo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/odoo/odoo/issues/7540/comments","statuses_url":"https://api.github.com/repos/odoo/odoo/statuses/0f7f49439613e597e1aaec32c6369b0d8d72812c","head":{"label":"odoo-dev:master-imp-web-barcodes-ama","ref":"master-imp-web-barcodes-ama","sha":"0f7f49439613e597e1aaec32c6369b0d8d72812c","user":{"login":"odoo-dev","id":7466976,"avatar_url":"https://avatars.githubusercontent.com/u/7466976?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo-dev","html_url":"https://github.com/odoo-dev","followers_url":"https://api.github.com/users/odoo-dev/followers","following_url":"https://api.github.com/users/odoo-dev/following{/other_user}","gists_url":"https://api.github.com/users/odoo-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo-dev/subscriptions","organizations_url":"https://api.github.com/users/odoo-dev/orgs","repos_url":"https://api.github.com/users/odoo-dev/repos","events_url":"https://api.github.com/users/odoo-dev/events{/privacy}","received_events_url":"https://api.github.com/users/odoo-dev/received_events","type":"Organization","site_admin":false},"repo":{"id":19853934,"name":"odoo","full_name":"odoo-dev/odoo","owner":{"login":"odoo-dev","id":7466976,"avatar_url":"https://avatars.githubusercontent.com/u/7466976?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo-dev","html_url":"https://github.com/odoo-dev","followers_url":"https://api.github.com/users/odoo-dev/followers","following_url":"https://api.github.com/users/odoo-dev/following{/other_user}","gists_url":"https://api.github.com/users/odoo-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo-dev/subscriptions","organizations_url":"https://api.github.com/users/odoo-dev/orgs","repos_url":"https://api.github.com/users/odoo-dev/repos","events_url":"https://api.github.com/users/odoo-dev/events{/privacy}","received_events_url":"https://api.github.com/users/odoo-dev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/odoo-dev/odoo","description":"RD Dev Repository","fork":true,"url":"https://api.github.com/repos/odoo-dev/odoo","forks_url":"https://api.github.com/repos/odoo-dev/odoo/forks","keys_url":"https://api.github.com/repos/odoo-dev/odoo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/odoo-dev/odoo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/odoo-dev/odoo/teams","hooks_url":"https://api.github.com/repos/odoo-dev/odoo/hooks","issue_events_url":"https://api.github.com/repos/odoo-dev/odoo/issues/events{/number}","events_url":"https://api.github.com/repos/odoo-dev/odoo/events","assignees_url":"https://api.github.com/repos/odoo-dev/odoo/assignees{/user}","branches_url":"https://api.github.com/repos/odoo-dev/odoo/branches{/branch}","tags_url":"https://api.github.com/repos/odoo-dev/odoo/tags","blobs_url":"https://api.github.com/repos/odoo-dev/odoo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/odoo-dev/odoo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/odoo-dev/odoo/git/refs{/sha}","trees_url":"https://api.github.com/repos/odoo-dev/odoo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/odoo-dev/odoo/statuses/{sha}","languages_url":"https://api.github.com/repos/odoo-dev/odoo/languages","stargazers_url":"https://api.github.com/repos/odoo-dev/odoo/stargazers","contributors_url":"https://api.github.com/repos/odoo-dev/odoo/contributors","subscribers_url":"https://api.github.com/repos/odoo-dev/odoo/subscribers","subscription_url":"https://api.github.com/repos/odoo-dev/odoo/subscription","commits_url":"https://api.github.com/repos/odoo-dev/odoo/commits{/sha}","git_commits_url":"https://api.github.com/repos/odoo-dev/odoo/git/commits{/sha}","comments_url":"https://api.github.com/repos/odoo-dev/odoo/comments{/number}","issue_comment_url":"https://api.github.com/repos/odoo-dev/odoo/issues/comments{/number}","contents_url":"https://api.github.com/repos/odoo-dev/odoo/contents/{+path}","compare_url":"https://api.github.com/repos/odoo-dev/odoo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/odoo-dev/odoo/merges","archive_url":"https://api.github.com/repos/odoo-dev/odoo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/odoo-dev/odoo/downloads","issues_url":"https://api.github.com/repos/odoo-dev/odoo/issues{/number}","pulls_url":"https://api.github.com/repos/odoo-dev/odoo/pulls{/number}","milestones_url":"https://api.github.com/repos/odoo-dev/odoo/milestones{/number}","notifications_url":"https://api.github.com/repos/odoo-dev/odoo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/odoo-dev/odoo/labels{/name}","releases_url":"https://api.github.com/repos/odoo-dev/odoo/releases{/id}","created_at":"2014-05-16T11:16:19Z","updated_at":"2015-06-17T11:07:18Z","pushed_at":"2015-07-17T09:20:56Z","git_url":"git://github.com/odoo-dev/odoo.git","ssh_url":"git@github.com:odoo-dev/odoo.git","clone_url":"https://github.com/odoo-dev/odoo.git","svn_url":"https://github.com/odoo-dev/odoo","homepage":"https://www.odoo.com","size":1224238,"stargazers_count":57,"watchers_count":57,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":22,"mirror_url":null,"open_issues_count":0,"forks":22,"open_issues":0,"watchers":57,"default_branch":"master"}},"base":{"label":"odoo:master","ref":"master","sha":"3ced0ff61bd5b48e8846c30dc8a972a81f1688f4","user":{"login":"odoo","id":6368483,"avatar_url":"https://avatars.githubusercontent.com/u/6368483?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo","html_url":"https://github.com/odoo","followers_url":"https://api.github.com/users/odoo/followers","following_url":"https://api.github.com/users/odoo/following{/other_user}","gists_url":"https://api.github.com/users/odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo/subscriptions","organizations_url":"https://api.github.com/users/odoo/orgs","repos_url":"https://api.github.com/users/odoo/repos","events_url":"https://api.github.com/users/odoo/events{/privacy}","received_events_url":"https://api.github.com/users/odoo/received_events","type":"Organization","site_admin":false},"repo":{"id":19745004,"name":"odoo","full_name":"odoo/odoo","owner":{"login":"odoo","id":6368483,"avatar_url":"https://avatars.githubusercontent.com/u/6368483?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo","html_url":"https://github.com/odoo","followers_url":"https://api.github.com/users/odoo/followers","following_url":"https://api.github.com/users/odoo/following{/other_user}","gists_url":"https://api.github.com/users/odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo/subscriptions","organizations_url":"https://api.github.com/users/odoo/orgs","repos_url":"https://api.github.com/users/odoo/repos","events_url":"https://api.github.com/users/odoo/events{/privacy}","received_events_url":"https://api.github.com/users/odoo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/odoo/odoo","description":"Odoo (formerly OpenERP). Open Source Apps To Grow Your Business.","fork":false,"url":"https://api.github.com/repos/odoo/odoo","forks_url":"https://api.github.com/repos/odoo/odoo/forks","keys_url":"https://api.github.com/repos/odoo/odoo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/odoo/odoo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/odoo/odoo/teams","hooks_url":"https://api.github.com/repos/odoo/odoo/hooks","issue_events_url":"https://api.github.com/repos/odoo/odoo/issues/events{/number}","events_url":"https://api.github.com/repos/odoo/odoo/events","assignees_url":"https://api.github.com/repos/odoo/odoo/assignees{/user}","branches_url":"https://api.github.com/repos/odoo/odoo/branches{/branch}","tags_url":"https://api.github.com/repos/odoo/odoo/tags","blobs_url":"https://api.github.com/repos/odoo/odoo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/odoo/odoo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/odoo/odoo/git/refs{/sha}","trees_url":"https://api.github.com/repos/odoo/odoo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/odoo/odoo/statuses/{sha}","languages_url":"https://api.github.com/repos/odoo/odoo/languages","stargazers_url":"https://api.github.com/repos/odoo/odoo/stargazers","contributors_url":"https://api.github.com/repos/odoo/odoo/contributors","subscribers_url":"https://api.github.com/repos/odoo/odoo/subscribers","subscription_url":"https://api.github.com/repos/odoo/odoo/subscription","commits_url":"https://api.github.com/repos/odoo/odoo/commits{/sha}","git_commits_url":"https://api.github.com/repos/odoo/odoo/git/commits{/sha}","comments_url":"https://api.github.com/repos/odoo/odoo/comments{/number}","issue_comment_url":"https://api.github.com/repos/odoo/odoo/issues/comments{/number}","contents_url":"https://api.github.com/repos/odoo/odoo/contents/{+path}","compare_url":"https://api.github.com/repos/odoo/odoo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/odoo/odoo/merges","archive_url":"https://api.github.com/repos/odoo/odoo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/odoo/odoo/downloads","issues_url":"https://api.github.com/repos/odoo/odoo/issues{/number}","pulls_url":"https://api.github.com/repos/odoo/odoo/pulls{/number}","milestones_url":"https://api.github.com/repos/odoo/odoo/milestones{/number}","notifications_url":"https://api.github.com/repos/odoo/odoo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/odoo/odoo/labels{/name}","releases_url":"https://api.github.com/repos/odoo/odoo/releases{/id}","created_at":"2014-05-13T15:38:58Z","updated_at":"2015-07-17T06:33:55Z","pushed_at":"2015-07-17T09:20:59Z","git_url":"git://github.com/odoo/odoo.git","ssh_url":"git@github.com:odoo/odoo.git","clone_url":"https://github.com/odoo/odoo.git","svn_url":"https://github.com/odoo/odoo","homepage":"https://www.odoo.com","size":1339272,"stargazers_count":2790,"watchers_count":2790,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2361,"mirror_url":null,"open_issues_count":2426,"forks":2361,"open_issues":2426,"watchers":2790,"default_branch":"8.0"}},"_links":{"self":{"href":"https://api.github.com/repos/odoo/odoo/pulls/7540"},"html":{"href":"https://github.com/odoo/odoo/pull/7540"},"issue":{"href":"https://api.github.com/repos/odoo/odoo/issues/7540"},"comments":{"href":"https://api.github.com/repos/odoo/odoo/issues/7540/comments"},"review_comments":{"href":"https://api.github.com/repos/odoo/odoo/pulls/7540/comments"},"review_comment":{"href":"https://api.github.com/repos/odoo/odoo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/odoo/odoo/pulls/7540/commits"},"statuses":{"href":"https://api.github.com/repos/odoo/odoo/statuses/0f7f49439613e597e1aaec32c6369b0d8d72812c"}}}}