Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: chrome/browser/resources/md_bookmarks/edit_dialog.js

Issue 2780223004: MD Bookmarks: Implement dialog to add new folders/bookmarks (Closed)
Patch Set: Split out creation Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 Polymer({ 5 Polymer({
6 is: 'bookmarks-edit-dialog', 6 is: 'bookmarks-edit-dialog',
7 7
8 behaviors: [ 8 behaviors: [
9 Polymer.IronA11yKeysBehavior, 9 Polymer.IronA11yKeysBehavior,
10 ], 10 ],
11 11
12 properties: { 12 properties: {
13 /** @private {BookmarkNode} */ 13 /** @private */
14 isFolder_: Boolean,
15
16 /** @private */
17 isEdit_: Boolean,
18
19 /**
20 * Item that is being edited, or null when adding.
21 * @private {?BookmarkNode}
22 */
14 editItem_: Object, 23 editItem_: Object,
15 24
16 /** @private */ 25 /**
17 isFolder_: Boolean, 26 * Parent node for the item being added, or null when editing.
27 * @private {?string}
28 */
29 parentId_: String,
18 30
19 /** @private */ 31 /** @private */
20 titleValue_: String, 32 titleValue_: String,
21 33
22 /** @private */ 34 /** @private */
23 urlValue_: String, 35 urlValue_: String,
24 }, 36 },
25 37
26 keyBindings: { 38 keyBindings: {
27 'enter': 'onSaveButtonTap_', 39 'enter': 'onSaveButtonTap_',
28 }, 40 },
29 41
30 /** @param {BookmarkNode} editItem */ 42 /**
31 showEditDialog: function(editItem) { 43 * Show the dialog to add a new folder (if |isFolder|) or item, which will be
32 this.editItem_ = editItem; 44 * inserted into the tree as a child of |parentId|.
33 this.isFolder_ = !editItem.url; 45 * @param {boolean} isFolder
34 46 * @param {string} parentId
35 this.titleValue_ = editItem.title; 47 */
36 if (!this.isFolder_) { 48 showAddDialog: function(isFolder, parentId) {
37 this.$.url.invalid = false; 49 this.reset_();
38 this.urlValue_ = assert(editItem.url); 50 this.isEdit_ = false;
39 } 51 this.isFolder_ = isFolder;
52 this.parentId_ = parentId;
40 53
41 this.$.dialog.showModal(); 54 this.$.dialog.showModal();
42 }, 55 },
43 56
44 /** 57 /**
58 * Show the edit dialog for |editItem|.
59 * @param {BookmarkNode} editItem
60 */
61 showEditDialog: function(editItem) {
62 this.reset_();
63 this.isEdit_ = true;
64 this.isFolder_ = !editItem.url;
65 this.editItem_ = editItem;
66
67 this.titleValue_ = editItem.title;
68 if (!this.isFolder_)
69 this.urlValue_ = assert(editItem.url);
70
71 this.$.dialog.showModal();
72 },
73
74 /**
75 * Clear out existing values from the dialog, allowing it to be reused.
76 * @private
77 */
78 reset_: function() {
79 this.editItem_ = null;
80 this.parentId_ = null;
81 this.$.url.invalid = false;
82 this.titleValue_ = '';
83 this.urlValue_ = '';
84 },
85
86 /**
45 * @param {boolean} isFolder 87 * @param {boolean} isFolder
88 * @param {boolean} isEdit
46 * @return {string} 89 * @return {string}
47 * @private 90 * @private
48 */ 91 */
49 getDialogTitle_: function(isFolder) { 92 getDialogTitle_: function(isFolder, isEdit) {
50 return loadTimeData.getString( 93 var title;
51 isFolder ? 'renameFolderTitle' : 'editBookmarkTitle'); 94 if (isEdit)
95 title = isFolder ? 'renameFolderTitle' : 'editBookmarkTitle';
96 else
97 title = isFolder ? 'addFolderTitle' : 'addBookmarkTitle';
calamity 2017/04/03 07:20:48 nit: blank line after this.
tsergeant 2017/04/04 01:21:07 Done.
98 return loadTimeData.getString(title);
52 }, 99 },
53 100
54 /** 101 /**
55 * Validates the value of the URL field, returning true if it is a valid URL. 102 * Validates the value of the URL field, returning true if it is a valid URL.
56 * May modify the value by prepending 'http://' in order to make it valid. 103 * May modify the value by prepending 'http://' in order to make it valid.
57 * @return {boolean} 104 * @return {boolean}
58 * @private 105 * @private
59 */ 106 */
60 validateUrl_: function() { 107 validateUrl_: function() {
61 var urlInput = /** @type {PaperInputElement} */ (this.$.url); 108 var urlInput = /** @type {PaperInputElement} */ (this.$.url);
(...skipping 14 matching lines...) Expand all
76 /** @private */ 123 /** @private */
77 onSaveButtonTap_: function() { 124 onSaveButtonTap_: function() {
78 var edit = {'title': this.titleValue_}; 125 var edit = {'title': this.titleValue_};
79 if (!this.isFolder_) { 126 if (!this.isFolder_) {
80 if (!this.validateUrl_()) 127 if (!this.validateUrl_())
81 return; 128 return;
82 129
83 edit['url'] = this.urlValue_; 130 edit['url'] = this.urlValue_;
84 } 131 }
85 132
86 chrome.bookmarks.update(this.editItem_.id, edit); 133 if (this.isEdit_) {
134 chrome.bookmarks.update(this.editItem_.id, edit);
135 } else {
136 edit['parentId'] = this.parentId_;
137 chrome.bookmarks.create(edit);
138 }
87 this.$.dialog.close(); 139 this.$.dialog.close();
88 }, 140 },
89 141
90 /** @private */ 142 /** @private */
91 onCancelButtonTap_: function() { 143 onCancelButtonTap_: function() {
92 this.$.dialog.cancel(); 144 this.$.dialog.cancel();
93 }, 145 },
94 }); 146 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698