{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/comments/24564245","id":24564245,"diff_hunk":"@@ -0,0 +1,602 @@\n+/**\n+ * SimPinDialog is a constructor function that can help us process\n+ * any simpin related works like enable/disable lock, change pins ... etc.\n+ *\n+ * @module @SimPinDialog\n+ */\n+define(function() {\n+  'use strict';\n+\n+  var SettingsUtils = require('modules/settings_utils');\n+  var l10n = window.navigator.mozL10n;\n+\n+  function SimPinDialog(elements) {\n+    this._localize = l10n.setAttributes;\n+    this._elements = elements;\n+    this._method = '';\n+    this._icc = null;\n+    this._cardIndex = 0;\n+    this._pinOptions = {};\n+    this._allowedRetryCounts = {\n+      pin: 3,\n+      pin2: 3,\n+      puk: 10,\n+      puk2: 10\n+    };\n+  }\n+\n+  SimPinDialog.prototype = {\n+    /**\n+     * init function\n+     *\n+     * @memberOf SimPinDialog\n+     * @access public\n+     * @param {Object} options\n+     * @param {String} options.method - lock, unlock ... etc\n+     * @param {Number} options.cardIndex - which simcard\n+     * @param {Object} options.pinOptions - extra arguments for icc operations\n+     */\n+    init: function(options) {\n+      this._method = options.method;\n+      this._cardIndex = options.cardIndex;\n+      this._pinOptions = options.pinOptions;\n+      this._icc = SettingsUtils.getIccByCardIndex(this._cardIndex);\n+\n+      if (!this._icc) {\n+        console.error('We can\\'t find needed icc object');\n+        return;\n+      }\n+\n+      this._bindInputClickEvent();\n+      this._initUI();\n+    },\n+\n+    /**\n+     * We will call this function when users click on submit button to make sure\n+     * DialogService can do the right thing.\n+     *\n+     * @memberOf SimPinDialog\n+     * @access public\n+     * @return {Promise}\n+     */\n+    verify: function() {\n+      switch (this._method) {\n+        // unlock SIM\n+        case 'unlock_pin':\n+          return this._unlockPin();\n+        case 'unlock_puk':\n+          return this._unlockPuk('puk');\n+        case 'unlock_puk2':\n+          return this._unlockPuk('puk2');\n+\n+        // PIN lock\n+        case 'enable_lock':\n+          return this._enableLock(true);\n+        case 'disable_lock':\n+          return this._enableLock(false);\n+        case 'change_pin':\n+          return this._changePin('pin');\n+\n+        // get PIN2 code (FDN contact list)\n+        case 'get_pin2':\n+          return this._updateFdnContact();\n+\n+        // PIN2 lock (FDN)\n+        case 'enable_fdn':\n+          return this._enableFdn(true);\n+        case 'disable_fdn':\n+          return this._enableFdn(false);\n+        case 'change_pin2':\n+          return this._changePin('pin2');\n+\n+        default:\n+          return Promise.reject();\n+      }\n+    },\n+\n+    /**\n+     * We will clear all pre-set values when the dialog is hidden.\n+     *\n+     * @memberOf SimPinDialog\n+     * @access public\n+     */\n+    clear: function() {\n+      this._elements.errorMsg.hidden = true;\n+      this._elements.pinInput.value = '';\n+      this._elements.pukInput.value = '';\n+      this._elements.newPinInput.value = '';\n+      this._elements.confirmPinInput.value = '';\n+    },\n+\n+    /**\n+     * Unlock pin\n+     *\n+     * @memberOf SimPinDialog\n+     * @access private\n+     * @return {Promise}\n+     */\n+    _unlockPin: function() {\n+      var pin = this._elements.pinInput.value;\n+      if (pin === '') {\n+        return Promise.reject();\n+      }\n+      return this._unlockCardLock({\n+        lockType: 'pin',\n+        pin: pin\n+      });\n+    },\n+\n+    /**\n+     * Unlock puk1 or puk2\n+     *\n+     * @memberOf SimPinDialog\n+     * @param {String} lockType\n+     * @access private\n+     * @return {Promise}\n+     */\n+    _unlockPuk: function(lockType) {\n+      lockType = lockType || 'puk';\n+      var puk = this._elements.pukInput.value;\n+      var newPin = this._elements.newPinInput.value;\n+      var confirmPin = this._elements.confirmPinInput.value;\n+\n+      if (puk === '' || newPin === '' || confirmPin === '') {\n+        return Promise.reject();\n+      }\n+\n+      if (newPin !== confirmPin) {\n+        this._elements.showMessage('newPinErrorMsg');\n+        this._elements.newPinInput.value = '';\n+        this._elements.confirmPinInput.value = '';\n+        return Promise.reject();\n+      }\n+\n+      return this._unlockCardLock({\n+        lockType: lockType,\n+        puk: puk,\n+        newPin: newPin\n+      });\n+    },\n+\n+    /**\n+     * This is an internal function to pass all arguments to icc and waiting\n+     * for returned results.\n+     *\n+     * @memberOf SimPinDialog\n+     * @param {Object} options\n+     * @param {String} options.pin\n+     * @param {String} options.puk\n+     * @param {String} options.newPin\n+     * @access private\n+     * @return {Promise}\n+     */\n+    _unlockCardLock: function(options) {\n+      return this._icc.unlockCardLock(options).then(() => {","path":"apps/settings/js/panels/simpin_dialog/simpin_dialog.js","position":174,"original_position":174,"commit_id":"6781dbc0a2d0732fe900682a40e5d5c4f366b1b8","original_commit_id":"6781dbc0a2d0732fe900682a40e5d5c4f366b1b8","user":{"login":"crh0716","id":2899280,"avatar_url":"https://avatars.githubusercontent.com/u/2899280?v=3","gravatar_id":"","url":"https://api.github.com/users/crh0716","html_url":"https://github.com/crh0716","followers_url":"https://api.github.com/users/crh0716/followers","following_url":"https://api.github.com/users/crh0716/following{/other_user}","gists_url":"https://api.github.com/users/crh0716/gists{/gist_id}","starred_url":"https://api.github.com/users/crh0716/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crh0716/subscriptions","organizations_url":"https://api.github.com/users/crh0716/orgs","repos_url":"https://api.github.com/users/crh0716/repos","events_url":"https://api.github.com/users/crh0716/events{/privacy}","received_events_url":"https://api.github.com/users/crh0716/received_events","type":"User","site_admin":false},"body":"The resolve function does nothing in this case. It seems we can simply do:\r\n```\r\nreturn this._icc.unlockCardLock(options).catch((error) => {\r\n  // ...\r\n});\r\n```","created_at":"2015-02-12T08:11:34Z","updated_at":"2015-02-12T08:11:34Z","html_url":"https://github.com/mozilla-b2g/gaia/pull/27036#discussion_r24564245","pull_request_url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/27036","_links":{"self":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/comments/24564245"},"html":{"href":"https://github.com/mozilla-b2g/gaia/pull/27036#discussion_r24564245"},"pull_request":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/27036"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/27036","id":26635258,"html_url":"https://github.com/mozilla-b2g/gaia/pull/27036","diff_url":"https://github.com/mozilla-b2g/gaia/pull/27036.diff","patch_url":"https://github.com/mozilla-b2g/gaia/pull/27036.patch","issue_url":"https://api.github.com/repos/mozilla-b2g/gaia/issues/27036","number":27036,"state":"open","locked":false,"title":"Bug 1103808 - [Settings][Dialog] sim_security/change_pin should be shown...","user":{"login":"EragonJ","id":68322,"avatar_url":"https://avatars.githubusercontent.com/u/68322?v=3","gravatar_id":"","url":"https://api.github.com/users/EragonJ","html_url":"https://github.com/EragonJ","followers_url":"https://api.github.com/users/EragonJ/followers","following_url":"https://api.github.com/users/EragonJ/following{/other_user}","gists_url":"https://api.github.com/users/EragonJ/gists{/gist_id}","starred_url":"https://api.github.com/users/EragonJ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EragonJ/subscriptions","organizations_url":"https://api.github.com/users/EragonJ/orgs","repos_url":"https://api.github.com/users/EragonJ/repos","events_url":"https://api.github.com/users/EragonJ/events{/privacy}","received_events_url":"https://api.github.com/users/EragonJ/received_events","type":"User","site_admin":false},"body":"... as a dialog","created_at":"2014-12-29T08:09:09Z","updated_at":"2015-02-12T08:11:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7e292de5929f53e7b1b1dff0b24e4cd13d577ad7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/27036/commits","review_comments_url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/27036/comments","review_comment_url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/comments/{number}","comments_url":"https://api.github.com/repos/mozilla-b2g/gaia/issues/27036/comments","statuses_url":"https://api.github.com/repos/mozilla-b2g/gaia/statuses/6781dbc0a2d0732fe900682a40e5d5c4f366b1b8","head":{"label":"EragonJ:bug-1103808","ref":"bug-1103808","sha":"6781dbc0a2d0732fe900682a40e5d5c4f366b1b8","user":{"login":"EragonJ","id":68322,"avatar_url":"https://avatars.githubusercontent.com/u/68322?v=3","gravatar_id":"","url":"https://api.github.com/users/EragonJ","html_url":"https://github.com/EragonJ","followers_url":"https://api.github.com/users/EragonJ/followers","following_url":"https://api.github.com/users/EragonJ/following{/other_user}","gists_url":"https://api.github.com/users/EragonJ/gists{/gist_id}","starred_url":"https://api.github.com/users/EragonJ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EragonJ/subscriptions","organizations_url":"https://api.github.com/users/EragonJ/orgs","repos_url":"https://api.github.com/users/EragonJ/repos","events_url":"https://api.github.com/users/EragonJ/events{/privacy}","received_events_url":"https://api.github.com/users/EragonJ/received_events","type":"User","site_admin":false},"repo":{"id":12532996,"name":"gaia","full_name":"EragonJ/gaia","owner":{"login":"EragonJ","id":68322,"avatar_url":"https://avatars.githubusercontent.com/u/68322?v=3","gravatar_id":"","url":"https://api.github.com/users/EragonJ","html_url":"https://github.com/EragonJ","followers_url":"https://api.github.com/users/EragonJ/followers","following_url":"https://api.github.com/users/EragonJ/following{/other_user}","gists_url":"https://api.github.com/users/EragonJ/gists{/gist_id}","starred_url":"https://api.github.com/users/EragonJ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EragonJ/subscriptions","organizations_url":"https://api.github.com/users/EragonJ/orgs","repos_url":"https://api.github.com/users/EragonJ/repos","events_url":"https://api.github.com/users/EragonJ/events{/privacy}","received_events_url":"https://api.github.com/users/EragonJ/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/EragonJ/gaia","description":"Gaia is a HTML5-based Phone UI for the Boot 2 Gecko Project. NOTE: For details of what branches are used for what releases, see https://wiki.mozilla.org/Release_Management/B2G_Landing","fork":true,"url":"https://api.github.com/repos/EragonJ/gaia","forks_url":"https://api.github.com/repos/EragonJ/gaia/forks","keys_url":"https://api.github.com/repos/EragonJ/gaia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/EragonJ/gaia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/EragonJ/gaia/teams","hooks_url":"https://api.github.com/repos/EragonJ/gaia/hooks","issue_events_url":"https://api.github.com/repos/EragonJ/gaia/issues/events{/number}","events_url":"https://api.github.com/repos/EragonJ/gaia/events","assignees_url":"https://api.github.com/repos/EragonJ/gaia/assignees{/user}","branches_url":"https://api.github.com/repos/EragonJ/gaia/branches{/branch}","tags_url":"https://api.github.com/repos/EragonJ/gaia/tags","blobs_url":"https://api.github.com/repos/EragonJ/gaia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/EragonJ/gaia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/EragonJ/gaia/git/refs{/sha}","trees_url":"https://api.github.com/repos/EragonJ/gaia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/EragonJ/gaia/statuses/{sha}","languages_url":"https://api.github.com/repos/EragonJ/gaia/languages","stargazers_url":"https://api.github.com/repos/EragonJ/gaia/stargazers","contributors_url":"https://api.github.com/repos/EragonJ/gaia/contributors","subscribers_url":"https://api.github.com/repos/EragonJ/gaia/subscribers","subscription_url":"https://api.github.com/repos/EragonJ/gaia/subscription","commits_url":"https://api.github.com/repos/EragonJ/gaia/commits{/sha}","git_commits_url":"https://api.github.com/repos/EragonJ/gaia/git/commits{/sha}","comments_url":"https://api.github.com/repos/EragonJ/gaia/comments{/number}","issue_comment_url":"https://api.github.com/repos/EragonJ/gaia/issues/comments/{number}","contents_url":"https://api.github.com/repos/EragonJ/gaia/contents/{+path}","compare_url":"https://api.github.com/repos/EragonJ/gaia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/EragonJ/gaia/merges","archive_url":"https://api.github.com/repos/EragonJ/gaia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/EragonJ/gaia/downloads","issues_url":"https://api.github.com/repos/EragonJ/gaia/issues{/number}","pulls_url":"https://api.github.com/repos/EragonJ/gaia/pulls{/number}","milestones_url":"https://api.github.com/repos/EragonJ/gaia/milestones{/number}","notifications_url":"https://api.github.com/repos/EragonJ/gaia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/EragonJ/gaia/labels{/name}","releases_url":"https://api.github.com/repos/EragonJ/gaia/releases{/id}","created_at":"2013-09-02T05:56:31Z","updated_at":"2014-08-04T09:27:27Z","pushed_at":"2015-02-12T07:47:06Z","git_url":"git://github.com/EragonJ/gaia.git","ssh_url":"git@github.com:EragonJ/gaia.git","clone_url":"https://github.com/EragonJ/gaia.git","svn_url":"https://github.com/EragonJ/gaia","homepage":"https://wiki.mozilla.org/B2G","size":878534,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"mozilla-b2g:master","ref":"master","sha":"a0c9d82f060e80e90f70292726927f9b36da6e88","user":{"login":"mozilla-b2g","id":1261292,"avatar_url":"https://avatars.githubusercontent.com/u/1261292?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla-b2g","html_url":"https://github.com/mozilla-b2g","followers_url":"https://api.github.com/users/mozilla-b2g/followers","following_url":"https://api.github.com/users/mozilla-b2g/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-b2g/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-b2g/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-b2g/subscriptions","organizations_url":"https://api.github.com/users/mozilla-b2g/orgs","repos_url":"https://api.github.com/users/mozilla-b2g/repos","events_url":"https://api.github.com/users/mozilla-b2g/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-b2g/received_events","type":"Organization","site_admin":false},"repo":{"id":2317369,"name":"gaia","full_name":"mozilla-b2g/gaia","owner":{"login":"mozilla-b2g","id":1261292,"avatar_url":"https://avatars.githubusercontent.com/u/1261292?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla-b2g","html_url":"https://github.com/mozilla-b2g","followers_url":"https://api.github.com/users/mozilla-b2g/followers","following_url":"https://api.github.com/users/mozilla-b2g/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-b2g/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-b2g/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-b2g/subscriptions","organizations_url":"https://api.github.com/users/mozilla-b2g/orgs","repos_url":"https://api.github.com/users/mozilla-b2g/repos","events_url":"https://api.github.com/users/mozilla-b2g/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-b2g/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla-b2g/gaia","description":"Gaia is a HTML5-based Phone UI for the Boot 2 Gecko Project. NOTE: For details of what branches are used for what releases, see","fork":false,"url":"https://api.github.com/repos/mozilla-b2g/gaia","forks_url":"https://api.github.com/repos/mozilla-b2g/gaia/forks","keys_url":"https://api.github.com/repos/mozilla-b2g/gaia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla-b2g/gaia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla-b2g/gaia/teams","hooks_url":"https://api.github.com/repos/mozilla-b2g/gaia/hooks","issue_events_url":"https://api.github.com/repos/mozilla-b2g/gaia/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla-b2g/gaia/events","assignees_url":"https://api.github.com/repos/mozilla-b2g/gaia/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla-b2g/gaia/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla-b2g/gaia/tags","blobs_url":"https://api.github.com/repos/mozilla-b2g/gaia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla-b2g/gaia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla-b2g/gaia/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla-b2g/gaia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla-b2g/gaia/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla-b2g/gaia/languages","stargazers_url":"https://api.github.com/repos/mozilla-b2g/gaia/stargazers","contributors_url":"https://api.github.com/repos/mozilla-b2g/gaia/contributors","subscribers_url":"https://api.github.com/repos/mozilla-b2g/gaia/subscribers","subscription_url":"https://api.github.com/repos/mozilla-b2g/gaia/subscription","commits_url":"https://api.github.com/repos/mozilla-b2g/gaia/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla-b2g/gaia/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla-b2g/gaia/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla-b2g/gaia/issues/comments/{number}","contents_url":"https://api.github.com/repos/mozilla-b2g/gaia/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla-b2g/gaia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla-b2g/gaia/merges","archive_url":"https://api.github.com/repos/mozilla-b2g/gaia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla-b2g/gaia/downloads","issues_url":"https://api.github.com/repos/mozilla-b2g/gaia/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla-b2g/gaia/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla-b2g/gaia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla-b2g/gaia/labels{/name}","releases_url":"https://api.github.com/repos/mozilla-b2g/gaia/releases{/id}","created_at":"2011-09-03T01:38:46Z","updated_at":"2015-02-12T07:57:42Z","pushed_at":"2015-02-12T07:57:48Z","git_url":"git://github.com/mozilla-b2g/gaia.git","ssh_url":"git@github.com:mozilla-b2g/gaia.git","clone_url":"https://github.com/mozilla-b2g/gaia.git","svn_url":"https://github.com/mozilla-b2g/gaia","homepage":"https://wiki.mozilla.org/B2G","size":1410924,"stargazers_count":1871,"watchers_count":1871,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2212,"mirror_url":null,"open_issues_count":874,"forks":2212,"open_issues":874,"watchers":1871,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/27036"},"html":{"href":"https://github.com/mozilla-b2g/gaia/pull/27036"},"issue":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/issues/27036"},"comments":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/issues/27036/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/27036/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/27036/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/statuses/6781dbc0a2d0732fe900682a40e5d5c4f366b1b8"}}}}