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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: appengine/monorail/static/js/tracker/tracker-components.js
diff --git a/appengine/monorail/static/js/tracker/tracker-components.js b/appengine/monorail/static/js/tracker/tracker-components.js
new file mode 100644
index 0000000000000000000000000000000000000000..8851e36124fbf810df7c22c29f5d6c0d09d169b9
--- /dev/null
+++ b/appengine/monorail/static/js/tracker/tracker-components.js
@@ -0,0 +1,92 @@
+/* Copyright 2016 The Chromium Authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style
+ * license that can be found in the LICENSE file or at
+ * https://developers.google.com/open-source/licenses/bsd
+ */
+
+/**
+ * This file contains JS code for editing components and component definitions.
+ */
+
+var TKR_leafNameXmlHttp;
+
+var TKR_leafNameRE = /^[a-zA-Z]([-_]?[a-zA-Z0-9])+$/;
+var TKR_oldName = '';
+
+/**
+ * Function to validate the component leaf name..
+ * @param {string} projectName Current project name.
+ * @param {string} parentPath Path to this component's parent.
+ * @param {string} originalName Original leaf name, keeping that is always OK.
+ * @param {string} token security token.
+ */
+function TKR_checkLeafName(projectName, parentPath, originalName, token) {
+ var name = $('leaf_name').value;
+ var feedback = $('leafnamefeedback');
+ if (name == originalName) {
+ $('submit_btn').disabled = '';
+ feedback.innerText = '';
+ } else if (name != TKR_oldName) {
+ $('submit_btn').disabled = 'disabled';
+ if (name == '') {
+ feedback.innerText = 'Please choose a name';
+ } else if (!TKR_leafNameRE.test(name)) {
+ feedback.innerText = 'Invalid component name';
+ } else if (name.length > 30) {
+ feedback.innerText = 'Name is too long';
+ } else {
+ TKR_checkLeafNameOnServer(projectName, parentPath, name, token);
+ }
+ }
+ TKR_oldName = name;
+}
+
+
+
+/**
+ * Function that communicates with the server.
+ * @param {string} projectName Current project name.
+ * @param {string} leafName The proposed leaf name.
+ * @param {string} token security token.
+ */
+function TKR_checkLeafNameOnServer(projectName, parentPath, leafName, token) {
+ var url = ('/p/' + projectName + '/components/checkName' +
+ '?parent_path=' + parentPath +
+ '&leaf_name=' + encodeURIComponent(leafName) +
+ '&token=' + token);
+ TKR_leafNameXmlHttp = XH_XmlHttpCreate();
+ XH_XmlHttpGET(TKR_leafNameXmlHttp, url, TKR_leafNameCallback);
+
+}
+
+/**
+ * The communication with the server has made some progress. If it is
+ * done, then process the response.
+ */
+function TKR_leafNameCallback() {
+ if (TKR_leafNameXmlHttp.readyState == 4) {
+ if (TKR_leafNameXmlHttp.status == 200) {
+ TKR_gotLeafNameFeed(TKR_leafNameXmlHttp);
+ }
+ }
+}
+
+
+/**
+ * Function that evaluates the server response and sets the error message.
+ * @param {object} xhr AJAX response object.
+ */
+function TKR_gotLeafNameFeed(xhr) {
+ var json_data = null;
+ try {
+ json_data = CS_parseJSON(xhr);
+ }
+ catch (e) {
+ return;
+ }
+ var errorMessage = json_data['error_message'];
+ $('leafnamefeedback').innerText = errorMessage || '';
+
+ $('submit_btn').disabled = errorMessage ? 'disabled' : '';
+}
« 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