UI: add UNI & IPVC tabs (work in-progress)
[unimgr.git] / dlux / cpeui / cpeui-module / src / main / resources / cpeui / services / cpeui.dialogs.js
1 define([ 'app/cpeui/cpeui.module' ], function(cpeui) {
2
3   cpeui.factory('CpeuiDialogs', function($mdDialog, $mdMedia, CpeuiSvc) {
4     var svc = {};
5
6     svc.Dialog = function(tpl, params, callback, customController) {
7
8       this.customFullscreen = $mdMedia('xs') || $mdMedia('sm');
9
10       this.dialogController = function($scope, $mdDialog, params) {
11         $scope.params = params;
12
13         $scope.obj = {};
14         $scope.hide = function() {
15           $mdDialog.hide();
16         };
17         $scope.cancel = function() {
18           $mdDialog.cancel();
19         };
20         $scope.done = function() {
21           if ($scope.projectForm.$valid) {
22             callback($scope.obj);
23             $mdDialog.hide();
24           }
25         };
26
27         if (customController != undefined) {
28           customController($scope, $mdDialog, params);
29         }
30
31       };
32
33       this.show = function(ev, params) {
34         $mdDialog.show({
35           controller : this.dialogController,
36           templateUrl : 'src/app/cpeui/dialogs/' + tpl + '.tpl.html',
37           parent : angular.element(document.body),
38           targetEvent : ev,
39           clickOutsideToClose : true,
40           fullscreen : this.customFullscreen,
41           locals : {
42             params : params
43           },
44         // onComplete: function() {$('md-dialog').draggable();}
45         });
46       };
47     };
48
49     svc.confirm = function(callback_ok, callback_cancel) {
50       svc.customConfirm('Are you Sure?', "", callback_ok, callback_cancel);
51     };
52
53     svc.customConfirm = function(title, content, callback_ok, callback_cancel) {
54       var confirm = $mdDialog.confirm().title(title).textContent(content).ok(
55           'Yes!').cancel('Cancel');
56       $mdDialog.show(confirm).then(callback_ok, callback_cancel);
57     };
58
59     svc.alert = function(title, content, callback_ok) {
60       var alert = $mdDialog.alert().title(title).textContent(content).ok(
61           'Ok');
62       $mdDialog.show(alert).then(callback_ok);
63     };
64     
65     return svc;
66   });
67
68 });