[CORD-1780] XosConfirm implementation

Change-Id: I053c6ece6a5bd41014bdbb45d8fbf15f99a5b7ca
diff --git a/src/app/core/confirm/confirm.html b/src/app/core/confirm/confirm.html
new file mode 100644
index 0000000..c9b4c81
--- /dev/null
+++ b/src/app/core/confirm/confirm.html
@@ -0,0 +1,27 @@
+
+<!--
+Copyright 2017-present Open Networking Foundation
+
+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.
+-->
+
+<div class="modal-header" ng-show="vm.config.header">
+    <h4>{{vm.config.header}}</h4>
+</div>
+<div class="modal-body" ng-show="vm.config.text">
+    {{vm.config.text}}
+</div>
+<div class="modal-footer">
+    <a class="btn btn-default" ng-click="vm.dismiss()">Cancel</a>
+    <a class="btn" ng-class="action.class" ng-repeat="action in vm.config.actions" ng-click="vm.close(action.cb())">{{action.label}}</a>
+</div>
\ No newline at end of file
diff --git a/src/app/core/confirm/confirm.scss b/src/app/core/confirm/confirm.scss
new file mode 100644
index 0000000..7332fd6
--- /dev/null
+++ b/src/app/core/confirm/confirm.scss
@@ -0,0 +1,20 @@
+
+/*
+ * Copyright 2017-present Open Networking Foundation
+
+ * 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.
+ */
+
+.modal-content .modal-header, .modal-content .modal-body, .modal-content .modal-footer{
+  padding: 10px
+}
\ No newline at end of file
diff --git a/src/app/core/confirm/confirm.service.spec.ts b/src/app/core/confirm/confirm.service.spec.ts
new file mode 100644
index 0000000..84a61de
--- /dev/null
+++ b/src/app/core/confirm/confirm.service.spec.ts
@@ -0,0 +1,72 @@
+
+/*
+ * Copyright 2017-present Open Networking Foundation
+
+ * 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.
+ */
+
+
+import * as angular from 'angular';
+import 'angular-mocks';
+import {IXosConfirm, XosConfirm} from './confirm.service';
+
+let service: IXosConfirm;
+let modal;
+let modalInstance;
+
+describe('The XosConfirm service', () => {
+
+  beforeEach(() => {
+    angular.module('XosConfirmTest', ['ui.bootstrap.modal'])
+      .service('XosConfirm', XosConfirm);
+    angular.mock.module('XosConfirmTest');
+
+    angular.mock.inject((
+      XosConfirm: IXosConfirm,
+      $uibModal: any
+    ) => {
+      service = XosConfirm;
+      modal = $uibModal;
+    });
+  });
+
+  describe('the open method', () => {
+
+    let test1 = {
+        header: 'Test Header',
+        text: 'Test body',
+        actions: [{
+          label: 'Action',
+          cb: () => {
+            return;
+          },
+          class: 'btn-success'
+        }]
+      };
+
+    it('should open a modal', () => {
+      spyOn(modal, 'open');
+      modalInstance = service.open(test1);
+      expect(modal.open).toHaveBeenCalled();
+    });
+  });
+
+  // describe('the close method', () => {
+  //
+  // });
+  //
+  // describe('the dismiss method', () => {
+  //
+  // });
+
+});
diff --git a/src/app/core/confirm/confirm.service.ts b/src/app/core/confirm/confirm.service.ts
new file mode 100644
index 0000000..a8e802e
--- /dev/null
+++ b/src/app/core/confirm/confirm.service.ts
@@ -0,0 +1,65 @@
+
+/*
+ * Copyright 2017-present Open Networking Foundation
+
+ * 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.
+ */
+
+import {IXosConfirmConfig} from './confirm';
+
+export interface IXosConfirm {
+  open(config: IXosConfirmConfig) : void;
+  close(cb: Function) : void;
+  dismiss() : void;
+}
+
+export class XosConfirm implements IXosConfirm {
+
+  static $inject = ['$uibModal'];
+  public modalInstance;
+
+  constructor(
+    private $uibModal : any,
+  ) {
+
+  }
+
+  public open(config: IXosConfirmConfig) {
+
+    this.modalInstance = this.$uibModal.open({
+      keyboard: false,
+      component: 'xosConfirm',
+      backdrop: 'static',
+      resolve: {
+        config: () => config
+      }
+    });
+    return this.modalInstance;
+  }
+
+  public close(cb: Function) {
+    cb()
+      .then(() => {
+        this.modalInstance.close();
+      })
+      .catch((err) => {
+        this.modalInstance.dismiss(err);
+    });
+  }
+
+  public dismiss() {
+      this.modalInstance.dismiss();
+  }
+
+}
+
diff --git a/src/app/core/confirm/confirm.ts b/src/app/core/confirm/confirm.ts
new file mode 100644
index 0000000..92ca239
--- /dev/null
+++ b/src/app/core/confirm/confirm.ts
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+
+ * 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.
+ */
+
+import './confirm.scss';
+
+export interface IXosConfirmConfig {
+  header?: string;
+  text?: string;
+  actions: IXosConfirmConfigAction[];
+}
+
+export interface IXosConfirmConfigAction {
+  label?: string;
+  cb: Function;
+  icon?: string;
+  class?: string;
+}
+
+class ConfirmCtrl {
+
+  static $inject = ['XosConfirm'];
+
+  public resolve;
+  public config: IXosConfirmConfig;
+
+  constructor(
+    private XosConfirm: any
+  ) {
+
+  }
+
+  public $onInit() {
+    this.config = this.resolve.config;
+  }
+
+  public close(cb: Function) {
+    this.XosConfirm.close(cb);
+  }
+
+  public dismiss() {
+    this.XosConfirm.dismiss();
+  }
+
+}
+
+export const xosConfirm: angular.IComponentOptions = {
+  template: require('./confirm.html'),
+  controllerAs: 'vm',
+  controller: ConfirmCtrl,
+  bindings: {
+    resolve: '<',
+    close: '&',
+    dismiss: '&'
+  }
+};
diff --git a/src/app/core/index.ts b/src/app/core/index.ts
index 523bae6..bdd0157 100644
--- a/src/app/core/index.ts
+++ b/src/app/core/index.ts
@@ -46,6 +46,8 @@
 import {xosDebugSummary} from './debug/debug-summary';
 import {XosDebugService} from './debug/debug.service';
 import {xosDebugModel} from './debug/debug-model';
+import {xosConfirm} from './confirm/confirm';
+import {XosConfirm} from './confirm/confirm.service';
 
 export const xosCore = 'xosCore';
 
@@ -67,6 +69,7 @@
   .service('XosComponentInjector', XosComponentInjector)
   .service('XosDebouncer', XosDebouncer)
   .service('XosDebug', XosDebugService)
+  .service('XosConfirm', XosConfirm)
   .directive('xosLinkWrapper', xosLinkWrapper)
   .component('xosHeader', xosHeader)
   .component('xosFooter', xosFooter)
@@ -83,5 +86,6 @@
   .component('xosKeyBindingPanel', xosKeyBindingPanel)
   .component('xosDebugSummary', xosDebugSummary)
   .component('xosDebugModel', xosDebugModel)
+  .component('xosConfirm', xosConfirm)
   .filter('pagination', PaginationFilter)
   .filter('arrayToList', ArrayToListFilter);