github.com/sym3tri/etcd@v0.2.1-0.20140422215517-a563d82f95d6/mod/dashboard/app/ui/node-cog.js (about) 1 'use strict'; 2 3 angular.module('etcd.ui') 4 .directive('edNodeCog', function($modal, $rootScope, etcdApiSvc, toastSvc, 5 ETCD_EVENT) { 6 7 return { 8 templateUrl: '/ui/node-cog.html', 9 restrict: 'E', 10 replace: true, 11 scope: { 12 'node': '=' 13 }, 14 controller: function($scope){ 15 16 function getDeleteMsg() { 17 if ($scope.node.dir) { 18 return 'Are you sure you want to delete the directory "' + 19 $scope.node.key + '" and all of its keys?'; 20 } 21 return 'Are you sure you ant to delete "' + $scope.node.key + '"'; 22 } 23 24 // Options for both values and directories. 25 $scope.cogDropdownOptions = [ 26 { 27 label: 'View Details...', 28 callback: function() { 29 $modal.open({ 30 templateUrl: '/page/browser/node-info.html', 31 controller: 'NodeInfoCtrl', 32 resolve: { 33 node: d3.functor($scope.node) 34 } 35 }); 36 }, 37 weight: 100 38 }, 39 { 40 label: 'Delete Node...', 41 callback: function() { 42 $modal.open({ 43 templateUrl: '/coreos.ui/confirm-modal/confirm-modal.html', 44 controller: 'ConfirmModalCtrl', 45 resolve: { 46 title: d3.functor('Delete Node'), 47 message: getDeleteMsg, 48 btnText: d3.functor('Delete'), 49 errorFormatter: d3.functor('etcdApi'), 50 executeFn: _.identity.bind(null, function() { 51 return etcdApiSvc.delete($scope.node) 52 .then(function() { 53 $rootScope.$broadcast(ETCD_EVENT.NODE_DELETED, $scope.node); 54 }); 55 }) 56 } 57 }); 58 }, 59 weight: 300 60 } 61 ]; 62 63 // Options for directories only. 64 if ($scope.node.dir) { 65 $scope.cogDropdownOptions.push({ 66 label: 'Modify TTL...', 67 callback: function() { 68 $modal.open({ 69 templateUrl: '/page/browser/edit-ttl.html', 70 controller: 'EditTtlCtrl', 71 resolve: { 72 node: d3.functor($scope.node), 73 } 74 }); 75 }, 76 weight: 200 77 }); 78 } else { 79 // options for values only. 80 $scope.cogDropdownOptions.push({ 81 label: 'Modify Node...', 82 callback: function() { 83 $modal.open({ 84 templateUrl: '/page/browser/edit-node.html', 85 controller: 'EditNodeCtrl', 86 resolve: { 87 node: d3.functor($scope.node), 88 } 89 }); 90 }, 91 weight: 200 92 }); 93 } 94 95 } 96 }; 97 98 });