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

Unified Diff: appengine/monorail/static/js/tracker/tracker-fields.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-fields.js
diff --git a/appengine/monorail/static/js/tracker/tracker-fields.js b/appengine/monorail/static/js/tracker/tracker-fields.js
new file mode 100644
index 0000000000000000000000000000000000000000..cf91e6e35a16956fdfab570ef981ad6142ff5eb3
--- /dev/null
+++ b/appengine/monorail/static/js/tracker/tracker-fields.js
@@ -0,0 +1,86 @@
+/* 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 fields and field definitions.
+ */
+
+var TKR_fieldNameXmlHttp;
+
+
+/**
+ * Function that communicates with the server.
+ * @param {string} projectName Current project name.
+ * @param {string} fieldName The proposed field name.
+ * @param {string} token security token.
+ */
+function TKR_checkFieldNameOnServer(projectName, fieldName, token) {
+ var url = ('/p/' + projectName + '/fields/checkName' +
+ '?field=' + encodeURIComponent(fieldName) +
+ '&token=' + token);
+ TKR_fieldNameXmlHttp = XH_XmlHttpCreate();
+ XH_XmlHttpGET(TKR_fieldNameXmlHttp, url, TKR_fieldNameCallback);
+}
+
+/**
+ * The communication with the server has made some progress. If it is
+ * done, then process the response.
+ */
+function TKR_fieldNameCallback() {
+ if (TKR_fieldNameXmlHttp.readyState == 4) {
+ if (TKR_fieldNameXmlHttp.status == 200) {
+ TKR_gotFieldNameFeed(TKR_fieldNameXmlHttp);
+ }
+ }
+}
+
+
+/**
+ * Function that evaluates the server response and sets the error message.
+ * @param {object} xhr AJAX response with JSON text.
+ */
+function TKR_gotFieldNameFeed(xhr) {
+ var json_data = null;
+ try {
+ json_data = CS_parseJSON(xhr);
+ }
+ catch (e) {
+ return;
+ }
+ var errorMessage = json_data['error_message'];
+ $('fieldnamefeedback').innerText = errorMessage;
+
+ var choicesLines = [];
+ if (json_data['choices'].length > 0) {
+ for (var i = 0; i < json_data['choices'].length; i++) {
+ choicesLines.push(
+ json_data['choices'][i]['name'] + ' = ' +
+ json_data['choices'][i]['doc']);
+ }
+ $('choices').innerText = choicesLines.join('\n');
+ $('field_type').value = 'enum_type';
+ $('choices_row').style.display = '';
+ enableOtherTypeOptions(true);
+ } else {
+ enableOtherTypeOptions(false);
+ }
+
+ $('submit_btn').disabled = errorMessage ? 'disabled' : '';
+}
+
+
+function enableOtherTypeOptions(disabled) {
+ var type_option_el = $('field_type').firstChild;
+ while (type_option_el) {
+ if (type_option_el.tagName == 'OPTION') {
+ if (type_option_el.value != 'enum_type') {
+ type_option_el.disabled = disabled ? 'disabled' : '';
+ }
+ }
+ type_option_el = type_option_el.nextSibling;
+ }
+}
« no previous file with comments | « appengine/monorail/static/js/tracker/tracker-editing.js ('k') | appengine/monorail/static/js/tracker/tracker-keystrokes.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698