aboutsummaryrefslogtreecommitdiffstats
path: root/openo-portal/portal-extsys/src/main/webapp/extsys/sdn/js
diff options
context:
space:
mode:
Diffstat (limited to 'openo-portal/portal-extsys/src/main/webapp/extsys/sdn/js')
-rw-r--r--openo-portal/portal-extsys/src/main/webapp/extsys/sdn/js/sdn-validate.js67
-rw-r--r--openo-portal/portal-extsys/src/main/webapp/extsys/sdn/js/sdnController.js202
-rw-r--r--openo-portal/portal-extsys/src/main/webapp/extsys/sdn/js/sdnUtil.js89
3 files changed, 358 insertions, 0 deletions
diff --git a/openo-portal/portal-extsys/src/main/webapp/extsys/sdn/js/sdn-validate.js b/openo-portal/portal-extsys/src/main/webapp/extsys/sdn/js/sdn-validate.js
new file mode 100644
index 00000000..21b711af
--- /dev/null
+++ b/openo-portal/portal-extsys/src/main/webapp/extsys/sdn/js/sdn-validate.js
@@ -0,0 +1,67 @@
+$(function () {
+ var form = $('#sdn_form');
+ var error = $('.alert-danger', form);
+ var success = $('.alert-success', form);
+
+ form.validate({
+ doNotHideMessage : true, //this option enables to show the error/success messages on tab switch.
+ errorElement : 'span', //default input error message container
+ errorClass : 'help-block', // default input error message class
+ focusInvalid : false, // do not focus the last invalid input
+ rules : {
+ name : {
+ required : true,
+ maxlength : 20
+ },
+ url : {
+ required : true,
+ url : true
+ },
+ userName : {
+ required : true,
+ maxlength : 20
+ },
+ password : {
+ required : true,
+ maxlength : 20
+ }
+ },
+ messages : {
+ name : {
+ required : $.i18n.prop("roc-sdn-iui-validate-name")
+ },
+ url : {
+ required : $.i18n.prop("roc-sdn-iui-validate-url-required"),
+ url : $.i18n.prop("roc-sdn-iui-validate-url")
+ },
+ userName : {
+ required : $.i18n.prop('roc-sdn-iui-validate-username')
+ },
+ password : {
+ required : $.i18n.prop('roc-sdn-iui-validate-password')
+ }
+ },
+ errorPlacement : function (error, element) { // render error placement for each input type
+ error.insertAfter(element); // for other inputs, just perform default behavior
+ },
+ invalidHandler : function (event, validator) { //display error alert on form submit
+ success.hide();
+ error.show();
+ },
+ highlight : function (element) { // hightlight error inputs
+ $(element).closest('.form-group').removeClass('has-success').addClass('has-error'); // set error class to the control group
+ },
+ unhighlight : function (element) { // revert the change done by hightlight
+ $(element).closest('.form-group').removeClass('has-error'); // set error class to the control group
+ },
+ success : function (label) {
+ label.addClass('valid') // mark the current input as valid and display OK icon
+ .closest('.form-group').removeClass('has-error'); // set success class to the control group
+ },
+ submitHandler : function (form) {
+ success.show();
+ error.hide();
+ //add here some ajax code to submit your form or just call form.submit() if you want to submit the form without ajax
+ }
+ });
+});
diff --git a/openo-portal/portal-extsys/src/main/webapp/extsys/sdn/js/sdnController.js b/openo-portal/portal-extsys/src/main/webapp/extsys/sdn/js/sdnController.js
new file mode 100644
index 00000000..0b6c5c2e
--- /dev/null
+++ b/openo-portal/portal-extsys/src/main/webapp/extsys/sdn/js/sdnController.js
@@ -0,0 +1,202 @@
+/*
+ * Copyright (C) 2015 ZTE, Inc. and others. All rights reserved. (ZTE)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var vm = avalon
+ .define({
+ $id : "sdnController",
+ sdnInfo : [],
+ server_rtn : {
+ info_block : false,
+ warning_block : false,
+ rtn_info : "",
+ $RTN_SUCCESS : "RTN_SUCCESS",
+ $RTN_FAILED : "RTN_FAILED"
+ },
+ $Status : {
+ success : "active",
+ failed : "inactive"
+ },
+ $restUrl : {
+ querySdnControllerInfoUrl : '/openoapi/extsys/v1/sdncontrollers',
+ addSdnControllerInfoUrl : '/openoapi/extsys/v1/sdncontrollers',
+ updateSdnControllerInfoUrl : '/openoapi/extsys/v1/sdncontrollers',
+ delSdnControllerInfoUrl : '/openoapi/extsys/v1/sdncontrollers'
+ },
+ $htmlText : {
+ saveSuccess : $.i18n.prop("roc-sdn-iui-message-save-success"),
+ saveFail : $.i18n.prop("roc-sdn-iui-message-save-fail"),
+ updateSuccess : $.i18n.prop("roc-sdn-iui-message-update-success"),
+ updateFail : $.i18n.prop("roc-sdn-iui-message-update-fail")
+ },
+ $initTable : function () {
+ $.ajax({
+ "type" : 'GET',
+ "url" : vm.$restUrl.querySdnControllerInfoUrl,
+ "dataType" : "json",
+ "success" : function (resp) {
+ if (resp.operationResult == "SUCCESS") {
+ vm.sdnInfo = (resp == null) ? [] : resp.data;
+ } else {
+ vm.sdnInfo = [];
+ bootbox.alert($.i18n.prop("roc-sdn-iui-message-query-fail"));
+ return;
+ }
+ },
+ error : function (XMLHttpRequest, textStatus, errorThrown) {
+ bootbox.alert($.i18n.prop("roc-sdn-iui-message-query-fail") + ":" + textStatus + ":" + errorThrown);
+ return;
+ },
+ complete : function () {
+ sdnUtil.tooltipSdnStatus();
+ }
+ });
+ },
+ $sdnType : {
+ condName : $.i18n.prop("roc-sdn-iui-text-type"),
+ component_type : 'select',
+ selectItems : [{
+ cond_value : 'ODL',
+ name : "ODL",
+ value : true
+ }, {
+ cond_value : 'ONOS',
+ name : "ONOS",
+ value : true
+ }
+ ]
+ },
+ addSdn : {
+ title : $.i18n.prop("roc-sdn-iui-text-register"),
+ sdnId : "",
+ name : "",
+ type : "ODL",
+ typeDisabled : false,
+ url : "",
+ urlTip : $.i18n.prop("roc-sdn-iui-text-url-tip"),
+ userName : "",
+ password : "",
+ saveType : "add"
+ },
+ $showSdnTable : function () {
+ vm.addSdn.title = $.i18n.prop("roc-sdn-iui-text-register"),
+ vm.addSdn.sdnId = "";
+ vm.addSdn.name = "";
+ vm.addSdn.type = "ODL";
+ vm.addSdn.typeDisabled = false;
+ vm.addSdn.url = "";
+ vm.addSdn.userName = "";
+ vm.addSdn.password = "";
+ vm.addSdn.saveType = "add";
+ vm.server_rtn.warning_block = false;
+ vm.server_rtn.info_block = false;
+
+ $(".form-group").each(function () {
+ $(this).removeClass('has-success');
+ $(this).removeClass('has-error');
+ $(this).find(".help-block[id]").remove();
+ });
+ $("#addSdnDlg").modal("show");
+ },
+ $saveSdn : function () {
+ var form = $('#sdn_form');
+ if (form.valid() == false) {
+ return false;
+ }
+ vm.server_rtn.info_block = true;
+ vm.server_rtn.warning_block = false;
+ vm.addSdn.status = vm.$Status.success;
+
+ var param = {
+ name : vm.addSdn.name,
+ controllerType : $("#type").val(),
+ url : vm.addSdn.url,
+ userName : vm.addSdn.userName,
+ password : vm.addSdn.password
+ }
+ if (vm.addSdn.saveType == "add") {
+ for( var i = 0; i < vm.sdnInfo.length; i ++ ){
+ if(vm.addSdn.url == vm.sdnInfo[i].url){
+ sdnUtil.growl($.i18n.prop("roc-sdn-iui-message-growl-msg-title") + 'already exist',"info");
+ $('#addSdnDlg').modal('hide');
+ return;
+ }
+ }
+ $.ajax({
+ type : "POST",
+ url : vm.$restUrl.addSdnControllerInfoUrl,
+ data : JSON.stringify(param),
+ dataType : "json",
+ contentType : "application/json",
+ success : function (data) {
+ vm.server_rtn.info_block = false;
+ vm.server_rtn.warning_block = false;
+ if (data) {
+ vm.sdnInfo = [];
+ vm.$initTable();
+
+ $('#addSdnDlg').modal('hide');
+ sdnUtil.showMessage(vm.$htmlText.saveSuccess, "success");
+ } else {
+ vm.server_rtn.warning_block = true;
+ vm.server_rtn.rtn_info = vm.$htmlText.saveFail;
+ sdnUtil.showMessage(vm.$htmlText.saveFail, "failed");
+ }
+ },
+ error : function (XMLHttpRequest, textStatus, errorThrown) {
+ vm.server_rtn.warning_block = true;
+ vm.server_rtn.rtn_info = textStatus + ":" + errorThrown;
+ vm.server_rtn.info_block = false;
+ }
+ });
+ } else {
+ $.ajax({
+ type : "PUT",
+ url : vm.$restUrl.updateSdnControllerInfoUrl + vm.addSdn.sdnId,
+ data : JSON.stringify(param),
+ dataType : "json",
+ contentType : "application/json",
+ success : function (data) {
+ vm.server_rtn.info_block = false;
+ vm.server_rtn.warning_block = false;
+ if (data) {
+ for (var i = 0; i < vm.sdnInfo.length; i++) {
+ if (vm.sdnInfo[i].sdnControllerInstanceId == vm.addSdn.sdnId) {
+ vm.sdnInfo[i].name = vm.addSdn.name;
+ vm.sdnInfo[i].type = $("#type").val();
+ vm.sdnInfo[i].url = vm.addSdn.url;
+ vm.sdnInfo[i].userName = vm.addSdn.userName;
+ vm.sdnInfo[i].password = vm.addSdn.password;
+ }
+ }
+ $('#addSdnDlg').modal('hide');
+ sdnUtil.showMessage(vm.$htmlText.updateSuccess, "success");
+ } else {
+ vm.server_rtn.warning_block = true;
+ vm.server_rtn.rtn_info = vm.$htmlText.updateFail;
+ sdnUtil.showMessage(vm.$htmlText.updateFail, "failed");
+ }
+ },
+ error : function (XMLHttpRequest, textStatus, errorThrown) {
+ vm.server_rtn.warning_block = true;
+ vm.server_rtn.rtn_info = textStatus + ":" + errorThrown;
+ vm.server_rtn.info_block = false;
+ }
+ });
+ }
+ },
+ });
+avalon.scan();
+vm.$initTable();
diff --git a/openo-portal/portal-extsys/src/main/webapp/extsys/sdn/js/sdnUtil.js b/openo-portal/portal-extsys/src/main/webapp/extsys/sdn/js/sdnUtil.js
new file mode 100644
index 00000000..59062fcd
--- /dev/null
+++ b/openo-portal/portal-extsys/src/main/webapp/extsys/sdn/js/sdnUtil.js
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2015 ZTE, Inc. and others. All rights reserved. (ZTE)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+var sdnUtil = {};
+
+sdnUtil.delSdn = function (el) {
+ bootbox.confirm($.i18n.prop("roc-sdn-iui-message-delete-confirm"), function (result) {
+ if (result) {
+ $.ajax({
+ type : "DELETE",
+ url : vm.$restUrl.delSdnControllerInfoUrl + el.sdnControllerInstanceId,
+ dataType : "json",
+ success : function (data) {
+ if (data) {
+ for (var i = 0; i < vm.sdnInfo.length; i++) {
+ if (el.sdnControllerInstanceId == vm.sdnInfo[i].sdnControllerInstanceId) {
+ vm.sdnInfo.splice(i, 1);
+ break;
+ }
+ }
+ sdnUtil.showMessage($.i18n.prop("roc-sdn-iui-message-delete-success"), "success");
+ } else {
+ sdnUtil.showMessage($.i18n.prop("roc-sdn-iui-message-delete-fail"), "warning");
+ }
+ },
+ error : function () {
+ sdnUtil.showMessage($.i18n.prop("roc-sdn-iui-message-delete-fail"), "warning");
+ }
+ });
+ }
+ });
+}
+
+sdnUtil.updateSdn = function (data) {
+ vm.addSdn.sdnId = data.sdnControllerInstanceId;
+ vm.addSdn.name = data.name;
+ vm.addSdn.type = data.controllerType;
+ vm.addSdn.typeDisabled = true;
+ vm.addSdn.url = data.url;
+ vm.addSdn.userName = data.userName;
+ vm.addSdn.password = data.password;
+ vm.addSdn.saveType = "update";
+ vm.addSdn.title = $.i18n.prop("roc-sdn-iui-text-update");
+ vm.server_rtn.info_block = false;
+ vm.server_rtn.warning_block = false;
+
+ $(".form-group").each(function () {
+ $(this).removeClass('has-success');
+ $(this).removeClass('has-error');
+ $(this).find(".help-block[id]").remove();
+ });
+ $("#addSdnDlg").modal("show");
+}
+
+sdnUtil.tooltipSdnStatus = function () {
+ $("[data-toggle='tooltip']").tooltip();
+}
+
+sdnUtil.growl = function (message, type) {
+ $.growl({
+ icon : "fa fa-envelope-o fa-lg",
+ title : "&nbsp;&nbsp;Notice: ",
+ message : message + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
+ }, {
+ type : type
+ });
+}
+
+sdnUtil.showMessage = function(message, type) {
+ $.growl({
+ icon: "fa fa-envelope-o fa-lg",
+ title: "&nbsp;&nbsp;" + $.i18n.prop("roc-sdn-iui-common-tip"),
+ message: message
+ },{
+ type: type
+ });
+};