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

Side by Side Diff: appengine/monorail/static/js/tracker/tracker-components.js

Issue 1868553004: Open Source Monorail (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 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
(Empty)
1 /* Copyright 2016 The Chromium Authors. All Rights Reserved.
2 *
3 * Use of this source code is governed by a BSD-style
4 * license that can be found in the LICENSE file or at
5 * https://developers.google.com/open-source/licenses/bsd
6 */
7
8 /**
9 * This file contains JS code for editing components and component definitions.
10 */
11
12 var TKR_leafNameXmlHttp;
13
14 var TKR_leafNameRE = /^[a-zA-Z]([-_]?[a-zA-Z0-9])+$/;
15 var TKR_oldName = '';
16
17 /**
18 * Function to validate the component leaf name..
19 * @param {string} projectName Current project name.
20 * @param {string} parentPath Path to this component's parent.
21 * @param {string} originalName Original leaf name, keeping that is always OK.
22 * @param {string} token security token.
23 */
24 function TKR_checkLeafName(projectName, parentPath, originalName, token) {
25 var name = $('leaf_name').value;
26 var feedback = $('leafnamefeedback');
27 if (name == originalName) {
28 $('submit_btn').disabled = '';
29 feedback.innerText = '';
30 } else if (name != TKR_oldName) {
31 $('submit_btn').disabled = 'disabled';
32 if (name == '') {
33 feedback.innerText = 'Please choose a name';
34 } else if (!TKR_leafNameRE.test(name)) {
35 feedback.innerText = 'Invalid component name';
36 } else if (name.length > 30) {
37 feedback.innerText = 'Name is too long';
38 } else {
39 TKR_checkLeafNameOnServer(projectName, parentPath, name, token);
40 }
41 }
42 TKR_oldName = name;
43 }
44
45
46
47 /**
48 * Function that communicates with the server.
49 * @param {string} projectName Current project name.
50 * @param {string} leafName The proposed leaf name.
51 * @param {string} token security token.
52 */
53 function TKR_checkLeafNameOnServer(projectName, parentPath, leafName, token) {
54 var url = ('/p/' + projectName + '/components/checkName' +
55 '?parent_path=' + parentPath +
56 '&leaf_name=' + encodeURIComponent(leafName) +
57 '&token=' + token);
58 TKR_leafNameXmlHttp = XH_XmlHttpCreate();
59 XH_XmlHttpGET(TKR_leafNameXmlHttp, url, TKR_leafNameCallback);
60
61 }
62
63 /**
64 * The communication with the server has made some progress. If it is
65 * done, then process the response.
66 */
67 function TKR_leafNameCallback() {
68 if (TKR_leafNameXmlHttp.readyState == 4) {
69 if (TKR_leafNameXmlHttp.status == 200) {
70 TKR_gotLeafNameFeed(TKR_leafNameXmlHttp);
71 }
72 }
73 }
74
75
76 /**
77 * Function that evaluates the server response and sets the error message.
78 * @param {object} xhr AJAX response object.
79 */
80 function TKR_gotLeafNameFeed(xhr) {
81 var json_data = null;
82 try {
83 json_data = CS_parseJSON(xhr);
84 }
85 catch (e) {
86 return;
87 }
88 var errorMessage = json_data['error_message'];
89 $('leafnamefeedback').innerText = errorMessage || '';
90
91 $('submit_btn').disabled = errorMessage ? 'disabled' : '';
92 }
OLDNEW
« no previous file with comments | « appengine/monorail/static/js/tracker/tracker-ac.js ('k') | appengine/monorail/static/js/tracker/tracker-display.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698