modify copyright year
[msb/discovery.git] / discovery-ui / src / main / resources / iui / microservices / js / routeFunc.js
1 /*\r
2  * Copyright 2016-2017 ZTE, Inc. and others.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 $(function(){\r
17 \r
18 \r
19    $(".form-tip").blur(function(){\r
20     if($.trim($(this).val())==""){\r
21       $(this).removeClass("form-input-focus");\r
22       $(this).prev().removeClass("item-tip-focus");\r
23     }});\r
24 \r
25 $(".form-tip").focus(function(){\r
26   if(!$(this).hasClass("form-input-focus")){\r
27   $(this).addClass("form-input-focus");\r
28   $(this).prev().addClass("item-tip-focus");\r
29   }});\r
30 \r
31 $(".item-tip").click(function(){\r
32   $(this).next().focus();\r
33 });\r
34 \r
35 $("input[name='version']").blur(function(){\r
36     $(this).val($(this).val().toLowerCase());\r
37 \r
38     if(vm.msbRouteInfo.protocol=='REST' || vm.msbRouteInfo.protocol=='HTTP' ){\r
39     routeUtil.changeTargetServiceUrl();\r
40     }\r
41 });\r
42 \r
43 \r
44 \r
45 $("input[name='serviceName']").change(function(){\r
46  if(vm.msbRouteInfo.protocol=='REST' || vm.msbRouteInfo.protocol=='UI' || vm.msbRouteInfo.protocol=='HTTP'){\r
47     routeUtil.changeTargetServiceUrl();\r
48     }\r
49 \r
50 });\r
51 \r
52 $("input[name='url']").change(function(){\r
53 \r
54     routeUtil.changeTargetServiceUrl();\r
55 });\r
56 \r
57 \r
58 \r
59 $("select[name='protocol']").change(function(){\r
60 \r
61 routeUtil.changeTargetServiceUrl();\r
62 \r
63 });\r
64 \r
65 $("input[name='chkVisualRange']").change(function(){\r
66 \r
67 routeUtil.changeTargetServiceUrl();\r
68 \r
69 });\r
70 \r
71 $("input[name='publish_port']").change(function(){\r
72 \r
73 routeUtil.changeTargetServiceUrl();\r
74 \r
75 });\r
76 \r
77 $("input[name='http_publish_port']").change(function(){\r
78 \r
79 routeUtil.changeTargetServiceUrl();\r
80 \r
81 });\r
82 \r
83 $("input[name='networkPlaneType']").change(function(){\r
84 \r
85 routeUtil.changeTargetServiceUrl();\r
86 \r
87 });\r
88 \r
89 $("#labels").change(function(){\r
90 \r
91 routeUtil.changeTargetServiceUrl();\r
92 \r
93 });\r
94 \r
95 \r
96 \r
97 $("input[name='host']").change(function(){\r
98 \r
99 routeUtil.changeTargetServiceUrl();\r
100 \r
101 });\r
102 \r
103 $("input[name='path']").change(function(){\r
104 \r
105 routeUtil.changeTargetServiceUrl();\r
106 \r
107 });\r
108 \r
109 \r
110 $("input[name='namespace']").change(function(){\r
111 \r
112 vm.getApigatewayInfo($(this).val());\r
113 \r
114 });\r
115 \r
116 \r
117 \r
118 \r
119    jQuery.validator.addMethod("ip", function(value, element) {    \r
120       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
121     }, $.i18n.prop("org_onap_msb_discover_validator_ip_format"));\r
122 \r
123 \r
124 \r
125   jQuery.validator.addMethod("url_head", function(value, element) {    \r
126       return this.optional(element) || /^\/.+((?!\/).)$/i.test(value) || /^\/$/i.test(value);    \r
127     }, $.i18n.prop("org_onap_msb_discover_validator_url_head_format"));\r
128 \r
129 \r
130 jQuery.validator.addMethod("url_head_only", function(value, element) {    \r
131       return this.optional(element) || /^\/.*$/i.test(value);    \r
132     }, $.i18n.prop("org_onap_msb_discover_validator_url_head_only_format"));\r
133   \r
134     jQuery.validator.addMethod("version", function(value, element) {    \r
135       return this.optional(element) || /^v\d+(\.\d+)?$/i.test(value);    \r
136     }, $.i18n.prop("org_onap_msb_discover_form_version_tip"));\r
137 \r
138      jQuery.validator.addMethod("service_url", function(value, element) {    \r
139     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
140     }, $.i18n.prop("org_onap_msb_discover_validator_url_format"));\r
141 \r
142      jQuery.validator.addMethod("url_line", function(value, element) {    \r
143       return this.optional(element) || /^((?!\/).)*$/.test(value);    \r
144     }, $.i18n.prop("org_onap_msb_discover_validator_url_line_format"));\r
145 \r
146      jQuery.validator.addMethod("content", function(value, element) {    \r
147       return this.optional(element) ||  /^([0-9a-zA-Z]|-|_)*$/i.test(value);    \r
148     }, $.i18n.prop("org_onap_msb_discover_validator_content_format"));\r
149 \r
150      jQuery.validator.addMethod("custom_content", function(value, element) {    \r
151       return this.optional(element) ||  /^([0-9a-zA-Z]|-|_|\/)*$/i.test(value);    \r
152     }, $.i18n.prop("org_onap_msb_discover_validator_content_format"));\r
153 \r
154       jQuery.validator.addMethod("http_publish_port_content", function(value, element) {    \r
155       return this.optional(element) ||  /^([0-9]|\|)*$/i.test(value);    \r
156     }, $.i18n.prop("org_onap_msb_discover_validator_publish_port_format"));\r
157 \r
158 \r
159  });\r
160 \r
161  \r
162 \r
163       var msbform = $('#msbForm');\r
164      var msberror = $('.alert-danger', msbform);\r
165       var msbsuccess = $('.alert-success', msbform);\r
166 \r
167 \r
168     msbform.validate({\r
169     doNotHideMessage: true, //this option enables to show the error/success messages on tab switch.\r
170     errorElement: 'span', //default input error message container\r
171     errorClass: 'help-block', // default input error message class\r
172     focusInvalid: false, // do not focus the last invalid input\r
173     rules: {     \r
174     \r
175       serviceName:{\r
176         required: true,\r
177          content:true,\r
178         maxlength:50\r
179       },\r
180       version:{\r
181         maxlength:50,\r
182         version:true\r
183       },\r
184        url:{\r
185        // url_head:true,\r
186         maxlength:50\r
187       },\r
188        path:{\r
189         //url_head:true,\r
190         maxlength:50\r
191       },\r
192       newHost:{\r
193         ip:true,\r
194         maxlength:50\r
195       },\r
196       newttl:{\r
197         digits:true,\r
198         min:0\r
199       },    \r
200       http_publish_port:{\r
201         http_publish_port_content:true\r
202       }, \r
203       publish_port:{\r
204         digits:true,\r
205         min:1,\r
206         max:65535\r
207       },\r
208       protocol:{\r
209         required: true\r
210       },\r
211       visualRange:{\r
212         required: true,\r
213         minlength:1\r
214       },\r
215       host:{\r
216          content:true,\r
217         maxlength:50\r
218       }\r
219     },\r
220     messages: { \r
221         serviceName:{\r
222         required: "Please enter the service name"\r
223       },\r
224        protocol:{\r
225         required:"Please select a service protocol"\r
226        \r
227       },     \r
228        visualRange:{\r
229         required:"Please select the service visibleRange"\r
230        \r
231       },\r
232       newttl:{\r
233         digits:"Please enter a number",\r
234         min: "number must be > 0"\r
235       },\r
236       publish_port:{\r
237         digits:"Please enter a number"\r
238       }\r
239 \r
240     },\r
241     errorPlacement: function (msberror, element) { // render error placement for each input type\r
242       msberror.insertAfter(element); // for other inputs, just perform default behavior\r
243     },\r
244 \r
245     invalidHandler: function (event, validator) { //display error alert on form submit   \r
246       msbsuccess.hide();\r
247       msberror.show();\r
248       //ZteFrameWork.scrollTo(error, -200);\r
249     },\r
250 \r
251     highlight: function (element) { // hightlight error inputs\r
252       $(element)\r
253         .closest('.form-group').removeClass('has-success').addClass('has-error'); // set error class to the control group\r
254     },\r
255 \r
256     unhighlight: function (element) { // revert the change done by hightlight\r
257       $(element)\r
258         .closest('.form-group').removeClass('has-error'); // set error class to the control group\r
259     },\r
260 \r
261     success: function (label) {\r
262       label\r
263         .addClass('valid') // mark the current input as valid and display OK icon\r
264         .closest('.form-group').removeClass('has-error'); // set success class to the control group\r
265     },\r
266     submitHandler: function (form) {\r
267       msbsuccess.show();\r
268       msberror.hide();\r
269       //add here some ajax code to submit your form or just call form.submit() if you want to submit the form without ajax\r
270     }\r
271 \r
272    });\r
273 \r
274     \r
275     var nodeform = $('#nodeForm');\r
276      var nodeerror = $('.alert-danger', nodeform);\r
277       var nodesuccess = $('.alert-success', nodeform);\r
278 \r
279 \r
280     nodeform.validate({\r
281     doNotHideMessage: true, //this option enables to show the error/success messages on tab switch.\r
282     errorElement: 'span', //default input error message container\r
283     errorClass: 'help-block', // default input error message class\r
284     focusInvalid: false, // do not focus the last invalid input\r
285     rules: {     \r
286     \r
287       nodeInfo_ip:{\r
288         required: true,\r
289         ip:true,\r
290         maxlength:50\r
291       },\r
292       nodeInfo_port:{\r
293         required: true,\r
294         digits:true,\r
295         min:1,\r
296         max:65535\r
297       },\r
298       nodeInfo_weight:{\r
299         digits:true,\r
300         maxlength:3,\r
301         min:1\r
302       },\r
303       nodeInfo_max_fails:{\r
304         digits:true,\r
305         maxlength:3,\r
306         min:1\r
307       },\r
308       nodeInfo_fail_timeout:{\r
309         digits:true,\r
310         maxlength:3,\r
311         min:1\r
312       },\r
313       checkInterval:{\r
314         digits:true,\r
315         maxlength:3,\r
316         min:1\r
317       },\r
318       checkTimeOut:{\r
319         digits:true,\r
320         min:1\r
321       },\r
322       ttl:{\r
323         digits:true,\r
324         min:1\r
325       }\r
326      \r
327     },\r
328     messages: { \r
329         nodeInfo_ip:{\r
330         required:"Please enter the Host IP"\r
331       },\r
332        nodeInfo_port:{\r
333         required: "Please enter the Host Port",\r
334         digits:"Please enter a number",\r
335         min: "number must be > 1"    \r
336       } ,\r
337       nodeInfo_weight:{\r
338         digits:"only num",\r
339         min:"must>0"    \r
340       },\r
341        nodeInfo_max_fails:{\r
342         digits:"only num",\r
343         min: "must>0" \r
344       },\r
345        nodeInfo_fail_timeout:{\r
346         digits:"only num",\r
347         min: "must>0"       \r
348       } ,\r
349        checkInterval:{\r
350         digits:"only num",\r
351         min:"must>0"      \r
352       } ,\r
353        checkTimeOut:{\r
354         digits:"only num",\r
355         min:"must>0"      \r
356       } ,\r
357        ttl:{\r
358         digits:"only num",\r
359         min:"must>0"      \r
360       }      \r
361       \r
362       \r
363 \r
364     },\r
365     errorPlacement: function (nodeerror, element) { // render error placement for each input type\r
366       nodeerror.insertAfter(element); // for other inputs, just perform default behavior\r
367     },\r
368 \r
369     invalidHandler: function (event, validator) { //display error alert on form submit   \r
370       nodesuccess.hide();\r
371       nodeerror.show();\r
372       //ZteFrameWork.scrollTo(error, -200);\r
373     },\r
374 \r
375     highlight: function (element) { // hightlight error inputs\r
376       $(element)\r
377         .closest('.form-group').removeClass('has-success').addClass('has-error'); // set error class to the control group\r
378     },\r
379 \r
380     unhighlight: function (element) { // revert the change done by hightlight\r
381       $(element)\r
382         .closest('.form-group').removeClass('has-error'); // set error class to the control group\r
383     },\r
384 \r
385     success: function (label) {\r
386       label\r
387         .addClass('valid') // mark the current input as valid and display OK icon\r
388         .closest('.form-group').removeClass('has-error'); // set success class to the control group\r
389     },\r
390     submitHandler: function (form) {\r
391       nodesuccess.show();\r
392       nodeerror.hide();\r
393       //add here some ajax code to submit your form or just call form.submit() if you want to submit the form without ajax\r
394     }\r
395 \r
396    });\r
397 \r
398 \r
399       function spinnerButtonBindClick() {\r
400         $('.spinner .btn:first-of-type').unbind().on('click', function () {\r
401             var input = $('input', $(this).parents('.spinner'));\r
402 \r
403             if(input.val()=="") input.val("0");\r
404 \r
405             input.val(parseInt(input.val(), 10) + 1);\r
406             if (input.val() > 1) {\r
407                 $('.spinner .btn:last-of-type').attr("disabled", false);\r
408             }\r
409         });\r
410         $('.spinner .btn:last-of-type').unbind().on('click', function () {\r
411             var input = $('input', $(this).parents('.spinner'));\r
412              if(input.val()=="") input.val("2");\r
413 \r
414             input.val(parseInt(input.val(), 10) - 1);\r
415             if (input.val() <= 1) {\r
416                 $('.spinner .btn:last-of-type').attr("disabled", true);\r
417             }\r
418         });\r
419     }\r
420 \r
421     \r
422 \r
423 \r
424 \r