CLIENT GUI Framework
[vnfsdk/refrepo.git] / openo-portal / portal-extsys / src / main / webapp / extsys / vim / js / vim-validate.js
1 /*\r
2  * Copyright 2016-2017 ZTE Corporation.\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 /**\r
17  * Created by 10184303 on 15-11-17.\r
18  */\r
19 var form = $('#vim_form');\r
20 var error = $('.alert-danger', form);\r
21 var success = $('.alert-success', form);\r
22 form.validate({\r
23     doNotHideMessage: true, //this option enables to show the error/success messages on tab switch.\r
24     errorElement: 'span', //default input error message container\r
25     errorClass: 'help-block', // default input error message class\r
26     focusInvalid: false, // do not focus the last invalid input\r
27     rules: {\r
28         url: {\r
29             required: true,\r
30             url: true,\r
31             maxlength: 50\r
32             //,repeatedName: true\r
33         },\r
34         vimName: {\r
35             required: true,\r
36             maxlength: 20\r
37         },\r
38         version: {\r
39             required: true,\r
40             maxlength: 20\r
41         },\r
42         vendor: {\r
43             required: true,\r
44             maxlength: 20\r
45         },\r
46         userName: {\r
47             required: true,\r
48             maxlength: 20\r
49         },\r
50         password: {\r
51             required: true,\r
52             maxlength: 20\r
53         },\r
54         tenant: {\r
55             required: true,\r
56             maxlength: 20\r
57         }\r
58     },\r
59     messages: {\r
60         url: {\r
61             //required: $.i18n.prop('com_zte_ums_zenic_topology_connectmanager_enter_name')\r
62             required: $.i18n.prop('com_zte_ums_eco_roc_vim_auth_url_require_message'),\r
63             url: $.i18n.prop('com_zte_ums_eco_roc_vim_auth_url_alarm_message')\r
64         },\r
65         vimName: {\r
66             required: $.i18n.prop('com_zte_ums_eco_roc_vim_name_alarm_message')\r
67         },\r
68         userName: {\r
69             required: $.i18n.prop('com_zte_ums_eco_roc_vim_username_alarm_message')\r
70         },\r
71         password: {\r
72             required: $.i18n.prop('com_zte_ums_eco_roc_vim_password_alarm_message')\r
73         },\r
74         version: {\r
75             required: $.i18n.prop('com_zte_ums_eco_roc_vim_version_alarm_message')\r
76         },\r
77         vendor: {\r
78             required: $.i18n.prop('com_zte_ums_eco_roc_vim_vendor_alarm_message')\r
79         },\r
80         tenant: {\r
81             required: $.i18n.prop('com_zte_ums_eco_roc_vim_tenant_alarm_message')\r
82         }\r
83     },\r
84     errorPlacement: function (error, element) { // render error placement for each input type\r
85         error.insertAfter(element); // for other inputs, just perform default behavior\r
86     },\r
87 \r
88     invalidHandler: function (event, validator) { //display error alert on form submit\r
89         success.hide();\r
90         error.show();\r
91         //ZteFrameWork.scrollTo(error, -200);\r
92     },\r
93 \r
94     highlight: function (element) { // hightlight error inputs\r
95         $(element)\r
96             .closest('.form-group').removeClass('has-success').addClass('has-error'); // set error class to the control group\r
97     },\r
98 \r
99     unhighlight: function (element) { // revert the change done by hightlight\r
100         $(element)\r
101             .closest('.form-group').removeClass('has-error'); // set error class to the control group\r
102     },\r
103 \r
104     success: function (label) {\r
105         label\r
106             .addClass('valid') // mark the current input as valid and display OK icon\r
107             .closest('.form-group').removeClass('has-error'); // set success class to the control group\r
108     },\r
109 \r
110     submitHandler: function (form) {\r
111         success.show();\r
112         error.hide();\r
113         //add here some ajax code to submit your form or just call form.submit() if you want to submit the form without ajax\r
114     }\r
115 \r
116 });\r