--- /dev/null
+/*\r
+ * Copyright 2016 ZTE, Inc. and others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+$(function(){\r
+\r
+\r
+ $(".form-tip").blur(function(){\r
+ if($.trim($(this).val())==""){\r
+ $(this).removeClass("form-input-focus");\r
+ $(this).prev().removeClass("item-tip-focus");\r
+ }});\r
+\r
+$(".form-tip").focus(function(){\r
+ if(!$(this).hasClass("form-input-focus")){\r
+ $(this).addClass("form-input-focus");\r
+ $(this).prev().addClass("item-tip-focus");\r
+ }});\r
+\r
+$(".item-tip").click(function(){\r
+ $(this).next().focus();\r
+});\r
+\r
+$("input[name='version']").blur(function(){\r
+ $(this).val($(this).val().toLowerCase());\r
+\r
+ if(vm.msbRouteInfo.protocol=='REST' || vm.msbRouteInfo.protocol=='HTTP' ){\r
+ routeUtil.changeTargetServiceUrl();\r
+ }\r
+});\r
+\r
+\r
+\r
+$("input[name='serviceName']").change(function(){\r
+ if(vm.msbRouteInfo.protocol=='REST' || vm.msbRouteInfo.protocol=='UI' || vm.msbRouteInfo.protocol=='HTTP'){\r
+ routeUtil.changeTargetServiceUrl();\r
+ }\r
+\r
+});\r
+\r
+$("input[name='url']").change(function(){\r
+\r
+ routeUtil.changeTargetServiceUrl();\r
+});\r
+\r
+\r
+\r
+$("select[name='protocol']").change(function(){\r
+\r
+routeUtil.changeTargetServiceUrl();\r
+\r
+});\r
+\r
+$("input[name='chkVisualRange']").change(function(){\r
+\r
+routeUtil.changeTargetServiceUrl();\r
+\r
+});\r
+\r
+$("input[name='publish_port']").change(function(){\r
+\r
+routeUtil.changeTargetServiceUrl();\r
+\r
+});\r
+\r
+$("input[name='http_publish_port']").change(function(){\r
+\r
+routeUtil.changeTargetServiceUrl();\r
+\r
+});\r
+\r
+$("input[name='networkPlaneType']").change(function(){\r
+\r
+routeUtil.changeTargetServiceUrl();\r
+\r
+});\r
+\r
+$("#labels").change(function(){\r
+\r
+routeUtil.changeTargetServiceUrl();\r
+\r
+});\r
+\r
+\r
+\r
+$("input[name='host']").change(function(){\r
+\r
+routeUtil.changeTargetServiceUrl();\r
+\r
+});\r
+\r
+$("input[name='path']").change(function(){\r
+\r
+routeUtil.changeTargetServiceUrl();\r
+\r
+});\r
+\r
+\r
+$("input[name='namespace']").change(function(){\r
+\r
+vm.getApigatewayInfo($(this).val());\r
+\r
+});\r
+\r
+\r
+\r
+\r
+ jQuery.validator.addMethod("ip", function(value, element) { \r
+ return this.optional(element) || /^(([-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5])))\.)(([0-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5])))\.){2}([1-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5])))$/.test(value); \r
+ }, $.i18n.prop("org_onap_msb_discover_validator_ip_format"));\r
+\r
+\r
+\r
+ jQuery.validator.addMethod("url_head", function(value, element) { \r
+ return this.optional(element) || /^\/.+((?!\/).)$/i.test(value) || /^\/$/i.test(value); \r
+ }, $.i18n.prop("org_onap_msb_discover_validator_url_head_format"));\r
+\r
+\r
+jQuery.validator.addMethod("url_head_only", function(value, element) { \r
+ return this.optional(element) || /^\/.*$/i.test(value); \r
+ }, $.i18n.prop("org_onap_msb_discover_validator_url_head_only_format"));\r
+ \r
+ jQuery.validator.addMethod("version", function(value, element) { \r
+ return this.optional(element) || /^v\d+(\.\d+)?$/i.test(value); \r
+ }, $.i18n.prop("org_onap_msb_discover_form_version_tip"));\r
+\r
+ jQuery.validator.addMethod("service_url", function(value, element) { \r
+ return this.optional(element) || /^(|http:\/\/)(([1-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5])))\.)(([0-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5])))\.){2}([1-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5]))):(\d{1,5})\/.*$/.test(value); \r
+ }, $.i18n.prop("org_onap_msb_discover_validator_url_format"));\r
+\r
+ jQuery.validator.addMethod("url_line", function(value, element) { \r
+ return this.optional(element) || /^((?!\/).)*$/.test(value); \r
+ }, $.i18n.prop("org_onap_msb_discover_validator_url_line_format"));\r
+\r
+ jQuery.validator.addMethod("content", function(value, element) { \r
+ return this.optional(element) || /^([0-9a-zA-Z]|-|_)*$/i.test(value); \r
+ }, $.i18n.prop("org_onap_msb_discover_validator_content_format"));\r
+\r
+ jQuery.validator.addMethod("custom_content", function(value, element) { \r
+ return this.optional(element) || /^([0-9a-zA-Z]|-|_|\/)*$/i.test(value); \r
+ }, $.i18n.prop("org_onap_msb_discover_validator_content_format"));\r
+\r
+ jQuery.validator.addMethod("http_publish_port_content", function(value, element) { \r
+ return this.optional(element) || /^([0-9]|\|)*$/i.test(value); \r
+ }, $.i18n.prop("org_onap_msb_discover_validator_publish_port_format"));\r
+\r
+\r
+ });\r
+\r
+ \r
+\r
+ var msbform = $('#msbForm');\r
+ var msberror = $('.alert-danger', msbform);\r
+ var msbsuccess = $('.alert-success', msbform);\r
+\r
+\r
+ msbform.validate({\r
+ doNotHideMessage: true, //this option enables to show the error/success messages on tab switch.\r
+ errorElement: 'span', //default input error message container\r
+ errorClass: 'help-block', // default input error message class\r
+ focusInvalid: false, // do not focus the last invalid input\r
+ rules: { \r
+ \r
+ serviceName:{\r
+ required: true,\r
+ content:true,\r
+ maxlength:50\r
+ },\r
+ version:{\r
+ maxlength:50,\r
+ version:true\r
+ },\r
+ url:{\r
+ // url_head:true,\r
+ maxlength:50\r
+ },\r
+ path:{\r
+ //url_head:true,\r
+ maxlength:50\r
+ },\r
+ newHost:{\r
+ ip:true,\r
+ maxlength:50\r
+ },\r
+ newttl:{\r
+ digits:true,\r
+ min:0\r
+ }, \r
+ http_publish_port:{\r
+ http_publish_port_content:true\r
+ }, \r
+ publish_port:{\r
+ digits:true,\r
+ min:1,\r
+ max:65535\r
+ },\r
+ protocol:{\r
+ required: true\r
+ },\r
+ visualRange:{\r
+ required: true,\r
+ minlength:1\r
+ },\r
+ host:{\r
+ content:true,\r
+ maxlength:50\r
+ }\r
+ },\r
+ messages: { \r
+ serviceName:{\r
+ required: "Please enter the service name"\r
+ },\r
+ protocol:{\r
+ required:"Please select a service protocol"\r
+ \r
+ }, \r
+ visualRange:{\r
+ required:"Please select the service visibleRange"\r
+ \r
+ },\r
+ newttl:{\r
+ digits:"Please enter a number",\r
+ min: "number must be > 0"\r
+ },\r
+ publish_port:{\r
+ digits:"Please enter a number"\r
+ }\r
+\r
+ },\r
+ errorPlacement: function (msberror, element) { // render error placement for each input type\r
+ msberror.insertAfter(element); // for other inputs, just perform default behavior\r
+ },\r
+\r
+ invalidHandler: function (event, validator) { //display error alert on form submit \r
+ msbsuccess.hide();\r
+ msberror.show();\r
+ //ZteFrameWork.scrollTo(error, -200);\r
+ },\r
+\r
+ highlight: function (element) { // hightlight error inputs\r
+ $(element)\r
+ .closest('.form-group').removeClass('has-success').addClass('has-error'); // set error class to the control group\r
+ },\r
+\r
+ unhighlight: function (element) { // revert the change done by hightlight\r
+ $(element)\r
+ .closest('.form-group').removeClass('has-error'); // set error class to the control group\r
+ },\r
+\r
+ success: function (label) {\r
+ label\r
+ .addClass('valid') // mark the current input as valid and display OK icon\r
+ .closest('.form-group').removeClass('has-error'); // set success class to the control group\r
+ },\r
+ submitHandler: function (form) {\r
+ msbsuccess.show();\r
+ msberror.hide();\r
+ //add here some ajax code to submit your form or just call form.submit() if you want to submit the form without ajax\r
+ }\r
+\r
+ });\r
+\r
+ \r
+ var nodeform = $('#nodeForm');\r
+ var nodeerror = $('.alert-danger', nodeform);\r
+ var nodesuccess = $('.alert-success', nodeform);\r
+\r
+\r
+ nodeform.validate({\r
+ doNotHideMessage: true, //this option enables to show the error/success messages on tab switch.\r
+ errorElement: 'span', //default input error message container\r
+ errorClass: 'help-block', // default input error message class\r
+ focusInvalid: false, // do not focus the last invalid input\r
+ rules: { \r
+ \r
+ nodeInfo_ip:{\r
+ required: true,\r
+ ip:true,\r
+ maxlength:50\r
+ },\r
+ nodeInfo_port:{\r
+ required: true,\r
+ digits:true,\r
+ min:1,\r
+ max:65535\r
+ },\r
+ nodeInfo_weight:{\r
+ digits:true,\r
+ maxlength:3,\r
+ min:1\r
+ },\r
+ nodeInfo_max_fails:{\r
+ digits:true,\r
+ maxlength:3,\r
+ min:1\r
+ },\r
+ nodeInfo_fail_timeout:{\r
+ digits:true,\r
+ maxlength:3,\r
+ min:1\r
+ },\r
+ checkInterval:{\r
+ digits:true,\r
+ maxlength:3,\r
+ min:1\r
+ },\r
+ checkTimeOut:{\r
+ digits:true,\r
+ min:1\r
+ },\r
+ ttl:{\r
+ digits:true,\r
+ min:1\r
+ }\r
+ \r
+ },\r
+ messages: { \r
+ nodeInfo_ip:{\r
+ required:"Please enter the Host IP"\r
+ },\r
+ nodeInfo_port:{\r
+ required: "Please enter the Host Port",\r
+ digits:"Please enter a number",\r
+ min: "number must be > 1" \r
+ } ,\r
+ nodeInfo_weight:{\r
+ digits:"only num",\r
+ min:"must>0" \r
+ },\r
+ nodeInfo_max_fails:{\r
+ digits:"only num",\r
+ min: "must>0" \r
+ },\r
+ nodeInfo_fail_timeout:{\r
+ digits:"only num",\r
+ min: "must>0" \r
+ } ,\r
+ checkInterval:{\r
+ digits:"only num",\r
+ min:"must>0" \r
+ } ,\r
+ checkTimeOut:{\r
+ digits:"only num",\r
+ min:"must>0" \r
+ } ,\r
+ ttl:{\r
+ digits:"only num",\r
+ min:"must>0" \r
+ } \r
+ \r
+ \r
+\r
+ },\r
+ errorPlacement: function (nodeerror, element) { // render error placement for each input type\r
+ nodeerror.insertAfter(element); // for other inputs, just perform default behavior\r
+ },\r
+\r
+ invalidHandler: function (event, validator) { //display error alert on form submit \r
+ nodesuccess.hide();\r
+ nodeerror.show();\r
+ //ZteFrameWork.scrollTo(error, -200);\r
+ },\r
+\r
+ highlight: function (element) { // hightlight error inputs\r
+ $(element)\r
+ .closest('.form-group').removeClass('has-success').addClass('has-error'); // set error class to the control group\r
+ },\r
+\r
+ unhighlight: function (element) { // revert the change done by hightlight\r
+ $(element)\r
+ .closest('.form-group').removeClass('has-error'); // set error class to the control group\r
+ },\r
+\r
+ success: function (label) {\r
+ label\r
+ .addClass('valid') // mark the current input as valid and display OK icon\r
+ .closest('.form-group').removeClass('has-error'); // set success class to the control group\r
+ },\r
+ submitHandler: function (form) {\r
+ nodesuccess.show();\r
+ nodeerror.hide();\r
+ //add here some ajax code to submit your form or just call form.submit() if you want to submit the form without ajax\r
+ }\r
+\r
+ });\r
+\r
+\r
+ function spinnerButtonBindClick() {\r
+ $('.spinner .btn:first-of-type').unbind().on('click', function () {\r
+ var input = $('input', $(this).parents('.spinner'));\r
+\r
+ if(input.val()=="") input.val("0");\r
+\r
+ input.val(parseInt(input.val(), 10) + 1);\r
+ if (input.val() > 1) {\r
+ $('.spinner .btn:last-of-type').attr("disabled", false);\r
+ }\r
+ });\r
+ $('.spinner .btn:last-of-type').unbind().on('click', function () {\r
+ var input = $('input', $(this).parents('.spinner'));\r
+ if(input.val()=="") input.val("2");\r
+\r
+ input.val(parseInt(input.val(), 10) - 1);\r
+ if (input.val() <= 1) {\r
+ $('.spinner .btn:last-of-type').attr("disabled", true);\r
+ }\r
+ });\r
+ }\r
+\r
+ \r
+\r
+\r
+\r