{"action":"created","comment":{"url":"https://api.github.com/repos/isqua/asocial/pulls/comments/65815562","id":65815562,"diff_hunk":"@@ -1,12 +1,145 @@\n+/* global chrome, TimeHelper, FormManager */\n+\n 'use strict';\n-(function() {\n-    var addButton = document.querySelector('#add-button');\n-    var addRuleForm = document.querySelector('#add-rule-form');\n \n-    addButton.addEventListener('click', function(evt) {\n-        evt.preventDefault();\n+var rulesContainer;\n+var deleteRule;\n+var addButton = document.querySelector('#add-button');\n+var addRuleContainer = document.querySelector('#add-rule-container');\n+var editButtonRow = document.querySelector('.edit-buttons-row');\n+var saveButton = document.querySelector('#save-button');\n+var editButton = document.querySelector('#edit-button');\n+var deleteButton = document.querySelector('#delete-button');\n+var rulesTable = document.querySelector('.time-table');\n+var formManager = new FormManager();\n+\n+var DAY_ABBR = {\n+    0: 'Вс',\n+    1: 'Пн',\n+    2: 'Вт',\n+    3: 'Ср',\n+    4: 'Чт',\n+    5: 'Пт',\n+    6: 'Сб'\n+};\n+\n+function Rules(array) {\n+    this.storage = {'rules': array};\n+\n+    this.add = this.add.bind(this);\n+    this.remove = this.remove.bind(this);\n+}\n+\n+Rules.prototype.add = function(object) {\n+    this.storage.rules.push(object);\n+    chrome.storage.sync.set(this.storage);\n+};\n+\n+Rules.prototype.remove = function(number) {\n+    this.storage.rules.splice(number, 1);\n+    chrome.storage.sync.set(this.storage);\n+};\n+\n+Rules.prototype.edit = function(number, object) {\n+    this.storage.rules[number] = object;\n+    chrome.storage.sync.set(this.storage);\n+};\n+\n+function drawTableRow(rule, number) {\n+    var template = document.querySelector('#row-template');\n+    var templateRow = template.content.querySelector('.rule-line');\n+    var row = templateRow.cloneNode(true);\n+\n+    var days = row.querySelector('.days');\n+    var time = row.querySelector('.time');\n+    var networks = row.querySelector('.networks');\n+\n+    function createNetworkIcon(name) {\n+        var networkBlock = document.createElement('span');\n+        networkBlock.classList.add('icon');\n+        networkBlock.classList.add('icon-' + name);\n+        networks.appendChild(networkBlock);\n+    }\n+\n+    days.textContent = rule.days.map(day => DAY_ABBR[day]).join(', ');\n+    time.innerHTML = TimeHelper.formatPeriod(rule.start, rule.end);\n+\n+    Object.keys(rule.sites).filter(k => rule.sites[k]).forEach(createNetworkIcon);\n+\n+    row.dataset.number = number;\n+\n+    rulesTable.appendChild(row);\n+}\n+\n+function drawTable() {\n+    rulesTable.innerHTML = '';\n+    rulesContainer.storage.rules.forEach(drawTableRow);\n+}\n+\n+addButton.addEventListener('click', function(evt) {\n+    evt.preventDefault();\n+\n+    addButton.classList.add('hidden');\n+    addRuleContainer.classList.add('showed');\n+    editButtonRow.classList.add('hidden');\n+    saveButton.classList.remove('hidden');\n+});\n+\n+saveButton.addEventListener('click', function(evt) {\n+    evt.preventDefault();\n+    if (formManager.check()) {","path":"asocial/options/options.js","position":95,"original_position":95,"commit_id":"90c4cf79afb6afb6f99aa2531fba606f926666df","original_commit_id":"90c4cf79afb6afb6f99aa2531fba606f926666df","user":{"login":"isqua","id":529247,"avatar_url":"https://avatars.githubusercontent.com/u/529247?v=3","gravatar_id":"","url":"https://api.github.com/users/isqua","html_url":"https://github.com/isqua","followers_url":"https://api.github.com/users/isqua/followers","following_url":"https://api.github.com/users/isqua/following{/other_user}","gists_url":"https://api.github.com/users/isqua/gists{/gist_id}","starred_url":"https://api.github.com/users/isqua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isqua/subscriptions","organizations_url":"https://api.github.com/users/isqua/orgs","repos_url":"https://api.github.com/users/isqua/repos","events_url":"https://api.github.com/users/isqua/events{/privacy}","received_events_url":"https://api.github.com/users/isqua/received_events","type":"User","site_admin":false},"body":"Форма — `EventEmitter`. Она сама слушает клики на своих кнопках. \r\n\r\n```js\r\nsaveButton.addEventListener('click', (e) => {\r\n  if (this.check()) {\r\n   // ..\r\n  }\r\n});\r\n```\r\n\r\nПо клику проверяет, валидна ли она. Если произошёл клик и она валидна, триггерит событие. Типа:\r\n\r\n```js\r\nthis.trigger('save', this.make()); // Форма бросает событие `save` и отдаёт с ним данные.\r\n```\r\nили\r\n```js\r\nthis.trigger('add', this.make()); // Нажали кнопку «Добавить», форма валидна, выбросила событие.\r\n```\r\n\r\nА в этом файле у тебя будет типа:\r\n\r\n```js\r\nformManager.on('add', (rule) => {\r\n  rulesContainer.add(rule);\r\n});\r\n```\r\n\r\nВ результате в `options.js` про кнопки формы не должно ничего остаться.","created_at":"2016-06-05T11:06:24Z","updated_at":"2016-06-05T11:06:24Z","html_url":"https://github.com/isqua/asocial/pull/9#discussion_r65815562","pull_request_url":"https://api.github.com/repos/isqua/asocial/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/isqua/asocial/pulls/comments/65815562"},"html":{"href":"https://github.com/isqua/asocial/pull/9#discussion_r65815562"},"pull_request":{"href":"https://api.github.com/repos/isqua/asocial/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/isqua/asocial/pulls/9","id":72429659,"html_url":"https://github.com/isqua/asocial/pull/9","diff_url":"https://github.com/isqua/asocial/pull/9.diff","patch_url":"https://github.com/isqua/asocial/pull/9.patch","issue_url":"https://api.github.com/repos/isqua/asocial/issues/9","number":9,"state":"open","locked":false,"title":"Made functions for saving and getting options; Fix #8","user":{"login":"fyvfyv","id":3251438,"avatar_url":"https://avatars.githubusercontent.com/u/3251438?v=3","gravatar_id":"","url":"https://api.github.com/users/fyvfyv","html_url":"https://github.com/fyvfyv","followers_url":"https://api.github.com/users/fyvfyv/followers","following_url":"https://api.github.com/users/fyvfyv/following{/other_user}","gists_url":"https://api.github.com/users/fyvfyv/gists{/gist_id}","starred_url":"https://api.github.com/users/fyvfyv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fyvfyv/subscriptions","organizations_url":"https://api.github.com/users/fyvfyv/orgs","repos_url":"https://api.github.com/users/fyvfyv/repos","events_url":"https://api.github.com/users/fyvfyv/events{/privacy}","received_events_url":"https://api.github.com/users/fyvfyv/received_events","type":"User","site_admin":false},"body":"Сделал [сохранение настроек](https://github.com/isqua/asocial/issues/8).","created_at":"2016-06-02T22:44:02Z","updated_at":"2016-06-05T11:06:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1f61570ccf1d749e62b18195099f2155ef2623f3","assignee":{"login":"isqua","id":529247,"avatar_url":"https://avatars.githubusercontent.com/u/529247?v=3","gravatar_id":"","url":"https://api.github.com/users/isqua","html_url":"https://github.com/isqua","followers_url":"https://api.github.com/users/isqua/followers","following_url":"https://api.github.com/users/isqua/following{/other_user}","gists_url":"https://api.github.com/users/isqua/gists{/gist_id}","starred_url":"https://api.github.com/users/isqua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isqua/subscriptions","organizations_url":"https://api.github.com/users/isqua/orgs","repos_url":"https://api.github.com/users/isqua/repos","events_url":"https://api.github.com/users/isqua/events{/privacy}","received_events_url":"https://api.github.com/users/isqua/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/isqua/asocial/pulls/9/commits","review_comments_url":"https://api.github.com/repos/isqua/asocial/pulls/9/comments","review_comment_url":"https://api.github.com/repos/isqua/asocial/pulls/comments{/number}","comments_url":"https://api.github.com/repos/isqua/asocial/issues/9/comments","statuses_url":"https://api.github.com/repos/isqua/asocial/statuses/90c4cf79afb6afb6f99aa2531fba606f926666df","head":{"label":"isqua:save-options","ref":"save-options","sha":"90c4cf79afb6afb6f99aa2531fba606f926666df","user":{"login":"isqua","id":529247,"avatar_url":"https://avatars.githubusercontent.com/u/529247?v=3","gravatar_id":"","url":"https://api.github.com/users/isqua","html_url":"https://github.com/isqua","followers_url":"https://api.github.com/users/isqua/followers","following_url":"https://api.github.com/users/isqua/following{/other_user}","gists_url":"https://api.github.com/users/isqua/gists{/gist_id}","starred_url":"https://api.github.com/users/isqua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isqua/subscriptions","organizations_url":"https://api.github.com/users/isqua/orgs","repos_url":"https://api.github.com/users/isqua/repos","events_url":"https://api.github.com/users/isqua/events{/privacy}","received_events_url":"https://api.github.com/users/isqua/received_events","type":"User","site_admin":false},"repo":{"id":59510890,"name":"asocial","full_name":"isqua/asocial","owner":{"login":"isqua","id":529247,"avatar_url":"https://avatars.githubusercontent.com/u/529247?v=3","gravatar_id":"","url":"https://api.github.com/users/isqua","html_url":"https://github.com/isqua","followers_url":"https://api.github.com/users/isqua/followers","following_url":"https://api.github.com/users/isqua/following{/other_user}","gists_url":"https://api.github.com/users/isqua/gists{/gist_id}","starred_url":"https://api.github.com/users/isqua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isqua/subscriptions","organizations_url":"https://api.github.com/users/isqua/orgs","repos_url":"https://api.github.com/users/isqua/repos","events_url":"https://api.github.com/users/isqua/events{/privacy}","received_events_url":"https://api.github.com/users/isqua/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/isqua/asocial","description":"","fork":false,"url":"https://api.github.com/repos/isqua/asocial","forks_url":"https://api.github.com/repos/isqua/asocial/forks","keys_url":"https://api.github.com/repos/isqua/asocial/keys{/key_id}","collaborators_url":"https://api.github.com/repos/isqua/asocial/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/isqua/asocial/teams","hooks_url":"https://api.github.com/repos/isqua/asocial/hooks","issue_events_url":"https://api.github.com/repos/isqua/asocial/issues/events{/number}","events_url":"https://api.github.com/repos/isqua/asocial/events","assignees_url":"https://api.github.com/repos/isqua/asocial/assignees{/user}","branches_url":"https://api.github.com/repos/isqua/asocial/branches{/branch}","tags_url":"https://api.github.com/repos/isqua/asocial/tags","blobs_url":"https://api.github.com/repos/isqua/asocial/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/isqua/asocial/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/isqua/asocial/git/refs{/sha}","trees_url":"https://api.github.com/repos/isqua/asocial/git/trees{/sha}","statuses_url":"https://api.github.com/repos/isqua/asocial/statuses/{sha}","languages_url":"https://api.github.com/repos/isqua/asocial/languages","stargazers_url":"https://api.github.com/repos/isqua/asocial/stargazers","contributors_url":"https://api.github.com/repos/isqua/asocial/contributors","subscribers_url":"https://api.github.com/repos/isqua/asocial/subscribers","subscription_url":"https://api.github.com/repos/isqua/asocial/subscription","commits_url":"https://api.github.com/repos/isqua/asocial/commits{/sha}","git_commits_url":"https://api.github.com/repos/isqua/asocial/git/commits{/sha}","comments_url":"https://api.github.com/repos/isqua/asocial/comments{/number}","issue_comment_url":"https://api.github.com/repos/isqua/asocial/issues/comments{/number}","contents_url":"https://api.github.com/repos/isqua/asocial/contents/{+path}","compare_url":"https://api.github.com/repos/isqua/asocial/compare/{base}...{head}","merges_url":"https://api.github.com/repos/isqua/asocial/merges","archive_url":"https://api.github.com/repos/isqua/asocial/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/isqua/asocial/downloads","issues_url":"https://api.github.com/repos/isqua/asocial/issues{/number}","pulls_url":"https://api.github.com/repos/isqua/asocial/pulls{/number}","milestones_url":"https://api.github.com/repos/isqua/asocial/milestones{/number}","notifications_url":"https://api.github.com/repos/isqua/asocial/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/isqua/asocial/labels{/name}","releases_url":"https://api.github.com/repos/isqua/asocial/releases{/id}","deployments_url":"https://api.github.com/repos/isqua/asocial/deployments","created_at":"2016-05-23T19:06:14Z","updated_at":"2016-05-29T12:01:49Z","pushed_at":"2016-06-04T23:01:03Z","git_url":"git://github.com/isqua/asocial.git","ssh_url":"git@github.com:isqua/asocial.git","clone_url":"https://github.com/isqua/asocial.git","svn_url":"https://github.com/isqua/asocial","homepage":null,"size":568,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"isqua:master","ref":"master","sha":"444fa08a362af76bf0fca1e1ee29f963985c6b06","user":{"login":"isqua","id":529247,"avatar_url":"https://avatars.githubusercontent.com/u/529247?v=3","gravatar_id":"","url":"https://api.github.com/users/isqua","html_url":"https://github.com/isqua","followers_url":"https://api.github.com/users/isqua/followers","following_url":"https://api.github.com/users/isqua/following{/other_user}","gists_url":"https://api.github.com/users/isqua/gists{/gist_id}","starred_url":"https://api.github.com/users/isqua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isqua/subscriptions","organizations_url":"https://api.github.com/users/isqua/orgs","repos_url":"https://api.github.com/users/isqua/repos","events_url":"https://api.github.com/users/isqua/events{/privacy}","received_events_url":"https://api.github.com/users/isqua/received_events","type":"User","site_admin":false},"repo":{"id":59510890,"name":"asocial","full_name":"isqua/asocial","owner":{"login":"isqua","id":529247,"avatar_url":"https://avatars.githubusercontent.com/u/529247?v=3","gravatar_id":"","url":"https://api.github.com/users/isqua","html_url":"https://github.com/isqua","followers_url":"https://api.github.com/users/isqua/followers","following_url":"https://api.github.com/users/isqua/following{/other_user}","gists_url":"https://api.github.com/users/isqua/gists{/gist_id}","starred_url":"https://api.github.com/users/isqua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isqua/subscriptions","organizations_url":"https://api.github.com/users/isqua/orgs","repos_url":"https://api.github.com/users/isqua/repos","events_url":"https://api.github.com/users/isqua/events{/privacy}","received_events_url":"https://api.github.com/users/isqua/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/isqua/asocial","description":"","fork":false,"url":"https://api.github.com/repos/isqua/asocial","forks_url":"https://api.github.com/repos/isqua/asocial/forks","keys_url":"https://api.github.com/repos/isqua/asocial/keys{/key_id}","collaborators_url":"https://api.github.com/repos/isqua/asocial/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/isqua/asocial/teams","hooks_url":"https://api.github.com/repos/isqua/asocial/hooks","issue_events_url":"https://api.github.com/repos/isqua/asocial/issues/events{/number}","events_url":"https://api.github.com/repos/isqua/asocial/events","assignees_url":"https://api.github.com/repos/isqua/asocial/assignees{/user}","branches_url":"https://api.github.com/repos/isqua/asocial/branches{/branch}","tags_url":"https://api.github.com/repos/isqua/asocial/tags","blobs_url":"https://api.github.com/repos/isqua/asocial/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/isqua/asocial/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/isqua/asocial/git/refs{/sha}","trees_url":"https://api.github.com/repos/isqua/asocial/git/trees{/sha}","statuses_url":"https://api.github.com/repos/isqua/asocial/statuses/{sha}","languages_url":"https://api.github.com/repos/isqua/asocial/languages","stargazers_url":"https://api.github.com/repos/isqua/asocial/stargazers","contributors_url":"https://api.github.com/repos/isqua/asocial/contributors","subscribers_url":"https://api.github.com/repos/isqua/asocial/subscribers","subscription_url":"https://api.github.com/repos/isqua/asocial/subscription","commits_url":"https://api.github.com/repos/isqua/asocial/commits{/sha}","git_commits_url":"https://api.github.com/repos/isqua/asocial/git/commits{/sha}","comments_url":"https://api.github.com/repos/isqua/asocial/comments{/number}","issue_comment_url":"https://api.github.com/repos/isqua/asocial/issues/comments{/number}","contents_url":"https://api.github.com/repos/isqua/asocial/contents/{+path}","compare_url":"https://api.github.com/repos/isqua/asocial/compare/{base}...{head}","merges_url":"https://api.github.com/repos/isqua/asocial/merges","archive_url":"https://api.github.com/repos/isqua/asocial/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/isqua/asocial/downloads","issues_url":"https://api.github.com/repos/isqua/asocial/issues{/number}","pulls_url":"https://api.github.com/repos/isqua/asocial/pulls{/number}","milestones_url":"https://api.github.com/repos/isqua/asocial/milestones{/number}","notifications_url":"https://api.github.com/repos/isqua/asocial/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/isqua/asocial/labels{/name}","releases_url":"https://api.github.com/repos/isqua/asocial/releases{/id}","deployments_url":"https://api.github.com/repos/isqua/asocial/deployments","created_at":"2016-05-23T19:06:14Z","updated_at":"2016-05-29T12:01:49Z","pushed_at":"2016-06-04T23:01:03Z","git_url":"git://github.com/isqua/asocial.git","ssh_url":"git@github.com:isqua/asocial.git","clone_url":"https://github.com/isqua/asocial.git","svn_url":"https://github.com/isqua/asocial","homepage":null,"size":568,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/isqua/asocial/pulls/9"},"html":{"href":"https://github.com/isqua/asocial/pull/9"},"issue":{"href":"https://api.github.com/repos/isqua/asocial/issues/9"},"comments":{"href":"https://api.github.com/repos/isqua/asocial/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/isqua/asocial/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/isqua/asocial/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/isqua/asocial/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/isqua/asocial/statuses/90c4cf79afb6afb6f99aa2531fba606f926666df"}}}}
{"actor":{"display_login":"isqua"}}