{"action":"created","comment":{"url":"https://api.github.com/repos/MateusJabour/Car-Store/pulls/comments/51366276","id":51366276,"diff_hunk":"@@ -0,0 +1,109 @@\n+(function ($, doc) {\n+  'use strict';\n+\n+  /*\n+  Vamos estruturar um pequeno app utilizando módulos.\n+  Nosso APP vai ser um cadastro de carros. Vamos fazê-lo por partes.\n+  A primeira etapa vai ser o cadastro de veículos, de deverá funcionar da\n+  seguinte forma:\n+  - No início do arquivo, deverá ter as informações da sua empresa - nome e\n+  telefone (já vamos ver como isso vai ser feito)\n+  - Ao abrir a tela, ainda não teremos carros cadastrados. Então deverá ter\n+  um formulário para cadastro do carro, com os seguintes campos:\n+    - Imagem do carro (deverá aceitar uma URL)\n+    - Marca / Modelo\n+    - Ano\n+    - Placa\n+    - Cor\n+    - e um botão \"Cadastrar\"\n+\n+  Logo abaixo do formulário, deverá ter uma tabela que irá mostrar todos os\n+  carros cadastrados. Ao clicar no botão de cadastrar, o novo carro deverá\n+  aparecer no final da tabela.\n+\n+  Agora você precisa dar um nome para o seu app. Imagine que ele seja uma\n+  empresa que vende carros. Esse nosso app será só um catálogo, por enquanto.\n+  Dê um nome para a empresa e um telefone fictício, preechendo essas informações\n+  no arquivo company.json que já está criado.\n+\n+  Essas informações devem ser adicionadas no HTML via Ajax.\n+\n+  Parte técnica:\n+  Separe o nosso módulo de DOM criado nas últimas aulas em\n+  um arquivo DOM.js.\n+\n+  E aqui nesse arquivo, faça a lógica para cadastrar os carros, em um módulo\n+  que será nomeado de \"app\".\n+  */\n+\n+  function app () {\n+    var $inputImage = $('[data-js=\"input-image\"]');\n+    var $inputBrand = $('[data-js=\"input-brand\"]');\n+    var $inputYear = $('[data-js=\"input-year\"]');\n+    var $inputColor = $('[data-js=\"input-color\"]');\n+    var $carTable = $('[data-js=\"car-table\"]');\n+\n+    return {\n+      init: function init () {\n+        this.initEvents();\n+        this.makeRequest('GET', '/company.json', this.handleAjax);\n+      },\n+\n+      initEvents: function initEvents () {\n+        $('[data-js=\"submit-form\"]').on('click', this.handleSubmit);\n+\n+      },\n+\n+      isRequestOk: function isRequestOk (request) {\n+        return request.readyState === 4 && request.status === 200;\n+      },\n+    \n+      makeRequest: function makeRequest (method, url, callback) {\n+        var ajax = new XMLHttpRequest();\n+        ajax.open(method, url);\n+        ajax.send();\n+        ajax.addEventListener('readystatechange', callback);\n+      },\n+    \n+      handleAjax: function handleAjax () {\n+      if( app().isRequestOk(this) ) {\n+        try{\n+            var data = JSON.parse(this.responseText);\n+            $('[data-js=\"interprise-name\"]').get().textContent = data.name;\n+            $('[data-js=\"interprise-number\"]').get().textContent = data.phone;\n+          }catch(e){\n+            console.log(e);\n+          }\n+        }\n+      },\n+\n+      emptySubmits: function emptySubmits () {\n+        $inputImage.get().value = '';\n+        $inputBrand.get().value = '';\n+        $inputYear.get().value = '';\n+        $inputColor.get().value = '';\n+      },\n+\n+      handleSubmit: function handleSubmit (event) {\n+        event.preventDefault();\n+        $carTable.get().insertAdjacentHTML('beforeend', '<tr>'+ \n+          '<td>' + $inputImage.get().value + '</td>' +\n+          '<td>' + $inputBrand.get().value + '</td>' +\n+          '<td>' + $inputYear.get().value + '</td>' +\n+          '<td>' + $inputColor.get().value + '</td>' +\n+          '<td><button type=\"submit\" data-js=\"remove-button\">Remover</button></td>' +\n+          '</tr>');\n+        $('[data-js=\"remove-button\"]').on('click', app().handleRemoveButton);\n+        app().emptySubmits();\n+      },\n+\n+      handleRemoveButton: function handleRemoveButton (event) {\n+          event.preventDefault();\n+          $carTable.get().removeChild(this.parentNode.parentNode.parentNode);","path":"challenge-29.js","position":102,"original_position":102,"commit_id":"fd06192119acbd0f964f0b47ad2c50ae3fda7379","original_commit_id":"fd06192119acbd0f964f0b47ad2c50ae3fda7379","user":{"login":"fdaciuk","id":487669,"avatar_url":"https://avatars.githubusercontent.com/u/487669?v=3","gravatar_id":"","url":"https://api.github.com/users/fdaciuk","html_url":"https://github.com/fdaciuk","followers_url":"https://api.github.com/users/fdaciuk/followers","following_url":"https://api.github.com/users/fdaciuk/following{/other_user}","gists_url":"https://api.github.com/users/fdaciuk/gists{/gist_id}","starred_url":"https://api.github.com/users/fdaciuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fdaciuk/subscriptions","organizations_url":"https://api.github.com/users/fdaciuk/orgs","repos_url":"https://api.github.com/users/fdaciuk/repos","events_url":"https://api.github.com/users/fdaciuk/events{/privacy}","received_events_url":"https://api.github.com/users/fdaciuk/received_events","type":"User","site_admin":false},"body":"Só tem um problema de usar dessa forma: \r\nSe você precisar modificar sua marcação HTML, vai precisar modificar também essa regra. Imagine o caso de você precisar adicionar uma `div` ou um `span` dentro do `td`, já vai quebrar a funcionalidade :)\r\n\r\nQual a melhor forma de resolver?\r\n\r\nA cada linha criada, você pode criar um ID e atrelar à `tr` com um `data-js`, e adicionar um `data-tr-id` no botão, por exemplo. Ao clicar no botão de remover, você simplesmente pega o valor dessa propriedade e remove o `tr` inteiro :D ","created_at":"2016-01-31T20:02:18Z","updated_at":"2016-01-31T20:02:18Z","html_url":"https://github.com/MateusJabour/Car-Store/pull/2#discussion_r51366276","pull_request_url":"https://api.github.com/repos/MateusJabour/Car-Store/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/MateusJabour/Car-Store/pulls/comments/51366276"},"html":{"href":"https://github.com/MateusJabour/Car-Store/pull/2#discussion_r51366276"},"pull_request":{"href":"https://api.github.com/repos/MateusJabour/Car-Store/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/MateusJabour/Car-Store/pulls/2","id":55523216,"html_url":"https://github.com/MateusJabour/Car-Store/pull/2","diff_url":"https://github.com/MateusJabour/Car-Store/pull/2.diff","patch_url":"https://github.com/MateusJabour/Car-Store/pull/2.patch","issue_url":"https://api.github.com/repos/MateusJabour/Car-Store/issues/2","number":2,"state":"open","locked":false,"title":"Challenge 31","user":{"login":"MateusJabour","id":11710000,"avatar_url":"https://avatars.githubusercontent.com/u/11710000?v=3","gravatar_id":"","url":"https://api.github.com/users/MateusJabour","html_url":"https://github.com/MateusJabour","followers_url":"https://api.github.com/users/MateusJabour/followers","following_url":"https://api.github.com/users/MateusJabour/following{/other_user}","gists_url":"https://api.github.com/users/MateusJabour/gists{/gist_id}","starred_url":"https://api.github.com/users/MateusJabour/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MateusJabour/subscriptions","organizations_url":"https://api.github.com/users/MateusJabour/orgs","repos_url":"https://api.github.com/users/MateusJabour/repos","events_url":"https://api.github.com/users/MateusJabour/events{/privacy}","received_events_url":"https://api.github.com/users/MateusJabour/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-01-08T23:17:30Z","updated_at":"2016-01-31T20:02:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f7a6514645cc3b94a9fa9b9e818da57b4de22492","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/MateusJabour/Car-Store/pulls/2/commits","review_comments_url":"https://api.github.com/repos/MateusJabour/Car-Store/pulls/2/comments","review_comment_url":"https://api.github.com/repos/MateusJabour/Car-Store/pulls/comments{/number}","comments_url":"https://api.github.com/repos/MateusJabour/Car-Store/issues/2/comments","statuses_url":"https://api.github.com/repos/MateusJabour/Car-Store/statuses/fd06192119acbd0f964f0b47ad2c50ae3fda7379","head":{"label":"MateusJabour:challenge-31","ref":"challenge-31","sha":"fd06192119acbd0f964f0b47ad2c50ae3fda7379","user":{"login":"MateusJabour","id":11710000,"avatar_url":"https://avatars.githubusercontent.com/u/11710000?v=3","gravatar_id":"","url":"https://api.github.com/users/MateusJabour","html_url":"https://github.com/MateusJabour","followers_url":"https://api.github.com/users/MateusJabour/followers","following_url":"https://api.github.com/users/MateusJabour/following{/other_user}","gists_url":"https://api.github.com/users/MateusJabour/gists{/gist_id}","starred_url":"https://api.github.com/users/MateusJabour/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MateusJabour/subscriptions","organizations_url":"https://api.github.com/users/MateusJabour/orgs","repos_url":"https://api.github.com/users/MateusJabour/repos","events_url":"https://api.github.com/users/MateusJabour/events{/privacy}","received_events_url":"https://api.github.com/users/MateusJabour/received_events","type":"User","site_admin":false},"repo":{"id":49295239,"name":"Car-Store","full_name":"MateusJabour/Car-Store","owner":{"login":"MateusJabour","id":11710000,"avatar_url":"https://avatars.githubusercontent.com/u/11710000?v=3","gravatar_id":"","url":"https://api.github.com/users/MateusJabour","html_url":"https://github.com/MateusJabour","followers_url":"https://api.github.com/users/MateusJabour/followers","following_url":"https://api.github.com/users/MateusJabour/following{/other_user}","gists_url":"https://api.github.com/users/MateusJabour/gists{/gist_id}","starred_url":"https://api.github.com/users/MateusJabour/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MateusJabour/subscriptions","organizations_url":"https://api.github.com/users/MateusJabour/orgs","repos_url":"https://api.github.com/users/MateusJabour/repos","events_url":"https://api.github.com/users/MateusJabour/events{/privacy}","received_events_url":"https://api.github.com/users/MateusJabour/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/MateusJabour/Car-Store","description":"","fork":false,"url":"https://api.github.com/repos/MateusJabour/Car-Store","forks_url":"https://api.github.com/repos/MateusJabour/Car-Store/forks","keys_url":"https://api.github.com/repos/MateusJabour/Car-Store/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MateusJabour/Car-Store/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MateusJabour/Car-Store/teams","hooks_url":"https://api.github.com/repos/MateusJabour/Car-Store/hooks","issue_events_url":"https://api.github.com/repos/MateusJabour/Car-Store/issues/events{/number}","events_url":"https://api.github.com/repos/MateusJabour/Car-Store/events","assignees_url":"https://api.github.com/repos/MateusJabour/Car-Store/assignees{/user}","branches_url":"https://api.github.com/repos/MateusJabour/Car-Store/branches{/branch}","tags_url":"https://api.github.com/repos/MateusJabour/Car-Store/tags","blobs_url":"https://api.github.com/repos/MateusJabour/Car-Store/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MateusJabour/Car-Store/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MateusJabour/Car-Store/git/refs{/sha}","trees_url":"https://api.github.com/repos/MateusJabour/Car-Store/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MateusJabour/Car-Store/statuses/{sha}","languages_url":"https://api.github.com/repos/MateusJabour/Car-Store/languages","stargazers_url":"https://api.github.com/repos/MateusJabour/Car-Store/stargazers","contributors_url":"https://api.github.com/repos/MateusJabour/Car-Store/contributors","subscribers_url":"https://api.github.com/repos/MateusJabour/Car-Store/subscribers","subscription_url":"https://api.github.com/repos/MateusJabour/Car-Store/subscription","commits_url":"https://api.github.com/repos/MateusJabour/Car-Store/commits{/sha}","git_commits_url":"https://api.github.com/repos/MateusJabour/Car-Store/git/commits{/sha}","comments_url":"https://api.github.com/repos/MateusJabour/Car-Store/comments{/number}","issue_comment_url":"https://api.github.com/repos/MateusJabour/Car-Store/issues/comments{/number}","contents_url":"https://api.github.com/repos/MateusJabour/Car-Store/contents/{+path}","compare_url":"https://api.github.com/repos/MateusJabour/Car-Store/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MateusJabour/Car-Store/merges","archive_url":"https://api.github.com/repos/MateusJabour/Car-Store/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MateusJabour/Car-Store/downloads","issues_url":"https://api.github.com/repos/MateusJabour/Car-Store/issues{/number}","pulls_url":"https://api.github.com/repos/MateusJabour/Car-Store/pulls{/number}","milestones_url":"https://api.github.com/repos/MateusJabour/Car-Store/milestones{/number}","notifications_url":"https://api.github.com/repos/MateusJabour/Car-Store/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MateusJabour/Car-Store/labels{/name}","releases_url":"https://api.github.com/repos/MateusJabour/Car-Store/releases{/id}","deployments_url":"https://api.github.com/repos/MateusJabour/Car-Store/deployments","created_at":"2016-01-08T20:44:11Z","updated_at":"2016-01-08T20:44:11Z","pushed_at":"2016-01-13T23:14:59Z","git_url":"git://github.com/MateusJabour/Car-Store.git","ssh_url":"git@github.com:MateusJabour/Car-Store.git","clone_url":"https://github.com/MateusJabour/Car-Store.git","svn_url":"https://github.com/MateusJabour/Car-Store","homepage":null,"size":484,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"base":{"label":"MateusJabour:master","ref":"master","sha":"ba0104a877deacb11667729c931d4cb64e26ce70","user":{"login":"MateusJabour","id":11710000,"avatar_url":"https://avatars.githubusercontent.com/u/11710000?v=3","gravatar_id":"","url":"https://api.github.com/users/MateusJabour","html_url":"https://github.com/MateusJabour","followers_url":"https://api.github.com/users/MateusJabour/followers","following_url":"https://api.github.com/users/MateusJabour/following{/other_user}","gists_url":"https://api.github.com/users/MateusJabour/gists{/gist_id}","starred_url":"https://api.github.com/users/MateusJabour/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MateusJabour/subscriptions","organizations_url":"https://api.github.com/users/MateusJabour/orgs","repos_url":"https://api.github.com/users/MateusJabour/repos","events_url":"https://api.github.com/users/MateusJabour/events{/privacy}","received_events_url":"https://api.github.com/users/MateusJabour/received_events","type":"User","site_admin":false},"repo":{"id":49295239,"name":"Car-Store","full_name":"MateusJabour/Car-Store","owner":{"login":"MateusJabour","id":11710000,"avatar_url":"https://avatars.githubusercontent.com/u/11710000?v=3","gravatar_id":"","url":"https://api.github.com/users/MateusJabour","html_url":"https://github.com/MateusJabour","followers_url":"https://api.github.com/users/MateusJabour/followers","following_url":"https://api.github.com/users/MateusJabour/following{/other_user}","gists_url":"https://api.github.com/users/MateusJabour/gists{/gist_id}","starred_url":"https://api.github.com/users/MateusJabour/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MateusJabour/subscriptions","organizations_url":"https://api.github.com/users/MateusJabour/orgs","repos_url":"https://api.github.com/users/MateusJabour/repos","events_url":"https://api.github.com/users/MateusJabour/events{/privacy}","received_events_url":"https://api.github.com/users/MateusJabour/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/MateusJabour/Car-Store","description":"","fork":false,"url":"https://api.github.com/repos/MateusJabour/Car-Store","forks_url":"https://api.github.com/repos/MateusJabour/Car-Store/forks","keys_url":"https://api.github.com/repos/MateusJabour/Car-Store/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MateusJabour/Car-Store/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MateusJabour/Car-Store/teams","hooks_url":"https://api.github.com/repos/MateusJabour/Car-Store/hooks","issue_events_url":"https://api.github.com/repos/MateusJabour/Car-Store/issues/events{/number}","events_url":"https://api.github.com/repos/MateusJabour/Car-Store/events","assignees_url":"https://api.github.com/repos/MateusJabour/Car-Store/assignees{/user}","branches_url":"https://api.github.com/repos/MateusJabour/Car-Store/branches{/branch}","tags_url":"https://api.github.com/repos/MateusJabour/Car-Store/tags","blobs_url":"https://api.github.com/repos/MateusJabour/Car-Store/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MateusJabour/Car-Store/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MateusJabour/Car-Store/git/refs{/sha}","trees_url":"https://api.github.com/repos/MateusJabour/Car-Store/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MateusJabour/Car-Store/statuses/{sha}","languages_url":"https://api.github.com/repos/MateusJabour/Car-Store/languages","stargazers_url":"https://api.github.com/repos/MateusJabour/Car-Store/stargazers","contributors_url":"https://api.github.com/repos/MateusJabour/Car-Store/contributors","subscribers_url":"https://api.github.com/repos/MateusJabour/Car-Store/subscribers","subscription_url":"https://api.github.com/repos/MateusJabour/Car-Store/subscription","commits_url":"https://api.github.com/repos/MateusJabour/Car-Store/commits{/sha}","git_commits_url":"https://api.github.com/repos/MateusJabour/Car-Store/git/commits{/sha}","comments_url":"https://api.github.com/repos/MateusJabour/Car-Store/comments{/number}","issue_comment_url":"https://api.github.com/repos/MateusJabour/Car-Store/issues/comments{/number}","contents_url":"https://api.github.com/repos/MateusJabour/Car-Store/contents/{+path}","compare_url":"https://api.github.com/repos/MateusJabour/Car-Store/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MateusJabour/Car-Store/merges","archive_url":"https://api.github.com/repos/MateusJabour/Car-Store/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MateusJabour/Car-Store/downloads","issues_url":"https://api.github.com/repos/MateusJabour/Car-Store/issues{/number}","pulls_url":"https://api.github.com/repos/MateusJabour/Car-Store/pulls{/number}","milestones_url":"https://api.github.com/repos/MateusJabour/Car-Store/milestones{/number}","notifications_url":"https://api.github.com/repos/MateusJabour/Car-Store/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MateusJabour/Car-Store/labels{/name}","releases_url":"https://api.github.com/repos/MateusJabour/Car-Store/releases{/id}","deployments_url":"https://api.github.com/repos/MateusJabour/Car-Store/deployments","created_at":"2016-01-08T20:44:11Z","updated_at":"2016-01-08T20:44:11Z","pushed_at":"2016-01-13T23:14:59Z","git_url":"git://github.com/MateusJabour/Car-Store.git","ssh_url":"git@github.com:MateusJabour/Car-Store.git","clone_url":"https://github.com/MateusJabour/Car-Store.git","svn_url":"https://github.com/MateusJabour/Car-Store","homepage":null,"size":484,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/MateusJabour/Car-Store/pulls/2"},"html":{"href":"https://github.com/MateusJabour/Car-Store/pull/2"},"issue":{"href":"https://api.github.com/repos/MateusJabour/Car-Store/issues/2"},"comments":{"href":"https://api.github.com/repos/MateusJabour/Car-Store/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/MateusJabour/Car-Store/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/MateusJabour/Car-Store/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/MateusJabour/Car-Store/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/MateusJabour/Car-Store/statuses/fd06192119acbd0f964f0b47ad2c50ae3fda7379"}}}}